From: Pengfei Xu <pengfei.xu@intel.com>
To: Reinette Chatre <reinette.chatre@intel.com>
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()
Date: Sat, 16 Apr 2022 15:52:00 +0800 [thread overview]
Message-ID: <Ylp1oFenjgxWpM0D@xpf.sh.intel.com> (raw)
In-Reply-To: <7c49dbfe5bab04389ed84c516fcbfe31d66df880.1647360971.git.reinette.chatre@intel.com>
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 <skhan@linuxfoundation.org>
> Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
> 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
next prev parent reply other threads:[~2022-04-16 7:53 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-15 16:44 [PATCH V2 0/4] selftests: Remove duplicate CPUID wrappers Reinette Chatre
2022-03-15 16:44 ` [PATCH V2 1/4] selftests: Provide local define of __cpuid_count() Reinette Chatre
2022-04-16 7:52 ` Pengfei Xu [this message]
2022-04-18 16:04 ` Reinette Chatre
2022-04-19 4:31 ` Pengfei Xu
2022-04-19 22:34 ` Reinette Chatre
2022-04-20 7:22 ` Pengfei Xu
2022-03-15 16:44 ` [PATCH V2 2/4] selftests/vm/pkeys: Use provided __cpuid_count() macro Reinette Chatre
2022-03-15 16:44 ` [PATCH V2 3/4] selftests/x86/amx: " Reinette Chatre
2022-03-15 16:44 ` [PATCH V2 4/4] selftests/x86/corrupt_xstate_header: " Reinette Chatre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ylp1oFenjgxWpM0D@xpf.sh.intel.com \
--to=pengfei.xu@intel.com \
--cc=bauerman@linux.ibm.com \
--cc=bp@suse.de \
--cc=chang.seok.bae@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=desnesn@linux.vnet.ibm.com \
--cc=fweimer@redhat.com \
--cc=heng.su@intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=msuchanek@suse.de \
--cc=reinette.chatre@intel.com \
--cc=sandipan@linux.ibm.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).