From nobody Sat Oct 4 16:12:31 2025 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 90DE4214807 for ; Fri, 15 Aug 2025 00:12:39 +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=1755216761; cv=none; b=T6G/0WSTq/RhvGgUJrRlp/D7MJyFdrn29Q4hvq6mwWaxgjZDChzia05iA5D/vn2bLovluZPMsMJa6jbQJu8yTlxWJPIkGGcqxjAFpExNVtoK2o8LvO6sPoTmW0uRuBJ3Fv36XiNRwsdAAi0JMgqXfkV2vbdiaemi2hZZ0mldQWo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755216761; c=relaxed/simple; bh=RZ7Dz8xwBsHGy5mh7rqSjgoKEOyTvpiJll9GacNdIxQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=RY3WSgxv+JQLN+cinYA1QRvP5b7w2uPBbX3GiVyPVlMFeN90bqD1mI8J4nBhc8+v3bnFsZXBsuWc32ZX8Xcu10nDecNU04g93TleMjxz50CBBMHXtfUw2WeHrk5XuOvMB+BVSCBt3erxkTJrAGh6onYMOTMaJIToE6GR2vnsK9E= 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=sYLQ5sqP; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sYLQ5sqP" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b4716fc56a9so1752720a12.0 for ; Thu, 14 Aug 2025 17:12:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1755216759; x=1755821559; 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=5WU9voBHmtHCID+62ekjip+WsDaLPoXQ1Ho4KAjz+Bk=; b=sYLQ5sqP+joFgShRs229ltnfmFKtmVeGfB3+jobeQCppC5tinDwcFsakJuE7PWJD3n RCeGR2mhTHOLudMle49N2/iSBI+zo1uDLnobkkri/XPCm9PbmoHcXCRqVjaXl5Qlvot4 1YFwDbnobQPgw2RBW7qVG/mTcMaHToJ17ByTiYtamMmmkAyYUXi6wganyRUvLdNpuqSR mynmI/SGoZEdteBvLpBWSrl7x9M39eUcdefHVyzrvCdj/J85uhNZlG9DChjhAKJJShFo bVUZth8UMurwozCNBm0TRJnOxNRkLBlqeXdZupDpawqnW0lXdZaNP0ilI9s6LNIlcqln TJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755216759; x=1755821559; 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=5WU9voBHmtHCID+62ekjip+WsDaLPoXQ1Ho4KAjz+Bk=; b=vqkbYDJQnvwaKMLdNoUUF56AecAyH/Xujm4duAVuzaPnSQT1AMDcyD2JfM7RIf6ZHQ qO0ZGZ6BUF7nF1I3wbiaHkAEm+8Qvka9TZWOe9AihtVk/bo0wTAdUpXBcdI2f3/owQDe v3n+AJUm8bb8/k+5httYnmIWfzCGN7spofe1zT6GojteTDRj5zQ7WskmdHV/mgbAIMU7 xGq7YZ40/2phj2hmTGYlr0331/59blZ7YbKbFRrkKc/lr8ZLb/XwDezMnzAzpB20tTkG pc7J9P/UwjZ2YwngBpZpKkq0Ie+oFINh8LeRlNEhmNf0pDW4/zr60ZGe0EBNzzSRdgvI KQbA== X-Forwarded-Encrypted: i=1; AJvYcCXeaBHl6q6aatKo9pfPtZgxPB25T66nyT1sfsuPeMRoBaoTUEJjX/E8qBoc2/3b/G2+nTspNmVmgijTp/g=@vger.kernel.org X-Gm-Message-State: AOJu0Yz1UCRB9nuSfHnkn3up9kBQZbUJuBJ8sCTfGDvQ7jmDtEGn6Ve4 uA3s1e6jitzd4lwlyuWra3EE5ULO6Jd4H0P+1ogI5qiZ3xBBIka6c9T3t0Dt6xxDMWhunngOx3R VHVrzKQ== X-Google-Smtp-Source: AGHT+IHLp96Otjk1T4s0hj1MiompkYvxUqUTRUDczNOqtCXM0tJwB6ezd2X3zMPFXAvmZWvj66nHpW6DhT8= X-Received: from pgc14.prod.google.com ([2002:a05:6a02:2f8e:b0:b42:1052:52f5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:430d:b0:238:351a:6437 with SMTP id adf61e73a8af0-240d2f3f71bmr291638637.43.1755216758682; Thu, 14 Aug 2025 17:12:38 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 14 Aug 2025 17:11:59 -0700 In-Reply-To: <20250815001205.2370711-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: <20250815001205.2370711-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.rc1.163.g2494970778-goog Message-ID: <20250815001205.2370711-16-seanjc@google.com> Subject: [PATCH 6.1.y 15/21] KVM: x86: Convert vcpu_run()'s immediate exit param into a generic bitmap From: Sean Christopherson To: stable@vger.kernel.org, Greg Kroah-Hartman , Sasha Levin Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" [ Upstream commit 2478b1b220c49d25cb1c3f061ec4f9b351d9a131 ] Convert kvm_x86_ops.vcpu_run()'s "force_immediate_exit" boolean parameter into an a generic bitmap so that similar "take action" information can be passed to vendor code without creating a pile of boolean parameters. This will allow dropping kvm_x86_ops.set_dr6() in favor of a new flag, and will also allow for adding similar functionality for re-loading debugctl in the active VMCS. Opportunistically massage the TDX WARN and comment to prepare for adding more run_flags, all of which are expected to be mutually exclusive with TDX, i.e. should be WARNed on. No functional change intended. Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20250610232010.162191-3-seanjc@google.com Signed-off-by: Sean Christopherson [sean: drop TDX crud, account for lack of kvm_x86_call()] Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 6 +++++- arch/x86/kvm/svm/svm.c | 4 ++-- arch/x86/kvm/vmx/vmx.c | 3 ++- arch/x86/kvm/x86.c | 10 ++++++++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 86f3bd6601e7..1383f5e5238a 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1456,6 +1456,10 @@ static inline u16 kvm_lapic_irq_dest_mode(bool dest_= mode_logical) return dest_mode_logical ? APIC_DEST_LOGICAL : APIC_DEST_PHYSICAL; } =20 +enum kvm_x86_run_flags { + KVM_RUN_FORCE_IMMEDIATE_EXIT =3D BIT(0), +}; + struct kvm_x86_ops { const char *name; =20 @@ -1529,7 +1533,7 @@ struct kvm_x86_ops { =20 int (*vcpu_pre_run)(struct kvm_vcpu *vcpu); enum exit_fastpath_completion (*vcpu_run)(struct kvm_vcpu *vcpu, - bool force_immediate_exit); + u64 run_flags); int (*handle_exit)(struct kvm_vcpu *vcpu, enum exit_fastpath_completion exit_fastpath); int (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 12de50db401f..dc8a1b72d8ec 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4008,9 +4008,9 @@ static noinstr void svm_vcpu_enter_exit(struct kvm_vc= pu *vcpu, bool spec_ctrl_in guest_state_exit_irqoff(); } =20 -static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, - bool force_immediate_exit) +static __no_kcsan fastpath_t svm_vcpu_run(struct kvm_vcpu *vcpu, u64 run_f= lags) { + bool force_immediate_exit =3D run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT; struct vcpu_svm *svm =3D to_svm(vcpu); bool spec_ctrl_intercepted =3D msr_write_intercepted(vcpu, MSR_IA32_SPEC_= CTRL); =20 diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 179747d04edc..382f42200688 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7204,8 +7204,9 @@ static noinstr void vmx_vcpu_enter_exit(struct kvm_vc= pu *vcpu, guest_state_exit_irqoff(); } =20 -static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, bool force_immediate= _exit) +static fastpath_t vmx_vcpu_run(struct kvm_vcpu *vcpu, u64 run_flags) { + bool force_immediate_exit =3D run_flags & KVM_RUN_FORCE_IMMEDIATE_EXIT; struct vcpu_vmx *vmx =3D to_vmx(vcpu); unsigned long cr3, cr4; =20 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bc586a6df6ab..b9cc3c05590e 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10591,6 +10591,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) dm_request_for_irq_injection(vcpu) && kvm_cpu_accept_dm_intr(vcpu); fastpath_t exit_fastpath; + u64 run_flags; =20 bool req_immediate_exit =3D false; =20 @@ -10811,8 +10812,11 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) goto cancel_injection; } =20 - if (req_immediate_exit) + run_flags =3D 0; + if (req_immediate_exit) { + run_flags |=3D KVM_RUN_FORCE_IMMEDIATE_EXIT; kvm_make_request(KVM_REQ_EVENT, vcpu); + } =20 fpregs_assert_state_consistent(); if (test_thread_flag(TIF_NEED_FPU_LOAD)) @@ -10848,7 +10852,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) WARN_ON_ONCE((kvm_vcpu_apicv_activated(vcpu) !=3D kvm_vcpu_apicv_active(= vcpu)) && (kvm_get_apic_mode(vcpu) !=3D LAPIC_MODE_DISABLED)); =20 - exit_fastpath =3D static_call(kvm_x86_vcpu_run)(vcpu, req_immediate_exit= ); + exit_fastpath =3D static_call(kvm_x86_vcpu_run)(vcpu, run_flags); if (likely(exit_fastpath !=3D EXIT_FASTPATH_REENTER_GUEST)) break; =20 @@ -10860,6 +10864,8 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) break; } =20 + run_flags =3D 0; + /* Note, VM-Exits that go down the "slow" path are accounted below. */ ++vcpu->stat.exits; } --=20 2.51.0.rc1.163.g2494970778-goog