From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.202]) (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 BBF1E42848C for ; Wed, 27 May 2026 18:11:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779905487; cv=none; b=dJ0nNTUIJlI2U2dWdSMbL1lrMjkZbZLSWWSZaENmQGgeCOZme7kbGSBESv9tFJc4uJXoHwPWAb2LPNIkAY1x2mLQp5rknNiwmr3UrpeeFiAOu2HgTkN4QNxWVsoYEST5D4nw/BvWunt2LnxXczT5pxJbbPx8reLI+6KTvHNA6yY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779905487; c=relaxed/simple; bh=IZFrK7tQIvwtaqTUasFtZOb5QzjdQsOZURjmtFwyMTI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OpR5O2McL9A3Gt6qYDHKID1foCjvg613jyCxu4ZWloV1yjq8limzSaTyW9omfGglClWqZCFkLLW5P+jVdQDB8gQiDZpWcdTm6BUQAzRw8v+wt+x9keN3ZI35Scoe0ttdzKOHOrzwdpzXnkdlmH0avq7fUsdoOw5hDR1qcZivTYU= 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=VxZeMbxN; arc=none smtp.client-ip=209.85.210.202 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="VxZeMbxN" Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-83f7e7f7457so7653437b3a.1 for ; Wed, 27 May 2026 11:11:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1779905485; x=1780510285; 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=ZDvpxyzxmPMbzZEEHttxBwP/pTbHExob+ts2PActBeg=; b=VxZeMbxN7YTRz4gAlsjAuhZjQlTlc8f9GdunG10x+bz0PeKUFR6Fuy5H91feFTu+Ax W1gO6qzF1HZpht8VmQTgqakdMhUlk/z4Y2O9TQhg7mvji+R4Js6duG2ifkYT+C68lnIR IbotwV88/6Frr6B0TP9osyubLsra+BnhulOO3R0l/wWt7U/+W/g6guqmb+SbVpME7NMM wMKx1eQf2Wfuj6HvYpoQMYhyCkJ1f1QPsfbVJOr3oNHXYOj6m+g/CixN+7d7Crk3/ltp nNKWpEN3h+lUCkahZAHkUUCU5qjwr1WtGEC91/t4nKUlx7AU0sd6ZQ0aHb+CCyapFTqI S+Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779905485; x=1780510285; 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=ZDvpxyzxmPMbzZEEHttxBwP/pTbHExob+ts2PActBeg=; b=fO/VAlMQDXCNkzXR/hW8eCjUT5lSAfw1bICYgpDegnw+l8cpRkV7I9MKpQhdr2XKzg yQ1euftWGVhx2Rs4kKJJmIh6ur9eFpW0G4PMjIX0D46YGGfOrAW8lONtYZZXoLs/7mPr sy5XU1vysbCRjxnOkAGhcHPYj6RhLtow59qHnmuE7vPRJrc6VRSCwzPguk46doYenqzk 2fynzW7aPOVZyTqocmA/6j8D0gHx8R9bsJsLm9JaVkk0U4opivQOQosOJeIMmwsX7WO4 XsAUwn7o8MX4dedY0SjWyJ7pHDQnZXUBahex5XyTg65P7bIP17CyAAPPqGGLF7zIVLn3 fTcw== X-Forwarded-Encrypted: i=1; AFNElJ/v3pqCkikdy6RJLv7OILLt4i2o+O1ACn+5IuoJCwJ1JA++xwNyXjvmQELTsDscSmW61fwEkTyD2PAFWAA=@vger.kernel.org X-Gm-Message-State: AOJu0YyAdZ1RyIumlnGMNw9adKQnUFmsGUeK4VZ76McTyIOrlW1959c5 Pxx/1Q9h5n4+L9g6jHJWGFLq42ESWyqeiDUpTUE+6LlOsy7e3UncLhPv3QIFaywyQ9kM3xel+OM qXlj++g== X-Received: from pgju14.prod.google.com ([2002:a63:f64e:0:b0:c79:8241:6660]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:1518:b0:3a2:edff:2975 with SMTP id adf61e73a8af0-3b3297b0e28mr18720855637.25.1779905484895; Wed, 27 May 2026 11:11:24 -0700 (PDT) Date: Wed, 27 May 2026 11:11:24 -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 Tue, May 26, 2026 at 11:48=E2=80=AFAM Sean Christopherson wrote: > > > > 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= fault > > > > 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_fa= ult *fault); > > > > void (*inject_page_fault)(struct kvm_vcpu *vcpu, > > > > - struct x86_exception *fault); > > > > + struct x86_exception *fault, > > > > + bool from_hardware); > > > > > > 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= Violation > > 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 th= e MMIO > > access then hits a TDP fault, e.g. because L2 was accessing MMIO with a= MOVQ > > (memory-to-memory move), or because L1 has since unmapped the code stre= am, then > > the TDP fault synthesized to L1 will not be the "same" fault the trigge= red the > > VM-Exit. >=20 > Interesting, thanks for the example. Probably worth documenting this > somewhere (changelog? comment?). I added a version of the above to the changelog.