From nobody Mon Feb 9 04:14:36 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 76B83142624 for ; Fri, 30 Aug 2024 04:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724992573; cv=none; b=uLBaOzeLAqMz6j9HVTv3ACZHPb4+GByRE+2xX5IEcBfKm/WSNwNQc1deiJuEGAW1pIxtiqtMrHkvstKV1oJVRy/4L2choB3bJCXD+o0+0UTSyxK2/knwr317JdVsWEOerJuAsudOYtNe8pA2J6jsVfUp2wFdWodsLlrhefKYuEI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724992573; c=relaxed/simple; bh=SkdkZeFX/OYBPHicii+69oTq+aUN0l4hd2UZEocYL2Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=M8h99RS0Simtd1TaK3GMrG2WNhfTQ6F/rWCp3sPiUZ2tre1AOCZuR5CoMcVBYB28TGbvfpHkEa5pN1/V4b39IY50jlCyMQFQrguG0LAqGsvApO0vNk/ADs0qCWkMWIY2M02eHx36DZ16JP8cwx3G913cA4NF544S4Vf6divodpc= 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=gjHGMGaE; arc=none smtp.client-ip=209.85.214.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="gjHGMGaE" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-201ee593114so20429825ad.1 for ; Thu, 29 Aug 2024 21:36:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1724992571; x=1725597371; 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=9rj6vLr2Zw9u+tL14LjoFTcNuQx6nMKbwDhD6S7zy4M=; b=gjHGMGaEJVOzp+sHQ3KlnIlP4tCDlLAJQTb24L9c9knkyTEGa6dGtgdA6iK/RnygMA QmJDfXFmuK5BYczWLtWBddhLXFAQnoAtAjKmDPOTgiwZYX4PpNi+IAHCdYq2B0bt24cX YGYaGV6+c8NE8kqh/v5GeSk4g9oAwNz4lN60M8spI7H/S3FTlKpERuApBXXAPIoxQgMz Wkx3G8BOKP3EiNOJ7mmCYbnqSLrDn9xH0GEmMmiZhtpRlNSpZbyNvyoZJbJtCE6XVcoW Ljj327YKt6XHkVYxOmZ+dQOCCbYmYnpfohkPulWwyooiBBR8K90AKJBvjYxZf+NiidWE 9Y3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724992571; x=1725597371; 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=9rj6vLr2Zw9u+tL14LjoFTcNuQx6nMKbwDhD6S7zy4M=; b=KVxEOsr4Kxdhv579EES6j+3iGfffQx1TNH6tp3K4i45FU6EywZjcJN7WkkxCizQ05C /9JSGDQvMUSw2llTahP8nj7X6AQLc7ZBQx1lD19u2LCqkW93UY6LrRQ81jmkWQVT2Yz4 1+HioBJwZ1Td/EU2a8OR1MIiQiDmmLb1KfQZybFPwC5jOgK0Wv5PPu1kM0IfKil0mV94 NwgqGtwLC88XFhQUXcyOV5Co2hz5kgysMDPT7d65cxIph7iyACqzbP5ngcYyE7hkz9a4 0fotktYRDRhiCYc9qiz0UvU2Y8GPMVkHm7qlESboS8dYuKYpwoB0tY8G12KVQIbwsSLo uCPw== X-Forwarded-Encrypted: i=1; AJvYcCW6DZZuC8gaw9ubV/t2t1uO0i80ucB7Y5L51z9M0c/7DzLUOXe3EKr6uJ/Zx3dw6aPRX9F2Pp5sQTl9YzY=@vger.kernel.org X-Gm-Message-State: AOJu0YybLdsAtQU1ldLjlwS/KcuF9qJ+esGbpOOzxHetcHbrMBfh8Kw5 5csoHY9bT6fb6NnYTsCg2S65BeLXB3LXbKBKdU+5z9N78ZA3HwzYXnqDJlbQ5vrQ4ZeV01qCx9Q LlQ== X-Google-Smtp-Source: AGHT+IFzNLMOWxStSOb6dz4OqO52HXYFy1OXZpfuDNQs7ORrcRcLluFbTSNdD7idfuIi2MeqpuxkFW/WSPs= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:4303:b0:1f9:e5e4:494b with SMTP id d9443c01a7336-2050e9aaf54mr110245ad.2.1724992570417; Thu, 29 Aug 2024 21:36:10 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 29 Aug 2024 21:35:53 -0700 In-Reply-To: <20240830043600.127750-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: <20240830043600.127750-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog Message-ID: <20240830043600.127750-4-seanjc@google.com> Subject: [PATCH v4 03/10] KVM: Rename symbols related to enabling virtualization hardware From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Chao Gao , Kai Huang , Farrah Chen Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename the various functions (and a variable) 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. In lieu of the above qualifiers, append "_cpu" to the end of the functions that are per-CPU helpers for the outer APIs. Opportunistically prepend "kvm" to all functions to help make it clear that they are KVM helpers, but mostly because there's no reason not to. 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. Defer renaming the arch hooks to future patches, purely to reduce the amount of churn in a single commit. Reviewed-by: Chao Gao Reviewed-by: Kai Huang Acked-by: Kai Huang Tested-by: Farrah Chen Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a5826e16a106..fbdd2e46e65b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -136,8 +136,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 @@ -1220,7 +1220,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 @@ -1263,7 +1263,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: @@ -1360,7 +1360,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 @@ -5575,13 +5575,13 @@ static struct miscdevice kvm_dev =3D { __visible bool kvm_rebooting; EXPORT_SYMBOL_GPL(kvm_rebooting); =20 -static DEFINE_PER_CPU(bool, hardware_enabled); +static DEFINE_PER_CPU(bool, virtualization_enabled); static DEFINE_MUTEX(kvm_usage_lock); static int kvm_usage_count; =20 -static int hardware_enable_nolock(void) +static int kvm_enable_virtualization_cpu(void) { - if (__this_cpu_read(hardware_enabled)) + if (__this_cpu_read(virtualization_enabled)) return 0; =20 if (kvm_arch_hardware_enable()) { @@ -5590,7 +5590,7 @@ static int hardware_enable_nolock(void) return -EIO; } =20 - __this_cpu_write(hardware_enabled, true); + __this_cpu_write(virtualization_enabled, true); return 0; } =20 @@ -5601,22 +5601,22 @@ 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_cpu(); } =20 -static void hardware_disable_nolock(void *junk) +static void kvm_disable_virtualization_cpu(void *ign) { - if (!__this_cpu_read(hardware_enabled)) + if (!__this_cpu_read(virtualization_enabled)) return; =20 kvm_arch_hardware_disable(); =20 - __this_cpu_write(hardware_enabled, false); + __this_cpu_write(virtualization_enabled, false); } =20 static int kvm_offline_cpu(unsigned int cpu) { - hardware_disable_nolock(NULL); + kvm_disable_virtualization_cpu(NULL); return 0; } =20 @@ -5635,7 +5635,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_cpu, NULL, 1); } =20 static int kvm_suspend(void) @@ -5651,7 +5651,7 @@ static int kvm_suspend(void) lockdep_assert_not_held(&kvm_usage_lock); lockdep_assert_irqs_disabled(); =20 - hardware_disable_nolock(NULL); + kvm_disable_virtualization_cpu(NULL); return 0; } =20 @@ -5660,7 +5660,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_usage_lock); lockdep_assert_irqs_disabled(); =20 - WARN_ON_ONCE(hardware_enable_nolock()); + WARN_ON_ONCE(kvm_enable_virtualization_cpu()); } =20 static struct syscore_ops kvm_syscore_ops =3D { @@ -5669,7 +5669,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 @@ -5712,7 +5712,7 @@ static int hardware_enable_all(void) return r; } =20 -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { guard(mutex)(&kvm_usage_lock); =20 @@ -5723,12 +5723,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.46.0.469.g59c65b2a67-goog