Message ID | 20221130230934.1014142-22-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1199413wrr; Wed, 30 Nov 2022 15:13:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf5RvYxN6OzhnHwjKqAdIRrHJGNmRYgHlWhjoKtRjgm9HgAGIjEfWrkKo30hF4qefWIaRgna X-Received: by 2002:a17:90a:8402:b0:218:7744:5e9 with SMTP id j2-20020a17090a840200b00218774405e9mr68458218pjn.44.1669850025388; Wed, 30 Nov 2022 15:13:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669850025; cv=none; d=google.com; s=arc-20160816; b=I5ijhytL5WeS/ypk37J/giDwGXsDOj1Vmk4jv6TXkUFSukcPQAruMIZ2LAp1hITX0z PrsTszrejdpRPQLZm0HVnoJmxKgYpVh8zB+qkVRUvOIrFbERrKcjHtezlM/VMW1ir8GP MvsvvIrYDMx86NCjJN3tcd1rMNVdRnVZpGTvXv0+u5sfISSm/LUJUPJZwwbISJJSsH89 EBGv4USG+/Ah4n5QoBMEDKe6YF6KX7CG0C3jXgS53U/1Q2zzeoCNRq1aaqA+KoCbpfjG rRrmdExnpeSCurNKL1h2CN8g6mxy2o1jNDTDS0v3AzAjnye2N+DdRtORiWQoRSmOBLlo Ixgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=grdSlJzFo0VwdV8xgzvuVpRwKnA9GO3Mob4PH+ot8/0=; b=lBt47ubQ31ZVuq4/k0Apd2xF7mEm+xsq2mVNQp3ah437Bh44qWKvjq/Z/3yR3ij+yo YaJkQ3cjxD0/gtgjvEM4dhUPTOVq2UaHoPi0g3dj7Krgc/5ypwLBdwA045mi5wYScR4e BkbSoPpJ8oEh/mPzJfxyYd/q4PaqysU+X6xcgap40gJ09HDeGDECKoUF+swU4OIugyb2 6JlHY90BVZuNwoC56MXK7qeT5jbgWNdGzhoxBb1o3XpnQzeAToGrHa9/BxBjTGMGZuIs EyWKkx2Gk8kpbGpYQts7+MJcwTS3VIIt91oqg6WOnR8SebufHfxPNknJ2JZ7JjqTmicR XkTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CQKSwij2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u15-20020a170902e80f00b00186e8526793si2781961plg.143.2022.11.30.15.13.32; Wed, 30 Nov 2022 15:13:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CQKSwij2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229819AbiK3XNQ (ORCPT <rfc822;heyuhang3455@gmail.com> + 99 others); Wed, 30 Nov 2022 18:13:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229787AbiK3XMW (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 30 Nov 2022 18:12:22 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91A459B799 for <linux-kernel@vger.kernel.org>; Wed, 30 Nov 2022 15:10:30 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id h3-20020a170902f54300b00189af47afd0so1594599plf.9 for <linux-kernel@vger.kernel.org>; Wed, 30 Nov 2022 15:10:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=grdSlJzFo0VwdV8xgzvuVpRwKnA9GO3Mob4PH+ot8/0=; b=CQKSwij2dM5sxTN5vEM9Pg0UGQR7vXxLholFOCIYMDxZ1/3rA7vH+RqFmN1n0beWlD 7+BAU4/MoU1Z2zohEeDLQA2mrNFcLMI1vaNT8JUT+3n3Smxr3wpQu7rVUMeYIUjzYrKM QQRXU+fmSvdsXsp/lH1ncccopWZ+njKFlSsnkmBo5RgV0L2uInmLnHD4wZGB2dqPvFNW AFZHsbz5az7ZAwj41de9s/UvOppce1LN8jHb5JWdYWBnJ4FReLvafLy5jclWK6UngF05 cPIBeGpzAB3DL/mtUhAd3V5apiG8/mbBEcTlCsb8iWOJpXlQdaq+hFXcxIhaHoaH5jmv rjIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=grdSlJzFo0VwdV8xgzvuVpRwKnA9GO3Mob4PH+ot8/0=; b=c79i1Xn/DqjM4bQrwrcKt4cXIIWOhD505L9ZoUUIWtp6HOeroEEOD1+Yoj2UXhPH4O DYkCjWrfn1mxNOzFM916iLxWeWmHd+mIfpUleOsUiMmy5iP3Uz/89sTYwG4rUpoSIWEM JeTyJv5Pujqp2WlKJXiXK/EyW4Tmt9h9RsjD2+gH2JISkJ/YHkyPctcLACDm0Iz++Bjj olC9h7hMn3aCjMfuTN+smfjdzzoRODm9I6bovCai+JgmkorV+t5PjNmxQeOUDwALAeRN xZY5gt6L8hX/geIJV5t1eB7jpFSIbDDsi4ye2M/w7n2GY0qhLk1NwKC8VuGNmo0Vg1u/ DrmQ== X-Gm-Message-State: ANoB5plN7zbG9cX7HY6/i1ZLKm2GZTuOwQxTutqmG5lYH1Z2m7glgBm4 kRLYLyEgHDUdnSN+YEPFkc2A1lyYuG0= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:648a:0:b0:572:76dd:3756 with SMTP id y132-20020a62648a000000b0057276dd3756mr45058073pfb.9.1669849813287; Wed, 30 Nov 2022 15:10:13 -0800 (PST) Reply-To: Sean Christopherson <seanjc@google.com> Date: Wed, 30 Nov 2022 23:09:05 +0000 In-Reply-To: <20221130230934.1014142-1-seanjc@google.com> Mime-Version: 1.0 References: <20221130230934.1014142-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221130230934.1014142-22-seanjc@google.com> Subject: [PATCH v2 21/50] KVM: MIPS: Hardcode callbacks to hardware virtualization extensions From: Sean Christopherson <seanjc@google.com> To: Paolo Bonzini <pbonzini@redhat.com>, Marc Zyngier <maz@kernel.org>, Huacai Chen <chenhuacai@kernel.org>, Aleksandar Markovic <aleksandar.qemu.devel@gmail.com>, Anup Patel <anup@brainfault.org>, Paul Walmsley <paul.walmsley@sifive.com>, Palmer Dabbelt <palmer@dabbelt.com>, Albert Ou <aou@eecs.berkeley.edu>, Christian Borntraeger <borntraeger@linux.ibm.com>, Janosch Frank <frankja@linux.ibm.com>, Claudio Imbrenda <imbrenda@linux.ibm.com>, Matthew Rosato <mjrosato@linux.ibm.com>, Eric Farman <farman@linux.ibm.com>, Sean Christopherson <seanjc@google.com>, Vitaly Kuznetsov <vkuznets@redhat.com>, David Woodhouse <dwmw2@infradead.org>, Paul Durrant <paul@xen.org> Cc: James Morse <james.morse@arm.com>, Alexandru Elisei <alexandru.elisei@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Oliver Upton <oliver.upton@linux.dev>, Atish Patra <atishp@atishpatra.org>, David Hildenbrand <david@redhat.com>, 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 <yuan.yao@intel.com>, Cornelia Huck <cohuck@redhat.com>, Isaku Yamahata <isaku.yamahata@intel.com>, " =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= " <philmd@linaro.org>, Fabiano Rosas <farosas@linux.ibm.com>, Michael Ellerman <mpe@ellerman.id.au>, Kai Huang <kai.huang@intel.com>, Chao Gao <chao.gao@intel.com>, Thomas Gleixner <tglx@linutronix.de> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750964659875622047?= X-GMAIL-MSGID: =?utf-8?q?1750964659875622047?= |
Series |
KVM: Rework kvm_init() and hardware enabling
|
|
Commit Message
Sean Christopherson
Nov. 30, 2022, 11:09 p.m. UTC
Now that KVM no longer supports trap-and-emulate (see commit 45c7e8af4a5e
"MIPS: Remove KVM_TE support"), hardcode the MIPS callbacks to the
virtualization callbacks.
Harcoding the callbacks eliminates the technically-unnecessary check on
non-NULL kvm_mips_callbacks in kvm_arch_init(). MIPS has never supported
multiple in-tree modules, i.e. barring an out-of-tree module, where
copying and renaming kvm.ko counts as "out-of-tree", KVM could never
encounter a non-NULL set of callbacks during module init.
The callback check is also subtly broken, as it is not thread safe,
i.e. if there were multiple modules, loading both concurrently would
create a race between checking and setting kvm_mips_callbacks.
Given that out-of-tree shenanigans are not the kernel's responsibility,
hardcode the callbacks to simplify the code.
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/mips/include/asm/kvm_host.h | 2 +-
arch/mips/kvm/Makefile | 2 +-
arch/mips/kvm/callback.c | 14 --------------
arch/mips/kvm/mips.c | 9 ++-------
arch/mips/kvm/vz.c | 7 ++++---
5 files changed, 8 insertions(+), 26 deletions(-)
delete mode 100644 arch/mips/kvm/callback.c
Comments
On 1/12/22 00:09, Sean Christopherson wrote: > Now that KVM no longer supports trap-and-emulate (see commit 45c7e8af4a5e > "MIPS: Remove KVM_TE support"), hardcode the MIPS callbacks to the > virtualization callbacks. > > Harcoding the callbacks eliminates the technically-unnecessary check on > non-NULL kvm_mips_callbacks in kvm_arch_init(). MIPS has never supported > multiple in-tree modules, i.e. barring an out-of-tree module, where > copying and renaming kvm.ko counts as "out-of-tree", KVM could never > encounter a non-NULL set of callbacks during module init. > > The callback check is also subtly broken, as it is not thread safe, > i.e. if there were multiple modules, loading both concurrently would > create a race between checking and setting kvm_mips_callbacks. > > Given that out-of-tree shenanigans are not the kernel's responsibility, > hardcode the callbacks to simplify the code. > > Signed-off-by: Sean Christopherson <seanjc@google.com> > --- > arch/mips/include/asm/kvm_host.h | 2 +- > arch/mips/kvm/Makefile | 2 +- > arch/mips/kvm/callback.c | 14 -------------- > arch/mips/kvm/mips.c | 9 ++------- > arch/mips/kvm/vz.c | 7 ++++--- > 5 files changed, 8 insertions(+), 26 deletions(-) > delete mode 100644 arch/mips/kvm/callback.c > > diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h > index 28f0ba97db71..2803c9c21ef9 100644 > --- a/arch/mips/include/asm/kvm_host.h > +++ b/arch/mips/include/asm/kvm_host.h > @@ -758,7 +758,7 @@ struct kvm_mips_callbacks { > void (*vcpu_reenter)(struct kvm_vcpu *vcpu); > }; > extern struct kvm_mips_callbacks *kvm_mips_callbacks; IIUC we could even constify this pointer. Anyway, Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> > diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c > index af29490d9740..f0a6c245d1ff 100644 > --- a/arch/mips/kvm/mips.c > +++ b/arch/mips/kvm/mips.c > @@ -1012,17 +1012,12 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) > > int kvm_arch_init(void *opaque) > { > - if (kvm_mips_callbacks) { > - kvm_err("kvm: module already exists\n"); > - return -EEXIST; > - } > - > - return kvm_mips_emulation_init(&kvm_mips_callbacks); > + return kvm_mips_emulation_init(); > } > > void kvm_arch_exit(void) > { > - kvm_mips_callbacks = NULL; > + > } > > int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, > diff --git a/arch/mips/kvm/vz.c b/arch/mips/kvm/vz.c > index c706f5890a05..dafab003ea0d 100644 > --- a/arch/mips/kvm/vz.c > +++ b/arch/mips/kvm/vz.c > @@ -3304,7 +3304,10 @@ static struct kvm_mips_callbacks kvm_vz_callbacks = { > .vcpu_reenter = kvm_vz_vcpu_reenter, > }; > > -int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks) > +/* FIXME: Get rid of the callbacks now that trap-and-emulate is gone. */ > +struct kvm_mips_callbacks *kvm_mips_callbacks = &kvm_vz_callbacks;
On Thu, Dec 01, 2022, Philippe Mathieu-Daudé wrote: > On 1/12/22 00:09, Sean Christopherson wrote: > > Now that KVM no longer supports trap-and-emulate (see commit 45c7e8af4a5e > > "MIPS: Remove KVM_TE support"), hardcode the MIPS callbacks to the > > virtualization callbacks. > > > > Harcoding the callbacks eliminates the technically-unnecessary check on > > non-NULL kvm_mips_callbacks in kvm_arch_init(). MIPS has never supported > > multiple in-tree modules, i.e. barring an out-of-tree module, where > > copying and renaming kvm.ko counts as "out-of-tree", KVM could never > > encounter a non-NULL set of callbacks during module init. > > > > The callback check is also subtly broken, as it is not thread safe, > > i.e. if there were multiple modules, loading both concurrently would > > create a race between checking and setting kvm_mips_callbacks. > > > > Given that out-of-tree shenanigans are not the kernel's responsibility, > > hardcode the callbacks to simplify the code. > > > > Signed-off-by: Sean Christopherson <seanjc@google.com> > > --- > > arch/mips/include/asm/kvm_host.h | 2 +- > > arch/mips/kvm/Makefile | 2 +- > > arch/mips/kvm/callback.c | 14 -------------- > > arch/mips/kvm/mips.c | 9 ++------- > > arch/mips/kvm/vz.c | 7 ++++--- > > 5 files changed, 8 insertions(+), 26 deletions(-) > > delete mode 100644 arch/mips/kvm/callback.c > > > > diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h > > index 28f0ba97db71..2803c9c21ef9 100644 > > --- a/arch/mips/include/asm/kvm_host.h > > +++ b/arch/mips/include/asm/kvm_host.h > > @@ -758,7 +758,7 @@ struct kvm_mips_callbacks { > > void (*vcpu_reenter)(struct kvm_vcpu *vcpu); > > }; > > extern struct kvm_mips_callbacks *kvm_mips_callbacks; > > IIUC we could even constify this pointer. Good point. Protecting the pointer itself is a bit gross, but it is a nice stopgap until the callbacks are gone. I'll fold this in. Thanks! extern const struct kvm_mips_callbacks * const kvm_mips_callbacks;
diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h index 28f0ba97db71..2803c9c21ef9 100644 --- a/arch/mips/include/asm/kvm_host.h +++ b/arch/mips/include/asm/kvm_host.h @@ -758,7 +758,7 @@ struct kvm_mips_callbacks { void (*vcpu_reenter)(struct kvm_vcpu *vcpu); }; extern struct kvm_mips_callbacks *kvm_mips_callbacks; -int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks); +int kvm_mips_emulation_init(void); /* Debug: dump vcpu state */ int kvm_arch_vcpu_dump_regs(struct kvm_vcpu *vcpu); diff --git a/arch/mips/kvm/Makefile b/arch/mips/kvm/Makefile index 21ff75bcdbc4..805aeea2166e 100644 --- a/arch/mips/kvm/Makefile +++ b/arch/mips/kvm/Makefile @@ -17,4 +17,4 @@ kvm-$(CONFIG_CPU_LOONGSON64) += loongson_ipi.o kvm-y += vz.o obj-$(CONFIG_KVM) += kvm.o -obj-y += callback.o tlb.o +obj-y += tlb.o diff --git a/arch/mips/kvm/callback.c b/arch/mips/kvm/callback.c deleted file mode 100644 index d88aa2173fb0..000000000000 --- a/arch/mips/kvm/callback.c +++ /dev/null @@ -1,14 +0,0 @@ -/* - * This file is subject to the terms and conditions of the GNU General Public - * License. See the file "COPYING" in the main directory of this archive - * for more details. - * - * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved. - * Authors: Yann Le Du <ledu@kymasys.com> - */ - -#include <linux/export.h> -#include <linux/kvm_host.h> - -struct kvm_mips_callbacks *kvm_mips_callbacks; -EXPORT_SYMBOL_GPL(kvm_mips_callbacks); diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c index af29490d9740..f0a6c245d1ff 100644 --- a/arch/mips/kvm/mips.c +++ b/arch/mips/kvm/mips.c @@ -1012,17 +1012,12 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) int kvm_arch_init(void *opaque) { - if (kvm_mips_callbacks) { - kvm_err("kvm: module already exists\n"); - return -EEXIST; - } - - return kvm_mips_emulation_init(&kvm_mips_callbacks); + return kvm_mips_emulation_init(); } void kvm_arch_exit(void) { - kvm_mips_callbacks = NULL; + } int kvm_arch_vcpu_ioctl_get_sregs(struct kvm_vcpu *vcpu, diff --git a/arch/mips/kvm/vz.c b/arch/mips/kvm/vz.c index c706f5890a05..dafab003ea0d 100644 --- a/arch/mips/kvm/vz.c +++ b/arch/mips/kvm/vz.c @@ -3304,7 +3304,10 @@ static struct kvm_mips_callbacks kvm_vz_callbacks = { .vcpu_reenter = kvm_vz_vcpu_reenter, }; -int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks) +/* FIXME: Get rid of the callbacks now that trap-and-emulate is gone. */ +struct kvm_mips_callbacks *kvm_mips_callbacks = &kvm_vz_callbacks; + +int kvm_mips_emulation_init(void) { if (!cpu_has_vz) return -ENODEV; @@ -3318,7 +3321,5 @@ int kvm_mips_emulation_init(struct kvm_mips_callbacks **install_callbacks) return -ENODEV; pr_info("Starting KVM with MIPS VZ extensions\n"); - - *install_callbacks = &kvm_vz_callbacks; return 0; }