From mboxrd@z Thu Jan 1 00:00:00 1970 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 7FCC0C433F5 for ; Sat, 16 Apr 2022 07:53:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CE666B0072; Sat, 16 Apr 2022 03:53:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 95C866B0073; Sat, 16 Apr 2022 03:53:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 81F256B0074; Sat, 16 Apr 2022 03:53:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id 6F8216B0072 for ; Sat, 16 Apr 2022 03:53:27 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3A9A5238E7 for ; Sat, 16 Apr 2022 07:53:27 +0000 (UTC) X-FDA: 79361977254.17.E76D20C Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf07.hostedemail.com (Postfix) with ESMTP id 67A7E40006 for ; Sat, 16 Apr 2022 07:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650095605; x=1681631605; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=xV/d1iJRhjqgFrWqpQ6qFBsR6GoGgFOYv3MLCdk9Kno=; b=jKcesFDQW8DpAowDnu8HQ3nCAxv6bOOpJ3kOHH3srBKL4KmjRs6TDiau rorp6n2Cte96pPoVf++7BfiIkRrPNMqcSpc8v2vpNfvhGXjRDTjR+pmxx Lovki9r8sVhWgUT5gYWgp8OORj7Q3he3FOunVnk92hhBotx2CNxWzVzO9 5fItlhbnj4rSt6nSy7p+StECCniY77D5xw5d7Pu1H6RpvqSo0Bx7fV1X/ aNgZUbzXnWRC8yldElcootV/rkAPjBbFKnnx/Ezf5bt+JIJqIPTLgJbaz 0XpBE2OABjiBL7eX2//2U3d0Fw7UGghRvt+dZW06uboRcALPUnyYLY4Od Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10318"; a="262133364" X-IronPort-AV: E=Sophos;i="5.90,264,1643702400"; d="scan'208";a="262133364" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Apr 2022 00:53:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,264,1643702400"; d="scan'208";a="528214753" Received: from xpf.sh.intel.com ([10.239.182.112]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2022 00:53:19 -0700 Date: Sat, 16 Apr 2022 15:52:00 +0800 From: Pengfei Xu To: Reinette Chatre Cc: shuah@kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, 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, hpa@zytor.com, x86@kernel.org, luto@kernel.org, heng.su@intel.com Subject: Re: [PATCH V2 1/4] selftests: Provide local define of __cpuid_count() Message-ID: References: <7c49dbfe5bab04389ed84c516fcbfe31d66df880.1647360971.git.reinette.chatre@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7c49dbfe5bab04389ed84c516fcbfe31d66df880.1647360971.git.reinette.chatre@intel.com> X-Rspam-User: X-Rspamd-Queue-Id: 67A7E40006 X-Stat-Signature: b8zmwnz9jt94uqo3cpci7fo5m57ioo3b Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=jKcesFDQ; spf=none (imf07.hostedemail.com: domain of pengfei.xu@intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=pengfei.xu@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam01 X-HE-Tag: 1650095605-570795 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: On 2022-03-15 at 09:44:25 -0700, Reinette Chatre wrote: > Some selftests depend on information provided by the CPUID instruction. > To support this dependency the selftests implement private wrappers for > CPUID. > > Duplication of the CPUID wrappers should be avoided. > > Both gcc and clang/LLVM provide __cpuid_count() macros but neither > the macro nor its header file are available in all the compiler > versions that need to be supported by the selftests. __cpuid_count() > as provided by gcc is available starting with gcc v4.4, so it is > not available if the latest tests need to be run in all the > environments required to support kernels v4.9 and v4.14 that > have the minimal required gcc v3.2. > > Provide a centrally defined macro for __cpuid_count() to help > eliminate the duplicate CPUID wrappers while continuing to > compile in older environments. > > Suggested-by: Shuah Khan > Signed-off-by: Reinette Chatre > --- > Note to maintainers: > - Macro is identical to the one provided by gcc, but not liked by > checkpatch.pl with message "Macros with complex values should > be enclosed in parentheses". Similar style is used in kernel, > for example in arch/x86/kernel/fpu/xstate.h. > > tools/testing/selftests/kselftest.h | 15 +++++++++++++++ > 1 file changed, 15 insertions(+) > > diff --git a/tools/testing/selftests/kselftest.h b/tools/testing/selftests/kselftest.h > index f1180987492c..898d7b2fac6c 100644 > --- a/tools/testing/selftests/kselftest.h > +++ b/tools/testing/selftests/kselftest.h > @@ -52,6 +52,21 @@ > + * have __cpuid_count(). > + */ > +#ifndef __cpuid_count > +#define __cpuid_count(level, count, a, b, c, d) \ > + __asm__ __volatile__ ("cpuid\n\t" \ > + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ > + : "0" (level), "2" (count)) > +#endif Linux C check tool "scripts/checkpatch.pl" shows an error: " ERROR: Macros with complex values should be enclosed in parentheses ... +#define __cpuid_count(level, count, a, b, c, d) \ + __asm__ __volatile__ ("cpuid\n\t" \ + : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ + : "0" (level), "2" (count)) " Googling: https://www.google.com/search?q=Macros+with+complex+values+should+be+enclosed+in+parentheses&rlz=1C1GCEB_enUS884US884&oq=Macros+with+complex+values+should+be+enclosed+in+parentheses&aqs=chrome.0.69i59j0i5i30l2.313j0j7&sourceid=chrome&ie=UTF-8 -> https://stackoverflow.com/questions/8142280/why-do-we-need-parentheses-around-block-macro Could we fix it as follow, shall we? " #ifndef __cpuid_count #define __cpuid_count(level, count, a, b, c, d) ({ \ __asm__ __volatile__ ("cpuid\n\t" \ : "=a" (a), "=b" (b), "=c" (c), "=d" (d) \ : "0" (level), "2" (count)) \ }) #endif " Thanks! --Pengfei