Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751442AbdILUEY (ORCPT ); Tue, 12 Sep 2017 16:04:24 -0400 Received: from mx2.suse.de ([195.135.220.15]:41495 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750991AbdILUEX (ORCPT ); Tue, 12 Sep 2017 16:04:23 -0400 Date: Tue, 12 Sep 2017 22:04:16 +0200 From: Borislav Petkov To: Brijesh Singh Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org, Thomas Gleixner , Joerg Roedel , "Michael S . Tsirkin" , Paolo Bonzini , =?utf-8?B?XCJSYWRpbSBLcsSNbcOhxZlcIg==?= , Tom Lendacky Subject: Re: [RFC Part2 PATCH v3 05/26] KVM: SVM: Reserve ASID range for SEV guest Message-ID: <20170912200416.ygcsqvznkkp2gd7r@pd.tnic> References: <20170724200303.12197-1-brijesh.singh@amd.com> <20170724200303.12197-6-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20170724200303.12197-6-brijesh.singh@amd.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2312 Lines: 83 On Mon, Jul 24, 2017 at 03:02:42PM -0500, Brijesh Singh wrote: > SEV-enabled guest must use ASIDs from the defined subset, while non-SEV "A SEV-enabled ..." > guests can use the remaining ASID range. The range of ASID allowed for > SEV-enabled guest is from 1 to a maximum value defined via CPUID > Fn8000_001f[ECX]. I'd rewrite that to: "The range of allowed SEV guest ASIDs is [1 - CPUID_8000_001F[ECX][31:0]]". > > Signed-off-by: Brijesh Singh > --- > arch/x86/kvm/svm.c | 23 ++++++++++++++++++++++- > 1 file changed, 22 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 46f41bb..06bd902 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -319,6 +319,9 @@ enum { > > #define VMCB_AVIC_APIC_BAR_MASK 0xFFFFFFFFFF000ULL > > +/* Secure Encrypted Virtualization */ If anything, this comment should explain what that variable is. Basically the comment you have in sev_hardware_setup() now. > +static unsigned int max_sev_asid; > + > static inline void mark_all_dirty(struct vmcb *vmcb) > { > vmcb->control.clean = 0; > @@ -769,7 +772,7 @@ static int svm_hardware_enable(void) > sd->asid_generation = 1; > sd->max_asid = cpuid_ebx(SVM_CPUID_FUNC) - 1; > sd->next_asid = sd->max_asid + 1; > - sd->min_asid = 1; > + sd->min_asid = max_sev_asid + 1; > > gdt = get_current_gdt_rw(); > sd->tss_desc = (struct kvm_ldttss_desc *)(gdt + GDT_ENTRY_TSS); > @@ -1033,6 +1036,21 @@ static int avic_ga_log_notifier(u32 ga_tag) > return 0; > } > > +static __init void sev_hardware_setup(void) > +{ > + int nguests; > + > + /* > + * Get maximum number of encrypted guest supported: Fn8001_001F[ECX] > + * Bit 31:0: Number of supported guest > + */ > + nguests = cpuid_ecx(0x8000001F); > + if (!nguests) > + return; > + > + max_sev_asid = nguests; > +} max_sev_asid is static and it is already initialized to 0 and thus this function can be simplified to: /* * Get maximum number of encrypted guest supported: Fn8001_001F[ECX]. * [31:0]: Number of supported guests. */ static __init void sev_hardware_setup(void) { max_sev_asid = cpuid_ecx(0x8000001F); } -- Regards/Gruss, Boris. SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg) --