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 9FE014399CD for ; Mon, 17 Aug 2026 13:37:43 +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=1786973866; cv=none; b=GHuHBT7hUsXbibeiywokM5jaicVHV6qKAy2j55NYhxZQ7/fVeZ7MSSqxr8j4WhCFcoEoT4jE3mFG8wp9VUZftWEstCmJHbqDDsoBb7YauApUGrqUEJ4iWC1/Q6jLr6lskzPn13JAfhBCsdWfF59tWTu6CugfxIqr7y+TgpG4lcM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786973866; c=relaxed/simple; bh=30ZTbT56GY9AkmmdBy2y8tmHdsCkpJYYneFiHFc6OMg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Q6qJKK4uetR6RDfV+3xSm88UTqu0S6muG4SXkiFsDIhRpyBkdexvwhGJOF4AlcMykpONZmYpujC3WoXMeLTm/mVU1I40Bav8j2BOr1DsCeVF3SIO1SumAbdOPKg8cfpta8nKgMxqDszJ9ARDcZUmAI/MuPRJJmfxhV1LrpUKHQU= 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=m0Rw9Ght; 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="m0Rw9Ght" Received: by mail-pf1-f198.google.com with SMTP id d2e1a72fcca58-84e4ef486c7so3035329b3a.1 for ; Mon, 17 Aug 2026 06:37:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786973862; x=1787578662; darn=vger.kernel.org; h=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=BB4bAflOhpYzRfZSR0NX17xoh05DYymUXAZR8QHYHVg=; b=m0Rw9GhtVGid90pdmPTInFeCJGNu/ky3kQA+Nj4nhRuIis6eYWj9CpsQKv8oJ5xauD PUKJefaQiVxyPgrFEgnER/x86Civ8AKW6BIVnrUeNgU69x3GPYhboa9pRiYKELULUBcx E67TcGYFqUS/qNCk5frrzeyzOLNiXm4U0oXHFj7pzNPbooqp3vG2mBDg8xqfarbthPGf DLIhkiHLiJVfVZeurEIZ5R/f4S9SOi95iMVTaNJL8ciexONGojq3HR0NSWF4yIicffXO FQ0XS+jHC/BRh/OmygG0Kmj/1dwDF7LaZ/MUsMA+KAQrbGLJzusU3GV1smfi89rTuGpx VxmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786973862; x=1787578662; h=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=BB4bAflOhpYzRfZSR0NX17xoh05DYymUXAZR8QHYHVg=; b=X+noIrDNU7vXMEtU5F2InWY0+oAH5nEGwTlqVd/jcCE6TTus4MbXgHgx0ZCSlTMKWI mREvTTQZaMBn6EWCocdRIb4px6AWKH28K7h+y/TO66DG2VHkFBmmtmTXNo5FirM8fp9G x8ZA8K2EZmifr/GnYt8lh+ohsW/X0+sz5iaR5GajdNUsqvFztKadcx34QybH2+SH25r6 OM9VdJz4B1//A5h9whfBtQh5Pv7Ym9auUShqgQYE8UQ1iA/IiYs6kD9QwO3Dyi+Jbvk2 XnuFsoXKXljTAT/AdRit5bjXLL3QBggMYPqzirndtJ8S83HFZDFTASQSgFu32W8rIfev gwrw== X-Forwarded-Encrypted: i=1; AHgh+RrolRUE8wHmJodnLAl56OC6Szq3Rzzx/mLnjxFHQVo/UEuLMxCnMzectFF7U44jCwvWRELi6oA8YFnd1dY=@vger.kernel.org X-Gm-Message-State: AOJu0YxDjGsn/c0eGtIOMWeCKc06SoZbjCAlsp2qRAOZOZcj75pO1w3n bSX1V77oI4+qM+LSEsocnhU3WzDPMgaGVT/e76ZLvMub0NH50CvJERoifB9lg6Zr8eTHPrWC40J K7nW5JA== X-Received: from pfam7.prod.google.com ([2002:aa7:8a07:0:b0:847:926b:dc15]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2d11:b0:847:9d6c:a56d with SMTP id d2e1a72fcca58-84fdc77a25emr17322479b3a.12.1786973861885; Mon, 17 Aug 2026 06:37:41 -0700 (PDT) Date: Mon, 17 Aug 2026 06:37:39 -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: Yan Zhao Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang , Rick Edgecombe , Sashiko Bot Content-Type: text/plain; charset="us-ascii" On Mon, Aug 17, 2026, Yan Zhao wrote: > On Tue, Aug 11, 2026 at 10:07:41AM -0700, Sean Christopherson wrote: > > On Tue, Aug 11, 2026, Yan Zhao wrote: > > > On Thu, Aug 06, 2026 at 02:40:48PM -0700, Sean Christopherson wrote: > > > > Move kvm_tdp_mmu_map_private_pfn()'s reload of the MMU into its tight loop > > > > so that an unexpected root invalidation has a better chance of being > > > > handled gracefully, even though it should be impossible for the vCPU's root > > > > to be invalidated after the initial reload. As is, encountering an invalid > > > > root is *guaranteed* to put the task into an infinite loop (albeit a > > > > breakable loop that honors NEED_RESCHED). > > > Note: without the newly added is_page_fault_stale() check in patch 4, an invalid > > > root would not put the task into an infinite loop :) > > > > > > BTW: As noted in [1], is_page_fault_stale() only checks !mirror roots, and > > > kvm_mmu_reload() reloads mirror roots only when !mirror roots are also invalid, > > > since an invalid mirror root was considered impossible. (up to now, no?) > > > > > > [1] https://lore.kernel.org/all/anrD8nI8RfYoNvbf@yzhao56-desk.sh.intel.com > > > > > > Add a WARN to try and detect bugs that break KVM's expectations, along with > > > > a comment to explain why it should be impossible for the root to be > > > > invalidated. > > > And there's already a warning in kvm_tdp_mmu_map(): > > > "KVM_MMU_WARN_ON(!root || root->role.invalid);". > > > So the warning also seems redundant. > > > > No, KVM_REQ_MMU_FREE_OBSOLETE_ROOTS can be pending even if the current root is > > valid. And once the is_page_fault_stale() check comes along, the WARN in > > kvm_tdp_mmu_map() is effectively unreachable. The patch ordering is weird, but > > there wasn't a great solution because adding is_page_fault_stale() first would > > create an obvious infinite loop. > Ok. When KVM_REQ_MMU_FREE_OBSOLETE_ROOTS is pending, it is only for direct roots. No? KVM_REQ_MMU_FREE_OBSOLETE_ROOTS is also used by the shadow MMU, in __kvm_mmu_prepare_zap_page() and in FNAME(fetch). Or did I misunderstand the question? > This patch still holds that assumption true, right? > > If so, since mirror roots cannot be invalid after the first reload, any > subsequent kvm_mmu_reload() calls triggered later in the loop would only reload > direct roots. > > Is this necessary for kvm_tdp_mmu_map_private_pfn(), which only maps private pfn? > Or is the purpose of this patch simply to avoid the potential infinite loop > after patch 4? Yes, though I would still want this change even without patch 4, as there are no guarantees that KVM won't gain an equivalent check in kvm_tdp_mmu_map() in the future, e.g. as hardening.