On Tue, Aug 26, 2025 at 09:38:15AM -0700, Sean Christopherson wrote:
> On Mon, Aug 25, 2025, Yan Zhao wrote:
> > > + /*
> > > +  * Handcode "JMP rel8" at the RESET vector to jump back to the TD boot
> > > +  * code, as there are only 16 bytes at the RESET vector before RIP will
> > > +  * wrap back to zero.  Insert a trailing int3 so that the vCPU crashes
> > > +  * in case the JMP somehow falls through.  Note!  The target address is
> > > +  * relative to the end of the instruction!
> > > +  */
> > > + TEST_ASSERT(TD_BOOT_CODE_SIZE < 256,
> > Looks TD_BOOT_CODE_SIZE needs to be <= 126, as the jump range is limited to 
> > -128
> > to +127 for JMP rel8.
> 
> Gah, I managed to forget that relative targets obviously need to be signed 
> values,
> and I also forgot to account for the size of the JMP in the assert.  Go me.
> 
> Maybe express this as:
> 
>       TEST_ASSERT(TD_BOOT_CODE_SIZE + 2 < 128,
>                   "TD boot code not addressable by 'JMP rel8'");
I like this version, which's is much clearer than asserting TD_BOOT_CODE_SIZE
alone.

nit: TD_BOOT_CODE_SIZE + 2 can be equal to 128, i.e.,

        TEST_ASSERT(TD_BOOT_CODE_SIZE + 2 <= 128,
                    "TD boot code not addressable by 'JMP rel8'");


> > > +             "TD boot code not addressable by 'JMP rel8'");
> > > + hva[0] = 0xeb;
> > > + hva[1] = 256 - 2 - TD_BOOT_CODE_SIZE;
> 
> I think I lucked into getting this right though?
Yes, this one is correct :)


> > > + hva[2] = 0xcc;
> > > +}
> > > -- 
> > > 2.51.0.rc1.193.gad69d77794-goog
> > > 
> > > 

Reply via email to