From nobody Sat Feb 7 16:00:10 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 04021225760 for ; Thu, 16 Oct 2025 18:21:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760638915; cv=none; b=K/fOj8+Lg5ItOmFlB91u+XZUsWN6ZC/3uoMVX3Q/9LyEJzvNk8CNiRM+YFsTnkyW+rwu7n0JqNzlfdLD/FT+ar3SnqBRphFA1gFDFvEyLYYtPk+7mj6SiuCh9wPFqzADkVv390j57yqfJdX6sXWQbNdKjG8ujZuw9XZm+SiqvOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760638915; c=relaxed/simple; bh=uYpnbJuBmHSp7QJ67gj6MDeGEIKA9TFc51JDajZhu6A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=GTtrpvFKHV1TBIilmw3eyZA/CkvxRYe6ZQhnIhj/KJDS9PveNKDCh47DpyOnJCAFNacwpv5u5ddLlB9347mbgP4/J6JgGqP7+kCfABRSVzH8s7Y1+EUWcO1YzKPTywIncJYRIONdgoO9cc3ZYTObjfJpjmZIuYpxC7CZOB4Jqng= 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=UZQb3I8E; arc=none smtp.client-ip=209.85.216.73 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="UZQb3I8E" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-33bb3b235ebso1489062a91.1 for ; Thu, 16 Oct 2025 11:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760638913; x=1761243713; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:from:to:cc:subject:date :message-id:reply-to; bh=uUBwpQ9GQMbT81tR22zlfiB5L6CG6pQMTQyHLevdWto=; b=UZQb3I8EZ0L7yYNFFrelHNakazAUNrFjJ/1cGzSBtwG/oEjCpe7Iny7OVWz6bUaV+K 3s/I23yJclWrdCRBabSusZF83oe3uJcZL20XSOYbrb67lQ0uRv3i1KCr2PPXEAMaugCc ngA07SSsOKHWsg9B99j/EpNHiii4Kn32WOTknzVaYTiOJ1rh64JY6TM/ap5nbj/IqYxr mZm21HaZCf8GT2HPRMy2Ygw8NQ2U5lmx+PCra90Iv9zcnObWFitGIRa5kAJpnhnBVBfc AkN9NPZhCvBZpBTljGRU2BoUKHL790HNOoqScrAgQWaVLYrFkVyfL8jR3ysA++vUnJgG og2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760638913; x=1761243713; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=uUBwpQ9GQMbT81tR22zlfiB5L6CG6pQMTQyHLevdWto=; b=B214BfgIXu+o558TTo55vWJEMRCoHQahIFmC2G2nYUpBCjhMVKSCr4PclQv2Bjgk+b vFfx/l/9bNi4LAABh2csYzvuTp8amBWxm5v4BczkMXPYIpeWwoQaGNiv2kmlEMo3egqK YUk8Jw3rMgrev90Wy+g5a47pivDQPy3TnoWFl9PIbzrLJn23m3IXsrkxVX8FdS6i040K ukqozoAZUxgBmckQxB5/BtX/wEB279CKVyXu1wyd87DZ4WZcUJ0MhOxDILzzUG29NklX qSY0n4FYhXdALvQTXstGvyxQ/xgF+Go6osdVejBHqXUghqjfDIZZqr7lYUTAcZJyYABh 99mA== X-Forwarded-Encrypted: i=1; AJvYcCUgEMaD7pUgIKjMy4EFayfZ90idrnEq4rnB/vgZ0BUjvnMgWKMmXBU4jIXo9G80wwSPM80elGAd3r3KORg=@vger.kernel.org X-Gm-Message-State: AOJu0YxEOAQgEA+YzFiFgULqfpdqGyzOyAqJBhtajkEpHGN+4V5WLGdw oq5q2LyaN46K5YduSn4AWRksMZ049xVToqWKUWUSwwD9P73Xks8XFpquBfJLbldn+M72q6YWtXW Sts7Fqg== X-Google-Smtp-Source: AGHT+IGSCjzZCxLWWkxcWEdeWtPzVEdqwdS/VUOG+4Qi5BAqC1CvaJ2LaI2Tpxep8OdHj+RLQ9Y0bjdQcX4= X-Received: from pjbsp13.prod.google.com ([2002:a17:90b:52cd:b0:332:8389:c569]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:3848:b0:339:a243:e96d with SMTP id 98e67ed59e1d1-33bcf940649mr737873a91.36.1760638913246; Thu, 16 Oct 2025 11:21:53 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 16 Oct 2025 11:21:47 -0700 In-Reply-To: <20251016182148.69085-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016182148.69085-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016182148.69085-2-seanjc@google.com> Subject: [PATCH v2 1/2] KVM: VMX: Inject #UD if guest tries to execute SEAMCALL or TDCALL From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang , Xiaoyao Li , Rick Edgecombe , Dan Williams , Binbin Wu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add VMX exit handlers for SEAMCALL and TDCALL to inject a #UD if a non-TD guest attempts to execute SEAMCALL or TDCALL. Neither SEAMCALL nor TDCALL is gated by any software enablement other than VMXON, and so will generate a VM-Exit instead of e.g. a native #UD when executed from the guest kernel. Note! No unprivileged DoS of the L1 kernel is possible as TDCALL and SEAMCALL #GP at CPL > 0, and the CPL check is performed prior to the VMX non-root (VM-Exit) check, i.e. userspace can't crash the VM. And for a nested guest, KVM forwards unknown exits to L1, i.e. an L2 kernel can crash itself, but not L1. Note #2! The Intel=C2=AE Trust Domain CPU Architectural Extensions spec's pseudocode shows the CPL > 0 check for SEAMCALL coming _after_ the VM-Exit, but that appears to be a documentation bug (likely because the CPL > 0 check was incorrectly bundled with other lower-priority #GP checks). Testing on SPR and EMR shows that the CPL > 0 check is performed before the VMX non-root check, i.e. SEAMCALL #GPs when executed in usermode. Note #3! The aforementioned Trust Domain spec uses confusing pseudocode that says that SEAMCALL will #UD if executed "inSEAM", but "inSEAM" specifically means in SEAM Root Mode, i.e. in the TDX-Module. The long- form description explicitly states that SEAMCALL generates an exit when executed in "SEAM VMX non-root operation". But that's a moot point as the TDX-Module injects #UD if the guest attempts to execute SEAMCALL, as documented in the "Unconditionally Blocked Instructions" section of the TDX-Module base specification. Cc: stable@vger.kernel.org Cc: Kai Huang Cc: Xiaoyao Li Cc: Rick Edgecombe Cc: Dan Williams Cc: Binbin Wu Signed-off-by: Sean Christopherson Reviewed-by: Binbin Wu Reviewed-by: Kai Huang Reviewed-by: Xiaoyao Li --- arch/x86/include/uapi/asm/vmx.h | 1 + arch/x86/kvm/vmx/nested.c | 8 ++++++++ arch/x86/kvm/vmx/vmx.c | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/arch/x86/include/uapi/asm/vmx.h b/arch/x86/include/uapi/asm/vm= x.h index 9792e329343e..1baa86dfe029 100644 --- a/arch/x86/include/uapi/asm/vmx.h +++ b/arch/x86/include/uapi/asm/vmx.h @@ -93,6 +93,7 @@ #define EXIT_REASON_TPAUSE 68 #define EXIT_REASON_BUS_LOCK 74 #define EXIT_REASON_NOTIFY 75 +#define EXIT_REASON_SEAMCALL 76 #define EXIT_REASON_TDCALL 77 #define EXIT_REASON_MSR_READ_IMM 84 #define EXIT_REASON_MSR_WRITE_IMM 85 diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 76271962cb70..bcea087b642f 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6728,6 +6728,14 @@ static bool nested_vmx_l1_wants_exit(struct kvm_vcpu= *vcpu, case EXIT_REASON_NOTIFY: /* Notify VM exit is not exposed to L1 */ return false; + case EXIT_REASON_SEAMCALL: + case EXIT_REASON_TDCALL: + /* + * SEAMCALL and TDCALL unconditionally VM-Exit, but aren't + * virtualized by KVM for L1 hypervisors, i.e. L1 should + * never want or expect such an exit. + */ + return false; default: return true; } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 546272a5d34d..d1b34b7ca4a3 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6033,6 +6033,12 @@ static int handle_vmx_instruction(struct kvm_vcpu *v= cpu) return 1; } =20 +static int handle_tdx_instruction(struct kvm_vcpu *vcpu) +{ + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; +} + #ifndef CONFIG_X86_SGX_KVM static int handle_encls(struct kvm_vcpu *vcpu) { @@ -6158,6 +6164,8 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu= *vcpu) =3D { [EXIT_REASON_ENCLS] =3D handle_encls, [EXIT_REASON_BUS_LOCK] =3D handle_bus_lock_vmexit, [EXIT_REASON_NOTIFY] =3D handle_notify, + [EXIT_REASON_SEAMCALL] =3D handle_tdx_instruction, + [EXIT_REASON_TDCALL] =3D handle_tdx_instruction, [EXIT_REASON_MSR_READ_IMM] =3D handle_rdmsr_imm, [EXIT_REASON_MSR_WRITE_IMM] =3D handle_wrmsr_imm, }; --=20 2.51.0.858.gf9c4a03a3a-goog From nobody Sat Feb 7 16:00:10 2026 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.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 7DAF1233711 for ; Thu, 16 Oct 2025 18:21:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760638917; cv=none; b=C+jUwgh78avHziQid/wLnl7RIWB7wcekSj7QST8fpG7rQxGyVLeqdQa9BcXAqOp3WbYhgsgCzqzkCKo+3PGyjYTDsR4EBrS7WkavADYc6hPgcEXvRFBLt8KA3D5DkJKyquBDdc8AeAkUpar+ZtWjspjRXMTkIGpjQcwiWzPife8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760638917; c=relaxed/simple; bh=5E0C6i+nRm6fQLpXNiWJmnym7Onqera4NouEl8JYjVs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=HuFjnzSs5xGizfRQR/1u3xfx/xx/cM2gGMwQ11LWs08IQdtMXPznsn2f575f6JAIetE3tHDqkupuYcoltVaka7xBH15iI4P44QnTGyA70KCNUKRNOWMyfu6fSvE6qbaj4eJ4UtshzyCK0ghqtW/NLiwtPkBukkdaZeUqf18nY2Q= 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=DDFPWLE9; arc=none smtp.client-ip=209.85.214.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="DDFPWLE9" Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-27ee41e062cso15728455ad.1 for ; Thu, 16 Oct 2025 11:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760638915; x=1761243715; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=dg+uTAFM7lbsn7WFz9CbnP/ajLiTUmOm0LwLzXdzdtE=; b=DDFPWLE9P74ecLSNE7DSPHOzLGwTdoG80kdDtSY3D5uWDVUFjkJmVnMaNg7HrF0766 4q10AakPEociADNv0hiMCfjYN4oYbuHRVXFC/l9a87qYlq7JphgCx5a2gBkQgVQ0hLP/ WezqzjE795hTpmlgJIMA+3SmvmqBKLmC98nkdyKusdP+Bp0MdZ3QFt++Q7AmJKNhzrni t3fhAI/E1TYYL4sMJwHlsVJjdhTLMK6bBbe8flDYjZUVY6sQUILdPsTkES/H061gksON oufwemDb0tgnchUsKY+QkmgZaHRQwf0hJ/nOw4hQe/bPmYA6orEfLzu7mrqiaLqocK4d U2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760638915; x=1761243715; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dg+uTAFM7lbsn7WFz9CbnP/ajLiTUmOm0LwLzXdzdtE=; b=oq2RYsraltQj/OJsSGvicS8ocAEQiV0Jn1FEgVdeDGHXRFyXTUSZHK2Jy9oGORMFam EfG6hWqD1cd6DhO36IDBlv5nqIAdO3jNmCtXXcYLP0Th1riv1zTRPOCzxwsSYSTCfcJ7 I0Xxt6hsMGqyFGc2HyA5s2/xq2NZhS1xM5EWAFi8HDlUHvP/f/nY6T2q8AarwE2ujka9 oyPYeiDWQNRdMqZaSpNa9nWih3yv4oRU99Km40/JVm4tUN8Xyp4/3mjD+oE++gsJKz2h hy4wIGLaM7ZdK6cX9VmuOWAE2F0jGqOu7m+N1rJ1McyxmZ5I13aQ8hpqL7cQQVDlpLOT XSrQ== X-Forwarded-Encrypted: i=1; AJvYcCVg+xpqVCBglreoQO4hnpPLgS8UrfVcq8P5cf4fOzHQ6A29PjCZWrCVQ30ftv+npDP+I3mg64TDWTv+7JM=@vger.kernel.org X-Gm-Message-State: AOJu0Yze8OIi9zDjD3lOuqH7eMdF40yivHWHxvBF37O2KbTf4b/8megF M5BGxZD95+2iGkAvISnYg9oIi19xLXeOEPivb8q9Ky87O0huYl2Ba2vF1BAQrcCLETtBhA2CVMf Fw6PxwQ== X-Google-Smtp-Source: AGHT+IHLX+JIJP/xpi0UAaW6TGcXgazhRaRJEBLzAroZBMicx8wFXjI+9H930mLGqANzA7DPXew0mwyUPZE= X-Received: from plbmo5.prod.google.com ([2002:a17:903:a85:b0:290:b136:4f08]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:eccb:b0:276:842a:f9a7 with SMTP id d9443c01a7336-290cba4db6emr10000875ad.57.1760638914703; Thu, 16 Oct 2025 11:21:54 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 16 Oct 2025 11:21:48 -0700 In-Reply-To: <20251016182148.69085-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251016182148.69085-1-seanjc@google.com> X-Mailer: git-send-email 2.51.0.858.gf9c4a03a3a-goog Message-ID: <20251016182148.69085-3-seanjc@google.com> Subject: [PATCH v2 2/2] KVM: TDX: WARN if a SEAMCALL VM-Exit makes its way out to KVM From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang , Xiaoyao Li , Rick Edgecombe , Dan Williams , Binbin Wu Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" WARN if KVM observes a SEAMCALL VM-Exit while running a TD guest, as the TDX-Module is supposed to inject a #UD, per the "Unconditionally Blocked Instructions" section of the TDX-Module base specification. Reported-by: Xiaoyao Li Signed-off-by: Sean Christopherson Reviewed-by: Binbin Wu Reviewed-by: Xiaoyao Li --- arch/x86/kvm/vmx/tdx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c index 097304bf1e1d..ffcfe95f224f 100644 --- a/arch/x86/kvm/vmx/tdx.c +++ b/arch/x86/kvm/vmx/tdx.c @@ -2148,6 +2148,9 @@ int tdx_handle_exit(struct kvm_vcpu *vcpu, fastpath_t= fastpath) * - If it's not an MSMI, no need to do anything here. */ return 1; + case EXIT_REASON_SEAMCALL: + WARN_ON_ONCE(1); + break; default: break; } --=20 2.51.0.858.gf9c4a03a3a-goog