Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1883982iog; Thu, 16 Jun 2022 16:25:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1seRNSNxGoQUbT2eDvh96s6Z0toOYvX5byaNA1V0fIUxUnHguNMYXmlb70tksNpWwGvgDM0 X-Received: by 2002:a17:906:79ca:b0:705:111f:12dc with SMTP id m10-20020a17090679ca00b00705111f12dcmr6725276ejo.602.1655421956142; Thu, 16 Jun 2022 16:25:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655421956; cv=none; d=google.com; s=arc-20160816; b=MMcvdCm4a2Nb4miw9j37+sWkleFgfGLhBPdbY8OnLHkTqBPSD/6p8oACW6MYDrSs9w gfu8dsm/MXXzxtyar6Id2hZ8NOkj/4rllAJ5eh2QJHY6bQy4ueD45dQWPGCZ7w8q1/49 d/pVSZInzJenzuY/nspNkDQNNHPa4yjz5KLac3lg/UNuWprw/wxUGvOqifvnFgBxpwyC grIpUlkjVBHVBnu6L68QlqYaDsXRWsb2t+Gma5Iy1GgbKMVt388H0HTBIHN6YLa3JtJR 5giNG+BM4F6UOg8hfexwpy8UOu9+UVEjmKmWC3PbsB7x8aYK31GG+f9YJLP4mEs7ZKiU V0bA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=7wV78KF4dgnUbQxk8pc94OHUoJRSZfwr41EF876rjV4=; b=Wt77Ohf+jTltT0CqSrwv4wah6Yq150d1t0UW98zndpksKKoTIk/lGSozKCQKgHipAb fBd7LhJTdjwPGkH3vQkltrESo1CuNtYWGrpjBXYfqdNrXXS6Crhw8ayqD7mI7OkOVMhI u6tPzpBaO4G0Dm9a8v9yhyDLsogpginjWMxKD/1LLhEtMnTPpdq7z6UsSYd/f7rVmc0M nxxdGygPyRVZz1Qsk1Wbn37olqpz/vuDu7SkomJPUTvNdXyapF9a2JJv566BCYmQVapm i7u3yCszTYhGSHgeWVxWyBbDFHVC0rZy7GOX1OyvLq1brJQdghSyqsJp+t468NKtZE6/ cgyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=DNbvDqOb; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c27-20020a1709063f1b00b0070f78b64762si2945732ejj.364.2022.06.16.16.25.30; Thu, 16 Jun 2022 16:25:56 -0700 (PDT) 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=@linuxfoundation.org header.s=google header.b=DNbvDqOb; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378791AbiFPWye (ORCPT + 99 others); Thu, 16 Jun 2022 18:54:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349040AbiFPWyb (ORCPT ); Thu, 16 Jun 2022 18:54:31 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D449C6212F for ; Thu, 16 Jun 2022 15:54:28 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id q11so3513742oih.10 for ; Thu, 16 Jun 2022 15:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=7wV78KF4dgnUbQxk8pc94OHUoJRSZfwr41EF876rjV4=; b=DNbvDqObxLMXa/rES4xAoWU4Civ7qJLfBw5zxQx08WrRR7NVxi8Yzg408cwdWX+QH5 9dI2+M35fzecclwkWTTDSaRchm8T7VNkAQYYlab/R3Ecj5LgVXjZIXOOQQQIRqcx596j GtHWaX+RqlOcJcM5E4yqqQoF94qQLPi5aOnxw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=7wV78KF4dgnUbQxk8pc94OHUoJRSZfwr41EF876rjV4=; b=hLgSRthmA3jgP6QuJzw/xPk4pGChNZdk+Z/0DYeumse0/hMQ2v+PAgwcb2q/X/45BK ZAoTr0UZg9c0MCUIqwTR0IKQBxFEWq2NSPlBkJqPkLDv1XIwu1OhrswaBByHZaQMB1k7 iv4PvZ++RTR6W3scJyA1JqCivsbnquEribEslNaT8vpyAlejUUceeDfkIgWtOnqwOO/M o+7aD5mIdrUzmfNdiTrtiCpnuFR/jG8La7L4QX6cZ8X3GADwd1QdR/kpfEodq92rU1Nf zEiktQrgfval+6MdLpfp5OJJbRFn9Yl/mYoM+sCkV4khCQuFk8CEntLLU77STteH0LC9 nn5g== X-Gm-Message-State: AOAM5309x6uj5y04vo8RtPIiMsN3RLt6kCXubvjkX7fyYmogMT69uDr2 t2y9malmTOyDLBkAb2dt03PxEQ== X-Received: by 2002:a05:6808:2117:b0:32e:f441:8cbe with SMTP id r23-20020a056808211700b0032ef4418cbemr8919388oiw.167.1655420068100; Thu, 16 Jun 2022 15:54:28 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id u19-20020a056870951300b000f309d52933sm1501573oal.47.2022.06.16.15.54.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Jun 2022 15:54:27 -0700 (PDT) Subject: Re: [PATCH 2/2] selftests/x86/amx: Fix the test to avoid failure when AMX is unavailable To: "Chang S. Bae" , linux-kselftest@vger.kernel.org, shuah@kernel.org, linux-kernel@vger.kernel.org Cc: dave.hansen@linux.intel.com, tglx@linutronix.de, bp@suse.de, Shuah Khan References: <20220401221014.13556-1-chang.seok.bae@intel.com> <20220401221014.13556-3-chang.seok.bae@intel.com> From: Shuah Khan Message-ID: Date: Thu, 16 Jun 2022 16:54:26 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20220401221014.13556-3-chang.seok.bae@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On 4/1/22 4:10 PM, Chang S. Bae wrote: > When a CPU does not have AMX, the test fails. But this is wrong as it > should be runnable regardless. Skip the test instead. > > Reported-by: Thomas Gleixner > Fixes: 6a3e0651b4a ("selftests/x86/amx: Add test cases for AMX state management") > Signed-off-by: Chang S. Bae > Cc: linux-kselftest@vger.kernel.org > Cc: linux-kernel@vger.kernel.org > --- > tools/testing/selftests/x86/amx.c | 42 +++++++++++++++++++++++-------- > 1 file changed, 31 insertions(+), 11 deletions(-) > > diff --git a/tools/testing/selftests/x86/amx.c b/tools/testing/selftests/x86/amx.c > index 3615ef4a48bb..14abb6072a7d 100644 > --- a/tools/testing/selftests/x86/amx.c > +++ b/tools/testing/selftests/x86/amx.c > @@ -106,6 +106,12 @@ static void clearhandler(int sig) > > #define CPUID_LEAF1_ECX_XSAVE_MASK (1 << 26) > #define CPUID_LEAF1_ECX_OSXSAVE_MASK (1 << 27) > + > +static struct { > + unsigned xsave: 1; > + unsigned osxsave: 1; > +} cpuinfo; > + Why is this needed? Also naming this cpuinfo is confuing. > static inline void check_cpuid_xsave(void) > { > uint32_t eax, ebx, ecx, edx; > @@ -118,10 +124,8 @@ static inline void check_cpuid_xsave(void) > eax = 1; > ecx = 0; > cpuid(&eax, &ebx, &ecx, &edx); > - if (!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK)) > - fatal_error("cpuid: no CPU xsave support"); > - if (!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK)) > - fatal_error("cpuid: no OS xsave support"); > + cpuinfo.xsave = !!(ecx & CPUID_LEAF1_ECX_XSAVE_MASK); > + cpuinfo.osxsave = !!(ecx & CPUID_LEAF1_ECX_OSXSAVE_MASK); Why add this complexity. Why not just Skip here? > } > > static uint32_t xbuf_size; > @@ -161,14 +165,31 @@ static void check_cpuid_xtiledata(void) > * eax: XTILEDATA state component size > * ebx: XTILEDATA state component offset in user buffer > */ > - if (!eax || !ebx) > - fatal_error("xstate cpuid: invalid tile data size/offset: %d/%d", > - eax, ebx); > - > xtiledata.size = eax; > xtiledata.xbuf_offset = ebx; > } > > +static bool amx_available(void) > +{ > + check_cpuid_xsave(); > + if (!cpuinfo.xsave) { > + printf("[SKIP]\tcpuid: no CPU xsave support\n"); > + return false; > + } else if (!cpuinfo.osxsave) { > + printf("[SKIP]\tcpuid: no OS xsave support\n"); > + return false; > + } > + > + check_cpuid_xtiledata(); > + if (!xtiledata.size || !xtiledata.xbuf_offset) { > + printf("[SKIP]\txstate cpuid: no tile data (size/offset: %d/%d)\n", > + xtiledata.size, xtiledata.xbuf_offset); > + return false; > + } > + > + return true; > +} > + I am not seeing any value in adding this layer of abstraction. Keep it simple and do the handling in main() > /* The helpers for managing XSAVE buffer and tile states: */ > > struct xsave_buffer *alloc_xbuf(void) > @@ -826,9 +847,8 @@ static void test_context_switch(void) > > int main(void) > { > - /* Check hardware availability at first */ > - check_cpuid_xsave(); > - check_cpuid_xtiledata(); > + if (!amx_available()) > + return 0; This should KSFT_SKIP for this to be reported as a skip. Returning 0 will be reported as a Pass. > > init_stashed_xsave(); > sethandler(SIGILL, handle_noperm, 0); > thanks, -- Shuah