From nobody Sat Feb 7 18:28:49 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 68DFD1990D8 for ; Wed, 27 Nov 2024 23:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732751596; cv=none; b=eisMuC5zITLNIZ/NGywDyRAPg0B+R5YQSgAl4faFgbwqP7XSRnl9VZc7UVgaZxT8tXO3+N+OhAMb2UvN/6sC1/KWS/WO1UMUBDZfBRZfpZDgcl3KufzQfVu4WaUL7u5Npr6S6aiFZ1UlS9TKBred30vAWa+5fTjwbWDVzBJ3LaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732751596; c=relaxed/simple; bh=B+guaGM8zNDjHAblKR3rNrz7k+exZxvr6Z32NHXfp78=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=W9YLKF/s5kmpoEOHLc5KczIe9uISfZqhrtWRhHK5q2s+AQjyxwg+hZbgxk8sZ5uGnKnvN9GMNShcH8PvnD+bCn3AgA/yQ9qTTBF7ibzC4q0mkz7kTEvGixHMS7Jy5FK5ZaqS/Zc9tshWUf4aLaW6+Rq3cvu3ugzlMYRTRvMMT+A= 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=UVu59g6Z; arc=none smtp.client-ip=209.85.216.73 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="UVu59g6Z" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ea21082c99so226547a91.3 for ; Wed, 27 Nov 2024 15:53:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1732751595; x=1733356395; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:reply-to:from:to:cc :subject:date:message-id:reply-to; bh=jNdPCBLD98K20zOO6Bao1YI0NO02p0JCW7gr9Ds1ueM=; b=UVu59g6ZBOjQvWmBnPSDdqfB/5FbEBFQ+3yX5SJ+uNsP2Dh0zYhmJQySHJzHNfMeXD DMAr2Ewx0cShCHFdbn/Sl5aZaa6P/hr2zHc0ZJZI0+xuAuCaaMy1m2jk8kwl7bpeju4v q5E+aofuyJWb1xlQ/j7aqW7NjRmWiVZvXYMPuUN6vaIYuU0LqBJGDWmYZ3+AtdjgoIhW 9XRBsvSZZu7D0FY7aTIXms2+68IHv+VcA+4Bogof1q91Y/gBdqI1l8gPYMUtwhHxJ36l 1CpkwFv8qyPreRbPPjNoOeebrvDMowkTNTzmSXMzyXfyBp0AE9mCDTDxrK1hyCftGrrZ /szA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732751595; x=1733356395; h=cc:to:from:subject:message-id:mime-version:date:reply-to :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jNdPCBLD98K20zOO6Bao1YI0NO02p0JCW7gr9Ds1ueM=; b=CsomS2aUKDSZomBP7ER+EgbMjiziRck/Z/F5Q9ZKbXlHGpEHIKewTnayTFU2/8PcJI 1RrfpsDlzI0EwE7BipO6avCRJAgTSSBfbLku5EuoMtzV+nUE8Dns9xh+w+EIoev2N60K AgW+Yz6J2CoQaxsAvWPpDXMxoN7QGI9fWncL4iHTryUjrjp9t41y3yNP5TDjY2y/t7NI Y8EvGHul4ZGKfq/ulLDRwZskmqvaEkIjVLGv/0pRsP9Buisd/AzwihHJj+2d06c+gyWG hcPA9gfmLTONZD1hV/ePPweiu5pVxOBZ01D2T4L4qRsa03D6pptowP+1byZnvx/CW2pR DtHA== X-Forwarded-Encrypted: i=1; AJvYcCWiFZjxLwJCU6A4BYqPuatFEQWYyiRxLgvWx4YeJhiFOGv5nN6G6a5rbJNpT4ISOpotdbBMDnJJ/BoipFE=@vger.kernel.org X-Gm-Message-State: AOJu0Yw5Xd6XuW7QCICTwcdX2unos4R2bUGd5V9L2pioVhl37bvC6AnK cX2mXMQavq9vB0Hy8euNAS4Npi0WzDF5K75JZ+ASegYGeeZ8WsHi0yjTpbbg/3CaNovXtHa2NXE F4Q== X-Google-Smtp-Source: AGHT+IHR7A/TQXvzV6P238Oe4bPKg8Edeq87kZfXAl9SSGx/sR0jXBPGRSpiDg11scozZoz1hS5NEDgHQmo= X-Received: from pjtd6.prod.google.com ([2002:a17:90b:46:b0:2ea:c64d:fccb]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b51:b0:2ea:5054:6c44 with SMTP id 98e67ed59e1d1-2ee097e51b4mr6538986a91.31.1732751594839; Wed, 27 Nov 2024 15:53:14 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 27 Nov 2024 15:53:12 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241127235312.4048445-1-seanjc@google.com> Subject: [PATCH] KVM: SVM: Remove redundant TLB flush on guest CR4.PGE change From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop SVM's direct TLB flush when CR4.PGE is toggled and NPT is enabled, as KVM already guarantees TLBs are flushed appropriately. For the call from cr_trap(), kvm_post_set_cr4() requests TLB_FLUSH_GUEST (which is a superset of TLB_FLUSH_CURRENT) when CR4.PGE is toggled, regardless of whether or not KVM is using TDP. The calls from nested_vmcb02_prepare_save() and nested_svm_vmexit() are checking guest (L2) vs. host (L1) CR4, and so a flush is unnecessary as L2 is defined to use a different ASID (from L1's perspective). Lastly, the call from svm_set_cr0() passes in the current CR4 value, i.e. can't toggle PGE. Signed-off-by: Sean Christopherson --- arch/x86/kvm/svm/svm.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index dd15cc635655..f39724bf26be 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -284,8 +284,6 @@ u32 svm_msrpm_offset(u32 msr) return MSR_INVALID; } =20 -static void svm_flush_tlb_current(struct kvm_vcpu *vcpu); - static int get_npt_level(void) { #ifdef CONFIG_X86_64 @@ -1921,9 +1919,6 @@ void svm_set_cr4(struct kvm_vcpu *vcpu, unsigned long= cr4) unsigned long host_cr4_mce =3D cr4_read_shadow() & X86_CR4_MCE; unsigned long old_cr4 =3D vcpu->arch.cr4; =20 - if (npt_enabled && ((old_cr4 ^ cr4) & X86_CR4_PGE)) - svm_flush_tlb_current(vcpu); - vcpu->arch.cr4 =3D cr4; if (!npt_enabled) { cr4 |=3D X86_CR4_PAE; base-commit: 4d911c7abee56771b0219a9fbf0120d06bdc9c14 --=20 2.47.0.338.g60cca15819-goog