From nobody Sun Feb 8 14:10:22 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 ACF6C405F7 for ; Fri, 2 Jan 2026 14:24:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767363883; cv=none; b=VuRcP1R+3iycyOUJsbtITpmoTjv2souRzgdW5BLF1LqeVGR5wB765cJ0vmByxSiyYaDQtFpug6ilZpX0UJty8rjjGgkt0e1KyXMevtn4q2Hmy0Z9r/Oqh97IuxeScBGzaTOM9w8/puNxHyJtXg8ZII0Y4VGK+QKVmZMwhcKGgNo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767363883; c=relaxed/simple; bh=8bCdguI0P+zHvk9Zmg8dH3bElWlltPCX/49uN95TJ2w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ibtl+6RNfsIeE7qMMU3N7aT7iZWEUQmfy+bbbr4uLJlgoIuFU71uO5vmIYrHg13OGx+4OY7dMZcRj1c0DHSPyQvKIBVVDeWMsQMPDniqXGhyZBqr846LnJVEN7bIyfGxuEMst0J1rR8FDgJpbZ+lRGRwQc30YLNXF/W8+pCU1lM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jj2qa9Pc; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jj2qa9Pc" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-47aa03d3326so77488475e9.3 for ; Fri, 02 Jan 2026 06:24:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767363879; x=1767968679; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=BUDBG+Z446ax35YwK/0xo41xTx4t//UNWGzLYXJpIEI=; b=jj2qa9Pc9jCcgFtWvo6SrF3BL7Bm5m2AykaxbH0/Mz5Pwy1MTTZUSv38GmXWSSN9WN jRQWzd6fllyESfv6vUL0rRRRIvEDZ0v6VcrCAGnmBIduOYhhx2ikC4HH/tLftnsG9uN3 s/EtRnj+K2m+NNTRtKfC8qzS2ey/3ua+43FeWQH+86quTa+VB/ACqo/sKi65V9QJ3q5W 4/RmUNE3KhsKR4pcQq95Ks2iWxmZDudr4nOVUFZba4zKUWm7DhqWr3gLz8TqWLabvZet 1IPxnMsPGW0eUg/h98mEVKC8Ib86RsZrXk8kzBShTs5XqAGqKjkD9SE0x7Wyvd5fP6PP x36A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767363879; x=1767968679; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=BUDBG+Z446ax35YwK/0xo41xTx4t//UNWGzLYXJpIEI=; b=OprBigXJ5CBu2bPSsaNz0rF+Wf5LCK9rziHbwisQtXrc/m+tl9djWF1ROgvhpCw3Af cFIpTy9f2fJwCTiKSVzSBTtvZ3wBREDI46qFnNjz6Z+I4vvaukiS4F38w+fWKXOq8iLL cIDZkeNyQv+KE29k/mCPR/Re9YG0e+3oBDtuqTCqi7El8AmOuHENmbfc07LnNmQ7rETK wFIotWjwVahGtDSXWVUZuV3sy0MpDLbrRwquigjY+FgGQd38UxBFLOvgMgClWTeH1+Dp m0o9AUjctucTU7XK/JVUkL9OYaua5Ouzb80Tngp7Ji4aFB3RLKmgynP2vzlmtcRfLXl0 sM4w== X-Forwarded-Encrypted: i=1; AJvYcCV/HuvUNneVNcBIpXI5lmE2Ef2SIWX0mj8GEiO8fsdObfcOUhc819fZLW6rWz51YhJ1yF0bemRnzFmjCzo=@vger.kernel.org X-Gm-Message-State: AOJu0YyZbxBjRLSYPOZMfpU2xomGjhwLjt8v9FIjIe6Z3RcDMJv28P+f hbEiLpy1pIiCRQW1rfbsPkWpDxftwLAoi69s3YkCoUj9xPaW3y1TtSVU X-Gm-Gg: AY/fxX7NP50F9rGPbqiG5mEnTvqnz5DVNuGiWzfv3Fld6GmxpayIUYeu21US2tydhpk nJNjAoMiAaIuR+qviXBEgOenZLIti/brQ3273JSiffDn0R3AWMBbYbN3gkFNnNFJW4SUWQZ94YU bRWpgAn8rJNT6XxPpo3TJ/FlCKFhHXiUjaru9ILCdqOlRuQbzLtENGYLlp+t4L740XbLR7++yk7 aP1/9CXh5Pk55PZh25dT8jTLjg7L4a4qCxazAvk6bTuDWNRurcuUMXZRP2SXyvnJDJGAAT45sb2 u0V5fPN8jSuMW0d7jjAZ6ppLqlShwnIGjQm18uma/9ZUvVe9Kc/YfvSJXYEAPQj2sVNJYIk91dh CfpJxocPy7EAY5n7BXiY4m6CJfqOaVI62kijZ0CUQRX5vwW77XOVb/+5pVicuoIuxyJsvsks5hu QFY7Pp67Ayfn7dL6paOztYa45b7NxS1FiHqH5GEOFWMYGhsjdCwvtjNj+DvSRvjuc5BSI74TOes +YM1JsqOIqxvD8h2/11iJL9mrv0skBK X-Google-Smtp-Source: AGHT+IFuDIAl1iFvecTNI2RuxGtGC16JVZwqR1iDuYqgqETza5wGni24k5vxvT73r6kYc/g0EdQt5A== X-Received: by 2002:a05:600c:45d3:b0:47d:4044:4ada with SMTP id 5b1f17b1804b1-47d40444b44mr363810125e9.13.1767363878923; Fri, 02 Jan 2026 06:24:38 -0800 (PST) Received: from ip-10-0-150-200.eu-west-1.compute.internal (ec2-52-49-196-232.eu-west-1.compute.amazonaws.com. [52.49.196.232]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47be27b0d5asm806409235e9.13.2026.01.02.06.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jan 2026 06:24:38 -0800 (PST) From: Fred Griffoul To: kvm@vger.kernel.org Cc: seanjc@google.com, pbonzini@redhat.com, vkuznets@redhat.com, shuah@kernel.org, dwmw@amazon.co.uk, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Fred Griffoul Subject: [PATCH v4 03/10] KVM: x86: Add nested state validation for pfncache support Date: Fri, 2 Jan 2026 14:24:22 +0000 Message-ID: <20260102142429.896101-4-griffoul@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260102142429.896101-1-griffoul@gmail.com> References: <20260102142429.896101-1-griffoul@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Fred Griffoul Implement state validation for nested virtualization to enable pfncache support for L1 guest pages. This adds a new nested_ops callback 'is_nested_state_invalid()' that detects when KVM needs to reload nested virtualization state. A KVM_REQ_GET_NESTED_STATE_PAGES request is triggered to reload affected pages before L2 execution when it detects invalid state. The callback monitors L1 guest pages during guest entry/exit while the vCPU runs in IN_GUEST_MODE. Currently, VMX implementations return false, with full support planned for the next patch. Signed-off-by: Fred Griffoul --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/vmx/nested.c | 6 ++++++ arch/x86/kvm/x86.c | 14 +++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 5a3bfa293e8b..c9a1a43fbfde 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1956,6 +1956,7 @@ struct kvm_x86_nested_ops { struct kvm_nested_state __user *user_kvm_nested_state, struct kvm_nested_state *kvm_state); bool (*get_nested_state_pages)(struct kvm_vcpu *vcpu); + bool (*is_nested_state_invalid)(struct kvm_vcpu *vcpu); int (*write_log_dirty)(struct kvm_vcpu *vcpu, gpa_t l2_gpa); =20 int (*enable_evmcs)(struct kvm_vcpu *vcpu, diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index f05828aca7e5..a97d02b08ab8 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -3541,6 +3541,11 @@ static bool vmx_get_nested_state_pages(struct kvm_vc= pu *vcpu) return true; } =20 +static bool vmx_is_nested_state_invalid(struct kvm_vcpu *vcpu) +{ + return false; +} + static int nested_vmx_write_pml_buffer(struct kvm_vcpu *vcpu, gpa_t gpa) { struct vmcs12 *vmcs12; @@ -7485,6 +7490,7 @@ struct kvm_x86_nested_ops vmx_nested_ops =3D { .get_state =3D vmx_get_nested_state, .set_state =3D vmx_set_nested_state, .get_nested_state_pages =3D vmx_get_nested_state_pages, + .is_nested_state_invalid =3D vmx_is_nested_state_invalid, .write_log_dirty =3D nested_vmx_write_pml_buffer, #ifdef CONFIG_KVM_HYPERV .enable_evmcs =3D nested_enable_evmcs, diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ff8812f3a129..d830770363ab 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -2257,12 +2257,24 @@ int kvm_emulate_monitor(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_emulate_monitor); =20 +static inline bool kvm_invalid_nested_state(struct kvm_vcpu *vcpu) +{ + if (is_guest_mode(vcpu) && + kvm_x86_ops.nested_ops->is_nested_state_invalid && + kvm_x86_ops.nested_ops->is_nested_state_invalid(vcpu)) { + kvm_make_request(KVM_REQ_GET_NESTED_STATE_PAGES, vcpu); + return true; + } + return false; +} + static inline bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu) { xfer_to_guest_mode_prepare(); =20 return READ_ONCE(vcpu->mode) =3D=3D EXITING_GUEST_MODE || - kvm_request_pending(vcpu) || xfer_to_guest_mode_work_pending(); + kvm_request_pending(vcpu) || xfer_to_guest_mode_work_pending() || + kvm_invalid_nested_state(vcpu); } =20 static fastpath_t __handle_fastpath_wrmsr(struct kvm_vcpu *vcpu, u32 msr, = u64 data) --=20 2.43.0