Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp182531pxb; Mon, 7 Feb 2022 08:57:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxXkZV/DtS+zm3M989kO3VElq7dejirmJTS0lItc6KJE7KW2Wk3avWhK3fjLFXCHLvh5cit X-Received: by 2002:a17:906:524e:: with SMTP id y14mr463633ejm.757.1644253022869; Mon, 07 Feb 2022 08:57:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644253022; cv=none; d=google.com; s=arc-20160816; b=JJLpfh7R8KwCai1kR+T6ykZ9iGF20lDgf72mBbBNTJDNzvrYeuQmFtA1bXuZM0KHHr clHwx/k25paEOwPSkoj4sc/XmFwrKc232v4TfXcAoh0PjTAlFyeW74pY4fGNDeOFcyih 8TUGErUWidQS6ml5vS8G27hDfTj4hnYvRMQxn8ji+00NJt1E2p1ePWvK9yY7NBx9NrLB wwxkWTIC2/LysjmWoTB+EVVRehKdF3XSQ6wjTR8t5gM+gXcC7Hnj+xRrVhxRv76Spt8/ UzXK65Zd7eRagQjyKx91k9ap//lhyOFnxhUhUw4AjrgDi6+iF9eMA8l2DH9JoDZQoW0Z XAJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6chEKyb4dbs7IMH3i4P7lE/CyAnRMlZEGub6G0OHGDo=; b=Cbz9FPkwVrd7ZUatnN4w/3GCzNAUh2ohluq1/nc6jjRgQDZDd3qwHvfFfLwAxvcHFG chSPqyW95Z8ijf07CpcASHtR9x0RWygKd0rCoEBUXuLagQkNd6G9AJfB9GWjbmGQY9Tz Kun47AeaHrMuVkIzVuZOStYLd+Puotuyojv4TcECtQS5hX0/Ov9vGSAGx9rzYx1dw6ba FdDiQOMtRg80RABFOyzBzud7i0Qy8DsH//LJSKgXGa4oYiqWUkDVjZrxUWrEmWZID4bV b/qYJFZVGEM1LfIhHzuM2tqQV/Dt9f07CZoHZzd+OW5NtRvI/sT2LRjS9i+yDlwBZr64 IxqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=P2vOAFdX; 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=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hs15si8062289ejc.77.2022.02.07.08.56.37; Mon, 07 Feb 2022 08:57:02 -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=@intel.com header.s=Intel header.b=P2vOAFdX; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232713AbiBDTSK (ORCPT + 99 others); Fri, 4 Feb 2022 14:18:10 -0500 Received: from mga11.intel.com ([192.55.52.93]:61194 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232259AbiBDTSC (ORCPT ); Fri, 4 Feb 2022 14:18:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644002282; x=1675538282; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hSJGQlS3PL8jbOVhKeoI5KEQF3vEjiDdnv98cafGarE=; b=P2vOAFdX0BEzzPmO6u5f3hqQzAxFW1FA8piav8dZ6zVLXXuYdmUlZL6E 35XndsdzkeOKEVwAoEpBi1mrJD6J1eMh/YFGMYYCtXU0rn6TK91TkyiIl FfpCNTVSq5/3qAUTkw4yU0Be/s1CPMHqLd4lnPKgkEZvvX46aFBW7CurX k4rLgNs3rMxR0jyI0O1zVV8c8e/zPx4onHvWhBRqC+8nkXA2tVQ+0FN88 7ScmN7eHxovF00wx2zs+5pGzth83p8GEPUkqdSFKkSDOLrsGbq3jaylL+ yonF10znT+Il/TPo8dSCLReYjT6hNGzai5C+GA0LwK1XTtKKq0IOuGjUq g==; X-IronPort-AV: E=McAfee;i="6200,9189,10248"; a="246017070" X-IronPort-AV: E=Sophos;i="5.88,343,1635231600"; d="scan'208";a="246017070" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2022 11:18:00 -0800 X-IronPort-AV: E=Sophos;i="5.88,343,1635231600"; d="scan'208";a="524412819" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2022 11:18:00 -0800 From: Reinette Chatre To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Reinette Chatre , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , x86@kernel.org Subject: [PATCH 3/3] selftests/x86/corrupt_xstate_header: Use existing __cpuid_count() macro Date: Fri, 4 Feb 2022 11:17:11 -0800 Message-Id: <6bc87ebe3a62ad2ee31a5e5952897c48a8ef2d77.1644000145.git.reinette.chatre@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gcc as well as clang makes the __cpuid_count() macro available via cpuid.h to conveniently call the CPUID instruction. Below is a copy of the macro as found in cpuid.h: #define __cpuid_count(level, count, a, b, c, d) \ __asm__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) The corrupt_xstate_header test contains a local function used as wrapper to the CPUID instruction. One difference between the corrupt_xstate_header implementation and the macro from cpuid.h is that the corrupt_xstate_header implementation provides the "volatile" qualifier to the asm() call. The "volatile" qualifier is necessary when CPUID has side effects and thus any optimizations should be avoided. CPUID is used in the corrupt_xstate_header test to query the system for its XSAVE/XRSTOR support, a query without side effect, the "volatile" qualifier is thus not required and the macro from cpuid.h can be used instead. Remove the duplicated wrapper to CPUID and use __cpuid_count() from cpuid.h instead. Cc: Andy Lutomirski Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: x86@kernel.org Signed-off-by: Reinette Chatre --- .../selftests/x86/corrupt_xstate_header.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/tools/testing/selftests/x86/corrupt_xstate_header.c b/tools/testing/selftests/x86/corrupt_xstate_header.c index ab8599c10ce5..7a877612bc98 100644 --- a/tools/testing/selftests/x86/corrupt_xstate_header.c +++ b/tools/testing/selftests/x86/corrupt_xstate_header.c @@ -7,6 +7,7 @@ #define _GNU_SOURCE +#include #include #include #include @@ -17,25 +18,11 @@ #include #include -static inline void __cpuid(unsigned int *eax, unsigned int *ebx, - unsigned int *ecx, unsigned int *edx) -{ - asm volatile( - "cpuid;" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (*eax), "2" (*ecx)); -} - static inline int xsave_enabled(void) { unsigned int eax, ebx, ecx, edx; - eax = 0x1; - ecx = 0x0; - __cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(0x1, 0x0, eax, ebx, ecx, edx); /* Is CR4.OSXSAVE enabled ? */ return ecx & (1U << 27); -- 2.25.1