[PATCH] x86/nestedsvm: Inject #UD for not-intercepted VMMCALL

Ross Lagerwall posted 1 patch 3 days, 11 hours ago
xen/arch/x86/hvm/svm/nestedsvm.c | 3 ---
xen/arch/x86/hvm/svm/svm.c       | 7 ++++++-
2 files changed, 6 insertions(+), 4 deletions(-)
[PATCH] x86/nestedsvm: Inject #UD for not-intercepted VMMCALL
Posted by Ross Lagerwall 3 days, 11 hours ago
Rather than always forwarding VMMCALL to L1, follow the APM Vol 2 Rev
3.46 15.18 "VMMCALL Instruction" and inject #UD for a not-intercepted
VMMCALL.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 xen/arch/x86/hvm/svm/nestedsvm.c | 3 ---
 xen/arch/x86/hvm/svm/svm.c       | 7 ++++++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
index 366178ff54a7..7bc5710c8294 100644
--- a/xen/arch/x86/hvm/svm/nestedsvm.c
+++ b/xen/arch/x86/hvm/svm/nestedsvm.c
@@ -1261,9 +1261,6 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs,
             return NESTEDHVM_VMEXIT_HOST;
         return NESTEDHVM_VMEXIT_INJECT;
 
-    case VMEXIT_VMMCALL:
-        /* Always let the guest handle VMMCALL/VMCALL */
-        return NESTEDHVM_VMEXIT_INJECT;
     default:
         break;
     }
diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
index bfca1eda4af5..ef42d5eb981d 100644
--- a/xen/arch/x86/hvm/svm/svm.c
+++ b/xen/arch/x86/hvm/svm/svm.c
@@ -2924,9 +2924,14 @@ void asmlinkage svm_vmexit_handler(void)
         break;
 
     case VMEXIT_VMMCALL:
+        if ( vcpu_guestmode )
+        {
+            hvm_inject_hw_exception(X86_EXC_UD, X86_EVENT_NO_EC);
+            break;
+        }
+
         if ( (insn_len = svm_get_insn_len(v, INSTR_VMCALL)) == 0 )
             break;
-        BUG_ON(vcpu_guestmode);
         TRACE(TRC_HVM_VMMCALL, regs->eax);
 
         if ( hvm_hypercall(regs) == HVM_HCALL_completed )
-- 
2.56.0
Re: [PATCH] x86/nestedsvm: Inject #UD for not-intercepted VMMCALL
Posted by Teddy Astie 3 days ago
Le 20/11/2026 à 12:11, Ross Lagerwall a écrit :
> Rather than always forwarding VMMCALL to L1, follow the APM Vol 2 Rev
> 3.46 15.18 "VMMCALL Instruction" and inject #UD for a not-intercepted
> VMMCALL.
> 
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
> ---
>   xen/arch/x86/hvm/svm/nestedsvm.c | 3 ---
>   xen/arch/x86/hvm/svm/svm.c       | 7 ++++++-
>   2 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/svm/nestedsvm.c b/xen/arch/x86/hvm/svm/nestedsvm.c
> index 366178ff54a7..7bc5710c8294 100644
> --- a/xen/arch/x86/hvm/svm/nestedsvm.c
> +++ b/xen/arch/x86/hvm/svm/nestedsvm.c
> @@ -1261,9 +1261,6 @@ nestedsvm_check_intercepts(struct vcpu *v, struct cpu_user_regs *regs,
>               return NESTEDHVM_VMEXIT_HOST;
>           return NESTEDHVM_VMEXIT_INJECT;
>   
> -    case VMEXIT_VMMCALL:
> -        /* Always let the guest handle VMMCALL/VMCALL */
> -        return NESTEDHVM_VMEXIT_INJECT;
>       default:
>           break;
>       }
> diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c
> index bfca1eda4af5..ef42d5eb981d 100644
> --- a/xen/arch/x86/hvm/svm/svm.c
> +++ b/xen/arch/x86/hvm/svm/svm.c
> @@ -2924,9 +2924,14 @@ void asmlinkage svm_vmexit_handler(void)
>           break;
>   
>       case VMEXIT_VMMCALL:
> +        if ( vcpu_guestmode )
> +        {
> +            hvm_inject_hw_exception(X86_EXC_UD, X86_EVENT_NO_EC);
> +            break;
> +        }
> +
>           if ( (insn_len = svm_get_insn_len(v, INSTR_VMCALL)) == 0 )
>               break;
> -        BUG_ON(vcpu_guestmode);
>           TRACE(TRC_HVM_VMMCALL, regs->eax);
>   
>           if ( hvm_hypercall(regs) == HVM_HCALL_completed )

Reviewed-by: Teddy Astie <teddy.astie@vates.tech>

Teddy
Re: [PATCH] x86/nestedsvm: Inject #UD for not-intercepted VMMCALL
Posted by Andrew Cooper 3 days, 6 hours ago
On 20/11/2026 11:11 am, Ross Lagerwall wrote:
> Rather than always forwarding VMMCALL to L1, follow the APM Vol 2 Rev
> 3.46 15.18 "VMMCALL Instruction" and inject #UD for a not-intercepted
> VMMCALL.
>
> Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>