Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp63593lqp; Tue, 21 May 2024 18:41:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV9T0u6zcbZHm7mYKEsWuOl/rfgkyiuKGu6/K4msHyRUQJFpr9jLXdVMG5jEgrsibJCFNU/5I6QbvPWtIXBWBhTLnpyXrZlHuLTkEE7tQ== X-Google-Smtp-Source: AGHT+IEtaCbdpR3KgcyFydR1DjErv+8JJsKiSfJPYUanHrutb0WafWulgRiY5agEBekCqs4nO6PM X-Received: by 2002:a05:6512:73:b0:523:8858:db81 with SMTP id 2adb3069b0e04-526bd693d1cmr224820e87.22.1716342093536; Tue, 21 May 2024 18:41:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716342093; cv=pass; d=google.com; s=arc-20160816; b=TAzQFuPcdncg6PMGFB5hc4n76GUuulsysox5Q0ZNYyf7mOnmFgCcOpw711Q2RVPld/ UtloYtygkhhBQLRj10E9PksTv5JA+6xyuahBFWrYRZ1tX8uf9Mf2sIhaQirK1Q5IkMli Ktxer5U7wOoFcLbfpiVnEoO9dpMoGTeLOg48sZsqoMBAxD4602SROw2h1XIG/VyCmDu6 +0nwzSPo2kMgA59tnCitrmtB01Gb3IuMi6nWqYbQ5Mqp01s9jxEmxjmY31xWLjb21+nr bqwzcRonpnDTxiKmh8MGsCd16ty+Y4y63TsVVgYA+ZbckfYW6iHLw0HZK5ka8oHjlFbE C9xw== 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=Ky0OyQodlYj1lBm/FQov7vVQOSf0t15DeKBOaNpreRc=; fh=xXc03XcuIAUtsM1CMj+kbSoUILzKgPYVNZJ0CwGMn5k=; b=JiTqUuQkc7ZJLzwuHSY9EnuOOvoe+zKPMvm1wSp2lM+rpXFdgZ8Yl2TmbFD9tFqrY6 6wWygM9fNQAK8DDB2fRiKAgnheJLT9s/oSqkUaNVnrIHd3YMYOh4x9wb5ivH8BZx2qft OHFJWSb4ukdr0M/lGg4gW2klcZFSeS4NCYx9Ho/CZokBIYv6vFwJvJkfyAzl7no9PLtq Dm3eeMsh7PAIuqr8wwk3f6evuXI8oUb8zDih2cd4pVjVsxlJN6/ffaLfkUgqTFWCrBwE g81SL9fZvMWYPD46YA3e0SWF9TjKcUeGk6sJJU1kM2Htm5LK6HGUAXoYjrpOFJR75ksh gVew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WRdqG9vr; 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-185664-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185664-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a5cdc248f30si741933166b.838.2024.05.21.18.41.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 18:41:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-185664-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WRdqG9vr; 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-185664-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-185664-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 0C6131F23424 for ; Wed, 22 May 2024 01:41:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F83F25753; Wed, 22 May 2024 01:40:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WRdqG9vr" Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.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 9842E1CD16 for ; Wed, 22 May 2024 01:40:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716342024; cv=none; b=se5EkIZb/ZkyYtTE++0d4qSruYEMtiRHziLNoYHulvwXdQ0g9TkSZMCcSpQAtym3B1BPMxrKX0RKZyvmkIV/F7iXN4tqYmkTQyQRkH62G654BftGvAFCXvU3eTGmTV2OU99EYJOISPfKaFaim53q4uSWcCQiiJWRFocAqBBLZ1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716342024; c=relaxed/simple; bh=SZyLjBDPVAa/D0KwpeqI+MBejZ+xXEeWM4HL4osCdxI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bmWjoBHFLeyjK7hyugbI5Ndw+72CbbHOUpZXzg8I0VZiWA4cozyEaElKeeWc3Uz2lQZDqE88EEQvhQG89ZoxQHRuVc5gvtxc4lvQCMh1Civ0XmvuL5CIC7erhRGi28V7idf+gGT3+S2aq63zJfMIiaKCiIn/ZiUOFKUox9hUXTA= 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=WRdqG9vr; arc=none smtp.client-ip=209.85.128.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-yw1-f201.google.com with SMTP id 00721157ae682-61be1fcf9abso195670997b3.1 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=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=Ky0OyQodlYj1lBm/FQov7vVQOSf0t15DeKBOaNpreRc=; b=WRdqG9vrnF8rttfWGNfNCsXQRQ7jgjR3HLBWgjK5hIvDHr5+q+1csFuQ5E7c3HTDaK n54SOa5Nh1iYGGW8YVH23S5QKPuWXnsDlK+A6tBsTsU735SbFt8I6+eKlN/YjiLEUbOt wjoXBrEM5bys4BumIihtcPFbZOq4v+XN5JAOcQYyk48D+8mC/tF9zyJ/5VFb4gTAeCUp jC0K5XeyZOe873SSnhnL93Oze3cmAdvZDCKnYPOpABdgpAjT5yCRcJFg4d2vd2QYZ/QU dX6MNt2Wui3IIIGbf3C3kvFvzB8DCwRdOxL4BZDoh7LpFD72SSsBOABzyIiK60Oym4nU GoCA== 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=YIXLGOxJ1HS8/Hp8CNvf4ddVclaq8bYS7pO6ZItJECZUelBGUIS4aB/Og00IKpS6VT OfeCgCx0Ai/fu8HqmmUs/hEvvnOTjj3k/Lb0pHAxzwrgMbGlIBmmeOWX/3+a1ezl1dAK 9MfKrMWOsq7h05rHUdeRLv+dfumk13NMSkMPifbH83Ejgh2Ep6FinA3yFw1PSD2YZ1YD dfHO6ppgWS0m0pLgR99LA/zOA1TuTNgbc5PS33GYQeCu6MxSeJ1PzU3WFPBorcazyNCx 4Rb3KridnkuzoML6OJiUbXuXSgJ6YQq5fYnn/J4E+26xkyW5VxbA8PCPrlS3IOCcz54N q2bw== X-Forwarded-Encrypted: i=1; AJvYcCXrwf/u0pXRb2GVNGZd/TVQwC4E4GY70ctNpaDHB6gbaZe9xXI3rwg7CnI7TzZBZeCmfvFEQisQEs1Lw9toZd8Jy5giKemqo0y1dDJI X-Gm-Message-State: AOJu0YyeUm3DDa2mMy/4ovuakES2j/tjR9Nngg57cSn+6yI36gfXJDIg RDfi5aKQIzroyrGlg+rQG9jWB5R6hthQxUTGXMLL+vuB+DKUfvYfeeYpvZ52lvKTQERV6O7+flM HJA== 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) Reply-To: Sean Christopherson Date: Tue, 21 May 2024 18:40:10 -0700 In-Reply-To: <20240522014013.1672962-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: <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 Content-Type: text/plain; charset="UTF-8" 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 --- 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) -- 2.45.0.215.g3402c0e53f-goog