From patchwork Thu Apr 25 23:39:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13644025 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 A97EF156647 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=1714088398; cv=none; b=oQCtivBD8qCxfedMRBGpQx6XKY3+sndTo6GCsHachOvwNGw69vWvJpXcP+SmMhyb20U4ronJqzD05aH/IdlwXgNFHw7sdC8o+NQA3UYddVTEe9CUjSQW2coQU1WEXC7qot6po+E4EowYtEG6lYfDV6o1vl4I+WUBocIHlyVmvaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088398; c=relaxed/simple; bh=he1+vvXlMfNlWLI6LWMQzLKYVZpZflwhW5mVPorCCEc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iueGBs+vhvc/gQIYbKukrcMXEUd/aeKqb38NCAGqaHbdyT2ti2rDyeTq3KJ5ZpUJQ6CJgHxATZTGk0UEh8eTph8YEgSl2pVVqcri4cVuB4rt9ZNKqnyzShbFSl3q0C/WWz63DFAxE4YqVBwvuc3GSah2igtqCBWOVPIj4hDe2IQ= 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-2a473ba0632so1923774a91.0 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=tprUcMOuvgZOc/hCSR9opT9LuogiNirOcmo2vLAMgUym1QercdqVRMsAhwvkDgApbc KWXt6Y2iAUl3BRAQn9O4uZnz/WYT9JZDVbNN+lcekKS14ptotIgqy0hBC3YZb14hIIky BQaSP5dbCoKgujYdnbN5IVID71CshuDBRb5EEto4TukPEVMOC1J5jwVPczCa+sn/U5AB v2D5f7s42uXfV8XbCkAof2yWQCxy0En/UwXd9fIDQnUUuXpwx0XjzdS1xzdl3lkD91eL tgkrpaqVgd5d3JbRWZPIyByAiW1AHBJKWJ1AaorQ0XGPMxJieyBcBjkjy9YoPa7C6ePF wgHg== X-Gm-Message-State: AOJu0YxAOsWiznZC0kVlTNImKmICVQAK5vrxbmtPLOz3P2mVUN8KHM5C Utajc+QZA+gM9ZMlbcnEIMrLXUORjrcWyUz9XXyrPu3N5cCEv6zBhqw9areCikbwAgngZhTeFHK 1Zw== 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: kvm@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 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 -#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 *callback); void cpu_emergency_disable_virtualization(void); From patchwork Thu Apr 25 23:39:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13644026 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 B285F156F38 for ; Thu, 25 Apr 2024 23:39:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088400; cv=none; b=A6PZE9Xr60JmONf1vlWA2M6gY14kNvEeofX9TTExrcUVkejKQvGq2Qm/e7OSVmq/7sQEzZkJcx/ZQT/skgBbtRB/OOO2Szqa/wS0eb5PayoNaFPmJzGeFF1auBU8RRvo+HqW333N9sdYpomVwh+ik0An8yWQLT7LMyhXQAdVYp8= 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.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="mbjGI7qx" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-5f0382f688fso1515359a12.0 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=Xamm4OqxytOj1ftMGXmtKK3Ki6xIpaZgWc4q49qI/njdF00PAXCJrsUJkIizW+EoHJ XzvmXQgOI6nmRxkZUMkOFzb56C7mhdtBt71WuwYeoiudKNP0paviw/1IiOPbu3UR/f/l lf636LDuw11pZNN5MvERG+ruzliXU8raRdVkl4bFdxP1evI1LtedvlefUcLUwnipbmu3 84rzJeseXql3JV77Wwtf7dy6QY0quuXwSl1u5sJSwOg1BS+vqXjq6m8mATYx1zPom1z9 bBZY1ZBu9nQsNb4ZQ6VNX7ROCBsd+hY+ST+um4uZkjF19zYzAgrbYPC83rJAfUTqZDz2 LaTg== X-Gm-Message-State: AOJu0YxICNLqJf1yYHgHu+o4mhy69bRWOCf7IAHReuYP4wQeU9ZDb1KS udYPqBS4dRy7BHNQSt3ILRrnTX6GAcBJdnl1sUX7mO4cIovN71NzZfS0BScX0tkBKiTyOXJgFxG mlQ== 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: kvm@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 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_host.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 #define __KVM_HAVE_ARCH_VCPU_DEBUGFS @@ -1606,6 +1607,8 @@ struct kvm_x86_ops { 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_vcpu *vcpu) static struct kvm_x86_ops svm_x86_ops __initdata = { .name = KBUILD_MODNAME, + .emergency_disable = svm_emergency_disable, .check_processor_compatibility = svm_check_processor_compat, .hardware_unsetup = svm_hardware_unsetup, @@ -5352,8 +5353,6 @@ static struct kvm_x86_init_ops svm_init_ops __initdata = { static void __svm_exit(void) { kvm_x86_vendor_exit(); - - cpu_emergency_unregister_virt_callback(svm_emergency_disable); } static int __init svm_init(void) @@ -5369,8 +5368,6 @@ static int __init svm_init(void) if (r) return r; - 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 = { .hardware_enable = vmx_hardware_enable, .hardware_disable = vmx_hardware_disable, + .emergency_disable = vmx_emergency_disable, + .has_emulated_msr = vmx_has_emulated_msr, .vm_size = 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; } -static void vmx_emergency_disable(void) +void vmx_emergency_disable(void) { int cpu = raw_smp_processor_id(); struct loaded_vmcs *v; @@ -8562,8 +8562,6 @@ static void __vmx_exit(void) { allow_smaller_maxphyaddr = false; - cpu_emergency_unregister_virt_callback(vmx_emergency_disable); - vmx_cleanup_l1d_flush(); } @@ -8610,8 +8608,6 @@ static int __init vmx_init(void) pi_init_cpu(cpu); } - cpu_emergency_register_virt_callback(vmx_emergency_disable); - vmx_check_vmcs12_offsets(); /* 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) kvm_ops_update(ops); + 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; out_unwind_ops: + cpu_emergency_unregister_virt_callback(kvm_x86_ops.emergency_disable); kvm_x86_ops.hardware_enable = 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 = NULL; mutex_unlock(&vendor_module_lock); From patchwork Thu Apr 25 23:39:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13644027 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 CD80315A4BE for ; Thu, 25 Apr 2024 23:40:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088402; cv=none; b=TkgKgjh2PgUMZwB69u5gfA8TkV45yBqhnZiSKHjKd1m/R9XIURqKfDIuQrJqiuhcvIHwlOvcFwOZa17e1mjYyzr0x6tF4ptIjpp0Sy3i9HkIAvgiXTJ+EZB7aTVs5lF56jIBM8r3zBGi/mzoXVz/l/EeT9aLWynR3cdNg73DxWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088402; c=relaxed/simple; bh=DLVkwBnctplZYeJO9Qab+V58q04REYulWvztmTUqov8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T2SvNK44OQsHCDeDe5xFZiUGjcPSpWOpJBjSCYwD0w8PDljcp7smsKJ6lTzvpYr09C9yMDlO7QeKS/Pg4ztpeU7YypteTjrLUm3K1/BANytTIaB6tJu37m/jrVGrChvCfwfflJDvXkgHJ3btInY616S/ftHxA90QZkOKw4t+Ilw= 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.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="ZcuOsJve" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de45dba157dso2614123276.1 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=t9gX/jXWXKydwALTFtLbv+TsKa/SEcxGepfN52r9NgLtw8L2db8v8PUoTBxUogKwDL hBYrJ7rj2pWPQzhCRv/rK+hWcbvTI6/sln9DEqjmZs5n9tZuDHy4oUS45EmwRJw8fRPV rAjP+a3LKuwirEo1R0QGj+feTHoKknfU3rTpxz3HJyON3baDsKzthoxEDQkYpSRVvb1u SfM8yLUtMkx3tM7RznSm6WlKfnjkxsf1cokEuG+VGBpUrcyhLEUVOnIK/LyqxyfYFM+F c8lHmUP/N0Vnd1EpUM9+0kp6bwBpZWkimW7d4QCQvoHj8M8QfHS1DQIkacEzGFgqO2R7 zF5A== X-Gm-Message-State: AOJu0YxRHJ2SPfvkDGJ+60gUjWQNxLIy+QkZrSKqj+YRfKgiTBz3c2sN iyILwKUW4qRGN5JZUnqwqAo5X+ME3/7M5CEZyk1IFIEV/GK01pVJQWsYVoLnKvsvw1qbZJwM02j W1Q== 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: kvm@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 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; -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; } -static void hardware_enable_nolock(void *failed) -{ - if (__hardware_enable_nolock()) - atomic_inc(failed); -} - static int kvm_online_cpu(unsigned int cpu) { - int ret = 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 = __hardware_enable_nolock(); - mutex_unlock(&kvm_lock); - return ret; + return hardware_enable_nolock(); } -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; @@ -5543,78 +5527,10 @@ static void hardware_disable_nolock(void *junk) 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; } -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 = 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 == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF || - system_state == 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 = 0; - - kvm_usage_count++; - if (kvm_usage_count == 1) { - on_each_cpu(hardware_enable_nolock, &failed, 1); - - if (atomic_read(&failed)) { - hardware_disable_all_nolock(); - r = -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(); - if (kvm_usage_count) - hardware_disable_nolock(NULL); + hardware_disable_nolock(NULL); return 0; } @@ -5656,8 +5571,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); - if (kvm_usage_count) - WARN_ON_ONCE(__hardware_enable_nolock()); + WARN_ON_ONCE(hardware_enable_nolock()); } static struct syscore_ops kvm_syscore_ops = { @@ -5665,6 +5579,54 @@ static struct syscore_ops kvm_syscore_ops = { .resume = kvm_resume, .shutdown = kvm_shutdown, }; + +static int hardware_enable_all(void) +{ + int r; + + guard(mutex)(&kvm_lock); + + if (kvm_usage_count++) + return 0; + + r = 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 == SYSTEM_HALT || system_state == SYSTEM_POWER_OFF || + system_state == 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; -#ifdef CONFIG_KVM_GENERIC_HARDWARE_ENABLING - r = 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 = __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 = -ENOMEM; - goto err_vcpu_cache; - } + if (!kvm_vcpu_cache) + return -ENOMEM; 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); From patchwork Thu Apr 25 23:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13644028 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.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 B063F15F400 for ; Thu, 25 Apr 2024 23:40:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714088404; cv=none; b=DrlzTa0YtAg9oO9sRdD3xrVxhKkbJzfxsiK1r1n5unZPfCS14mI56quWvOuKK7xQqiXbkWmTnVeRy7Qe2kNOif7y2/nWRSDTy1sg6/W+cqKM7Je+R0W3kIqCdruOQ2VmYGdeuJJzNArDZfdgsYa30cEVJg1IluernJSvd6mivY0= 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.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="kWb5CGXw" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-6081a08df8fso1751354a12.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=WGxnYfmyd+i5r1oCFm2AlCjHRbXZU+0unCNWo0G6bU5ScpgZpAxX/qPyDGnO1w07fK UCzX5TeYEw8Cr7+ud9KvG31JoEayU5RKDTAsYW1oFhvqZHydjoNoKOipKZlYQYIqtTNH 9luV51Sm9BLFsFfifm2F00hlbuEYelvJ6zqFcrJgfOYEOXVjocOxAA4I69UEXXSW3mZu LcMps6QQfe2BZaaiIJUqMVpt4FjhkOyubGP8bC+fECspd5ltmUqvj8xsbiO+Z/0dJWU7 APRllYO4O2HSW3NGoE2RrLQtIpwcnHl2ZvCmW/CLw7sfu+9EPyq8PDKIYY4WhO7c/t8j oDMw== X-Gm-Message-State: AOJu0YzgRIiEiPw0xGuFVQn+wUMaaObprH8Y0EvpZfJid/q6O1NI+L9v w3kpKVMSRRit1iC1OcHaG5DvhmjQGDNUppmaqikMHYyYdhDVDDFT4i4lhK+mgUFuz+EJhT3e118 wUw== 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: kvm@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 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, struct file *file) #define KVM_COMPAT(c) .compat_ioctl = kvm_no_compat_ioctl, \ .open = 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); static void kvm_io_bus_destroy(struct kvm_io_bus *bus); @@ -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; - r = hardware_enable_all(); + r = kvm_enable_virtualization(); if (r) goto out_err_no_disable; @@ -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); } @@ -5490,7 +5490,7 @@ EXPORT_SYMBOL_GPL(kvm_rebooting); static DEFINE_PER_CPU(bool, hardware_enabled); static int kvm_usage_count; -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(); } -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) static int kvm_offline_cpu(unsigned int cpu) { - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } @@ -5546,7 +5546,7 @@ static void kvm_shutdown(void) */ pr_info("kvm: exiting hardware virtualization\n"); kvm_rebooting = true; - on_each_cpu(hardware_disable_nolock, NULL, 1); + on_each_cpu(__kvm_disable_virtualization, NULL, 1); } static int kvm_suspend(void) @@ -5562,7 +5562,7 @@ static int kvm_suspend(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } @@ -5571,7 +5571,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_lock); lockdep_assert_irqs_disabled(); - WARN_ON_ONCE(hardware_enable_nolock()); + WARN_ON_ONCE(__kvm_enable_virtualization()); } static struct syscore_ops kvm_syscore_ops = { @@ -5580,7 +5580,7 @@ static struct syscore_ops kvm_syscore_ops = { .shutdown = kvm_shutdown, }; -static int hardware_enable_all(void) +static int kvm_enable_virtualization(void) { int r; @@ -5617,7 +5617,7 @@ static int hardware_enable_all(void) return 0; } -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { guard(mutex)(&kvm_lock); @@ -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; } -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { }