From nobody Thu Dec 18 07:11:28 2025 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F08461F8733 for ; Thu, 13 Mar 2025 21:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741902964; cv=none; b=XE0ZJrIXmPJm0Uu4Ancc8MWDOoHfDH0c6EB4lsn7XwSF+m2LfruGRosHlwODXpEmt+6umcBCUVl/kJCRNWtvOn3Po7OJcR8JcxHUmK8Af/9RbijhRuVh3++zy/zfSH1/wLa77cbrmTlKER0tTOYpwaWGMMUqTQAXmpkKiakLUhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741902964; c=relaxed/simple; bh=hurQQCC+/qgM2ttjbpMEz4DnkjDjk25e6iRgNLhdD30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etdSwH0So1E8H3xLPSGCznLkgMFvPjlqmQ1okrnKSG9LdvIhadtYnr2XLyQ1oOGwnVhSmF20B9y5doFwjhoceLe77dSMaL1M4Hr8faFlXwh6p5ywfP3dHQZU67V+3P1RUALOamccgokWxe6YHLcwai+pPkL4gsaIQ15IEcpiHNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=FEjMtT3g; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="FEjMtT3g" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1741902961; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+bUxD6QRzJrIqWxcl0ag34BYxXxitzR3TXEhcC1owgE=; b=FEjMtT3gYSKmRfUz+g9jxHgt0JRf9SEPGgBg7xgoW+dNlDT5t4R1vdrt5no6wOylDjXHke +BoK1+o1TIPyPZUX0D6mffw6M2nbfMlPN1o4KeL9UoYzgf8afC/gqr8OmfHIYOVEgm6g8q 6ebn/RcZEWGFQezjDUb8oi7S9tkKriM= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Maxim Levitsky , x86@kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH 4/7] KVM: SVM: Flush everything if FLUSHBYASID is not available Date: Thu, 13 Mar 2025 21:55:37 +0000 Message-ID: <20250313215540.4171762-5-yosry.ahmed@linux.dev> In-Reply-To: <20250313215540.4171762-1-yosry.ahmed@linux.dev> References: <20250313215540.4171762-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Currently, if FLUSHBYASID is not available when performing a TLB flush, the fallback is decrementing the ASID generation to trigger allocating a new ASID. In preparation for using a static ASID per VM, just fallback to flushing everything if FLUSHBYASID is not available. This is probably worse from a performance perspective, but FLUSHBYASID has been around for ~15 years and it's not worth carrying the complexity. The fallback logic is moved within svm_vmcb_set_flush_asid(), as more callers will be added and will need the fallback as well. Suggested-by: Sean Christopherson Signed-off-by: Yosry Ahmed --- arch/x86/kvm/svm/svm.c | 5 +---- arch/x86/kvm/svm/svm.h | 5 ++++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8c90686a33f44..e5064fbefb822 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4005,10 +4005,7 @@ static void svm_flush_tlb_asid(struct kvm_vcpu *vcpu) * unconditionally does a TLB flush on both nested VM-Enter and nested * VM-Exit (via kvm_mmu_reset_context()). */ - if (static_cpu_has(X86_FEATURE_FLUSHBYASID)) - svm_vmcb_set_flush_asid(svm->vmcb); - else - svm->current_vmcb->asid_generation--; + svm_vmcb_set_flush_asid(svm->vmcb); } =20 static void svm_flush_tlb_current(struct kvm_vcpu *vcpu) diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 9fd5b249b9c19..0f6426809e1b9 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -645,7 +645,10 @@ void svm_complete_interrupt_delivery(struct kvm_vcpu *= vcpu, int delivery_mode, =20 static inline void svm_vmcb_set_flush_asid(struct vmcb *vmcb) { - vmcb->control.tlb_ctl =3D TLB_CONTROL_FLUSH_ASID; + if (static_cpu_has(X86_FEATURE_FLUSHBYASID)) + vmcb->control.tlb_ctl =3D TLB_CONTROL_FLUSH_ASID; + else + vmcb->control.tlb_ctl =3D TLB_CONTROL_FLUSH_ALL_ASID; } =20 static inline void svm_vmcb_clear_flush_asid(struct vmcb *vmcb) --=20 2.49.0.rc1.451.g8f38331e32-goog