From patchwork Tue Feb 14 18:46:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 653593 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 157AEC64ED8 for ; Tue, 14 Feb 2023 18:46:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233041AbjBNSqY (ORCPT ); Tue, 14 Feb 2023 13:46:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232889AbjBNSqY (ORCPT ); Tue, 14 Feb 2023 13:46:24 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95B9F25B98 for ; Tue, 14 Feb 2023 10:46:22 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id h5-20020a170902748500b0019aacd1fb04so2520817pll.2 for ; Tue, 14 Feb 2023 10:46:22 -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=5nUSaAHTCtcISA3mdIgge3B10pS6vcmVmT5MYhffil4=; b=ZTtGmMonLp63QLXd3+qi7ZNjcLN08BBqVEFbE3+QZzT8r/Pvq6CIEIGkJohT90B8R6 Bjpx1TI25787jVCqUdpEHMgeHJvFIM+nIpyq8XN3inXL4spBTFSwqXwQZnhoZiBQzJO6 TN+GES4KnuSQWeoAnQ4EAPgfIVhNAudXijByl3hE8hl2j4fi1LWLZYCYu9CdvXUxaZ+u whraXb0fPSbe/bqB67ELNCxCUtB7C5sm77ANXkef5sRLCRoQqMBaN9IQ5ZVI5yJYOoTD LYXZbCC5CA9silAM3ISnSO2mnYZASaUQMaJVmym+J7JMADsXMw8yOX1wcizMa5EDG6+W muJA== 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=5nUSaAHTCtcISA3mdIgge3B10pS6vcmVmT5MYhffil4=; b=AqMFcmXNhz5x9Tahx+SWBtHz6jb0b4VOPL5zppThN2tXSlJUJNX61LLcght6hQ6O0S sxng+2qgIqAU1+nW+luMc2sFuJX6ZtsOSBlSmOmSzaQmUCbHCf8+d98ZzhmGivg4GrLh FE2VZ2dajDhvgsXn77kSk+1GgSHUb5oEYeN2MmeAu+PlDqcmwExGr73LAobpSjgzkp/p aqXCQgqS6Wtf+eirZebBUMTd9N1+67OdAgkPLctnoXhpUQSgj+W0GeJ31KS1GGKDnNxU QRkSL10SxQWt/J4aay8rRInUIDZ8R0YfnpM0Xj/LeWyCwUPV5+8IcUfydKK/Q5jxuz2r 1P9Q== X-Gm-Message-State: AO0yUKUWD5q0TMgLfFwnR9sJCB+dkOhOBputImo1y/E+9FMk8dQUwxFp mSvF1Rlq1+geT6vv5sD2n9FrpFaEeZdI X-Google-Smtp-Source: AK7set+TikdqMEeRUvVc4ODDzinFrSvu9UtzSrnUkSE7ruTqGTaliOA/CLOW87EdIftH6vdxa9RhB7caRSYZ X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:6dc7:0:b0:4fb:ba81:7143 with SMTP id i190-20020a636dc7000000b004fbba817143mr63323pgc.0.1676400382093; Tue, 14 Feb 2023 10:46:22 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 14 Feb 2023 18:46:01 +0000 In-Reply-To: <20230214184606.510551-1-mizhang@google.com> Mime-Version: 1.0 References: <20230214184606.510551-1-mizhang@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230214184606.510551-3-mizhang@google.com> Subject: [PATCH v2 2/7] KVM: selftests: x86: Fix an error in comment of amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org After the execution of __tilerelease(), AMX component will be in INIT state. Therefore, execution of XSAVEC saving the AMX state into memory will cause the xstate_bv[18] cleared in xheader. However, the xcomp_bv[18] will remain set. Fix the error in comment. Also, update xsavec() to XSAVEC because xcomp_bv[18] is set due to the instruction, not the function. Finally, use XTILEDATA instead 'bit 18' in comments. Cc: Jim Mattson Cc: Venkatesh Srinivas Cc: Aaron Lewis Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index d506821a5a26..aac727ff7cf8 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 14 18:46:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 653592 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5C37C6379F for ; Tue, 14 Feb 2023 18:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233441AbjBNSqd (ORCPT ); Tue, 14 Feb 2023 13:46:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233178AbjBNSq2 (ORCPT ); Tue, 14 Feb 2023 13:46:28 -0500 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D371630283 for ; Tue, 14 Feb 2023 10:46:26 -0800 (PST) Received: by mail-pl1-x64a.google.com with SMTP id h5-20020a170902748500b0019aacd1fb04so2520929pll.2 for ; Tue, 14 Feb 2023 10:46: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=3bW5FuKrIfXRo88FKUNDpYqHZp7+18tX4wacmmrm8Gk=; b=aB+fVOG0ZogMNPWQZ2b1Wf3xANIRYlugnuwlbdPPGPEHz6wvWyQ3TNUhDEGEfmqq0m TymQAkocu2l38TVGBDqJRcGkKsMZtKKGls3r3ORrZOQ3gmRHFd7nDtml1wqoiuAtyBU0 2Pn/wGx/LAhcM8siOvd/nLPYmZOXZA/Yn0k35vv1/jU16Ulmua9W/NLy9ifYxf4eOFhN Mrms9i+uHgqEW9d1sVT5rY+M9Ui9+ImWRApVZjuOQTg2PpKYUAehBZ2qWD6W8iocMU/L goLl3zrgBxV2lL+KJAI/4taxOisx85I7gG+m1FIKQjVjRn8ldQmhSqY5G3hYDh5VNqFV fDRQ== 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=3bW5FuKrIfXRo88FKUNDpYqHZp7+18tX4wacmmrm8Gk=; b=5oxqd8UK/tp+KIv3YYeRcDuLkBVqgAraU9aq30RlhDJzfQs+BoinV6ZUgqKm7rM6WK /WDZso0o+FrMZhxj5qhH9Opnt/n+nIJFZXqoFx2j421Fa2uH70nNxJRXhhYixAGpgRLv 76JUMRhI568zic5iF+YLXH/IAwGSc6K1aKia74zMxcuZg/0W5R0FBY5kft6strHuNqVS NVSFRwHwBX029eQTejHJpvZLhqBPGGbFudol/TtnLk9eS79YAgwsjfboOBSFqt+MZ8dx duFIaSAgUfLhfIbeioe0sSkItunmtqmVq9XJPtQWVrJmttQF6PAnXncHH1vsduDtpWpS /zOg== X-Gm-Message-State: AO0yUKWnTU7xQFvwU4JqX8F5JIPkpbmulmvY9dKCNb0JHL3sPFnfiP8Q UhW8PefRq5AW4vMUIhRCjeWRCm34Arp+ X-Google-Smtp-Source: AK7set9WUSpyDoSjh/Xxe2GtC0MW65lxlPEcpJKTam+H34pLso9YWFBBVwE8KxMflLxS11pdrY6LOmflZhQm X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:3dc4:0:b0:4fb:58bf:d25f with SMTP id k187-20020a633dc4000000b004fb58bfd25fmr62667pga.7.1676400386299; Tue, 14 Feb 2023 10:46:26 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 14 Feb 2023 18:46:03 +0000 In-Reply-To: <20230214184606.510551-1-mizhang@google.com> Mime-Version: 1.0 References: <20230214184606.510551-1-mizhang@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230214184606.510551-5-mizhang@google.com> Subject: [PATCH v2 4/7] KVM: selftests: Add the XFD check to IA32_XFD in #NM handler From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add an extra check to IA32_XFD to ensure the behavior is consistent with the AMX archtecture. In addition, repeat the checks across context switch to ensure the values of IA32_XFD and IA32_XFD_ERR are well preserved. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index 847752998660..44c907215343 100644 --- a/tools/testing/selftests/kvm/x86_64/amx_test.c +++ b/tools/testing/selftests/kvm/x86_64/amx_test.c @@ -217,8 +217,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 14 18:46:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mingwei Zhang X-Patchwork-Id: 653591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F27FC64EC7 for ; Tue, 14 Feb 2023 18:46:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233213AbjBNSqn (ORCPT ); Tue, 14 Feb 2023 13:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231964AbjBNSqi (ORCPT ); Tue, 14 Feb 2023 13:46:38 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C36302B6 for ; Tue, 14 Feb 2023 10:46:30 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id h15-20020a170902f7cf00b0019a819e2d93so6180791plw.4 for ; Tue, 14 Feb 2023 10:46: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=6RZ7TspMKDDk7tmMAFyvIRoGpdz/k0McGOaNtuOXScs=; b=mHLMbcVVgMDEwYayJ9YUqi2Dw/jj0GYAjAZKWXI4WKsLDy/gyCPJJ0nf7Qy2PNmSyp k6KjMqwph6digoMqvido6AvIDuV+z+trxmm7HluclADFe1vYGJfovo80iN7x5D3Ni8aj RncvhqsMaqT+sRK+wYRVHs8u94Y6vhKS4jWU3AHQmyXPGprS0/tuVqk08DitnA0wlGWg VSfm0DI1b1QvgzpNC7HkBN6EaboH9RGMY5tCaCfxK3sq0IOjGdLvYMfEtrW7q0L9ADrb rNGLC+ah7weJiVsJSeqmbOjqWuXkrRTroxPUja7wHZgIxhi2NRChj/KcnUDNyRnb9GNe aQhg== 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=6RZ7TspMKDDk7tmMAFyvIRoGpdz/k0McGOaNtuOXScs=; b=4KW3quEEjitD098dU6NEcCsmZFJuMyLgwukjj6bHq7L53idPhUgfJMmU7fBPD3Grzf 1kHKXMMJnIl7NEffsgCUcI6CLzBNA3EgMi28ox2y6f081Utrye6jRA9oks5kRpGyAaVS fCI+eUApGAQPxygibJTens4dLUGmayvCyV9Jt06VU9A5s592Iqwp9LAZJs8lYhGRhBcb 5rl5G1EXM2hgJNtdwsqb21bboEQOd1pWYUyiVV2U7BKbhc/vklK8Bzdga45NXyLDmGU7 4hXWzR0LwW4BAEP/RhgrbSJtAKvCN4WagqILMmhmbFLUjU6thHUw0QljsaqYamXDnaiW iaaQ== X-Gm-Message-State: AO0yUKXaol3PfLE9gFDp7vDSEGvSZip8y9dpOBML5UsXDeEmHRcOTVGV aqKh0sbb7wbVtndL0mdLjVjgZ9QrHPj3 X-Google-Smtp-Source: AK7set/dCoOrkzvEF9g82ilEvxmu8NS4Fkw+W9zyWTu/n8cDaqHWmQp5aPVWu/ReyfWEMU8QXVaMyzvYJTPx X-Received: from mizhang-super.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1071]) (user=mizhang job=sendgmr) by 2002:a63:3855:0:b0:4fb:d300:c637 with SMTP id h21-20020a633855000000b004fbd300c637mr63299pgn.6.1676400389768; Tue, 14 Feb 2023 10:46:29 -0800 (PST) Reply-To: Mingwei Zhang Date: Tue, 14 Feb 2023 18:46:05 +0000 In-Reply-To: <20230214184606.510551-1-mizhang@google.com> Mime-Version: 1.0 References: <20230214184606.510551-1-mizhang@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230214184606.510551-7-mizhang@google.com> Subject: [PATCH v2 6/7] KVM: selftests: x86: Enable checking on xcomp_bv in amx_test From: Mingwei Zhang To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , Jim Mattson , Venkatesh Srinivas , Aaron Lewis , "Chang S. Bae" Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org After tilerelease instruction, AMX tiles are in INIT state. According to Intel SDM vol 1. 13.10: "If RFBM[i] = 1, XSTATE_BV[i] is set to the value of XINUSE[i].", XSTATE_BV[18] should be cleared after xsavec. On the other hand, according to Intel SDM vol 1. 13.4.3: "If XCOMP_BV[i] = 1, state component i is located at a byte offset locationI from the base address of the XSAVE area". Since at the time of xsavec, XCR0[18] is set indicating AMX tile data component is still enabled, xcomp_bv[18] should be set. Complete the checks by adding the assert to xcomp_bv[18] after xsavec. Signed-off-by: Mingwei Zhang --- tools/testing/selftests/kvm/x86_64/amx_test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/kvm/x86_64/amx_test.c b/tools/testing/selftests/kvm/x86_64/amx_test.c index bd8bd9936f8e..0e4c65f9e2f2 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);