From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) (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 56BAE2E7391 for ; Fri, 7 Aug 2026 22:18:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786141109; cv=none; b=CskhmqlqbgfnEguuvnzz4VucQCXsi718SoC9jgYYRLKST2HSXS1xH6ha1D8hDXC9Np7IGPx4xK8ILR/Sb/9SPZzQBhn1e2ZlSvW4BRi3bN5DrNMkYsgOFF0iPb4k0ZE2sMMtEcGAmEJDu19EtdXEaCPIIFY8yWb0rrNugfXEtc8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786141109; c=relaxed/simple; bh=UaZLKKYAR0Bykvjw7Qw7kvekD6nDm2+d1Ld06FHPdAo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Mb6/x9kgWWWDQ/kLHYGKriFqJGWsG1CMQY5PEdvkcHpXHWFcteWwDidohRm5Oe+XeddhceRP/kKRbDlWO4/eI7N7z2njimEEC8g/V8ENVVgOX5ae5I7Ifwj1wALv+vAMspu3u0bhLPWoA6wuY9w2kKR37jKxbus3WOWWa9uVZ2Q= 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=k5dPZ4XQ; arc=none smtp.client-ip=209.85.210.198 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="k5dPZ4XQ" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-8488ac68185so56175b3a.2 for ; Fri, 07 Aug 2026 15:18:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786141107; x=1786745907; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=lbAbat6Q7esV8SJCpy/SV9WJwrsxxo4l4sIA0GuCoM0=; b=k5dPZ4XQ7LnhelJL9zvtHR5ynb3Mh+TXa7YG2Ea9uTZOJDiXMjpTWaTFvjdVFbQvxc Fj7BEQgR/TM1zqteaLvRuTs/5fxSy2U7oPr5Z37if0QyFbuYNHo0CjJoHOUz1IZogBWb pW51gURip6vhOhWQhNSuqmkw4BNe6YWNJnuCRjBFHIFcAT8e3ahCYPooMz4z+v3fSdoB zEOSzabSW9RQ4jvBp5fOIgZ/WWdfqCdEmhVFuNiyKESmCfPAIx0noShABraMrmgSea+T /Y3PYuakp7c+NqpeA6Ge6GUcS3X271mWuWvesNPsQAdVaYB1YMZynr70hYvE3Zc7sNUW /cxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786141107; x=1786745907; h=content-transfer-encoding:content-type:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=lbAbat6Q7esV8SJCpy/SV9WJwrsxxo4l4sIA0GuCoM0=; b=eJ0CTCmqxwUFoxu8WjaSHV8vdH7JH0w7KD0XNfuaWMLw0Vd1EjlLSbCHu8p9+IHWf1 U6yQDOYRz6MT94hMnDloU4BRzB8CuEgTXsYv9g+PDfhCiVqYNmR/W1mMqiGCpF751ADa SDEwkuYCMY+N1aXqLR66oSj7vQmpdoHHJMKmKSDH6KrWP0aBfvHb871V3DZ8322zapp1 5ZAcUhWgUzNdzPoKN+IQOtrMp1N1Tt21s96vNIO+155Z7PtIWXHX2wWdxZcMrVjbY67q ny1mZu0CFnyZcGmdO5hGDkwbPRJpXkCZiZy5qEGVmZwTHWMPHaBNCBPpQTGtRXlx0Tp8 /2Pg== X-Forwarded-Encrypted: i=1; AHgh+RozT/iimP/7RTruDLh2wHpmRgVsBxCd4EdGOwe7W/002kxBBjRSDUAMVEDw8VlipwSNOiGCTRdoqA0f3EQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxWZLbHVeIBl96zOTDp/keJIFifFW1sD1UNbm+rbOcZLo6J7yCK 5k/+NoKkmy1sgUf9ZPNmE9IOLEr3YQV6QFpSIoSE4gfiyArQfspV3BI+krW2EKXL2vRtmLt/um6 JWbeE2Q== X-Received: from pfbgh5.prod.google.com ([2002:a05:6a00:6385:b0:845:48ff:3362]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:987:b0:847:8b1d:230d with SMTP id d2e1a72fcca58-84f69421bcamr3113008b3a.3.1786141107295; Fri, 07 Aug 2026 15:18:27 -0700 (PDT) Date: Fri, 7 Aug 2026 15:18:26 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260806214050.78058-1-seanjc@google.com> <20260806214050.78058-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH 2/4] KVM: x86/mmu: Harden "map private PFN" against unexpected root invalidation From: Sean Christopherson To: Rick P Edgecombe Cc: "pbonzini@redhat.com" , "sashiko-bot@kernel.org" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Kai Huang , Yan Y Zhao Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Fri, Aug 07, 2026, Rick P Edgecombe wrote: > On Thu, 2026-08-06 at 14:40 -0700, Sean Christopherson wrote: > > @@ -5199,10 +5195,21 @@ int kvm_tdp_mmu_map_private_pfn(struct kvm_vcpu= *vcpu, gfn_t gfn, kvm_pfn_t pfn) > > =C2=A0 if (kvm_test_request(KVM_REQ_VM_DEAD, vcpu)) > > =C2=A0 return -EIO; > > =C2=A0 > > + r =3D kvm_mmu_reload(vcpu); > > + if (r) > > + return r; > > + > > =C2=A0 cond_resched(); > > =C2=A0 > > =C2=A0 guard(read_lock)(&kvm->mmu_lock); > > =C2=A0 > > + /* > > + * Because slots_lock is held, it should be impossible for roots > > + * to be invalidated after the initial MMU reload.=C2=A0 WARN, but > > + * continue and re-reload the MMU to try and keep the VM alive. > > + */ >=20 > It might be a little confusing when no MMU reload follows the comment. Ma= ybe > mention that the MMU reload is above? Either way ok to me. Yeah, I don't love the comment either. The subtlety that it doesn't captur= e is that KVM_REQ_MMU_FREE_OBSOLETE_ROOTS doesn't actually mean the current root= is invalid, just that it might be invalid and the vCPU needs to check. How about this? =20 /* * Because slots_lock is held, it should be impossible for *any* * roots to be invalidated after the initial MMU reload. WARN, * but continue on; the above MMU reload will do the right thing * if the current root is actually invalid. */ > > + WARN_ON_ONCE(kvm_test_request(KVM_REQ_MMU_FREE_OBSOLETE_ROOTS, vcpu)= ); > > + > > =C2=A0 r =3D kvm_tdp_mmu_map(vcpu, &fault); >=20