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: 60162 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106290wrd; Tue, 21 Feb 2023 08:38:00 -0800 (PST) X-Google-Smtp-Source: AK7set/21P8sP472LZecMM+olBKa4enXXvGcnJ8cTbOOhjcSwGVy3ZgQiRcBX+sDWCvwqaDJYL93 X-Received: by 2002:aa7:d957:0:b0:4ad:316:b4d9 with SMTP id l23-20020aa7d957000000b004ad0316b4d9mr5544926eds.15.1676997479942; Tue, 21 Feb 2023 08:37:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997479; cv=none; d=google.com; s=arc-20160816; b=PnQQBtF8kbviSmP6YaAURQFETOw1Sa0Fu2644bGKPuI1xHOXSzBvqDqgbIkmQlH46K 8hYmAqjYSkPV2aKuby2iB97NYU8356BpdNiTolKQwy9Wm3xe99zsKXj3GLsJ+fa0cARJ ltWqJ3PLDQnmTesenbSVL1mKAAn4pIF3N0jw3cZXfHU9xNnK11VmSuNWc1yBTz6j+NXf 8U36DDsveEqKweBwVvdNQD4QY4aLE7pPIvrM3lO1kwCQ4JaECTzCESlP1tq6UQhalRkJ PPnlwcRBaOMNyUBw7XLIL8k2Qb/jLqQEZ5uiUZo1d46A2e+w1qbaO6Veb6vqEt+dDVGH 050g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=2iAI7qeN019fW7cnXiCIU1jbXC6JQmM9w058O8z3YH8=; b=UuYXgRyrS6DFQGE18xMJcN9yHTCg4Qh8ctPZBDFiO+ETWkK2Djt/1hY1wLvVjnjlkd un3nTLcHj9M3SQ7Pbylahe6pKFfVkeVaIlpd8xQFx+kKL2NkhmhImsgeGmGXcJVdtQzj Lq1l5Vg1ua8PwM3M12Oa1aqdffqgU5oxzWs0nTDubydF6jEfHaoD6KpoiPLA8QesojFd hG8xVRWW16NO/qb6xGX7vGJVtkLqBLShTUv8O4IezdQ+WxTEcxhE4sDhtd4igGNz74iw sLJTz8hO0pChBvM7x9KN6fV6AlpkNx+ugujIQkIuU8r6Ysbhs8v54G7WqIkOIpAsRabU T2vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XdkwDudC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x20-20020aa7cd94000000b004ab4db42572si6714033edv.580.2023.02.21.08.37.37; Tue, 21 Feb 2023 08:37:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XdkwDudC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234708AbjBUQhX (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234231AbjBUQhU (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 5B4CA279AA for ; Tue, 21 Feb 2023 08:37:19 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id j19-20020aa783d3000000b005b9ac633454so2912122pfn.0 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=DFwqAA9akhWMv//6SZV9ImLAruHYXMftW5Q0ijWkdVxwonlq/RVKd/9qfVG6oQ2iBN 8m6sObIvPLsGGHQLFQqu416Xcgn9HDh6JsRYc38akS9me0CIgPxmSQVc1lgcBIDmHh4p h6jhws5Qb8L4lYBwg3elGv3Ui+7OeltUHJkNR52BUp9JTAi+FGdrwbefYux83iV+CW1A vs9dA1cgMLIBTw8HexcP9aw+np0S/IewxjjxImnApn+c7hNL7NeLds/QeRbUlrEBnJBU hNPsGyOmPSKa85FF2nUzoq27itthW/SJOhz3hDOdhAhpS/9Zifp+8W+AEMHYyohsoyMH ho0w== X-Gm-Message-State: AO0yUKV+2Xq7dCUaruYGlRDmttVYPvlS0OzuDeJXKAqHNEnNtj0FTr/Y ZLJBW9DBGno82/JWCq2Mmgq41RsKHT9j 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459309269783619?= X-GMAIL-MSGID: =?utf-8?q?1758459309269783619?= 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: 60165 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106576wrd; Tue, 21 Feb 2023 08:38:30 -0800 (PST) X-Google-Smtp-Source: AK7set9BqYdx+aU9YICWoUYFOe7n5IjGRyCrSYQFHhshXsGSORzkkLbokJlpZwMQIEpWgOWgUbAf X-Received: by 2002:a17:906:55d4:b0:8de:e66a:ee68 with SMTP id z20-20020a17090655d400b008dee66aee68mr3052147ejp.35.1676997510830; Tue, 21 Feb 2023 08:38:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997510; cv=none; d=google.com; s=arc-20160816; b=T8NEmWQzWvoAfI6ec3hDrhCsVTDzGD62QVJp2dXCFYlxvVWxLQurtTcR1XWqbfEb8m 0ng5Wikd508Z107c3B7INGrcs2bC9EOADiddcciHhr97zeTdGxSWi5xjRawk6TaL5QK8 gE5KfGGhxEYP/eM/e/bo/DRkU3yOqKCu5SyENrCYQZlLsb/0VS+CiR9AfauyfkO4IOr8 rtKL3FXJUzGBl7bE2+DG2MgVaifgKWgNtif/2E6hD3/i6JaIgL1HBmJvEamxDmv5BvWv 7+B6dZNTpPrkluuY6H4h3874zjZnFxHhNdwqmZnPpB1iondlh7tvOoNvccNcIKGzfRg3 ydYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=CDOmnOlE8Y16AZivwv4VrFjTYze8Lvbli++k4cFr8iw=; b=o+ooizgcAl470g6YfBAYv52EBuI2x5gZ3E8aqRgX7WBmxvyI72XGq+csjy1mlN8etG Nh41fskw+yYCv2/OP8wUNGt/Guqu9wmL2ed/fS5NHeTKeNBzJ+KPOK79+DlBecFZwFgh Tk5oK2D4KAVNyQC22fkxE9DmXPtzAGtq/H7Pd9xoMAPEQpx3JIuO1653QIM45+YJ2csi k7qURKqb3MTmGQ87OjWe9wUh6hpQ2PFnyO/F62QnAKVwdcQswGyvVgx2t75DyxKRBwW3 AGRHw/PGf4C4HXquXas1KyJLZ3ZAszGRrxdwzdhmAs43K/K1+cPy5r33VMAeAc21v2yG dBMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PAhlZ3TH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wj4-20020a170907050400b008c797d4010esi10662222ejb.1005.2023.02.21.08.38.07; Tue, 21 Feb 2023 08:38:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PAhlZ3TH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234785AbjBUQhb (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234508AbjBUQh1 (ORCPT ); Tue, 21 Feb 2023 11:37:27 -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 797432CC67 for ; Tue, 21 Feb 2023 08:37:21 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id cx12-20020a17090afd8c00b002366e47e91bso2384017pjb.7 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=6d8KgGPQFqeMDMKIM+1+hWQGyTnJlJ6HjrkHkypEkpmi1kAsiU3glq6PbDRbiysiPR H4le+wJPh9tJYCPfWuwqGuNFcW/8bhfJRULyTsvRX2NlVMjllNc8vRlH1oeXuQ+TgF0C rNanyx8Zhzi58+nCef/6lLiZDzfQK5+lA8cNz1V1YdgcDkz0Pe0+v+52oUfLbPetJblx SeEf3LCUGOEcytzoT3QWyCWUAgYskq5tYDpQKSe8aVa/3gzoxkCPoHL0L86wG0ai//F7 OJaJKwMtHEvZ5qGlC5t5ybEOWQ0sKX3/GOkGeAS7RjqDcc1mdtNCjMy7nR3/mtepyPrt tDDw== X-Gm-Message-State: AO0yUKUiAHz7v1KnpGA7zM0mB4dqj0+KMvyMpGBV5IOVRZPTtdb5ZEfc QHBAoLJ7h7c3DiwmtoSEgq8r5gGBy+C7 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459341875642362?= X-GMAIL-MSGID: =?utf-8?q?1758459341875642362?= 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: 60163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106490wrd; Tue, 21 Feb 2023 08:38:21 -0800 (PST) X-Google-Smtp-Source: AK7set8WIfccltyACFqJH4OlrkGa0pkaXRvuC1msS7+MYMtkFo+aLQBqN4qOwil3tTkGZtBtsxx7 X-Received: by 2002:a05:6402:286:b0:4ad:6ca7:612c with SMTP id l6-20020a056402028600b004ad6ca7612cmr5794919edv.27.1676997500976; Tue, 21 Feb 2023 08:38:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997500; cv=none; d=google.com; s=arc-20160816; b=si+XEd9Nen96al3bkdNEnY9ySnlKuNXA3OvMdUgwMHFb8agNyl4h6/6vha9lYsFwb0 V6NrC3mxvGjgn8nbUxUj+iNpjoa/rYGltQkLbjN/WnyGs9pPtf9wBF2JrHVVGhi3aNNx hMm1MB6LtBsmG3ZCZiBZYQpr3l6s+qayCyyOrLn8DKFhqvmq/rzV7d/HE/rSO9qGQe23 SJiCmaBQfuO42e3ajHiobFWBTnuVWSoQr+5kuMrpRse8wztA+MVF8W/rp35+T6N/t7AM Bx+8rWSE92OfTe/IBD1nFDeXHh8TW1uQQ1KM7U5cH3Vly6PsQpTpvL/0CR9I2jbKx0/K e4Kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=AyHb4Yx7urg+Zx7LCzA3DPIwt3rV/2dFui2+3APs9Tw=; b=NIUwmvFG8U4tsm/EMNveAmR/acVrjnbEAAKFi+CiwqP2OSsIlOnChsTdaMxx+dOxG/ X+ZiYiOj5uQ8JRIrxib5ifdyC/LsJetqU+HJ225wnasxWO7+vMgf/OzuTiCcVauNz1F6 aAsO6G6NfQQxIg+m9/KTZ9cqGEdVxbso7iyijFqCuFs1dhy9NSOi4o+VqzgaLbdiB04o UjHB9tdttV4EwjmL4VcaVBtGQPmi+VPhJjFR9TIJz/VhOCYaD4oSn+wZCm5cZEx0lSbq AueZW7TPgiIFky3bPLc8O7UWl+4yD+84L6D3CDP0Pg8qB30B84zl7zhZFReAa5HeIx9w ixAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rJnHYpiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e2-20020a50fb82000000b004acc68a5878si107726edq.274.2023.02.21.08.37.58; Tue, 21 Feb 2023 08:38:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rJnHYpiq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234804AbjBUQhd (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234742AbjBUQh3 (ORCPT ); Tue, 21 Feb 2023 11:37:29 -0500 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EC26279AA for ; Tue, 21 Feb 2023 08:37:23 -0800 (PST) Received: by mail-pj1-x104a.google.com with SMTP id d5-20020a17090a6a4500b00233fbf2cc15so2585268pjm.3 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=hpixdgmMC0Kd6kLDPfg/rBK+2eLQr46rB5ewugd9b8VwlMDkOidLq9jpm7iyZ27oq7 acsR2dU6bWzOkqxKK8VOOv1rw6o47+gSVc7i6i/e2UmYAUsRWMmEJzRWEE8z40KN+9IL sBMr0KmioJkonFLnOKC9LNyl2O2xYCf/Pd0KYg2wB1Z3IyBQIjT2mEge1/APYfTKnqF9 Wgydebp9J6Wvm/cIDUASy1B5QAJSYY4U4MdT9lnuTdou1ytlGy95dJm5XYT40C+gRfJf DEYeptpnv+gvomuVSXPSWvZEBpkU3cvWgjs8wyx/Qv56dxSIdP8slHNbtPqqwChtmGRT r2Tg== X-Gm-Message-State: AO0yUKWn5nFtw10w//lehmramwZi3ovu2VSdWl5zJLU1KpRawmEbDAP7 kEry15SR4R0E+GWjYXiprWAXvO1kaDaF 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459331827920466?= X-GMAIL-MSGID: =?utf-8?q?1758459331827920466?= 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: 60164 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106547wrd; Tue, 21 Feb 2023 08:38:27 -0800 (PST) X-Google-Smtp-Source: AK7set8uS9d0lRO02gvpTfu0s+UirD8qZyUTtWDFEy9Md1NkPZFk9g5ngdkAN1sMd96K/bjCpRhG X-Received: by 2002:a05:6402:60d:b0:4ad:7c30:259a with SMTP id n13-20020a056402060d00b004ad7c30259amr5757448edv.2.1676997507126; Tue, 21 Feb 2023 08:38:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997507; cv=none; d=google.com; s=arc-20160816; b=FcOcWZNhX0hxtNNO5KKUjJZz2iY500kpo0VvMET0iIn4hSiL8jA2UIlGPz7GVKAi78 Uq0k3ORWLfyMcn9rmMAx7UuHX7v5bqErSuh2EvJGKPltXsAfsXW60p6v9RTBN1wtHnzS GgqeQFptsuRdT6EgoeIC5hjofF/ZEHsQG2SYVJMsacHKnyG+ekfPWuDG4N+whaKjer1Q GEjvZzjcrxsNHv2+FpTdUk+zcf6jojZBEHhdKeEJVCSafLQm40aTR5fkkc//nxJSTdXR oleqy/1GSO4NMZ7J43QcmbE1bETdBAsQAyyCLDUUoK2GUTo4610kp6A5krsjP9OpGdj5 OQGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=b5cXkH41Dpz3xl6Z7o6kxBjd79dMhYH0BWx6BfiSfBo=; b=wn7cnupYz8fpSpSQBbhjFmJCKeu17m/BJc5Wycrtp7lQxiw7xfz6c5bIuRKMvg30XQ tMQmB/OzQL8ESTC/jmx1RFGGGtY48GV5UIX6huuzs5k3T+8AJU/TGicoGXabIMC0RVzh mymqSoyBwscVeDbIqX4QhQyxEcRWtbQAAwqu1vzjwlgUi9xjrXB9nkdBstQFu5wNTXf1 TGu9U5RdOQIvvOfQHNe/pILX9owlhvDRCEmPWZaTYQpMDvXBN/iHJiCKxD0Bp384cKQp 008nFtdCrsnm1OFK574ccRqzQA7N5+8tr+okJHB4MseQwzjj5ZtCD8lXRZ6K6bIFstek GrxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CZqHake4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j24-20020aa7c418000000b004acc6cdc950si650143edq.123.2023.02.21.08.38.04; Tue, 21 Feb 2023 08:38:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=CZqHake4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234815AbjBUQhf (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234678AbjBUQha (ORCPT ); Tue, 21 Feb 2023 11:37:30 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E8A42B29F for ; Tue, 21 Feb 2023 08:37:25 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id d62-20020a251d41000000b009802c10698cso4894571ybd.22 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=3JnkRojRVqTpuGpb9vITfr5Nw8JTR/fNoNtSga4RiHmPhDFR0zKJFJimjizn3GZ3o4 AZ/CbNm1ccHkFggbj2/sy6MTtsGstUZ7hAgUWlDO1syt50M87CKxvJ5RZMIcIRlnElgt yNgN8Lo7xO6VgPKFTYP/Alwsf01XBVVQLwCFf+3NpbR1wziqTd/qaL1vbeHyxscMSHaO GAv+rr55tB31uKbxqRAogCVBR755GujsafkjiIVn7jMVZedbwnun5+5FERtHRxAtiiBU 25N/XVoqETxdTr/i3n98vmWdVC5Un6rMjEH9Op8ZBpH6835tJpiVDCBi+dC9xs4OZAfy xD5A== X-Gm-Message-State: AO0yUKUHf5ucf3QkIP5Yd+BDqEzh1bkdFRXIr6GfTR61nWJDbujkJu6J sIp7XrSvvy+mOAUf2P2yeJ7c/Gx6gHWo 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459338238504649?= X-GMAIL-MSGID: =?utf-8?q?1758459338238504649?= 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: 60166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106593wrd; Tue, 21 Feb 2023 08:38:32 -0800 (PST) X-Google-Smtp-Source: AK7set9rEojmx1cxAvQ/+1xpi8RiqrecnYXQadpuHNKyDDChCWZmgBoHVzzbYBA9iQQZ3pOcpd6J X-Received: by 2002:a17:907:33cc:b0:895:58be:94a with SMTP id zk12-20020a17090733cc00b0089558be094amr13359357ejb.14.1676997512147; Tue, 21 Feb 2023 08:38:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997512; cv=none; d=google.com; s=arc-20160816; b=IYLlYKZnpTNHMkbQ6C/9F81I2jBrHJfuAz5EEqFuHXbp1bL2XvIJ0ZOw9hJnrr5caI zcbtBY5W8W2DmEXHPh5/vI8Srxdiqpu43VYwXDgtUUq+D1KUp2AJOwHhDbZRYmnqTZcy zIkPbwtqmfkxGuyzBRDrdhaNbd3US11zZtfTuWdqZLaonL3AG27wED9BXsLrk/a030pn s3pSwZ2z9q9g3ZxaxFeEa0LUgRTXG1uRZIJcxh1FoP7tMrGNZRJXk1og8mrQ5O7B6+KI BKOTkTJu3031POUNIGhtIN4xLyJs0psTDep00lZVqJP/RdI3SHk77BeeVTaaRHJPQMmg wbhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=LHzOHHZRF0Z0PxEe7g90IRKekQBPW5kSPBGZ896mCAw=; b=i23jlB5wstiXrHp8nwppF2NivgK+ypL2LWZPSMXQSTmcAivCBS1mO02mQ4uK3r6MY3 BBkYfVgvlhyyOrvyo1Iz+oltN8SvAxq5a2CzUDXqliM7OvUH9qkDx5XsbFPy1vqt8/92 tDwNpuNHrYkqgedv1aVe9sjIUlGinkzUHVfgjmd4GHx0k7sFZYB7tQnDosL7LxOZTzk5 /mqwhSzUQ+s/WUcAFfUUtF8LXqivm2RvLZXKJZLlpCWaFrlg9pBBvZlpO/rhEo+Oq+r1 olkNyIXPFE1Jxhvb3j3vP2Dg07dYvWy94yORcFcKoH/YQJfrmq9I3j0CNG7oh6WE7zXB qv+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="iYq/M/sw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mz13-20020a1709071b8d00b008be3fe9b454si10865312ejc.111.2023.02.21.08.38.08; Tue, 21 Feb 2023 08:38:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="iYq/M/sw"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234707AbjBUQhi (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234771AbjBUQha (ORCPT ); Tue, 21 Feb 2023 11:37:30 -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 5F59A2CFE0 for ; Tue, 21 Feb 2023 08:37:26 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id g15-20020a63200f000000b004fb0bd64941so1970204pgg.16 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=sZfOtHjbx+ll+IU7aCtuTisl63GWNmQb+n+3EbpzGW6/7B67qpSXdXkFZhXZzm1C4b JYExMbtRHR4dru/iqqebKGnrR1Dxo+lI4VlfRFCebXUScCbzr+RgiV5gJrFiTkWeOWTY SLnmv6/CGmnf/E7ZfwU7eQNvfmCAArMlG5Om6bary6E4hrRILIJ12NNJeAvhNnYILDOQ b56Ey0B2f8uh0V3rfVi5a8EyKHhL1H8OJG+vxRq0BdgSf2UtPVPTWWJZx6oo+gaj2xcs 22Qz1lfmMDI8tMffrsx3x/t2Sx9X0dUGYCNTyY0zALq7WUBLgEi7OLuDlEKjFy70ZLUF /F6Q== X-Gm-Message-State: AO0yUKWIiqX1JCvMKeTUUhTVklwQ07d0MGKHZ+0HCNeTNBj/9mfxqu9g O+ajTlxIVBntHenadN6ZYHGsFiyZWJh3 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459343258731856?= X-GMAIL-MSGID: =?utf-8?q?1758459343258731856?= 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: 60171 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp107077wrd; Tue, 21 Feb 2023 08:39:37 -0800 (PST) X-Google-Smtp-Source: AK7set8NEnIbebMJPn3u739lu3B1ORh8bWgcfEbnIWUBefFehPpxvcpiQMeXXXF6yptr4bNX//CE X-Received: by 2002:a17:906:6b02:b0:8aa:c038:c768 with SMTP id q2-20020a1709066b0200b008aac038c768mr12572813ejr.66.1676997577221; Tue, 21 Feb 2023 08:39:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997577; cv=none; d=google.com; s=arc-20160816; b=x1QTSSMtVcMtrzoQRLpiXxGIENq3NYWTdyV2TgR3GW/OX8Sx+4NVWta/X9drDhFNHH TPYr06PbLumyY28yQtCHdiDO2IMlomi2qXvaqDKW/FZLPkSTj5gw/Ub34U1ny1vccHf6 5VUYvZgXYB/TMiRmk4MfPG8+R5yHJ6FBYYCD46XUkHdxnQ8TEg1WY+TrsNL9bUl4m11k Ec4u5A30WgeykJU9AuerWGJJNe56y8/OyVhjirghtZdw5bPIrBtWTLWknzh3E2TKwXaR 2BQMn4m7Dm7akFSLh0c35pLkJOQGY/eMkV/M7aNN/XcC0eVX1ZhTSo8xBNeb4W2fOdF5 OnQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=CiebZgZnEDP7VZY8GkyG9xLC+cq7WThHzeBIf6OXg2A=; b=qTQZdWVD9/LwYikj43ijN0DD93AKLMDns/zdHOQR25hPAInOGYHFTK9VjiLyzw2gNc 0aeN6KCcDk4A8mksF45YR8xUz3Bw5RM+U/fZS2yALKM2iVedkqPtkVo8X4DLqhAlaMLu abD3sgIZPTGMYI0kW7NuX/4alWDq137kHzO6MaVx1UQhsm7/CGFyHYcVal1Q9sw2XII/ /kYDu0RFhDH+6AinmCEYxoeCwm4bFUgJY82ktQce7cT1cc5HO9qFWY/O35ZK1VJKe2+p 5uFzIsg4eIq+Ka99LXxvjCXdKl4FKOYijY566LvyKO9mCOypQlmFTzK0duLdDbVWwqSm HfWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jI478qIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h15-20020a17090791cf00b008b9b135aee9si12227167ejz.350.2023.02.21.08.39.14; Tue, 21 Feb 2023 08:39:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=jI478qIY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234848AbjBUQhm (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234787AbjBUQhb (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 04BFF2D155 for ; Tue, 21 Feb 2023 08:37:27 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id 62-20020a630241000000b004fb3343142dso1858593pgc.5 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=O4uVoUjWYYrCVkzvih7C9sWxP2G/qrOMLYjwbkaP0zU5DsaMPbPlBj8tSzoLop5XEH mpQQszLYOnAW7bPOuvhebaKOBUkQyID65cbyK6z15NVEim9encxVi/hzoWDDNnI8sqVl SiLPp2juqhfMvTl5Eeu7C1PM0Nb5YyqSi9jz7hv/OCDTVIP9NL+IglYzJpQwE82zzQtJ NJOrWED0x158EuzazMto+1R4boULZFL9fDz8E9SoTfz/UHlsqz8umKHS+fQ1y2cG3u8q 0Xl5WHbKPOwK7Japh1TWrNWzb4xRbJ4S2VhY9ll4HjUJWssL2gWZBuLbr0bNEMftG+MA vvUA== X-Gm-Message-State: AO0yUKVItbUBmK1aeAQFrii8q5xL8G5neyAVd2+KNlBt234nPNgpq1FQ fyFweU2dZdZI2ppcwZwBtWuKZ0gOAzzw 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459411186694738?= X-GMAIL-MSGID: =?utf-8?q?1758459411186694738?= 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: 60167 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106692wrd; Tue, 21 Feb 2023 08:38:46 -0800 (PST) X-Google-Smtp-Source: AK7set/aPvzBoSKD/E0ZWDBq06hTM56DyLbMk5BPczFuKUKb2j5zgyKUIaJP01RBmmV/4hwtm5Zj X-Received: by 2002:a17:906:1093:b0:8b1:75a0:e5c6 with SMTP id u19-20020a170906109300b008b175a0e5c6mr16178186eju.18.1676997526515; Tue, 21 Feb 2023 08:38:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997526; cv=none; d=google.com; s=arc-20160816; b=K181Ed8BsXHYq26zHBl5pEEPTpFuVAS3Fql6gn2tuhyecpEnjeInZky1YGAPeYCZ/c qUfauDlXs1Wv18tZ9tb+iNKTUwdLk6WfXUuGSIi9mUqI7P2h/iJyMplSbF9d1BAc3q+V 7F0vnHu85yoNWdRtVR1L3Bk+pwVxVTRpFKSiHv3S5d29YqxzRH0FfADGRacos+oTg50C UH/ctm3ddVbQCXu5SxqbgLj/ok1e1x9eW4g4kJI1VlpoHyDecgIUpTC709f9e1CvOgng nFcyfVxpPbWMPdcjLtzIZINXm/iaGFvPU++jfq/qup9orE0XQK1B0fnTHmucBR6YB94o nY0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=w2vMSj1pqCX3K6DVzozBWZ+Uf2g2Y7SPE2PRI36z9us=; b=yKjCJg9Xv5htMDt6CH5GD+hMG7u7mkpmXdkIhOB55ZmHjyANkbVnUwjb3VbKBb24ZV CisQJBMu6Z+ky1fSeYIrI4WutGVO4kK8Zs+PQMJpQHSIFBn89lzyC5EEKvPOfXBaJ+1c 8RmqSRD5BF6lIk9p+bNSMOriNM6qNzY0CGZFYmg6Mnl/CNA4wsmu3V/8B4nliJ0fBL7k YC6ElLAoTJzEbXTidX0yOEqkIbwrUIO+R1wVDl79Aakm3n0YtDI0cHhaQPaCTUSIOGYa u7l49AKFpZmDnHTHTPo2VHalcgvjIxlua6AJatrJ7Xu72dfDtAOWxaGAJDn48nch1um+ MIvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DajTbx4B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ui7-20020a170907c90700b008d8476ffb06si5328108ejc.318.2023.02.21.08.38.23; Tue, 21 Feb 2023 08:38:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=DajTbx4B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234819AbjBUQh5 (ORCPT + 99 others); Tue, 21 Feb 2023 11:37:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234779AbjBUQhf (ORCPT ); Tue, 21 Feb 2023 11:37:35 -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 48EE32CFD7 for ; Tue, 21 Feb 2023 08:37:30 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id a23-20020a63d417000000b004f2f2dafb21so1406658pgh.0 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=wdvHsquNdVWSortZ2QlVBHa4a3cT0JFK1Iui5Qd6PuOvHJruIdY0PRt3stOOIEpzhX x4lJWJKnkbQwNPsihRZMedY0D4ZcscgdYIkwpGxAY4KvmQdPk3i7UyFrJdlnio1Br0NL yyeG29e97NUFHtZqkLkZEZMoEyNj1v2VjfMcznPyD9gNJr7DpmqU3rZ3yxqXDCc6Lc42 1MnlIahpHylDEB8zAJYlVboAP7cXvQLj92hr49QDyiNjwzgvT3ZptfMwgVdKXesgWygG 1Nd6mrv1/NuaSgpPbce2Dp0pX8pjum6Xl/6Xnk4TaVWED1FXK1xnWqkpG2GJyX8VpQMF pepQ== X-Gm-Message-State: AO0yUKVbDxn9gROMgZMYMRNzA98esiA4OfCJzxy0xQ3+/5Fy+ePq+wZS +xSeSZyW3kz64Q5pEg/G5YUpTt1B1D5i 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459357870228856?= X-GMAIL-MSGID: =?utf-8?q?1758459357870228856?= 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: 60168 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106732wrd; Tue, 21 Feb 2023 08:38:51 -0800 (PST) X-Google-Smtp-Source: AK7set9dxvmlBSNu8QROQf2aF0RxU+A4ewlSQ4Uut9yv9EacwxrX0uNxJFJxRXk5uCOPZhWW0MYT X-Received: by 2002:a17:906:dc90:b0:8b1:304b:8e2c with SMTP id cs16-20020a170906dc9000b008b1304b8e2cmr16688627ejc.0.1676997531252; Tue, 21 Feb 2023 08:38:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997531; cv=none; d=google.com; s=arc-20160816; b=bGYN8zke8jv/fOuOcNxR3IuoBi9GjSJyrR7Gr0DDq+VX4IFf4plPh8Lwe+Vm68toU/ zTuZAEjqXqO9rmsU7DYvNIl2fUepl7hcTXu3RO7/kbahrr/HD+rvu2ddyBa90fqXTEGw DXwYKzLYagvXsGHsknu+qMdB+YEzMzWxoP1Tw/li+vxTG/LIDlmwE0JgFrKu+k1cLOzo +8uCM8Iz23VXKsHkVN+vECR9vtVxtLi2ymoQJAQM+5LIANIRyyc3g2uPSHH3sJfYD0FM cF7ir5ifyGBGiY9CgK2d9Kr34uUVgKSz9SC7MaPYHWaC4geF60SPBm524z7Pk7GOLq6s 3XpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=6eya8RvAso0oVSkPG+SqCdov6cQuqd8KcPbcmXzNxTo=; b=Yn2+jtRNzqWYDOeLhhL18AC7yRKHzSPcGtFWXhYibxMo71ZnZJ28/mbbrlS12UJHDE uwHeCntF+fa+6+85HhPEuTS5i9MpRk+R7u9XpEzMhsqkVTUNs6O+LAiyAl1UnoTilYps 2ySoAbPQlQtEUcraQ66NmnGcUl30zV72fqQ4XWTLXL/nfZTn6lzO3oNTZo9t7v4bgYs+ 6HjCwaC6HeshMm9ja6WhxCeypmY73l5vxPoELoHGoMr2CVZfRM2uN9VP+wfw8vXtMi3I jp3baeIy3X6dvVl8CyWIdQ5homPddMMvEghWDZHv0Fxuoc/Tq/D7tk4prAONrCbJhnOi zdnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TVd18GDS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v26-20020a17090610da00b008b19489a9eesi18163227ejv.602.2023.02.21.08.38.27; Tue, 21 Feb 2023 08:38:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=TVd18GDS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234909AbjBUQiE (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234853AbjBUQhn (ORCPT ); Tue, 21 Feb 2023 11:37:43 -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 E9DC22A6E0 for ; Tue, 21 Feb 2023 08:37:31 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id a23-20020a62bd17000000b0058db55a8d7aso2191386pff.21 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=GBPQgzphgi14AnEwlWZp1BgaUpGYY2/+LqQv2j5mbHBtiEF0fp+wGCEi3qKGp+EVF2 giYo+DFSTyBk/yeq6WEL3as6j3WIJzMyfY3wR/v7y67iS+DpcLIiCIlMTOt7YqN1/OiN hXzZkG+7c4j8LzJnQcHl0m0rV7iVfJMyQKxo+uPQaeLEaA+lvW5tveZwSgSzDmjctbG4 od8zkHciqaM6qhzGn/29/8uquirew9vSGcBe1OQfudfgCVl5YIakCNax7Fhod0steTF3 wuQXh28EczZqzvNNF6TxnJU4B0w7l2/01cDM4ictMqGd1yABu2eqZVDuRkA3gsQ+qUrF XPvQ== X-Gm-Message-State: AO0yUKVp63UJaLjoVMqWhEyW/gfXyi8DO3RTq2fsYN+uVrB4/1X1qehX 5ReHEn0Q3xLyYNdts+IPvgik/TJtrjrd 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459363589746965?= X-GMAIL-MSGID: =?utf-8?q?1758459363589746965?= 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: 60169 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106794wrd; Tue, 21 Feb 2023 08:39:00 -0800 (PST) X-Google-Smtp-Source: AK7set+nOMDt+rjyjuNLLrH3nZC3Fwpkjz3/I14McdNPoOL0eJyehl5gnMYriSBy46+R7f+w2WLS X-Received: by 2002:a17:907:7ea9:b0:8e4:dc2b:4550 with SMTP id qb41-20020a1709077ea900b008e4dc2b4550mr526093ejc.64.1676997540138; Tue, 21 Feb 2023 08:39:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997540; cv=none; d=google.com; s=arc-20160816; b=SrhRgeA8/Hkn6MTVVw3xbVMyIQ3m9J5I9Gqh7HXjEoYcdJP7ThstUdPoxiFipnHnAU sNgg0Yd6sIvSLmgqJ2VcWmJtyao8y8NjVO/ybcYKVCiUyYpiYqf8LWaGq1J20D0Elfqy SJOIASSo/LJOUZiCiVXBRfZp5PPS6wI5rF8sXYdrP6f+zI7sIHoNxXrkgXfEnYNhbuuJ Jb+VVbcSYzVtZsa5obq0TFM66HcC7CwjhkwQYbo+yZByJ7Qcke4OF+OZEfxFrSJ4IKTq bzSIciYmKojTZPRY8AeWWImiQ+4Gk9xUJRX70PWpzzPGCssugVFX65B+Xlq7oHeuj+Is IrLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=iiRrB1La2XaBQ8X9jljAYPafLfxRlgHLwbfoJQq6vJc=; b=FkXy2RKidDLTCazPmx2b8k9v5ixh4JNZClomyluGGdk893h+OrU3WKBnLO0zXYUNDp aWJx/rUlgD9172mfEI+s+rLnePJ1oHsQQPTfaJKuPXHB936MG5FyfzCmf97IgyXZiA2i bskqauEtT90IJ8GnHA3USFh8v49GZVZfNin2CU5AX6g2reYYBiJicepHwWM1diGJ6/1V TNc1YSSDGNYydBKKx0Z3NAqX1V5V2YYgVjsh9jdwOqcyrCZxhu/w/2fT6DA6rJKObWFf 8NA0wRJS4GLHqwGuhYZssB5Yyv3Zo0XUgpFnTue9372Prd5MXxL3nmd7oW9lyykpDEVZ kx+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fAH3hCUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf8-20020a0564021a4800b004ad12d1ffc4si8080268edb.236.2023.02.21.08.38.37; Tue, 21 Feb 2023 08:39:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=fAH3hCUl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234916AbjBUQiI (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234862AbjBUQht (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 D7DF12D14E for ; Tue, 21 Feb 2023 08:37:33 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id q15-20020a63d60f000000b00502e1c551aaso265915pgg.21 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=DSXuOjbfRV4OxrVl5bY5NRiWWXx7/ZIRJEi0Ck7ThUP8EAuLs8Ytyxbj1NiJF83Hj2 qiBYJZO3ws/a/CpS1dU71SorTWi4j7IEDP530diLCCY5VNV89uFIkFwCHX1BG53P9ibg 77gwWtWMDEW7UgrynPJZiMflqVNn+FMAHRePvE0rLCU0q1jfPx62UI30WIvJNk9rMu4N 8xubFRAce5oFsZjte0KH/GGdzEpaH2BGNqIAIPAEXDjtZUwIxQWOMO2VxKLC9sDQaQYZ 4O1ADnIXoyKYpomQGsJQ58wljpnkH/Z++6Qrx4mRAaJKgJ1SyyvD5gTbQvS1oFj9lbVT onYA== X-Gm-Message-State: AO0yUKXLSMpA/9cjxsjY7tSHhwmsq5f2tPA3Q4glp4Oiajk2imEqQlk8 qre3lJ0tPZVFrwZAxUcg4UBZ8EgilVfy 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459372615402281?= X-GMAIL-MSGID: =?utf-8?q?1758459372615402281?= 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: 60170 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp106878wrd; Tue, 21 Feb 2023 08:39:10 -0800 (PST) X-Google-Smtp-Source: AK7set9yr7R/44Nv0bbR509/olxFBvARY51j6v7/MJhnIqZh0aednIv/wghS5a4zuqyRN2nN9J9i X-Received: by 2002:aa7:db82:0:b0:4ad:5217:a191 with SMTP id u2-20020aa7db82000000b004ad5217a191mr4555108edt.42.1676997550632; Tue, 21 Feb 2023 08:39:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997550; cv=none; d=google.com; s=arc-20160816; b=R+qoTLKg6AO4BkCy0Hnzbv910EgJf5g8bm7Y+UhJQaBdLwGbng2m/Fp4hATHU6+KUs l1H1UoINx++Iww9uBN0U/BYBqhHHZzbTFzQMmLAAYdHTyAOQ1SZqxsWCzqExPHdQ/6l6 ovC6luJXl3DhJWYwkOD8yVptLHrct82oxsfgkZxOPYg19oDnEVhumPdFSYW76G11ghlF uIbzmjsj5dCqiB4jyYDeZsafGG2TMW3I5NHtsoV7ebsUa9g489JRKmX2mYGhfz72yQhY b168HLw1133SR3NhfksveER0nUwiydIODGcBzWa2NjVq2WRktCQERKMmzS6kkoJW+qlQ kjsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=zK45IqxP1dNnwcbmnxiq3xISvws3WCC9xNptFeG9RGY=; b=pSy/O4jybYE+TYngzbnXnhZ733LXBpKdz78dsKeuiDku4M+dnkyv+VHlyOB5jnimkp /NbhAYDeoslMUkBjNVen7wUu2yyOneXMqpMwmWU+BekRPNCA/hANkHxmsiFCOACEcOI1 SDdzOA5S8nuY6l1EIEC8A0GBe+6pqPyBYStuIS2m9WxJPDYxbuFm5kwDfpMahwQTlzoR Ioc2uPYRAAxXlVDaFlSjSUSScxe70v/Ap98N7va0+wwZUZO0SbOcnKC7SB9NYuHHg57S O0p6P0A2QpIZjSoV+7w+EPJs5d7tjUig/7TMOciPPzDd/llC2ZBIMhYKj/Xs0RCtRDiP XXxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gat5zcpI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j12-20020a50ed0c000000b004a05aed2d1fsi651344eds.197.2023.02.21.08.38.47; Tue, 21 Feb 2023 08:39:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Gat5zcpI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234839AbjBUQiU (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234832AbjBUQh7 (ORCPT ); Tue, 21 Feb 2023 11:37:59 -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 BFDB12DE4E for ; Tue, 21 Feb 2023 08:37:36 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id s6-20020a17090aba0600b00230ffd3f340so1622792pjr.9 for ; Tue, 21 Feb 2023 08:37:36 -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=Z2RyS+7o/DOaz3s2ftVEBxtTvWaccEKW6UMA0hQUwHxrdlxDobJVg7Qtn2241RGIou oAG5RB0As/xEm8bbN5MGCAjhqDvjZXCVwLL9+I70H8oXfEkxjW2XMq7n6fOy3VfNf7qm OFmH3lX9TC1L5NHqmiGsHLtqu9xVvsmzxkG8ZAuE2IwKhSmjM8YlAg8IWD9DCWbLSJKb l8y7wo06L+Ph5e5XguTtkGshJSfNTwcOppCJJ/bmTkOVYWSneXRuQGehB0XDwl+DhviX gL4ujILvAh6RO+CX6HNoY1dY0ftmMCpJ27Px22VxxiWFd4GT2OK7XcWRmsQOOblV1/6E PfFw== X-Gm-Message-State: AO0yUKVsvUq9nM+w8Bd3DdT+PMG/RYWbpLX5ejuwBzgjtocfjBKTP7i2 /V6OVMRJBp4S5TVxYDbnLSUflBKmX+5J 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459383923883844?= X-GMAIL-MSGID: =?utf-8?q?1758459383923883844?= 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: 60172 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp107860wrd; Tue, 21 Feb 2023 08:41:19 -0800 (PST) X-Google-Smtp-Source: AK7set87iUhUn9lHxlSTV6mioyFIBK1dFoOHq4pNZa9mYTm9NNZkRSbC9F2b7KKIbk8+t+vDOX21 X-Received: by 2002:a17:907:6da0:b0:8dd:5710:a017 with SMTP id sb32-20020a1709076da000b008dd5710a017mr5419596ejc.4.1676997679311; Tue, 21 Feb 2023 08:41:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676997679; cv=none; d=google.com; s=arc-20160816; b=fQj4KkxgJ+6Y6lNt2OEdYPz7hbXZKO3YgVRLpUq5ZC6tzhWtv8rwed17GM8qau+Sej VbseD8pz+GxN5YAo9omAHagyM4A+YYwXBLZBPj2ReMlPXI9kA0u54V08mCtDFg4DGIL8 iOLb3wAoGUaJ/+XOjmFGik1by8Z2MwLWmzYRGtfs4h1O1I9MbLDf6yCUpehOGGPERH+K bohm3EbrD8KYP+5YPRdo1pUkTDCzUtO1PV2kU7J3uSagQtJikMb7rPH67rBDpiUg+Ycq Sd7Uz9Ret49+XhqAWBbMg0LebQCzPYKuYNpnhAIV4QiP0999aIsuNCtdZOCHt2ofDrOG IGAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=iGUJ74hklZ9IC2JyxMgKiaxBDpYa7dvkgnZvEvOVY64=; b=e1clxBux+YQ+ZKbmN+WgbvfzSztHSQffzg/tffUuAj8b75QBoTV+3Z6ug8aRpCPYN9 QKjGEhpGY6Q6uGF9RyE679GREXTmnILm56KkI3X/qW/cKmIfAy48SQEJoyTe9SEXYXlW M5x0eyI1wSih0UoxcoYqZ1o+hJggjD/GbkY9Xi01gQAX9QLR01EkUgLU1WTGjGFKyK1P jbeqU/QmNm3H417xFFgC+oTH0zVok0O+EpuLL4AsP0Kqn623Sp2ji2WkRh/Yn4U95TgU FPj1O4cWCZB2IoMmYKSkXstWUPaHyeDNROFxno6GvuoqL+SCR+i9GrPXxKt1n4AmT4IZ uFKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rLLClLSL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020a17090673d500b008b176cc834bsi20261290ejl.939.2023.02.21.08.40.53; Tue, 21 Feb 2023 08:41:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rLLClLSL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234942AbjBUQiW (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234841AbjBUQiC (ORCPT ); Tue, 21 Feb 2023 11:38:02 -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 0398E2DE60 for ; Tue, 21 Feb 2023 08:37:37 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id k24-20020aa790d8000000b005a8ad1228d4so2339032pfk.10 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=qWHle1nN+mUGxKfTExL+Ib3pxhV449hDFruo3oRRjOYV5pFNw+Nh4/yoO8TriFIkD1 pru0u8hqSdOtLwoFc2niNQCVGMlGzKxr+neEyp6ctNsdYJGRf6mDFa5Fyacki3YJYoDN 6i1FXS05FqQ5Pjq7cziKzxZdcJXM8D8xxnub9WcC9snasCDO11/H8ouEiEYESb6OAB+B 1BzDq6QkeRqz4zIPo0lHotLlx53xI3wkxBn/gHrfTcrqYeQnM+p4sBdm23cVpjCIyMDR Y1klX1Kze5bebv3kmW3WvQ4y/xG1+wWS2ZPyiB5/mtwuQchEvNKGVKG/3G9uedpOLYTb DgDw== X-Gm-Message-State: AO0yUKWc0dWoYpitWjM9jL11jQVYUaMVEKOs8tKfAAvlH2cjfwHXYuuO TyMs8oXPI1lgD4pWfjo2Z3bQ6AK1ENWg 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758459518568121679?= X-GMAIL-MSGID: =?utf-8?q?1758459518568121679?= 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: 60173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp111877wrd; Tue, 21 Feb 2023 08:50:46 -0800 (PST) X-Google-Smtp-Source: AK7set87GT5iu4eB4qr5MP1fgfD2509AeS1XUcKYHCqRELil+8m3Tii4RJOzc3k3xmkVktEjAYYf X-Received: by 2002:a17:902:f541:b0:19a:98c9:8cea with SMTP id h1-20020a170902f54100b0019a98c98ceamr9754843plf.39.1676998245858; Tue, 21 Feb 2023 08:50:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676998245; cv=none; d=google.com; s=arc-20160816; b=TxmGmzf1Se7Trrnig6FHllDU3AAwbytcPsGvu/7Gjb7age1RALzrushIymzbos5+b6 5pQkZLKKvYj4HG8Ue2/YVYJX8gA1qRnJRGIDJVxc3FUy5+UlOis9fpzhMMaI7SVLCOs8 QxeerDsSkXKegeEokcOc/su6CYQw/l+3IFt3DCfDzhZQAgjejWxl18YaAWKrPdjglvoq psIIbpQyv/tG5KYuGz5yQulJrQ2Gp9aGPrpNHbyEOpBYbjz50YUvCx7K1yPnTOx6577y jbwfw2/NJGWov1UHQJbybFWk6/hI71b+bBX682L73f163P+gc2rrNEAWWfXsYGbq9h3v Xj6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=V/DDoXnf2opyFk/JIknDREbRoogTSxKXRqdxFHEiFI8=; b=iqMtngOrA6MMUJ9BOJ7R1ggGjuvFGD5mDCBq3XKlQ1HOdta4Rtm1KkC/pPGe9bCCTm RFLYB1biTzkTX64fYEebknNOpyUQyDchvwavbNNH7gdnf2Me7SPprsLRia03NyGqSYKr Y2uKhtObHDlpBl+aG7lcUJGQ/LqrmhyBhyq1/wmuOker3VDszOc5azmdE/E4s5SFstfj vT/2WcscovOL1wGhl2wbf1CdRN9Kpv8UpNT+Gd53gJ/PYci+Klv0Sm4CdA01g86NnBZP aWwLXJRYZWYKlNbGiPDxZBa5jz6NLAiCz1VaBVsDqYENrxjhmR522UE+D2L7EMqzJuvu DSYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=azZPMaZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u16-20020a17090341d000b0019a7c890c6esi15197395ple.621.2023.02.21.08.50.32; Tue, 21 Feb 2023 08:50:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=azZPMaZP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234856AbjBUQi2 (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234900AbjBUQiC (ORCPT ); Tue, 21 Feb 2023 11:38:02 -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 BE71D2D143 for ; Tue, 21 Feb 2023 08:37:39 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id g13-20020a63f40d000000b005015be7b9faso2219323pgi.15 for ; Tue, 21 Feb 2023 08:37:39 -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=UJB9u2rTD55R3KSwHKH2ojKv39rtZXBmxnnfQjztpASsyGs0TpsR3coynr8sf19qEK 5baqXmG2lvj2syktFIeAJjYX8OXMXCaszYrVTKyB64cOqdRZzfgg/Znr15HWU3PaW4kA kpye9WOztwaT8rhysf4yNrPA0yZ5bYR5tbF1DcQTQTxYpjk4neXqIlDlNZMrWCwzf1iE MJCxOflydb3S2qH8lvqDe2Szc/8gSgfLk99zEbtnVq8+UFNFT4DR2/7DTVwREpAMZKDv XzoAsxmr3eL6FdaKmDZuPTeP0w9eR9eDRgCqnmdLJaeKyBHP83d2t1/dvCRCdEwVCn1B KV4w== X-Gm-Message-State: AO0yUKWtfyWWxEKFPEgDytnAS3ecfdCI5Pm7xb8+ZL/dVmdYtw5lW3w4 zaf+Pvus4BfWJs+wRSRU8ZstSQZWgW3e 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758460112450177608?= X-GMAIL-MSGID: =?utf-8?q?1758460112450177608?= 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: 60174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp115207wrd; Tue, 21 Feb 2023 08:58:39 -0800 (PST) X-Google-Smtp-Source: AK7set+iGNCo5TPsRoC8B7KxdPOut7x3T7uUcyT4GOOvtCFkDklRx7Pf321KAASnezxww9TG2r8i X-Received: by 2002:a17:902:e84b:b0:198:f8c9:7f4b with SMTP id t11-20020a170902e84b00b00198f8c97f4bmr3858066plg.2.1676998719442; Tue, 21 Feb 2023 08:58:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676998719; cv=none; d=google.com; s=arc-20160816; b=siD+sClERxQs2UDftWsnn5kFPewtIqDO/kIvRz/sYbUL+DhzfyjScKe3jtnDVJOx9+ lp61FsV0mDKwgDdC5471aJLRZ66pehrjEoL/aCuCfW46KKmIGw/GkhYHIEO7NFdqVSFr 1EGdzea+nDxtFko6jzh+st7v0mijJs7KZPrkbdkMk0octLJU/13S45IBOi+B0rvAn4M3 wa3LTmB6tRCl+6AG4Bww7qYT6bJzYZ4ZLINXciRhTX2okFTSukLpHSlnJn1JNWvoandE S5ESlmf1/wN1r4NDn/IA04Qulc+QW9piV0twj93sFe9/vWeU5+2r9VUBT6BTiKCMyZwK 7a4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=HMhvhuYsZ3myRfljiC/gjTRwZifcMTe4p3PNN7RnFQc=; b=nc+Wc29q0Ewl3M20NbbdgfIrAiKMvykkFtfMYVtWBzBBnDZk0h9Hwgx580LP5TNK3S Q826Fj+/i7u752OU2eGlAGSExnMSlP/g/YB6Kr6onUTdgn0vlKxGO/DZUZ0JFKQ8lY2N e/d7hEA08f8D/BUb8o1Yt0EKR1jZ11TqDtkedWN2YpkJkRNpfZc0iRkgmtQpxYfYc0X7 fdTpzO4/nzEEGfTML+QKtJHWvpZtGW5Nb9nOPJ3v2IdlyJcAqxNyvTaWedO7uQCnZ/lH 2v7j0AzlF3JFA5tldpTRuRtm5VW76poNnWMCFZbq5GuMUvHTrA9wPeP6ri/Fn9kmzA9F yTHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KmVIllOg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ix9-20020a170902f80900b0019611a98665si6274181plb.112.2023.02.21.08.58.26; Tue, 21 Feb 2023 08:58:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=KmVIllOg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234969AbjBUQih (ORCPT + 99 others); Tue, 21 Feb 2023 11:38:37 -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 S234862AbjBUQiK (ORCPT ); Tue, 21 Feb 2023 11:38:10 -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 59B352D168 for ; Tue, 21 Feb 2023 08:37:44 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id o38-20020a635d66000000b004fbec68e875so1519400pgm.1 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=Rct222PeZ+68VBInbPTeW+h8VTd51Nq/U6fTBU1mwDcIIdMIo6UqlIVW7JzBa+BBjB XBfi9LB55IitBILmnXfoMlRZVA4nXto/STbadeCL3d4MpYmKQy4vaf8KfayqED6PgxxI /DPFTezueSUzcreHbgdwLP4Vkwc1W69LulxKxbFWPVc38Y5Yl0zJZhGc3uEdxnH/ucZR H7JHppKSbcobxXpmXevngJ5RYKocZGhnX+8RZPaEQbF5C9aWkvXYCjoE0D6RfaA9wh+W RHF8FheCDZQrp1Zrm+IRIm4rGD0DX08KURUml7gICQgh5m+6MM4Eaolosi8wmggittqZ iQWw== X-Gm-Message-State: AO0yUKXhDUXB4lr8roxrQdC0iWkGOP1rHzJ92nxEL+pUM28yIQNunuEm mIprmlbdy3xkqxrCQ0QXblMvtBD+MC+H 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 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758460609240381959?= X-GMAIL-MSGID: =?utf-8?q?1758460609240381959?= 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);