From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.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 564E22AF1B for ; Wed, 21 Jan 2026 00:49:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768956552; cv=none; b=GIFW/FzvpghrYLFr26ykJHcbUHhwhQnAWQWhPfKykYHYxBMK4PXeWGED+o/jzJcYuX73RrmT0t/WdLns1gwkOe9e4KvO0hEnxo4HYCf6UO0NVDo7th8i5ivQPdK1hclK/ElAaWJeQYv/iInMI9Izp3be3ScgcIPCj6JAQh/EN9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768956552; c=relaxed/simple; bh=9j2viwc1zDrFmOD8zGiRuaIRwVAFEMbh/MRAdfXkeGo=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=esAYVWv0X7yuhmC+XQmSC0ot+nRz9oayHt8EJg/8j6sZ1/aw6qab67SZ9Syvx7yd7abfbDqdb/NS4kCAYYvHyXWjVTYzHBy/7/PhLsdpny/vX/O6+8gOEEXJ8zZ7dF6LcTC0DZtq/R+CjbfR+BCAb1EgSFPY+Y2sJFfo+ESEuL4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--chengkev.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=y54rM0ox; arc=none smtp.client-ip=209.85.214.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--chengkev.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="y54rM0ox" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a7701b6328so17916905ad.2 for ; Tue, 20 Jan 2026 16:49:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768956550; x=1769561350; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=bqs8q2npJfseM6OyP1kL552rWw1NXKbYV/GgcDPI09A=; b=y54rM0oxkVCJ1ZrLjPbgpYqLW8TT1WmFjWsZFy33/9Gly6BB7BWqZbduKEYDdzNuA2 9bqIz0reNcPgDFDAyIZQ+vL1xvOpcl6h8LJ8FXx5KgiZ44Ow7bZWlZDMqzt8SQp6v/Ih cv8t7WqGXrEzUpi2nmy4Es2hyUfTD9gC45TjAp7Wl8AKEXQqIaTvPD9RLp16XqVIlXX+ too0FO9gd+IAqpmjVV22sl1p4V7sfwEWDJ+Tk+H2BsQ7QzxpPWItIhjx+zSem3koVNBK 7m8t6hYFk21gMOxNmDBRMp1QDffZN97niAz3azMNtfix9x6YV4FjDyHu0LVdq4ABoYnh rELw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768956550; x=1769561350; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=bqs8q2npJfseM6OyP1kL552rWw1NXKbYV/GgcDPI09A=; b=trlLc8PObsot54Uj/62spaiF9xcH13ZLxQsLpQJjk5mvWP88qrr9kEI7IyOmz+4CNl q8KOPnXXC6r7dWqwO1NRn49JCCwPgXaNQSMgU1jkgy9SkpmJWsCOcx0jL6DfjGgy21u3 QcGk8ePfG5nz2te2KBYtUje29rA93EFPK/HrUN12cVG3Ec7Osh14VKZGVTW7BCmcWHRP 7Fq1SGPnUWCtYuPEc6snEikg34hUwhc9pbSfPWd4ngaPvdADhp77j44MO+nwSOn87ABG bywBZiUoxd0rDONqcT2Plc/MMhZ9KH4Eo6VbLEqrdv8O/THkqxFzGMVdLsZDnLhucdRk 7M8Q== X-Forwarded-Encrypted: i=1; AJvYcCWRyTZSievLCd7LJyZyIXP7XK8HBnkW5XgvBKs8BOoxAYBvsMOeRoy9te9V3CheDq4aD1bDfpsyOqBjs8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YzrxxW6IgMGuUWoSHnZSXh4uP621v/dT1Mympp5MKeQdpfQCz+4 IZTQrJ6Bg8qkxEhRnhbLw4HoGELGJ6pmb+hJ/IlBtT0S9YWN6F2SdNcxQRc1e+U0YLhTypQ8z6w pCrZEEjoegr8mbA== X-Received: from pjbmp11.prod.google.com ([2002:a17:90b:190b:b0:352:e2af:ed76]) (user=chengkev job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:1aab:b0:29e:e925:1abb with SMTP id d9443c01a7336-2a7698f853fmr31175025ad.27.1768956550644; Tue, 20 Jan 2026 16:49:10 -0800 (PST) Date: Wed, 21 Jan 2026 00:49:03 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260121004906.2373989-1-chengkev@google.com> Subject: [PATCH 0/3] KVM: SVM: Set PFERR_GUEST_{PAGE,FINAL}_MASK for nested NPF and add selftest From: Kevin Cheng To: seanjc@google.com, pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, yosry.ahmed@linux.dev, Kevin Cheng Content-Type: text/plain; charset="UTF-8" This series fixes the setting of PFERR_GUEST_PAGE_MASK and PFERR_GUEST_FINAL_MASK when injecting a nested page fault to L1, and adds a selftest to verify the behavior. When a nested page fault occurs, L1 needs to know whether the fault happened during the page table walk (on a PT page) or on the final data page translation. This information is conveyed through PFERR_GUEST_PAGE_MASK (bit 33) and PFERR_GUEST_FINAL_MASK (bit 32) in exit_info_1. Currently, these bits are not set when an NPF is injected during instruction emulation where the original exit reason was not NPF (e.g., during string I/O emulation). This series fixes that and adds test coverage. Patch 1 adds the PFERR_GUEST_{PAGE,FINAL}_MASK bits to the fault error code in paging_tmpl.h when the GPA->HPA translation fails during a guest page table walk or final page translation. Patch 2 adds TDP unmap helper functions to the selftest library, enabling tests to selectively unmap pages from the NPT to trigger nested page faults. Patch 3 adds a selftest that exercises the nested NPF injection path by having L2 execute an OUTS instruction with the source address unmapped from L1's NPT. The test verifies that the correct PFERR_GUEST_* bit is set and that exit_info_2 contains the faulting GPA. Kevin Cheng (3): KVM: SVM: Fix nested NPF injection to set PFERR_GUEST_{PAGE,FINAL}_MASK KVM: selftests: Add TDP unmap helpers KVM: selftests: Add nested NPF injection test for SVM arch/x86/kvm/kvm_emulate.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 22 ++- arch/x86/kvm/svm/nested.c | 11 +- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/x86/processor.h | 6 + .../testing/selftests/kvm/lib/x86/processor.c | 53 ++++++ .../selftests/kvm/x86/svm_nested_npf_test.c | 154 ++++++++++++++++++ 7 files changed, 230 insertions(+), 19 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86/svm_nested_npf_test.c base-commit: 38f626812b20ad22ab6dc9cfe6d811850f2d8244 -- 2.52.0.457.g6b5491de43-goog