From patchwork Mon Apr 25 21:01:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Reinette Chatre X-Patchwork-Id: 12826247 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 87627C43219 for ; Mon, 25 Apr 2022 21:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245344AbiDYVE2 (ORCPT ); Mon, 25 Apr 2022 17:04:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245361AbiDYVE1 (ORCPT ); Mon, 25 Apr 2022 17:04:27 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7474418366 for ; Mon, 25 Apr 2022 14:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650920482; x=1682456482; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=w7ZUWLKRXUP8kqeBeYtwr3UEk83DO0yta+5VHHRAy2k=; b=UStEipLaCJLiuVRVQtdiLEL9/grsmD1Z21yv+M5HkIQ3p38u8D2JKYsB cPU7sGtIgDr0hwzhYqWdLY5eYd6jfBLOvIPiF9DT2wgexr3rHjA9GbQF7 /nX/HrG/g/CjmDL0Jd+PI5fvqE4I8gg2U9F/y9S5UlVHq3FtRtTMZWcje r3rOjL+ae+wxAyGj5Z0dnRC1D+h39ZQDU1F4mKPHPFh5YJfvvHTZqGGQO NsK2BrbgsGwzAiPPrYWr8JkoSdtvaKe58ajCjTBxCEb7hVbSlhmS0RBts 1tKoIvJYVwWbxdZAR9hlSbQr4BMbURMEChKnrKBbZU7P5kgUV3KAI7Q6K A==; X-IronPort-AV: E=McAfee;i="6400,9594,10328"; a="290502307" X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="290502307" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 14:01:19 -0700 X-IronPort-AV: E=Sophos;i="5.90,289,1643702400"; d="scan'208";a="579499498" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2022 14:01:19 -0700 From: Reinette Chatre To: shuah@kernel.org, linux-kselftest@vger.kernel.org Cc: dave.hansen@linux.intel.com, sandipan@linux.ibm.com, fweimer@redhat.com, desnesn@linux.vnet.ibm.com, mingo@kernel.org, bauerman@linux.ibm.com, mpe@ellerman.id.au, msuchanek@suse.de, linux-mm@kvack.org, chang.seok.bae@intel.com, bp@suse.de, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com, luto@kernel.org, x86@kernel.org Subject: [PATCH V3 2/4] selftests/vm/pkeys: Use provided __cpuid_count() macro Date: Mon, 25 Apr 2022 14:01:12 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org kselftest.h makes the __cpuid_count() macro available to conveniently call the CPUID instruction. Remove the local CPUID wrapper and use __cpuid_count() from already included kselftest.h instead. __cpuid_count() from kselftest.h is used instead of the macro provided by the compiler since gcc v4.4 (via cpuid.h) because the selftest needs to be compiled with gcc v3.2, the minimal required version for stable kernels. Cc: Dave Hansen 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 --- No changes since V2. Changes since V1: - Update changelog - Remove Ram Pai from cc list (email address no longer valid) - No longer include cpuid.h but obtain __cpuid_count() from kselftest.h. tools/testing/selftests/vm/pkey-x86.h | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/tools/testing/selftests/vm/pkey-x86.h b/tools/testing/selftests/vm/pkey-x86.h index e4a4ce2b826d..b078ce9c6d2a 100644 --- a/tools/testing/selftests/vm/pkey-x86.h +++ b/tools/testing/selftests/vm/pkey-x86.h @@ -80,19 +80,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 +91,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 +127,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;