From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.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 DF2C521323C for ; Wed, 15 Oct 2025 13:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760536659; cv=none; b=odwjIGrcCqfAmNGcsPg3SRNm/CbYGwoH2UtQOF+NuA983GqwvNwtB1mh+/YLxAg3tDyVn3BlsghP+nyQxwOkOzWRNVaDCDac7wvqjZkkI0F8NhOkZtFWL5Y0EQ+UA/3kk3Lgz3foNPgOrLlBlCkEw6jOqFJEunQIeFDWzaQcELI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760536659; c=relaxed/simple; bh=914YWKhORdAdREtonmghsM3z/MP7Mw+k1IVoaRAXaCI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i48wF+Bw4G51yeUgwB5jcFBNrOCPYLZd2jEvF1vS0XIMBTvLTwweHVhiEi0rp/dp19RiB5U/0u96sWZU21thsqgzMvprrxY4olGugR7dZmdBBlKq9vTB02z84Zh3uyDfyCNWbxVSyCbmDOndhMSlY6xB46bWipuV23lXMdDwbQU= 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=R8yaAC/M; arc=none smtp.client-ip=209.85.215.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="R8yaAC/M" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-b5a013bc46dso9491731a12.1 for ; Wed, 15 Oct 2025 06:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1760536657; x=1761141457; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qN/u3D1Ic2NfIT6zYQD+vHPHON5q0zRxCVjBfN7LZuE=; b=R8yaAC/MxgTA1fsrfoeliujYAK0ZKCX4Gj1NFFA+J9ApQUuvZrLLoZaBmTc9LWjzrU FjJBdhRrJEuV4yscFAHr+Y4cgevC1/Et4CIOivTd8KP1nZ4orKyHRgEWQZaPKdalwbYi fZph9fOQuo6l9HNr+a/pALcsW3y2yuZlQqTegqIKLM993HJ2m0ul0K36GU1HjgSc4b+R rVNeNRG/Uq5aRBlxLBjfR74ZlEblaDHT3IOSQRtJPR366gnYiGAG+GQuEhWA/kcgjOyD 7jLi6Oj8NiiRBuuOU2Wpw1io4lUBTZiE7cFpmhJdrVNE/rC6AaPx1X9cTi//k4SXU3gJ IDng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760536657; x=1761141457; h=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=qN/u3D1Ic2NfIT6zYQD+vHPHON5q0zRxCVjBfN7LZuE=; b=iZPNiGmJD67wNgeAuTlEsLvpVDGYvR2oUa4ILSeYoRLSdAhXde2Mqn77G3Ze6BBb2/ +sqpXBt3WEqK+pHrFCXHp7PmKaDNlIQ06ICVbQxPp+XJr7L8Jqg02i6JQzD/kzWIVAnR hPIoIZcHo/R7IrfzEev7OUplQAqXB2Xk/IWSXECgaRXog+YnO+hojpqEq1IJOKOn6T/O PoiCadyipHjPeEs4wfXxGvei/k7f4P1XGGqGzzj7Z0va2dCS5umvXZYIyubt1IKvyjUQ vCTZk19Z+uCuhyymHmIVpqA5I6AlecHZvhQ9+RuzqdiO+ujHCaTmvIGeX5Zih1l4+9te 3s1Q== X-Forwarded-Encrypted: i=1; AJvYcCVy3eSycFhRgH43TTTrikQFzgP8JA6NHd6Gn2rSTeVsQFhoC3bQs79qfZXUPdzaICXvZ8ICgF1Xi1j7LzI=@vger.kernel.org X-Gm-Message-State: AOJu0YzOyHV7PYb2bp6S1j7W6wcQ+zeiTRy1nRAyk8IyU5pQjYOaJVdW OeJGy082u8yZaYBM5i6Hspj5JAnOoT8DTpW4zhFM6z6VY0ZRL97Hq44NxDQBirxcrwSoYte5OVL iBL2FhQ== X-Google-Smtp-Source: AGHT+IEyIzQLWPhAYYB3gtJgp/BmJ24/oEbEbNVeRBVUNOIF4pnDsqkLncvGwTJJ1+Rn/DPUNhJxMmTiu40= X-Received: from pjon8.prod.google.com ([2002:a17:90a:9288:b0:32e:b34b:92e8]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:1b11:b0:330:7f80:bbd9 with SMTP id 98e67ed59e1d1-33b5139a422mr36589740a91.31.1760536657007; Wed, 15 Oct 2025 06:57:37 -0700 (PDT) Date: Wed, 15 Oct 2025 06:57:35 -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: <20251014231042.1399849-1-seanjc@google.com> Message-ID: Subject: Re: [PATCH] KVM: VMX: Inject #UD if guest tries to execute SEAMCALL or TDCALL From: Sean Christopherson To: Xiaoyao Li Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kai Huang , Rick Edgecombe Content-Type: text/plain; charset="us-ascii" On Wed, Oct 15, 2025, Xiaoyao Li wrote: > On 10/15/2025 7:10 AM, Sean Christopherson wrote: > > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c > > index 76271962cb70..f64a1eb241b6 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. > > + */ > > The i.e. part is confusing? It is exactly forwarding the EXITs to L1, while > it says L1 should never want or expect such an exit. Gah, the comment is right, the code is wrong. /facepalm I even tried to explicitly test this, but I put the TDCALL and SEAMCALL in L1 instead of L2. diff --git a/tools/testing/selftests/kvm/x86/vmx_invalid_nested_guest_state.c b/tools/testing/selftests/kvm/x86/vmx_invalid_nested_guest_state.c index a100ee5f0009..1d7ef7d2d381 100644 --- a/tools/testing/selftests/kvm/x86/vmx_invalid_nested_guest_state.c +++ b/tools/testing/selftests/kvm/x86/vmx_invalid_nested_guest_state.c @@ -23,11 +23,17 @@ static void l2_guest_code(void) : : [port] "d" (ARBITRARY_IO_PORT) : "rax"); } +#define tdcall ".byte 0x66,0x0f,0x01,0xcc" +#define seamcall ".byte 0x66,0x0f,0x01,0xcf" + static void l1_guest_code(struct vmx_pages *vmx_pages) { #define L2_GUEST_STACK_SIZE 64 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + TEST_ASSERT_EQ(kvm_asm_safe(tdcall), UD_VECTOR); + TEST_ASSERT_EQ(kvm_asm_safe(seamcall), UD_VECTOR); + GUEST_ASSERT(prepare_for_vmx_operation(vmx_pages)); GUEST_ASSERT(load_vmcs(vmx_pages));