Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934158AbcDLOeu (ORCPT ); Tue, 12 Apr 2016 10:34:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34908 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756169AbcDLOet (ORCPT ); Tue, 12 Apr 2016 10:34:49 -0400 Date: Tue, 12 Apr 2016 16:34:43 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Suravee Suthikulpanit Cc: pbonzini@redhat.com, joro@8bytes.org, bp@alien8.de, gleb@kernel.org, alex.williamson@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, wei@redhat.com, sherry.hurwitz@amd.com Subject: Re: [PART1 RFC v4 11/11] svm: Manage vcpu load/unload when enable AVIC Message-ID: <20160412143443.GC6762@potion.brq.redhat.com> References: <1460017232-17429-1-git-send-email-Suravee.Suthikulpanit@amd.com> <1460017232-17429-12-git-send-email-Suravee.Suthikulpanit@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1460017232-17429-12-git-send-email-Suravee.Suthikulpanit@amd.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2135 Lines: 65 2016-04-07 03:20-0500, Suravee Suthikulpanit: > From: Suravee Suthikulpanit > > 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 > --- Thanks, Reviewed-by: Radim Krčmář > 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.)