2016-04-07 03:20-0500, Suravee Suthikulpanit: > From: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> > > When a vcpu is loaded/unloaded to a physical core, we need to update > host physical APIC ID information in the Physical APIC-ID table > accordingly. > > Also, when vCPU is blocking/un-blocking (due to halt instruction), > we need to make sure that the is-running bit in set accordingly in the > physical APIC-ID table. > > Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx> > --- Thanks, Reviewed-by: Radim Krčmář <rkrcmar@xxxxxxxxxx> > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > #define AVIC_LOGICAL_ID_ENTRY_GUEST_PHYSICAL_ID_MASK (0xFF) > @@ -1330,6 +1332,64 @@ free_avic: > +/** > + * This function is called during VCPU halt/unhalt. > + */ > +static int avic_set_running(struct kvm_vcpu *vcpu, bool is_run) > +{ > + u64 entry; > + int h_physical_id = __default_cpu_present_to_apicid(vcpu->cpu); > + struct vcpu_svm *svm = to_svm(vcpu); > + > + if (!svm_vcpu_avic_enabled(svm)) > + return 0; > + > + /* ID = 0xff (broadcast), ID > 0xff (reserved) */ > + if (h_physical_id >= AVIC_PHYSICAL_ID_MAX) > + return -EINVAL; > + > + entry = READ_ONCE(*(svm->avic_physical_id_cache)); > + if (is_run) > + WARN_ON((entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK) != 0); > + else > + WARN_ON((entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK) == 0); (We're pretty unlikely to hit this, so I'd give it just one line with: "is_run == !!(entry & AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK)") > + > + entry &= ~AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK; > + if (is_run) > + entry |= AVIC_PHYSICAL_ID_ENTRY_IS_RUNNING_MASK; > + WRITE_ONCE(*(svm->avic_physical_id_cache), entry); > + > + return 0; > +} > @@ -1395,6 +1455,11 @@ static struct kvm_vcpu *svm_create_vcpu(struct kvm *kvm, unsigned int id) > } > } > > + /* We initialize this flag to one to make sure that the is_running > + * bit would be set the first time the vcpu is loaded. > + */ > + svm->avic_is_blocking = false; (svm was zalloc'ed, so we know it to be false, but I guess that a bit of documentation doesn't hurt.) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html