[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 5/5] x86/hvm: Un-indent the HVM_FEP block in the #UD handler


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Thu, 12 Mar 2026 15:02:36 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=suse.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ygk6T4hWc/DWYmyFTOeqWe2L6qfEZIP82s69SGYY8OU=; b=eTRBb1Ps85l3CM8vjMvbkWmrtlP/18jfL+fJgESr9ZVc7pZN9cmW8xC4Ms+mEXMwY36yffnoNblk5Y5zsyaFTBRyl/uSVDAlsaI664NxJOiSMBfge4w3HfZgD5zZqMcja9R4cDxEKit9XiJ9QUY/WT8WdK3Z+pXF9g0YeqQUbtDRRZMIxiNnKFwiESeu8naLIQ0DL7fTW2G+ienZu4f3l1SfNp40EOlgWqLpPrGml6CnqsF/c74BCJJvo9manhddiYOlx5qWr9X2/dJHMrsXM36i6BSplWy8MxCDBiCdxdJ3mceXKetGhNuaGMCQ7p8xsBicR8I6CW87eiptyaHsRg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vpmd9RGo7BiJyRPhdE3gvBIryy7pFAD6al1gukHKtG1h6gPM4qfPOv2/ctHAWjnb4DNs2KwbvZFmjwMf77irMObj91wyDGhXJMzkdXxLEURm8h1Cz0h1DlrhV4S3wBY34c9ytJwWv1iDXP8J7no11jQ+fCOJWjcplOsOLBPBf7UPR/nmXm8TkG6cBjaSNPQqOdYp6CS87GEt2R07gJ0ROBvYgHHAw8cD8qv4ltxOf/6ZvCLwrAexN5B1TQ1HhgFDbcUkLY4A75pOrbYVFhAzXOTCfIBuIl+WFMQ7XdRcM5uWVdJhKlJOF3Cj9uXGwRuOJBZV0+t643L5wUFdvTfaRw==
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Thu, 12 Mar 2026 14:11:38 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu Mar 12, 2026 at 12:42 PM CET, Jan Beulich wrote:
> On 12.03.2026 12:21, Alejandro Vallejo wrote:
>> --- a/xen/arch/x86/hvm/hvm.c
>> +++ b/xen/arch/x86/hvm/hvm.c
>> @@ -3837,35 +3837,34 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
>>      struct vcpu *cur = current;
>>      bool should_emulate = false;
>>      struct hvm_emulate_ctxt ctxt;
>> +    const struct segment_register *cs;
>> +    uint32_t walk;
>> +    unsigned long addr;
>> +    char sig[5]; /* ud2; .ascii "xen" */
>>  
>>      hvm_emulate_init_once(&ctxt, NULL, regs);
>>  
>> -    if ( opt_hvm_fep )
>> +    cs = &ctxt.seg_reg[x86_seg_cs];
>> +    walk = ((ctxt.seg_reg[x86_seg_ss].dpl == 3)
>> +            ? PFEC_user_mode : 0) | PFEC_insn_fetch;
>
> While of course functionally everything's fine this way, I'm now entirely 
> lost:
> Why are what were ...
>
>> +    if ( hvm_virtual_to_linear_addr(x86_seg_cs, cs, regs->rip,
>> +                                    sizeof(sig), hvm_access_insn_fetch,
>> +                                    cs, &addr) &&
>> +         (hvm_copy_from_guest_linear(sig, addr, sizeof(sig),
>> +                                     walk, NULL) == HVMTRANS_okay) &&
>> +         (memcmp(sig, "\xf\xb" "xen", sizeof(sig)) == 0) )
>>      {
>> -        const struct segment_register *cs = &ctxt.seg_reg[x86_seg_cs];
>> -        uint32_t walk = ((ctxt.seg_reg[x86_seg_ss].dpl == 3)
>> -                         ? PFEC_user_mode : 0) | PFEC_insn_fetch;
>
> ... initializers before not initializers anymore, when all you're doing is
> (supposedly) re-indentation (and, necessarily, moving decls up to the top of
> the scope they need to live in)?

walk cannot be initialised at the delcaration site because it relies on
hvm_emulate_init_once() having run and you made a strong argument to preserve
the current form so I left cs next to walk, as it was before.

>
>> -        unsigned long addr;
>> -        char sig[5]; /* ud2; .ascii "xen" */
>> -
>> -        if ( hvm_virtual_to_linear_addr(x86_seg_cs, cs, regs->rip,
>> -                                        sizeof(sig), hvm_access_insn_fetch,
>> -                                        cs, &addr) &&
>> -             (hvm_copy_from_guest_linear(sig, addr, sizeof(sig),
>> -                                         walk, NULL) == HVMTRANS_okay) &&
>> -             (memcmp(sig, "\xf\xb" "xen", sizeof(sig)) == 0) )
>> -        {
>> -            regs->rip += sizeof(sig);
>> -            regs->eflags &= ~X86_EFLAGS_RF;
>> +        regs->rip += sizeof(sig);
>> +        regs->eflags &= ~X86_EFLAGS_RF;
>>  
>> -            /* Zero the upper 32 bits of %rip if not in 64bit mode. */
>> -            if ( !(hvm_long_mode_active(cur) && cs->l) )
>> -                regs->rip = (uint32_t)regs->rip;
>> +        /* Zero the upper 32 bits of %rip if not in 64bit mode. */
>> +        if ( !(hvm_long_mode_active(cur) && cs->l) )
>> +            regs->rip = (uint32_t)regs->rip;
>>  
>> -            add_taint(TAINT_HVM_FEP);
>> +        add_taint(TAINT_HVM_FEP);
>>  
>> -            should_emulate = true;
>> -        }
>> +        should_emulate = true;
>>      }
>>  
>>      if ( !should_emulate )
>
> With this, the purpose of the should_emulate variable effectively vanishes,
> without it actually being purged (unlike you had it earlier).

That goes away with patch 6, that I neglected to send before.

>
> Jan




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.