Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1370007lqt; Fri, 7 Jun 2024 17:07:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUrqUD+7C9eIjXjc3TWF5+Oz2tMpZVeg4VPunv7DrxUv/SOUc913ezOv12yvyUeV2Avp/IMRMQ48GYOR1dXDua/notQFEVR2O+7KcLnfw== X-Google-Smtp-Source: AGHT+IGgzH8jEjI0eIBMVWrpmRKxRsZ8CoI7BNHexdM0GvTJfoVn5qKVpw2CWfiRFBFJKWWE3o5A X-Received: by 2002:a50:9509:0:b0:578:649e:e63e with SMTP id 4fb4d7f45d1cf-57c508b42fbmr2452613a12.16.1717805257587; Fri, 07 Jun 2024 17:07:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717805257; cv=pass; d=google.com; s=arc-20160816; b=F8eJ8a73DYIZCV0sw7Z29adx+GBUgjDZQopMrsMyBse5PKXEgQfD9BW+rTgOe1uDve 3H2bKZLoN1nhgtwhF0Yw9qtKSgAZODb0Ml+f3cXN54+xKVVVAXcpEQnMGJ35g9ZigChm uXQFCRoCriLAtHSqXR4Bu73LDyr8jVnSE+l8EtpqzbCPpsJF+63D/7yT3o1mGI08CCe4 XV5iUCJegJRkHaHNl91FIM05GgknuuxkgrtAhEeXTxiPO1PDsvnvqroHa8kvmSz0ve/0 /5GQLN1vTeAtDBN4SHB+78t76soqzeSC+cmCV0efMAme/DxVFRrEFN78qOCXeJ4lpvB4 Ydew== 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=6oG2p3ebAbUpQGVelwukytqESKts/k/4HZBdB34fsng=; fh=C/TMi6cgbsDVja8e+fEFRfoCTcdcbtg076KWdBajC7E=; b=YSc/S4OzJkYXQwLMoWW5vFzzGOvaZYCIyrGmwStRYmvvZeHp726wlBqF/MNSp+6LD4 kP2LKulDHwpjwAM8dTExbt7rxLFW98xGKWRa+WkbGQqJf/hZfW2TCrNybF6sVv/GS1/s 4gbCjGk+loBwAra2TBF0rx28GxdsB/QtanmfBfAbm62vrIOkUlEfcJ4Xaap8sCs2Tw3L 1SQi6U3o5Sd6HxaPlIWbt3ddmgYgTP8uRZkcu1k24RjAPswf7FaOFflEkIDiE87K/fIU 2cOa3IU0YHXztsqWoTSV5pLRl0XntDszK7vTMUZtNVI44DJrV2G7FnWd+AC59jossm/1 YsCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XN9w915w; 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-206842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206842-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57aae0c6f67si2308012a12.68.2024.06.07.17.07.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 17:07:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-206842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=XN9w915w; 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-206842-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-206842-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 1FF9D1F235BF for ; Sat, 8 Jun 2024 00:07:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D26DF9F7; Sat, 8 Jun 2024 00:06:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="XN9w915w" 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 7EB12610C for ; Sat, 8 Jun 2024 00:06:48 +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=1717805210; cv=none; b=FuvvQXYGCFv+DJowIWjf9SUoChZU6zdZ2taYr32Wi/qEX3tjjuEvLM0AEpACvS7XQfUKIQgMHuUoSMz06fzCPg2vcqy+eZ1mAlcRZJWQjIt1/KW68lwO/6Xm8mujk5bzzC+YCa/Tn4mweTAjSRbTkkis6gEj11mRBJuuRNx2bpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717805210; c=relaxed/simple; bh=/RdPxhM/6HHEDqv6agcyx/TVxEplMU6sNYeT51ttpZo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ho/tOvI4mq7DhXnl1Kk7NTTPFF70nLj0x4DOwvH0/lSeEKwfvny4pVBh5hZ6es4vAKftER3Gen2wZSyOBRClO2WcSGGHe/K1c+IpnSBmrU5hpH3j05Nn6AOew1CfF3YHQliAKBpMe2ATJbEBh0bmLXI0dk3FNDnG2ZMydJE2REA= 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=XN9w915w; 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 Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-6c8f99fef10so2451607a12.3 for ; Fri, 07 Jun 2024 17:06:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717805208; x=1718410008; 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=6oG2p3ebAbUpQGVelwukytqESKts/k/4HZBdB34fsng=; b=XN9w915wTqmJxdAJuxOU5fYBHAZax4NN4UM5MbF4XPV9bM6ZLVN6FIFi6CnRAB3pH5 K43mDknMSeIhi9n4Ip7vTad1YOhRDj0wWXkuAoI+UiRWML/5k9r6LwGSSkHVRsCQ6AiP OcX08mykLh9sZzbizs1yvGvZv84WXLhMQQlpmDev5BjcHmkDS+tknAcjxqiz4ZM+/GHC hAbWxX28+a8YdU3ASeXaqvIzsF/xFcUlZPgJGLQVhEd+oxQcF0T40gqxfGO0rTA09SdD 89LVFiLod3R9M/qadwWXczNfCTxc1QuJCyVB89MG2G2b90EV+BfVVwwUt5h9u9GsfYro HKag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717805208; x=1718410008; 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=6oG2p3ebAbUpQGVelwukytqESKts/k/4HZBdB34fsng=; b=oMxHueqroEdZB9+kTKvZJ1umMZsE0oJ9dr3GnJsFODoQqQew730XsQcl/cc+SzUMF5 s/Qz/o91NVUEJfEUzK8vBLEeh/D24/IXo7dECVC9U8ghNzzvuPSZQubx3KlB5q5NKc1x lXLpzXnDAhk2fL1X96ZOinq8o2Ef8ALQs8krESlqhfqKQ25oVgpbyqNeWSBZfGRI7ywx yH8tl9gpYOW3qrCxduRyf4mkSGLMctbUqtV45808pSqiyLoVCX7n0qzk5g1zeaaipqTy JRHV93Sl/ljPtHtcTo53J5R+JjhAJPYyUUYx+NHgKXNeRCWuulhdB7HnX1vahbpENDm3 CJQg== X-Forwarded-Encrypted: i=1; AJvYcCW6B8LVKVpYXbXmb5dpqhjF22ErIO11pyqjZtEElJBbezEVPAScjEFeGfX5xy8gFuBmZDmHctktBHCtkPzPm4TLvBrRFlsPy1Irqdhf X-Gm-Message-State: AOJu0Ywv9xL3R65cvreeZqHFxkxTySBEypsOXthaXODlPwiqTRp5fOWQ fMBfnIV1PGzIWN7a8H6lE5OGZaHl2zXGU6YUugEj2Tch9sWz7WeOM48zYCYUF/sl2xRGl+g7LwW Xyg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a65:5c85:0:b0:65b:7bff:881b with SMTP id 41be03b00d2f7-6e15ebbfb56mr9302a12.8.1717805207578; Fri, 07 Jun 2024 17:06:47 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 7 Jun 2024 17:06:34 -0700 In-Reply-To: <20240608000639.3295768-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: <20240608000639.3295768-1-seanjc@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240608000639.3295768-4-seanjc@google.com> Subject: [PATCH v3 3/8] KVM: Rename functions related to enabling virtualization hardware From: Sean Christopherson To: Paolo Bonzini , Sean Christopherson Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Chao Gao , Kai Huang 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. Opportunistically prepend "kvm" to all functions to help make it clear that they are KVM helpers, but mostly 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. Reviewed-by: Chao Gao Reviewed-by: Kai Huang 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 f6b114f42433..98e52d12f137 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -138,8 +138,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); @@ -1215,7 +1215,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; @@ -1258,7 +1258,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: @@ -1353,7 +1353,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); } @@ -5502,7 +5502,7 @@ static DEFINE_PER_CPU(bool, hardware_enabled); static DEFINE_MUTEX(kvm_usage_lock); 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; @@ -5524,10 +5524,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 *junk) +static void __kvm_disable_virtualization(void *ign) { if (!__this_cpu_read(hardware_enabled)) return; @@ -5539,7 +5539,7 @@ static void hardware_disable_nolock(void *junk) static int kvm_offline_cpu(unsigned int cpu) { - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } @@ -5558,7 +5558,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) @@ -5574,7 +5574,7 @@ static int kvm_suspend(void) lockdep_assert_not_held(&kvm_usage_lock); lockdep_assert_irqs_disabled(); - hardware_disable_nolock(NULL); + __kvm_disable_virtualization(NULL); return 0; } @@ -5583,7 +5583,7 @@ static void kvm_resume(void) lockdep_assert_not_held(&kvm_usage_lock); lockdep_assert_irqs_disabled(); - WARN_ON_ONCE(hardware_enable_nolock()); + WARN_ON_ONCE(__kvm_enable_virtualization()); } static struct syscore_ops kvm_syscore_ops = { @@ -5592,7 +5592,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; @@ -5635,7 +5635,7 @@ static int hardware_enable_all(void) return r; } -static void hardware_disable_all(void) +static void kvm_disable_virtualization(void) { guard(mutex)(&kvm_usage_lock); @@ -5646,12 +5646,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.45.2.505.gda0bf45e8d-goog