From patchwork Wed May 22 01:40:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670168 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D138C25B74 for ; Wed, 22 May 2024 01:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=l8y9Yo1zBlHbeIeP2QOCoUmkK3RjDwNNrhKGsAekggQ=; b=AqMzDpNDEi8ukK hKRd38P2poFTlZ2D/jM6V3czb5Aqsxt/oV3QtU/zxQcyxKFbE7xYjq3kkKdXJy7vpHPuPDB91iP1e wR49FsBgSv2yyhsBUG5mcIsXofBXApmgpYwn7S1TmmusS1e13c2XqjG4mIn8pzu1QZbP2Y1rqN6+5 GSl6LaFUxn4FdlSEsXlecVcDcAQluc+a6W5wqJxkFopXBs8pjAhhjXtnvNLxZkd/9GDtzUruePFp1 4FuDbsqKDbGLnPHE0+DG9C/17sYDAOxnRO19a0xKt8yoZmHKayb1UkE3tl4pW+wTE7Cv9Av4wCYIr DR9uBRPEYOxCtgdXJvkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axw-00000001edC-3tIa; Wed, 22 May 2024 01:40:28 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axn-00000001eVs-3swq for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:22 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-5c670f70a37so12359855a12.2 for ; Tue, 21 May 2024 18:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342018; x=1716946818; darn=lists.infradead.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=ksrstYm4acNB+vq44uyCoC45OYvJ0DDPXjwdxHvKYos=; b=Nb8IXEKIJBZsXrVP2jqmjh1b/Y/iYj7DHGX3WBPb+StFQdzr4US2/cTWEGqgLR5tK0 xH6vgsrrMGIVEFt9Ie1R5FL3wIajApYjXZQcAaF9fCndqM7tcD7AdnRod5i1vVPqma74 FKmVPHQhDaB33pFRgXLMB9pE+eNPGzt0OKqg5j5ifrc25C0F0Ee8CQpJRhVG4VhoCvbE niRAUa3Rj2uf6ilPLi4hftB+opruiv4nmF5Vu41yP4LdwBTMuLHrvRaqC09PXfGxkWAc hRWOLgDcBvztD/R/N6Ts99OEaVh29Pw/F5Zz5Z4t8MBr/3/Vp2MWox723XJ0+jgu/zjR x/0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342018; x=1716946818; 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=ksrstYm4acNB+vq44uyCoC45OYvJ0DDPXjwdxHvKYos=; b=pphLvTYzJ65/vHWV1rbfPf1XdBsHOq3jhLFBdrsyZ+oALXn2D9HOTsRRf5Ry090lEE KewsEI82bju+LAYeLdVQrrGvqcvJwQYmiryDRmbFu9yawzFpHGlCkxn7GanCiY3o20Fg CAg0khtr07kiM1MtLicnXNj+auaXLPjiWv+zvi0OkGeAA5ZMldoqT/R+ZelIm2mBRz5+ BdOjatv1WyivVvnpdicGgjIzUbII0KCiAuNL7kIyjvoEi8+aju4L9WCeBP/xXUEkYZ7q uw5Wl3COWLgHSm6nP6B4uWrk9MdReyYk22cPSIivzEg3RAbvnn0bpX/e1Uo+u8IpC0mI Ju6w== X-Forwarded-Encrypted: i=1; AJvYcCU9ZMippKabQ3f0lw6nrsbRLNYvQYTsqFSKbZEjg3ot8XuuHj+Rj8n1+0IAvoQ3andZNkoLhw17tDW5i9szKNObn+DDk6O0xMOIowbA+1ju X-Gm-Message-State: AOJu0YytsamfWSomxcLEfYNUCdvjk7UL1R8GWSZxCGv08iymPsiuohYt 7msx0PiYI+oq7dY8SR8ZMiwETV2Skp0Bsel3HokBbirjNgc6995JGQcrLYS6atP9AohBbuFNchT EFg== X-Google-Smtp-Source: AGHT+IHJLNUzIn6ctcMF+INwxFBaLeFnt3jt+tGT+n5clQV+H1h//pkXMDRUR1aNO5clBwbY0FCScT/OPUo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:484:b0:5dc:5111:d8b1 with SMTP id 41be03b00d2f7-676492dc83emr2297a12.5.1716342017980; Tue, 21 May 2024 18:40:17 -0700 (PDT) Date: Tue, 21 May 2024 18:40:08 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-2-seanjc@google.com> Subject: [PATCH v2 1/6] KVM: Add a flag to track if a loaded vCPU is scheduled out From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184020_000139_18231BE6 X-CRM114-Status: GOOD ( 13.27 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Add a kvm_vcpu.scheduled_out flag to track if a vCPU is in the process of being scheduled out (vCPU put path), or if the vCPU is being reloaded after being scheduled out (vCPU load path). In the short term, this will allow dropping kvm_arch_sched_in(), as arch code can query scheduled_out during kvm_arch_vcpu_load(). Longer term, scheduled_out opens up other potential optimizations, without creating subtle/brittle dependencies. E.g. it allows KVM to keep guest state (that is managed via kvm_arch_vcpu_{load,put}()) loaded across kvm_sched_{out,in}(), if KVM knows the state isn't accessed by the host kernel. Forcing arch code to coordinate between kvm_arch_sched_{in,out}() and kvm_arch_vcpu_{load,put}() is awkward, not reusable, and relies on the exact ordering of calls into arch code. Adding scheduled_out also obviates the need for a kvm_arch_sched_out() hook, e.g. if arch code needs to do something novel when putting vCPU state. And even if KVM never uses scheduled_out for anything beyond dropping kvm_arch_sched_in(), just being able to remove all of the arch stubs makes it worth adding the flag. Link: https://lore.kernel.org/all/20240430224431.490139-1-seanjc@google.com Cc: Oliver Upton Signed-off-by: Sean Christopherson Reviewed-by: Oliver Upton --- include/linux/kvm_host.h | 1 + virt/kvm/kvm_main.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 7b57878c8c18..bde69f74b031 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -380,6 +380,7 @@ struct kvm_vcpu { #endif bool preempted; bool ready; + bool scheduled_out; struct kvm_vcpu_arch arch; struct kvm_vcpu_stat stat; char stats_id[KVM_STATS_NAME_SIZE]; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index a1756d5077ee..7ecea573d121 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -6288,6 +6288,8 @@ static void kvm_sched_in(struct preempt_notifier *pn, int cpu) __this_cpu_write(kvm_running_vcpu, vcpu); kvm_arch_sched_in(vcpu, cpu); kvm_arch_vcpu_load(vcpu, cpu); + + WRITE_ONCE(vcpu->scheduled_out, false); } static void kvm_sched_out(struct preempt_notifier *pn, @@ -6295,6 +6297,8 @@ static void kvm_sched_out(struct preempt_notifier *pn, { struct kvm_vcpu *vcpu = preempt_notifier_to_vcpu(pn); + WRITE_ONCE(vcpu->scheduled_out, true); + if (current->on_rq) { WRITE_ONCE(vcpu->preempted, true); WRITE_ONCE(vcpu->ready, true); From patchwork Wed May 22 01:40:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670169 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A4FD4C25B74 for ; Wed, 22 May 2024 01:40:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ChdvRurSUlYYXXYCwE51tPFYWPiFxYyymP+8u9GXKSY=; b=Ys6zigQKMpWFoM eN9ZE0fbkCIwXqfUVhW5BArKPdtLyaOWNqImQ0IQAElxAWG2BcCLAvt3Puz+NsJaW4zOvZjtM5x3E hn6i0FmY7OWAKQifCX922CmTAxIKvUKCyazP5qoWqWnlLlDS4mMrcN0urUKZq1TGX17B8Wcf7d2Qd HrqnuCymd8RUylPxiUrouVqnxQ7mg4zNxWzZDxmkZfEaq4p8h65GHfv+Rfu69NkfamfrEm4FroEyH B01hcfft39Tyx+/eDHmB0Wjj4/qIfavoYY99ThE4X65BQlib/Zx64zUgH9xoFDQbQt2lfPqmOpnsA L3neSMCwCfhTHNiiED/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9ay4-00000001ej1-1HkJ; Wed, 22 May 2024 01:40:36 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axp-00000001eXG-2tgb for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:25 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-622ce716ceaso5474457b3.0 for ; Tue, 21 May 2024 18:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342020; x=1716946820; darn=lists.infradead.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=RHSd/NUpLA+qEQZ24Usoansq2bi58Ee8oOJzhOJ4pNg=; b=f47rIsr7rSvHGI8c1nZqyVTBraC0zIlcdK8AmE65aCCSwAvhPoqgD/34lt+Yw46RTp AuQfhziQNu5duyyGQSEChxGk/QRIxgYW0ClIijZ+vqED2rGStPI5WlxpEas//YTaRyyS zQ5o3QyR5tj08n56fSGAOdDf/M9+O2BY8Poh2dapnNAWJI8ARyIYXMt/sQu1YYo586rA mP3BfkBoeRkkgmOQr6XpG86EdazHq6x9rg6WVTcn8t83SbIP0V6UsbGVO+zNpdXQR5qT As/zynYovmqxNspGQK+XxRtkj6je8bse/CDke/epoldhCcALr+dS1RMB+N1/nUtIcXAH a0cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342020; x=1716946820; 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=RHSd/NUpLA+qEQZ24Usoansq2bi58Ee8oOJzhOJ4pNg=; b=vwMkJSFLdGnGbtUYqnDthIcjGlx9bIW1TzSwqAdsqYyo2XYJYvjQnuRdpgf773y0pF s5y17mktTe+vGWnFkjBpjooxP6t24qusUtD6aOh88MVgMTpuXgdWLd8rPkNDESgAghgb XIZ0g+SI3aW2w86/bMggPlrvYPXaVoVcBEStGKRl6JxWdeymdB5v/aptTkd8gutaZWWM LKXtDdSPmDI6nIK9ZvqTzxsiTaMBTKo6N+4UX6NVwN5CCXEQXi541YbFA8voe1HM6982 FCDCIAXH/VNMol/79WMj6w+peHFbFZtMcBXrasikZV4r62AIrID+Y2UqyD+6trVEAgVc XIzA== X-Forwarded-Encrypted: i=1; AJvYcCWN2fD8WVh7LFCAHf7yOy7bkeuz7woW8sQLTYqd5OcN3n8Fjjf8dR3VQnEmEq6fA7JjJCytevaRff6Xx80pTb+UWZANhTRCe5IQasbTjlvw X-Gm-Message-State: AOJu0YyvKJDzeXfkIPUEKWZ4tB3nfrdNj8UUjAezXNWH3JsG9aVoFQSf vp5M/3JfGb7BJcSkB4yJ4bDst7XGn9/XmQle1VjfhLTb6R50iAUdljGLoESDryca/KB6c64EMKJ rKg== X-Google-Smtp-Source: AGHT+IE9wMBEKwP41aGLYHN5gIBbi7welOi0G93+qj4AotHFqdz8JFE0XRpN5nX1Yz+N7pw0xKG3cBx+pVY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ca57:0:b0:61b:e53e:c7ae with SMTP id 00721157ae682-627e46aa2e9mr2093257b3.2.1716342019957; Tue, 21 May 2024 18:40:19 -0700 (PDT) Date: Tue, 21 May 2024 18:40:09 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-3-seanjc@google.com> Subject: [PATCH v2 2/6] KVM: VMX: Move PLE grow/shrink helpers above vmx_vcpu_load() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184021_838343_ADD05ECF X-CRM114-Status: GOOD ( 10.01 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Move VMX's {grow,shrink}_ple_window() above vmx_vcpu_load() in preparation of moving the sched_in logic, which handles shrinking the PLE window, into vmx_vcpu_load(). No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 64 +++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 51b2cd13250a..07a4d6a3a43e 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1410,6 +1410,38 @@ static void vmx_write_guest_kernel_gs_base(struct vcpu_vmx *vmx, u64 data) } #endif +static void grow_ple_window(struct kvm_vcpu *vcpu) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + unsigned int old = vmx->ple_window; + + vmx->ple_window = __grow_ple_window(old, ple_window, + ple_window_grow, + ple_window_max); + + if (vmx->ple_window != old) { + vmx->ple_window_dirty = true; + trace_kvm_ple_window_update(vcpu->vcpu_id, + vmx->ple_window, old); + } +} + +static void shrink_ple_window(struct kvm_vcpu *vcpu) +{ + struct vcpu_vmx *vmx = to_vmx(vcpu); + unsigned int old = vmx->ple_window; + + vmx->ple_window = __shrink_ple_window(old, ple_window, + ple_window_shrink, + ple_window); + + if (vmx->ple_window != old) { + vmx->ple_window_dirty = true; + trace_kvm_ple_window_update(vcpu->vcpu_id, + vmx->ple_window, old); + } +} + void vmx_vcpu_load_vmcs(struct kvm_vcpu *vcpu, int cpu, struct loaded_vmcs *buddy) { @@ -5889,38 +5921,6 @@ int vmx_vcpu_pre_run(struct kvm_vcpu *vcpu) return 1; } -static void grow_ple_window(struct kvm_vcpu *vcpu) -{ - struct vcpu_vmx *vmx = to_vmx(vcpu); - unsigned int old = vmx->ple_window; - - vmx->ple_window = __grow_ple_window(old, ple_window, - ple_window_grow, - ple_window_max); - - if (vmx->ple_window != old) { - vmx->ple_window_dirty = true; - trace_kvm_ple_window_update(vcpu->vcpu_id, - vmx->ple_window, old); - } -} - -static void shrink_ple_window(struct kvm_vcpu *vcpu) -{ - struct vcpu_vmx *vmx = to_vmx(vcpu); - unsigned int old = vmx->ple_window; - - vmx->ple_window = __shrink_ple_window(old, ple_window, - ple_window_shrink, - ple_window); - - if (vmx->ple_window != old) { - vmx->ple_window_dirty = true; - trace_kvm_ple_window_update(vcpu->vcpu_id, - vmx->ple_window, old); - } -} - /* * Indicate a busy-waiting vcpu in spinlock. We do not enable the PAUSE * exiting, so only get here on cpu with PAUSE-Loop-Exiting. From patchwork Wed May 22 01:40:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670170 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD1ABC25B74 for ; Wed, 22 May 2024 01:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jRRDJTKGf90Tk1/+CtyVRDdT9boWmKznS2Hn6FKeobc=; b=i6Ea9KB3REXU6P Cz4QjZPq9+kzf0Z8Rcr6Vkr4f71qLAPibqazr6dr4CiL//k1LUCctRaHLlZ5+le9tm9xOhK3UC4g/ v3Vbpv6tKqu828bHz6APRW251DDNLpHL+mPBs+1KeS0WX2GKKZb5NaSf0bP8kzLfDniijkEihu//+ vaEdJB5t+SNTFfIO+BiqJPfNpP5yntp0ZIgwplxJOn3aZEe3ycrmgTeKa5MDSALs0EVGmj406ntEO cwASMrxA2M04qIc1WA3N8fqlk1PKdny5jC81k24dGEng5kbtIE+Yy/ysVlpdTc5WVrT35W5idfqb8 mQajVBB2J8+QmGGNPqEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9ayD-00000001eq0-0Vqk; Wed, 22 May 2024 01:40:45 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axr-00000001eYG-0D8A for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:25 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-61be4601434so266111777b3.3 for ; Tue, 21 May 2024 18:40:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342022; x=1716946822; darn=lists.infradead.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=Ky0OyQodlYj1lBm/FQov7vVQOSf0t15DeKBOaNpreRc=; b=1+Ur9oZoxbezZ2v9kPDH/X757xMGGdghj2hlShPl+HpMiJNcujAT4PcDHlFN8qsyCs cw7g9iv+3GwsJ5zY+kgFrd+5+cK8seglbHefSg+e4LFsK8IKEg4OiyKrSgqazqnNZpCb zP6O9mVLOv5P0qSG0wFCtkzYL7zvgarFzuV3xIpAk1v37SWYInDvi12O8c6Rol4ZIOlS 7g3x7zBhnVsRUtxPxgVRBBNcPEq1eZI04O8zfbcLTiHE/wl9zy/tVE67ZVt1N661sRM1 ERR0nQGKIcMoY9KoTMfIlJDIF+KNPPbB+4/JGH4NtMBz2usEg3wZjZAb69oD7rljb/+n Sv9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342022; x=1716946822; 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=Ky0OyQodlYj1lBm/FQov7vVQOSf0t15DeKBOaNpreRc=; b=rODHRUeht5z7bvA2HJktrprXGEXB1sOIeYjyxojsfgKji9Q6SQJ2CBLMKP96zET9LB g32vHWcJKg1lk2RpmGF9gartXCUG/Iw8arqjetkNRv0O/PQ5Jmryzh/JTsrXX1ivzDaA G5nnT79bEn6XH2ZMnY2PJLDyr0Jtj++FykIWdaVrulBkHxREAGVSaMxPmw3TFmYWLhei kgOFuk6ARKqS5/XKQmCRTL7TVISlzYyePRFWCKiLVWCRI5TYLNPb5NIYG6rlfKtY1es0 5btG0gflkz//Lqp75LHzwKa4eu75bnoUygJlI7RfSf9PeG2HQiSZhumju94XT5x/wory HHmQ== X-Forwarded-Encrypted: i=1; AJvYcCU3GIKpzvAAqGFslDF0FVTGtrz8Tcr4mjc91Rxa5ceieKJbyp49E7ik7BlJ3WzJTspjk7R7kSNPLduReky6dJh5nDc9+RZRdRcUhHxfzGTo X-Gm-Message-State: AOJu0Yz5zinh6B/4DHY7CsliXarwWuW1LyJD4hAXar7xJ0FYcUVScPnH W+pXMWKCDb1/f0NCGr4v9LahmGCUYUUobxFrDqgWnMhWsmV1wnDevVqi53hnKtcSKct76siHKQF oGw== X-Google-Smtp-Source: AGHT+IH3ylTQdVbQjZOc6EesCmA9Xrxy9wlcjQn2SMB7bi30ktsJ//ZvCxppwijf1/jMZuHd3SCyhhC4bqo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:251:b0:61b:1dbf:e3f with SMTP id 00721157ae682-627e46d457amr2201297b3.4.1716342021752; Tue, 21 May 2024 18:40:21 -0700 (PDT) Date: Tue, 21 May 2024 18:40:10 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-4-seanjc@google.com> Subject: [PATCH v2 3/6] KVM: x86: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184023_217229_CB4EDB30 X-CRM114-Status: GOOD ( 14.36 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Fold the guts of kvm_arch_sched_in() into kvm_arch_vcpu_load(), keying off the recently added kvm_vcpu.scheduled_out as appropriate. Note, there is a very slight functional change, as PLE shrink updates will now happen after blasting WBINVD, but that is quite uninteresting as the two operations do not interact in any way. Signed-off-by: Sean Christopherson Acked-by: Kai Huang --- arch/x86/include/asm/kvm-x86-ops.h | 1 - arch/x86/include/asm/kvm_host.h | 2 -- arch/x86/kvm/svm/svm.c | 11 +++-------- arch/x86/kvm/vmx/main.c | 2 -- arch/x86/kvm/vmx/vmx.c | 9 +++------ arch/x86/kvm/vmx/x86_ops.h | 1 - arch/x86/kvm/x86.c | 17 ++++++++++------- 7 files changed, 16 insertions(+), 27 deletions(-) diff --git a/arch/x86/include/asm/kvm-x86-ops.h b/arch/x86/include/asm/kvm-x86-ops.h index 566d19b02483..5a8b74c2e6c4 100644 --- a/arch/x86/include/asm/kvm-x86-ops.h +++ b/arch/x86/include/asm/kvm-x86-ops.h @@ -103,7 +103,6 @@ KVM_X86_OP(write_tsc_multiplier) KVM_X86_OP(get_exit_info) KVM_X86_OP(check_intercept) KVM_X86_OP(handle_exit_irqoff) -KVM_X86_OP(sched_in) KVM_X86_OP_OPTIONAL(update_cpu_dirty_logging) KVM_X86_OP_OPTIONAL(vcpu_blocking) KVM_X86_OP_OPTIONAL(vcpu_unblocking) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index aabf1648a56a..0df4d14db896 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1750,8 +1750,6 @@ struct kvm_x86_ops { struct x86_exception *exception); void (*handle_exit_irqoff)(struct kvm_vcpu *vcpu); - void (*sched_in)(struct kvm_vcpu *vcpu, int cpu); - /* * Size of the CPU's dirty log buffer, i.e. VMX's PML buffer. A zero * value indicates CPU dirty logging is unsupported or disabled. diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 3d0549ca246f..51a5eb31aee5 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1548,6 +1548,9 @@ static void svm_vcpu_load(struct kvm_vcpu *vcpu, int cpu) struct vcpu_svm *svm = to_svm(vcpu); struct svm_cpu_data *sd = per_cpu_ptr(&svm_data, cpu); + if (vcpu->scheduled_out && !kvm_pause_in_guest(vcpu->kvm)) + shrink_ple_window(vcpu); + if (sd->current_vmcb != svm->vmcb) { sd->current_vmcb = svm->vmcb; @@ -4572,12 +4575,6 @@ static void svm_handle_exit_irqoff(struct kvm_vcpu *vcpu) vcpu->arch.at_instruction_boundary = true; } -static void svm_sched_in(struct kvm_vcpu *vcpu, int cpu) -{ - if (!kvm_pause_in_guest(vcpu->kvm)) - shrink_ple_window(vcpu); -} - static void svm_setup_mce(struct kvm_vcpu *vcpu) { /* [63:9] are reserved. */ @@ -5046,8 +5043,6 @@ static struct kvm_x86_ops svm_x86_ops __initdata = { .check_intercept = svm_check_intercept, .handle_exit_irqoff = svm_handle_exit_irqoff, - .sched_in = svm_sched_in, - .nested_ops = &svm_nested_ops, .deliver_interrupt = svm_deliver_interrupt, diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c index 7c546ad3e4c9..4fee9a8cc5a1 100644 --- a/arch/x86/kvm/vmx/main.c +++ b/arch/x86/kvm/vmx/main.c @@ -121,8 +121,6 @@ struct kvm_x86_ops vt_x86_ops __initdata = { .check_intercept = vmx_check_intercept, .handle_exit_irqoff = vmx_handle_exit_irqoff, - .sched_in = vmx_sched_in, - .cpu_dirty_log_size = PML_ENTITY_NUM, .update_cpu_dirty_logging = vmx_update_cpu_dirty_logging, diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 07a4d6a3a43e..da2f95385a12 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1517,6 +1517,9 @@ void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); + if (vcpu->scheduled_out && !kvm_pause_in_guest(vcpu->kvm)) + shrink_ple_window(vcpu); + vmx_vcpu_load_vmcs(vcpu, cpu, NULL); vmx_vcpu_pi_load(vcpu, cpu); @@ -8171,12 +8174,6 @@ void vmx_cancel_hv_timer(struct kvm_vcpu *vcpu) } #endif -void vmx_sched_in(struct kvm_vcpu *vcpu, int cpu) -{ - if (!kvm_pause_in_guest(vcpu->kvm)) - shrink_ple_window(vcpu); -} - void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); diff --git a/arch/x86/kvm/vmx/x86_ops.h b/arch/x86/kvm/vmx/x86_ops.h index 502704596c83..3cb0be94e779 100644 --- a/arch/x86/kvm/vmx/x86_ops.h +++ b/arch/x86/kvm/vmx/x86_ops.h @@ -112,7 +112,6 @@ u64 vmx_get_l2_tsc_multiplier(struct kvm_vcpu *vcpu); void vmx_write_tsc_offset(struct kvm_vcpu *vcpu); void vmx_write_tsc_multiplier(struct kvm_vcpu *vcpu); void vmx_request_immediate_exit(struct kvm_vcpu *vcpu); -void vmx_sched_in(struct kvm_vcpu *vcpu, int cpu); void vmx_update_cpu_dirty_logging(struct kvm_vcpu *vcpu); #ifdef CONFIG_X86_64 int vmx_set_hv_timer(struct kvm_vcpu *vcpu, u64 guest_deadline_tsc, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d750546ec934..e924d1c51e31 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5004,6 +5004,16 @@ static bool need_emulate_wbinvd(struct kvm_vcpu *vcpu) void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { + struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); + + if (vcpu->scheduled_out) { + vcpu->arch.l1tf_flush_l1d = true; + if (pmu->version && unlikely(pmu->event_count)) { + pmu->need_cleanup = true; + kvm_make_request(KVM_REQ_PMU, vcpu); + } + } + /* Address WBINVD may be executed by guest */ if (need_emulate_wbinvd(vcpu)) { if (static_call(kvm_x86_has_wbinvd_exit)()) @@ -12578,14 +12588,7 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu) void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) { - struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); - vcpu->arch.l1tf_flush_l1d = true; - if (pmu->version && unlikely(pmu->event_count)) { - pmu->need_cleanup = true; - kvm_make_request(KVM_REQ_PMU, vcpu); - } - static_call(kvm_x86_sched_in)(vcpu, cpu); } void kvm_arch_free_vm(struct kvm *kvm) From patchwork Wed May 22 01:40:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670171 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 30028C25B78 for ; Wed, 22 May 2024 01:40:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iNjeOOcFg7E7vtZli0YrjdxKUgMZZEYOoGJe9fXhl88=; b=A45xU35jJW+2yl JGddG7EqZgscsEFuBu2W838xPxzEc3MZB+AiaCrFnbtV2dM3/uUAo/hXoOs1PEihK0SbfHE4nS2nG 4VQGFX/7pNSvhVmR59ylBldkW7ptF3zT9uMXsga0T68W7AXqoM6ZB2LKxgjZ5phJLP6+grMP/Cn4f OqsC75ns9HN6q1u2BIixGtd20C4RvxuPa0RxbVhTZ8BADKBz2xvvK5mVI2Pw8QzrHLh8lyuKehWRL uOMnj5OiISN4PucocmgVH+Us6pKeN66H7H+ijyBNvYLEDgMW8/EYb46CO6WEZcMqOnUBgeZ4LP1JM XBz+J65qjUSqgzZsgmuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9ayG-00000001esb-0oo2; Wed, 22 May 2024 01:40:48 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axt-00000001eZR-2FUc for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:27 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc6dbdcfd39so25305096276.2 for ; Tue, 21 May 2024 18:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342023; x=1716946823; darn=lists.infradead.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=YIaHuI54z6BrBG13k0tb5gdPpybD0vyJf2+hzL+sGEQ=; b=Za5LChpIMO069be2bzEmg+J12GiQ71VPr/ZTIP/5aIlFK0PnOz6bFn7klpkDMqMoAj RroXMfFn4gZdj2OXCLmZGlZvvT1dX43U/Yj5cOh8uzyH5Vg/Z2NWhtTFY8Owlc36Q1fI 6CtgaPffX0n9cuZ6I+eE/Td8ixk3+zlQIb4swjCFkui2Sn7aTxjIXJtc1awNMBuG28B+ PzMHeRp/fc7K6sykgdp4hhPvWR9UC2Eky9s5uZbLQkw+hhYXTmlpTNXEfvLYLcPbqnXi zVhqyV4Uc9sevQozHUMJhdlp9BliV9qa8sc2BxgMiTQcjIPudWTY4In3M7ehUYy6OBfU gfbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342023; x=1716946823; 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=YIaHuI54z6BrBG13k0tb5gdPpybD0vyJf2+hzL+sGEQ=; b=UZrq1zv0eOVK7dADt74SOQVgXylw6JxpMWGilirA6v8Echxmk4Jnty0g3l+SNC4ndh g91ltkvdNT8JIAHNmyd8jcguiQJn9dwLR7Y1K6tR+x1Uy197tKErEAnx6mEwHHOqjODu okdTgUPpzEbNBsnePEe/AuHVHBL4x2jM26TNiJKUUlCt5s7xpVX2mqIm8N2O8VQPXUpf 16FKDHiv8rIgSXACdP7lj7PCfiqnVABwPDRKD6yRvZF8yxOkKZRHYBf6NMndjugcjzdb R8evthMuU8OcYbww3kiKiTDQtVI6rpQLwa4aTOTFl291kt7RPnWzBvcqedwjoJYx5lQy rh8Q== X-Forwarded-Encrypted: i=1; AJvYcCXqS2nVPF+15xQF5Q3bDfOQNnX2lxCx1lq35WW7YjMX365YTXju/yEtIa1QpKS8vft85HnzVdq3zRrZsyJdG9k6k0RslGTZSkb3MXSQaAki X-Gm-Message-State: AOJu0YyfZ+UwX/bIA1rwMn6cyquYZMJGWyTeP/hzxpZiwvfTc/nbcGqP Z+SlPdPW2/qpni/9DIfkw/6R73ikbw1708rfHHwyP3yImRm86XMETQ+SY1inp95JKtYZOVr1Dk4 hPA== X-Google-Smtp-Source: AGHT+IFtIcfoZKgdjst/9jN1ZKnYmldDCh/IcPZbGUEgdBNc2SyD0bVhs92SlTALzbm7WKOs3vxydBMimy8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:100b:b0:dee:7f2c:ad90 with SMTP id 3f1490d57ef6-df4e0d38b1bmr236895276.10.1716342023595; Tue, 21 May 2024 18:40:23 -0700 (PDT) Date: Tue, 21 May 2024 18:40:11 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-5-seanjc@google.com> Subject: [PATCH v2 4/6] KVM: Delete the now unused kvm_arch_sched_in() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184025_745167_75E1EB0E X-CRM114-Status: GOOD ( 12.38 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Delete kvm_arch_sched_in() now that all implementations are nops. Signed-off-by: Sean Christopherson Reviewed-by: Bibo Mao --- arch/arm64/include/asm/kvm_host.h | 1 - arch/loongarch/include/asm/kvm_host.h | 1 - arch/mips/include/asm/kvm_host.h | 1 - arch/powerpc/include/asm/kvm_host.h | 1 - arch/riscv/include/asm/kvm_host.h | 1 - arch/s390/include/asm/kvm_host.h | 1 - arch/x86/kvm/pmu.c | 6 +++--- arch/x86/kvm/x86.c | 5 ----- include/linux/kvm_host.h | 2 -- virt/kvm/kvm_main.c | 1 - 10 files changed, 3 insertions(+), 17 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 8170c04fde91..615e7a2e5590 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1225,7 +1225,6 @@ static inline bool kvm_system_needs_idmapped_vectors(void) } static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} void kvm_arm_init_debug(void); void kvm_arm_vcpu_init_debug(struct kvm_vcpu *vcpu); diff --git a/arch/loongarch/include/asm/kvm_host.h b/arch/loongarch/include/asm/kvm_host.h index c87b6ea0ec47..4162a252cdf6 100644 --- a/arch/loongarch/include/asm/kvm_host.h +++ b/arch/loongarch/include/asm/kvm_host.h @@ -261,7 +261,6 @@ static inline bool kvm_is_ifetch_fault(struct kvm_vcpu_arch *arch) static inline void kvm_arch_hardware_unsetup(void) {} static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_block_finish(struct kvm_vcpu *vcpu) {} diff --git a/arch/mips/include/asm/kvm_host.h b/arch/mips/include/asm/kvm_host.h index 179f320cc231..6743a57c1ab4 100644 --- a/arch/mips/include/asm/kvm_host.h +++ b/arch/mips/include/asm/kvm_host.h @@ -890,7 +890,6 @@ static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 8abac532146e..c4fb6a27fb92 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -897,7 +897,6 @@ struct kvm_vcpu_arch { static inline void kvm_arch_sync_events(struct kvm *kvm) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} static inline void kvm_arch_flush_shadow_all(struct kvm *kvm) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_vcpu_blocking(struct kvm_vcpu *vcpu) {} static inline void kvm_arch_vcpu_unblocking(struct kvm_vcpu *vcpu) {} diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index d96281278586..dd77c2db6819 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -286,7 +286,6 @@ struct kvm_vcpu_arch { }; static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} #define KVM_RISCV_GSTAGE_TLB_MIN_ORDER 12 diff --git a/arch/s390/include/asm/kvm_host.h b/arch/s390/include/asm/kvm_host.h index 95990461888f..e9fcaf4607a6 100644 --- a/arch/s390/include/asm/kvm_host.h +++ b/arch/s390/include/asm/kvm_host.h @@ -1045,7 +1045,6 @@ extern int kvm_s390_gisc_register(struct kvm *kvm, u32 gisc); extern int kvm_s390_gisc_unregister(struct kvm *kvm, u32 gisc); static inline void kvm_arch_sync_events(struct kvm *kvm) {} -static inline void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) {} static inline void kvm_arch_free_memslot(struct kvm *kvm, struct kvm_memory_slot *slot) {} static inline void kvm_arch_memslots_updated(struct kvm *kvm, u64 gen) {} diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index a593b03c9aed..f9149c9fc275 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -521,9 +521,9 @@ void kvm_pmu_handle_event(struct kvm_vcpu *vcpu) } /* - * Unused perf_events are only released if the corresponding MSRs - * weren't accessed during the last vCPU time slice. kvm_arch_sched_in - * triggers KVM_REQ_PMU if cleanup is needed. + * Release unused perf_events if the corresponding guest MSRs weren't + * accessed during the last vCPU time slice (need_cleanup is set when + * the vCPU is scheduled back in). */ if (unlikely(pmu->need_cleanup)) kvm_pmu_cleanup(vcpu); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e924d1c51e31..59aa772af755 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -12586,11 +12586,6 @@ bool kvm_vcpu_is_bsp(struct kvm_vcpu *vcpu) return (vcpu->arch.apic_base & MSR_IA32_APICBASE_BSP) != 0; } -void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu) -{ - -} - void kvm_arch_free_vm(struct kvm *kvm) { #if IS_ENABLED(CONFIG_HYPERV) diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index bde69f74b031..c404c428a866 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1495,8 +1495,6 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu, struct kvm_guest_debug *dbg); int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu); -void kvm_arch_sched_in(struct kvm_vcpu *vcpu, int cpu); - void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu); void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu); int kvm_arch_vcpu_precreate(struct kvm *kvm, unsigned int id); diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 7ecea573d121..b312d0cbe60b 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -6286,7 +6286,6 @@ static void kvm_sched_in(struct preempt_notifier *pn, int cpu) WRITE_ONCE(vcpu->ready, false); __this_cpu_write(kvm_running_vcpu, vcpu); - kvm_arch_sched_in(vcpu, cpu); kvm_arch_vcpu_load(vcpu, cpu); WRITE_ONCE(vcpu->scheduled_out, false); From patchwork Wed May 22 01:40:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670172 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F0ECC25B74 for ; Wed, 22 May 2024 01:41:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2LHy02nMk8a1HWHiYC7lfnzSv+tqja3hiueE1eJj2yM=; b=KAIdcQPjgqjdGj u1w0t9HxewhINCNPZF6swAu/Mp1jr/AQes2M2vxYDl2nNrwN0Nq283U7w0zEoJrOnalUsaizJCDxt wu08Ls9Gv3EdU339fiEPQEoKceMVC0FDDixoSW07Pes7tgB9DYp0VTUfHBDRJT1OT5saW5Hb8GwRt N3yMaqxVKEa1zcAvb6c607BPdCSzpg3rFKZPQJO7smcYF21BxOPV0mSU5YprL8bvTt09KL2fTrPJS gzY8VMhoqqB7BqxltQYt+qFP14alVTDj2WjQZgqcNsnoTeZzSEGI0AIZ9l+XPJYv/4xBj3YDvsb/S oz5OVVKk3FhvHNovAzfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9ayP-00000001f1d-3xwd; Wed, 22 May 2024 01:40:58 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axu-00000001eaz-3snD for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:29 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-df4da80ce08so603543276.1 for ; Tue, 21 May 2024 18:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342025; x=1716946825; darn=lists.infradead.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=9/Jh3NT05cAP4Dr5P4AOID5+N71m8JBqExCgFsAlL8M=; b=u6h1KlB/GvGreFt/YHQM63RBZuzUrh8ra/vfj0jaGCQzmFSge1pMIJNN6bizO7lxcj msbgdj1HGND/dkXd014iU3xdFC8TYi9Ya5kxkDyfSmsZIrBSzJv5hQkfjDzaaT6uo2Bn HsXmKJIJtNCkboBe+wlvUH+tcArRv89ufmI0sIqfUE242l0KztXeuaN52Lhe7V167i5F KuYY3s8MfPU+OYlhOEiy3ehNr/rEIV2XNdz0+UwU3zIXCCRl3i5jHRqt+oPU2TooJPNl dIGRPUP5YBvm0CsBk9OUblskT7AfZdw5cWSKaRduuQbteUtsr0NQ3f+0xT9slVv/l4/9 0WYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342025; x=1716946825; 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=9/Jh3NT05cAP4Dr5P4AOID5+N71m8JBqExCgFsAlL8M=; b=TGAsXgWZ7veVG2FsYnjfgneEHSLuxBUDNRrnqJrG4xyz2HL96V2g15ryn1mPaDmGIi pi9z0VZDALUa9rooloiX1sx+33EtY0EVx0ZIMzM7Uc7uWQJbhvImiiDOoC96n28k00il TEpS9kkKBCGdnDpIg1HrOyqnxsapLWU0/QaEsQvzKgLU5cfm5WEAsKqihCIdYVFzmlSZ qadsNbEDZi2vrt1KuJS22uExH4kkKkRnlB+imWz26fOzZV+aIk2MYb6/KCQnbO979tXS iWtR+nKiDQtY2gpyddoY7riuW6c4yBnYL2joEqGzA2exJRM2P0oNIAmwmnp8bR0vAetO oWBw== X-Forwarded-Encrypted: i=1; AJvYcCVirsZ07J18rhaR3pzaz4bJLB3CEgNYLRid614syFkY5BCALyc8OsGeW31Y5oHVq1ODlDtKptBawS033+0zXeC9Pj51biIVCMYCIhuQiPCM X-Gm-Message-State: AOJu0YzByf8EntPa8SuQ1BNCJS0Cr2Dki1LxgEvNR7Gswn38BuRSBFol TzYfcBQWCtXDcpMAHPimKAGa+HWFncgJVt7uXohV3Jid6VUQlb8VDdIhockVIjsA006T49l0LSD aQw== X-Google-Smtp-Source: AGHT+IFb4ojjFIBjH/g1gqSAZtGdXjScECyPQCKxtonXS1wS1/Q6Sfuh8cMohHl5GHkfuJ7096x7AKNuxdo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:100f:b0:dda:c4ec:7db5 with SMTP id 3f1490d57ef6-df4e10405f6mr210549276.4.1716342025422; Tue, 21 May 2024 18:40:25 -0700 (PDT) Date: Tue, 21 May 2024 18:40:12 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-6-seanjc@google.com> Subject: [PATCH v2 5/6] KVM: x86: Unconditionally set l1tf_flush_l1d during vCPU load From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184027_049828_8A50A93F X-CRM114-Status: GOOD ( 10.90 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Always set l1tf_flush_l1d during kvm_arch_vcpu_load() instead of setting it only when the vCPU is being scheduled back in. The flag is processed only when VM-Enter is imminent, and KVM obviously needs to load the vCPU before VM-Enter, so attempting to precisely set l1tf_flush_l1d provides no meaningful value. I.e. the flag _will_ be set either way, it's simply a matter of when. Signed-off-by: Sean Christopherson Acked-by: Kai Huang --- arch/x86/kvm/x86.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 59aa772af755..60fea297f91f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5006,12 +5006,11 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu) { struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); - if (vcpu->scheduled_out) { - vcpu->arch.l1tf_flush_l1d = true; - if (pmu->version && unlikely(pmu->event_count)) { - pmu->need_cleanup = true; - kvm_make_request(KVM_REQ_PMU, vcpu); - } + vcpu->arch.l1tf_flush_l1d = true; + + if (vcpu->scheduled_out && pmu->version && pmu->event_count) { + pmu->need_cleanup = true; + kvm_make_request(KVM_REQ_PMU, vcpu); } /* Address WBINVD may be executed by guest */ From patchwork Wed May 22 01:40:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13670224 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 233ECC25B78 for ; Wed, 22 May 2024 02:46:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VwjOOqUVwF0qr8UMJB5Y+DHo8JRP3Gum9G0807AmqaM=; b=qrprjGgMcsB/Kq myuDS8UlRkU3gQP++c+cEa8BJCJ6vW0gbWWGLYNxdFatWMJWRNpTDL085HkkHgrLXHcJzE0ylYogp DufdgdnUR93oe5gDey2sYIpKvoURI1HTqOS49GpnUUlqfUe7p0wmhucXKULVbixAKqu2HQOuUTXPL joUKIz/Wel+L2kp1+va8K76OINj03fDt0qjrS0WPsnhUraaW18vRTkELVg9DxHtHTIRowHyfvylTj FmStwKwZdIeKcrcz3AnMOvhhaSpPvHrrKQJ8wgVHRi9tIjBRjdxeWqWXyay4yTpeRvbu1qFeapydy Gcccd6DBHhr+8O07wYTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9bzd-00000001oiw-09PS; Wed, 22 May 2024 02:46:17 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s9axw-00000001ecT-2bF8 for linux-riscv@lists.infradead.org; Wed, 22 May 2024 01:40:30 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-627751b5411so138420977b3.2 for ; Tue, 21 May 2024 18:40:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1716342027; x=1716946827; darn=lists.infradead.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=N3tcdNqgpk0g0Qawt6D2SIU8FL4Y9j5vsBcc8xUlRY4=; b=2oWGlNmCe8w33HIw9yv4q15DZuN1ISUv3VtStwK62131kbYjxOBYNiOtI8lPumkUwk C/dqbCvjkJG6Ag7MLebMpYcqdq4HlPRSM4nyNZ1sU6q3WD6+yf9c1mg0LNELhf87puDW VcMISYhRNEWbs6F1TrIfQZAZsncUreiG2qOYGqyxNg2IStN23Wasgi9zP+rGjjqGDstl OkCtGhC/MBXiB8mt0AK3fW4ekqDSFSMndw4Krem1LMbjYcBfStwibVz769HUOU2ZWNQg GEd0QrLM7sn0/MrS+am7Q88fBf88LyQKWhw1dC4Uk0jfpi92DmrPA47hN7cOW4iPc4LT 32gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716342027; x=1716946827; 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=N3tcdNqgpk0g0Qawt6D2SIU8FL4Y9j5vsBcc8xUlRY4=; b=KQpULjhf6+Zw8Z5yBe90TctJmQGMEu0KGXiOteU6Pojd2hYNNGUWYUl7Ybb0+brL9c scHUUl4HibfA8zbpWvFRYiPIs6JHlaem8+MZFbpqrol77qP3FKp0FW1JxrNG8modEsP6 pA8/YrHnpOPDnc5nekVV3kBBmbIrVBusG6kiRd9qVOzMTQWbGndvSOjI9jWu/Z6gRILz IEx6Y6OXPjiC9LzLQoX9V8ImzEbERf0LYiM6Gt/4ofSPq2wpUkDmWUTYGEHJ9nSH/v6+ AypLckCiJJ2ecmaRnoAXsJj0g4FjVHa3oWqKoSJDEhiYVN6XSROWTdOtu9mU/XKWVlaC bKKQ== X-Forwarded-Encrypted: i=1; AJvYcCXV9CjYKeLB890hgdBwDl/xlvmINotiP8srb+E4BELFlV07zXvvMyY4+CScQDYm2NVCCh5uxcCuKcHiez9X0Apz9gyn93kioO+6W+gfRveW X-Gm-Message-State: AOJu0YxYeM5gAyoAHgOO1otMI280E9VgCh8cdf3dyHJgPEjuuaH9Be6t vafztARszKYWnVofMkhZVEIso3nRgbEP6GD986dfDXoPHuS4Sb6jx9ftP64oDS4o1vT+fudBMbb MCQ== X-Google-Smtp-Source: AGHT+IFL81/qwy5rtkuJ10qcaRdu2JQbneM9E+pjVdbps1/0e/VA4O7XiaE6CliC0DQxJV6ImSRXVMyGgXw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a81:4984:0:b0:61b:e6d8:1c01 with SMTP id 00721157ae682-627e487fd2emr1914977b3.10.1716342027243; Tue, 21 May 2024 18:40:27 -0700 (PDT) Date: Tue, 21 May 2024 18:40:13 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Mime-Version: 1.0 References: <20240522014013.1672962-1-seanjc@google.com> X-Mailer: git-send-email 2.45.0.215.g3402c0e53f-goog Message-ID: <20240522014013.1672962-7-seanjc@google.com> Subject: [PATCH v2 6/6] KVM: x86: Drop now-superflous setting of l1tf_flush_l1d in vcpu_run() From: Sean Christopherson To: Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240521_184028_700360_01E2F37F X-CRM114-Status: GOOD ( 12.23 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Now that KVM unconditionally sets l1tf_flush_l1d in kvm_arch_vcpu_load(), drop the redundant store from vcpu_run(). The flag is cleared only when VM-Enter is imminent, deep below vcpu_run(), i.e. barring a KVM bug, it's impossible for l1tf_flush_l1d to be cleared between loading the vCPU and calling vcpu_run(). Signed-off-by: Sean Christopherson --- arch/x86/kvm/vmx/vmx.c | 7 ++++--- arch/x86/kvm/x86.c | 1 - 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index da2f95385a12..552b6a9887a5 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6672,9 +6672,10 @@ static noinstr void vmx_l1d_flush(struct kvm_vcpu *vcpu) bool flush_l1d; /* - * Clear the per-vcpu flush bit, it gets set again - * either from vcpu_run() or from one of the unsafe - * VMEXIT handlers. + * Clear the per-vcpu flush bit, it gets set again if the vCPU + * is reloaded, i.e. if the vCPU is scheduled out or if KVM + * exits to userspace, or if KVM reaches one of the unsafe + * VMEXIT handlers, e.g. if KVM calls into the emulator. */ flush_l1d = vcpu->arch.l1tf_flush_l1d; vcpu->arch.l1tf_flush_l1d = false; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 60fea297f91f..86ae7392cc59 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -11264,7 +11264,6 @@ static int vcpu_run(struct kvm_vcpu *vcpu) int r; vcpu->run->exit_reason = KVM_EXIT_UNKNOWN; - vcpu->arch.l1tf_flush_l1d = true; for (;;) { /*