linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: kajoljain <kjain@linux.ibm.com>
To: Michael Ellerman <mpe@ellerman.id.au>,
	David Binderman <dcb314@hotmail.com>,
	"npiggin@gmail.com" <npiggin@gmail.com>,
	"christophe.leroy@csgroup.eu" <christophe.leroy@csgroup.eu>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-kselftest@vger.kernel.org"
	<linux-kselftest@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Possible bug in linux-6.2/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c
Date: Tue, 28 Feb 2023 15:36:09 +0530	[thread overview]
Message-ID: <d989254a-a3c4-615e-59cb-96667d0a63b3@linux.ibm.com> (raw)
In-Reply-To: <87ttz7vfva.fsf@mpe.ellerman.id.au>



On 2/27/23 10:56, Michael Ellerman wrote:
> David Binderman <dcb314@hotmail.com> writes:
>> Hello there,
>>
>> I ran the static analyser cppcheck over the linux-6.2 source code and got this:
>>
>> linux-6.2/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c:68:10: style: Same expression '0x3' found multiple times in chain of '&' operators. [duplicateExpression]

Hi,
  Thanks David for reporting it.

> 
> Thanks.
> 
>> Source code is
>>
>>     FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample & 0x3) !=
>>             get_mmcra_sample_mode(get_reg_value(intr_regs, "MMCRA"), 4));
>>
>> but
>>
>> #define EV_CODE_EXTRACT(x, y)   \
>>     ((x >> ev_shift_##y) & ev_mask_##y)
>>
>>
>> Given the token pasting, I very much doubt an expression like "sample & 0x3"
>> will work correctly. Same thing on the line above 
>>
>>     FAIL_IF(EV_CODE_EXTRACT(event.attr.config, sample >> 2) !=
>>             get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4));
>>
>> "sample >> 2" doesn't look like a valid token to me.
> 
> It expands to:
> 
>  if ((((event.attr.config >> ev_shift_sample >> 2) & ev_mask_sample >> 2) != get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4))) 
> 
> Which AFAICS is valid, and does compile.
> 
> Whether it's what the author actually intended is less clear.
> 
> And the other example with & 0x3 seems obviously wrong, it expands to:
> 
>   if ((((event.attr.config >> ev_shift_sample & 0x3) & ev_mask_sample & 0x3) != get_mmcra_sample_mode(get_reg_value(intr_regs, "MMCRA"), 4)))
> 
> The shift is 24, so bitwise anding it with 0x3 gets 0 which doesn't seem
> likely to be what was intended.
> 

Hi Michael,
   Thanks for checking it. The intention is to check 3 bits of
rand_samp_elig field and 2 bits of rand_samp_mode field from the
sampling bits. Basically we first want to extract that sample field
using EV_CODE_EXTRACT macro and then fetch required value of
rand_samp_elig and rand_samp_mode, to compare it with MMCRA bits.

Right approach to do that would be:

 FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) >> 2) !=
get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4));

 FAIL_IF((EV_CODE_EXTRACT(event.attr.config, sample) & 0x3) !=
get_mmcra_rand_samp_elig(get_reg_value(intr_regs, "MMCRA"), 4));

I will send a fix patch for same.

Thanks,
Kajol Jain

> cheers

      reply	other threads:[~2023-02-28 10:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-24 14:32 Possible bug in linux-6.2/tools/testing/selftests/powerpc/pmu/sampling_tests/mmcra_thresh_marked_sample_test.c David Binderman
2023-02-27  5:26 ` Michael Ellerman
2023-02-28 10:06   ` kajoljain [this message]

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=d989254a-a3c4-615e-59cb-96667d0a63b3@linux.ibm.com \
    --to=kjain@linux.ibm.com \
    --cc=christophe.leroy@csgroup.eu \
    --cc=dcb314@hotmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=shuah@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).