From patchwork Tue Feb 21 16:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CCEDC64ED6 for ; Tue, 21 Feb 2023 16:37:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234697AbjBUQhW (ORCPT ); Tue, 21 Feb 2023 11:37:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234670AbjBUQhU (ORCPT ); Tue, 21 Feb 2023 11:37:20 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D48C279AB for ; Tue, 21 Feb 2023 08:37:19 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id s9-20020a056a00194900b005a8c5cd5ae9so2629923pfk.22 for ; Tue, 21 Feb 2023 08:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=2iAI7qeN019fW7cnXiCIU1jbXC6JQmM9w058O8z3YH8=; b=XdkwDudCAzkUeqDZelIh5hAd5V3dHZzXBuFYZkqJd4pFfa+UTybJ8/AW+lAhYwqmS+ tbVt7VgxCnQmFM8/M2zF08LXl+P5rYttqkZsSMpRyNm2aUA2qkAZtGyIcbLnnVGKH7MB vhtd85nvW4gXenpyrZSEHHvz0+5qG0Ei5unm5oCB1/Qmmt3XyFzr8cJWPQfnh05mvVAV jpcjB8DFA/xaMuE68egf7ZIkGP57N7Fc7cCyBUTy31SaY7FwcTnTA1B86Fv9eMZ5LzA+ OY1P17jE1KaBI0GR9zW0iasO6w+Zn6hq5XF74zuLr9/ITXX3ToAx4IVTHsLJQoRAX22W ccKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2iAI7qeN019fW7cnXiCIU1jbXC6JQmM9w058O8z3YH8=; b=jsClZ+jE1QoiC3lPoje9snHnr9ULBO3o2t2Qc/Glfs+cgVIRSzVzdZrCfTWMe675nS FhU3zyai1OpQpdyeyd4NpPRckuKYNs35J/7vL0kREeoUGK3o5TG86+NjXviOjLV2mKhR BUFZ8btfME3HKM1k3+PmXdr+lt+0TZwoJQBZ0VC/zx8UgS+u+5oqSUJlIzHbrf75vyOS ql8lRswUR0sfAZc+ZOLdLUVRbsnefKynQlxJ6LTaOG2lCIDEQpKhDS9oiBQ2L+5Wpa1o DxIB1Shyr0yFJaXGnwnuqxW+MEt3pXsMmSGfm5Nja3SbS9r+YFOtjTEo9RnCT7oLsA/p wm7w== X-Gm-Message-State: AO0yUKW/hUfkzqT29wGP5c11VLnKHCFL5TgaLrD76qZCpMDECNnCpFdS 2wxH1SUUyrfL87oqp96W2UZkssI3aUKt X-Google-Smtp-Source: AK7set8LvhHN5qmTlVL5B5s+7zuXmCqcFbefrPXxO60eZ8HvEU34oKqDiVYD48Dd6NrtMWxW9iZ6W1TH5i+F X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:2c4f:0:b0:502:2111:ba7c with SMTP id s76-20020a632c4f000000b005022111ba7cmr669064pgs.2.1676997438814; Tue, 21 Feb 2023 08:37:18 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:43 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-2-mizhang@google.com> Subject: [PATCH v3 01/13] x86/fpu/xstate: Avoid getting xstate address of init_fpstate if fpstate contains the component From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Avoid getting xstate address of init_fpstate if fpstate contains the xstate component. Since XTILEDATA (bit 18) was turned off in xinit, when KVM calls __raw_xsave_addr(xinit, 18), it triggers a warning as follows. __raw_xsave_addr() is an internal function that assume caller does the checking, ie., all function arguments should be checked before calling. So, instead of removing the WARNING, add checks in __copy_xstate_to_uabi_buf(). [ 168.814082] ------------[ cut here ]------------ [ 168.814083] WARNING: CPU: 35 PID: 15304 at arch/x86/kernel/fpu/xstate.c:934 __raw_xsave_addr+0xc8/0xe0 [ 168.814088] Modules linked in: kvm_intel dummy bridge stp llc cdc_ncm cdc_eem cdc_ether usbnet mii ehci_pci ehci_hcd vfat fat cdc_acm xhci_pci xhci_hcd idpf(O) [ 168.814100] CPU: 35 PID: 15304 Comm: amx_test Tainted: G S O 6.2.0-smp-DEV #6 [ 168.814103] RIP: 0010:__raw_xsave_addr+0xc8/0xe0 [ 168.814105] Code: 83 f9 40 72 b0 eb 10 48 63 ca 44 8b 04 8d 60 13 1e 82 eb 03 41 89 f8 44 89 c1 48 01 c8 48 83 c4 08 5d c3 cc 0f 0b 31 c0 eb f3 <0f> 0b 48 c7 c7 c7 28 11 82 e8 da 30 b0 00 31 c0 eb e1 66 0f 1f 44 [ 168.814106] RSP: 0018:ff110020ef79bc90 EFLAGS: 00010246 [ 168.814108] RAX: ffffffff821e0340 RBX: 0000000000000012 RCX: 0000000000000012 [ 168.814109] RDX: 0000000000000012 RSI: 80000000000206e7 RDI: 0000000000040000 [ 168.814110] RBP: ff110020ef79bc98 R08: 0000000000000a00 R09: 0000000000000012 [ 168.814112] R10: 0000000000000012 R11: 0000000000000004 R12: ffa00000089f2a40 [ 168.814113] R13: 0000001200000000 R14: 0000000000000012 R15: ff110020ef288b00 [ 168.814114] FS: 00007f1812761300(0000) GS:ff11003fff4c0000(0000) knlGS:0000000000000000 [ 168.814116] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 168.814117] CR2: 00007f1812555008 CR3: 0000002093a80002 CR4: 0000000000373ee0 [ 168.814118] DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 [ 168.814119] DR3: 0000000000000000 DR6: 00000000fffe07f0 DR7: 0000000000000400 [ 168.814120] Call Trace: [ 168.814121] [ 168.814122] __copy_xstate_to_uabi_buf+0x3cb/0x520 [ 168.814125] fpu_copy_guest_fpstate_to_uabi+0x29/0x50 [ 168.814127] kvm_arch_vcpu_ioctl+0x9f7/0xee0 [ 168.814130] ? __kmem_cache_free+0x16b/0x220 [ 168.814133] kvm_vcpu_ioctl+0x47c/0x5a0 [ 168.814136] __se_sys_ioctl+0x77/0xc0 [ 168.814138] __x64_sys_ioctl+0x1d/0x20 [ 168.814139] do_syscall_64+0x3d/0x80 [ 168.814142] entry_SYSCALL_64_after_hwframe+0x63/0xcd [ 168.814146] RIP: 0033:0x7f1812892c87 [ 168.814148] Code: 5d c3 cc 48 8b 05 39 1d 07 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 cc cc cc cc cc cc cc cc cc cc b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 09 1d 07 00 f7 d8 64 89 01 48 [ 168.814149] RSP: 002b:00007ffc4cebf538 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 [ 168.814151] RAX: ffffffffffffffda RBX: 00007f1812761280 RCX: 00007f1812892c87 [ 168.814152] RDX: 00000000004dcda0 RSI: 000000009000aecf RDI: 0000000000000007 [ 168.814153] RBP: 0000000000002b00 R08: 00000000004d5010 R09: 0000000000002710 [ 168.814154] R10: 00007f1812906980 R11: 0000000000000246 R12: 00000000004d8110 [ 168.814155] R13: 0000000000000004 R14: 00000000004d78b0 R15: 0000000000000004 [ 168.814156] [ 168.814157] ---[ end trace 0000000000000000 ]--- Fixes: e84ba47e313d ("x86/fpu: Hook up PKRU into ptrace()") Signed-off-by: Mingwei Zhang --- arch/x86/kernel/fpu/xstate.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 714166cc25f2..5cc1426c3800 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -1063,6 +1063,7 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate, struct xregs_state *xsave = &fpstate->regs.xsave; struct xstate_header header; unsigned int zerofrom; + void *xsave_addr; u64 mask; int i; @@ -1151,10 +1152,11 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate, pkru.pkru = pkru_val; membuf_write(&to, &pkru, sizeof(pkru)); } else { - copy_feature(header.xfeatures & BIT_ULL(i), &to, - __raw_xsave_addr(xsave, i), - __raw_xsave_addr(xinit, i), - xstate_sizes[i]); + xsave_addr = (header.xfeatures & BIT_ULL(i)) ? + __raw_xsave_addr(xsave, i) : + __raw_xsave_addr(xinit, i); + + membuf_write(&to, xsave_addr, xstate_sizes[i]); } /* * Keep track of the last copied state in the non-compacted From patchwork Tue Feb 21 16:36:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148182 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7BBD6C61DA3 for ; Tue, 21 Feb 2023 16:37:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234731AbjBUQh3 (ORCPT ); Tue, 21 Feb 2023 11:37:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234702AbjBUQhW (ORCPT ); Tue, 21 Feb 2023 11:37:22 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 749E02CC48 for ; Tue, 21 Feb 2023 08:37:21 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id u15-20020a17090341cf00b0019af23e69dcso2386879ple.19 for ; Tue, 21 Feb 2023 08:37:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=CDOmnOlE8Y16AZivwv4VrFjTYze8Lvbli++k4cFr8iw=; b=PAhlZ3TH/qi87Rr35Iq03hgqMaNyTkBefespOAIKOR/aUKjLdJ5kjRUHll7B1SOPRP caqMqqEaoONZstLTVWne2rgdF7JqpXohyWkg8KiM6ga+4pg31UD/3Cy1IV4e153IF8O4 CTbMT7hYH07pc+exh90qXksXCE7KWlUOajHS6W/SoG+BtS0ENgjnEFBKI8GM2EdZ/uai 2nkqhBr70racrzPMN0lpvzrhC6P7WB50lH5b8H2C53mPkX3xwEBdoCMPyHV1JWUM5FSV sHoE4/Zem+o5Bb4PpV672rHwIQ7Ggdn1D+8Qorn7Dfozq/9s3VP+OVk4vc93j+4aUypw kTXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CDOmnOlE8Y16AZivwv4VrFjTYze8Lvbli++k4cFr8iw=; b=OrCoiFcC4vhfLRSiFtHa3YDVnY/1JqRMLCkaG/SYa5d401lrJ80mwdY3XzItNeSITn aLPeiQouEMSc6aeDWmX/0pSRWkZ0iwFj9Fdm5LItvrqY6xWLz8QkNxXCEQDNr/Ju0Lbo fKgBBHOBXxV/w2S0aGpXloiwJQDvfZhVLy731/EnHFoN2rxdWN23eL7FxBPBaQknoFXy x5tyCJjI6r4kpJpXsJn2IKSn4DRdijdKUuGe7Qg9+YpIqLYJwYcbF28tSFppG0bpawxc YP9PEGeIzdIPl2LwJVu6Rp84Gr02UHD1Sh6zj6NuYzMczW4E8zTBFZpl9HTBFoy5Z+MZ t6RQ== X-Gm-Message-State: AO0yUKUV1qeA8n56zMLvr//bJ+DRP+ojzncemkwZW+QqU69M2lpmDX/y 2mOt6FmJ/4iM7+VW9P+nvnKHUfGVaint X-Google-Smtp-Source: AK7set9AbFU6MwOpGnqsU4KVjGfpEIXXqS1rDAeVKZ15ImsolzbD3XEA4itgbEXg6SUnKjup0K78dciNs0gt X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:903:2651:b0:19b:8cbb:30fe with SMTP id je17-20020a170903265100b0019b8cbb30femr708174plb.13.1676997440971; Tue, 21 Feb 2023 08:37:20 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:44 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-3-mizhang@google.com> Subject: [PATCH v3 02/13] KVM: selftests: x86: Add a working xstate data structure From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add a working xstate data structure for the usage of AMX and potential future usage on other xstate components. AMX selftest requires checking both the xstate_bv and xcomp_bv. Existing code relies on pointer arithmetics to fetch xstate_bv and does not support xcomp_bv. So, add a working xstate data structure into processor.h for x86. Suggested-by: Sean Christopherson Signed-off-by: Mingwei Zhang --- .../selftests/kvm/include/x86_64/processor.h | 12 +++++++ tools/testing/selftests/kvm/x86_64/amx_test.c | 36 ++++++------------- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index b1a31de7108a..5cfd7ef40d78 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -45,6 +45,18 @@ #define X86_CR4_SMAP (1ul << 21) #define X86_CR4_PKE (1ul << 22) +struct xstate_header { + u64 xstate_bv; + u64 xcomp_bv; + u64 reserved[6]; +} __attribute__((packed)); + +struct xstate { + u8 i387[512]; + struct xstate_header header; + u8 extended_state_area[0]; +} __attribute__ ((packed, aligned (64))); + /* Note, these are ordered alphabetically to match kvm_cpuid_entry2. Eww. */ enum cpuid_output_regs { KVM_CPUID_EAX, diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index bd72c6eb3b67..bb9dc0008f43 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -41,10 +41,6 @@ #define XSAVE_HDR_OFFSET 512 -struct xsave_data { - u8 area[XSAVE_SIZE]; -} __aligned(64); - struct tile_config { u8 palette_id; u8 start_row; @@ -103,13 +99,13 @@ static inline void __tilerelease(void) asm volatile(".byte 0xc4, 0xe2, 0x78, 0x49, 0xc0" ::); } -static inline void __xsavec(struct xsave_data *data, uint64_t rfbm) +static inline void __xsavec(struct xstate *xstate, uint64_t rfbm) { uint32_t rfbm_lo = rfbm; uint32_t rfbm_hi = rfbm >> 32; asm volatile("xsavec (%%rdi)" - : : "D" (data), "a" (rfbm_lo), "d" (rfbm_hi) + : : "D" (xstate), "a" (rfbm_lo), "d" (rfbm_hi) : "memory"); } @@ -158,16 +154,6 @@ static void set_tilecfg(struct tile_config *cfg) } } -static void set_xstatebv(void *data, uint64_t bv) -{ - *(uint64_t *)(data + XSAVE_HDR_OFFSET) = bv; -} - -static u64 get_xstatebv(void *data) -{ - return *(u64 *)(data + XSAVE_HDR_OFFSET); -} - static void init_regs(void) { uint64_t cr4, xcr0; @@ -184,7 +170,7 @@ static void init_regs(void) static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, struct tile_data *tiledata, - struct xsave_data *xsave_data) + struct xstate *xstate) { init_regs(); check_cpuid_xsave(); @@ -205,9 +191,9 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, __tilerelease(); GUEST_SYNC(5); /* bit 18 not in the XCOMP_BV after xsavec() */ - set_xstatebv(xsave_data, XFEATURE_MASK_XTILEDATA); - __xsavec(xsave_data, XFEATURE_MASK_XTILEDATA); - GUEST_ASSERT((get_xstatebv(xsave_data) & XFEATURE_MASK_XTILEDATA) == 0); + xstate->header.xstate_bv = XFEATURE_MASK_XTILEDATA; + __xsavec(xstate, XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(!(xstate->header.xstate_bv & XFEATURE_MASK_XTILEDATA)); /* xfd=0x40000, disable amx tiledata */ wrmsr(MSR_IA32_XFD, XFEATURE_MASK_XTILEDATA); @@ -244,7 +230,7 @@ int main(int argc, char *argv[]) struct kvm_run *run; struct kvm_x86_state *state; int xsave_restore_size; - vm_vaddr_t amx_cfg, tiledata, xsavedata; + vm_vaddr_t amx_cfg, tiledata, xstate; struct ucall uc; u32 amx_offset; int stage, ret; @@ -284,10 +270,10 @@ int main(int argc, char *argv[]) tiledata = vm_vaddr_alloc_pages(vm, 2); memset(addr_gva2hva(vm, tiledata), rand() | 1, 2 * getpagesize()); - /* 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, PAGE_SIZE * DIV_ROUND_UP(XSAVE_SIZE, PAGE_SIZE)); + vcpu_args_set(vcpu, 3, amx_cfg, tiledata, xstate); for (stage = 1; ; stage++) { vcpu_run(vcpu); From patchwork Tue Feb 21 16:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148183 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B504EC64EC7 for ; Tue, 21 Feb 2023 16:37:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234782AbjBUQha (ORCPT ); Tue, 21 Feb 2023 11:37:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234726AbjBUQh2 (ORCPT ); Tue, 21 Feb 2023 11:37:28 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CF222CFE3 for ; Tue, 21 Feb 2023 08:37:23 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id l1-20020a056a0016c100b0059395f5a701so2224011pfc.13 for ; Tue, 21 Feb 2023 08:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=AyHb4Yx7urg+Zx7LCzA3DPIwt3rV/2dFui2+3APs9Tw=; b=rJnHYpiq5KubUJYTSiL6hLKa3WdBN7dObACs3EooXynZnDtSUFMMac+rcUMHzOwXan N1auXr5kJDb0xBpddo87Mu10IQGJR64S8FHMz7w2VZCZrOABJv8RJQfeccvr41wzKuom CcPj7lu4XfpGMjIfHZj+AZxChF9kGaoUu1jJT6X6HY6KZdk9lD/y8fCAy9NdLTQ8U65X zFbtEdVVKjkf9uhBse6jbZoYCl5miFUFGutHh65L/bFqbxAsG3kbRVKbd+BUT/X+7qyw k4CuWZv7SUWSuzzMxtGskoyZqxq30YuNSC4xEkZuIFkGG0liJhveNy5yECEk8jlwxhMu w4yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AyHb4Yx7urg+Zx7LCzA3DPIwt3rV/2dFui2+3APs9Tw=; b=rlktbTfA7kXspK9yw8IktCzl1nu4985O+vKHFGaFBxfe7XKBjBL5twMmASjbBjRRVa a3YR/trpZ7WWYDz8bAEPiRpp0BavnPoLcj0brHQ5u8XZ7Dz+MTeDIDZA8qn58HYHmyQC 32xvx99E/O/UTyWB2vZsYamQq07ilmuSCaGERa5n+PHlpfReIYXrEp8BuuGTgsNE09Be 810XFjJMxAaguCmiIItdnEiV5cue0bW8FHBx5dYVeAHSFijb1Zz5zNcORUJ1Pw+WFJNx n3ntp3K/HOBYYEo4UgmjyUOuP3vLJWKw8gOYbTlI4A2ZRFRmCueyxZvvWuCa6WYGS20E fcYg== X-Gm-Message-State: AO0yUKXPaWAeik3flp7eegq1cCziFoB/nTMmNbpevGISEYWjUJKc4xrh u1j6hGiQeDbjkAD2lB6ro9YqgsKgsmwB X-Google-Smtp-Source: AK7set+WXUie8cV2x/2H7NwHmU008RDRGepmXDcXx6OTSn+v7LisP2WwfmcqvY9as4zuGcs0HwwzGct/WAfm X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a62:de44:0:b0:5a8:670c:c94e with SMTP id h65-20020a62de44000000b005a8670cc94emr859351pfg.12.1676997442517; Tue, 21 Feb 2023 08:37:22 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:45 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-4-mizhang@google.com> Subject: [PATCH v3 03/13] KVM: selftests: x86: Fix an error in comment of amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org After the execution of __tilerelease(), AMX component will be in INIT state. Therefore, execution of XSAVEC saving the AMX state into memory will cause the xstate_bv[18] cleared in xheader. However, the xcomp_bv[18] will remain set. Fix the error in comment. Also, update xsavec() to XSAVEC because xcomp_bv[18] is set due to the instruction, not the function. Finally, use XTILEDATA instead 'bit 18' in comments. Cc: Jim Mattson Cc: Venkatesh Srinivas Cc: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index bb9dc0008f43..16c857c1052e 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -190,7 +190,10 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, GUEST_SYNC(4); __tilerelease(); GUEST_SYNC(5); - /* bit 18 not in the XCOMP_BV after xsavec() */ + /* + * After XSAVEC, XTILEDATA is cleared in the xstate_bv but is set in + * the xcomp_bv. + */ xstate->header.xstate_bv = XFEATURE_MASK_XTILEDATA; __xsavec(xstate, XFEATURE_MASK_XTILEDATA); GUEST_ASSERT(!(xstate->header.xstate_bv & XFEATURE_MASK_XTILEDATA)); From patchwork Tue Feb 21 16:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148184 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB583C636D7 for ; Tue, 21 Feb 2023 16:37:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234807AbjBUQhd (ORCPT ); Tue, 21 Feb 2023 11:37:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234766AbjBUQha (ORCPT ); Tue, 21 Feb 2023 11:37:30 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7432B2BF for ; Tue, 21 Feb 2023 08:37:25 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536bf649e70so38999517b3.0 for ; Tue, 21 Feb 2023 08:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=b5cXkH41Dpz3xl6Z7o6kxBjd79dMhYH0BWx6BfiSfBo=; b=CZqHake47gq3cd03ZUsZh+xOkan8dZo2tmN+vrMtOJQriJNPTqmfglWH2l9ManWKVJ ze1EbMlWwtI2gznNO6XbtWUxOWwDC4cTM7CUf6WrRBL5FWgdYDu3fcCNnA9+BWCDiMYp i4GHjTBuI9ijI9LjZWNWantpodnjMqpS1kNGyrFtoSUd8vz1GJdeEtRhXpqBq3D8DSC8 5cUNM3sbtaxkSj2cJvJ4tDH9/kZlZ075/b2Lh7toAGX7RwWHeFQe/XA0pO7iCSbCjtIo A7C2ltL8CxMbBRvN3g61e/lXrHTT0bZJG3OAKapt8gRsAB8tv0bxsF/81Gp26/Tfmo4+ D9cQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=b5cXkH41Dpz3xl6Z7o6kxBjd79dMhYH0BWx6BfiSfBo=; b=f41mcZdyIs+Fi8gOSM5QUN3wL+iYI07EEA6pZYq7emvk7oc3ScxP0r1UgBN5sHS7Ah NbV0Z3vOXpG4Ia5udEVpwZHAvJV00xbFdvCQMp82p9H9Tgi3QAPlmiePUUrRlBCnwykP E/AlW98bH/ryM9L1w3iOHWEyQm1QN6Rt/WErAJVuSSgP/O/utR80ZCAQtuIOp/t6uI3T pcE1V3z4frkY1ptODGmiBOBO+wVEwqQ/1+Fm/kKzEJpnKXZUkWnpORxbAGxBDClSPnM0 0ttliL4rABk1iFU0RzWNeRGEfD6s8qQ/fsaHWYdHJYkQXtliq91BrSUuiJeXjU/OpcEC sTgQ== X-Gm-Message-State: AO0yUKXoO41oCSFTi/ClROMp006/sXU8IXdIXDM/r+JdQZkuXaTEvT5f LdyaZp+fDMHfxa92+ZcyF22tGdgIfIho X-Google-Smtp-Source: AK7set+lsrO0DRQyUKeLS34m+CI/REvkWAnKXiFjmVCheEFMJ7XVJNdadgKb6R5DIHKliO32zKTKPYD50nIW X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a25:828a:0:b0:959:9937:49ce with SMTP id r10-20020a25828a000000b00959993749cemr1788344ybk.188.1676997444339; Tue, 21 Feb 2023 08:37:24 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:46 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-5-mizhang@google.com> Subject: [PATCH v3 04/13] KVM: selftests: x86: Enable checking on xcomp_bv in amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org After tilerelease instruction, AMX tiles are in INIT state. According to Intel SDM vol 1. 13.10: "If RFBM[i] = 1, XSTATE_BV[i] is set to the value of XINUSE[i].", XSTATE_BV[18] should be cleared after xsavec. On the other hand, according to Intel SDM vol 1. 13.4.3: "If XCOMP_BV[i] = 1, state component i is located at a byte offset locationI from the base address of the XSAVE area". Since at the time of xsavec, XCR0[18] is set indicating AMX tile data component is still enabled, xcomp_bv[18] should be set. Complete the checks by adding the assert to xcomp_bv[18] after xsavec. Signed-off-by: Mingwei Zhang --- 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 16c857c1052e..ba8c0afdbac8 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -197,6 +197,7 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, xstate->header.xstate_bv = XFEATURE_MASK_XTILEDATA; __xsavec(xstate, XFEATURE_MASK_XTILEDATA); GUEST_ASSERT(!(xstate->header.xstate_bv & XFEATURE_MASK_XTILEDATA)); + GUEST_ASSERT((xstate->header.xcomp_bv & XFEATURE_MASK_XTILEDATA)); /* xfd=0x40000, disable amx tiledata */ wrmsr(MSR_IA32_XFD, XFEATURE_MASK_XTILEDATA); From patchwork Tue Feb 21 16:36:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148185 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 376EBC678DB for ; Tue, 21 Feb 2023 16:37:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234811AbjBUQhe (ORCPT ); Tue, 21 Feb 2023 11:37:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234772AbjBUQha (ORCPT ); Tue, 21 Feb 2023 11:37:30 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EF972D144 for ; Tue, 21 Feb 2023 08:37:26 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id o17-20020a17090ab89100b00230aa3c1350so1616327pjr.2 for ; Tue, 21 Feb 2023 08:37:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=LHzOHHZRF0Z0PxEe7g90IRKekQBPW5kSPBGZ896mCAw=; b=iYq/M/swxMz4Ajz5CWey7J9Cn2hGpOfZNKoeQVqLmLqWDDu83kf7cKxB5F54bE8hgY 6vq352hL3hkuyr+xvGGBPsMBFVU/kUaywZAPGbjpw45pwBVNsUBhXvaHp3p5ij76cNyt rDAfZbAgReB4EQSAA7OwInJ6lY9U5BvKp/01wMwOxtpg44NJRhHT8Xq4rTmDcrsxjTti pfGVpDEXEfEJGnxNtzFVmYPT2BiwBWDwDKgsfrnnVyf/fxGl4166/OjhO4zVgoSeAI5l SvSQxAOupvX+FgQXWxfzi4j2RPAPPbmJeclJTu28XTV+YePpR+2e/aj+jRqUzJYVs/du fzmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LHzOHHZRF0Z0PxEe7g90IRKekQBPW5kSPBGZ896mCAw=; b=Oawo25hl7156EJkT45tDK6jc/kOscxxjj0kFwWREEVwRQdGwDf0ZF1a4ZkD/NgyaG/ UV5FhR+08IKbgs/jIKsgCH8jJCihl2JydRK2jPLbFQq37S7EKNb/QQfTTM29Cu3v6VbP JTnS/VgeFy8zpe1YRFzugXpyhys4vJi34Qv4FXX1hlK75dne9fhvhsrjUcSmd4t0btf6 9FyJAxC6NgQogj12mQAERDw4r37xwntbyIkIdTfiIDQicA7Ud/9EF4SoM4hZAjfXg35W iVXI5SB3+uAUD9hHIni767sXqnNK6eztVP5XdVB3H5QtO13CSuW3uHxtnfH/fAVobJLD +9ZA== X-Gm-Message-State: AO0yUKU49u4kQKh8OFNuNxtAHcMjKLTH38s6Lwd4KJUhJkEwkOxxmwiN Q8B+sgQbbhSjlp4MCzP0gJgGpxoMS6oC X-Google-Smtp-Source: AK7set/FsPqQ8rlzY7E1G6gdIEFDYIPaZx1jD1gvFI1btYAhTJ4yElO3zkb5t9OHD55Nxe6cLFjy5KIM8l9A X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:3344:0:b0:502:e48d:6ea7 with SMTP id z65-20020a633344000000b00502e48d6ea7mr9485pgz.10.1676997445850; Tue, 21 Feb 2023 08:37:25 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:47 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-6-mizhang@google.com> Subject: [PATCH v3 05/13] KVM: selftests: x86: Add check of CR0.TS in the #NM handler in amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- 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 ba8c0afdbac8..ac49b14460b6 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -216,6 +216,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); GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); GUEST_SYNC(8); GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); From patchwork Tue Feb 21 16:36:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EBB6C64EC7 for ; Tue, 21 Feb 2023 16:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234837AbjBUQhk (ORCPT ); Tue, 21 Feb 2023 11:37:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234784AbjBUQhb (ORCPT ); Tue, 21 Feb 2023 11:37:31 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048492CFDE for ; Tue, 21 Feb 2023 08:37:27 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id z64-20020a636543000000b004fb4f0424f3so2015568pgb.14 for ; Tue, 21 Feb 2023 08:37:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=CiebZgZnEDP7VZY8GkyG9xLC+cq7WThHzeBIf6OXg2A=; b=jI478qIYl8eqgu3YXohpyPzECLUUXvFMIS+VtaoksIUpieQMTxJ7WVrtEPqL+SXA0R n28bqlflqmoXPFVylk4UPj+PnFocuOpDYwOtbN+ASUgjwpYRRNR2PSIXIPF+DeWz3u7z PMn0moezB10GhriN8s1FUiVpp7moukJ6tw4qNt7CAz6pIp14n1ede97Hv7AhAXg0pfUp 6PvZOczLkRMN/XtBVpaoISkiKB4Nr0O60ZWjqMcRvOp+cZr+Fj3L6/Uor8Yb4dffGETM ddhL5c7x1xz6hJUr65iOEmQwwBEdtlV0+89js8ai8btv7XH3iLXu6C+4e5Nvays9rPTD WZ9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=CiebZgZnEDP7VZY8GkyG9xLC+cq7WThHzeBIf6OXg2A=; b=QrmhG8qENE0XesmCzxXeMx9cBsPXTjEaBhFNnEO9sEexFz8DeS1Nt0Ao7RSKac7LTW OgTj9CqEJvtRnxPG+S0j3jSwlGhn5DloHlCcGGkh4ZNLLBgzg7ee/Ap9QA5CKLVmpBPn 2MIEpfcfQtu/WrLcvD5eAKyxg/ljwRH3Z0/VRoXwFFovsYKAAxVrJciifIYDC49/Jhum uCttTaOFNA0WzUzTnl5VLXoahvUAPrvezA8HtRJeGPKHvTetoj6cKxBSjSx8MNEHTk2b np4GavQ/gjiUBFCYaOF+IdN/dYP24+gZ4Ic42iYQwN8CGA/58QntMUInpS3LgHvqoXUt MBVw== X-Gm-Message-State: AO0yUKX6wG+83peTEklZPgTA8Wv6pdF2SJxJBEzqm6Quu8Mx9Thz3c91 lqHD/XbXiEp6nm8DU4NqdAMCUwlM06PY X-Google-Smtp-Source: AK7set/sjoRS/b8w2JVAxhnoQhQkHhjBNHss1dBGUzpg589CiqV6m1WV9H0wP2jbnxhKownzwWVPetSndLEN X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:902:f783:b0:199:1eba:e0ef with SMTP id q3-20020a170902f78300b001991ebae0efmr710853pln.4.1676997447502; Tue, 21 Feb 2023 08:37:27 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:48 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-7-mizhang@google.com> Subject: [PATCH v3 06/13] KVM: selftests: x86: Add the XFD check to IA32_XFD in #NM handler From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add an extra check to IA32_XFD to ensure the behavior is consistent with the AMX archtecture. In addition, repeat the checks across context switch to ensure the values of IA32_XFD and IA32_XFD_ERR are well preserved. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index ac49b14460b6..296c954dfd6d 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -218,8 +218,10 @@ void guest_nm_handler(struct ex_regs *regs) GUEST_SYNC(7); GUEST_ASSERT((get_cr0() & X86_CR0_TS) == 0); GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(rdmsr(MSR_IA32_XFD) & XFEATURE_MASK_XTILEDATA); GUEST_SYNC(8); GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(rdmsr(MSR_IA32_XFD) & XFEATURE_MASK_XTILEDATA); /* Clear xfd_err */ wrmsr(MSR_IA32_XFD_ERR, 0); /* xfd=0, enable amx */ From patchwork Tue Feb 21 16:36:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148187 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F05EC61DA3 for ; Tue, 21 Feb 2023 16:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234877AbjBUQh5 (ORCPT ); Tue, 21 Feb 2023 11:37:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234816AbjBUQhf (ORCPT ); Tue, 21 Feb 2023 11:37:35 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0E292CFE3 for ; Tue, 21 Feb 2023 08:37:30 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id q15-20020a63d60f000000b00502e1c551aaso265845pgg.21 for ; Tue, 21 Feb 2023 08:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=w2vMSj1pqCX3K6DVzozBWZ+Uf2g2Y7SPE2PRI36z9us=; b=DajTbx4B7dtFVQSGSpYck2dVAgO/b8AL4deOPuANwJ64sRfLWumNJeJtLq/ZJhv1cd yZWJoeLFSSuBT/rlTQHY7vzTP4QT3n/5udfMxWhlVkEWx4t5gCEsKVk8sNPlw4dDbHA0 Ursp80w7OYSX68Zf6OoswIr88aR9PE0Qfsr7QHn9+wrdLLSluIsk6n9xW0rfPs7VeskL pq8Vr+ypMELlFgBAowcAcH2M9km1WyH9jA/iXN8M1XBA/G0Z/B319HA3S0cOzj7+0iIe USKzDbX8ParyU9iv0Dge7ttZs31dbK/DxHkLUDoeCXa+esdohVJqyFf9LjHvGXXzV6JK ac9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=w2vMSj1pqCX3K6DVzozBWZ+Uf2g2Y7SPE2PRI36z9us=; b=Z5RPrSXhcC8iO7lPXqJDje4kBsClK9pyB/PL5IiWbdyqAvE1ZBIpCHsXf2Q1rpZfn1 bxMxvlIB/Eh5o8+JoAda1Llxlqp6cwBtv/8CyTAlOVQxbpTzuBVNXb6L7WnIUVgUWOg2 dzKGGFkWMqw4SIKSO7IkA2pTWsl3grh53HswDcaIxRtx6aBOhVCUu0LobApmUzbF+D5O cJ9EPNJs1Ck0L8UM6YNDi1EGlJq6Wba77cVvBPc2hqC1w0JjvsHsxSVJWIvXXOQWKu5/ 6jlaivwxldwDIxYhkDUk3W6ESfdz7LOnDZdEPoNB1Kdv3DOIbBBxmtwdCcxC+zaULLDA VT1g== X-Gm-Message-State: AO0yUKXyqnw6oI70U70AycC9er3jyUBNmBbwFxISfBQ37I2MNS+YXGa0 KXOma5TVAK9MgvbyNlSddVvJPIvkDWNu X-Google-Smtp-Source: AK7set8qAXOR2/Hd1KkJ1/GP+RXMvy0M0Bdho4jquC9vVEHvs+inVCvxtWU0xDTeZGKfNFydgvkLwrV+5g1l X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:902:f811:b0:19a:f153:b73e with SMTP id ix17-20020a170902f81100b0019af153b73emr729491plb.4.1676997449336; Tue, 21 Feb 2023 08:37:29 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:49 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-8-mizhang@google.com> Subject: [PATCH v3 07/13] KVM: selftests: x86: Fix the checks to XFD_ERR using and operation From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Fix the checks to XFD_ERR using logical AND operation because XFD_ERR might contain more information in the future. According Intel SDM Vol 1. 13.14: "Specifically, the MSR is loaded with the logical AND of the IA32_XFD MSR and the bitmap corresponding to the state component(s) required by the faulting instruction." So fix the check by using AND instead of '=='. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 296c954dfd6d..62fff3363b3b 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -217,10 +217,10 @@ 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); - GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) & XFEATURE_MASK_XTILEDATA); GUEST_ASSERT(rdmsr(MSR_IA32_XFD) & XFEATURE_MASK_XTILEDATA); GUEST_SYNC(8); - GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) == XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(rdmsr(MSR_IA32_XFD_ERR) & XFEATURE_MASK_XTILEDATA); GUEST_ASSERT(rdmsr(MSR_IA32_XFD) & XFEATURE_MASK_XTILEDATA); /* Clear xfd_err */ wrmsr(MSR_IA32_XFD_ERR, 0); From patchwork Tue Feb 21 16:36:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CEDDC64EC7 for ; Tue, 21 Feb 2023 16:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234846AbjBUQiB (ORCPT ); Tue, 21 Feb 2023 11:38:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234841AbjBUQhl (ORCPT ); Tue, 21 Feb 2023 11:37:41 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9185D2CFD0 for ; Tue, 21 Feb 2023 08:37:31 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id cn3-20020a056a00340300b0059085684b50so2595985pfb.16 for ; Tue, 21 Feb 2023 08:37:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1676997451; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=6eya8RvAso0oVSkPG+SqCdov6cQuqd8KcPbcmXzNxTo=; b=TVd18GDSarLsA2/lPOgVrYfYPYZtvFYr4jPuI+f6by2zc3e5pGx1TLe7+8F/v5CLcD C+ZUrDVI4U1jkWxXvQCJTohZULj91OSBWXga7XMNHoIQ3y9p1MLfmHOOfYPQREsSOSVx g2LY0iK/jP8K4IOeK/N+J+awTSjk0wSuqNeNvwP34Qzf7NDM+YArW/aoRPdbQATy4QU1 iVfIDNRyN55PI5w/GyAPsWGgV/GAQlDYeyBx5D/HeDQ9QmeP44S8Gix/v/R9ZkOr8sJU QoVSUyIk00vSaTEyVgZc4PCsBDX7yXWROpx9vZXMV81E9I5nSvgGpWREuTz/5ZJP9+KS vIXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1676997451; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6eya8RvAso0oVSkPG+SqCdov6cQuqd8KcPbcmXzNxTo=; b=dNrtyhiLrHmZp4g/CSXNYO0pY1ANQx3EGASk5hwPjzp5RqTvpvMQpafk/Pw0QHCxOJ VZOLQBuQWGs47JWaWcFG/FswkM93HF8HlKb1M56mObWbLwCUuiTQtxmOv4RcM0GYnKu3 QH/XWHhB+2C4wjImBFmo9oEIbAxrwGAOaxjn7wHfRxLICtx8tA4D0GRl4Uxb1ezRWFpW Mhi/UVRh9LVFmIpizmtYy/KAkDK6WY0gU4hJjsLL1P1NRDHTEzuSVCXZjU6wUhMIh+Xk 5k8Ocf4+rvZeUCIL815yobubnZ2/SjS4g2NuIfaay/tA08S3y2V+HxHcSwc3xqzkyiEl EqWg== X-Gm-Message-State: AO0yUKUxcGZpFHBslFEjBP31zmvF/CgO1d1PrsqWhDJM4C8sCRgooUd4 lBljd6T2GRx8KeyMc0HYl0MYAsslrVbh X-Google-Smtp-Source: AK7set9GqgvFSkGmlkChA0S8+JUftH2z6x67/RS3rMWptrG7AL4MP9X7ck4FrIKaNCD4eHIBUs6gU2jSXexQ X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a62:c143:0:b0:593:d4cb:dba2 with SMTP id i64-20020a62c143000000b00593d4cbdba2mr655957pfg.13.1676997451249; Tue, 21 Feb 2023 08:37:31 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:50 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-9-mizhang@google.com> Subject: [PATCH v3 08/13] KVM: selftests: x86: Repeat the checking of xheader when IA32_XFD[XTILEDATA] is set in amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Repeat the checking of AMX component in xheader after XSAVEC when IA32_XFD[XTILEDATA] is set. This check calibrates the functionality scope of IA32_XFD: it does not intercept the XSAVE state management. Regardless of the values in IA32_XFD, AMX component state will still be managed by XSAVE* and XRSTOR* as long as the corresponding bits are set XCR0. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 62fff3363b3b..724e991ba814 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -201,6 +201,16 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, /* xfd=0x40000, disable amx tiledata */ wrmsr(MSR_IA32_XFD, XFEATURE_MASK_XTILEDATA); + + /* + * XTILEDATA is cleared in xstate_bv but set in xcomp_bv, this property + * remains the same even when amx tiledata is disabled by IA32_XFD. + */ + xstate->header.xstate_bv = XFEATURE_MASK_XTILEDATA; + __xsavec(xstate, XFEATURE_MASK_XTILEDATA); + GUEST_ASSERT(!(xstate->header.xstate_bv & XFEATURE_MASK_XTILEDATA)); + GUEST_ASSERT((xstate->header.xcomp_bv & XFEATURE_MASK_XTILEDATA)); + GUEST_SYNC(6); GUEST_ASSERT(rdmsr(MSR_IA32_XFD) == XFEATURE_MASK_XTILEDATA); set_tilecfg(amx_cfg); From patchwork Tue Feb 21 16:36:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148189 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7E90C61DA3 for ; Tue, 21 Feb 2023 16:38:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234919AbjBUQiK (ORCPT ); Tue, 21 Feb 2023 11:38:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234866AbjBUQht (ORCPT ); Tue, 21 Feb 2023 11:37:49 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0842D2CFDC for ; Tue, 21 Feb 2023 08:37:33 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id g13-20020a63f40d000000b005015be7b9faso2219205pgi.15 for ; Tue, 21 Feb 2023 08:37:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=iiRrB1La2XaBQ8X9jljAYPafLfxRlgHLwbfoJQq6vJc=; b=fAH3hCUl7uqbwUtd34iFW4FxURELK93IK/02Vx0KEZ+6k0X581BSlqbabdxNOqoBgo meEl6t2ZiDTIdhAK579ZxSCzIGixUue+EXZ/tFu3HlVbvdHU3QCq9IeS3SSra0MJxJ7i nbq8TQ51m3339oT33ydPu9XaJMCzD1QjV689OxEdbjY4FRc7QacllNDSkJuhhi5eFXoL TcOKXj4ubRAQ5sUHN9Y8qlxN5G8h5tss7+dpwoJDOirM9qLKmpDmS1YaqKN3XDYNUPCz zOiltEGWXv2rsSRM7wh4fzWdgxRKe5qA04L0Htv1bI7O/TZF70MfnASoGoq6SDuVhfq9 FSxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iiRrB1La2XaBQ8X9jljAYPafLfxRlgHLwbfoJQq6vJc=; b=zTx7QSenRoHBpxPZxqxrC2N6XXbPIH8royNmP+0uuAzeujcKyuETY1jC9R3wi2jWCt jMidl0bycEW8h8oxmrs86khC0xaBYGsmMkmSdnvnhXrLNuAUwAGPUoRiF8nNOL/B3Rlm 0BOG/0mdVDnmbELZG/FqUQ/BnJS/+kQGJ6B7SjZdvP50fr3RIOd1I/Xj90i/Y0kivigl rN4A5vF5dhgTRsJa3TUeHwkJEAkvvFLRhbc4XFEXkIvH6I2U4v++8z1E7TGiKRx524vu IclzfI7DCorPMI3eO6mQFOWFQNwL2Le3V4GUoonrJuTvR0N0ti8DD9TsoC6pOu0vc58w rlyA== X-Gm-Message-State: AO0yUKUsQUSZtEoWxYMPsl22ZjYU1HzvO9L+MLY3RTGEdgTpKkgDrcOF UD1vPWFY2foyWa/+ymHo4KkbysCVy884 X-Google-Smtp-Source: AK7set+yc+UPbgHRSjGfHtztbpCerRitgUNtWXsAYPaaIY95QIVoKUQZahzKckS3seET9A2paVtccvS0Jy9Q X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:7a56:0:b0:4fb:b88f:e98a with SMTP id j22-20020a637a56000000b004fbb88fe98amr733518pgn.7.1676997453182; Tue, 21 Feb 2023 08:37:33 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:51 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-10-mizhang@google.com> Subject: [PATCH v3 09/13] KVM: selftests: x86: Assert that XTILE is XSAVE-enabled From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Aaron Lewis Assert that XTILE is XSAVE-enabled. check_xsave_supports_xtile() doesn't actually check anything since its return value is not used. Add the intended assert. Opportunistically, move the assert to a more appropriate location: immediately after XSETBV and remove check_xsave_supports_xtile(). Fixes: 5dc19f1c7dd3 ("KVM: selftests: Convert AMX test to use X86_PROPRETY_XXX") Signed-off-by: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 724e991ba814..d1fbf8936192 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -115,11 +115,6 @@ static inline void check_cpuid_xsave(void) GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE)); } -static bool check_xsave_supports_xtile(void) -{ - return __xgetbv(0) & XFEATURE_MASK_XTILE; -} - static void check_xtile_info(void) { GUEST_ASSERT(this_cpu_has_p(X86_PROPERTY_XSTATE_MAX_SIZE_XCR0)); @@ -166,6 +161,7 @@ static void init_regs(void) xcr0 = __xgetbv(0); xcr0 |= XFEATURE_MASK_XTILE; __xsetbv(0x0, xcr0); + GUEST_ASSERT(__xgetbv(0) & XFEATURE_MASK_XTILE); } static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, @@ -174,7 +170,6 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, { init_regs(); check_cpuid_xsave(); - check_xsave_supports_xtile(); check_xtile_info(); GUEST_SYNC(1); From patchwork Tue Feb 21 16:36:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148190 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CF62C636D7 for ; Tue, 21 Feb 2023 16:38:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234881AbjBUQiQ (ORCPT ); Tue, 21 Feb 2023 11:38:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234883AbjBUQh6 (ORCPT ); Tue, 21 Feb 2023 11:37:58 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 828BB2B2BF for ; Tue, 21 Feb 2023 08:37:35 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id o17-20020a17090ab89100b00230aa3c1350so1616486pjr.2 for ; Tue, 21 Feb 2023 08:37:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=zK45IqxP1dNnwcbmnxiq3xISvws3WCC9xNptFeG9RGY=; b=Gat5zcpIdqxDUUs9rI3U/ZnYNeRDCgoLyPWphjHiI0NoTTfVzwEtdYFnegIry5t6Bp whgGCn3+2SGGQhoJ/Ak0JM25nAjVuGShFnUeP746rfB5ELk7VYHyBlGXNw+bWuGAbNpU Z525o6MWE7QbLXs3z2fVNZ4J51w6z4iKnak8a42nQwmn1v8qeLPWnihkqbYvcUxT7vhr giL415jit6jUW/p7Vpsl22Ngx/8PNouqTuGxAAKzF7lGNpwMdmK+XhAKYNCUkyIcIerb qLTyR4Yo/3lE6VnJT37dMOAG6/ZJdYn60tzqrpczNKX16BB4mcEUoWRZAguwPrJANmUd Ry7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zK45IqxP1dNnwcbmnxiq3xISvws3WCC9xNptFeG9RGY=; b=CGsZfFScZVKszxSl7PXbeojpxt0aqo9JMGqRYJthGsJ1ytB8XbM/HfLcoUeDlKhwET xJZ6429/HTV8xXL3GPfJrmDpzR4ByFDOKf3v6StASNdwcvUoG+rpdFyLEiW6imv8eGly 1ujuGBetyUuJHzjpEwewkHVuAdJjC2o4Nn7BlzxC8Pqbk+mB7SrKs06F3KNHKqnIdOG5 NTptbmuPm/YinewQCKml4KfBJ2wRi//EPl0a5q0z78PBgDsTDYdrd5uSHlLYijnukBig 6kExPygk40jZlSPwbYj0xiugAeDhCEH1jVgMaS0nauL5edFntxn8bsbazpd6ul31fl/X qmJg== X-Gm-Message-State: AO0yUKWQ6uCgp8i9a9bM5sZEqr+FVEi5CdlwZ8zXXoqc1V1HFmNgVeUC T6VjAWpAKcLoLJBDJF8pTPR4OuTD1bJu X-Google-Smtp-Source: AK7set+x/m6cFFW80guHk8IlWuUdvUqC/N4oLPQVmmgR4cwzKWJ2ArdlnfautVAaiE3SLYGPvp+vL45F6igz X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a05:6a00:450a:b0:593:d27e:10e0 with SMTP id cw10-20020a056a00450a00b00593d27e10e0mr792249pfb.3.1676997455081; Tue, 21 Feb 2023 08:37:35 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:52 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-11-mizhang@google.com> Subject: [PATCH v3 10/13] KVM: selftests: x86: Assert that both XTILE{CFG,DATA} are XSAVE-enabled From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Aaron Lewis Assert that both XTILE{CFG,DATA} are XSAVE-enabled. The original check in amx_test only ensures at least one of the XTILE bits are set, XTILECFG or XTILEDATA, when it really should be checking that both are set. Assert that both XTILECFG and XTILEDATA a set. Fixes: bf70636d9443 ("selftest: kvm: Add amx selftest") Signed-off-by: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index d1fbf8936192..1a1565126255 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -161,7 +161,7 @@ static void init_regs(void) xcr0 = __xgetbv(0); xcr0 |= XFEATURE_MASK_XTILE; __xsetbv(0x0, xcr0); - GUEST_ASSERT(__xgetbv(0) & XFEATURE_MASK_XTILE); + GUEST_ASSERT((__xgetbv(0) & XFEATURE_MASK_XTILE) == XFEATURE_MASK_XTILE); } static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, From patchwork Tue Feb 21 16:36:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 21F59C636D7 for ; Tue, 21 Feb 2023 16:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234895AbjBUQiV (ORCPT ); Tue, 21 Feb 2023 11:38:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234896AbjBUQiA (ORCPT ); Tue, 21 Feb 2023 11:38:00 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0319C2DE4A for ; Tue, 21 Feb 2023 08:37:37 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id h18-20020a056a001a5200b005a8b508aecdso2411455pfv.20 for ; Tue, 21 Feb 2023 08:37:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=iGUJ74hklZ9IC2JyxMgKiaxBDpYa7dvkgnZvEvOVY64=; b=rLLClLSLRO2Tp90/r7PQXQ0zXhJU4bH3YbgREwBPeec4T+BSaGhme3PS6pRryZIl2I 3Vx6/7T14jB9wybO+c1oOfMR7bCqjQQ/VnYnqMjA6woidQlCuLjLIdfMuBQdNW48M941 Ri2FghSa86fAhOxHk5FbQr06jmgvgYyjPOrcT1UStStg1SBpOofv9Yg9vgeVv+T0o5XV u1OEO1L0WyfNDRkM9ADA7YHu99CylDNoC72jQ2FPD4hpuo8q+nPo7sttGxOYOMxUEcy9 3sXqIBJywR+kvP6c1+AAe5h7SsBxplT6ztBAGAMYaw4kKN6FKiGbS9msYuRp8SiysKQo dDrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=iGUJ74hklZ9IC2JyxMgKiaxBDpYa7dvkgnZvEvOVY64=; b=PR+OtaetJRDZdyYzNGzKMs4cYh0ew7ec/tnxf616+x4Jh0WdQtDp+C830WbwtKdl9Z PVyDsDFN+LdBQ3H+u90DtG7aRBfA5px4ZIUw5pxU5Zg0DiiERncUio1p4Ocf80bu+qxG E54wpFCRVtFlpxFLwzWfBKyZCqzrjHXUjea6Ebi8BnPUvTd5uqFF/jFkizp46sjp0kCn PShwYw/BiPvGAIFMeGGI355XGPboEGU10CmN22R0vhhaKeHLxsADoAfphbaN7JXhkOfa TFTPMFAzvn3MlxaXCTLVOrYsdeuWrBN/J52jeCspaM7kAYjc8yGoieRHJZkXfue3x9y2 RaMA== X-Gm-Message-State: AO0yUKWGq0wf/aTWb5oR1z1p16ZCjX3lrfd/K0U1AZ2epq22P4oMVaYl pEAHMtiARz862PyzLm7UDwDd72Wnkj9y X-Google-Smtp-Source: AK7set+m1UL4EQdVkgxFOWJtVr69/x8dmtIcB6yIkcdQ2Uw9+EflID8jEffCwLg3f81uwnaUjq48GPyiEo04 X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a17:903:2651:b0:19b:8cbb:30fe with SMTP id je17-20020a170903265100b0019b8cbb30femr708263plb.13.1676997457301; Tue, 21 Feb 2023 08:37:37 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:53 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-12-mizhang@google.com> Subject: [PATCH v3 11/13] KVM: selftests: x86: Remove redundant check that XSAVE is supported From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Aaron Lewis In amx_test, userspace requires that XSAVE is supported before running the test, then the guest checks that it is supported after enabling AMX. Remove the redundant check in the guest that XSAVE is supported. Opportunistically, move the check that OSXSAVE is set to immediately after the guest sets it, rather than in a separate helper. Signed-off-by: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 1a1565126255..deacd21cf744 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -109,12 +109,6 @@ static inline void __xsavec(struct xstate *xstate, uint64_t rfbm) : "memory"); } -static inline void check_cpuid_xsave(void) -{ - GUEST_ASSERT(this_cpu_has(X86_FEATURE_XSAVE)); - GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE)); -} - static void check_xtile_info(void) { GUEST_ASSERT(this_cpu_has_p(X86_PROPERTY_XSTATE_MAX_SIZE_XCR0)); @@ -157,6 +151,7 @@ static void init_regs(void) cr4 = get_cr4(); cr4 |= X86_CR4_OSXSAVE; set_cr4(cr4); + GUEST_ASSERT(this_cpu_has(X86_FEATURE_OSXSAVE)); xcr0 = __xgetbv(0); xcr0 |= XFEATURE_MASK_XTILE; @@ -169,7 +164,6 @@ static void __attribute__((__flatten__)) guest_code(struct tile_config *amx_cfg, struct xstate *xstate) { init_regs(); - check_cpuid_xsave(); check_xtile_info(); GUEST_SYNC(1); From patchwork Tue Feb 21 16:36:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148192 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 592AEC61DA3 for ; Tue, 21 Feb 2023 16:38:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234841AbjBUQiX (ORCPT ); Tue, 21 Feb 2023 11:38:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234906AbjBUQiD (ORCPT ); Tue, 21 Feb 2023 11:38:03 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 533E92CFD2 for ; Tue, 21 Feb 2023 08:37:40 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id cl18-20020a17090af69200b0023470d96ae6so1952553pjb.1 for ; Tue, 21 Feb 2023 08:37:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=V/DDoXnf2opyFk/JIknDREbRoogTSxKXRqdxFHEiFI8=; b=azZPMaZPqkrP+aRIze5KyWBJigIWuhR7vtvT2AIX7QbIONV/SEZfaTC3RTMNBJ/gmU WYfczP8dXkhdM244WOARnjbjac48VMe8eRTwD7rTm6azex04IDUSY5aK7pYJUH5Q9fSQ cAuHVy840VC+14rudyO4RSecU0L00tAeBdKtH7NcPLH8GxDkvp1xvPKlLwmrkMt57oNf sBPRwczKUdtLW4cbVPp72zxUCHV+SKGOro4n/9T6lq8U5i6fhwmfhXtLw29/sNy2c/G6 ful7j4FyU0Ce4ymO3+jQVgWQIIwUy0pocwJ+mztGJ2ZXd0XKM3AY0LmeezohXhHHMwUK vnaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V/DDoXnf2opyFk/JIknDREbRoogTSxKXRqdxFHEiFI8=; b=2bXw2VvZdwyQWEbJeKXgpA8J3bXf9G+5ciQXbkRK+CEI2DQC4nSNKbsrnFQakWcSf1 GQEbLGHqzLw/15+ahnzWW9elI6T1z+jhpaVQMe4QNrrIwiJ+aiATx7mwIURwYw4CcnDO kZxjUcbRN+BhQEdGz9jTnqMCQDiqFae+whKXNEwza7Imioac5VZ3Sa6AAegbvM0LIbcv OawK2bUjwRcKpfWv0VEvlKhxtO49x0WEbRxh3+MK8Pmmegn3pmRdfKrs7Y7V/18jJk84 Ih0+vHJoBJFkRjtG9TGYNkpvcg48PQ3t5ntecOeb5VeaD7wbb/YaIRwYY9ksjdZQWAGy Cm4Q== X-Gm-Message-State: AO0yUKVckk+cnuiIJI5MKVu881DUpHu0JWUt3Y078dzdR0SgOky/Ca8b QzfpB29DW+VytcVle4S7H+qPy5jB1bFE X-Google-Smtp-Source: AK7set+uCt7SuZB25GG76skCLbvVlwbw3NDGyd+ph4vafj6zCKa42RtEONl+cA12mbmKCbURNFSBFoNJic7t X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:77c1:0:b0:4fc:27da:54a5 with SMTP id s184-20020a6377c1000000b004fc27da54a5mr681202pgc.1.1676997459042; Tue, 21 Feb 2023 08:37:39 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:54 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-13-mizhang@google.com> Subject: [PATCH v3 12/13] KVM: selftests: x86: Check that the palette table exists before using it From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Aaron Lewis Check that the palette table exists before using it. The maximum number of AMX palette tables is enumerated by CPUID.1DH:EAX. Assert that the palette used in amx_test, CPUID.1DH.1H, does not exceed that maximum. Signed-off-by: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/x86_64/amx_test.c | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 5cfd7ef40d78..a6a86c41ed75 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -223,6 +223,7 @@ struct kvm_x86_cpu_property { #define X86_PROPERTY_XSTATE_MAX_SIZE KVM_X86_CPU_PROPERTY(0xd, 0, ECX, 0, 31) #define X86_PROPERTY_XSTATE_TILE_SIZE KVM_X86_CPU_PROPERTY(0xd, 18, EAX, 0, 31) #define X86_PROPERTY_XSTATE_TILE_OFFSET KVM_X86_CPU_PROPERTY(0xd, 18, EBX, 0, 31) +#define X86_PROPERTY_AMX_MAX_PALETTE_TABLES KVM_X86_CPU_PROPERTY(0x1d, 0, EAX, 0, 31) #define X86_PROPERTY_AMX_TOTAL_TILE_BYTES KVM_X86_CPU_PROPERTY(0x1d, 1, EAX, 0, 15) #define X86_PROPERTY_AMX_BYTES_PER_TILE KVM_X86_CPU_PROPERTY(0x1d, 1, EAX, 16, 31) #define X86_PROPERTY_AMX_BYTES_PER_ROW KVM_X86_CPU_PROPERTY(0x1d, 1, EBX, 0, 15) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index deacd21cf744..2fd6a8a928d9 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -30,6 +30,7 @@ #define XSAVE_SIZE ((NUM_TILES * TILE_SIZE) + PAGE_SIZE) /* Tile configuration associated: */ +#define PALETTE_TABLE_INDEX 1 #define MAX_TILES 16 #define RESERVED_BYTES 14 @@ -120,6 +121,10 @@ static void check_xtile_info(void) GUEST_ASSERT(xtile.xsave_size == 8192); GUEST_ASSERT(sizeof(struct tile_data) >= xtile.xsave_size); + GUEST_ASSERT(this_cpu_has_p(X86_PROPERTY_AMX_MAX_PALETTE_TABLES)); + GUEST_ASSERT(this_cpu_property(X86_PROPERTY_AMX_MAX_PALETTE_TABLES) >= + PALETTE_TABLE_INDEX); + GUEST_ASSERT(this_cpu_has_p(X86_PROPERTY_AMX_NR_TILE_REGS)); xtile.max_names = this_cpu_property(X86_PROPERTY_AMX_NR_TILE_REGS); GUEST_ASSERT(xtile.max_names == 8); From patchwork Tue Feb 21 16:36:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 13148193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14025C61DA3 for ; Tue, 21 Feb 2023 16:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234962AbjBUQig (ORCPT ); Tue, 21 Feb 2023 11:38:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234802AbjBUQiH (ORCPT ); Tue, 21 Feb 2023 11:38:07 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C0062D16A for ; Tue, 21 Feb 2023 08:37:44 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id w3-20020aa78583000000b005d244af158eso418383pfn.23 for ; Tue, 21 Feb 2023 08:37:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=HMhvhuYsZ3myRfljiC/gjTRwZifcMTe4p3PNN7RnFQc=; b=KmVIllOgr72sC/pqD6niGV7eoTluq+PS7s7CCPGlsX1a2kPtiFgCkfe/csntWgWF9O OmiYudDws7aCektHRVfDdkOlHQnKMwbf59UDCpld140yXaGH+KdKApX6nXhTN/SgZ2nq 5U1n+Lxme8YZL0X0OOafeKn73deIl7BysH+vQNQw5kIWq78UX6dnOhjQ7IP8rDCLcYIT 4hN80G10dXWP4zMV4Bjl90+cJk/RDZIBOYURHPeIwUegjZDRIYoNYTggUb3Qzz6fPH+g MguyLJitJgtzcDpXLOsQoIfVG2/345V/I7EC3KPaLv8bj/LmBYyfcUSN5ReCIyGhkxhY uXDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=HMhvhuYsZ3myRfljiC/gjTRwZifcMTe4p3PNN7RnFQc=; b=XUZeQJ/lPXC4tYJk+XejcwGHomgXx4c/AoUmDQtIxxsFrIcp39qO9twiWdfxKd7PKe X7UI/2/EjelcBZ6K2PCsLVJY4XxfSwOGLMLoXyLJ/biCKZkekra3i+hRF7nFX4Fhf7wV TgvOuvcNOrmd+uO0uX4tXhpE93ZWjFZVmA0mjbNBTPimf+Pundwa3BMi7ndeWSYJfRPv kubxFzG1OlSBt7mWh2gL7rrAw9PJ8OprxN6kuMu0MJu4EXQ0glq8sqf7UOGAHXCaMLDQ bnKXumM/P0SsylY7p4Qmn5B7cwPiE0KqmHVtLoZ0swt8spSXzT4cJMnfOQqvbbzclsRM pl0w== X-Gm-Message-State: AO0yUKXTppHT7HVRNNlMBVZYSLYhQC+5XqMoG/LVrSj9Qi4Y0dNV6bsL z+vYPUjtfjd2n+vUHctTqbWN7t0UKMeU X-Google-Smtp-Source: AK7set84GVPCvLI6mWm++un/vVhlpwfDQIVN2HL5K5Uy9ESpyg35gAsQNDDeljXg4j72rXVwu8BYtk/LyP5h X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:3445:0:b0:4fb:d8d:2362 with SMTP id b66-20020a633445000000b004fb0d8d2362mr748058pga.8.1676997460862; Tue, 21 Feb 2023 08:37:40 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 21 Feb 2023 16:36:55 +0000 In-Reply-To: <20230221163655.920289-1-mizhang@google.com> Mime-Version: 1.0 References: <20230221163655.920289-1-mizhang@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221163655.920289-14-mizhang@google.com> Subject: [PATCH v3 13/13] KVM: selftests: x86: Check that XTILEDATA supports XFD From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" , Chao Gao Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Aaron Lewis Check that XTILEDATA supports XFD. In amx_test, add the requirement that the guest allows the xfeature, XTILEDATA, to be set in XFD. Otherwise, the test may fail. Signed-off-by: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/include/x86_64/processor.h | 1 + tools/testing/selftests/kvm/x86_64/amx_test.c | 1 + 2 files changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index a6a86c41ed75..4f6d2d31ff34 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -140,6 +140,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_XTILEDATA KVM_X86_CPU_FEATURE(0xD, 0, EAX, 18) #define X86_FEATURE_XSAVES KVM_X86_CPU_FEATURE(0xD, 1, EAX, 3) #define X86_FEATURE_XFD KVM_X86_CPU_FEATURE(0xD, 1, EAX, 4) +#define X86_FEATURE_XTILEDATA_XFD KVM_X86_CPU_FEATURE(0xD, 18, ECX, 2) /* * Extended Leafs, a.k.a. AMD defined diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 2fd6a8a928d9..2eb265297898 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -257,6 +257,7 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_AMX_TILE)); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILECFG)); TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILEDATA)); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_XTILEDATA_XFD)); /* Create VM */ vm = vm_create_with_one_vcpu(&vcpu, guest_code);