From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 25F20C4332F for ; Mon, 5 Dec 2022 20:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=cNAg0vMKh+Q/kpbCo0vGV5bz13SsX1Cc1qMM+fW4mB4=; b=31aVrRGt4ZgUVn XQsnDw5di/gHQIE7MLrQcJ3YYjjXeGRCQWUu90Ia6+fSQw+/7yf9BzjdwJdSJxZ489bKs6ypCnHxt VfXa870NR8Njd7F/xnNH6FIQvxtv0jgN63QUMXK8zGxpYpmvlhdlJlbdxdT7Wq5ZiT0kS6sIkHq7D zz4d0Jqtuzv2WTZU656I4bq9ambMn2AIvjAGLrneVVUh3rrh9mvMlkHWRyahN8OR2j6uUsebn+ZRh qHCtxihNdl9tZ0L2BXySJ+HlW/d2u4upDGPNTOLmj9rcNSPfNULylxLVu+jaahJYuPfWbNkWY73aG pdubGYvvq/9yD6lQpATA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2ISY-00AUrX-CW; Mon, 05 Dec 2022 20:53:06 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p2ISK-00AUj3-Hr; Mon, 05 Dec 2022 20:52:54 +0000 Received: by mail-pf1-x42d.google.com with SMTP id a14so8547639pfa.1; Mon, 05 Dec 2022 12:52:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=N16dq1CjYHOw+jv6Di6rohy5xmWMqcOUPt5c96rryYM=; b=YfFvmGBbFyecNX7HuYSwK+aGIglSOKNXdG/GyCa5qUzLMOe/bS3LGfF0q9vWX+ZfHt 3Z92dtbJE772PsZ/NJy5FRdBdPEPZm5rcU7jdu4sFmCGP/7IKFYS0/CsqrcgEPVmen5V y6ej8cIOWvXwaBIve/M5ONQiyIWsJPUuFBVbweXevgwwGb/E9u9wEIP6iF6QJbkluoas PAiChapsuF6enaxC+tqdFRIctA1WbhgM/AjJeBOJlUlozWnDnw8Sd2pTj6YzSHsPtsBl J/2/tufxjQZdaKhz5ClxSt9r4yMQhCI1VtASfuD1Pfedea9GvzKUkPwh7azEivUucBcM puDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=N16dq1CjYHOw+jv6Di6rohy5xmWMqcOUPt5c96rryYM=; b=TEMpJe2aBh32gVT/hcer2ZSy+BWTnWOFozc4lBSMp7FgXNVUyxZBzxp+pmW/tuFaD/ pmAzoX/OoAXyj9J0iJW0tuNyjUssaifWxpSvQjRfGO7bLofClVCoSZqD6i0D+PJUGspV VOqScpYPvAKtbzaCz4O9V4+f05UwRbw1YBKxmZyr13hF41wqqKYW97B7jI4+PUPjMbRA r2Metr2uoJN+pntWb5nQOQqzuWj8zeUihYibEocwgz4MITsQ0bsHCx9ajLMWoCCwayuA TJvrEJNDNNmqHjFnmcn65MeH+klgBcLQM0/Ws9jo3mg6PTXRk6lGneTUf4v85RC0GvC0 BGfQ== X-Gm-Message-State: ANoB5pn9kce/9WSKOUBBlZQpOyjBxba45ozK4e2XQvCzSjiRB217pdfz hm0v5iQdnyN+6NqulDTyJtU= X-Google-Smtp-Source: AA0mqf4HpL3/0El3PrCiEsjkXuyAuKLQ7k5vbcFuFyn7/o3SL661WsLVyVHRUVAGEIBg3Ob2/Ax1ug== X-Received: by 2002:a05:6a00:4097:b0:576:cadf:16cc with SMTP id bw23-20020a056a00409700b00576cadf16ccmr9458181pfb.55.1670273568627; Mon, 05 Dec 2022 12:52:48 -0800 (PST) Received: from localhost ([192.55.54.55]) by smtp.gmail.com with ESMTPSA id f3-20020a170902ce8300b001780e4e6b65sm11105896plg.114.2022.12.05.12.52.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Dec 2022 12:52:47 -0800 (PST) Date: Mon, 5 Dec 2022 12:52:46 -0800 From: Isaku Yamahata To: Sean Christopherson Cc: Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Matthew Rosato , Eric Farman , Vitaly Kuznetsov , David Woodhouse , Paul Durrant , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Yao , Cornelia Huck , Isaku Yamahata , Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner , isaku.yamahata@gmail.com Subject: Re: [PATCH v2 31/50] KVM: x86: Do CPU compatibility checks in x86 code Message-ID: <20221205205246.GA3630770@ls.amr.corp.intel.com> References: <20221130230934.1014142-1-seanjc@google.com> <20221130230934.1014142-32-seanjc@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221130230934.1014142-32-seanjc@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221205_125252_611938_85E6DFD5 X-CRM114-Status: GOOD ( 25.06 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Wed, Nov 30, 2022 at 11:09:15PM +0000, Sean Christopherson wrote: > Move the CPU compatibility checks to pure x86 code, i.e. drop x86's use > of the common kvm_x86_check_cpu_compat() arch hook. x86 is the only > architecture that "needs" to do per-CPU compatibility checks, moving > the logic to x86 will allow dropping the common code, and will also > give x86 more control over when/how the compatibility checks are > performed, e.g. TDX will need to enable hardware (do VMXON) in order to > perform compatibility checks. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/svm/svm.c | 2 +- > arch/x86/kvm/vmx/vmx.c | 2 +- > arch/x86/kvm/x86.c | 49 ++++++++++++++++++++++++++++++++---------- > 3 files changed, 40 insertions(+), 13 deletions(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 19e81a99c58f..d7ea1c1175c2 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -5103,7 +5103,7 @@ static int __init svm_init(void) > * Common KVM initialization _must_ come last, after this, /dev/kvm is > * exposed to userspace! > */ > - r = kvm_init(&svm_init_ops, sizeof(struct vcpu_svm), > + r = kvm_init(NULL, sizeof(struct vcpu_svm), > __alignof__(struct vcpu_svm), THIS_MODULE); > if (r) > goto err_kvm_init; > diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c > index 654d81f781da..8deb1bd60c10 100644 > --- a/arch/x86/kvm/vmx/vmx.c > +++ b/arch/x86/kvm/vmx/vmx.c > @@ -8592,7 +8592,7 @@ static int __init vmx_init(void) > * Common KVM initialization _must_ come last, after this, /dev/kvm is > * exposed to userspace! > */ > - r = kvm_init(&vmx_init_ops, sizeof(struct vcpu_vmx), > + r = kvm_init(NULL, sizeof(struct vcpu_vmx), > __alignof__(struct vcpu_vmx), THIS_MODULE); > if (r) > goto err_kvm_init; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 66f16458aa97..3571bc968cf8 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -9277,10 +9277,36 @@ static inline void kvm_ops_update(struct kvm_x86_init_ops *ops) > kvm_pmu_ops_update(ops->pmu_ops); > } > > +struct kvm_cpu_compat_check { > + struct kvm_x86_init_ops *ops; > + int *ret; minor nitpick: just int ret. I don't see the necessity of the pointer. Anyway overall it looks good to me. Reviewed-by: Isaku Yamahata > +}; > + > +static int kvm_x86_check_processor_compatibility(struct kvm_x86_init_ops *ops) > +{ > + struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); > + > + WARN_ON(!irqs_disabled()); > + > + if (__cr4_reserved_bits(cpu_has, c) != > + __cr4_reserved_bits(cpu_has, &boot_cpu_data)) > + return -EIO; > + > + return ops->check_processor_compatibility(); > +} > + > +static void kvm_x86_check_cpu_compat(void *data) > +{ > + struct kvm_cpu_compat_check *c = data; > + > + *c->ret = kvm_x86_check_processor_compatibility(c->ops); > +} > + > static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > { > + struct kvm_cpu_compat_check c; > u64 host_pat; > - int r; > + int r, cpu; > > if (kvm_x86_ops.hardware_enable) { > pr_err("kvm: already loaded vendor module '%s'\n", kvm_x86_ops.name); > @@ -9360,6 +9386,14 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > if (r != 0) > goto out_mmu_exit; > > + c.ret = &r; > + c.ops = ops; > + for_each_online_cpu(cpu) { > + smp_call_function_single(cpu, kvm_x86_check_cpu_compat, &c, 1); > + if (r < 0) Here it can be "c.ret < 0". > + goto out_hardware_unsetup; > + } > + > /* > * Point of no return! DO NOT add error paths below this point unless > * absolutely necessary, as most operations from this point forward > @@ -9402,6 +9436,8 @@ static int __kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) > kvm_init_msr_list(); > return 0; > > +out_hardware_unsetup: > + ops->runtime_ops->hardware_unsetup(); > out_mmu_exit: > kvm_mmu_vendor_module_exit(); > out_free_percpu: > @@ -12037,16 +12073,7 @@ void kvm_arch_hardware_disable(void) > > int kvm_arch_check_processor_compat(void *opaque) > { > - struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); > - struct kvm_x86_init_ops *ops = opaque; > - > - WARN_ON(!irqs_disabled()); > - > - if (__cr4_reserved_bits(cpu_has, c) != > - __cr4_reserved_bits(cpu_has, &boot_cpu_data)) > - return -EIO; > - > - return ops->check_processor_compatibility(); > + return 0; > } > > bool kvm_vcpu_is_reset_bsp(struct kvm_vcpu *vcpu) > -- > 2.38.1.584.g0f3c55d4c2-goog > -- Isaku Yamahata _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv