From patchwork Fri Feb 4 19:17:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 12735480 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D595C433F5 for ; Fri, 4 Feb 2022 19:18:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B6416B0073; Fri, 4 Feb 2022 14:18:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7546C6B0074; Fri, 4 Feb 2022 14:18:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F3866B0075; Fri, 4 Feb 2022 14:18:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0148.hostedemail.com [216.40.44.148]) by kanga.kvack.org (Postfix) with ESMTP id 4BABA6B0073 for ; Fri, 4 Feb 2022 14:18:03 -0500 (EST) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 0BCCA81FA9A1 for ; Fri, 4 Feb 2022 19:18:03 +0000 (UTC) X-FDA: 79106057604.09.4F0E767 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by imf27.hostedemail.com (Postfix) with ESMTP id 6275040012 for ; Fri, 4 Feb 2022 19:18:02 +0000 (UTC) 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=AMRK/0riEvu7xWjL/b2Vknzv7nHsvl6H7fyafRDpRZ0=; b=iYvd1SQDfrAsX3u7cNGj4zyGqF04MS6Wm+5JCt+wJBd7vtUiwOL3r8FO Mx/KnscI8P89ekMGdQf79hBedU+PC0TOuzth2/rTNeIoOTeCzyZQVvLZO Z4bMqDALMIuX8EKHCtBE/nttYrin7kfdWNgd5a3nEBPrSkf2DIHiuQYTk GDZ+PslTL2ZtjBvsNLBx9Q3qFWeZIr6FAmHwxApY+Hywi4+sR7GiAhwiX QhZaJC9ldYZnFH3jva5yUa9C6cd9oowfli5loEQCCIvT7obKTJIJGTUI2 vVklWwgV2Rqs8sk7o3QfIQ0IluI99Y0gsWKkgyLIGSmHow7t/hCAa+mlp A==; X-IronPort-AV: E=McAfee;i="6200,9189,10248"; a="311729089" X-IronPort-AV: E=Sophos;i="5.88,343,1635231600"; d="scan'208";a="311729089" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2022 11:17:59 -0800 X-IronPort-AV: E=Sophos;i="5.88,343,1635231600"; d="scan'208";a="524412814" 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:17:59 -0800 From: Reinette Chatre To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Reinette Chatre , Dave Hansen , Ram Pai , Sandipan Das , Florian Weimer , "Desnes A. Nunes do Rosario" , Ingo Molnar , Thiago Jung Bauermann , Michael Ellerman , Michal Suchanek , linux-mm@kvack.org Subject: [PATCH 1/3] selftests/vm/pkeys: Use existing __cpuid_count() macro Date: Fri, 4 Feb 2022 11:17:09 -0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6275040012 X-Rspam-User: nil Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=iYvd1SQD; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf27.hostedemail.com: domain of reinette.chatre@intel.com has no SPF policy when checking 134.134.136.100) smtp.mailfrom=reinette.chatre@intel.com X-Stat-Signature: a5bc7hsp7dphpodcoapjhs71amqbwmw4 X-HE-Tag: 1644002282-69493 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 pkeys test contains a local function used as wrapper of the CPUID instruction. One difference between the pkeys implementation and the macro from cpuid.h is that the pkeys implementation provides the "volatile" qualifier to the asm() call. The "volatile" qualifier is necessary if CPUID has side effects and thus specifies that any optimizations should be avoided. The pkeys test uses CPUID to query the system for its protection keys status and save area properties, queries without side effect, the "volatile" qualifier is 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: Dave Hansen Cc: Ram Pai Cc: Sandipan Das Cc: Florian Weimer Cc: "Desnes A. Nunes do Rosario" Cc: Ingo Molnar Cc: Thiago Jung Bauermann Cc: Michael Ellerman Cc: Michal Suchanek Cc: linux-mm@kvack.org Signed-off-by: Reinette Chatre --- tools/testing/selftests/vm/pkey-x86.h | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index e4a4ce2b826d..17b20af8d8f8 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -2,6 +2,7 @@ #ifndef _PKEYS_X86_H #define _PKEYS_X86_H +#include #ifdef __i386__ @@ -80,19 +81,6 @@ static inline void __write_pkey_reg(u64 pkey_reg) assert(pkey_reg == __read_pkey_reg()); } -static inline void __cpuid(unsigned int *eax, unsigned int *ebx, - unsigned int *ecx, unsigned int *edx) -{ - /* ecx is often an input as well as an output. */ - asm volatile( - "cpuid;" - : "=a" (*eax), - "=b" (*ebx), - "=c" (*ecx), - "=d" (*edx) - : "0" (*eax), "2" (*ecx)); -} - /* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx) */ #define X86_FEATURE_PKU (1<<3) /* Protection Keys for Userspace */ #define X86_FEATURE_OSPKE (1<<4) /* OS Protection Keys Enable */ @@ -104,9 +92,7 @@ static inline int cpu_has_pkeys(void) unsigned int ecx; unsigned int edx; - eax = 0x7; - ecx = 0x0; - __cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(0x7, 0x0, eax, ebx, ecx, edx); if (!(ecx & X86_FEATURE_PKU)) { dprintf2("cpu does not have PKU\n"); @@ -142,9 +128,7 @@ int pkey_reg_xstate_offset(void) /* assume that XSTATE_PKEY is set in XCR0 */ leaf = XSTATE_PKEY_BIT; { - eax = XSTATE_CPUID; - ecx = leaf; - __cpuid(&eax, &ebx, &ecx, &edx); + __cpuid_count(XSTATE_CPUID, leaf, eax, ebx, ecx, edx); if (leaf == XSTATE_PKEY_BIT) { xstate_offset = ebx;