Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1450868lqd; Thu, 25 Apr 2024 16:42:21 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXXbpcs5V9pP2ytmxOhMV54oTKMLzoZNy/Z9AE7C3cgEHmLyT9wUMq2k5CsqYT5c7dnzoQFieQTEFAxf7u74mjOSmDJri+iWjbP0ARuYg== X-Google-Smtp-Source: AGHT+IG8nIsBsTfjT2h2H4GBcuQ/cvDKPuMBVLlVJ6J9Drz2/KdpaCqG/++Py9JdANUIHOvSOmNm X-Received: by 2002:a05:6a20:1005:b0:1aa:33a5:c5d8 with SMTP id gs5-20020a056a20100500b001aa33a5c5d8mr1349772pzc.46.1714088541648; Thu, 25 Apr 2024 16:42:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714088541; cv=pass; d=google.com; s=arc-20160816; b=INy1H8CWr7CPtR6F+icAFuWAPuVbiDXEZXda1dOa5l4LnwaFNtRH4R8BGNjHTxkxmf PjKoGGjyAZCuOtfGwOKIjDWvnw2almV6aoA6yh4MRegP3QGPWnxwq6fXfvgokbSetD/W 2PIIXy6JnO7L4Y7HcrrcpVKdJZ2+zxC9Emt8oWZiXaxzMtovKP2XrGRLiE2dAVH3eWxF h2kD1gpankfDQ4+Ct6CR2e22YPNxxOHS74R7PE0n800GsMcyNcUct31rzRHc9HKH57+L jTpKPUAaFjxgZ6dHlURAf9KTtvh6he3ynqoQsPbGj0c61AUIy7+kCsWv+1sg0Bj9Z8l+ aabw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :reply-to:dkim-signature; bh=/NaaHWoathmI+8UuflB46ON2NyuL/ZRdqhokuCuaP+c=; fh=FS56lbEAmlGAOvQb5aeDsaTsjdsG0wNdcmLDS0CnmAI=; b=ri0T/jvjfQe5UJPvqsi2IqWgEtw/HcEcGqEEQTGa2mvJ91KZT8YZVFHZmfHMpqatOo uGwyAJ7HnuFBnSRkFUft9RzmmABrTMOrvFctxo3MJvqRXwJ5bVrvdE9qcAw9mhx3wKb8 o3sCO9QR7qadArDtJn6CT/6Tw6/DVEbgv4hCGNXIOmU514BmkIIVY8o9Y8HDi2TlmNO1 t9rjlbJXsoJ4bnbaM2lvs8YDI8Et90kdn5ISXSCDBHIWaRHhwrH9LUbGDQhquQI7NYcb d0mTq4yY3HGGrKHrd8m0+N+dFV5CNlrzOAb4H72/ACmdqEUEWo+j27qBdzUiVTlKCeL+ Xm8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kWb5CGXw; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159365-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159365-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id f6-20020a635546000000b006003ee04f15si7927069pgm.698.2024.04.25.16.42.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 16:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159365-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kWb5CGXw; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-159365-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159365-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E9640B237A4 for ; Thu, 25 Apr 2024 23:41:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 152F416D9D7; Thu, 25 Apr 2024 23:40:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kWb5CGXw" 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 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-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-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, 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) { } -- 2.44.0.769.g3c40516874-goog