From: Frank Li <Frank.li@nxp.com>
To: Borislav Petkov <bp@alien8.de>
Cc: York Sun <york.sun@nxp.com>, Tony Luck <tony.luck@intel.com>,
James Morse <james.morse@arm.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Robert Richter <rric@kernel.org>,
Krzysztof Kozlowski <krzk@kernel.org>,
Rob Herring <robh@kernel.org>, Conor Dooley <conor+dt@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
Priyanka Singh <priyanka.singh@nxp.com>,
Sherry Sun <sherry.sun@nxp.com>, Li Yang <leoyang.li@nxp.com>
Subject: Re: [PATCH v2 3/6] EDAC/fsl_ddr: Fix bad bit shift operations
Date: Tue, 15 Oct 2024 11:31:41 -0400 [thread overview]
Message-ID: <Zw6K3dlsnlhV3F/6@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20241014181647.GQZw1gDwIhBdnFnleH@fat_crate.local>
On Mon, Oct 14, 2024 at 08:16:47PM +0200, Borislav Petkov wrote:
> On Fri, Oct 11, 2024 at 11:31:31AM -0400, Frank Li wrote:
> > From: Priyanka Singh <priyanka.singh@nxp.com>
> >
> > Fix undefined behavior caused by left-shifting a negative value in the
> > expression:
> >
> > cap_high ^ (1 << (bad_data_bit - 32))
> >
> > The variable `bad_data_bit` ranges from 0 to 63. When `bad_data_bit` is
> > less than 32, `bad_data_bit - 32` becomes negative, and left-shifting by a
> > negative value in C is undefined behavior.
> >
> > Fix this by checking the range of `bad_data_bit` before performing the
> > shift.
> >
> > Fixes: ea2eb9a8b620 ("EDAC, fsl-ddr: Separate FSL DDR driver from MPC85xx")
>
> Is this an urgent fix which needs to go to stable or someone just caught it
> from code review?
I don't think it is urgent. In most system the return value is 0. I am not
sure who caught it because patch already exist at downstream tree for a
whole.
>
> Does it trigger in real life, IOW?
The problem is triggered. But the output result is correct at our hardware.
The result may change depend on compiler and cpu version.
Frank
>
> > Signed-off-by: Priyanka Singh <priyanka.singh@nxp.com>
> > Reviewed-by: Sherry Sun <sherry.sun@nxp.com>
> > Signed-off-by: Li Yang <leoyang.li@nxp.com>
> > Signed-off-by: Frank Li <Frank.Li@nxp.com>
> > ---
> > drivers/edac/fsl_ddr_edac.c | 17 ++++++++++++-----
> > 1 file changed, 12 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/edac/fsl_ddr_edac.c b/drivers/edac/fsl_ddr_edac.c
> > index 7a9fb1202f1a0..ccc13c2adfd6f 100644
> > --- a/drivers/edac/fsl_ddr_edac.c
> > +++ b/drivers/edac/fsl_ddr_edac.c
> > @@ -338,11 +338,18 @@ static void fsl_mc_check(struct mem_ctl_info *mci)
> > fsl_mc_printk(mci, KERN_ERR,
> > "Faulty ECC bit: %d\n", bad_ecc_bit);
> >
> > - fsl_mc_printk(mci, KERN_ERR,
> > - "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
> > - cap_high ^ (1 << (bad_data_bit - 32)),
> > - cap_low ^ (1 << bad_data_bit),
> > - syndrome ^ (1 << bad_ecc_bit));
> > + if ((bad_data_bit > 0 && bad_data_bit < 32) && bad_ecc_bit > 0) {
> > + fsl_mc_printk(mci, KERN_ERR,
> > + "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
> > + cap_high, cap_low ^ (1 << bad_data_bit),
> > + syndrome ^ (1 << bad_ecc_bit));
> > + }
> > + if (bad_data_bit >= 32 && bad_ecc_bit > 0) {
> > + fsl_mc_printk(mci, KERN_ERR,
> > + "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n",
> > + cap_high ^ (1 << (bad_data_bit - 32)),
> > + cap_low, syndrome ^ (1 << bad_ecc_bit));
> > + }
>
> This is getting unnecessarily clumsy than it should be. Please do the
> following:
>
> if (bad_data_bit != 1 && bad_ecc_bit != -1) {
>
> // prep the values you need to print
>
> // do an exactly one fsl_mc_printk() with the prepared values.
>
> }
>
> Not have 4 fsl_mc_printks with a bunch of silly if-checks in front.
>
> Thx.
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2024-10-15 15:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-11 15:31 [PATCH v2 0/6] EDAC/fsl-ddr: Add imx9 support Frank Li
2024-10-11 15:31 ` [PATCH v2 1/6] EDAC/fsl_ddr: Pass down fsl_mc_pdata in ddr_in32() and ddr_out32() Frank Li
2024-10-11 15:31 ` [PATCH v2 2/6] EDAC/fsl_ddr: Move global variables into struct fsl_mc_pdata Frank Li
2024-10-11 15:31 ` [PATCH v2 3/6] EDAC/fsl_ddr: Fix bad bit shift operations Frank Li
2024-10-14 18:16 ` Borislav Petkov
2024-10-15 15:31 ` Frank Li [this message]
2024-10-15 16:11 ` Borislav Petkov
2024-10-15 18:55 ` Frank Li
2024-10-11 15:31 ` [PATCH v2 4/6] dt-bindings: memory: fsl: Add compatible string nxp,imx9-memory-controller Frank Li
2024-10-11 15:31 ` [PATCH v2 5/6] EDAC/fsl_ddr: Add support for i.MX9 DDR controller Frank Li
2024-10-15 14:52 ` Borislav Petkov
2024-10-15 15:19 ` Frank Li
2024-10-15 16:09 ` Borislav Petkov
2024-10-11 15:31 ` [PATCH v2 6/6] arm64: dts: imx93: add ddr edac support Frank Li
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=Zw6K3dlsnlhV3F/6@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=bp@alien8.de \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=james.morse@arm.com \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=krzk@kernel.org \
--cc=leoyang.li@nxp.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=priyanka.singh@nxp.com \
--cc=robh@kernel.org \
--cc=rric@kernel.org \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
--cc=sherry.sun@nxp.com \
--cc=tony.luck@intel.com \
--cc=york.sun@nxp.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