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.