From: <Conor.Dooley@microchip.com>
To: <Claudiu.Beznea@microchip.com>, <mturquette@baylibre.com>,
<sboyd@kernel.org>, <robh+dt@kernel.org>,
<krzysztof.kozlowski+dt@linaro.org>, <palmer@dabbelt.com>,
<Daire.McNamara@microchip.com>
Cc: <paul.walmsley@sifive.com>, <aou@eecs.berkeley.edu>,
<linux-clk@vger.kernel.org>, <devicetree@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-riscv@lists.infradead.org>,
<nathan@kernel.org>
Subject: Re: [PATCH v4 01/13] clk: microchip: mpfs: fix clk_cfg array bounds violation
Date: Fri, 9 Sep 2022 11:01:57 +0000 [thread overview]
Message-ID: <c2974113-83de-85db-106e-7e3e5437b14d@microchip.com> (raw)
In-Reply-To: <9ffd5028-6639-9c3c-e09b-c9b7602a2ec1@microchip.com>
On 08/09/2022 07:48, Conor Dooley wrote:
> On 08/09/2022 07:44, Claudiu Beznea - M18063 wrote:
>> On 30.08.2022 15:52, Conor Dooley wrote:
>>> Unnoticed in current code, there is an array bounds violation present
>>> during clock registration. This seems to fail gracefully in v6.0-rc1,
>>> and life carrys on. While converting the driver to use standard clock
>>> structs/ops, kernel panics were seen during boot when built with clang:
>>>
>>> [ 0.581754] Unable to handle kernel NULL pointer dereference at virtual address 00000000000000b1
>>> [ 0.591520] Oops [#1]
>>> [ 0.594045] Modules linked in:
>>> [ 0.597435] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.0.0-rc1-00011-g8e1459cf4eca #1
>>> [ 0.606188] Hardware name: Microchip PolarFire-SoC Icicle Kit (DT)
>>> [ 0.613012] epc : __clk_register+0x4a6/0x85c
>>> [ 0.617759] ra : __clk_register+0x49e/0x85c
>>> [ 0.622489] epc : ffffffff803faf7c ra : ffffffff803faf74 sp : ffffffc80400b720
>>> [ 0.630466] gp : ffffffff810e93f8 tp : ffffffe77fe60000 t0 : ffffffe77ffb3800
>>> [ 0.638443] t1 : 000000000000000a t2 : ffffffffffffffff s0 : ffffffc80400b7c0
>>> [ 0.646420] s1 : 0000000000000001 a0 : 0000000000000001 a1 : 0000000000000000
>>> [ 0.654396] a2 : 0000000000000001 a3 : 0000000000000000 a4 : 0000000000000000
>>> [ 0.662373] a5 : ffffffff803a5810 a6 : 0000000200000022 a7 : 0000000000000006
>>> [ 0.670350] s2 : ffffffff81099d48 s3 : ffffffff80d6e28e s4 : 0000000000000028
>>> [ 0.678327] s5 : ffffffff810ed3c8 s6 : ffffffff810ed3d0 s7 : ffffffe77ffbc100
>>> [ 0.686304] s8 : ffffffe77ffb1540 s9 : ffffffe77ffb1540 s10: 0000000000000008
>>> [ 0.694281] s11: 0000000000000000 t3 : 00000000000000c6 t4 : 0000000000000007
>>> [ 0.702258] t5 : ffffffff810c78c0 t6 : ffffffe77ff88cd0
>>> [ 0.708125] status: 0000000200000120 badaddr: 00000000000000b1 cause: 000000000000000d
>>> [ 0.716869] [<ffffffff803fb892>] devm_clk_hw_register+0x62/0xaa
>>> [ 0.723420] [<ffffffff80403412>] mpfs_clk_probe+0x1e0/0x244
>>>
>>> It fails on "clk_periph_timer" - which uses a different parent, that it
>>> tries to find using the macro:
>>> \#define PARENT_CLK(PARENT) (&mpfs_cfg_clks[CLK_##PARENT].cfg.hw)
>>>
>>> If parent is RTCREF, so the macro becomes: &mpfs_cfg_clks[33].cfg.hw
>>> which is well beyond the end of the array. Amazingly, builds with GCC
>>> 11.1 see no problem here, booting correctly and hooking the parent up
>>> etc. Builds with clang-15 do not, with the above panic.
>>>
>>> Drop the macro for the RTCREF and use the array directly to avoid the
>>> panic, using a newly added define that brings the index into the valid
>>> range.
>>>
>>> Fixes: 1c6a7ea32b8c ("clk: microchip: mpfs: add RTCREF clock control")
>>> CC: Nathan Chancellor <nathan@kernel.org>
>>> Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
>>> ---
>>> drivers/clk/microchip/clk-mpfs.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/clk/microchip/clk-mpfs.c b/drivers/clk/microchip/clk-mpfs.c
>>> index 070c3b896559..9e41f07b3fa6 100644
>>> --- a/drivers/clk/microchip/clk-mpfs.c
>>> +++ b/drivers/clk/microchip/clk-mpfs.c
>>> @@ -27,6 +27,8 @@
>>> #define MSSPLL_POSTDIV_WIDTH 0x07u
>>> #define MSSPLL_FIXED_DIV 4u
>>> +#define RTCREF_OFFSET (CLK_RTCREF - CLK_ENVM)
>>> +
>>> struct mpfs_clock_data {
>>> void __iomem *base;
>>> void __iomem *msspll_base;
>>> @@ -381,7 +383,8 @@ static struct mpfs_periph_hw_clock mpfs_periph_clks[] = {
>>> CLK_PERIPH(CLK_MAC0, "clk_periph_mac0", PARENT_CLK(AHB), 1, 0),
>>> CLK_PERIPH(CLK_MAC1, "clk_periph_mac1", PARENT_CLK(AHB), 2, 0),
>>> CLK_PERIPH(CLK_MMC, "clk_periph_mmc", PARENT_CLK(AHB), 3, 0),
>>> - CLK_PERIPH(CLK_TIMER, "clk_periph_timer", PARENT_CLK(RTCREF), 4, 0),
>>> + CLK_PERIPH(CLK_TIMER, "clk_periph_timer",
>>> + &mpfs_cfg_clks[CLK_RTCREF - RTCREF_OFFSET].hw, 4, 0),
>>
>> A personal taste: as clk IDs and clk indexes in mpfs_cfg_clks[] array are
>> different thing (ID for clk_periph_timer is already different) and the
>> CLK_RTCREF - RTCREF_OFFSET here is in the end CLK_ENVM = 3 maybe easier to
>> follow the code would be to add new macros like:
>>
>> #define CLK_CPU_OFF 0
>> #define CLK_AXI_OFF 1
>> #define CLK_AHB_OFF 2
>> #define CLK_RTCREF_OFF 3
>>
>> and change the CLK_PARENT() macro something as follows:
>>
>> #define PARENT_CLK(PARENT) (&mpfs_cfg_clks[CLK_##PARENT##_OFF].hw)
>
> Sure, but that is out-of-scope for this fix which needs backporting.
I think I mis-interpreted your suggestion. Gonna give it a go & unless
clang screams and yells at me I think I like it more than relying on
the relationships between the binding numbers.
Thanks,
Conor.
next prev parent reply other threads:[~2022-09-09 11:02 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 12:50 [PATCH v4 00/13] PolarFire SoC reset controller & clock cleanups Conor Dooley
2022-08-30 12:52 ` [PATCH v4 01/13] clk: microchip: mpfs: fix clk_cfg array bounds violation Conor Dooley
2022-08-31 17:03 ` Conor.Dooley
2022-09-08 6:44 ` Claudiu.Beznea
2022-09-08 6:48 ` Conor.Dooley
2022-09-09 11:01 ` Conor.Dooley [this message]
2022-08-30 12:52 ` [PATCH v4 02/13] dt-bindings: clk: microchip: mpfs: add reset controller support Conor Dooley
2022-08-30 12:52 ` [PATCH v4 03/13] clk: microchip: mpfs: add reset controller Conor Dooley
2022-09-08 6:45 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 04/13] reset: add polarfire soc reset support Conor Dooley
2022-09-08 6:44 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 05/13] MAINTAINERS: add polarfire soc reset controller Conor Dooley
2022-08-30 12:52 ` [PATCH v4 06/13] riscv: dts: microchip: add mpfs specific macb reset support Conor Dooley
2022-08-30 12:52 ` [PATCH v4 07/13] clk: microchip: mpfs: add MSS pll's set & round rate Conor Dooley
2022-09-08 6:46 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 08/13] clk: microchip: mpfs: move id & offset out of clock structs Conor Dooley
2022-09-08 6:46 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 09/13] clk: microchip: mpfs: simplify control reg access Conor Dooley
2022-09-08 6:46 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 10/13] clk: microchip: mpfs: delete 2 line mpfs_clk_register_foo() Conor Dooley
2022-09-08 6:47 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 11/13] clk: microchip: mpfs: convert cfg_clk to clk_divider Conor Dooley
2022-09-08 6:47 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 12/13] clk: microchip: mpfs: convert periph_clk to clk_gate Conor Dooley
2022-09-08 6:47 ` Claudiu.Beznea
2022-08-30 12:52 ` [PATCH v4 13/13] clk: microchip: mpfs: update module authorship & licencing Conor Dooley
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=c2974113-83de-85db-106e-7e3e5437b14d@microchip.com \
--to=conor.dooley@microchip.com \
--cc=Claudiu.Beznea@microchip.com \
--cc=Daire.McNamara@microchip.com \
--cc=aou@eecs.berkeley.edu \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mturquette@baylibre.com \
--cc=nathan@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=robh+dt@kernel.org \
--cc=sboyd@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).