mbox series

[v2,0/7] Overhauling amx_test

Message ID 20230214184606.510551-1-mizhang@google.com
Headers show
Series Overhauling amx_test | expand

Message

Mingwei Zhang Feb. 14, 2023, 6:45 p.m. UTC
AMX architecture involves several entities such as xstate, XCR0,
IA32_XFD. This series add several missing checks on top of the existing
amx_test.

v1 -> v2:
 - Add a working xstate data structure suggested by seanjc.
 - Split the checking of CR0.TS from the checking of XFD.
 - Fix all the issues pointed by in review.

v1:
https://lore.kernel.org/all/20230110185823.1856951-1-mizhang@google.com/

Mingwei Zhang (7):
  KVM: selftests: x86: Fix an error in comment of amx_test
  KVM: selftests: x86: Add a working xstate data structure
  KVM: selftests: x86: Add check of CR0.TS in the #NM handler in
    amx_test
  KVM: selftests: Add the XFD check to IA32_XFD in #NM handler
  KVM: selftests: Fix the checks to XFD_ERR using and operation
  KVM: selftests: x86: Enable checking on xcomp_bv in amx_test
  KVM: selftests: x86: Repeat the checking of xheader when
    IA32_XFD[XTILEDATA] is set in amx_test

 .../selftests/kvm/include/x86_64/processor.h  | 12 ++++
 tools/testing/selftests/kvm/x86_64/amx_test.c | 59 ++++++++++---------
 2 files changed, 43 insertions(+), 28 deletions(-)

Comments

Aaron Lewis Feb. 17, 2023, 10:01 p.m. UTC | #1
On Tue, Feb 14, 2023 at 6:46 PM Mingwei Zhang <mizhang@google.com> wrote:
>
> Add check of CR0.TS[bit 3] before the check of IA32_XFD_ERR in the #NM
> handler in amx_test. This is because XFD may not be the only reason of
> the IA32_XFD MSR and the bitmap corresponding to the state components
> required by the faulting instruction." (Intel SDM vol 1. Section 13.14)
>
> Add the missing check of CR0.TS.
>
> Signed-off-by: Mingwei Zhang <mizhang@google.com>
> ---
>  tools/testing/selftests/kvm/x86_64/amx_test.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c
> index aac727ff7cf8..847752998660 100644
> --- a/tools/testing/selftests/kvm/x86_64/amx_test.c
> +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c
> @@ -215,6 +215,7 @@ void guest_nm_handler(struct ex_regs *regs)
>  {
>         /* Check if #NM is triggered by XFEATURE_MASK_XTILEDATA */
>         GUEST_SYNC(7);
> +       GUEST_ASSERT((get_cr0() & X86_CR0_TS) == 0);

Can't we infer that the #NM is the result of an XFD error due to the fact
that IA32_XFD_ERR is set?  Is this check needed?
SDM vol 1, 13.14, EXTENDED FEATURE DISABLE (XFD)
 - Device-not-available exceptions that are not due to XFD - those
   resulting from setting CR0.TS to 1 - do not modify the IA32_XFD_ERR
   MSR.

>         GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
>         GUEST_SYNC(8);
>         GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
> --
> 2.39.1.581.gbfd45094c4-goog
>
Aaron Lewis Feb. 17, 2023, 10:04 p.m. UTC | #2
On Tue, Feb 14, 2023 at 6:46 PM Mingwei Zhang <mizhang@google.com> wrote:
>
> AMX architecture involves several entities such as xstate, XCR0,
> IA32_XFD. This series add several missing checks on top of the existing
> amx_test.
>
> v1 -> v2:
>  - Add a working xstate data structure suggested by seanjc.
>  - Split the checking of CR0.TS from the checking of XFD.
>  - Fix all the issues pointed by in review.
>
> v1:
> https://lore.kernel.org/all/20230110185823.1856951-1-mizhang@google.com/
>
> Mingwei Zhang (7):
>   KVM: selftests: x86: Fix an error in comment of amx_test
>   KVM: selftests: x86: Add a working xstate data structure
>   KVM: selftests: x86: Add check of CR0.TS in the #NM handler in
>     amx_test
>   KVM: selftests: Add the XFD check to IA32_XFD in #NM handler
>   KVM: selftests: Fix the checks to XFD_ERR using and operation
>   KVM: selftests: x86: Enable checking on xcomp_bv in amx_test
>   KVM: selftests: x86: Repeat the checking of xheader when
>     IA32_XFD[XTILEDATA] is set in amx_test
>
>  .../selftests/kvm/include/x86_64/processor.h  | 12 ++++
>  tools/testing/selftests/kvm/x86_64/amx_test.c | 59 ++++++++++---------
>  2 files changed, 43 insertions(+), 28 deletions(-)
>
> --
> 2.39.1.581.gbfd45094c4-goog
>

Would you be open to adding my series to the end of this one?  That
way we have one series that's overhauling amx_test.

https://lore.kernel.org/kvm/20230217215959.1569092-1-aaronlewis@google.com/
Mingwei Zhang Feb. 18, 2023, 12:57 a.m. UTC | #3
On Fri, Feb 17, 2023, Aaron Lewis wrote:
> On Tue, Feb 14, 2023 at 6:46 PM Mingwei Zhang <mizhang@google.com> wrote:
> >
> > Add check of CR0.TS[bit 3] before the check of IA32_XFD_ERR in the #NM
> > handler in amx_test. This is because XFD may not be the only reason of
> > the IA32_XFD MSR and the bitmap corresponding to the state components
> > required by the faulting instruction." (Intel SDM vol 1. Section 13.14)
> >
> > Add the missing check of CR0.TS.
> >
> > Signed-off-by: Mingwei Zhang <mizhang@google.com>
> > ---
> >  tools/testing/selftests/kvm/x86_64/amx_test.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c
> > index aac727ff7cf8..847752998660 100644
> > --- a/tools/testing/selftests/kvm/x86_64/amx_test.c
> > +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c
> > @@ -215,6 +215,7 @@ void guest_nm_handler(struct ex_regs *regs)
> >  {
> >         /* Check if #NM is triggered by XFEATURE_MASK_XTILEDATA */
> >         GUEST_SYNC(7);
> > +       GUEST_ASSERT((get_cr0() & X86_CR0_TS) == 0);
> 
> Can't we infer that the #NM is the result of an XFD error due to the fact
> that IA32_XFD_ERR is set?  Is this check needed?
> SDM vol 1, 13.14, EXTENDED FEATURE DISABLE (XFD)
>  - Device-not-available exceptions that are not due to XFD - those
>    resulting from setting CR0.TS to 1 - do not modify the IA32_XFD_ERR
>    MSR.
> 
We don't infer from the reasons of #NM and that is the purpose of this
selftest. Yes, this looks a little bit pedantic. But still, it is worth
adding the check since violation of that indicates either 1) the
selftest mistakenly did not clear XFD_ERR prior to #NM or 2) hardware is
broken.

> >         GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
> >         GUEST_SYNC(8);
> >         GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA);
> > --
> > 2.39.1.581.gbfd45094c4-goog
> >
Mingwei Zhang Feb. 18, 2023, 12:58 a.m. UTC | #4
On Fri, Feb 17, 2023, Aaron Lewis wrote:
> On Tue, Feb 14, 2023 at 6:46 PM Mingwei Zhang <mizhang@google.com> wrote:
> >
> > AMX architecture involves several entities such as xstate, XCR0,
> > IA32_XFD. This series add several missing checks on top of the existing
> > amx_test.
> >
> > v1 -> v2:
> >  - Add a working xstate data structure suggested by seanjc.
> >  - Split the checking of CR0.TS from the checking of XFD.
> >  - Fix all the issues pointed by in review.
> >
> > v1:
> > https://lore.kernel.org/all/20230110185823.1856951-1-mizhang@google.com/
> >
> > Mingwei Zhang (7):
> >   KVM: selftests: x86: Fix an error in comment of amx_test
> >   KVM: selftests: x86: Add a working xstate data structure
> >   KVM: selftests: x86: Add check of CR0.TS in the #NM handler in
> >     amx_test
> >   KVM: selftests: Add the XFD check to IA32_XFD in #NM handler
> >   KVM: selftests: Fix the checks to XFD_ERR using and operation
> >   KVM: selftests: x86: Enable checking on xcomp_bv in amx_test
> >   KVM: selftests: x86: Repeat the checking of xheader when
> >     IA32_XFD[XTILEDATA] is set in amx_test
> >
> >  .../selftests/kvm/include/x86_64/processor.h  | 12 ++++
> >  tools/testing/selftests/kvm/x86_64/amx_test.c | 59 ++++++++++---------
> >  2 files changed, 43 insertions(+), 28 deletions(-)
> >
> > --
> > 2.39.1.581.gbfd45094c4-goog
> >
> 
> Would you be open to adding my series to the end of this one?  That
> way we have one series that's overhauling amx_test.
> 
> https://lore.kernel.org/kvm/20230217215959.1569092-1-aaronlewis@google.com/

