From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 6255033D6DF for ; Tue, 24 Feb 2026 07:18:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771917507; cv=none; b=KD0v+9p+UHd/YE23yBfEOUJYgWrbVwcDKF1KZB9Gnr6tTBJ3VtoIIZu7YtEx7S+5Xntb96UH0tX6PD3Re32dZ/OpM/9mLkFxtJaJ9nnGuuWqiRJiR2RpceqHHK3c13QLUFttkjT4JBZ2vaAF3gnj3Fq6e3iLyetOSl26jG/i3f4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771917507; c=relaxed/simple; bh=AfZLDwqO66H5LJDEaWF/fe/tqVuDFAvBOaQfPOcO+zk=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=YOIzpxKc+ip/1H9afi6MwsPQ/3ky2Vf5q0dzmqPyK3yy0f58u7gc8954lAdXUtdZm89heQG4DQQREtQZwx4xn5Txu7jDrH6DRxC/S94VoBIh5I4J3rhYui+l8Ng6ZoctxLdvLbCTxZtoacbnlaNqSx0LXB7fjtj2LCntrXj3+LI= 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=X+YXkr8y; arc=none smtp.client-ip=209.85.210.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--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="X+YXkr8y" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-824b3532298so2333372b3a.0 for ; Mon, 23 Feb 2026 23:18:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771917506; x=1772522306; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=d3uAVpWbRTVOFSJsLQhXE4M7XqcyYTVrb22AyF4z+wk=; b=X+YXkr8y/sCZnG2X8au2AeJQ5oN5V65IwsiY9LWx5iyQYrn8wbf2zOl85hZiWaneAS pA8NRArAK9hHuHU+DZuvsq1ea6EZexUMTS69VC+fms16V97ElED1MEL5p+UP2lXKbqlP iR+bgZ2J+buwGEvdlzJmn+zZvbOYj+jeairwiStDFOsDLUmifcneWK2jx6ySgJjKYrSE +iwhZLpP8JEuHq47EvxYCYYfKV25dA31zc3u95051m9F53TOycFWCp3nsiiwIsPHffXU 9HVDMZS3JzKoYO8pgigfYDJJQmCJSVLtEowfE1Zyqr8sgosLZCmQ+VmnVVN6CfHeww4O Yh8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771917506; x=1772522306; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=d3uAVpWbRTVOFSJsLQhXE4M7XqcyYTVrb22AyF4z+wk=; b=KnbHIuKVw27pCLIwSKvgC4T8YauSj2txLPCxJobtutjCg2ZCB2HuJoGtSd4fZPuPgu sCQxvXkyhcu9N3/K8niO9RObKzhodXW1IlyC6iSQVr6684mS5bzGG8S7wyBMPqCqZkwP FGGd9p/WnZaUOkQT1nqCXGlTQyeIl7gbtDfHPC8t7bVuNcQSRI74aSv2TBpdzRlKDHNc /5vwtXgeA58YcPkCXSPtzOKFYEeKPEYLBmYFxM7K6sjKEBbRrCgQrTl58daZzwgWPaTD TkDVBwLftJVhZZEWzPspifl+0s7JLRxE8WgS0HjmYMQAg8cMtuO+aZ4N2oDg6uOYu6wM QjcQ== X-Forwarded-Encrypted: i=1; AJvYcCWMAHDq7C5jKxhwxdEXW/yJXgCGcWTmhLEf2g2g5vlrQC8U0euhDXEoMrinOIe60R05dIWaZbAh0XiuSY4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz5zSjvYN8oc86N0/0AccT+dOkHrOVogf5Z36MEn7CILPBZoF/7 3pQRgMmkCAexWMrhX2YFUumi25lz4FmenkxbeOxKd4KCEU9heOJokwmO/H8GnriBw5UEKlQRmy+ Oh4+pmglcA47LMg== X-Received: from pfwy32.prod.google.com ([2002:a05:6a00:1ca0:b0:824:99df:a87e]) (user=chengkev job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2d86:b0:7b9:ef46:ec61 with SMTP id d2e1a72fcca58-826da90790bmr8681984b3a.26.1771917505496; Mon, 23 Feb 2026 23:18:25 -0800 (PST) Date: Tue, 24 Feb 2026 07:18:18 +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.53.0.414.gf7e9f6c205-goog Message-ID: <20260224071822.369326-1-chengkev@google.com> Subject: [PATCH V2 0/4] KVM: X86: Correctly populate nested page fault 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 how KVM populates error information whne injecting nested page faults (NPF on SVM, EPT violations on VMX) to L1 during instruction emulation, and adds a selftest to exercise these paths. 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. Two issues exist today: 1. SVM: The page table walker does not set PFERR_GUEST_{PAGE,FINAL}_MASK bits in the error code, and nested_svm_inject_page_fault() hardcodes the PFERR_GUEST_FINAL_MASK error code. 2. VMX: nested_ept_inject_page_fault() OR's bit 7-8 from the original exit qualification, which has no relation to the synthesized EPT violation regardless of whether it was originally an EPT violation or not. Patch 1 widens x86_exception.error_code from u16 to u64 so it can carry the PFERR_GUEST_* bits (bits 32-33). Patch 2 sets PFERR_GUEST_PAGE_MASK and PFERR_GUEST_FINAL_MASK in the walker at the kvm_translate_gpa() failure sites, and updates nested_svm_inject_npf_exit() to use the walker-provided error code. Patch 3 removes the OR with the hardware exit qualification in nested_ept_inject_page_fault(), and populates EPT_VIOLATION_GVA_IS_VALID and EPT_VIOLATION_GVA_TRANSLATED in the walker alongside the NPF bits. Patch 4 adds a selftest covering both SVM and VMX with three scenarios: - Final data page unmapped (final translation fault) - Page table page unmapped (page walk fault) - Final data page write-protected (protection violation) - Page table page write-protected (protection violation) v1 -> v2: - Split out the widening of the x86_exception error code into a separate patch as per Sean. - Added a WARN if both PFERR_GUEST_* bits are set and force the exit_info_1 to PFERR_GUEST_FINAL_MASK if this occurs. - Removed the selftest TDP helpers as per Sean - Added a patch to populate the EPT violation bits for VMX nested page faults as per Sean. - Expanded the added selftest to support VMX and also added a test case for write protected pages using the INS instruction. base-commit: 183bb0ce8c77b0fd1fb25874112bc8751a461e49 Kevin Cheng (4): KVM: x86: Widen x86_exception's error_code to 64 bits KVM: SVM: Fix nested NPF injection to set PFERR_GUEST_{PAGE,FINAL}_MASK KVM: VMX: Don't consult original exit qualification for nested EPT violation injection KVM: selftests: Add nested page fault injection test arch/x86/include/asm/kvm_host.h | 2 + arch/x86/kvm/kvm_emulate.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 44 ++- arch/x86/kvm/svm/nested.c | 19 +- arch/x86/kvm/vmx/nested.c | 3 - tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/x86/nested_npf_test.c | 374 ++++++++++++++++++ 7 files changed, 422 insertions(+), 23 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86/nested_npf_test.c -- 2.53.0.414.gf7e9f6c205-goog