From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (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 ED7523BB661 for ; Tue, 26 May 2026 18:48:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779821329; cv=none; b=Kp5JewLrHSpF5K+4AH7GVd5y/Xdd/ApBAfTpaOvK3prtrLVmo8Y2j39PQdRygR5Ohi6M7z9ipqGfC6jALONL5TJNJwNlA23Yb7TCvGAwJHm1IiNLLQHBSgYSwvn4nJ3GN28/6giERAOfGQDhkARr6HrTlb6RRZKPMwLg94zqwAg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779821329; c=relaxed/simple; bh=qH5ydZTL16aqqrXJxD8FORHctjtluuXD7zvUAHgMGoE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=q+mNFRhWhBnLmwE1K2wiQ9KpswGNdLcmsbYVYQES6xFd7X3JINRFDynKktQOE/GAeCrioPzqS1heocJSOE1aMxj97Sytuqn/qDdDvBCwyf/sYjDfV5To+C9H+Ge5xdyWgcmEBcd6udmo6M27JK14Yp1U2ZshdLwYZQNfRvFQhyE= 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=ScgxQvip; arc=none smtp.client-ip=209.85.215.201 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="ScgxQvip" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-c8294d8c48eso6924389a12.0 for ; Tue, 26 May 2026 11:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779821326; x=1780426126; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=hXup8dSlnszi+d3/erXjPvvWu01OYaVmB0HkJAin+e4=; b=ScgxQvipuveEujwv/F0CPcC4Dsb6oPIHtakCFi7l3yC+1EvNg+tF1UTsUKTS8s1RIM YdIZ/fTX8GODZuXAjJxP+fLeYKYytLiyFYm0PyqbNk/hP3G5w4dlWoHeOipLf5SVl8OJ e6c1FQWMmEKTWKrMKsjSi1lqhXoeLfKD9GknZiuQ2oouXN1G/rp5UEJSlGr8mSnk2CUu YUVfD7Z3BYI3gFrpqbzKXHojErlIYZVEDurgyCXDbTmHobhoSoy537Y+ARjJsqJ/KrpL e8wMkIGslIE9ah7Q4UcGqMeBiTRF4Skke1Ma67KpoWZhk8W/HXvQ7IhZH1WfqE10r0QY AyTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779821326; x=1780426126; h=content-transfer-encoding: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=hXup8dSlnszi+d3/erXjPvvWu01OYaVmB0HkJAin+e4=; b=s0VYYawOkmiOXjsx3tJ2oiSMo0BHAd2WUfokjDCUH8diogLUjDThGW9AkAV43wWjo1 L+0XjK5qxm0w8U7CQRJNZ2xh9gBZVzbcDHdlSvIKomAzUQk5j4eCuW4e+stU/K4jbSpm XXgvlqmuyt22s9PWXu0cmCICS4W+xuwC3sztTSqxq9fTFT2sDdagXASPRLaWfYfx2sja 0S9zexhjRT6RF7JhB2YcfT6zCyPRdlUktz/0S9vmEmmc6QeJ0EQ3T0hReRunSxOwqOUj accioZcnJRA7Non1sMN/rmh70Wl/t9XqyDCOhGXwuFjpn0NkMq5avPgAtRJumZUfedc7 SRMQ== X-Forwarded-Encrypted: i=1; AFNElJ/swK3h2DrdF52PLeUJqFx73rUApYTDSjWYG+j/FTKtpGWWNJ0Fgk/RZdyiZyVCzID+JFXXe20QNT3oHqI=@vger.kernel.org X-Gm-Message-State: AOJu0YyAd2BENB8SM1XzoQWT/x9By4xDjaY/9Q6mF5rSswTAlXbWVLeu KFDx1cfPlNHzGCYFtFWmby6bbNj2OBpS2Cn3pQbohR0MHftQ+JbSyVz/OZ7gtVEicbiHDx0Vd7w A1tw3PA== X-Received: from pgi186.prod.google.com ([2002:a63:8c3:0:b0:c79:71c6:fd98]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6f15:b0:3a2:d53f:6915 with SMTP id adf61e73a8af0-3b328c6f316mr19943021637.10.1779821326138; Tue, 26 May 2026 11:48:46 -0700 (PDT) Date: Tue, 26 May 2026 11:48:45 -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: <20260522232701.3671446-1-seanjc@google.com> <20260522232701.3671446-3-seanjc@google.com> Message-ID: Subject: Re: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware From: Sean Christopherson To: Yosry Ahmed Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kevin Cheng Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Tue, May 26, 2026, Yosry Ahmed wrote: > On Fri, May 22, 2026 at 4:27=E2=80=AFPM Sean Christopherson wrote: > > > > When injecting a page fault (including nested TDP faults into L1), tell= the > > injection routine whether or not the fault originated in hardware, i.e.= if > > KVM is effectively forwarding a fault it intercept. For nested TDP fau= lt > > injection, KVM needs to grab PAGE_WALK vs. GUEST_FINAL information from= the > > VMCB/VMCS, _if_ the fault originated in hardware. > > > > No functional change intended (nothing uses the new param, yet...). > > > > Signed-off-by: Sean Christopherson > > --- > > arch/x86/include/asm/kvm_host.h | 18 ++++++++++++++---- > > arch/x86/kvm/mmu/paging_tmpl.h | 2 +- > > arch/x86/kvm/svm/nested.c | 3 ++- > > arch/x86/kvm/vmx/nested.c | 3 ++- > > arch/x86/kvm/x86.c | 16 +++++++++------- > > 5 files changed, 28 insertions(+), 14 deletions(-) > > > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm= _host.h > > index 271bdd109a98..d11063c36f03 100644 > > --- a/arch/x86/include/asm/kvm_host.h > > +++ b/arch/x86/include/asm/kvm_host.h > > @@ -484,7 +484,8 @@ struct kvm_mmu { > > u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index); > > int (*page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault = *fault); > > void (*inject_page_fault)(struct kvm_vcpu *vcpu, > > - struct x86_exception *fault); > > + struct x86_exception *fault, > > + bool from_hardware); >=20 > Probably a bit late to ask this question, but why do we need > from_hardware (or the previous hardware_nested_page_fault) as opposed > to just checking exit_code / exit_reason? Is it possible to get an > NPF/EPT violation but then synthesize a different one into L1 rather > than forwarding the one we got from HW? Yes. E.g. if access to emulated MMIO from L2 hit a !PRESENT fault (EPT Vio= lation or #NPF), e.g. because MMIO caching is disabled or it's the first time the = GPA has been accessed by L2, then KVM will enter the emulator. If emulating the MM= IO access then hits a TDP fault, e.g. because L2 was accessing MMIO with a MOV= Q (memory-to-memory move), or because L1 has since unmapped the code stream, = then the TDP fault synthesized to L1 will not be the "same" fault the triggered = the VM-Exit.