From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 117F134F47E for ; Fri, 6 Mar 2026 22:22:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772835736; cv=none; b=W+qkYSkLmhSYbe0+S2wEsGNK4mAkvlbedom0CGNoAQ8sOospY/Ln0NIHtQXNZPQnMRGHo6Qh7oas6TKURfu+nd+S2AKxcCFgiTN++09Cu6TMpGJzKIzCNwWkvNlrVbeGea/nnPFgJrIN4r5H08MIarJAuBA6RK+6atOMJB1mdow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772835736; c=relaxed/simple; bh=7y7bW0euFqRFl2pAT8uq9BnHtLvpcbHApIe+8yy8qz4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i86WmNBnSbFRhe+33RGMaI1dx/Aw0Rj9L0u34tlhKTlauc13OZ3b0f4Mj81V80IAXL6x2QrOoHQclm3/HNaFAB8olLee8tias7voTPTeRZOSmUGjeJr//igJ4rhoZIX6LoWkVrltaNHmRz1bmG7R7EbpK01EGXZOD72d4AW8ShM= 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=ARqtqvr7; arc=none smtp.client-ip=209.85.216.74 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="ARqtqvr7" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3598733bec0so29823518a91.2 for ; Fri, 06 Mar 2026 14:22:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1772835734; x=1773440534; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=WjbFTwqUIkgjoHiZRe9Sew4VJBm0utvvvEEjQeXLqkQ=; b=ARqtqvr7TTsTPHvyLbVk76rvCsuUfwfWbR/YjZ4pjDURmT/tfVGunA7IpJLdIFYOXY Z24fGQSJrB2adDghYnOj6H6lCpcsX0XypPfmjddahn+DYy95qIjtLsnS0dXvJawWtTCK +kCNH/I/I9ptRjODj/F2qQctV3ydmJBt5IPRMhtfYp3xT2q7vdNx4E3BQltE7U8MnB0X ZSwwC+5uU+9CluRviL83cGX/jxok43i41etayvBAi0La6uaOqajVThKTYVV3PhM83wfV Dcf/lT8BiTXM7dPWXeS778otmwwRXdb4ICyj1GGwckeAsg1E7f33j2cY52/fuExI+eaA mlUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772835734; x=1773440534; h=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; bh=WjbFTwqUIkgjoHiZRe9Sew4VJBm0utvvvEEjQeXLqkQ=; b=Aj8w0QjQiKXml3d/wzodqDyBu7/fqLCC7W0DG+g7ynQnrJqY/ShQ3raUUF6cqQD6qg DANkffgse4tZJK6f2WNG33+7o/mKItTzJUgdIUV6pajnaodiHdvP6LJzcC6drCzZEilK 1GdfJ7z202DIk87BMJLXDuVgHPhuCTDvmkye8HWwnOEENjIToA2JN+cr8TRuPb/SorpO WFoil+fqQ+fs9xFFK4fLzGtP0qb9BFzkkGCkjEZrD9zVvPuIlo1/ZMY06RCH6+/a/OXI AcJPWTUav2HFr5xj5+G2/CF/6Pb3KF8BjtclnUedgGYdqGnv8wVXnqYWjVBo6tgFiM4Z tJ8w== X-Forwarded-Encrypted: i=1; AJvYcCXku2ilG2/lk0zezjxLXQ3sTT9eohN6HvKh+tqxA21JfLSjjPf/oPcg0n6Fb1vewqFdexqMs+Szy0xPaSg=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9IK4of8f1UKWrs8QWR3gpY3O2VT/2tzt0MjVOcasNd8u4VSlO 1hqDHAjiBlNTbBnSbWnEQGdZvwKctwhCqPDiuBr6xXUi6rt0Gkx4pVAqv13O7TZrEvJ1czHuUTW lWK3tFw== X-Received: from pjam9.prod.google.com ([2002:a17:90a:1589:b0:359:96a8:84e7]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3f46:b0:354:c602:a573 with SMTP id 98e67ed59e1d1-359be31e12amr2753981a91.27.1772835734276; Fri, 06 Mar 2026 14:22:14 -0800 (PST) Date: Fri, 6 Mar 2026 14:22:12 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260219002241.2908563-1-seanjc@google.com> Message-ID: Subject: Re: [PATCH] KVM: x86/mmu: Don't create SPTEs for addresses that aren't mappable From: Sean Christopherson To: Yan Zhao Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Rick Edgecombe , Yosry Ahmed Content-Type: text/plain; charset="us-ascii" On Thu, Mar 05, 2026, Yan Zhao wrote: > On Wed, Feb 18, 2026 at 04:22:41PM -0800, Sean Christopherson wrote: > > Track the mask of guest physical address bits that can actually be mapped > > by a given MMU instance that utilizes TDP, and either exit to userspace > > with -EFAULT or go straight to emulation without creating an SPTE (for > > emulated MMIO) if KVM can't map the address. Attempting to create an SPTE > > can cause KVM to drop the unmappable bits, and thus install a bad SPTE. > > E.g. when starting a walk, the TDP MMU will round the GFN based on the > > root level, and drop the upper bits. > > > > Exit with -EFAULT in the unlikely scenario userspace is misbehaving and > > created a memslot that can't be addressed, e.g. if userspace installed > > memory above the guest.MAXPHYADDR defined in CPUID, as there's nothing KVM > > can do to make forward progress, and there _is_ a memslot for the address. > > For emulated MMIO, KVM can at least kick the bad address out to userspace > > via a normal MMIO exit. > > > > The flaw has existed for a very long time, and was exposed by commit > > 988da7820206 ("KVM: x86/tdp_mmu: WARN if PFN changes for spurious faults") > > thanks to a syzkaller program that prefaults memory at GPA 0x1000000000000 > > and then faults in memory at GPA 0x0 (the extra-large GPA gets wrapped to > > '0'). > If the scenario is: when ad bit is disabled, prefault memory at GPA 0x0, then > guest reads memory at GPA 0x1000000000000, would fast_page_fault() fix a wrong > wrapped sptep for GPA 0x1000000000000? > > Do we need to check fault->addr in fast_page_fault() as well? Ugh, yeah, good catch!