From nobody Mon Feb 9 06:25:12 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 A5F45374188 for ; Mon, 12 Jan 2026 17:45:49 +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=1768239952; cv=none; b=rYDR4eakc4FsgojB8Dcytw4dl1ta94yreJeAjlnftJIsNb0NTu11QJDYzUYNWN2neYL1XU1S+Nl9zQYQ90I7E1wMCYx1Rkby96zONxFiaU9BdiXbZPHfxIYJhYQj3erRVYLERc0DDr4zOMErLqkO+ugim71r7V25AU3BiSuEk2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768239952; c=relaxed/simple; bh=SRn/8LkmaiDx4mbVxdInxzII+UnuGlGMzo2ATeYcp5o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=qldiMI5xpNSJKT+VVuk5d3Y0/Ge1wlIyFihtltzhpeYZ5RZ5i8f8/I+R73v9cjnX1uJyu+nPjIxNzFwsX3LyDhWVs1FxAEjYkoOlG3QxuCZyv1RS68dNyFXsddRyiiSPv8e4Yv95ahJ/ROnxqlebsaOeDoF5TjkhYEtcAl0qDoM= 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=hlbxr/0l; 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--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="hlbxr/0l" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-34ab459c051so2755990a91.0 for ; Mon, 12 Jan 2026 09:45:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1768239949; x=1768844749; 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=24RTjXW0RUIu3mbeBBuCS6+SaZyDve2lWE6uRECn1KA=; b=hlbxr/0lTFVl0DgOiIfM25GdVIgj02xHAIkz5ckR+iawUH7LBwPrvpnhm4zpUFaIT6 bnEMlTceM2eEQAc7VMVCORljeOWoV3OJDgbmjFkcaO6z25k8z2iOQzE2cet5Tpj+KaGl f4IwqErMiqfoQ+CVzDdCL5IIKRmbAeProoJ+ceqX5URbBnoM6Z2YOp0pzlCP3CbcuclI hFlqmiTzFtnpEOzb85PWXs0GhOwgoeq2LJeuhx43Em/KJCF49Odd7gkh8DxMulKtP14h yPFkIUT5pYD5jLm+ofUVviuK7URlNl41CukCmNEBmqCDUtGEK4wl7UZLR2EcYGx30Qkj Fsjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768239949; x=1768844749; 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=24RTjXW0RUIu3mbeBBuCS6+SaZyDve2lWE6uRECn1KA=; b=S0e3IaHEZSw849brmJaNHb7s9LpP/zyoi1dy9sftb+r3D3XSt2UZSDk0SQo+JJd4fg E4iVMu1KgTQNkA2WvQTIfhfaCjZek0Flvr7oa+cu2gsjJFNdYFUI3XriPlE67KYZZyDF /EzwEYayiRn5dZi0NcNOuauZ1CwvJBiuQxYk3SEUN05/S92zjcm4pns6G3px5KbkBcbz 11Sn35Idg3WEoXGq19+LN/vKiE9DfsaQnC6lZC1rX1BedC6QJ4R56mnRSFsc9wwqPvIP YHc0IB1vKX2EzXdL1IaGDMlio+tYXrd+mjIicDGT0IlGhMqHGAOlbCVfa6Ho4WeDfGoC 0yUw== X-Forwarded-Encrypted: i=1; AJvYcCW5zOZcuc//Xi1zKF2phfSwRPuGCD9SqlNnv3ko6pK+IhrH6QTdWvmRzAUeEm+dBV+lqZZAQLyhGRcqwPY=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0CLlr/HkYs2NzWjPDs4qlgu2xFn+mtQbdZeD8JHVwCkWcafKN VX5X0pLj3t/OqcxFkuNGplWNhoJGQ0t0yKQhaXJKHbw3T9tdHa8wLf+N88Kb1VQgSaVwpqAcHiv sX0ngv4np6stUtw== X-Google-Smtp-Source: AGHT+IHJL4gsPR2YUXI6J7F9iMrruLFSR8LmSuYPPLBbIXHlG9kM+3w07TqUZ3x+3X2RlYrnCrIw8LKbY0DrKA== X-Received: from pjbrs15.prod.google.com ([2002:a17:90b:2b8f:b0:34a:b143:87d7]) (user=chengkev job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4e:b0:330:82b1:ef76 with SMTP id 98e67ed59e1d1-34f68c62a25mr14612405a91.28.1768239948999; Mon, 12 Jan 2026 09:45:48 -0800 (PST) Date: Mon, 12 Jan 2026 17:45:35 +0000 In-Reply-To: <20260112174535.3132800-1-chengkev@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260112174535.3132800-1-chengkev@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260112174535.3132800-6-chengkev@google.com> Subject: [PATCH V2 5/5] KVM: SVM: Raise #UD if VMMCALL instruction is not intercepted 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The AMD APM states that if VMMCALL instruction is not intercepted, the instruction raises a #UD exception. Create a vmmcall exit handler that generates a #UD if a VMMCALL exit from L2 is being handled by L0, which means that L1 did not intercept the VMMCALL instruction. Suggested-by: Sean Christopherson Signed-off-by: Kevin Cheng Reviewed-by: Manali Shukla Reviewed-by: Yosry Ahmed Tested-by: Manali Shukla --- arch/x86/kvm/svm/svm.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 92a66b62cfabd..805267a5106ac 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -3180,6 +3180,20 @@ static int bus_lock_exit(struct kvm_vcpu *vcpu) return 0; } =20 +static int vmmcall_interception(struct kvm_vcpu *vcpu) +{ + /* + * VMMCALL #UDs if it's not intercepted, and KVM reaches this point if + * and only if the VMMCALL intercept is not set in vmcb12. + */ + if (is_guest_mode(vcpu)) { + kvm_queue_exception(vcpu, UD_VECTOR); + return 1; + } + + return kvm_emulate_hypercall(vcpu); +} + static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) =3D { [SVM_EXIT_READ_CR0] =3D cr_interception, [SVM_EXIT_READ_CR3] =3D cr_interception, @@ -3230,7 +3244,7 @@ static int (*const svm_exit_handlers[])(struct kvm_vc= pu *vcpu) =3D { [SVM_EXIT_TASK_SWITCH] =3D task_switch_interception, [SVM_EXIT_SHUTDOWN] =3D shutdown_interception, [SVM_EXIT_VMRUN] =3D vmrun_interception, - [SVM_EXIT_VMMCALL] =3D kvm_emulate_hypercall, + [SVM_EXIT_VMMCALL] =3D vmmcall_interception, [SVM_EXIT_VMLOAD] =3D vmload_interception, [SVM_EXIT_VMSAVE] =3D vmsave_interception, [SVM_EXIT_STGI] =3D stgi_interception, --=20 2.52.0.457.g6b5491de43-goog