Sure, I will integrate your changes into this series.
Chao Gao Feb. 19, 2023, 8:33 a.m. UTC | #5
On Tue, Feb 14, 2023 at 06:46:00PM +0000, Mingwei Zhang wrote:
>-	/* xsave data for guest_code */
>-	xsavedata = vm_vaddr_alloc_pages(vm, 3);
>-	memset(addr_gva2hva(vm, xsavedata), 0, 3 * getpagesize());
>-	vcpu_args_set(vcpu, 3, amx_cfg, tiledata, xsavedata);
>+	/* XSAVE state for guest_code */
>+	xstate = vm_vaddr_alloc_pages(vm, DIV_ROUND_UP(XSAVE_SIZE, PAGE_SIZE));
>+	memset(addr_gva2hva(vm, xstate), 0, DIV_ROUND_UP(XSAVE_SIZE, PAGE_SIZE));

					    ^ this should be the size in bytes instead of in pages. Right?
Mingwei Zhang Feb. 19, 2023, 5:56 p.m. UTC | #6
On Sun, Feb 19, 2023 at 12:33 AM Chao Gao <chao.gao@intel.com> wrote:
>
> On Tue, Feb 14, 2023 at 06:46:00PM +0000, Mingwei Zhang wrote:
> >-      /* xsave data for guest_code */
> >-      xsavedata = vm_vaddr_alloc_pages(vm, 3);
> >-      memset(addr_gva2hva(vm, xsavedata), 0, 3 * getpagesize());
> >-      vcpu_args_set(vcpu, 3, amx_cfg, tiledata, xsavedata);
> >+      /* XSAVE state for guest_code */
> >+      xstate = vm_vaddr_alloc_pages(vm, DIV_ROUND_UP(XSAVE_SIZE, PAGE_SIZE));
> >+      memset(addr_gva2hva(vm, xstate), 0, DIV_ROUND_UP(XSAVE_SIZE, PAGE_SIZE));
>
>                                             ^ this should be the size in bytes instead of in pages. Right?

Right, thanks for catching that. I will fix it in the next version.