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: 13670152 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 CB52B171D8 for ; Wed, 22 May 2024 01:40:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716342023; cv=none; b=BwYBc51I8wmdZgTwkbKYixwqDcIaRHR4d2CUboBPx8Xyu+17jJaGJcgowP6i/VymRUd2n0MiH8jAHMIteyfXO2IA7GI5KkpnG26GqenODh05EXU2DrkLGz/3dsSSLrN8aoQ19DUJmZ5HVaWGC0DOKY/q1gwNQZB5gSu+koKBB6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716342023; c=relaxed/simple; bh=a3/l+BJfoA/G/28RbhkAW1tXtxlUYPuy/d4D+LgwoZ4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R52zTOEa15Kra26f+VRJHOzezy+rPwrwitYFsW2T2fhK/DFcsyW+aO9CNyra3uTCPX8cUCsuoSBP4CazvY1K+H9t2aNhnAKJRABKQfvRcmYkv6DzNQQ3PQy1ZGi5CSyuKoK21dpaOJ7v8MIoiSMGuMUeOvsGbWDKkHd4ysW4r3A= 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=TgYaxdIS; arc=none smtp.client-ip=209.85.128.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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TgYaxdIS" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be325413eso6068387b3.1 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=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=RHSd/NUpLA+qEQZ24Usoansq2bi58Ee8oOJzhOJ4pNg=; b=TgYaxdISmyZDw09b+yhTo9D4kjNP98X+q+pEZ8fFnuqu36J46RgbMVXCkwOtzeh7d/ 1Tbyq3M816qXa8YRexIlj497IAm8vM2lv3j27GWZpdPBEKP6s9pphJmGIC3umYeqxk6w pKK8esdZZxJ14RQLML3m/kUEBNzKTq0qI3x0S5w4Pvv7S80qKV+R9BV0xAF65mTBPXWp R6128rG4gbfk6PqCS5EcxWD+30ZAR47BpaLlfA/zN+G1d45Xv3qkZei4iKZUG8rJDR5k OUkGrhTu000s4qlEpy32P5imIdxuPqSyID1EBzHanMiUkprL6i0AO4RmJxv7m4x7RAqv BjxQ== 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=h4UUuPKsc4ke2XWSLhe+GopYMIn/H9Umtuh4TFoctgt4pApRSRXoIU82nFg92wJe8x HDHo81YctSQDAqJ8/DelLlmK20Qj/TToTAkoCXfvIq7wke14ScjN3VcKzIyAp2dmr366 jCyskolKbva8K5esW6VykxUmZ45Nv1aGti7v3TUPnkZX6AyVLTumzAV9PzDPDX4p5ziz RfK3eabckvTwYTPD/T5JtcSq0uPnapNXW19GvYQrBCa6rkWBxy26ghcWMPgb949lf/dk UVmyplMdrvbAjV+0TOz+I8ygpFhTZgzsKwyDC5LdX7tY1yjg8w+fZL30XonVCefFkAwA TpNQ== X-Forwarded-Encrypted: i=1; AJvYcCWRDuI4y1ZAbCQq2d3mTUQB64GADoxdKzeNYJzumhHUP5dP4R4I4ju2iovC3fRhI9wc8SGe+WpxCt7Swhf6FjYKuhJX X-Gm-Message-State: AOJu0YyPUmUgHo7GH6FEzgQ2Qo9VX8UzFbvDQl65HJWq8ph3SRa/2vuC zNqvuTOwiEEctBJNING4nzPt8C4I62kJ1BOimw/mn+CGEexbxCzdw4a57ZNK5YtaWSqITvN3A1y Ehw== 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) Reply-To: Sean Christopherson Date: Tue, 21 May 2024 18:40:09 -0700 In-Reply-To: <20240522014013.1672962-1-seanjc@google.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.