From nobody Sun May 19 15:05:10 2024 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A983715665E for ; Thu, 25 Apr 2024 23:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088399; cv=none; b=sTxzB3Z3YRx2Jyqx7fEl0na+B2z7UwfsRk7WwHE8P7Uf0mde9WJiv5SmcyodMan/scbuj6T2iQ3rdzCsX8Ow04kX3K3PXkYSvqTJdZ/6ssIAikaRFHUgpyG1DBL0z3SPhx767F6qvUYOAE8QGzEneRuZekoiTQVslwltHv1eQ94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088399; c=relaxed/simple; bh=he1+vvXlMfNlWLI6LWMQzLKYVZpZflwhW5mVPorCCEc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mcbiEnJ0zP5V+BEe/JFwKbhr6H9UaiMHeS+KsF9DkAqJ/hbvdxa8Fkw3qUU/Urr3zCstJTBiMBFEmeCbI0qF8Swy8snRhWbMo+SEtt/MD/rvqy9itJpxFppCxZPfZMh1cPtgLDlT3eDupVGSYPWnYQY8Y682TPOwCYnvQSxVozg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vGqvj1g2; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vGqvj1g2" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2a5c5e69461so1897458a91.2 for ; Thu, 25 Apr 2024 16:39:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714088396; x=1714693196; darn=vger.kernel.org; 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=7egpFUZiACQcekVxaNpuXSMxIq5MtX0L1qRkEu6b+Fk=; b=vGqvj1g28r0yi8omBoWVDZSYadn4NwBO94etafOSxsNDHlikzBhtPH8oUwDl/Dymf/ XlvV42jJdOpPfty+I0JTAWGMqQIfA4XdVt0NWsU+JT+cgbTWmQhiEkMFPbej3fHtqgat c6PQ6260cFlVDClHcxABDkNnIp11T6YcJAXVlz3lwIXkNZsEFtJWQd5hI35dfxlu2F3D mkhu0WtYquPSP3NbMOqU9H34TbD4PY3nDqizNNIezywfNfP8pkjJ2zkdlon+3VeaBui/ yo537PRpBPfMiISELMEir2l29g0BWX0/khppyEa7ajf2CDwn9iVC4PDZQQ5YGMANB2fn naqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714088396; x=1714693196; 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=7egpFUZiACQcekVxaNpuXSMxIq5MtX0L1qRkEu6b+Fk=; b=p0G3jGhcdGmd+Yrm2YyPVDbzLeSTsiWu/DKTLhW0g6ivFjm3wlrmD87kYEg5MbZbfb DsRSEscYM2y6TPLDGm5PI9BbvXlDG3ynEldDCgR5LZbPBfLUiHmDkmLEOqok+pOsjZKY /JN5UqwUTg/yReeqgiW/uDPwFKb2iaj17gl4fc2tQg5C8Xkxf940cm43CYh0ExG1gACL 0Ke69lv6RUjTgO1KYp250j2qGxSSo/bA94w0xQh9F16NQfKdaM0RM82nT2J93tJaXn1o G31xH4VXuXdegFi8nJgQJ60gm0KML6865KhWfj/s3P5r4whPcMqZGS4dv7NB7hIUA/1M YztA== X-Forwarded-Encrypted: i=1; AJvYcCV0fpfCD2BIAcSszJc71T3OMd0m4c8P9mCjyqT6yGQgysAIoP48FywQ9NwE7HRqbnx7kxN7lanW3DabXC7eGI8bjZjPQySpSYVPkgf/ X-Gm-Message-State: AOJu0YzcZb3/cnUJDFKvtt5pYw2j6+McYgLTMFs6xIwyByiJXHuQlmif 0a9zqKreCG/aXPUFTj26hxvonSWx3OTG8lvYc+f2iYBszQFE/3MfYRKdo7nHP2ercdR/a5ZXUNs TQg== X-Google-Smtp-Source: AGHT+IFpNydi+RGS1Jthdz8Ql+lk2sE6LKmNRcPrMcbtOYRSnA4O+O1tBGwgspj5RQ3J5mqE4DImMHqS6hQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:89:b0:2b0:25b6:6d44 with SMTP id bb9-20020a17090b008900b002b025b66d44mr52334pjb.4.1714088396018; Thu, 25 Apr 2024 16:39:56 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Apr 2024 16:39:48 -0700 In-Reply-To: <20240425233951.3344485-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425233951.3344485-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425233951.3344485-2-seanjc@google.com> Subject: [PATCH 1/4] x86/reboot: Unconditionally define cpu_emergency_virt_cb typedef From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define cpu_emergency_virt_cb even if the kernel is being built without KVM support so that KVM can reference the typedef in asm/kvm_host.h without needing yet more #ifdefs. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/reboot.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h index 6536873f8fc0..d0ef2a678d66 100644 --- a/arch/x86/include/asm/reboot.h +++ b/arch/x86/include/asm/reboot.h @@ -25,8 +25,8 @@ void __noreturn machine_real_restart(unsigned int type); #define MRR_BIOS 0 #define MRR_APM 1 =20 -#if IS_ENABLED(CONFIG_KVM_INTEL) || IS_ENABLED(CONFIG_KVM_AMD) typedef void (cpu_emergency_virt_cb)(void); +#if IS_ENABLED(CONFIG_KVM_INTEL) || IS_ENABLED(CONFIG_KVM_AMD) void cpu_emergency_register_virt_callback(cpu_emergency_virt_cb *callback); void cpu_emergency_unregister_virt_callback(cpu_emergency_virt_cb *callbac= k); void cpu_emergency_disable_virtualization(void); --=20 2.44.0.769.g3c40516874-goog From nobody Sun May 19 15:05:10 2024 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA93B156F3D for ; Thu, 25 Apr 2024 23:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088400; cv=none; b=G+LgP4YRsj4RIgqpR1u0O0V/qiRKix0MlktKYKf2FFkc2Zcw/JqdYyKF2J2/bK9+s9omcfw4iWka3GaAw+UCW8A+8rApqaHp14Ly1ayHTxOQ7miScc/yq2lOKMkAmaF6CKBtki5ciFgqLD2gJ7HAfb362Gds5F6dKKUC9ftHs/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088400; c=relaxed/simple; bh=u0lb4oEcZFhRwqHLflAlZi4AVPo3Csa5cR5x94rnGgU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jCZs6RC90rfYrSRYTCf0xKbTXqVABRRK+rpVN2j8Ymx4c7owaGODrJm9WMPNQiVSN5RR1gUnW14I9IAhD+aZ+gQS6POutv4b/ng9GOwyFgpIh/k6lqJyuNjL+6ChuXQtG7MUO54WvnmU08kpRHIYxjeo9rN8wzmXAvl5d/i+bFk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mbjGI7qx; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mbjGI7qx" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-5cec8bc5c66so1355238a12.1 for ; Thu, 25 Apr 2024 16:39:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714088398; x=1714693198; darn=vger.kernel.org; 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=IUxUfKFq5lce0AjD/oJDwXVLlkKMz5g8I16agotNVL4=; b=mbjGI7qx6U/Uo5P/vMKiZ40FneSsARjUICbK0shH+eS000q5s+aGFv7V/GpoLIhDsY aLUZQdH8ki8UeIudqKoQzlULAz5l1O4KSnYyu1oO2W0b4elsC6tfDLFno2fHHiwsI2Pl abTB1gD1rm5LBNkfcfGQY1U8F/5eyoEb9eHNhlOf3twiRJwctuh3iwXxn/jmCABgk/K5 c36rQJN7D8FnXqpuKiKf5qJ7WBcr+hsvGNHTPpUW2cvDZho/Ha8dtK4AKEo08jSACzis jijq4JcsIBLqG9e6NJnP5VcIDjaSXbj/z+urJ+beuheC2/7/HlYuNrKC9F0nb6K5uoCh J5HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714088398; x=1714693198; 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=IUxUfKFq5lce0AjD/oJDwXVLlkKMz5g8I16agotNVL4=; b=SBFZeZz7ZoVKJBEV9a/AvRBpAUUlhL5iSqYENmfhI6zi23q7zjIw5ApzA/XUyIvqFZ f+fUJQTZE9jR82tiJvH1jgZsVc8wr3ghlT/9Gmcf0exMtPlQ09R3wt4EywTB8VYl5QWl sRFCWnvfmgNyuO6llypxoZfmIs5v6t37MmmAu/ukQf4XwCmHpC8XdTzQIZHXeJaU6G2X YknVKXfUU9Vca4/5xr4rtZIn2M1VjXRKLd/yq5OeeuS6CjtnNdysbV5G9mX1K7i3eGRe qioHqQDm45mytS2C78bykheZ+fGpUlOCye37/XGT3tVR0dzxjzHTo4ugWjb7CeM+tePT 7BTQ== X-Forwarded-Encrypted: i=1; AJvYcCWsmpC9cI+8KU7h/cw50t6+ZAgVXkf1qBn1Y6Kk5flV/l5oWkPx2dOoQBsB72LAGMJwP8tZNzqWAoLlN6AJuaVoFDSbx6+d6e1IIXOB X-Gm-Message-State: AOJu0YzPM22J3BT2n8nhstuM3iPJcs/YIhXxHvWJHp/8S/8ju4yWDkOQ U1jUUuEY4umWGLbuWxuDUYUwAjVbbyk1N1SdlF0rkJgmNkOv5G21iNc1A7Fr7y5jZI4nMwSvSvk 3nA== X-Google-Smtp-Source: AGHT+IH+h5i/PU988dchPZRoVoVXuOPZqOT4+Rtk3PzisjubvPt97qk8f0RN68qdB9ceRIRH+7GBxqygKEs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:2c13:0:b0:5dc:af73:89e1 with SMTP id s19-20020a632c13000000b005dcaf7389e1mr3328pgs.10.1714088398066; Thu, 25 Apr 2024 16:39:58 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Apr 2024 16:39:49 -0700 In-Reply-To: <20240425233951.3344485-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425233951.3344485-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425233951.3344485-3-seanjc@google.com> Subject: [PATCH 2/4] KVM: x86: Register emergency virt callback in common code, via kvm_x86_ops From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move the registration of KVM's "disable virtualization in an emergency" callbacks into common KVM code, using a pointer in kvm_x86_ops to provide each vendor's callback. There is no reason to force vendor code to do the registration, and the callback should be installed when kvm_x86_ops themselves are ready, i.e. when it's possible for .hardware_enabled() to be invoked. E.g. TDX needs to do VMXON during module initialization, so registering the callback as part of early setup means one less thing to mess up. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 3 +++ arch/x86/kvm/svm/svm.c | 5 +---- arch/x86/kvm/vmx/main.c | 2 ++ arch/x86/kvm/vmx/vmx.c | 6 +----- arch/x86/kvm/vmx/x86_ops.h | 1 + arch/x86/kvm/x86.c | 5 +++++ 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 1d13e3cd1dc5..d64a51da150c 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -36,6 +36,7 @@ #include #include #include +#include =20 #define __KVM_HAVE_ARCH_VCPU_DEBUGFS =20 @@ -1606,6 +1607,8 @@ struct kvm_x86_ops { =20 int (*hardware_enable)(void); void (*hardware_disable)(void); + cpu_emergency_virt_cb *emergency_disable; + void (*hardware_unsetup)(void); bool (*has_emulated_msr)(struct kvm *kvm, u32 index); void (*vcpu_after_set_cpuid)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 0f3b59da0d4a..3b54243d0c22 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4919,6 +4919,7 @@ static void *svm_alloc_apic_backing_page(struct kvm_v= cpu *vcpu) static struct kvm_x86_ops svm_x86_ops __initdata =3D { .name =3D KBUILD_MODNAME, =20 + .emergency_disable =3D svm_emergency_disable, .check_processor_compatibility =3D svm_check_processor_compat, =20 .hardware_unsetup =3D svm_hardware_unsetup, @@ -5352,8 +5353,6 @@ static struct kvm_x86_init_ops svm_init_ops __initdat= a =3D { static void __svm_exit(void) { kvm_x86_vendor_exit(); - - cpu_emergency_unregister_virt_callback(svm_emergency_disable); } =20 static int __init svm_init(void) @@ -5369,8 +5368,6 @@ static int __init svm_init(void) if (r) return r; =20 - cpu_emergency_register_virt_callback(svm_emergency_disable); - /* * Common KVM initialization _must_ come last, after this, /dev/kvm is * exposed to userspace! diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 7c546ad3e4c9..3f423afc263b 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -24,6 +24,8 @@ struct kvm_x86_ops vt_x86_ops __initdata =3D { =20 .hardware_enable =3D vmx_hardware_enable, .hardware_disable =3D vmx_hardware_disable, + .emergency_disable =3D vmx_emergency_disable, + .has_emulated_msr =3D vmx_has_emulated_msr, =20 .vm_size =3D sizeof(struct kvm_vmx), diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index f10b5f8f364b..19bc62b60fac 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -753,7 +753,7 @@ static int kvm_cpu_vmxoff(void) return -EIO; } =20 -static void vmx_emergency_disable(void) +void vmx_emergency_disable(void) { int cpu =3D raw_smp_processor_id(); struct loaded_vmcs *v; @@ -8562,8 +8562,6 @@ static void __vmx_exit(void) { allow_smaller_maxphyaddr =3D false; =20 - cpu_emergency_unregister_virt_callback(vmx_emergency_disable); - vmx_cleanup_l1d_flush(); } =20 @@ -8610,8 +8608,6 @@ static int __init vmx_init(void) pi_init_cpu(cpu); } =20 - cpu_emergency_register_virt_callback(vmx_emergency_disable); - vmx_check_vmcs12_offsets(); =20 /* diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index 502704596c83..afddfe3747dd 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -15,6 +15,7 @@ void vmx_hardware_unsetup(void); int vmx_check_processor_compat(void); int vmx_hardware_enable(void); void vmx_hardware_disable(void); +void vmx_emergency_disable(void); int vmx_vm_init(struct kvm *kvm); void vmx_vm_destroy(struct kvm *kvm); int vmx_vcpu_precreate(struct kvm *kvm); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e9ef1fa4b90b..12e88aa2cca2 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -9797,6 +9797,8 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) =20 kvm_ops_update(ops); =20 + cpu_emergency_register_virt_callback(kvm_x86_ops.emergency_disable); + for_each_online_cpu(cpu) { smp_call_function_single(cpu, kvm_x86_check_cpu_compat, &r, 1); if (r < 0) @@ -9847,6 +9849,7 @@ int kvm_x86_vendor_init(struct kvm_x86_init_ops *ops) return 0; =20 out_unwind_ops: + cpu_emergency_unregister_virt_callback(kvm_x86_ops.emergency_disable); kvm_x86_ops.hardware_enable =3D NULL; static_call(kvm_x86_hardware_unsetup)(); out_mmu_exit: @@ -9887,6 +9890,8 @@ void kvm_x86_vendor_exit(void) static_key_deferred_flush(&kvm_xen_enabled); WARN_ON(static_branch_unlikely(&kvm_xen_enabled.key)); #endif + cpu_emergency_unregister_virt_callback(kvm_x86_ops.emergency_disable); + mutex_lock(&vendor_module_lock); kvm_x86_ops.hardware_enable =3D NULL; mutex_unlock(&vendor_module_lock); --=20 2.44.0.769.g3c40516874-goog From nobody Sun May 19 15:05:10 2024 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB89215AAA1 for ; Thu, 25 Apr 2024 23:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088403; cv=none; b=frwhBm8z7OzACIbjwYn0JVRM49F5MWxYp9zrUn0kR+1UOqd7C3e6XJUDiaI61IF2vYLuW2YXxWbRjUJKu3lxmIaORuZEzhuRiypFRhOUJfsYwO6kbkOw5wnVMjRRpk+yIFvuq7l9KeyKP800S1OeUNeeqKb+oKYPrVwxu1fpz7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088403; c=relaxed/simple; bh=DLVkwBnctplZYeJO9Qab+V58q04REYulWvztmTUqov8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=BJtBRe5VdPOYWoxFv/to2SP/mRxs0jhMePeDYZDFQYsEHNy8iLRnIdsLz8TS/H3zvrRNpkNNM8HMDm9ZhDVO2K7/4QHwOwN6NGHtjHZH5AytERfi4u/wDr/a3Ly4X515B6VtFY/SPp88nVeIl9/1fXShnrU+cUWtGNvMX825rz8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ZcuOsJve; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ZcuOsJve" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de59ff8af0bso1127552276.2 for ; Thu, 25 Apr 2024 16:40:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714088400; x=1714693200; darn=vger.kernel.org; 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=Sm/Nwd+keDoiSkXA1rIahABfNZCZE+Lf5pqQeKGPdBA=; b=ZcuOsJveV75fB1Zou3pkyUN36or78CgcQ7Wf8wbJVYbhUIUcZAiu9xzWBGho3cbXci bqfEuHzoPCU73X5dzsL7E7YH3dwz1GAxWnn+cOjXEca1etOX4WHkU1kmiyOi/kNRDMTc uB2nRbcGAPR7ABtOWwTb3wMiQs+UnwnAbxWhnLAMebYkeM+K42xhN8It0ebALZSEx6c6 azRdpvx2jBFa2tBtlGhJUw1E4Joa5y3CX0bKDrpS5c0+Mbw1tGG6upEhtG9PAqkdtaAy VY8vNwp4GxdshMdAbBjGLe5aLuXalf9NTKMk+/w2aPjC2zSOYSem+Ma7PAKWLQk3VaP8 WDAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714088400; x=1714693200; 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=Sm/Nwd+keDoiSkXA1rIahABfNZCZE+Lf5pqQeKGPdBA=; b=bfrib4eQxLk2ItFnJ5rTPuPYfxaM4U3m6BGCzSxxSYfoNPf8ipzHrjIHWC8Ko2Na6i hpPFxalb4D0W9eMX4M65XQ0HwhRMBfTbdWAJ6JCbEmIstda3Msyp4OnNX0xYbnbnKP9A j7R40GZiCBtkhoOLCF6n8UVlXEicpFYNSjITWoicFkY+2cx4Ds41Yq6VkFWcZAquoWa6 HAkb/wyCIc1o7e/zrlcy7bX8GFWb7+OBRM891vqpl3U4uRrrJ9b94laDgtsZN/5Hra7m s9EW24zxKZioHJGtVVDqvIw1MgDqOevDVIcpk77JmxliJ+ajiBhq75h12t5XrEyMOIuH CNjQ== X-Forwarded-Encrypted: i=1; AJvYcCXNhy7QqOdwsRLY3iAVBEjjLHvmx1s2/FPC8MnRscVwmCYFy7MgKqI5lnEK1S+SU2n16PaybXJzsIpH3Fgtatl7vWi9EWaPs6vP+TZw X-Gm-Message-State: AOJu0Yz0pI9w96RD3Es9BJ2HYXEelkJDhzMu80ZmoqBblFcy9gVUL4Jo LHeKVpd++eFTssI0xc6hbnDJVwV8GxfrUCKbtyilnqcT48Q90sbdtwB1Vvb28YA7YCnBG+b8cT7 OIQ== X-Google-Smtp-Source: AGHT+IHIvZeFy21VU3fyWm++MnV/Yc8tN9Aqs+7NCcUu4vlBSWU6oOWLy+cGUYar2HfcaZIONOO3XrHzrQw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:18cd:b0:dc6:b813:5813 with SMTP id ck13-20020a05690218cd00b00dc6b8135813mr126526ybb.9.1714088399909; Thu, 25 Apr 2024 16:39:59 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Apr 2024 16:39:50 -0700 In-Reply-To: <20240425233951.3344485-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425233951.3344485-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425233951.3344485-4-seanjc@google.com> Subject: [PATCH 3/4] KVM: Register cpuhp and syscore callbacks when enabling hardware From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Register KVM's cpuhp and syscore callback when enabling virtualization in hardware instead of registering the callbacks during initialization, and let the CPU up/down framework invoke the inner enable/disable functions. Registering the callbacks during initialization makes things more complex than they need to be, as KVM needs to be very careful about handling races between enabling CPUs being onlined/offlined and hardware being enabled/disabled. Intel TDX support will require KVM to enable virtualization during KVM initialization, i.e. will add another wrinkle to things, at which point sorting out the potential races with kvm_usage_count would become even more complex. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 170 +++++++++++++++----------------------------- 1 file changed, 56 insertions(+), 114 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 10dad093b7fb..ad1b5a9e86d4 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5490,7 +5490,7 @@ EXPORT_SYMBOL_GPL(kvm_rebooting); static DEFINE_PER_CPU(bool, hardware_enabled); static int kvm_usage_count; =20 -static int __hardware_enable_nolock(void) +static int hardware_enable_nolock(void) { if (__this_cpu_read(hardware_enabled)) return 0; @@ -5505,34 +5505,18 @@ static int __hardware_enable_nolock(void) return 0; } =20 -static void hardware_enable_nolock(void *failed) -{ - if (__hardware_enable_nolock()) - atomic_inc(failed); -} - static int kvm_online_cpu(unsigned int cpu) { - int ret =3D 0; - /* * Abort the CPU online process if hardware virtualization cannot * be enabled. Otherwise running VMs would encounter unrecoverable * errors when scheduled to this CPU. */ - mutex_lock(&kvm_lock); - if (kvm_usage_count) - ret =3D __hardware_enable_nolock(); - mutex_unlock(&kvm_lock); - return ret; + return hardware_enable_nolock(); } =20 -static void hardware_disable_nolock(void *junk) +static void hardware_disable_nolock(void *ign) { - /* - * Note, hardware_disable_all_nolock() tells all online CPUs to disable - * hardware, not just CPUs that successfully enabled hardware! - */ if (!__this_cpu_read(hardware_enabled)) return; =20 @@ -5543,78 +5527,10 @@ static void hardware_disable_nolock(void *junk) =20 static int kvm_offline_cpu(unsigned int cpu) { - mutex_lock(&kvm_lock); - if (kvm_usage_count) - hardware_disable_nolock(NULL); - mutex_unlock(&kvm_lock); + hardware_disable_nolock(NULL); return 0; } =20 -static void hardware_disable_all_nolock(void) -{ - BUG_ON(!kvm_usage_count); - - kvm_usage_count--; - if (!kvm_usage_count) - on_each_cpu(hardware_disable_nolock, NULL, 1); -} - -static void hardware_disable_all(void) -{ - cpus_read_lock(); - mutex_lock(&kvm_lock); - hardware_disable_all_nolock(); - mutex_unlock(&kvm_lock); - cpus_read_unlock(); -} - -static int hardware_enable_all(void) -{ - atomic_t failed =3D ATOMIC_INIT(0); - int r; - - /* - * Do not enable hardware virtualization if the system is going down. - * If userspace initiated a forced reboot, e.g. reboot -f, then it's - * possible for an in-flight KVM_CREATE_VM to trigger hardware enabling - * after kvm_reboot() is called. Note, this relies on system_state - * being set _before_ kvm_reboot(), which is why KVM uses a syscore ops - * hook instead of registering a dedicated reboot notifier (the latter - * runs before system_state is updated). - */ - if (system_state =3D=3D SYSTEM_HALT || system_state =3D=3D SYSTEM_POWER_O= FF || - system_state =3D=3D SYSTEM_RESTART) - return -EBUSY; - - /* - * When onlining a CPU, cpu_online_mask is set before kvm_online_cpu() - * is called, and so on_each_cpu() between them includes the CPU that - * is being onlined. As a result, hardware_enable_nolock() may get - * invoked before kvm_online_cpu(), which also enables hardware if the - * usage count is non-zero. Disable CPU hotplug to avoid attempting to - * enable hardware multiple times. - */ - cpus_read_lock(); - mutex_lock(&kvm_lock); - - r =3D 0; - - kvm_usage_count++; - if (kvm_usage_count =3D=3D 1) { - on_each_cpu(hardware_enable_nolock, &failed, 1); - - if (atomic_read(&failed)) { - hardware_disable_all_nolock(); - r =3D -EBUSY; - } - } - - mutex_unlock(&kvm_lock); - cpus_read_unlock(); - - return r; -} - static void kvm_shutdown(void) { /* @@ -5646,8 +5562,7 @@ static int kvm_suspend(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); =20 - if (kvm_usage_count) - hardware_disable_nolock(NULL); + hardware_disable_nolock(NULL); return 0; } =20 @@ -5656,8 +5571,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); =20 - if (kvm_usage_count) - WARN_ON_ONCE(__hardware_enable_nolock()); + WARN_ON_ONCE(hardware_enable_nolock()); } =20 static struct syscore_ops kvm_syscore_ops =3D { @@ -5665,6 +5579,54 @@ static struct syscore_ops kvm_syscore_ops =3D { .resume =3D kvm_resume, .shutdown =3D kvm_shutdown, }; + +static int hardware_enable_all(void) +{ + int r; + + guard(mutex)(&kvm_lock); + + if (kvm_usage_count++) + return 0; + + r =3D cpuhp_setup_state(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online", + kvm_online_cpu, kvm_offline_cpu); + if (r) + return r; + + register_syscore_ops(&kvm_syscore_ops); + + /* + * Undo virtualization enabling and bail if the system is going down. + * If userspace initiated a forced reboot, e.g. reboot -f, then it's + * possible for an in-flight operation to enable virtualization after + * syscore_shutdown() is called, i.e. without kvm_shutdown() being + * invoked. Note, this relies on system_state being set _before_ + * kvm_shutdown(), e.g. to ensure either kvm_shutdown() is invoked + * or this CPU observes the impending shutdown. Which is why KVM uses + * a syscore ops hook instead of registering a dedicated reboot + * notifier (the latter runs before system_state is updated). + */ + if (system_state =3D=3D SYSTEM_HALT || system_state =3D=3D SYSTEM_POWER_O= FF || + system_state =3D=3D SYSTEM_RESTART) { + unregister_syscore_ops(&kvm_syscore_ops); + cpuhp_remove_state(CPUHP_AP_KVM_ONLINE); + return -EBUSY; + } + + return 0; +} + +static void hardware_disable_all(void) +{ + guard(mutex)(&kvm_lock); + + if (--kvm_usage_count) + return; + + unregister_syscore_ops(&kvm_syscore_ops); + cpuhp_remove_state(CPUHP_AP_KVM_ONLINE); +} #else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */ static int hardware_enable_all(void) { @@ -6370,15 +6332,6 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align= , struct module *module) int r; int cpu; =20 -#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING - r =3D cpuhp_setup_state_nocalls(CPUHP_AP_KVM_ONLINE, "kvm/cpu:online", - kvm_online_cpu, kvm_offline_cpu); - if (r) - return r; - - register_syscore_ops(&kvm_syscore_ops); -#endif - /* A kmem cache lets us meet the alignment requirements of fx_save. */ if (!vcpu_align) vcpu_align =3D __alignof__(struct kvm_vcpu); @@ -6389,10 +6342,8 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align= , struct module *module) offsetofend(struct kvm_vcpu, stats_id) - offsetof(struct kvm_vcpu, arch), NULL); - if (!kvm_vcpu_cache) { - r =3D -ENOMEM; - goto err_vcpu_cache; - } + if (!kvm_vcpu_cache) + return -ENOMEM; =20 for_each_possible_cpu(cpu) { if (!alloc_cpumask_var_node(&per_cpu(cpu_kick_mask, cpu), @@ -6449,11 +6400,6 @@ int kvm_init(unsigned vcpu_size, unsigned vcpu_align= , struct module *module) for_each_possible_cpu(cpu) free_cpumask_var(per_cpu(cpu_kick_mask, cpu)); kmem_cache_destroy(kvm_vcpu_cache); -err_vcpu_cache: -#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING - unregister_syscore_ops(&kvm_syscore_ops); - cpuhp_remove_state_nocalls(CPUHP_AP_KVM_ONLINE); -#endif return r; } EXPORT_SYMBOL_GPL(kvm_init); @@ -6475,10 +6421,6 @@ void kvm_exit(void) kmem_cache_destroy(kvm_vcpu_cache); kvm_vfio_ops_exit(); kvm_async_pf_deinit(); -#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING - unregister_syscore_ops(&kvm_syscore_ops); - cpuhp_remove_state_nocalls(CPUHP_AP_KVM_ONLINE); -#endif kvm_irqfd_exit(); } EXPORT_SYMBOL_GPL(kvm_exit); --=20 2.44.0.769.g3c40516874-goog From nobody Sun May 19 15:05:10 2024 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A301A15F30F for ; Thu, 25 Apr 2024 23:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088404; cv=none; b=rNZthV1lsho65YgKhNmE1qurIzZHCcaSA9nUaz6Ngd/htgN+wB6Zb2MvFw2sDAogrTcIUwfxXX3b5DbOlS36R6H0eAoVRK1vrX49nu19Q0ZDJmbCZUgqXyLU/BQ43YiqUH1znc9BGIcfHlbjgxvDFonMlLk8e/kaR7+zghqv2Fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088404; c=relaxed/simple; bh=MJPzSo3K8o6iA/n7UkA1+bc7lne1qdZDGEpRTlZuZI8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=EYQwRD2or+24B1kkzfGwj+N8UEwwlh4izbTOICXH2X/ZAhk7rU8Lz1t7qgVLUwTPoQwwATqTJQhhnOJimgyL4OId5QCZM6TPlROSgWtd+gunPvpmTzAp84tdZq+uAaCbVMsWrP5XdGJqcuXOZ05/ZroEgNW4FgzV5k/j4glViu8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=kWb5CGXw; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kWb5CGXw" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-6081a08df8fso1751353a12.1 for ; Thu, 25 Apr 2024 16:40:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714088402; x=1714693202; darn=vger.kernel.org; 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=/NaaHWoathmI+8UuflB46ON2NyuL/ZRdqhokuCuaP+c=; b=kWb5CGXwcxHKV1ARYh6UbIfHiH7abNDR0NuP024bHAlszl+iefVnZk4q7nKLhbNY7u x86DpVFTUYqLvKBj+9FDelYE+Op67K29tAWYfC3Y/6WdbQQsganyBKoKl8u2wTQcvq4H JUGf5rf4aQjCt4k0bLhzf9F7TDFc1270QgrhKtFcKHBdExz8Rnvexc5ElhdSpZg1kkks A6YiikhtgRBTMVa9/TQyLe9VA4VHDQjY6oISjymKil/MymgT5FI0D5S/s8B9iCjc30jM Dw5w4aEphVfohyN5gifalK9G04YjeRlPyzm9mWX+vUayAlT5zYJikKaLaUtS2Y6TTqzY +HUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714088402; x=1714693202; 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=/NaaHWoathmI+8UuflB46ON2NyuL/ZRdqhokuCuaP+c=; b=eKxVktM3JX9inmTl8svwoY9pAKl6B4K4dlJqFxr5O1OlhzUtG9tLg7PYBbfb/BeiY2 igRfDQAqmCuLfN++G7Uxg5/ojL6wt9rxCn5OKhDkZJwMGkRY74m1hm/YL/fYKQv+T9iA ALr6d6KMhKDhdTocHf8gm7Y/tvZJTpF+8ueKFeU6y9xJjZjnLXS8P9Ekg6kBL9n6A5LC T2Fsuv9DUfyO7RPfzeKtimBDTqqAW9oS51eESVVIdfse9a6bvo/AkxFz+UQr1eAXgJ2E PX7U3PD+HJDsaor/cAOzbQIXYQmCni22UWh9oqoSaPHQATeSSAJB8UlE8ehzC16mOaON 19Cw== X-Forwarded-Encrypted: i=1; AJvYcCX7VSlw6sYqWGx+vuHyHOgRzqAXanVoRd1HzR4dbi9RxUbF+pYJgKAtbR334buEXtMSjmSyvfteSRtBrN9X0wyuzIqzI9wvGgng9wZq X-Gm-Message-State: AOJu0Yz4zKsp46DeGxstt8wkF9GTWzJFJKaYz/B0BB8uD4fxfpLFh78P f1bRMYNLvdN6T+4PE71D7Ga6FbacUnLX0nicaMrGOgRb2+XrQ6n0gcSLCeUSPJ4tlod3zNgR++7 9Uw== X-Google-Smtp-Source: AGHT+IFEk/4Fpza+8/ED6blAeYExygS554kH4VB6EPG3G987AZdrRXIKgQ/Bx3DMkpGtNN8vV2lMWQft4DQ= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:5b21:0:b0:5dc:6127:e8b6 with SMTP id p33-20020a635b21000000b005dc6127e8b6mr3641pgb.3.1714088401803; Thu, 25 Apr 2024 16:40:01 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Apr 2024 16:39:51 -0700 In-Reply-To: <20240425233951.3344485-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240425233951.3344485-1-seanjc@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Message-ID: <20240425233951.3344485-5-seanjc@google.com> Subject: [PATCH 4/4] KVM: Rename functions related to enabling virtualization hardware From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename the various functions that enable virtualization to prepare for upcoming changes, and to clean up artifacts of KVM's previous behavior, which required manually juggling locks around kvm_usage_count. Drop the "nolock" qualifier from per-CPU functions now that there are no "nolock" implementations of the "all" variants, i.e. now that calling a non-nolock function from a nolock function isn't confusing (unlike this sentence). Drop "all" from the outer helpers as they no longer manually iterate over all CPUs, and because it might not be obvious what "all" refers to. Instead, use double-underscores to communicate that the per-CPU functions are helpers to the outer APIs. Prepend "kvm" to all functions to prepare for exposing the outermost enable/disable APIs to external users (Intel's TDX needs to enable virtualization during KVM initialization). Lastly, use "virtualization" instead of "hardware", because while the functions do enable virtualization in hardware, there are a _lot_ of things that KVM enables in hardware. E.g. calling kvm_hardware_enable() or kvm_hardware_enable_all() from TDX code is less intuitive than kvm_enable_virtualization(). Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ad1b5a9e86d4..7579bda0e310 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -139,8 +139,8 @@ static int kvm_no_compat_open(struct inode *inode, stru= ct file *file) #define KVM_COMPAT(c) .compat_ioctl =3D kvm_no_compat_ioctl, \ .open =3D kvm_no_compat_open #endif -static int hardware_enable_all(void); -static void hardware_disable_all(void); +static int kvm_enable_virtualization(void); +static void kvm_disable_virtualization(void); =20 static void kvm_io_bus_destroy(struct kvm_io_bus *bus); =20 @@ -1213,7 +1213,7 @@ static struct kvm *kvm_create_vm(unsigned long type, = const char *fdname) if (r) goto out_err_no_arch_destroy_vm; =20 - r =3D hardware_enable_all(); + r =3D kvm_enable_virtualization(); if (r) goto out_err_no_disable; =20 @@ -1256,7 +1256,7 @@ static struct kvm *kvm_create_vm(unsigned long type, = const char *fdname) mmu_notifier_unregister(&kvm->mmu_notifier, current->mm); #endif out_err_no_mmu_notifier: - hardware_disable_all(); + kvm_disable_virtualization(); out_err_no_disable: kvm_arch_destroy_vm(kvm); out_err_no_arch_destroy_vm: @@ -1345,7 +1345,7 @@ static void kvm_destroy_vm(struct kvm *kvm) #endif kvm_arch_free_vm(kvm); preempt_notifier_dec(); - hardware_disable_all(); + kvm_disable_virtualization(); mmdrop(mm); } =20 @@ -5490,7 +5490,7 @@ EXPORT_SYMBOL_GPL(kvm_rebooting); static DEFINE_PER_CPU(bool, hardware_enabled); static int kvm_usage_count; =20 -static int hardware_enable_nolock(void) +static int __kvm_enable_virtualization(void) { if (__this_cpu_read(hardware_enabled)) return 0; @@ -5512,10 +5512,10 @@ static int kvm_online_cpu(unsigned int cpu) * be enabled. Otherwise running VMs would encounter unrecoverable * errors when scheduled to this CPU. */ - return hardware_enable_nolock(); + return __kvm_enable_virtualization(); } =20 -static void hardware_disable_nolock(void *ign) +static void __kvm_disable_virtualization(void *ign) { if (!__this_cpu_read(hardware_enabled)) return; @@ -5527,7 +5527,7 @@ static void hardware_disable_nolock(void *ign) =20 static int kvm_offline_cpu(unsigned int cpu) { - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } =20 @@ -5546,7 +5546,7 @@ static void kvm_shutdown(void) */ pr_info("kvm: exiting hardware virtualization\n"); kvm_rebooting =3D true; - on_each_cpu(hardware_disable_nolock, NULL, 1); + on_each_cpu(__kvm_disable_virtualization, NULL, 1); } =20 static int kvm_suspend(void) @@ -5562,7 +5562,7 @@ static int kvm_suspend(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); =20 - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } =20 @@ -5571,7 +5571,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); =20 - WARN_ON_ONCE(hardware_enable_nolock()); + WARN_ON_ONCE(__kvm_enable_virtualization()); } =20 static struct syscore_ops kvm_syscore_ops =3D { @@ -5580,7 +5580,7 @@ static struct syscore_ops kvm_syscore_ops =3D { .shutdown =3D kvm_shutdown, }; =20 -static int hardware_enable_all(void) +static int kvm_enable_virtualization(void) { int r; =20 @@ -5617,7 +5617,7 @@ static int hardware_enable_all(void) return 0; } =20 -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { guard(mutex)(&kvm_lock); =20 @@ -5628,12 +5628,12 @@ static void hardware_disable_all(void) cpuhp_remove_state(CPUHP_AP_KVM_ONLINE); } #else /* CONFIG_KVM_GENERIC_HARDWARE_ENABLING */ -static int hardware_enable_all(void) +static int kvm_enable_virtualization(void) { return 0; } =20 -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { =20 } --=20 2.44.0.769.g3c40516874-goog