Intel-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: intel-gfx@lists.freedesktop.org, Borislav Petkov <bp@suse.de>,
	Randy Dunlap <rdunlap@infradead.org>,
	Ruiqi GONG <gongruiqi1@huawei.com>
Subject: Re: [Intel-gfx] [PATCH 1/2] drm/i915/reg: fix undefined behavior due to shift overflowing the constant
Date: Wed, 18 May 2022 16:52:53 +0300	[thread overview]
Message-ID: <878rqzdk22.fsf@intel.com> (raw)
In-Reply-To: <YoTsVS5AaJfNe9hE@intel.com>

On Wed, 18 May 2022, Ville Syrjälä <ville.syrjala@linux.intel.com> wrote:
> On Wed, May 18, 2022 at 02:33:14PM +0300, Jani Nikula wrote:
>> Use REG_GENMASK() and REG_FIELD_PREP() to avoid errors due to
>> -fsanitize=shift.
>
> I presume it's just unhappy about shifting into the sign bit?

Yeah, and apparently it also only happens on some GCC versions. *shrug*.

>
> Changes look correct:
> Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>

Thanks,
Jani.

>
>> 
>> References: https://lore.kernel.org/r/20220405151517.29753-12-bp@alien8.de
>> Reported-by: Borislav Petkov <bp@suse.de>
>> Reported-by: Ruiqi GONG <gongruiqi1@huawei.com>
>> Cc: Randy Dunlap <rdunlap@infradead.org>
>> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
>> ---
>>  drivers/gpu/drm/i915/i915_reg.h | 32 ++++++++++++++++----------------
>>  1 file changed, 16 insertions(+), 16 deletions(-)
>> 
>> diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h
>> index 321a08281a3f..dff3f88d8090 100644
>> --- a/drivers/gpu/drm/i915/i915_reg.h
>> +++ b/drivers/gpu/drm/i915/i915_reg.h
>> @@ -7607,25 +7607,25 @@ enum skl_power_gate {
>>  #define _PORT_CLK_SEL_A			0x46100
>>  #define _PORT_CLK_SEL_B			0x46104
>>  #define PORT_CLK_SEL(port) _MMIO_PORT(port, _PORT_CLK_SEL_A, _PORT_CLK_SEL_B)
>> -#define  PORT_CLK_SEL_LCPLL_2700	(0 << 29)
>> -#define  PORT_CLK_SEL_LCPLL_1350	(1 << 29)
>> -#define  PORT_CLK_SEL_LCPLL_810		(2 << 29)
>> -#define  PORT_CLK_SEL_SPLL		(3 << 29)
>> -#define  PORT_CLK_SEL_WRPLL(pll)	(((pll) + 4) << 29)
>> -#define  PORT_CLK_SEL_WRPLL1		(4 << 29)
>> -#define  PORT_CLK_SEL_WRPLL2		(5 << 29)
>> -#define  PORT_CLK_SEL_NONE		(7 << 29)
>> -#define  PORT_CLK_SEL_MASK		(7 << 29)
>> +#define  PORT_CLK_SEL_MASK		REG_GENMASK(31, 29)
>> +#define  PORT_CLK_SEL_LCPLL_2700	REG_FIELD_PREP(PORT_CLK_SEL_MASK, 0)
>> +#define  PORT_CLK_SEL_LCPLL_1350	REG_FIELD_PREP(PORT_CLK_SEL_MASK, 1)
>> +#define  PORT_CLK_SEL_LCPLL_810		REG_FIELD_PREP(PORT_CLK_SEL_MASK, 2)
>> +#define  PORT_CLK_SEL_SPLL		REG_FIELD_PREP(PORT_CLK_SEL_MASK, 3)
>> +#define  PORT_CLK_SEL_WRPLL(pll)	REG_FIELD_PREP(PORT_CLK_SEL_MASK, 4 + (pll))
>> +#define  PORT_CLK_SEL_WRPLL1		REG_FIELD_PREP(PORT_CLK_SEL_MASK, 4)
>> +#define  PORT_CLK_SEL_WRPLL2		REG_FIELD_PREP(PORT_CLK_SEL_MASK, 5)
>> +#define  PORT_CLK_SEL_NONE		REG_FIELD_PREP(PORT_CLK_SEL_MASK, 7)
>>  
>>  /* On ICL+ this is the same as PORT_CLK_SEL, but all bits change. */
>>  #define DDI_CLK_SEL(port)		PORT_CLK_SEL(port)
>> -#define  DDI_CLK_SEL_NONE		(0x0 << 28)
>> -#define  DDI_CLK_SEL_MG			(0x8 << 28)
>> -#define  DDI_CLK_SEL_TBT_162		(0xC << 28)
>> -#define  DDI_CLK_SEL_TBT_270		(0xD << 28)
>> -#define  DDI_CLK_SEL_TBT_540		(0xE << 28)
>> -#define  DDI_CLK_SEL_TBT_810		(0xF << 28)
>> -#define  DDI_CLK_SEL_MASK		(0xF << 28)
>> +#define  DDI_CLK_SEL_MASK		REG_GENMASK(31, 28)
>> +#define  DDI_CLK_SEL_NONE		REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0x0)
>> +#define  DDI_CLK_SEL_MG			REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0x8)
>> +#define  DDI_CLK_SEL_TBT_162		REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0xC)
>> +#define  DDI_CLK_SEL_TBT_270		REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0xD)
>> +#define  DDI_CLK_SEL_TBT_540		REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0xE)
>> +#define  DDI_CLK_SEL_TBT_810		REG_FIELD_PREP(DDI_CLK_SEL_MASK, 0xF)
>>  
>>  /* Transcoder clock selection */
>>  #define _TRANS_CLK_SEL_A		0x46140
>> -- 
>> 2.30.2

-- 
Jani Nikula, Intel Open Source Graphics Center

  reply	other threads:[~2022-05-18 13:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-18 11:33 [Intel-gfx] [PATCH 1/2] drm/i915/reg: fix undefined behavior due to shift overflowing the constant Jani Nikula
2022-05-18 11:33 ` [Intel-gfx] [PATCH 2/2] drm/i915/uc: Fix " Jani Nikula
2022-05-18 14:08   ` Michal Wajdeczko
2022-05-18 14:15     ` Jani Nikula
2022-05-19  8:38       ` Jani Nikula
2022-05-18 12:53 ` [Intel-gfx] [PATCH 1/2] drm/i915/reg: fix " Ville Syrjälä
2022-05-18 13:52   ` Jani Nikula [this message]
2022-05-19  8:25     ` Jani Nikula
2022-05-18 13:59 ` [Intel-gfx] ✗ Fi.CI.SPARSE: warning for series starting with [1/2] " Patchwork
2022-05-18 14:23 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2022-05-18 17:10 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork

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=878rqzdk22.fsf@intel.com \
    --to=jani.nikula@intel.com \
    --cc=bp@suse.de \
    --cc=gongruiqi1@huawei.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=rdunlap@infradead.org \
    --cc=ville.syrjala@linux.intel.com \
    /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