[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aK5hCCbIsxRJEUe2@yzhao56-desk.sh.intel.com>
Date: Wed, 27 Aug 2025 09:36:08 +0800
From: Yan Zhao <yan.y.zhao@...el.com>
To: Sean Christopherson <seanjc@...gle.com>
CC: Sagi Shahar <sagis@...gle.com>, <linux-kselftest@...r.kernel.org>, "Paolo
Bonzini" <pbonzini@...hat.com>, Shuah Khan <shuah@...nel.org>, Ackerley Tng
<ackerleytng@...gle.com>, Ryan Afranji <afranji@...gle.com>, Andrew Jones
<ajones@...tanamicro.com>, Isaku Yamahata <isaku.yamahata@...el.com>, "Erdem
Aktas" <erdemaktas@...gle.com>, Rick Edgecombe <rick.p.edgecombe@...el.com>,
Roger Wang <runanwang@...gle.com>, Binbin Wu <binbin.wu@...ux.intel.com>,
Oliver Upton <oliver.upton@...ux.dev>, "Pratik R. Sampat"
<pratikrajesh.sampat@....com>, Reinette Chatre <reinette.chatre@...el.com>,
Ira Weiny <ira.weiny@...el.com>, Chao Gao <chao.gao@...el.com>, Chenyi Qiang
<chenyi.qiang@...el.com>, <linux-kernel@...r.kernel.org>,
<kvm@...r.kernel.org>
Subject: Re: [PATCH v9 10/19] KVM: selftests: Set up TDX boot code region
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
> > >
> > >
Powered by blists - more mailing lists