linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Reinette Chatre <reinette.chatre@intel.com>
To: Pengfei Xu <pengfei.xu@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: Mon, 18 Apr 2022 09:04:33 -0700	[thread overview]
Message-ID: <50067c2d-5563-7d8c-f992-5fef787d4d38@intel.com> (raw)
In-Reply-To: <Ylp1oFenjgxWpM0D@xpf.sh.intel.com>

Hi Pengfei,

On 4/16/2022 12:52 AM, Pengfei Xu wrote:
> 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

I encountered this also and that is why this patch contains the "Note to
maintainers" above. It is not clear to me whether you considered the note
since your response does not acknowledge it.

> ...
> +#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

More information available in
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html#Statement-Exprs
but from what I understand it does not apply to this macro. Even so, I do
not know what checkpatch.pl uses to determine that this is a "Macro with
complex values".

> 
> 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
> "

Sure, I can do so.

Reinette

  reply	other threads:[~2022-04-18 16:04 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
2022-04-18 16:04     ` Reinette Chatre [this message]
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=50067c2d-5563-7d8c-f992-5fef787d4d38@intel.com \
    --to=reinette.chatre@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=pengfei.xu@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).