source
large_stringclasses
2 values
subject
large_stringclasses
112 values
code
large_stringclasses
112 values
critique
large_stringlengths
61
3.04M
metadata
dict
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
All the MFGPLL require MFG_EB to be on for any operation on them, and they only tick when MFG_EB is on as well, therefore making this a parent-child relationship. This dependency wasn't clear during the initial upstreaming of these clock controllers, as it only made itself known when I could observe the effects of the clock by bringing up a different piece of hardware. Add a new PLL_PARENT_EN flag to mediatek's clk-pll.h, and check for it when initialising the pll to then translate it into the actual CLK_OPS_PARENT_ENABLE flag. Then add the mfg_eb parent to the mfgpll clocks, and set the new PLL_PARENT_EN flag. Fixes: 03dc02f8c7dc ("clk: mediatek: Add MT8196 mfg clock support") Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- drivers/clk/mediatek/clk-mt8196-mfg.c | 13 +++++++------ drivers/clk/mediatek/clk-pll.c | 3 +++ drivers/clk/mediatek/clk-pll.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/clk/mediatek/clk-mt8196-mfg.c b/drivers/clk/mediatek/clk-mt8196-mfg.c index 8e09c0f7b7548f8e286671cea2dac64530b8ce47..a317183f1681bc6e8167c44b2bbe4a78566ba639 100644 --- a/drivers/clk/mediatek/clk-mt8196-mfg.c +++ b/drivers/clk/mediatek/clk-mt8196-mfg.c @@ -58,24 +58,25 @@ .pcw_shift = _pcw_shift, \ .pcwbits = _pcwbits, \ .pcwibits = MT8196_INTEGER_BITS, \ + .parent_name = "mfg_eb", \ } static const struct mtk_pll_data mfg_ao_plls[] = { - PLL(CLK_MFG_AO_MFGPLL, "mfgpll", MFGPLL_CON0, MFGPLL_CON0, 0, 0, 0, - BIT(0), MFGPLL_CON1, 24, 0, 0, 0, + PLL(CLK_MFG_AO_MFGPLL, "mfgpll", MFGPLL_CON0, MFGPLL_CON0, 0, 0, + PLL_PARENT_EN, BIT(0), MFGPLL_CON1, 24, 0, 0, 0, MFGPLL_CON1, 0, 22), }; static const struct mtk_pll_data mfgsc0_ao_plls[] = { PLL(CLK_MFGSC0_AO_MFGPLL_SC0, "mfgpll-sc0", MFGPLL_SC0_CON0, - MFGPLL_SC0_CON0, 0, 0, 0, BIT(0), MFGPLL_SC0_CON1, 24, 0, 0, 0, - MFGPLL_SC0_CON1, 0, 22), + MFGPLL_SC0_CON0, 0, 0, PLL_PARENT_EN, BIT(0), MFGPLL_SC0_CON1, 24, + 0, 0, 0, MFGPLL_SC0_CON1, 0, 22), }; static const struct mtk_pll_data mfgsc1_ao_plls[] = { PLL(CLK_MFGSC1_AO_MFGPLL_SC1, "mfgpll-sc1", MFGPLL_SC1_CON0, - MFGPLL_SC1_CON0, 0, 0, 0, BIT(0), MFGPLL_SC1_CON1, 24, 0, 0, 0, - MFGPLL_SC1_CON1, 0, 22), + MFGPLL_SC1_CON0, 0, 0, PLL_PARENT_EN, BIT(0), MFGPLL_SC1_CON1, 24, + 0, 0, 0, MFGPLL_SC1_CON1, 0, 22), }; static const struct of_device_id of_match_clk_mt8196_mfg[] = { diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c index c4f9c06e5133dbc5902f261353c197fbde95e54d..0f3759fcd9d0228c23f4916d041d17b731a6c838 100644 --- a/drivers/clk/mediatek/clk-pll.c +++ b/drivers/clk/mediatek/clk-pll.c @@ -359,6 +359,9 @@ struct clk_hw *mtk_clk_register_pll_ops(struct mtk_clk_pll *pll, init.name = data->name; init.flags = (data->flags & PLL_AO) ? CLK_IS_CRITICAL : 0; + if (data->flags & PLL_PARENT_EN) + init.flags |= CLK_OPS_PARENT_ENABLE; + init.ops = pll_ops; if (data->parent_name) init.parent_names = &data->parent_name; diff --git a/drivers/clk/mediatek/clk-pll.h b/drivers/clk/mediatek/clk-pll.h index f6493699c4e367b45038ceede9565ae42a030b47..f49dc2732ffee50ebf023c01b513d74989a6ec7b 100644 --- a/drivers/clk/mediatek/clk-pll.h +++ b/drivers/clk/mediatek/clk-pll.h @@ -19,6 +19,7 @@ struct mtk_pll_div_table { #define HAVE_RST_BAR BIT(0) #define PLL_AO BIT(1) +#define PLL_PARENT_EN BIT(2) #define POSTDIV_MASK GENMASK(2, 0) struct mtk_pll_data { -- 2.51.0
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Fri, 10 Oct 2025 22:47:13 +0200", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Hi Nicolas, On Fri, Oct 10, 2025 at 10:47:09PM +0200, Nicolas Frattaroli wrote: clk_change_rate() has the following code: if (core->flags & CLK_OPS_PARENT_ENABLE) clk_core_prepare_enable(parent); ... core->rate = clk_recalc(core, best_parent_rate); ... if (core->flags & CLK_OPS_PARENT_ENABLE) clk_core_disable_unprepare(parent); clk_change_rate() ultimately is called by various clk_set_rate functions. Will that be a problem for the double calls to clk_core_prepare_enable()? Fanning this out to the edge further is going to make the code even more complicated. What do you think about moving this to clk_core_enable_lock()? I know the set_parent operation has a special case that would need to be worked around. Brian
{ "author": "Brian Masney <bmasney@redhat.com>", "date": "Thu, 16 Oct 2025 16:52:30 -0400", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Thursday, 16 October 2025 22:52:30 Central European Summer Time Brian Masney wrote: I don't see how multiple prepares are a problem as long as they're balanced. __clk_core_init also needs special code in that case, as it calls the bare recalc_rate op with no clk_core_enable_lock beforehand. It's also wrong, in that recalc_rate does not necessitate the clock being on as far as I'm aware. (if it did, this wouldn't be a problem in the first place, as enabling it would enable the parent as well). Changing the semantics of clk_recalc, and therefore clk_get_rate, to also enable the clock, would be a major change in how the common clock framework functions. In my case, the __clk_core_init callback was the one that crashed, so it really needs to happen there, and I really don't want to refactor every location where `CLK_OPS_PARENT_ENABLE` is used for a bugfix just to avoid potentially checking the same flag twice. Having `CLK_OPS_PARENT_ENABLE` cleaned up such that every clk op that has potential register access is never directly called by the clk core except for one place, an accessor function that does both pmdomain and `CLK_OPS_PARENT_ENABLE` checks, would be nice, e.g. by keeping the clk_recalc change and then having __clk_core_init call clk_recalc instead of the recalc op directly. But then the __clk_core_init logic needs further refactoring as well. I'm not sure I want to do that in this series, because it's quite a bit different from just adding the missing check and parent toggling, and has the chance of me introducing subtle logic bugs in what is supposed to be a bugfix. Kind regards, Nicolas Frattaroli
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Fri, 17 Oct 2025 14:21:55 +0200", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Hi Nicolas, On Fri, Oct 17, 2025 at 02:21:55PM +0200, Nicolas Frattaroli wrote: I agree and that makes sense. Thanks for the explanation. What you have is a good compromise. Reviewed-by: Brian Masney <bmasney@redhat.com>
{ "author": "Brian Masney <bmasney@redhat.com>", "date": "Mon, 20 Oct 2025 15:36:41 -0400", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Fri, Oct 10, 2025 at 10:47:09PM +0200, Nicolas Frattaroli wrote: I'm seeing boot regressions in -next on the Avenger96 which bisect to this patch in -next. The board resets during startup: [ 0.297034] /soc/display-controller@5a001000: Fixed dependency cycle(s) with /soc/bus@5c007000/i2c@5c002000/hdmi-transmitter@3d [ 0.307482] /soc/bus@5c007000/sai@4400b000/audio-controller@4400b004: Fixed dependency cycle(s) with /soc/bus@5c007000/i2c@5c002000/hdmi-transmitter@3d [ 0.321193] /soc/bus@5c007000/i2c@5c002000/hdmi-transmitter@3d: Fixed dependency cycle(s) with /soc/bus@5c007000/sai@4400b000/audio-controller@4400b004 [ 0.334454] /soc/bus@5c007000/i2c@5c002000/hdmi-transmitter@3d: Fixed dependency cycle(s) with /soc/display-controller@5a001000 U-Boot SPL 2023.07.02-dh-stm32mp1-dhcor-avenger96-20230727.02 (Jul 11 2023 - 15:20:44 +0000) Model: Arrow Electronics STM32MP15xx Avenger96 board https://lava.sirena.org.uk/scheduler/job/2409783 bisect log: # bad: [615aad0f61e0c7a898184a394dc895c610100d4f] Add linux-next specific files for 20260126 # good: [50814c5ce8d8f6751fd49c818abeb8853f8be2df] Merge branch 'for-linux-next-fixes' of https://gitlab.freedesktop.org/drm/misc/kernel.git # good: [702ce71d32f2c30b4f45b7c6b701d87583c58df8] ASoC: SDCA: Add NO_DIRECT_COMPLETE flag to class driver # good: [d0ab89951197f0fc509a0cd732d830880e79c2d4] ASoC: cs35l56: Add KUnit testing of cs35l56_set_fw_suffix() # good: [7f428282fde34f06f3ab898b8a9081bf93a41f22] ALSA: hda: controllers: intel: add support for Nova Lake # good: [cafadbf430f4b2f3ca4158de48ef6ba4d97fbf17] ASoC: renesas: rz-ssi: Drop goto label # good: [00ca2dd431fa2acb07b3ecc6ce49fb9a0a4d72cb] ASoC: SOF: Intel: hda: Remove MODULE_SOFTDEP for snd-hda-codec-hdmi # good: [3495a5df94a9ad7a8940bcb3ebfda58255f5b952] spi: dt-bindings: nxp,imx94-xspi: add nxp,imx952-xspi # good: [a18467a50eddbd7c6548b53b25b68e5454ceb587] ASoC: realtek: fix misspelling of "minimum" in comments # good: [c3608162a95a259c669cf9fdccf900782fa8d902] spi: xilinx: make irq optional # good: [3c5ddd56aa93048314c64533c21e731a44b0f067] ASoC: codecs: es8323: Enable proper DAPM widgets for chip power # good: [20c4701b75a3d6ce09d61e17125aefe77e7eb333] dt-bindings: regulator: mark regulator-suspend-microvolt as deprecated # good: [37fbc1ab0f225d23f0839260a11375b4f1f7cf8c] spi: Drop duplicate device_set_node() call # good: [83ba6efa711fad83a0fbf02178ad64d3906d8d09] spi: rockchip: Use plain request_irq() # good: [4fbd3b2ec04dc6ef93090ec24733a5c5671fb71f] ASoC: soc-acpi-intel-ptl-match: use aggregated endpoint in ptl_rt722_l0_rt1320_l23 # good: [7a3d1b04d938f31e112fe09c0ffc1af830ba1f6d] ASoC: SDCA: Handle CONFIG_PM_SLEEP not being set # good: [dccc66b0e92d48d9a1908a3ccb8142e0ee3381f5] regmap: Enable REGMAP when REGMAP_SLIMBUS is enabled # good: [61d2a7699ab39d448f44919ef15c16187e6f70ec] ASoC: SDCA: Tidy up some memory allocations # good: [519d0a6b2ca5a891340b6c24a4c40545f518e1a8] ASoC: codecs: aw88261: use dvdd-supply regulator # good: [da7afdc79cba00f952df12cd579e44832d829c0a] ASoC: SDCA: Add lock to serialise the Function initialisation # good: [8a98e7f55f975360975083166e21982ef307b8fd] ASoC: tlv320adcx140: add channel sum control # good: [10303b32519f52a5afd40593a507543143c8ec6a] dt-bindings: sound: google,goldfish-audio: Convert to DT schema # good: [62b04225e99a5d1c71c5c73d2aa6618bc2c0738f] regulator: dt-bindings: rpi-panel: Mark 7" Raspberry Pi as GPIO controller # good: [de9f1b1583aecb246b659effb03f2456604fab64] regulator: dt-bindings: mediatek,mt6331: Add missing ldo-vio28 vreg # good: [a014c203b54d9013ad52ad8a531cf46e71028f2b] spi: fsi: Simplify with scoped for each OF child loop # good: [e7c30ac379b429d439eb62ae1bb69720a6701e26] ASoC: amd: acp: soc-acpi: add is_device_rt712_vb() helper # good: [09dc08b396c954820f119e1ab0c7d72333c18323] regulator: dummy, make dummy_regulator_driver static # good: [6be9ea62afedef0f976eb3dba4c117be0c1d3809] ASoC: codecs: rtq9128: Add compatible changes for rtq9154 # good: [e590752119029d87ce46d725e11245a52d22e1fe] ASoC: wm8962: Don't report a microphone if it's shorted to ground on plug # good: [77157cb45c66bd652a08a360693fcced558c5ef9] ASoC: codecs: rt1320-sdw: convert to snd_soc_dapm_xxx() # good: [b0fc1e7701940d12ea2c41f386aa552bc4cc3629] regulator: Add TPS65185 driver # good: [8618271887ca10ac5108fe7e1d82ba8f1b152cf9] spi: spi-mem: Limit octal DTR constraints to octal DTR situations # good: [8672e4b51adfc57150f3862b1665faff0acf1bad] spi: dt-bindings: nxp,lpc3220-spi: Add DMA specific properties # good: [fc6ceb7e4ea746e663ff8c5593e67ad8ccbee34a] ASoC: sof ipc4: Add sof_ipc4_widget_setup_msg_payload() and call it # good: [83aee46dc2142eed2dc40b5cef0e9e08e14cac42] ASoC: SOF: ipc/ops: Use guard() for spinlocks # good: [8d38423d9dea7353a8a54a3ab2e0d0aa04ed34d0] regulator: core: don't fail regulator_register() with missing required supply # good: [b9198ce5c6dfee19b9662dda95ba559af9cdf53f] ASoC: codecs: aw88261: Add devicetree support # good: [db4371d13f82fb12463fe053f4864980a2af2106] MAINTAINERS: Add entries for the Axiado SPI DB controller # good: [b6376dbed8e173f9571583b5d358b08ff394e864] spi: Simplify devm_spi_*_controller() # good: [0cd9bf6a6d9a1861087236cc5c275b3bea83cfdd] ASoC: codecs: da7213: Move comma operator at the end of the line # good: [22a4776a9ce50aa47f602d28f53ba9d613a38f49] ASoC: codecs: es8375: remove unnecessary format check # good: [75d208bddcca55ec31481420fbb4d6c9703ba195] spi: stm32: avoid __maybe_unused and use pm_ptr # good: [04b61513dfe40f80f0dcc795003637b510522b3c] ASoC: SDCA: Replace use of system_wq with system_dfl_wq # good: [9bf0bd7bdea6c402007ffb784dd0c0f704aa2310] ASoC: nau8821: Sort #include directives # good: [96d337436fe0921177a6090aeb5bb214753654fc] spi: dt-bindings: at91: add microchip,lan9691-spi # good: [52ddc0106c77ff0eacf07b309833ae6e6a4e8587] ASoC: es8328: Remove duplicate DAPM routes # good: [211243b69533e968cc6f0259fb80ffee02fbe0ca] firmware: cs_dsp: test_bin: Add tests for offsets > 0xffff # good: [420739112e95c9bb286b4e87875706925970abd3] ASoC: rt5575: Add the codec driver for the ALC5575 # good: [4c5e6d5b31bc623d89185d551681ab91cfd037c9] ASoC: codecs: ES8389: Update clock configuration # good: [25abdc151a448a17d500ea9468ce32582c479faa] ASoC: rt1320: fix the remainder calculation of r0 value # good: [284853affe73fe1ca9786bd52b934eb9d420a942] ASoC: rt1320: fix size_t format string # good: [45e9066f3a487e9e26b842644364d045af054775] ASoC: Intel: avs: replace strcmp with sysfs_streq # good: [0f698d742f628d02ab2a222f8cf5f793443865d0] spi: bcm63xx-hsspi: add support for 1-2-2 read ops # good: [b0655377aa5a410df02d89170c20141a1a5bbc28] rust: regulator: replace `kernel::c_str!` with C-Strings # good: [8db50f0fa43efe8799fd40b872dcdd39a90d7549] ASoC: rt1320: fix the warning the string may be truncated # good: [99a3ef1e81cd1775bc1f8cc2ad188b1fc755d5cd] ASoC: SDCA: Add ASoC jack hookup in class driver # good: [4ab48cc63e15cb619d641d1edf9a15a0a98875b2] ASoC: qcom: audioreach: Constify function arguments # good: [c6bca73d699cfe00d3419566fdb2a45e112f44b0] ASoC: rt1320: Fix retry checking in rt1320_rae_load() # good: [a2a631830deb382a3d27b6f52b2d654a3e6bb427] ASoC: qcom: Constify APR/GPR result structs # good: [32a708ba5db50cf928a1f1b2039ceef33de2c286] regulator: Add rt8092 support # good: [b39ef93a2e5b5f4289a3486d8a94a09a1e6a4c67] spi: stm32: perform small transfer in polling mode # good: [7a8447fc71a09000cee5a2372b6efde45735d2c8] ASoC: codecs: wcd939x-sdw: use devres for regmap allocation # good: [2a28b5240f2b328495c6565d277f438dbc583d61] ASoC: SOF: ipc4-control: Add support for generic bytes control # good: [3622dc47a4b13e0ec86358c7b54a0b33bfcaa03c] ASoC: codec: rt286: Use devm_request_threaded_irq to manage IRQ lifetime and fix smatch warning # good: [02e7af5b6423d2dbf82f852572f2fa8c00aafb19] ASoC: Intel: sof_rt5682: add tas2563 speaker amp support # good: [29c8c00d9f9db5fb659b6f05f9e8964afc13f3e2] spi: add driver for NXP XSPI controller # good: [9a6bc0a406608e2520f18d996483c9d2e4a9fb27] ASoC: codecs: ES8326: Add kcontrol for DRE # good: [f764645cb85a8b8f58067289cdfed28f6c1cdf49] ASoC: codecs: tas2780: tidyup format check in tas2780_set_fmt() # good: [7f7b350e4a65446f5d52ea8ae99e12eac8a972db] spi: stm32-qspi: Remove unneeded semicolon # good: [1303c2903889b01d581083ed92e439e7544dd3e5] MAINTAINERS: Add MAINTAINERS entry for the ATCSPI200 SPI controller driver # good: [524ee559948d8d079b13466e70fa741f909699c0] ASoC: SOF: Intel: hda: Only check SSP MCLK mask in case of IPC3 # good: [f25c7d709b93602ee9a08eba522808a18e1f5d56] ASoC: SOF: Intel: pci-nvl: Set on_demand_dsp_boot for NVL-S # good: [f4acea9eef704607d1a950909ce3a52a770d6be2] spi: dt-bindings: st,stm32-spi: add 'power-domains' property # good: [e39011184f23de3d04ca8e80b4df76c9047b4026] ASoC: SDCA: functions: Fix confusing cleanup.h syntax # good: [fa08b566860bca8ebf9300090b85174c34de7ca5] spi: rzv2h-rspi: add support for DMA mode # good: [03d281f384768610bf90697bce9e35d3d596de77] rust: regulator: add __rust_helper to helpers # good: [b884e34994ca41f7b7819f3c41b78ff494787b27] spi: spi-fsl-lpspi: convert min_t() to simple min() # good: [124f6155f3d97b0e33f178c10a5138a42c8fd207] ASoC: renesas: rz-ssi: Add support for 32 bits sample width # good: [aa30193af8873b3ccfd70a4275336ab6cbd4e5e6] ASoC: Intel: catpt: Drop superfluous space in PCM code # good: [0bb160c92ad400c692984763996b758458adea17] ASoC: qcom: Minor readability improve with new lines # good: [fee876b2ec75dcc18fdea154eae1f5bf14d82659] spi: stm32-qspi: Simplify SMIE interrupt test # good: [81acbdc51bbbec822a1525481f2f70677c47aee0] ASoC: sdw-mockup: Drop dummy remove function # good: [9e92c559d49d6fb903af17a31a469aac51b1766d] regulator: max77675: Add MAX77675 regulator driver # good: [ba9b28652c75b07383e267328f1759195d5430f7] spi: imx: enable DMA mode for target operation # good: [6c177775dcc5e70a64ddf4ee842c66af498f2c7c] Merge branch 'next/drivers' into for-next git bisect start '615aad0f61e0c7a898184a394dc895c610100d4f' '50814c5ce8d8f6751fd49c818abeb8853f8be2df' '702ce71d32f2c30b4f45b7c6b701d87583c58df8' 'd0ab89951197f0fc509a0cd732d830880e79c2d4' '7f428282fde34f06f3ab898b8a9081bf93a41f22' 'cafadbf430f4b2f3ca4158de48ef6ba4d97fbf17' '00ca2dd431fa2acb07b3ecc6ce49fb9a0a4d72cb' '3495a5df94a9ad7a8940bcb3ebfda58255f5b952' 'a18467a50eddbd7c6548b53b25b68e5454ceb587' 'c3608162a95a259c669cf9fdccf900782fa8d902' '3c5ddd56aa93048314c64533c21e731a44b0f067' '20c4701b75a3d6ce09d61e17125aefe77e7eb333' '37fbc1ab0f225d23f0839260a11375b4f1f7cf8c' '83ba6efa711fad83a0fbf02178ad64d3906d8d09' '4fbd3b2ec04dc6ef93090ec24733a5c5671fb71f' '7a3d1b04d938f31e112fe09c0ffc1af830ba1f6d' 'dccc66b0e92d48d9a1908a3ccb8142e0ee3381f5' '61d2a7699ab39d448f44919ef15c16187e6f70ec' '519d0a6b2ca5a891340b6c24a4c40545f518e1a8' 'da7afdc79cba00f952df12cd579e44832d829c0a' '8a98e7f55f975360975083166e21982ef307b8fd' '10303b32519f52a5afd40593a507543143c8ec6a' '62b04225e99a5d1c71c5c73d2aa6618bc2c0738f' 'de9f1b1583aecb246b659effb03f2456604fab64' 'a014c203b54d9013ad52ad8a531cf46e71028f2b' 'e7c30ac379b429d439eb62ae1bb69720a6701e26' '09dc08b396c954820f119e1ab0c7d72333c18323' '6be9ea62afedef0f976eb3dba4c117be0c1d3809' 'e590752119029d87ce46d725e11245a52d22e1fe' '77157cb45c66bd652a08a360693fcced558c5ef9' 'b0fc1e7701940d12ea2c41f386aa552bc4cc3629' '8618271887ca10ac5108fe7e1d82ba8f1b152cf9' '8672e4b51adfc57150f3862b1665faff0acf1bad' 'fc6ceb7e4ea746e663ff8c5593e67ad8ccbee34a' '83aee46dc2142eed2dc40b5cef0e9e08e14cac42' '8d38423d9dea7353a8a54a3ab2e0d0aa04ed34d0' 'b9198ce5c6dfee19b9662dda95ba559af9cdf53f' 'db4371d13f82fb12463fe053f4864980a2af2106' 'b6376dbed8e173f9571583b5d358b08ff394e864' '0cd9bf6a6d9a1861087236cc5c275b3bea83cfdd' '22a4776a9ce50aa47f602d28f53ba9d613a38f49' '75d208bddcca55ec31481420fbb4d6c9703ba195' '04b61513dfe40f80f0dcc795003637b510522b3c' '9bf0bd7bdea6c402007ffb784dd0c0f704aa2310' '96d337436fe0921177a6090aeb5bb214753654fc' '52ddc0106c77ff0eacf07b309833ae6e6a4e8587' '211243b69533e968cc6f0259fb80ffee02fbe0ca' '420739112e95c9bb286b4e87875706925970abd3' '4c5e6d5b31bc623d89185d551681ab91cfd037c9' '25abdc151a448a17d500ea9468ce32582c479faa' '284853affe73fe1ca9786bd52b934eb9d420a942' '45e9066f3a487e9e26b842644364d045af054775' '0f698d742f628d02ab2a222f8cf5f793443865d0' 'b0655377aa5a410df02d89170c20141a1a5bbc28' '8db50f0fa43efe8799fd40b872dcdd39a90d7549' '99a3ef1e81cd1775bc1f8cc2ad188b1fc755d5cd' '4ab48cc63e15cb619d641d1edf9a15a0a98875b2' 'c6bca73d699cfe00d3419566fdb2a45e112f44b0' 'a2a631830deb382a3d27b6f52b2d654a3e6bb427' '32a708ba5db50cf928a1f1b2039ceef33de2c286' 'b39ef93a2e5b5f4289a3486d8a94a09a1e6a4c67' '7a8447fc71a09000cee5a2372b6efde45735d2c8' '2a28b5240f2b328495c6565d277f438dbc583d61' '3622dc47a4b13e0ec86358c7b54a0b33bfcaa03c' '02e7af5b6423d2dbf82f852572f2fa8c00aafb19' '29c8c00d9f9db5fb659b6f05f9e8964afc13f3e2' '9a6bc0a406608e2520f18d996483c9d2e4a9fb27' 'f764645cb85a8b8f58067289cdfed28f6c1cdf49' '7f7b350e4a65446f5d52ea8ae99e12eac8a972db' '1303c2903889b01d581083ed92e439e7544dd3e5' '524ee559948d8d079b13466e70fa741f909699c0' 'f25c7d709b93602ee9a08eba522808a18e1f5d56' 'f4acea9eef704607d1a950909ce3a52a770d6be2' 'e39011184f23de3d04ca8e80b4df76c9047b4026' 'fa08b566860bca8ebf9300090b85174c34de7ca5' '03d281f384768610bf90697bce9e35d3d596de77' 'b884e34994ca41f7b7819f3c41b78ff494787b27' '124f6155f3d97b0e33f178c10a5138a42c8fd207' 'aa30193af8873b3ccfd70a4275336ab6cbd4e5e6' '0bb160c92ad400c692984763996b758458adea17' 'fee876b2ec75dcc18fdea154eae1f5bf14d82659' '81acbdc51bbbec822a1525481f2f70677c47aee0' '9e92c559d49d6fb903af17a31a469aac51b1766d' 'ba9b28652c75b07383e267328f1759195d5430f7' '6c177775dcc5e70a64ddf4ee842c66af498f2c7c' # test job: [702ce71d32f2c30b4f45b7c6b701d87583c58df8] https://lava.sirena.org.uk/scheduler/job/2393428 # test job: [d0ab89951197f0fc509a0cd732d830880e79c2d4] https://lava.sirena.org.uk/scheduler/job/2392919 # test job: [7f428282fde34f06f3ab898b8a9081bf93a41f22] https://lava.sirena.org.uk/scheduler/job/2391339 # test job: [cafadbf430f4b2f3ca4158de48ef6ba4d97fbf17] https://lava.sirena.org.uk/scheduler/job/2389514 # test job: [00ca2dd431fa2acb07b3ecc6ce49fb9a0a4d72cb] https://lava.sirena.org.uk/scheduler/job/2389628 # test job: [3495a5df94a9ad7a8940bcb3ebfda58255f5b952] https://lava.sirena.org.uk/scheduler/job/2389353 # test job: [a18467a50eddbd7c6548b53b25b68e5454ceb587] https://lava.sirena.org.uk/scheduler/job/2386094 # test job: [c3608162a95a259c669cf9fdccf900782fa8d902] https://lava.sirena.org.uk/scheduler/job/2387959 # test job: [3c5ddd56aa93048314c64533c21e731a44b0f067] https://lava.sirena.org.uk/scheduler/job/2386640 # test job: [20c4701b75a3d6ce09d61e17125aefe77e7eb333] https://lava.sirena.org.uk/scheduler/job/2386301 # test job: [37fbc1ab0f225d23f0839260a11375b4f1f7cf8c] https://lava.sirena.org.uk/scheduler/job/2386363 # test job: [83ba6efa711fad83a0fbf02178ad64d3906d8d09] https://lava.sirena.org.uk/scheduler/job/2387001 # test job: [4fbd3b2ec04dc6ef93090ec24733a5c5671fb71f] https://lava.sirena.org.uk/scheduler/job/2386168 # test job: [7a3d1b04d938f31e112fe09c0ffc1af830ba1f6d] https://lava.sirena.org.uk/scheduler/job/2377308 # test job: [dccc66b0e92d48d9a1908a3ccb8142e0ee3381f5] https://lava.sirena.org.uk/scheduler/job/2377141 # test job: [61d2a7699ab39d448f44919ef15c16187e6f70ec] https://lava.sirena.org.uk/scheduler/job/2375730 # test job: [519d0a6b2ca5a891340b6c24a4c40545f518e1a8] https://lava.sirena.org.uk/scheduler/job/2372387 # test job: [da7afdc79cba00f952df12cd579e44832d829c0a] https://lava.sirena.org.uk/scheduler/job/2372298 # test job: [8a98e7f55f975360975083166e21982ef307b8fd] https://lava.sirena.org.uk/scheduler/job/2372505 # test job: [10303b32519f52a5afd40593a507543143c8ec6a] https://lava.sirena.org.uk/scheduler/job/2372322 # test job: [62b04225e99a5d1c71c5c73d2aa6618bc2c0738f] https://lava.sirena.org.uk/scheduler/job/2369376 # test job: [de9f1b1583aecb246b659effb03f2456604fab64] https://lava.sirena.org.uk/scheduler/job/2368867 # test job: [a014c203b54d9013ad52ad8a531cf46e71028f2b] https://lava.sirena.org.uk/scheduler/job/2368397 # test job: [e7c30ac379b429d439eb62ae1bb69720a6701e26] https://lava.sirena.org.uk/scheduler/job/2366032 # test job: [09dc08b396c954820f119e1ab0c7d72333c18323] https://lava.sirena.org.uk/scheduler/job/2365474 # test job: [6be9ea62afedef0f976eb3dba4c117be0c1d3809] https://lava.sirena.org.uk/scheduler/job/2365609 # test job: [e590752119029d87ce46d725e11245a52d22e1fe] https://lava.sirena.org.uk/scheduler/job/2364789 # test job: [77157cb45c66bd652a08a360693fcced558c5ef9] https://lava.sirena.org.uk/scheduler/job/2363794 # test job: [b0fc1e7701940d12ea2c41f386aa552bc4cc3629] https://lava.sirena.org.uk/scheduler/job/2364720 # test job: [8618271887ca10ac5108fe7e1d82ba8f1b152cf9] https://lava.sirena.org.uk/scheduler/job/2364881 # test job: [8672e4b51adfc57150f3862b1665faff0acf1bad] https://lava.sirena.org.uk/scheduler/job/2363802 # test job: [fc6ceb7e4ea746e663ff8c5593e67ad8ccbee34a] https://lava.sirena.org.uk/scheduler/job/2364433 # test job: [83aee46dc2142eed2dc40b5cef0e9e08e14cac42] https://lava.sirena.org.uk/scheduler/job/2363989 # test job: [8d38423d9dea7353a8a54a3ab2e0d0aa04ed34d0] https://lava.sirena.org.uk/scheduler/job/2354063 # test job: [b9198ce5c6dfee19b9662dda95ba559af9cdf53f] https://lava.sirena.org.uk/scheduler/job/2354856 # test job: [db4371d13f82fb12463fe053f4864980a2af2106] https://lava.sirena.org.uk/scheduler/job/2354230 # test job: [b6376dbed8e173f9571583b5d358b08ff394e864] https://lava.sirena.org.uk/scheduler/job/2349545 # test job: [0cd9bf6a6d9a1861087236cc5c275b3bea83cfdd] https://lava.sirena.org.uk/scheduler/job/2348802 # test job: [22a4776a9ce50aa47f602d28f53ba9d613a38f49] https://lava.sirena.org.uk/scheduler/job/2343130 # test job: [75d208bddcca55ec31481420fbb4d6c9703ba195] https://lava.sirena.org.uk/scheduler/job/2337394 # test job: [04b61513dfe40f80f0dcc795003637b510522b3c] https://lava.sirena.org.uk/scheduler/job/2337624 # test job: [9bf0bd7bdea6c402007ffb784dd0c0f704aa2310] https://lava.sirena.org.uk/scheduler/job/2330756 # test job: [96d337436fe0921177a6090aeb5bb214753654fc] https://lava.sirena.org.uk/scheduler/job/2330496 # test job: [52ddc0106c77ff0eacf07b309833ae6e6a4e8587] https://lava.sirena.org.uk/scheduler/job/2330490 # test job: [211243b69533e968cc6f0259fb80ffee02fbe0ca] https://lava.sirena.org.uk/scheduler/job/2330643 # test job: [420739112e95c9bb286b4e87875706925970abd3] https://lava.sirena.org.uk/scheduler/job/2330595 # test job: [4c5e6d5b31bc623d89185d551681ab91cfd037c9] https://lava.sirena.org.uk/scheduler/job/2330948 # test job: [25abdc151a448a17d500ea9468ce32582c479faa] https://lava.sirena.org.uk/scheduler/job/2307350 # test job: [284853affe73fe1ca9786bd52b934eb9d420a942] https://lava.sirena.org.uk/scheduler/job/2298066 # test job: [45e9066f3a487e9e26b842644364d045af054775] https://lava.sirena.org.uk/scheduler/job/2295621 # test job: [0f698d742f628d02ab2a222f8cf5f793443865d0] https://lava.sirena.org.uk/scheduler/job/2295231 # test job: [b0655377aa5a410df02d89170c20141a1a5bbc28] https://lava.sirena.org.uk/scheduler/job/2291689 # test job: [8db50f0fa43efe8799fd40b872dcdd39a90d7549] https://lava.sirena.org.uk/scheduler/job/2292502 # test job: [99a3ef1e81cd1775bc1f8cc2ad188b1fc755d5cd] https://lava.sirena.org.uk/scheduler/job/2290488 # test job: [4ab48cc63e15cb619d641d1edf9a15a0a98875b2] https://lava.sirena.org.uk/scheduler/job/2290397 # test job: [c6bca73d699cfe00d3419566fdb2a45e112f44b0] https://lava.sirena.org.uk/scheduler/job/2290128 # test job: [a2a631830deb382a3d27b6f52b2d654a3e6bb427] https://lava.sirena.org.uk/scheduler/job/2281785 # test job: [32a708ba5db50cf928a1f1b2039ceef33de2c286] https://lava.sirena.org.uk/scheduler/job/2279465 # test job: [b39ef93a2e5b5f4289a3486d8a94a09a1e6a4c67] https://lava.sirena.org.uk/scheduler/job/2269679 # test job: [7a8447fc71a09000cee5a2372b6efde45735d2c8] https://lava.sirena.org.uk/scheduler/job/2271774 # test job: [2a28b5240f2b328495c6565d277f438dbc583d61] https://lava.sirena.org.uk/scheduler/job/2266163 # test job: [3622dc47a4b13e0ec86358c7b54a0b33bfcaa03c] https://lava.sirena.org.uk/scheduler/job/2268465 # test job: [02e7af5b6423d2dbf82f852572f2fa8c00aafb19] https://lava.sirena.org.uk/scheduler/job/2263583 # test job: [29c8c00d9f9db5fb659b6f05f9e8964afc13f3e2] https://lava.sirena.org.uk/scheduler/job/2263419 # test job: [9a6bc0a406608e2520f18d996483c9d2e4a9fb27] https://lava.sirena.org.uk/scheduler/job/2263708 # test job: [f764645cb85a8b8f58067289cdfed28f6c1cdf49] https://lava.sirena.org.uk/scheduler/job/2263393 # test job: [7f7b350e4a65446f5d52ea8ae99e12eac8a972db] https://lava.sirena.org.uk/scheduler/job/2263713 # test job: [1303c2903889b01d581083ed92e439e7544dd3e5] https://lava.sirena.org.uk/scheduler/job/2263162 # test job: [524ee559948d8d079b13466e70fa741f909699c0] https://lava.sirena.org.uk/scheduler/job/2243761 # test job: [f25c7d709b93602ee9a08eba522808a18e1f5d56] https://lava.sirena.org.uk/scheduler/job/2243682 # test job: [f4acea9eef704607d1a950909ce3a52a770d6be2] https://lava.sirena.org.uk/scheduler/job/2243493 # test job: [e39011184f23de3d04ca8e80b4df76c9047b4026] https://lava.sirena.org.uk/scheduler/job/2231781 # test job: [fa08b566860bca8ebf9300090b85174c34de7ca5] https://lava.sirena.org.uk/scheduler/job/2232081 # test job: [03d281f384768610bf90697bce9e35d3d596de77] https://lava.sirena.org.uk/scheduler/job/2231184 # test job: [b884e34994ca41f7b7819f3c41b78ff494787b27] https://lava.sirena.org.uk/scheduler/job/2231834 # test job: [124f6155f3d97b0e33f178c10a5138a42c8fd207] https://lava.sirena.org.uk/scheduler/job/2232196 # test job: [aa30193af8873b3ccfd70a4275336ab6cbd4e5e6] https://lava.sirena.org.uk/scheduler/job/2231987 # test job: [0bb160c92ad400c692984763996b758458adea17] https://lava.sirena.org.uk/scheduler/job/2232057 # test job: [fee876b2ec75dcc18fdea154eae1f5bf14d82659] https://lava.sirena.org.uk/scheduler/job/2231321 # test job: [81acbdc51bbbec822a1525481f2f70677c47aee0] https://lava.sirena.org.uk/scheduler/job/2231999 # test job: [9e92c559d49d6fb903af17a31a469aac51b1766d] https://lava.sirena.org.uk/scheduler/job/2231743 # test job: [ba9b28652c75b07383e267328f1759195d5430f7] https://lava.sirena.org.uk/scheduler/job/2231572 # test job: [6c177775dcc5e70a64ddf4ee842c66af498f2c7c] https://lava.sirena.org.uk/scheduler/job/2058633 # test job: [615aad0f61e0c7a898184a394dc895c610100d4f] https://lava.sirena.org.uk/scheduler/job/2407321 # bad: [615aad0f61e0c7a898184a394dc895c610100d4f] Add linux-next specific files for 20260126 git bisect bad 615aad0f61e0c7a898184a394dc895c610100d4f # test job: [a85cfbd09f2d2f3bfab8fbe8246d0ae43a0c1628] https://lava.sirena.org.uk/scheduler/job/2407528 # bad: [a85cfbd09f2d2f3bfab8fbe8246d0ae43a0c1628] Merge branch 'master' of https://git.kernel.org/pub/scm/linux/kernel/git/bluetooth/bluetooth-next.git git bisect bad a85cfbd09f2d2f3bfab8fbe8246d0ae43a0c1628 # test job: [75fe66db9e85a2fd9743f7598a2aaea9eb5fbfd7] https://lava.sirena.org.uk/scheduler/job/2407694 # bad: [75fe66db9e85a2fd9743f7598a2aaea9eb5fbfd7] Merge branch 'xtensa-for-next' of https://github.com/jcmvbkbc/linux-xtensa.git git bisect bad 75fe66db9e85a2fd9743f7598a2aaea9eb5fbfd7 # test job: [0578997f52fb9a1b9adfc5fe5a95ceab4bb331d2] https://lava.sirena.org.uk/scheduler/job/2407737 # good: [0578997f52fb9a1b9adfc5fe5a95ceab4bb331d2] Merge branch 'soc_fsl' of https://git.kernel.org/pub/scm/linux/kernel/git/chleroy/linux.git git bisect good 0578997f52fb9a1b9adfc5fe5a95ceab4bb331d2 # test job: [5cd67271caee30972d751ab3763c3de4b1fa73d0] https://lava.sirena.org.uk/scheduler/job/2407794 # good: [5cd67271caee30972d751ab3763c3de4b1fa73d0] Merge branch 'next' of https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-devel.git git bisect good 5cd67271caee30972d751ab3763c3de4b1fa73d0 # test job: [039a29817a494720c25222b6daf104bf230583a7] https://lava.sirena.org.uk/scheduler/job/2407855 # good: [039a29817a494720c25222b6daf104bf230583a7] Merge branch 'for-next' of https://git.kernel.org/pub/scm/linux/kernel/git/tegra/linux.git git bisect good 039a29817a494720c25222b6daf104bf230583a7 # test job: [a142a51e64a948a70e8bcd5810fca89cab6347a5] https://lava.sirena.org.uk/scheduler/job/2407950 # bad: [a142a51e64a948a70e8bcd5810fca89cab6347a5] Merge branch 'clk-next' of https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git git bisect bad a142a51e64a948a70e8bcd5810fca89cab6347a5 # test job: [f5b748e97c52c31ad73b3534dfd1905efe664cc1] https://lava.sirena.org.uk/scheduler/job/2408066 # bad: [f5b748e97c52c31ad73b3534dfd1905efe664cc1] Merge branch 'clk-mediatek' into clk-next git bisect bad f5b748e97c52c31ad73b3534dfd1905efe664cc1 # test job: [df9e5d59dcebe3217f1f5925f51b6beeb780c9b7] https://lava.sirena.org.uk/scheduler/job/2408105 # good: [df9e5d59dcebe3217f1f5925f51b6beeb780c9b7] Merge branch 'clk-spacemit' into clk-next git bisect good df9e5d59dcebe3217f1f5925f51b6beeb780c9b7 # test job: [e98a16bf3cc49397a0fd88fe48d24e5f5f885707] https://lava.sirena.org.uk/scheduler/job/2408143 # good: [e98a16bf3cc49397a0fd88fe48d24e5f5f885707] Merge branch 'clk-amlogic' into clk-next git bisect good e98a16bf3cc49397a0fd88fe48d24e5f5f885707 # test job: [e9955171948a226ee834a3092d71684acce84b65] https://lava.sirena.org.uk/scheduler/job/2408163 # good: [e9955171948a226ee834a3092d71684acce84b65] Merge branch 'clk-cleanup' into clk-next git bisect good e9955171948a226ee834a3092d71684acce84b65 # test job: [ecffd05839b32f17bde1f3701b68ab182a837b07] https://lava.sirena.org.uk/scheduler/job/2408248 # bad: [ecffd05839b32f17bde1f3701b68ab182a837b07] clk: mediatek: Pass device to clk_hw_register for PLLs git bisect bad ecffd05839b32f17bde1f3701b68ab182a837b07 # test job: [a2ed1aed687a21738a6c8bd4043149c443298e88] https://lava.sirena.org.uk/scheduler/job/2408288 # good: [a2ed1aed687a21738a6c8bd4043149c443298e88] dt-bindings: clock: mediatek,mt7622-pciesys: Remove syscon compatible git bisect good a2ed1aed687a21738a6c8bd4043149c443298e88 # test job: [c9ced38af56fe6411118c6bc6522eab80849326d] https://lava.sirena.org.uk/scheduler/job/2408615 # bad: [c9ced38af56fe6411118c6bc6522eab80849326d] clk: mediatek: Refactor pll registration to pass device git bisect bad c9ced38af56fe6411118c6bc6522eab80849326d # test job: [669917676e93fca5ea3c66fc9539830312bec58e] https://lava.sirena.org.uk/scheduler/job/2409704 # bad: [669917676e93fca5ea3c66fc9539830312bec58e] clk: Respect CLK_OPS_PARENT_ENABLE during recalc git bisect bad 669917676e93fca5ea3c66fc9539830312bec58e # first bad commit: [669917676e93fca5ea3c66fc9539830312bec58e] clk: Respect CLK_OPS_PARENT_ENABLE during recalc
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Tue, 27 Jan 2026 17:01:29 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Tue, Jan 27, 2026 at 05:01:35PM +0000, Mark Brown wrote: I am also seeing some similar regressions even earlier on i.MX8MP platforms, though they're resetting even earlier before any output is produced (even with earlycon). Didn't confirm yet with a revert or anything though.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Tue, 27 Jan 2026 17:25:04 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Tuesday, 27 January 2026 18:25:04 Central European Standard Time Mark Brown wrote: Someone else seemingly bisected to this commit on i.MX8MP as well and replied to the RESEND of the series, and confirmed with a revert[1]. I'm somewhat surprised by this, because to me it doesn't make intuitive sense that some platforms would rely on CLK_OPS_PARENT_ENABLE to not enable the parent clock during a recalc. Can someone let me know which clocks (with which parent) in those affected devices is causing this? I'm wondering if this change unmasked some undeclared dependency that it's now stumbling over because it's enabling the parent earlier than ever. Would appreciate if we could fix up the affected platforms rather than revert this, because the platform I added this for was definitely using a parent-child relationship, and definitely needed to have the parent clock on during recalc. I can always bring back the RPM model I went for previously, but that feels like more of a hack around this caveat than a proper description of the clock relationship. To not have me break everyone's -next for days on end, feel free to drop this patch. MT8196, which this was added for, doesn't boot with mainline yet anyway. Kind regards, Nicolas Frattaroli https://lore.kernel.org/all/6239343.lOV4Wx5bFT@steina-w/ [1]
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Tue, 27 Jan 2026 19:18:02 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Tue, Jan 27, 2026 at 07:18:02PM +0100, Nicolas Frattaroli wrote: Do you have a debugging patch we could run which would say which clocks are impacted? I guess it's more of an issue for the platforms that give no output but for at least Avenger96 I was getting earlycon output. Please, this is making my test lab miserable.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Tue, 27 Jan 2026 23:14:29 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wednesday, 28 January 2026 00:14:29 Central European Standard Time Mark Brown wrote: Try this one --- diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 1b0f9d567f48..fa1443517768 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -1921,13 +1921,21 @@ static unsigned long clk_recalc(struct clk_core *core, unsigned long rate = parent_rate; if (core->ops->recalc_rate && !clk_pm_runtime_get(core)) { - if (core->flags & CLK_OPS_PARENT_ENABLE) + if (core->flags & CLK_OPS_PARENT_ENABLE) { + pr_info("%s: enabling parent %s for %s\n", __func__, + core->parent ? core->parent->name : "(null)", + core->name); clk_core_prepare_enable(core->parent); + } rate = core->ops->recalc_rate(core->hw, parent_rate); - if (core->flags & CLK_OPS_PARENT_ENABLE) + if (core->flags & CLK_OPS_PARENT_ENABLE) { + pr_info("%s: disabling parent %s for %s\n", __func__, + core->parent ? core->parent->name : "(null)", + core->name); clk_core_disable_unprepare(core->parent); + } clk_pm_runtime_put(core); } @@ -4038,8 +4046,12 @@ static int __clk_core_init(struct clk_core *core) */ clk_core_update_duty_cycle_nolock(core); - if (core->flags & CLK_OPS_PARENT_ENABLE) + if (core->flags & CLK_OPS_PARENT_ENABLE) { + pr_info("%s: enabling parent %s for %s\n", __func__, + core->parent ? core->parent->name : "(null)", + core->name); clk_core_prepare_enable(core->parent); + } /* * Set clk's rate. The preferred method is to use .recalc_rate. For @@ -4056,8 +4068,12 @@ static int __clk_core_init(struct clk_core *core) rate = 0; core->rate = core->req_rate = rate; - if (core->flags & CLK_OPS_PARENT_ENABLE) + if (core->flags & CLK_OPS_PARENT_ENABLE) { + pr_info("%s: disabling parent %s for %s\n", __func__, + core->parent ? core->parent->name : "(null)", + core->name); clk_core_disable_unprepare(core->parent); + } /* * Enable CLK_IS_CRITICAL clocks so newly added critical clocks --- I don't remember if printk buffers are flushed after each invocation and couldn't quickly find a kernel parameter to control this, but from experience I think these prints should show up if it then hangs the SoC on the very next line. The good news is that the rest of the series can stay without doing any harm if this single patch gets dropped, and I can re-attempt this in the next cycle. Kind regards, Nicolas Frattaroli
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Wed, 28 Jan 2026 15:09:46 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wed, Jan 28, 2026 at 03:09:46PM +0100, Nicolas Frattaroli wrote: For the Avenger96 that says: [ 0.347816] __clk_core_init: enabling parent ck_hse for ck_per [ 0.352230] __clk_core_init: disabling parent ck_hse for ck_per [ 0.358207] __clk_core_init: enabling parent pll1_p for ck_mpu [ 0.364005] __clk_core_init: disabling parent pll1_p for ck_mpu https://lava.sirena.org.uk/scheduler/job/2412562#L563
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Wed, 28 Jan 2026 14:47:08 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Hi everyone, Am Mittwoch, 28. Januar 2026, 15:47:08 CET schrieb Mark Brown: This is for TQMa8MPxL/MBa8MPxL: [ 1.452788] __clk_core_init: enabling parent audio_pll1_out for clkout1_sel [ 1.457677] __clk_core_init: disabling parent audio_pll1_out for clkout1_sel [ 1.464270] __clk_core_init: enabling parent audio_pll1_out for clkout2_sel [ 1.471760] __clk_core_init: disabling parent audio_pll1_out for clkout2_sel [ 1.478360] __clk_core_init: enabling parent sys_pll2_500m for arm_a53_div [ 1.485259] __clk_core_init: disabling parent sys_pll2_500m for arm_a53_div Best regards, Alexander -- TQ-Systems GmbH | Mhlstrae 2, Gut Delling | 82229 Seefeld, Germany Amtsgericht Mnchen, HRB 105018 Geschftsfhrer: Detlef Schneider, Rdiger Stahl, Stefan Schneider http://www.tq-group.com/
{ "author": "Alexander Stein <alexander.stein@ew.tq-group.com>", "date": "Wed, 28 Jan 2026 15:55:54 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wed, Jan 28, 2026 at 03:55:54PM +0100, Alexander Stein wrote: As expected same result on i.MX8MP-EVK.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Wed, 28 Jan 2026 15:21:47 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wednesday, 28 January 2026 15:47:08 Central European Standard Time Mark Brown wrote: Okay, on this one, there may be a problem in the clock tree. ck_mpu is marked CLK_IS_CRITICAL, but its parent, pll1_p, is not. Clock core doesn't seem to check whether any children of a clock are marked as critical before disabling it. I'm not super familiar with the intended semantics of critical clocks. If we need to manually mark all parents of critical clocks as critical as well, then a (potentially partial) fix for the Avenger96 might be: --- diff --git a/drivers/clk/stm32/clk-stm32mp1.c b/drivers/clk/stm32/clk-stm32mp1.c index 2d9ccd96ec98..6bf3fad1e0dc 100644 --- a/drivers/clk/stm32/clk-stm32mp1.c +++ b/drivers/clk/stm32/clk-stm32mp1.c @@ -1783,12 +1783,12 @@ static const struct clock_config stm32mp1_clock_cfg[] = { PLL(PLL4, "pll4", ref4_parents, 0, RCC_PLL4CR, RCC_RCK4SELR), /* ODF */ - COMPOSITE(PLL1_P, "pll1_p", PARENT("pll1"), 0, + COMPOSITE(PLL1_P, "pll1_p", PARENT("pll1"), CLK_IS_CRITICAL, _GATE(RCC_PLL1CR, 4, 0), _NO_MUX, _DIV(RCC_PLL1CFGR2, 0, 7, 0, NULL)), - COMPOSITE(PLL2_P, "pll2_p", PARENT("pll2"), 0, + COMPOSITE(PLL2_P, "pll2_p", PARENT("pll2"), CLK_IS_CRITICAL, _GATE(RCC_PLL2CR, 4, 0), _NO_MUX, _DIV(RCC_PLL2CFGR2, 0, 7, 0, NULL)), @@ -1803,7 +1803,7 @@ static const struct clock_config stm32mp1_clock_cfg[] = { _NO_MUX, _DIV(RCC_PLL2CFGR2, 16, 7, 0, NULL)), - COMPOSITE(PLL3_P, "pll3_p", PARENT("pll3"), 0, + COMPOSITE(PLL3_P, "pll3_p", PARENT("pll3"), CLK_IS_CRITICAL, _GATE(RCC_PLL3CR, 4, 0), _NO_MUX, _DIV(RCC_PLL3CFGR2, 0, 7, 0, NULL)), --- I just looked for CLK_IS_CRITICAL clocks in that file that have the CLK_OPS_PARENT_ENABLE flag, and marked their PLL parents as critical as well. An alternate approach would be to skip the parent enable/disable pair in the problematic patch in __clk_core_init for clocks that are marked as critical, because if the parent wasn't on for a critical clock then we wouldn't be in that function, we would be dead. Kind regards, Nicolas Frattaroli
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Wed, 28 Jan 2026 17:04:55 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wednesday, 28 January 2026 16:21:47 Central European Standard Time Mark Brown wrote: This one puzzles me a little. arm_a53_div is neither marked critical nor is its parent. If arm_a53_div is required for the system to function, then I'd have expected at least it to be marked as critical, allowing us to do the workaround in init I proposed as an alternate solution for the stm32mp1 in my other reply. Also, after reading the code some more, I think that alternate solution has a simpler implementation: move the parent disable to after the if (core->flags & CLK_IS_CRITICAL) { check in __clk_core_init. One explanation is that some other critical clock hangs off sys_pll2_500m, but we're spoiled for choice here. I can't think of a simple fix right now that I feel confident in. Every IMX8MP composite clock that isn't critical seems to set IMX_COMPOSITE_CLK_FLAGS_DEFAULT, which includes CLK_OPS_PARENT_ENABLE, which seems like a pretty weird choice to make when you then rely on the parent not getting touched during __clk_core_init. I will try to get an RFC fix out tonight (CET). I think STM32MP1 is falling over because I messed up, and i.MX8MP is falling over due to a combination of me messing up and its clock driver messing up. Kind regards, Nicolas Frattaroli
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Wed, 28 Jan 2026 17:31:35 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wed, Jan 28, 2026 at 05:31:35PM +0100, Nicolas Frattaroli wrote: Given that all the cores in the system are A53s I rather fear that it is in fact critical and should be marked as such.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Wed, 28 Jan 2026 17:08:28 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Quoting Nicolas Frattaroli (2026-01-28 09:04:55) Marking parents critical hasn't been strictly necessary so far because we've been relying on the prepare/enable count on a critical child to keep the parent prepared/enabled. The parent may not be known yet in __clk_core_init() because we lazily find parents. Putting it another way, we can get to the recalc_rate() call in __clk_core_init() for a clk with CLK_OPS_PARENT_ENABLE when the parent pointer is NULL. This hasn't been a problem because when we adopt the orphan clk the rate is recalculated (see clk_core_reparent_orphans_nolock()). I don't see an easy way out of this problem because in general we need to know a clk with CLK_OPS_PARENT_ENABLE is parented enough to be able to read the registers when calling clk_ops like recalc_rate() (and probably get_parent() as well meaning that clk_op can't touch hardware?). Maybe the simplest approach is to skip any sort of hardware access when this flag is set during setup and reparenting. BTW, I don't know what this patch is actually fixing, so I'm going to revert it. When it is resubmitted please describe the problem you're seeing.
{ "author": "Stephen Boyd <sboyd@kernel.org>", "date": "Wed, 28 Jan 2026 12:01:22 -0700", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wednesday, 28 January 2026 20:01:22 Central European Standard Time Stephen Boyd wrote: In this instance, it doesn't seem like the parent pointer is null, since it does print a parent clock name. I think the problem really is that the parent gets disabled before the CLK_IS_CRITICAL check re-enables it. The issue both SoCs seem to run into is that the parent gets disabled when it shouldn't be, which I fixed in [1]. I don't think any platform that already worked before this change will stop working with this fix and the fix for the fix in [1], because if the parent is absent, then the enable/disables are no-ops anyway. NULL clocks are explicitly handled by the common clock framework. The justification got lost in the revisions of the series this was done in. It's to deal with the MediaTek MT8196's MFGPLL clocks, where the parent clock needs to be on before the clock registers of the child clock can be touched in any way. I first modeled this as an RPM clock, but Angelo didn't like this approach, and with some hackery I could sort of see that the child clock indeed does not tick if the would-be RPM clock is off, so it must be a parent clock instead. The problem with making it a parent clock and adding this flag to it though is that the flag is not respected in recalc_rate, so it reads from an unclocked register. If you want me to make it an RPM clock instead, I can do that, but then we're leaking that the NXP i.MX8MP has a broken clock driver into the device tree bindings of the MediaTek MT8196 PLLs, which seems like a hard sell for the DT bindings maintainers. So in conclusion, I'm fairly confident I've found a fix for the fix, and I'm also very confident the problem doesn't go as deep as you fear. I'll squash the fix for the fix into the fix when I resubmit the fix with a fix for the i.MX, but that'll have to wait until after -rc1 I think. Kind regards, Nicolas Frattaroli Link: https://lore.kernel.org/all/20260128-ops-parent-enable-fix-v1-1-ff39cc37f98d@collabora.com/ [1]
{ "author": "Nicolas Frattaroli <nicolas.frattaroli@collabora.com>", "date": "Wed, 28 Jan 2026 20:59:24 +0100", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH v3 0/5] MediaTek PLL Refactors and Fixes
This series refactors all users of mtk-pll, just so we can enable runtime power management for the clock controllers that want it. It's also generally more useful to have the struct device in the pll code, rather than the device node. Also fix up MT8196 mfgpll to declare its parent-child relationship with mfg_eb, and fix the common clock framework core to take CLK_OPS_PARENT_ENABLE into account for the recalc_rate op as well. The reason why this is all in the same series is that it grew out of me first modelling this as an RPM clock for mfgpll, which Angelo disagreed with, so I did some investigation and it seems MFG_EB indeed is a parent clock. However, the earlier refactoring to pass the device pointer down is still useful. Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com> --- Changes in v3: - Make device_node forward declaration a device forward declaration - Remove forward declarations of struct clk_ops and struct clk_hw_onecell_data. (clk-provider.h include remains as it's needed for a complete type of clk_hw) - Move PLL_PARENT_EN flag to individual mfgpll definitions. - Link to v2: https://lore.kernel.org/r/20251008-mtk-pll-rpm-v2-0-170ed0698560@collabora.com Changes in v2: - Drop bindings patch - Drop mfgpll RPM patch - Add patch to also transition pllfh to passing device - Add fixes patch to make CLK_OPS_PARENT_ENABLE also apply to the recalc_rate operation - Remodel mfgpll's mfg_eb dependency as parent-child with CLK_OPS_PARENT_ENABLE - Link to v1: https://lore.kernel.org/r/20250929-mtk-pll-rpm-v1-0-49541777878d@collabora.com --- Nicolas Frattaroli (5): clk: Respect CLK_OPS_PARENT_ENABLE during recalc clk: mediatek: Refactor pll registration to pass device clk: mediatek: Pass device to clk_hw_register for PLLs clk: mediatek: Refactor pllfh registration to pass device clk: mediatek: Add mfg_eb as parent to mt8196 mfgpll clocks drivers/clk/clk.c | 13 +++++++++++++ drivers/clk/mediatek/clk-mt2701.c | 2 +- drivers/clk/mediatek/clk-mt2712-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6735-apmixedsys.c | 4 ++-- drivers/clk/mediatek/clk-mt6765.c | 2 +- drivers/clk/mediatek/clk-mt6779.c | 2 +- drivers/clk/mediatek/clk-mt6795-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt6797.c | 2 +- drivers/clk/mediatek/clk-mt7622-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt7629.c | 2 +- drivers/clk/mediatek/clk-mt7981-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7986-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt7988-apmixed.c | 2 +- drivers/clk/mediatek/clk-mt8135-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8167-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8173-apmixedsys.c | 14 +++++++------- drivers/clk/mediatek/clk-mt8183-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8186-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8188-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8192-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8195-apusys_pll.c | 3 ++- drivers/clk/mediatek/clk-mt8196-apmixedsys.c | 3 ++- drivers/clk/mediatek/clk-mt8196-mcu.c | 2 +- drivers/clk/mediatek/clk-mt8196-mfg.c | 15 ++++++++------- drivers/clk/mediatek/clk-mt8196-vlpckgen.c | 2 +- drivers/clk/mediatek/clk-mt8365-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-mt8516-apmixedsys.c | 2 +- drivers/clk/mediatek/clk-pll.c | 19 +++++++++++++------ drivers/clk/mediatek/clk-pll.h | 15 ++++++++------- drivers/clk/mediatek/clk-pllfh.c | 13 ++++++++----- drivers/clk/mediatek/clk-pllfh.h | 2 +- 32 files changed, 87 insertions(+), 59 deletions(-) --- base-commit: adff43957b0d8b9f6ad0e1b1f6daa7136f9ffbef change-id: 20250929-mtk-pll-rpm-bf28192dd016 Best regards, -- Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
On Wed, Jan 28, 2026 at 12:01:22PM -0700, Stephen Boyd wrote: The patch is still in -next today and the issues it causes are still visible.
{ "author": "Mark Brown <broonie@kernel.org>", "date": "Mon, 2 Feb 2026 16:54:32 +0000", "thread_id": "e98290b1-274a-4f8c-b629-11c1167b0370@sirena.org.uk.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Modify online_memory_block() to accept the online type through its arg parameter rather than calling mhp_get_default_online_type() internally. This prepares for allowing callers to specify explicit online types. Update the caller in add_memory_resource() to pass the default online type via a local variable. No functional change. Cc: Oscar Salvador <osalvador@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Acked-by: David Hildenbrand (Red Hat) <david@kernel.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- mm/memory_hotplug.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index bc805029da51..87796b617d9e 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -1337,7 +1337,9 @@ static int check_hotplug_memory_range(u64 start, u64 size) static int online_memory_block(struct memory_block *mem, void *arg) { - mem->online_type = mhp_get_default_online_type(); + int *online_type = arg; + + mem->online_type = *online_type; return device_online(&mem->dev); } @@ -1578,8 +1580,12 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) merge_system_ram_resource(res); /* online pages if requested */ - if (mhp_get_default_online_type() != MMOP_OFFLINE) - walk_memory_blocks(start, size, NULL, online_memory_block); + if (mhp_get_default_online_type() != MMOP_OFFLINE) { + int online_type = mhp_get_default_online_type(); + + walk_memory_blocks(start, size, &online_type, + online_memory_block); + } return ret; error: -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:34 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Enable dax kmem driver to select how to online the memory rather than implicitly depending on the system default. This will allow users of dax to plumb through a preferred auto-online policy for their region. Refactor and new interface: Add __add_memory_driver_managed() which accepts an explicit online_type and export mhp_get_default_online_type() so callers can pass it when they want the default behavior. Refactor: Extract __add_memory_resource() to take an explicit online_type parameter, and update add_memory_resource() to pass the system default. No functional change for existing users. Cc: David Hildenbrand <david@kernel.org> Cc: Oscar Salvador <osalvador@suse.de> Cc: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- include/linux/memory_hotplug.h | 3 ++ mm/memory_hotplug.c | 91 ++++++++++++++++++++++++---------- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index f2f16cdd73ee..1eb63d1a247d 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -293,6 +293,9 @@ extern int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); extern int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags); extern int add_memory_resource(int nid, struct resource *resource, mhp_t mhp_flags); +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + int online_type); extern int add_memory_driver_managed(int nid, u64 start, u64 size, const char *resource_name, mhp_t mhp_flags); diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 87796b617d9e..d3ca95b872bd 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -239,6 +239,7 @@ int mhp_get_default_online_type(void) return mhp_default_online_type; } +EXPORT_SYMBOL_GPL(mhp_get_default_online_type); void mhp_set_default_online_type(int online_type) { @@ -1490,7 +1491,8 @@ static int create_altmaps_and_memory_blocks(int nid, struct memory_group *group, * * we are OK calling __meminit stuff here - we have CONFIG_MEMORY_HOTPLUG */ -int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +static int __add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags, + int online_type) { struct mhp_params params = { .pgprot = pgprot_mhp(PAGE_KERNEL) }; enum memblock_flags memblock_flags = MEMBLOCK_NONE; @@ -1580,12 +1582,9 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) merge_system_ram_resource(res); /* online pages if requested */ - if (mhp_get_default_online_type() != MMOP_OFFLINE) { - int online_type = mhp_get_default_online_type(); - + if (online_type != MMOP_OFFLINE) walk_memory_blocks(start, size, &online_type, online_memory_block); - } return ret; error: @@ -1601,7 +1600,13 @@ int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) return ret; } -/* requires device_hotplug_lock, see add_memory_resource() */ +int add_memory_resource(int nid, struct resource *res, mhp_t mhp_flags) +{ + return __add_memory_resource(nid, res, mhp_flags, + mhp_get_default_online_type()); +} + +/* requires device_hotplug_lock, see __add_memory_resource() */ int __add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) { struct resource *res; @@ -1629,29 +1634,24 @@ int add_memory(int nid, u64 start, u64 size, mhp_t mhp_flags) } EXPORT_SYMBOL_GPL(add_memory); -/* - * Add special, driver-managed memory to the system as system RAM. Such - * memory is not exposed via the raw firmware-provided memmap as system - * RAM, instead, it is detected and added by a driver - during cold boot, - * after a reboot, and after kexec. - * - * Reasons why this memory should not be used for the initial memmap of a - * kexec kernel or for placing kexec images: - * - The booting kernel is in charge of determining how this memory will be - * used (e.g., use persistent memory as system RAM) - * - Coordination with a hypervisor is required before this memory - * can be used (e.g., inaccessible parts). +/** + * __add_memory_driver_managed - add driver-managed memory with explicit online_type + * @nid: NUMA node ID where the memory will be added + * @start: Start physical address of the memory range + * @size: Size of the memory range in bytes + * @resource_name: Resource name in format "System RAM ($DRIVER)" + * @mhp_flags: Memory hotplug flags + * @online_type: Online behavior (MMOP_ONLINE, MMOP_ONLINE_KERNEL, + * MMOP_ONLINE_MOVABLE, or MMOP_OFFLINE) * - * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided - * memory map") are created. Also, the created memory resource is flagged - * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case - * this memory as well (esp., not place kexec images onto it). + * Add driver-managed memory with explicit online_type specification. + * The resource_name must have the format "System RAM ($DRIVER)". * - * The resource_name (visible via /proc/iomem) has to have the format - * "System RAM ($DRIVER)". + * Return: 0 on success, negative error code on failure. */ -int add_memory_driver_managed(int nid, u64 start, u64 size, - const char *resource_name, mhp_t mhp_flags) +int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags, + int online_type) { struct resource *res; int rc; @@ -1661,6 +1661,9 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, resource_name[strlen(resource_name) - 1] != ')') return -EINVAL; + if (online_type < 0 || online_type > MMOP_ONLINE_MOVABLE) + return -EINVAL; + lock_device_hotplug(); res = register_memory_resource(start, size, resource_name); @@ -1669,7 +1672,7 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, goto out_unlock; } - rc = add_memory_resource(nid, res, mhp_flags); + rc = __add_memory_resource(nid, res, mhp_flags, online_type); if (rc < 0) release_memory_resource(res); @@ -1677,6 +1680,40 @@ int add_memory_driver_managed(int nid, u64 start, u64 size, unlock_device_hotplug(); return rc; } +EXPORT_SYMBOL_FOR_MODULES(__add_memory_driver_managed, "kmem"); + +/* + * Add special, driver-managed memory to the system as system RAM. Such + * memory is not exposed via the raw firmware-provided memmap as system + * RAM, instead, it is detected and added by a driver - during cold boot, + * after a reboot, and after kexec. + * + * Reasons why this memory should not be used for the initial memmap of a + * kexec kernel or for placing kexec images: + * - The booting kernel is in charge of determining how this memory will be + * used (e.g., use persistent memory as system RAM) + * - Coordination with a hypervisor is required before this memory + * can be used (e.g., inaccessible parts). + * + * For this memory, no entries in /sys/firmware/memmap ("raw firmware-provided + * memory map") are created. Also, the created memory resource is flagged + * with IORESOURCE_SYSRAM_DRIVER_MANAGED, so in-kernel users can special-case + * this memory as well (esp., not place kexec images onto it). + * + * The resource_name (visible via /proc/iomem) has to have the format + * "System RAM ($DRIVER)". + * + * Memory will be onlined using the system default online type. + * + * Returns 0 on success, negative error code on failure. + */ +int add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, mhp_t mhp_flags) +{ + return __add_memory_driver_managed(nid, start, size, resource_name, + mhp_flags, + mhp_get_default_online_type()); +} EXPORT_SYMBOL_GPL(add_memory_driver_managed); /* -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:35 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
There is no way for drivers leveraging dax_kmem to plumb through a preferred auto-online policy - the system default policy is forced. Add online_type field to DAX device creation path to allow drivers to specify an auto-online policy when using the kmem driver. Current callers initialize online_type to mhp_get_default_online_type() which resolves to the system default (memhp_default_online_type). No functional change to existing drivers. Cc:David Hildenbrand <david@kernel.org> Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/region.c | 2 ++ drivers/cxl/cxl.h | 1 + drivers/dax/bus.c | 3 +++ drivers/dax/bus.h | 1 + drivers/dax/cxl.c | 1 + drivers/dax/dax-private.h | 2 ++ drivers/dax/hmem/hmem.c | 2 ++ drivers/dax/kmem.c | 13 +++++++++++-- drivers/dax/pmem.c | 2 ++ 9 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 5bd1213737fa..eef5d5fe3f95 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* Copyright(c) 2022 Intel Corporation. All rights reserved. */ #include <linux/memregion.h> +#include <linux/memory_hotplug.h> #include <linux/genalloc.h> #include <linux/debugfs.h> #include <linux/device.h> @@ -3459,6 +3460,7 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) if (IS_ERR(cxlr_dax)) return PTR_ERR(cxlr_dax); + cxlr_dax->online_type = mhp_get_default_online_type(); dev = &cxlr_dax->dev; rc = dev_set_name(dev, "dax_region%d", cxlr->id); if (rc) diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index ba17fa86d249..07d57d13f4c7 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -591,6 +591,7 @@ struct cxl_dax_region { struct device dev; struct cxl_region *cxlr; struct range hpa_range; + int online_type; /* MMOP_ value for kmem driver */ }; /** diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index fde29e0ad68b..121a6dd0afe7 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2017-2018 Intel Corporation. All rights reserved. */ #include <linux/memremap.h> +#include <linux/memory_hotplug.h> #include <linux/device.h> #include <linux/mutex.h> #include <linux/list.h> @@ -395,6 +396,7 @@ static ssize_t create_store(struct device *dev, struct device_attribute *attr, .size = 0, .id = -1, .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; struct dev_dax *dev_dax = __devm_create_dev_dax(&data); @@ -1494,6 +1496,7 @@ static struct dev_dax *__devm_create_dev_dax(struct dev_dax_data *data) ida_init(&dev_dax->ida); dev_dax->memmap_on_memory = data->memmap_on_memory; + dev_dax->online_type = data->online_type; inode = dax_inode(dax_dev); dev->devt = inode->i_rdev; diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index cbbf64443098..4ac92a4edfe7 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -24,6 +24,7 @@ struct dev_dax_data { resource_size_t size; int id; bool memmap_on_memory; + int online_type; /* MMOP_ value for kmem driver */ }; struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index 13cd94d32ff7..856a0cd24f3b 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -27,6 +27,7 @@ static int cxl_dax_region_probe(struct device *dev) .id = -1, .size = range_len(&cxlr_dax->hpa_range), .memmap_on_memory = true, + .online_type = cxlr_dax->online_type, }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/dax-private.h b/drivers/dax/dax-private.h index c6ae27c982f4..9559718cc988 100644 --- a/drivers/dax/dax-private.h +++ b/drivers/dax/dax-private.h @@ -77,6 +77,7 @@ struct dev_dax_range { * @dev: device core * @pgmap: pgmap for memmap setup / lifetime (driver owned) * @memmap_on_memory: allow kmem to put the memmap in the memory + * @online_type: MMOP_* online type for memory hotplug * @nr_range: size of @ranges * @ranges: range tuples of memory used */ @@ -91,6 +92,7 @@ struct dev_dax { struct device dev; struct dev_pagemap *pgmap; bool memmap_on_memory; + int online_type; int nr_range; struct dev_dax_range *ranges; }; diff --git a/drivers/dax/hmem/hmem.c b/drivers/dax/hmem/hmem.c index c18451a37e4f..119914b08fd9 100644 --- a/drivers/dax/hmem/hmem.c +++ b/drivers/dax/hmem/hmem.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include <linux/platform_device.h> +#include <linux/memory_hotplug.h> #include <linux/memregion.h> #include <linux/module.h> #include <linux/dax.h> @@ -36,6 +37,7 @@ static int dax_hmem_probe(struct platform_device *pdev) .id = -1, .size = region_idle ? 0 : range_len(&mri->range), .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; return PTR_ERR_OR_ZERO(devm_create_dev_dax(&data)); diff --git a/drivers/dax/kmem.c b/drivers/dax/kmem.c index c036e4d0b610..550dc605229e 100644 --- a/drivers/dax/kmem.c +++ b/drivers/dax/kmem.c @@ -16,6 +16,11 @@ #include "dax-private.h" #include "bus.h" +/* Internal function exported only to kmem module */ +extern int __add_memory_driver_managed(int nid, u64 start, u64 size, + const char *resource_name, + mhp_t mhp_flags, int online_type); + /* * Default abstract distance assigned to the NUMA node onlined * by DAX/kmem if the low level platform driver didn't initialize @@ -72,6 +77,7 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) struct dax_kmem_data *data; struct memory_dev_type *mtype; int i, rc, mapped = 0; + int online_type; mhp_t mhp_flags; int numa_node; int adist = MEMTIER_DEFAULT_DAX_ADISTANCE; @@ -134,6 +140,8 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) goto err_reg_mgid; data->mgid = rc; + online_type = dev_dax->online_type; + for (i = 0; i < dev_dax->nr_range; i++) { struct resource *res; struct range range; @@ -174,8 +182,9 @@ static int dev_dax_kmem_probe(struct dev_dax *dev_dax) * Ensure that future kexec'd kernels will not treat * this as RAM automatically. */ - rc = add_memory_driver_managed(data->mgid, range.start, - range_len(&range), kmem_name, mhp_flags); + rc = __add_memory_driver_managed(data->mgid, range.start, + range_len(&range), kmem_name, mhp_flags, + online_type); if (rc) { dev_warn(dev, "mapping%d: %#llx-%#llx memory add failed\n", diff --git a/drivers/dax/pmem.c b/drivers/dax/pmem.c index bee93066a849..a5925146b09f 100644 --- a/drivers/dax/pmem.c +++ b/drivers/dax/pmem.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */ +#include <linux/memory_hotplug.h> #include <linux/memremap.h> #include <linux/module.h> #include "../nvdimm/pfn.h" @@ -63,6 +64,7 @@ static struct dev_dax *__dax_pmem_probe(struct device *dev) .pgmap = &pgmap, .size = range_len(&range), .memmap_on_memory = false, + .online_type = mhp_get_default_online_type(), }; return devm_create_dev_dax(&data); -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:36 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Move the pmem region driver logic from region.c into pmem_region.c. No functional changes. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 1 + drivers/cxl/core/pmem_region.c | 191 +++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 184 ------------------------------- 4 files changed, 193 insertions(+), 184 deletions(-) create mode 100644 drivers/cxl/core/pmem_region.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 5ad8fef210b5..23269c81fd44 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -17,6 +17,7 @@ cxl_core-y += cdat.o cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) += edac.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index dd987ef2def5..26991de12d76 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -43,6 +43,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port); struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); +int devm_cxl_add_pmem_region(struct cxl_region *cxlr); #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c new file mode 100644 index 000000000000..81b66e548bb5 --- /dev/null +++ b/drivers/cxl/core/pmem_region.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2022 Intel Corporation. All rights reserved. */ +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_pmem_region_release(struct device *dev) +{ + struct cxl_pmem_region *cxlr_pmem = to_cxl_pmem_region(dev); + int i; + + for (i = 0; i < cxlr_pmem->nr_mappings; i++) { + struct cxl_memdev *cxlmd = cxlr_pmem->mapping[i].cxlmd; + + put_device(&cxlmd->dev); + } + + kfree(cxlr_pmem); +} + +static const struct attribute_group *cxl_pmem_region_attribute_groups[] = { + &cxl_base_attribute_group, + NULL, +}; + +const struct device_type cxl_pmem_region_type = { + .name = "cxl_pmem_region", + .release = cxl_pmem_region_release, + .groups = cxl_pmem_region_attribute_groups, +}; +bool is_cxl_pmem_region(struct device *dev) +{ + return dev->type == &cxl_pmem_region_type; +} +EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); + +struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), + "not a cxl_pmem_region device\n")) + return NULL; + return container_of(dev, struct cxl_pmem_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); +static struct lock_class_key cxl_pmem_region_key; + +static int cxl_pmem_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int i; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return -ENXIO; + + struct cxl_pmem_region *cxlr_pmem __free(kfree) = + kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); + if (!cxlr_pmem) + return -ENOMEM; + + cxlr_pmem->hpa_range.start = p->res->start; + cxlr_pmem->hpa_range.end = p->res->end; + + /* Snapshot the region configuration underneath the cxl_rwsem.region */ + cxlr_pmem->nr_mappings = p->nr_targets; + for (i = 0; i < p->nr_targets; i++) { + struct cxl_endpoint_decoder *cxled = p->targets[i]; + struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); + struct cxl_pmem_region_mapping *m = &cxlr_pmem->mapping[i]; + + /* + * Regions never span CXL root devices, so by definition the + * bridge for one device is the same for all. + */ + if (i == 0) { + cxl_nvb = cxl_find_nvdimm_bridge(cxlmd->endpoint); + if (!cxl_nvb) + return -ENODEV; + cxlr->cxl_nvb = cxl_nvb; + } + m->cxlmd = cxlmd; + get_device(&cxlmd->dev); + m->start = cxled->dpa_res->start; + m->size = resource_size(cxled->dpa_res); + m->position = i; + } + + dev = &cxlr_pmem->dev; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_pmem_region_type; + cxlr_pmem->cxlr = cxlr; + cxlr->cxlr_pmem = no_free_ptr(cxlr_pmem); + + return 0; +} + +static void cxlr_pmem_unregister(void *_cxlr_pmem) +{ + struct cxl_pmem_region *cxlr_pmem = _cxlr_pmem; + struct cxl_region *cxlr = cxlr_pmem->cxlr; + struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; + + /* + * Either the bridge is in ->remove() context under the device_lock(), + * or cxlr_release_nvdimm() is cancelling the bridge's release action + * for @cxlr_pmem and doing it itself (while manually holding the bridge + * lock). + */ + device_lock_assert(&cxl_nvb->dev); + cxlr->cxlr_pmem = NULL; + cxlr_pmem->cxlr = NULL; + device_unregister(&cxlr_pmem->dev); +} + +static void cxlr_release_nvdimm(void *_cxlr) +{ + struct cxl_region *cxlr = _cxlr; + struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; + + scoped_guard(device, &cxl_nvb->dev) { + if (cxlr->cxlr_pmem) + devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, + cxlr->cxlr_pmem); + } + cxlr->cxl_nvb = NULL; + put_device(&cxl_nvb->dev); +} + +/** + * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge + * @cxlr: parent CXL region for this pmem region bridge device + * + * Return: 0 on success negative error code on failure. + */ +int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + struct cxl_pmem_region *cxlr_pmem; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int rc; + + rc = cxl_pmem_region_alloc(cxlr); + if (rc) + return rc; + cxlr_pmem = cxlr->cxlr_pmem; + cxl_nvb = cxlr->cxl_nvb; + + dev = &cxlr_pmem->dev; + rc = dev_set_name(dev, "pmem_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + scoped_guard(device, &cxl_nvb->dev) { + if (cxl_nvb->dev.driver) + rc = devm_add_action_or_reset(&cxl_nvb->dev, + cxlr_pmem_unregister, + cxlr_pmem); + else + rc = -ENXIO; + } + + if (rc) + goto err_bridge; + + /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ + return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); + +err: + put_device(dev); +err_bridge: + put_device(&cxl_nvb->dev); + cxlr->cxl_nvb = NULL; + return rc; +} + + diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e4097c464ed3..fc56f8f03805 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2747,46 +2747,6 @@ static ssize_t delete_region_store(struct device *dev, } DEVICE_ATTR_WO(delete_region); -static void cxl_pmem_region_release(struct device *dev) -{ - struct cxl_pmem_region *cxlr_pmem = to_cxl_pmem_region(dev); - int i; - - for (i = 0; i < cxlr_pmem->nr_mappings; i++) { - struct cxl_memdev *cxlmd = cxlr_pmem->mapping[i].cxlmd; - - put_device(&cxlmd->dev); - } - - kfree(cxlr_pmem); -} - -static const struct attribute_group *cxl_pmem_region_attribute_groups[] = { - &cxl_base_attribute_group, - NULL, -}; - -const struct device_type cxl_pmem_region_type = { - .name = "cxl_pmem_region", - .release = cxl_pmem_region_release, - .groups = cxl_pmem_region_attribute_groups, -}; - -bool is_cxl_pmem_region(struct device *dev) -{ - return dev->type == &cxl_pmem_region_type; -} -EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); - -struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) -{ - if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), - "not a cxl_pmem_region device\n")) - return NULL; - return container_of(dev, struct cxl_pmem_region, dev); -} -EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); - struct cxl_poison_context { struct cxl_port *port; int part; @@ -3236,64 +3196,6 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset, return -ENXIO; } -static struct lock_class_key cxl_pmem_region_key; - -static int cxl_pmem_region_alloc(struct cxl_region *cxlr) -{ - struct cxl_region_params *p = &cxlr->params; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int i; - - guard(rwsem_read)(&cxl_rwsem.region); - if (p->state != CXL_CONFIG_COMMIT) - return -ENXIO; - - struct cxl_pmem_region *cxlr_pmem __free(kfree) = - kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); - if (!cxlr_pmem) - return -ENOMEM; - - cxlr_pmem->hpa_range.start = p->res->start; - cxlr_pmem->hpa_range.end = p->res->end; - - /* Snapshot the region configuration underneath the cxl_rwsem.region */ - cxlr_pmem->nr_mappings = p->nr_targets; - for (i = 0; i < p->nr_targets; i++) { - struct cxl_endpoint_decoder *cxled = p->targets[i]; - struct cxl_memdev *cxlmd = cxled_to_memdev(cxled); - struct cxl_pmem_region_mapping *m = &cxlr_pmem->mapping[i]; - - /* - * Regions never span CXL root devices, so by definition the - * bridge for one device is the same for all. - */ - if (i == 0) { - cxl_nvb = cxl_find_nvdimm_bridge(cxlmd->endpoint); - if (!cxl_nvb) - return -ENODEV; - cxlr->cxl_nvb = cxl_nvb; - } - m->cxlmd = cxlmd; - get_device(&cxlmd->dev); - m->start = cxled->dpa_res->start; - m->size = resource_size(cxled->dpa_res); - m->position = i; - } - - dev = &cxlr_pmem->dev; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); - device_set_pm_not_required(dev); - dev->parent = &cxlr->dev; - dev->bus = &cxl_bus_type; - dev->type = &cxl_pmem_region_type; - cxlr_pmem->cxlr = cxlr; - cxlr->cxlr_pmem = no_free_ptr(cxlr_pmem); - - return 0; -} - static void cxl_dax_region_release(struct device *dev) { struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); @@ -3357,92 +3259,6 @@ static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) return cxlr_dax; } -static void cxlr_pmem_unregister(void *_cxlr_pmem) -{ - struct cxl_pmem_region *cxlr_pmem = _cxlr_pmem; - struct cxl_region *cxlr = cxlr_pmem->cxlr; - struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; - - /* - * Either the bridge is in ->remove() context under the device_lock(), - * or cxlr_release_nvdimm() is cancelling the bridge's release action - * for @cxlr_pmem and doing it itself (while manually holding the bridge - * lock). - */ - device_lock_assert(&cxl_nvb->dev); - cxlr->cxlr_pmem = NULL; - cxlr_pmem->cxlr = NULL; - device_unregister(&cxlr_pmem->dev); -} - -static void cxlr_release_nvdimm(void *_cxlr) -{ - struct cxl_region *cxlr = _cxlr; - struct cxl_nvdimm_bridge *cxl_nvb = cxlr->cxl_nvb; - - scoped_guard(device, &cxl_nvb->dev) { - if (cxlr->cxlr_pmem) - devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, - cxlr->cxlr_pmem); - } - cxlr->cxl_nvb = NULL; - put_device(&cxl_nvb->dev); -} - -/** - * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge - * @cxlr: parent CXL region for this pmem region bridge device - * - * Return: 0 on success negative error code on failure. - */ -static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) -{ - struct cxl_pmem_region *cxlr_pmem; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int rc; - - rc = cxl_pmem_region_alloc(cxlr); - if (rc) - return rc; - cxlr_pmem = cxlr->cxlr_pmem; - cxl_nvb = cxlr->cxl_nvb; - - dev = &cxlr_pmem->dev; - rc = dev_set_name(dev, "pmem_region%d", cxlr->id); - if (rc) - goto err; - - rc = device_add(dev); - if (rc) - goto err; - - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), - dev_name(dev)); - - scoped_guard(device, &cxl_nvb->dev) { - if (cxl_nvb->dev.driver) - rc = devm_add_action_or_reset(&cxl_nvb->dev, - cxlr_pmem_unregister, - cxlr_pmem); - else - rc = -ENXIO; - } - - if (rc) - goto err_bridge; - - /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ - return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); - -err: - put_device(dev); -err_bridge: - put_device(&cxl_nvb->dev); - cxlr->cxl_nvb = NULL; - return rc; -} - static void cxlr_dax_unregister(void *_cxlr_dax) { struct cxl_dax_region *cxlr_dax = _cxlr_dax; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:38 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Move the CXL DAX region device infrastructure from region.c into a new dax_region.c file. No functional changes. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 1 + drivers/cxl/core/dax_region.c | 113 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 102 ------------------------------ 4 files changed, 115 insertions(+), 102 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 23269c81fd44..36f284d7c500 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -17,6 +17,7 @@ cxl_core-y += cdat.o cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o +cxl_core-$(CONFIG_CXL_REGION) += dax_region.o cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 26991de12d76..217dd708a2a6 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -43,6 +43,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port); struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); +int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); #else diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c new file mode 100644 index 000000000000..0602db5f7248 --- /dev/null +++ b/drivers/cxl/core/dax_region.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright(c) 2022 Intel Corporation. All rights reserved. + * Copyright(c) 2026 Meta Technologies Inc. All rights reserved. + */ +#include <linux/memory_hotplug.h> +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_dax_region_release(struct device *dev) +{ + struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); + + kfree(cxlr_dax); +} + +static const struct attribute_group *cxl_dax_region_attribute_groups[] = { + &cxl_base_attribute_group, + NULL, +}; + +const struct device_type cxl_dax_region_type = { + .name = "cxl_dax_region", + .release = cxl_dax_region_release, + .groups = cxl_dax_region_attribute_groups, +}; + +static bool is_cxl_dax_region(struct device *dev) +{ + return dev->type == &cxl_dax_region_type; +} + +struct cxl_dax_region *to_cxl_dax_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_dax_region(dev), + "not a cxl_dax_region device\n")) + return NULL; + return container_of(dev, struct cxl_dax_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_dax_region, "CXL"); + +static struct lock_class_key cxl_dax_region_key; + +static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_dax_region *cxlr_dax; + struct device *dev; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return ERR_PTR(-ENXIO); + + cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); + if (!cxlr_dax) + return ERR_PTR(-ENOMEM); + + cxlr_dax->hpa_range.start = p->res->start; + cxlr_dax->hpa_range.end = p->res->end; + + dev = &cxlr_dax->dev; + cxlr_dax->cxlr = cxlr; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_dax_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_dax_region_type; + + return cxlr_dax; +} + +static void cxlr_dax_unregister(void *_cxlr_dax) +{ + struct cxl_dax_region *cxlr_dax = _cxlr_dax; + + device_unregister(&cxlr_dax->dev); +} + +int devm_cxl_add_dax_region(struct cxl_region *cxlr, + enum dax_driver_type dax_driver) +{ + struct cxl_dax_region *cxlr_dax; + struct device *dev; + int rc; + + cxlr_dax = cxl_dax_region_alloc(cxlr); + if (IS_ERR(cxlr_dax)) + return PTR_ERR(cxlr_dax); + + cxlr_dax->online_type = mhp_get_default_online_type(); + cxlr_dax->dax_driver = dax_driver; + dev = &cxlr_dax->dev; + rc = dev_set_name(dev, "dax_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister, + cxlr_dax); +err: + put_device(dev); + return rc; +} diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index fc56f8f03805..61ec939c1462 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3196,108 +3196,6 @@ static int region_offset_to_dpa_result(struct cxl_region *cxlr, u64 offset, return -ENXIO; } -static void cxl_dax_region_release(struct device *dev) -{ - struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); - - kfree(cxlr_dax); -} - -static const struct attribute_group *cxl_dax_region_attribute_groups[] = { - &cxl_base_attribute_group, - NULL, -}; - -const struct device_type cxl_dax_region_type = { - .name = "cxl_dax_region", - .release = cxl_dax_region_release, - .groups = cxl_dax_region_attribute_groups, -}; - -static bool is_cxl_dax_region(struct device *dev) -{ - return dev->type == &cxl_dax_region_type; -} - -struct cxl_dax_region *to_cxl_dax_region(struct device *dev) -{ - if (dev_WARN_ONCE(dev, !is_cxl_dax_region(dev), - "not a cxl_dax_region device\n")) - return NULL; - return container_of(dev, struct cxl_dax_region, dev); -} -EXPORT_SYMBOL_NS_GPL(to_cxl_dax_region, "CXL"); - -static struct lock_class_key cxl_dax_region_key; - -static struct cxl_dax_region *cxl_dax_region_alloc(struct cxl_region *cxlr) -{ - struct cxl_region_params *p = &cxlr->params; - struct cxl_dax_region *cxlr_dax; - struct device *dev; - - guard(rwsem_read)(&cxl_rwsem.region); - if (p->state != CXL_CONFIG_COMMIT) - return ERR_PTR(-ENXIO); - - cxlr_dax = kzalloc(sizeof(*cxlr_dax), GFP_KERNEL); - if (!cxlr_dax) - return ERR_PTR(-ENOMEM); - - cxlr_dax->hpa_range.start = p->res->start; - cxlr_dax->hpa_range.end = p->res->end; - - dev = &cxlr_dax->dev; - cxlr_dax->cxlr = cxlr; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_dax_region_key); - device_set_pm_not_required(dev); - dev->parent = &cxlr->dev; - dev->bus = &cxl_bus_type; - dev->type = &cxl_dax_region_type; - - return cxlr_dax; -} - -static void cxlr_dax_unregister(void *_cxlr_dax) -{ - struct cxl_dax_region *cxlr_dax = _cxlr_dax; - - device_unregister(&cxlr_dax->dev); -} - -static int devm_cxl_add_dax_region(struct cxl_region *cxlr, - enum dax_driver_type dax_driver) -{ - struct cxl_dax_region *cxlr_dax; - struct device *dev; - int rc; - - cxlr_dax = cxl_dax_region_alloc(cxlr); - if (IS_ERR(cxlr_dax)) - return PTR_ERR(cxlr_dax); - - cxlr_dax->online_type = mhp_get_default_online_type(); - cxlr_dax->dax_driver = dax_driver; - dev = &cxlr_dax->dev; - rc = dev_set_name(dev, "dax_region%d", cxlr->id); - if (rc) - goto err; - - rc = device_add(dev); - if (rc) - goto err; - - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), - dev_name(dev)); - - return devm_add_action_or_reset(&cxlr->dev, cxlr_dax_unregister, - cxlr_dax); -err: - put_device(dev); - return rc; -} - static int match_decoder_by_range(struct device *dev, const void *data) { const struct range *r1, *r2 = data; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:39 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Add a new cxl_devdax_region driver that probes CXL regions in device dax mode and creates dax_region devices. This allows explicit binding to the device_dax dax driver instead of the kmem driver. Exports to_cxl_region() to core.h so it can be used by the driver. Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/core.h | 2 ++ drivers/cxl/core/dax_region.c | 16 ++++++++++++++++ drivers/cxl/core/region.c | 21 +++++++++++++++++---- drivers/cxl/cxl.h | 1 + 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 217dd708a2a6..ea4df8abc2ad 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -46,6 +46,8 @@ u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); +extern struct cxl_driver cxl_devdax_region_driver; + #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa) diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c index 0602db5f7248..391d51e5ec37 100644 --- a/drivers/cxl/core/dax_region.c +++ b/drivers/cxl/core/dax_region.c @@ -111,3 +111,19 @@ int devm_cxl_add_dax_region(struct cxl_region *cxlr, put_device(dev); return rc; } + +static int cxl_devdax_region_driver_probe(struct device *dev) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + + if (cxlr->mode != CXL_PARTMODE_RAM) + return -ENODEV; + + return devm_cxl_add_dax_region(cxlr, DAXDRV_DEVICE_TYPE); +} + +struct cxl_driver cxl_devdax_region_driver = { + .name = "cxl_devdax_region", + .probe = cxl_devdax_region_driver_probe, + .id = CXL_DEVICE_REGION, +}; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 61ec939c1462..6200ca1cc2dd 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -39,8 +39,6 @@ */ static nodemask_t nodemask_region_seen = NODE_MASK_NONE; -static struct cxl_region *to_cxl_region(struct device *dev); - #define __ACCESS_ATTR_RO(_level, _name) { \ .attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = _name##_access##_level##_show, \ @@ -2430,7 +2428,7 @@ bool is_cxl_region(struct device *dev) } EXPORT_SYMBOL_NS_GPL(is_cxl_region, "CXL"); -static struct cxl_region *to_cxl_region(struct device *dev) +struct cxl_region *to_cxl_region(struct device *dev) { if (dev_WARN_ONCE(dev, dev->type != &cxl_region_type, "not a cxl_region device\n")) @@ -3726,11 +3724,26 @@ static struct cxl_driver cxl_region_driver = { int cxl_region_init(void) { - return cxl_driver_register(&cxl_region_driver); + int rc; + + rc = cxl_driver_register(&cxl_region_driver); + if (rc) + return rc; + + rc = cxl_driver_register(&cxl_devdax_region_driver); + if (rc) + goto err_dax; + + return 0; + +err_dax: + cxl_driver_unregister(&cxl_region_driver); + return rc; } void cxl_region_exit(void) { + cxl_driver_unregister(&cxl_devdax_region_driver); cxl_driver_unregister(&cxl_region_driver); } diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index c06a239c0008..674d5f870c70 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -859,6 +859,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, struct cxl_endpoint_dvsec_info *info); bool is_cxl_region(struct device *dev); +struct cxl_region *to_cxl_region(struct device *dev); extern const struct bus_type cxl_bus_type; -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:40 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
CXL regions may wish not to auto-configure their memory as dax kmem, but the current plumbing defaults all cxl-created dax devices to the kmem driver. This exposes them to hotplug policy, even if the user intends to use the memory as a dax device. Add plumbing to allow CXL drivers to select whether a DAX region should default to kmem (DAXDRV_KMEM_TYPE) or device (DAXDRV_DEVICE_TYPE). Add a 'dax_driver' field to struct cxl_dax_region and update devm_cxl_add_dax_region() to take a dax_driver_type parameter. In drivers/dax/cxl.c, the IORESOURCE_DAX_KMEM flag used by dax driver matching code is now set conditionally based on dax_region->dax_driver. Exports `enum dax_driver_type` to linux/dax.h for use in the cxl driver. All current callers pass DAXDRV_KMEM_TYPE for backward compatibility. Cc: John Groves <john@jagalactic.com> Signed-off-by: Gregory Price <gourry@gourry.net> --- drivers/cxl/core/core.h | 1 + drivers/cxl/core/region.c | 6 ++++-- drivers/cxl/cxl.h | 2 ++ drivers/dax/bus.h | 6 +----- drivers/dax/cxl.c | 6 +++++- include/linux/dax.h | 5 +++++ 6 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 1fb66132b777..dd987ef2def5 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -6,6 +6,7 @@ #include <cxl/mailbox.h> #include <linux/rwsem.h> +#include <linux/dax.h> extern const struct device_type cxl_nvdimm_bridge_type; extern const struct device_type cxl_nvdimm_type; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index eef5d5fe3f95..e4097c464ed3 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3450,7 +3450,8 @@ static void cxlr_dax_unregister(void *_cxlr_dax) device_unregister(&cxlr_dax->dev); } -static int devm_cxl_add_dax_region(struct cxl_region *cxlr) +static int devm_cxl_add_dax_region(struct cxl_region *cxlr, + enum dax_driver_type dax_driver) { struct cxl_dax_region *cxlr_dax; struct device *dev; @@ -3461,6 +3462,7 @@ static int devm_cxl_add_dax_region(struct cxl_region *cxlr) return PTR_ERR(cxlr_dax); cxlr_dax->online_type = mhp_get_default_online_type(); + cxlr_dax->dax_driver = dax_driver; dev = &cxlr_dax->dev; rc = dev_set_name(dev, "dax_region%d", cxlr->id); if (rc) @@ -3994,7 +3996,7 @@ static int cxl_region_probe(struct device *dev) p->res->start, p->res->end, cxlr, is_system_ram) > 0) return 0; - return devm_cxl_add_dax_region(cxlr); + return devm_cxl_add_dax_region(cxlr, DAXDRV_KMEM_TYPE); default: dev_dbg(&cxlr->dev, "unsupported region mode: %d\n", cxlr->mode); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 07d57d13f4c7..c06a239c0008 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -12,6 +12,7 @@ #include <linux/node.h> #include <linux/io.h> #include <linux/range.h> +#include <linux/dax.h> extern const struct nvdimm_security_ops *cxl_security_ops; @@ -592,6 +593,7 @@ struct cxl_dax_region { struct cxl_region *cxlr; struct range hpa_range; int online_type; /* MMOP_ value for kmem driver */ + enum dax_driver_type dax_driver; }; /** diff --git a/drivers/dax/bus.h b/drivers/dax/bus.h index 4ac92a4edfe7..9144593b4029 100644 --- a/drivers/dax/bus.h +++ b/drivers/dax/bus.h @@ -2,6 +2,7 @@ /* Copyright(c) 2016 - 2018 Intel Corporation. All rights reserved. */ #ifndef __DAX_BUS_H__ #define __DAX_BUS_H__ +#include <linux/dax.h> #include <linux/device.h> #include <linux/range.h> @@ -29,11 +30,6 @@ struct dev_dax_data { struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data); -enum dax_driver_type { - DAXDRV_KMEM_TYPE, - DAXDRV_DEVICE_TYPE, -}; - struct dax_device_driver { struct device_driver drv; struct list_head ids; diff --git a/drivers/dax/cxl.c b/drivers/dax/cxl.c index 856a0cd24f3b..b13ecc2f9806 100644 --- a/drivers/dax/cxl.c +++ b/drivers/dax/cxl.c @@ -11,14 +11,18 @@ static int cxl_dax_region_probe(struct device *dev) struct cxl_dax_region *cxlr_dax = to_cxl_dax_region(dev); int nid = phys_to_target_node(cxlr_dax->hpa_range.start); struct cxl_region *cxlr = cxlr_dax->cxlr; + unsigned long flags = 0; struct dax_region *dax_region; struct dev_dax_data data; + if (cxlr_dax->dax_driver == DAXDRV_KMEM_TYPE) + flags |= IORESOURCE_DAX_KMEM; + if (nid == NUMA_NO_NODE) nid = memory_add_physaddr_to_nid(cxlr_dax->hpa_range.start); dax_region = alloc_dax_region(dev, cxlr->id, &cxlr_dax->hpa_range, nid, - PMD_SIZE, IORESOURCE_DAX_KMEM); + PMD_SIZE, flags); if (!dax_region) return -ENOMEM; diff --git a/include/linux/dax.h b/include/linux/dax.h index bf103f317cac..e62f92d0ace1 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -19,6 +19,11 @@ enum dax_access_mode { DAX_RECOVERY_WRITE, }; +enum dax_driver_type { + DAXDRV_KMEM_TYPE, + DAXDRV_DEVICE_TYPE, +}; + struct dax_operations { /* * direct_access: translate a device-relative -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:37 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Explain the binding process for sysram and daxdev regions which are explicit about which dax driver to use during region creation. Jonathan Corbet <corbet@lwn.net> Signed-off-by: Gregory Price <gourry@gourry.net> --- .../driver-api/cxl/linux/cxl-driver.rst | 43 +++++++++++++++++++ .../driver-api/cxl/linux/dax-driver.rst | 29 +++++++++++++ 2 files changed, 72 insertions(+) diff --git a/Documentation/driver-api/cxl/linux/cxl-driver.rst b/Documentation/driver-api/cxl/linux/cxl-driver.rst index dd6dd17dc536..1f857345e896 100644 --- a/Documentation/driver-api/cxl/linux/cxl-driver.rst +++ b/Documentation/driver-api/cxl/linux/cxl-driver.rst @@ -445,6 +445,49 @@ for more details. :: dax0.0 devtype modalias uevent dax_region driver subsystem +DAX regions are created when a CXL RAM region is bound to one of the +following drivers: + +* :code:`cxl_devdax_region` - Creates a dax_region for device_dax mode. + The resulting DAX device provides direct userspace access via + :code:`/dev/daxN.Y`. + +* :code:`cxl_dax_kmem_region` - Creates a dax_region for kmem mode via a + sysram_region intermediate device. See `Sysram Region`_ below. + +Sysram Region +~~~~~~~~~~~~~ +A `Sysram Region` is an intermediate device between a CXL `Memory Region` +and a `DAX Region` for kmem mode. It is created when a CXL RAM region is +bound to the :code:`cxl_sysram_region` driver. + +The sysram_region device provides an interposition point where users can +configure memory hotplug policy before the underlying dax_region is created +and memory is hotplugged to the system. + +The device hierarchy for kmem mode is:: + + regionX -> sysram_regionX -> dax_regionX -> daxX.Y + +The sysram_region exposes an :code:`online_type` attribute that controls +how memory will be onlined when the dax_kmem driver binds: + +* :code:`invalid` - Not configured (default). Blocks driver binding. +* :code:`offline` - Memory will not be onlined automatically. +* :code:`online` - Memory will be onlined in ZONE_NORMAL. +* :code:`online_movable` - Memory will be onlined in ZONE_MOVABLE. + +Example two-stage binding process:: + + # Bind region to sysram_region driver + echo region0 > /sys/bus/cxl/drivers/cxl_sysram_region/bind + + # Configure memory online type + echo online_movable > /sys/bus/cxl/devices/sysram_region0/online_type + + # Bind sysram_region to dax_kmem_region driver + echo sysram_region0 > /sys/bus/cxl/drivers/cxl_dax_kmem_region/bind + Mailbox Interfaces ------------------ A mailbox command interface for each device is exposed in :: diff --git a/Documentation/driver-api/cxl/linux/dax-driver.rst b/Documentation/driver-api/cxl/linux/dax-driver.rst index 10d953a2167b..2b8e21736292 100644 --- a/Documentation/driver-api/cxl/linux/dax-driver.rst +++ b/Documentation/driver-api/cxl/linux/dax-driver.rst @@ -17,6 +17,35 @@ The DAX subsystem exposes this ability through the `cxl_dax_region` driver. A `dax_region` provides the translation between a CXL `memory_region` and a `DAX Device`. +CXL DAX Region Drivers +====================== +CXL provides multiple drivers for creating DAX regions, each suited for +different use cases: + +cxl_devdax_region +----------------- +The :code:`cxl_devdax_region` driver creates a dax_region configured for +device_dax mode. When a CXL RAM region is bound to this driver, the +resulting DAX device provides direct userspace access via :code:`/dev/daxN.Y`. + +Device hierarchy:: + + regionX -> dax_regionX -> daxX.Y + +This is the simplest path for applications that want to manage CXL memory +directly from userspace. + +cxl_dax_kmem_region +------------------- +For kmem mode, CXL provides a two-stage binding process that allows users +to configure memory hotplug policy before memory is added to the system. + +The :code:`cxl_dax_kmem_region` driver then binds a sysram_region +device and creates a dax_region configured for kmem mode. + +The :code:`online_type` policy will be passed from sysram_region to +the dax kmem driver for use when hotplugging the memory. + DAX Device ========== A `DAX Device` is a file-like interface exposed in :code:`/dev/daxN.Y`. A -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:42 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
In the current kmem driver binding process, the only way for users to define hotplug policy is via a build-time option, or by not onlining memory by default and setting each individual memory block online after hotplug occurs. We can solve this with a configuration step between region-probe and dax-probe. Add the infrastructure for a two-stage driver binding for kmem-mode dax regions. The cxl_dax_kmem_region driver probes cxl_sysram_region devices and creates cxl_dax_region with dax_driver=kmem. This creates an interposition step where users can configure policy. Device hierarchy: region0 -> sysram_region0 -> dax_region0 -> dax0.0 The sysram_region device exposes a sysfs 'online_type' attribute that allows users to configure the memory online type before the underlying dax_region is created and memory is hotplugged. sysram_region0/online_type: invalid: not configured, blocks probe offline: memory will not be onlined automatically online: memory will be onlined in ZONE_NORMAL online_movable: memory will be onlined in ZONE_MMOVABLE The device initializes with online_type=invalid which prevents the cxl_dax_kmem_region driver from binding until the user explicitly configures a valid online_type. This enables a two-step binding process: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind Signed-off-by: Gregory Price <gourry@gourry.net> --- Documentation/ABI/testing/sysfs-bus-cxl | 21 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 6 + drivers/cxl/core/dax_region.c | 50 +++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 14 ++ drivers/cxl/core/sysram_region.c | 180 ++++++++++++++++++++++++ drivers/cxl/cxl.h | 25 ++++ 8 files changed, 299 insertions(+) create mode 100644 drivers/cxl/core/sysram_region.c diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/testing/sysfs-bus-cxl index c80a1b5a03db..a051cb86bdfc 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -624,3 +624,24 @@ Description: The count is persistent across power loss and wraps back to 0 upon overflow. If this file is not present, the device does not have the necessary support for dirty tracking. + + +What: /sys/bus/cxl/devices/sysram_regionZ/online_type +Date: January, 2026 +KernelVersion: v7.1 +Contact: linux-cxl@vger.kernel.org +Description: + (RW) This attribute allows users to configure the memory online + type before the underlying dax_region engages in hotplug. + + Valid values: + 'invalid': Not configured (default). Blocks probe. + 'offline': Memory will not be onlined automatically. + 'online' : Memory will be onlined in ZONE_NORMAL. + 'online_movable': Memory will be onlined in ZONE_MOVABLE. + + The device initializes with online_type='invalid' which prevents + the cxl_dax_kmem_region driver from binding until the user + explicitly configures a valid online_type. This enables a + two-step binding process that gives users control over memory + hotplug policy before memory is added to the system. diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 36f284d7c500..faf662c7d88b 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -18,6 +18,7 @@ cxl_core-y += ras.o cxl_core-$(CONFIG_TRACING) += trace.o cxl_core-$(CONFIG_CXL_REGION) += region.o cxl_core-$(CONFIG_CXL_REGION) += dax_region.o +cxl_core-$(CONFIG_CXL_REGION) += sysram_region.o cxl_core-$(CONFIG_CXL_REGION) += pmem_region.o cxl_core-$(CONFIG_CXL_MCE) += mce.o cxl_core-$(CONFIG_CXL_FEATURES) += features.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index ea4df8abc2ad..04b32015e9b1 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -26,6 +26,7 @@ extern struct device_attribute dev_attr_delete_region; extern struct device_attribute dev_attr_region; extern const struct device_type cxl_pmem_region_type; extern const struct device_type cxl_dax_region_type; +extern const struct device_type cxl_sysram_region_type; extern const struct device_type cxl_region_type; int cxl_decoder_detach(struct cxl_region *cxlr, @@ -37,6 +38,7 @@ int cxl_decoder_detach(struct cxl_region *cxlr, #define SET_CXL_REGION_ATTR(x) (&dev_attr_##x.attr), #define CXL_PMEM_REGION_TYPE(x) (&cxl_pmem_region_type) #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type) +#define CXL_SYSRAM_REGION_TYPE(x) (&cxl_sysram_region_type) int cxl_region_init(void); void cxl_region_exit(void); int cxl_get_poison_by_endpoint(struct cxl_port *port); @@ -44,9 +46,12 @@ struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); int devm_cxl_add_dax_region(struct cxl_region *cxlr, enum dax_driver_type); +int devm_cxl_add_sysram_region(struct cxl_region *cxlr); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); extern struct cxl_driver cxl_devdax_region_driver; +extern struct cxl_driver cxl_dax_kmem_region_driver; +extern struct cxl_driver cxl_sysram_region_driver; #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -81,6 +86,7 @@ static inline void cxl_region_exit(void) #define SET_CXL_REGION_ATTR(x) #define CXL_PMEM_REGION_TYPE(x) NULL #define CXL_DAX_REGION_TYPE(x) NULL +#define CXL_SYSRAM_REGION_TYPE(x) NULL #endif struct cxl_send_command; diff --git a/drivers/cxl/core/dax_region.c b/drivers/cxl/core/dax_region.c index 391d51e5ec37..a379f5b85e3d 100644 --- a/drivers/cxl/core/dax_region.c +++ b/drivers/cxl/core/dax_region.c @@ -127,3 +127,53 @@ struct cxl_driver cxl_devdax_region_driver = { .probe = cxl_devdax_region_driver_probe, .id = CXL_DEVICE_REGION, }; + +static int cxl_dax_kmem_region_driver_probe(struct device *dev) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + struct cxl_dax_region *cxlr_dax; + struct cxl_region *cxlr; + int rc; + + if (!cxlr_sysram) + return -ENODEV; + + /* Require explicit online_type configuration before binding */ + if (cxlr_sysram->online_type == -1) + return -ENODEV; + + cxlr = cxlr_sysram->cxlr; + + cxlr_dax = cxl_dax_region_alloc(cxlr); + if (IS_ERR(cxlr_dax)) + return PTR_ERR(cxlr_dax); + + /* Inherit online_type from parent sysram_region */ + cxlr_dax->online_type = cxlr_sysram->online_type; + cxlr_dax->dax_driver = DAXDRV_KMEM_TYPE; + + /* Parent is the sysram_region device */ + cxlr_dax->dev.parent = dev; + + rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(&cxlr_dax->dev); + if (rc) + goto err; + + dev_dbg(dev, "%s: register %s\n", dev_name(dev), + dev_name(&cxlr_dax->dev)); + + return devm_add_action_or_reset(dev, cxlr_dax_unregister, cxlr_dax); +err: + put_device(&cxlr_dax->dev); + return rc; +} + +struct cxl_driver cxl_dax_kmem_region_driver = { + .name = "cxl_dax_kmem_region", + .probe = cxl_dax_kmem_region_driver_probe, + .id = CXL_DEVICE_SYSRAM_REGION, +}; diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 3310dbfae9d6..dc7262a5efd6 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -66,6 +66,8 @@ static int cxl_device_id(const struct device *dev) return CXL_DEVICE_PMEM_REGION; if (dev->type == CXL_DAX_REGION_TYPE()) return CXL_DEVICE_DAX_REGION; + if (dev->type == CXL_SYSRAM_REGION_TYPE()) + return CXL_DEVICE_SYSRAM_REGION; if (is_cxl_port(dev)) { if (is_cxl_root(to_cxl_port(dev))) return CXL_DEVICE_ROOT; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 6200ca1cc2dd..8bef91dc726c 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3734,8 +3734,20 @@ int cxl_region_init(void) if (rc) goto err_dax; + rc = cxl_driver_register(&cxl_sysram_region_driver); + if (rc) + goto err_sysram; + + rc = cxl_driver_register(&cxl_dax_kmem_region_driver); + if (rc) + goto err_dax_kmem; + return 0; +err_dax_kmem: + cxl_driver_unregister(&cxl_sysram_region_driver); +err_sysram: + cxl_driver_unregister(&cxl_devdax_region_driver); err_dax: cxl_driver_unregister(&cxl_region_driver); return rc; @@ -3743,6 +3755,8 @@ int cxl_region_init(void) void cxl_region_exit(void) { + cxl_driver_unregister(&cxl_dax_kmem_region_driver); + cxl_driver_unregister(&cxl_sysram_region_driver); cxl_driver_unregister(&cxl_devdax_region_driver); cxl_driver_unregister(&cxl_region_driver); } diff --git a/drivers/cxl/core/sysram_region.c b/drivers/cxl/core/sysram_region.c new file mode 100644 index 000000000000..5665db238d0f --- /dev/null +++ b/drivers/cxl/core/sysram_region.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2026 Meta Platforms, Inc. All rights reserved. */ +/* + * CXL Sysram Region - Intermediate device for kmem hotplug configuration + * + * This provides an intermediate device between cxl_region and cxl_dax_region + * that allows users to configure memory hotplug parameters (like online_type) + * before the underlying dax_region is created and memory is hotplugged. + */ + +#include <linux/memory_hotplug.h> +#include <linux/device.h> +#include <linux/slab.h> +#include <cxlmem.h> +#include <cxl.h> +#include "core.h" + +static void cxl_sysram_region_release(struct device *dev) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + kfree(cxlr_sysram); +} + +static ssize_t online_type_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + switch (cxlr_sysram->online_type) { + case MMOP_OFFLINE: + return sysfs_emit(buf, "offline\n"); + case MMOP_ONLINE: + return sysfs_emit(buf, "online\n"); + case MMOP_ONLINE_MOVABLE: + return sysfs_emit(buf, "online_movable\n"); + default: + return sysfs_emit(buf, "invalid\n"); + } +} + +static ssize_t online_type_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_sysram_region *cxlr_sysram = to_cxl_sysram_region(dev); + + if (sysfs_streq(buf, "offline")) + cxlr_sysram->online_type = MMOP_OFFLINE; + else if (sysfs_streq(buf, "online")) + cxlr_sysram->online_type = MMOP_ONLINE; + else if (sysfs_streq(buf, "online_movable")) + cxlr_sysram->online_type = MMOP_ONLINE_MOVABLE; + else + return -EINVAL; + + return len; +} + +static DEVICE_ATTR_RW(online_type); + +static struct attribute *cxl_sysram_region_attrs[] = { + &dev_attr_online_type.attr, + NULL, +}; + +static const struct attribute_group cxl_sysram_region_attribute_group = { + .attrs = cxl_sysram_region_attrs, +}; + +static const struct attribute_group *cxl_sysram_region_attribute_groups[] = { + &cxl_base_attribute_group, + &cxl_sysram_region_attribute_group, + NULL, +}; + +const struct device_type cxl_sysram_region_type = { + .name = "cxl_sysram_region", + .release = cxl_sysram_region_release, + .groups = cxl_sysram_region_attribute_groups, +}; + +static bool is_cxl_sysram_region(struct device *dev) +{ + return dev->type == &cxl_sysram_region_type; +} + +struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_sysram_region(dev), + "not a cxl_sysram_region device\n")) + return NULL; + return container_of(dev, struct cxl_sysram_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_sysram_region, "CXL"); + +static struct lock_class_key cxl_sysram_region_key; + +static struct cxl_sysram_region *cxl_sysram_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p = &cxlr->params; + struct cxl_sysram_region *cxlr_sysram; + struct device *dev; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state != CXL_CONFIG_COMMIT) + return ERR_PTR(-ENXIO); + + cxlr_sysram = kzalloc(sizeof(*cxlr_sysram), GFP_KERNEL); + if (!cxlr_sysram) + return ERR_PTR(-ENOMEM); + + cxlr_sysram->hpa_range.start = p->res->start; + cxlr_sysram->hpa_range.end = p->res->end; + cxlr_sysram->online_type = -1; /* Require explicit configuration */ + + dev = &cxlr_sysram->dev; + cxlr_sysram->cxlr = cxlr; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_sysram_region_key); + device_set_pm_not_required(dev); + dev->parent = &cxlr->dev; + dev->bus = &cxl_bus_type; + dev->type = &cxl_sysram_region_type; + + return cxlr_sysram; +} + +static void cxlr_sysram_unregister(void *_cxlr_sysram) +{ + struct cxl_sysram_region *cxlr_sysram = _cxlr_sysram; + + device_unregister(&cxlr_sysram->dev); +} + +int devm_cxl_add_sysram_region(struct cxl_region *cxlr) +{ + struct cxl_sysram_region *cxlr_sysram; + struct device *dev; + int rc; + + cxlr_sysram = cxl_sysram_region_alloc(cxlr); + if (IS_ERR(cxlr_sysram)) + return PTR_ERR(cxlr_sysram); + + dev = &cxlr_sysram->dev; + rc = dev_set_name(dev, "sysram_region%d", cxlr->id); + if (rc) + goto err; + + rc = device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + return devm_add_action_or_reset(&cxlr->dev, cxlr_sysram_unregister, + cxlr_sysram); +err: + put_device(dev); + return rc; +} + +static int cxl_sysram_region_driver_probe(struct device *dev) +{ + struct cxl_region *cxlr = to_cxl_region(dev); + + /* Only handle RAM regions */ + if (cxlr->mode != CXL_PARTMODE_RAM) + return -ENODEV; + + return devm_cxl_add_sysram_region(cxlr); +} + +struct cxl_driver cxl_sysram_region_driver = { + .name = "cxl_sysram_region", + .probe = cxl_sysram_region_driver_probe, + .id = CXL_DEVICE_REGION, +}; diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 674d5f870c70..1544c27e9c89 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -596,6 +596,25 @@ struct cxl_dax_region { enum dax_driver_type dax_driver; }; +/** + * struct cxl_sysram_region - CXL RAM region for system memory hotplug + * @dev: device for this sysram_region + * @cxlr: parent cxl_region + * @hpa_range: Host physical address range for the region + * @online_type: Memory online type (MMOP_* 0-3, or -1 if not configured) + * + * Intermediate device that allows configuration of memory hotplug + * parameters before the underlying dax_region is created. The device + * starts with online_type=-1 which prevents the cxl_dax_kmem_region + * driver from binding until the user explicitly sets online_type. + */ +struct cxl_sysram_region { + struct device dev; + struct cxl_region *cxlr; + struct range hpa_range; + int online_type; +}; + /** * struct cxl_port - logical collection of upstream port devices and * downstream port devices to construct a CXL memory @@ -890,6 +909,7 @@ void cxl_driver_unregister(struct cxl_driver *cxl_drv); #define CXL_DEVICE_PMEM_REGION 7 #define CXL_DEVICE_DAX_REGION 8 #define CXL_DEVICE_PMU 9 +#define CXL_DEVICE_SYSRAM_REGION 10 #define MODULE_ALIAS_CXL(type) MODULE_ALIAS("cxl:t" __stringify(type) "*") #define CXL_MODALIAS_FMT "cxl:t%d" @@ -907,6 +927,7 @@ bool is_cxl_pmem_region(struct device *dev); struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); int cxl_add_to_region(struct cxl_endpoint_decoder *cxled); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); +struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); #else static inline bool is_cxl_pmem_region(struct device *dev) @@ -925,6 +946,10 @@ static inline struct cxl_dax_region *to_cxl_dax_region(struct device *dev) { return NULL; } +static inline struct cxl_sysram_region *to_cxl_sysram_region(struct device *dev) +{ + return NULL; +} static inline u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa) { -- 2.52.0
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:04:41 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
Annoyingly, my email client has been truncating my titles: cxl: explicit DAX driver selection and hotplug policy for CXL regions ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Thu, 29 Jan 2026 16:17:55 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, Jan 29, 2026 at 04:04:33PM -0500, Gregory Price wrote: Looks like build regression on configs without hotplug MMOP_ defines and mhp_get_default_online_type() undefined Will let this version sit for a bit before spinning a v2 ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Fri, 30 Jan 2026 12:34:33 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On 1/29/2026 3:04 PM, Gregory Price wrote: This technically comes up in the devdax_region driver patch first, but I noticed it here so this is where I'm putting it: I like the idea here, but the implementation is all off. Firstly, devm_cxl_add_sysram_region() is never called outside of sysram_region_driver::probe(), so I'm not sure how they ever get added to the system (same with devdax regions). Second, there's this weird pattern of adding sub-region (sysram, devdax, etc.) devices being added inside of the sub-region driver probe. I would expect the devices are added then the probe function is called. What I think should be going on here (and correct me if I'm wrong) is: 1. a cxl_region device is added to the system 2. cxl_region::probe() is called on said device (one in cxl/core/region.c) 3. Said probe function figures out the device is a dax_region or whatever else and creates that type of region device (i.e. cxl_region::probe() -> device_add(&cxl_sysram_device)) 4. if the device's dax driver type is DAXDRV_DEVICE_TYPE it gets sent to the daxdev_region driver 5a. if the device's dax driver type is DAXDRV_KMEM_TYPE it gets sent to the sysram_region driver which holds it until the online_type is set 5b. Once the online_type is set, the device is forwarded to the dax_kmem_region driver? Not sure on this part What seems to be happening is that the cxl_region is added, all of these region drivers try to bind to it since they all use the same device id (CXL_DEVICE_REGION) and the correct one is figured out by magic? I'm somewhat confused at this point :/. This should be removed from the valid values section since it's not a valid value to write to the attribute. The mention of the default in the paragraph below should be enough. You can use cleanup.h here to remove the goto's (I think). Following should work: #DEFINE_FREE(cxlr_dax_region_put, struct cxl_dax_region *, if (!IS_ERR_OR_NULL(_T)) put_device(&cxlr_dax->dev)) static int cxl_dax_kmem_region_driver_probe(struct device *dev) { ... struct cxl_dax_region *cxlr_dax __free(cxlr_dax_region_put) = cxl_dax_region_alloc(cxlr); if (IS_ERR(cxlr_dax)) return PTR_ERR(cxlr_dax); ... rc = dev_set_name(&cxlr_dax->dev, "dax_region%d", cxlr->id); if (rc) return rc; rc = device_add(&cxlr_dax->dev); if (rc) return rc; dev_dbg(dev, "%s: register %s\n", dev_name(dev), dev_name(&cxlr_dax->dev)); return devm_add_action_or_reset(dev, cxlr_dax_unregister, no_free_ptr(cxlr_dax)); } Same thing as above Thanks, Ben
{ "author": "\"Cheatham, Benjamin\" <benjamin.cheatham@amd.com>", "date": "Fri, 30 Jan 2026 15:27:12 -0600", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Fri, Jan 30, 2026 at 03:27:12PM -0600, Cheatham, Benjamin wrote: I originally tried doing with region0/region_driver, but that design pattern is also confusing - and it creates differently bad patterns. echo region0 > decoder0.0/create_ram_region -> creates region0 # Current pattern echo region > driver/region/probe /* auto-region behavior */ # region_driver attribute pattern echo "sysram" > region0/region_driver echo region0 > driver/region/probe /* uses sysram region driver */ https://lore.kernel.org/linux-cxl/20260113202138.3021093-1-gourry@gourry.net/ Ira pointed out that this design makes the "implicit" design of the driver worse. The user doesn't actually know what driver is being used under the hood - it just knows something is being used. This at least makes it explicit which driver is being used - and splits the uses-case logic up into discrete drivers (dax users don't have to worry about sysram users breaking their stuff). If it makes more sense, you could swap the ordering of the names echo region0 > region/bind echo region0 > region_sysram/bind echo region0 > region_daxdev/bind echo region0 > region_dax_kmem/bind echo region0 > region_pony/bind --- The underlying issue is that region::probe() is trying to be a god-function for every possible use case, and hiding the use case behind an attribute vs a driver is not good. (also the default behavior for region::probe() in an otherwise unconfigured region is required for backwards compatibility) For auto-regions: region_probe() eats it and you get the default behavior. For non-auto regions: create_x_region generates an un-configured region and fails to probe until the user commits it and probes it. auto-regions are evil and should be discouraged. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Fri, 30 Jan 2026 17:12:50 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On 1/30/2026 4:12 PM, Gregory Price wrote: Ok, that makes sense. I think I just got lost in the sauce while looking at this last week and this explanation helped a lot.> I think this was the source of my misunderstanding. I was trying to understand how it works for auto regions when it's never meant to apply to them. Sorry if this is a stupid question, but what stops auto regions from binding to the sysram/dax region drivers? They all bind to region devices, so I assume there's something keeping them from binding before the core region driver gets a chance. Thanks, Ben
{ "author": "\"Cheatham, Benjamin\" <benjamin.cheatham@amd.com>", "date": "Mon, 2 Feb 2026 11:02:37 -0600", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:34 -0500 Gregory Price <gourry@gourry.net> wrote: Trivial comment inline. I don't really care either way. Pushing the policy up to the caller and ensuring it's explicitly constant for all the memory blocks (as opposed to relying on locks) seems sensible to me even without anything else. Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Maybe move the local variable outside the loop to avoid the double call.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:10:29 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:35 -0500 Gregory Price <gourry@gourry.net> wrote: Hi Gregory, I think maybe I'd have left the export for the first user outside of memory_hotplug.c. Not particularly important however. Maybe talk about why a caller of __add_memory_driver_managed() might want the default? Feels like that's for the people who don't... Or is this all a dance to avoid an if (special mode) __add_memory_driver_managed(); else add_memory_driver_managed(); ? Other comments are mostly about using a named enum. I'm not sure if there is some existing reason why that doesn't work? -Errno pushed through this variable or anything like that? Given online_type values are from an enum anyway, maybe we can name that enum and use it explicitly? Ah. Fair enough, ignore comment in previous patch. I should have read on... It's a little odd to add nice kernel-doc formatted documentation when the non __ variant has free form docs. Maybe tidy that up first if we want to go kernel-doc in this file? (I'm in favor, but no idea on general feelings...) Given that's currently the full set, seems like enum wins out here over an int. This is where using an enum would help compiler know what is going on and maybe warn if anyone writes something that isn't defined.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:25:24 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 11:02:37AM -0600, Cheatham, Benjamin wrote: Auto regions explicitly use the dax_kmem path (all existing code, unchanged)- which auto-plugs into dax/hotplug. I do get what you're saying that everything binds on a region type, I will look a little closer at this and see if there's something more reasonable we can do. I think i can update `region/bind` to use the sysram driver with online_type=mhp_default_online_type so you'd end up with effective the auto-region logic: cxlcli create-region -m ram ... existing argument set ------ echo region0 > create_ram_region /* program decoders */ echo region0 > region/bind /* * region_bind(): * 1) alloc sysram_region object * 2) sysram_regionN->online_type=mhp_default_online_type() * 3) add device to bus * 4) device auto-probes all the way down to dax * 5) dax auto-onlines with system default setting */ ------ and Non-auto-region logic (approximation) cxlcli creation-region -m ram --type sysram --online-type=movable ----- echo region0 > create_ram_region /* program decoders */ echo region0 > sysram/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > dax_kmem/bind ----- I want to retain the dax_kmem driver because there may be multiple users other than sysram. For example, a compressed memory region wants to utilize dax_kmem, but has its own complex policy (via N_MEMORY_PRIVATE) so it doesn't want to abstract through sysram_region, but it does want to abstract through dax_kmem. weeeee "software defined memory" weeeee ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 12:41:31 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 05:10:29PM +0000, Jonathan Cameron wrote: ack. will update for next version w/ Ben's notes and the build fix. Thanks! ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 12:46:25 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:37 -0500 Gregory Price <gourry@gourry.net> wrote: LGTM Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:54:17 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:38 -0500 Gregory Price <gourry@gourry.net> wrote: Needs to answer the question: Why? Minor stuff inline. Maybe sneak in dropping that trailing comma whilst you are moving it. ... Bonus line...
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:56:40 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:39 -0500 Gregory Price <gourry@gourry.net> wrote: Likewise. Why?
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 17:57:11 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 05:25:24PM +0000, Jonathan Cameron wrote: Less about why they want the default, more about maintaining backward compatibility. In the cxl driver, Ben pointed out something that made me realize we can change `region/bind()` to actually use the new `sysram/bind` path by just adding a one line `sysram_regionN->online_type = default()` I can add this detail to the changelog. I can add a cleanup-patch prior to use the enum, but i don't think this actually enables the compiler to do anything new at the moment? An enum just resolves to an int, and setting `enum thing val = -1` when the enum definition doesn't include -1 doesn't actually fire any errors (at least IIRC - maybe i'm just wrong). Same with function(enum) -> function(-1) wouldn't fire a compilation error It might actually be worth adding `MMOP_NOT_CONFIGURED = -1` so that the cxl-sysram driver can set this explicitly rather than just setting -1 as an implicit version of this - but then why would memory_hotplug.c ever want to expose a NOT_CONFIGURED option lol. So, yeah, the enum looks nicer, but not sure how much it buys us beyond that. ack. Can add some more cleanups early in the series. I think you still have to sanity check this, but maybe the code looks cleaner, so will do. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 13:02:10 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Thu, 29 Jan 2026 16:04:41 -0500 Gregory Price <gourry@gourry.net> wrote: ZONE_MOVABLE Trivial stuff. Will mull over this series as a whole... My first instinctive reaction is positive - I'm just wondering where additional drivers fit into this and whether it has the right degree of flexibility. This smells like a loop over an array of drivers is becoming sensible. As below. Trivial, but don't want a comma on that NULL. Ah. An there's our reason for an int. Can we just add a MMOP enum value for not configured yet and so let us use it as an enum? Or have a separate bool for that and ignore the online_type until it's set.
{ "author": "Jonathan Cameron <jonathan.cameron@huawei.com>", "date": "Mon, 2 Feb 2026 18:20:15 +0000", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH 0/9] cxl: explicit DAX driver selection and hotplug
Currently, CXL regions that create DAX devices have no mechanism to control select the hotplug online policy for kmem regions at region creation time. Users must either rely on a build-time default or manually configure each memory block after hotplug occurs. Additionally, there is no explicit way to choose between device_dax and dax_kmem modes at region creation time - regions default to kmem. This series addresses both issues by: 1. Plumbing an online_type parameter through the memory hotplug path, from mm/memory_hotplug through the DAX layer, enabling drivers to specify the desired policy (offline, online, online_movable). 2. Adding infrastructure for explicit dax driver selection (kmem vs device) when creating CXL DAX regions. 3. Introducing new CXL region drivers that provide a two-stage binding process with user-configurable policy between region creation and memory hotplug. The new drivers are: - cxl_devdax_region: Creates dax_regions that bind to device_dax driver - cxl_sysram_region: Creates sysram_region devices with hotplug policy - cxl_dax_kmem_region: Probes sysram_regions to create kmem dax_regions The sysram_region device exposes an 'online_type' sysfs attribute allowing users to configure the memory online type before hotplug: echo region0 > cxl_sysram_region/bind echo online_movable > sysram_region0/online_type echo sysram_region0 > cxl_dax_kmem_region/bind This enables explicit control over both the dax driver mode and the memory hotplug policy for CXL memory regions. In the future, with DCD regions, this will also provide a policy step which dictates how extents will be surfaces and managed (e.g. if the dc region is bound to the sysram driver, it will surface as system memory, while the devdax driver will surface extents as new devdax). Gregory Price (9): mm/memory_hotplug: pass online_type to online_memory_block() via arg mm/memory_hotplug: add __add_memory_driver_managed() with online_type arg dax: plumb online_type from dax_kmem creators to hotplug drivers/cxl,dax: add dax driver mode selection for dax regions cxl/core/region: move pmem region driver logic into pmem_region cxl/core/region: move dax region device logic into dax_region.c cxl/core: add cxl_devdax_region driver for explicit userland region binding cxl/core: Add dax_kmem_region and sysram_region drivers Documentation/driver-api/cxl: add dax and sysram driver documentation Documentation/ABI/testing/sysfs-bus-cxl | 21 ++ .../driver-api/cxl/linux/cxl-driver.rst | 43 +++ .../driver-api/cxl/linux/dax-driver.rst | 29 ++ drivers/cxl/core/Makefile | 3 + drivers/cxl/core/core.h | 11 + drivers/cxl/core/dax_region.c | 179 ++++++++++ drivers/cxl/core/pmem_region.c | 191 +++++++++++ drivers/cxl/core/port.c | 2 + drivers/cxl/core/region.c | 321 ++---------------- drivers/cxl/core/sysram_region.c | 180 ++++++++++ drivers/cxl/cxl.h | 29 ++ drivers/dax/bus.c | 3 + drivers/dax/bus.h | 7 +- drivers/dax/cxl.c | 7 +- drivers/dax/dax-private.h | 2 + drivers/dax/hmem/hmem.c | 2 + drivers/dax/kmem.c | 13 +- drivers/dax/pmem.c | 2 + include/linux/dax.h | 5 + include/linux/memory_hotplug.h | 3 + mm/memory_hotplug.c | 95 ++++-- 21 files changed, 826 insertions(+), 322 deletions(-) create mode 100644 drivers/cxl/core/dax_region.c create mode 100644 drivers/cxl/core/pmem_region.c create mode 100644 drivers/cxl/core/sysram_region.c -- 2.52.0
On Mon, Feb 02, 2026 at 06:20:15PM +0000, Jonathan Cameron wrote: I think the latter is more reasonably, MMOP_UNCONFIGURED doesn't much make sense for memory_hotplug.c ack. ~Gregory
{ "author": "Gregory Price <gourry@gourry.net>", "date": "Mon, 2 Feb 2026 13:23:37 -0500", "thread_id": "aYDmor_ruasxaZ-7@gourry-fedora-PF4VCD3F.mbox.gz" }
lkml
[PATCH v7 0/2] init/initramfs.c: make initramfs support pivot_root
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> As Luis Chamberlain suggested, I split the patch: [init/initramfs.c: make initramfs support pivot_root] (https://lore.kernel.org/linux-fsdevel/20210520154244.20209-1-dong.menglong@zte.com.cn/) into three. The goal of the series patches is to make pivot_root() support initramfs. In the first patch, I introduce the function ramdisk_exec_exist(), which is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN lookup mode. In the second patch, I create a second mount, which is called 'user root', and make it become the root. Therefore, the root has a parent mount, and it can be umounted or pivot_root. In the third patch, I fix rootfs_fs_type with ramfs, as it is not used directly any more, and it make no sense to switch it between ramfs and tmpfs, just fix it with ramfs to simplify the code. Changes since V6: Fix some bugs by Zhang Yunkai. Changes since V5: Remove the third patch and make it combined with the second one. Changes since V4: Do some more code cleanup for the second patch, include: - move 'ramdisk_exec_exist()' to 'init.h' - remove unnecessary struct 'fs_rootfs_root' - introduce 'revert_mount_rootfs()' - [...] Changes since V3: Do a code cleanup for the second patch, as Christian Brauner suggested: - remove the concept 'user root', which seems not suitable. - introduce inline function 'check_tmpfs_enabled()' to avoid duplicated code. - rename function 'mount_user_root' to 'prepare_mount_rootfs' - rename function 'end_mount_user_root' to 'finish_mount_rootfs' - join 'init_user_rootfs()' with 'prepare_mount_rootfs()' Changes since V2: In the first patch, I use vfs_path_lookup() in init_eaccess() to make the path lookup follow the mount on '/'. After this, the problem reported by Masami Hiramatsu is solved. Thanks for your report :/ Changes since V1: In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make it support the check of filesystem mounted on '/'. In the second patch, I control 'user root' with kconfig option 'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain suggested. In the third patch, I make 'rootfs_fs_type' in control of 'CONFIG_INITRAMFS_USER_ROOT'. Zhang Yunkai (2): init/main.c: introduce function ramdisk_exec_exist() init/do_mounts.c: create second mount for initramfs fs/init.c | 11 +++++++++-- include/linux/init.h | 1 + init/do_mounts.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 17 ++++++++++++++++- init/initramfs.c | 12 +++++++++++- init/main.c | 7 ++++++- usr/Kconfig | 10 ++++++++++ 7 files changed, 98 insertions(+), 5 deletions(-) -- 2.25.1
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> Introduce the function ramdisk_exec_exist, which is used to check the exist of 'ramdisk_execute_command'. To make path lookup follow the mount on '/', use vfs_path_lookup() in init_eaccess(), and make the filesystem that mounted on '/' as root during path lookup. Reported-by: Menglong Dong <dong.menglong@zte.com.cn> Signed-off-by: Zhang Yunkai <zhang.yunkai@zte.com.cn> --- fs/init.c | 11 +++++++++-- include/linux/init.h | 1 + init/main.c | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fs/init.c b/fs/init.c index 5c36adaa9b44..166356a1f15f 100644 --- a/fs/init.c +++ b/fs/init.c @@ -112,14 +112,21 @@ int __init init_chmod(const char *filename, umode_t mode) int __init init_eaccess(const char *filename) { - struct path path; + struct path path, root; int error; - error = kern_path(filename, LOOKUP_FOLLOW, &path); + error = kern_path("/", LOOKUP_DOWN, &root); if (error) return error; + error = vfs_path_lookup(root.dentry, root.mnt, filename, + LOOKUP_FOLLOW, &path); + if (error) + goto on_err; error = path_permission(&path, MAY_ACCESS); + path_put(&path); +on_err: + path_put(&root); return error; } diff --git a/include/linux/init.h b/include/linux/init.h index d82b4b2e1d25..889d538b6dfa 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -149,6 +149,7 @@ extern unsigned int reset_devices; void setup_arch(char **); void prepare_namespace(void); void __init init_rootfs(void); +bool ramdisk_exec_exist(void); extern struct file_system_type rootfs_fs_type; #if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_STRICT_MODULE_RWX) diff --git a/init/main.c b/init/main.c index bb984ed79de0..ed1c63f4ed87 100644 --- a/init/main.c +++ b/init/main.c @@ -1577,6 +1577,11 @@ void __init console_on_rootfs(void) fput(file); } +bool __init ramdisk_exec_exist(void) +{ + return init_eaccess(ramdisk_execute_command) == 0; +} + static noinline void __init kernel_init_freeable(void) { /* Now the scheduler is fully set up and can do blocking allocations */ @@ -1618,7 +1623,7 @@ static noinline void __init kernel_init_freeable(void) * check if there is an early userspace init. If yes, let it do all * the work */ - if (init_eaccess(ramdisk_execute_command) != 0) { + if (!ramdisk_exec_exist()) { ramdisk_execute_command = NULL; prepare_namespace(); } -- 2.25.1
{ "author": "cgel.zte@gmail.com", "date": "Mon, 17 Jan 2022 13:43:51 +0000", "thread_id": "20260202145234.2245271-1-safinaskar@gmail.com.mbox.gz" }
lkml
[PATCH v7 0/2] init/initramfs.c: make initramfs support pivot_root
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> As Luis Chamberlain suggested, I split the patch: [init/initramfs.c: make initramfs support pivot_root] (https://lore.kernel.org/linux-fsdevel/20210520154244.20209-1-dong.menglong@zte.com.cn/) into three. The goal of the series patches is to make pivot_root() support initramfs. In the first patch, I introduce the function ramdisk_exec_exist(), which is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN lookup mode. In the second patch, I create a second mount, which is called 'user root', and make it become the root. Therefore, the root has a parent mount, and it can be umounted or pivot_root. In the third patch, I fix rootfs_fs_type with ramfs, as it is not used directly any more, and it make no sense to switch it between ramfs and tmpfs, just fix it with ramfs to simplify the code. Changes since V6: Fix some bugs by Zhang Yunkai. Changes since V5: Remove the third patch and make it combined with the second one. Changes since V4: Do some more code cleanup for the second patch, include: - move 'ramdisk_exec_exist()' to 'init.h' - remove unnecessary struct 'fs_rootfs_root' - introduce 'revert_mount_rootfs()' - [...] Changes since V3: Do a code cleanup for the second patch, as Christian Brauner suggested: - remove the concept 'user root', which seems not suitable. - introduce inline function 'check_tmpfs_enabled()' to avoid duplicated code. - rename function 'mount_user_root' to 'prepare_mount_rootfs' - rename function 'end_mount_user_root' to 'finish_mount_rootfs' - join 'init_user_rootfs()' with 'prepare_mount_rootfs()' Changes since V2: In the first patch, I use vfs_path_lookup() in init_eaccess() to make the path lookup follow the mount on '/'. After this, the problem reported by Masami Hiramatsu is solved. Thanks for your report :/ Changes since V1: In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make it support the check of filesystem mounted on '/'. In the second patch, I control 'user root' with kconfig option 'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain suggested. In the third patch, I make 'rootfs_fs_type' in control of 'CONFIG_INITRAMFS_USER_ROOT'. Zhang Yunkai (2): init/main.c: introduce function ramdisk_exec_exist() init/do_mounts.c: create second mount for initramfs fs/init.c | 11 +++++++++-- include/linux/init.h | 1 + init/do_mounts.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 17 ++++++++++++++++- init/initramfs.c | 12 +++++++++++- init/main.c | 7 ++++++- usr/Kconfig | 10 ++++++++++ 7 files changed, 98 insertions(+), 5 deletions(-) -- 2.25.1
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> If using container platforms such as Docker, upon initialization it wants to use pivot_root() so that currently mounted devices do not propagate to containers. An example of value in this is that a USB device connected prior to the creation of a containers on the host gets disconnected after a container is created; if the USB device was mounted on containers, but already removed and umounted on the host, the mount point will not go away until all containers unmount the USB device. Another reason for container platforms such as Docker to use pivot_root is that upon initialization the net-namspace is mounted under /var/run/docker/netns/ on the host by dockerd. Without pivot_root Docker must either wait to create the network namespace prior to the creation of containers or simply deal with leaking this to each container. pivot_root is supported if the rootfs is a initrd or block device, but it's not supported if the rootfs uses an initramfs (tmpfs). This means container platforms today must resort to using block devices if they want to pivot_root from the rootfs. A workaround to use chroot() is not a clean viable option given every container will have a duplicate of every mount point on the host. In order to support using container platforms such as Docker on all the supported rootfs types we must extend Linux to support pivot_root on initramfs as well. This patch does the work to do just that. pivot_root will unmount the mount of the rootfs from its parent mount and mount the new root to it. However, when it comes to initramfs, it donesn't work, because the root filesystem has not parent mount, which makes initramfs not supported by pivot_root. In order to make pivot_root supported on initramfs, we create a second mount with type of rootfs before unpacking cpio, and change root to this mount after unpacking. While mounting the second rootfs, 'rootflags' is passed, and it means that we can set options for the mount of rootfs in boot cmd now. For example, the size of tmpfs can be set with 'rootflags=size=1024M'. This patch is from: [init/initramfs.c: make initramfs support pivot_root] https://lore.kernel.org/all/20210605034447.92917-3-dong.menglong@zte.com.cn/ I fix some console bugs. Reported-by: dong.menglong@zte.com.cn Signed-off-by: Zhang Yunkai <zhang.yunkai@zte.com.cn> --- init/do_mounts.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 17 ++++++++++++++++- init/initramfs.c | 12 +++++++++++- usr/Kconfig | 10 ++++++++++ 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/init/do_mounts.c b/init/do_mounts.c index 762b534978d9..8a72c1fe17c8 100644 --- a/init/do_mounts.c +++ b/init/do_mounts.c @@ -650,6 +650,50 @@ void __init prepare_namespace(void) } static bool is_tmpfs; +#ifdef CONFIG_INITRAMFS_MOUNT + +/* + * Give systems running from the initramfs and making use of pivot_root a + * proper mount so it can be umounted during pivot_root. + */ +int __init prepare_mount_rootfs(void) +{ + char *rootfs = "ramfs"; + + if (is_tmpfs) + rootfs = "tmpfs"; + + init_mkdir("/root", 0700); + return do_mount_root(rootfs, rootfs, + root_mountflags & ~MS_RDONLY, + root_mount_data); +} + +/* + * Revert to previous mount by chdir to '/' and unmounting the second + * mount. + */ +void __init revert_mount_rootfs(void) +{ + init_chdir("/"); + init_umount(".", MNT_DETACH); +} + +/* + * Change root to the new rootfs that mounted in prepare_mount_rootfs() + * if cpio is unpacked successfully and 'ramdisk_execute_command' exist. + */ +void __init finish_mount_rootfs(void) +{ + init_mount(".", "/", NULL, MS_MOVE, NULL); + if (likely(ramdisk_exec_exist())) + init_chroot("."); + else + revert_mount_rootfs(); +} + +#define rootfs_init_fs_context ramfs_init_fs_context +#else static int rootfs_init_fs_context(struct fs_context *fc) { if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs) @@ -657,6 +701,7 @@ static int rootfs_init_fs_context(struct fs_context *fc) return ramfs_init_fs_context(fc); } +#endif struct file_system_type rootfs_fs_type = { .name = "rootfs", diff --git a/init/do_mounts.h b/init/do_mounts.h index 7a29ac3e427b..ae4ab306caa9 100644 --- a/init/do_mounts.h +++ b/init/do_mounts.h @@ -10,9 +10,24 @@ #include <linux/root_dev.h> #include <linux/init_syscalls.h> +extern int root_mountflags; + void mount_block_root(char *name, int flags); void mount_root(void); -extern int root_mountflags; + +#ifdef CONFIG_INITRAMFS_MOUNT + +int prepare_mount_rootfs(void); +void finish_mount_rootfs(void); +void revert_mount_rootfs(void); + +#else + +static inline int prepare_mount_rootfs(void) { return 0; } +static inline void finish_mount_rootfs(void) { } +static inline void revert_mount_rootfs(void) { } + +#endif static inline __init int create_dev(char *name, dev_t dev) { diff --git a/init/initramfs.c b/init/initramfs.c index 2f3d96dc3db6..881fb8ea4352 100644 --- a/init/initramfs.c +++ b/init/initramfs.c @@ -17,6 +17,8 @@ #include <linux/init_syscalls.h> #include <linux/umh.h> +#include "do_mounts.h" + static ssize_t __init xwrite(struct file *file, const char *p, size_t count, loff_t *pos) { @@ -671,7 +673,12 @@ static void __init populate_initrd_image(char *err) static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) { /* Load the built in initramfs */ - char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size); + char *err; + + if (prepare_mount_rootfs()) + panic("Failed to mount rootfs\n"); + + err = unpack_to_rootfs(__initramfs_start, __initramfs_size); if (err) panic_show_mem("%s", err); /* Failed to decompress INTERNAL initramfs */ @@ -685,11 +692,14 @@ static void __init do_populate_rootfs(void *unused, async_cookie_t cookie) err = unpack_to_rootfs((char *)initrd_start, initrd_end - initrd_start); if (err) { + revert_mount_rootfs(); #ifdef CONFIG_BLK_DEV_RAM populate_initrd_image(err); #else printk(KERN_EMERG "Initramfs unpacking failed: %s\n", err); #endif + } else { + finish_mount_rootfs(); } done: diff --git a/usr/Kconfig b/usr/Kconfig index 8bbcf699fe3b..af2aeeef8635 100644 --- a/usr/Kconfig +++ b/usr/Kconfig @@ -52,6 +52,16 @@ config INITRAMFS_ROOT_GID If you are not sure, leave it set to "0". +config INITRAMFS_MOUNT + bool "Create second mount to make pivot_root() supported" + default y + help + Before unpacking cpio, create a second mount and make it become + the root filesystem. Therefore, initramfs will be supported by + pivot_root(). + + If container platforms is used with initramfs, say Y. + config RD_GZIP bool "Support initial ramdisk/ramfs compressed using gzip" default y -- 2.25.1
{ "author": "cgel.zte@gmail.com", "date": "Mon, 17 Jan 2022 13:43:52 +0000", "thread_id": "20260202145234.2245271-1-safinaskar@gmail.com.mbox.gz" }
lkml
[PATCH v7 0/2] init/initramfs.c: make initramfs support pivot_root
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> As Luis Chamberlain suggested, I split the patch: [init/initramfs.c: make initramfs support pivot_root] (https://lore.kernel.org/linux-fsdevel/20210520154244.20209-1-dong.menglong@zte.com.cn/) into three. The goal of the series patches is to make pivot_root() support initramfs. In the first patch, I introduce the function ramdisk_exec_exist(), which is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN lookup mode. In the second patch, I create a second mount, which is called 'user root', and make it become the root. Therefore, the root has a parent mount, and it can be umounted or pivot_root. In the third patch, I fix rootfs_fs_type with ramfs, as it is not used directly any more, and it make no sense to switch it between ramfs and tmpfs, just fix it with ramfs to simplify the code. Changes since V6: Fix some bugs by Zhang Yunkai. Changes since V5: Remove the third patch and make it combined with the second one. Changes since V4: Do some more code cleanup for the second patch, include: - move 'ramdisk_exec_exist()' to 'init.h' - remove unnecessary struct 'fs_rootfs_root' - introduce 'revert_mount_rootfs()' - [...] Changes since V3: Do a code cleanup for the second patch, as Christian Brauner suggested: - remove the concept 'user root', which seems not suitable. - introduce inline function 'check_tmpfs_enabled()' to avoid duplicated code. - rename function 'mount_user_root' to 'prepare_mount_rootfs' - rename function 'end_mount_user_root' to 'finish_mount_rootfs' - join 'init_user_rootfs()' with 'prepare_mount_rootfs()' Changes since V2: In the first patch, I use vfs_path_lookup() in init_eaccess() to make the path lookup follow the mount on '/'. After this, the problem reported by Masami Hiramatsu is solved. Thanks for your report :/ Changes since V1: In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make it support the check of filesystem mounted on '/'. In the second patch, I control 'user root' with kconfig option 'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain suggested. In the third patch, I make 'rootfs_fs_type' in control of 'CONFIG_INITRAMFS_USER_ROOT'. Zhang Yunkai (2): init/main.c: introduce function ramdisk_exec_exist() init/do_mounts.c: create second mount for initramfs fs/init.c | 11 +++++++++-- include/linux/init.h | 1 + init/do_mounts.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 17 ++++++++++++++++- init/initramfs.c | 12 +++++++++++- init/main.c | 7 ++++++- usr/Kconfig | 10 ++++++++++ 7 files changed, 98 insertions(+), 5 deletions(-) -- 2.25.1
On Mon, Jan 17, 2022 at 01:43:52PM +0000, cgel.zte@gmail.com wrote: Sorry if this was already answered. My understanding is that you have initramfs with docker installed on it and with one or more container images packed there. And the desire is to use this initramfs to run docker containers and for that you need to enable pivot_root for initramfs. Have you tried packing docker and the containers to a block image that can be loop-mounted from the initramfs? Then you can chroot to that loop mounted filesystem and there pivot_root will be available for docker. -- Sincerely yours, Mike.
{ "author": "Mike Rapoport <rppt@kernel.org>", "date": "Tue, 18 Jan 2022 09:41:02 +0200", "thread_id": "20260202145234.2245271-1-safinaskar@gmail.com.mbox.gz" }
lkml
[PATCH v7 0/2] init/initramfs.c: make initramfs support pivot_root
From: Zhang Yunkai <zhang.yunkai@zte.com.cn> As Luis Chamberlain suggested, I split the patch: [init/initramfs.c: make initramfs support pivot_root] (https://lore.kernel.org/linux-fsdevel/20210520154244.20209-1-dong.menglong@zte.com.cn/) into three. The goal of the series patches is to make pivot_root() support initramfs. In the first patch, I introduce the function ramdisk_exec_exist(), which is used to check the exist of 'ramdisk_execute_command' in LOOKUP_DOWN lookup mode. In the second patch, I create a second mount, which is called 'user root', and make it become the root. Therefore, the root has a parent mount, and it can be umounted or pivot_root. In the third patch, I fix rootfs_fs_type with ramfs, as it is not used directly any more, and it make no sense to switch it between ramfs and tmpfs, just fix it with ramfs to simplify the code. Changes since V6: Fix some bugs by Zhang Yunkai. Changes since V5: Remove the third patch and make it combined with the second one. Changes since V4: Do some more code cleanup for the second patch, include: - move 'ramdisk_exec_exist()' to 'init.h' - remove unnecessary struct 'fs_rootfs_root' - introduce 'revert_mount_rootfs()' - [...] Changes since V3: Do a code cleanup for the second patch, as Christian Brauner suggested: - remove the concept 'user root', which seems not suitable. - introduce inline function 'check_tmpfs_enabled()' to avoid duplicated code. - rename function 'mount_user_root' to 'prepare_mount_rootfs' - rename function 'end_mount_user_root' to 'finish_mount_rootfs' - join 'init_user_rootfs()' with 'prepare_mount_rootfs()' Changes since V2: In the first patch, I use vfs_path_lookup() in init_eaccess() to make the path lookup follow the mount on '/'. After this, the problem reported by Masami Hiramatsu is solved. Thanks for your report :/ Changes since V1: In the first patch, I add the flag LOOKUP_DOWN to init_eaccess(), to make it support the check of filesystem mounted on '/'. In the second patch, I control 'user root' with kconfig option 'CONFIG_INITRAMFS_USER_ROOT', and add some comments, as Luis Chamberlain suggested. In the third patch, I make 'rootfs_fs_type' in control of 'CONFIG_INITRAMFS_USER_ROOT'. Zhang Yunkai (2): init/main.c: introduce function ramdisk_exec_exist() init/do_mounts.c: create second mount for initramfs fs/init.c | 11 +++++++++-- include/linux/init.h | 1 + init/do_mounts.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ init/do_mounts.h | 17 ++++++++++++++++- init/initramfs.c | 12 +++++++++++- init/main.c | 7 ++++++- usr/Kconfig | 10 ++++++++++ 7 files changed, 98 insertions(+), 5 deletions(-) -- 2.25.1
cgel.zte@gmail.com: Exactly this problem solved by these two patchsets: https://lore.kernel.org/all/20251229-work-empty-namespace-v1-0-bfb24c7b061f@kernel.org/ https://lore.kernel.org/all/20260112-work-immutable-rootfs-v2-0-88dd1c34a204@kernel.org/ -- Askar Safin
{ "author": "Askar Safin <safinaskar@gmail.com>", "date": "Mon, 2 Feb 2026 17:52:33 +0300", "thread_id": "20260202145234.2245271-1-safinaskar@gmail.com.mbox.gz" }
lkml
[PATCH 1/1] mshv: Add comment about huge page mappings in guest physical address space
From: Michael Kelley <mhklinux@outlook.com> Huge page mappings in the guest physical address space depend on having matching alignment of the userspace address in the parent partition and of the guest physical address. Add a comment that captures this information. See the link to the mailing list thread. No code or functional change. Link: https://lore.kernel.org/linux-hyperv/aUrC94YvscoqBzh3@skinsburskii.localdomain/T/#m0871d2cae9b297fd397ddb8459e534981307c7dc Signed-off-by: Michael Kelley <mhklinux@outlook.com> --- drivers/hv/mshv_root_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..bc738ff4508e 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1389,6 +1389,20 @@ mshv_partition_ioctl_set_memory(struct mshv_partition *partition, if (mem.flags & BIT(MSHV_SET_MEM_BIT_UNMAP)) return mshv_unmap_user_memory(partition, mem); + /* + * If the userspace_addr and the guest physical address (as derived + * from the guest_pfn) have the same alignment modulo PMD huge page + * size, the MSHV driver can map any PMD huge pages to the guest + * physical address space as PMD huge pages. If the alignments do + * not match, PMD huge pages must be mapped as single pages in the + * guest physical address space. The MSHV driver does not enforce + * that the alignments match, and it invokes the hypervisor to set + * up correct functional mappings either way. See mshv_chunk_stride(). + * The caller of the ioctl is responsible for providing userspace_addr + * and guest_pfn values with matching alignments if it wants the guest + * to get the performance benefits of PMD huge page mappings of its + * physical address space to real system memory. + */ return mshv_map_user_memory(partition, mem); } -- 2.25.1
On Mon, Feb 02, 2026 at 08:51:01AM -0800, mhkelley58@gmail.com wrote: Thanks. However, I'd suggest to reduce this commet a lot and put the details into the commit message instead. Also, why this place? Why not a part of the function description instead, for example? Thanks, Stanislav
{ "author": "Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>", "date": "Mon, 2 Feb 2026 09:17:33 -0800", "thread_id": "SN6PR02MB41570BBE17C50675E94789FDD49AA@SN6PR02MB4157.namprd02.prod.outlook.com.mbox.gz" }
lkml
[PATCH 1/1] mshv: Add comment about huge page mappings in guest physical address space
From: Michael Kelley <mhklinux@outlook.com> Huge page mappings in the guest physical address space depend on having matching alignment of the userspace address in the parent partition and of the guest physical address. Add a comment that captures this information. See the link to the mailing list thread. No code or functional change. Link: https://lore.kernel.org/linux-hyperv/aUrC94YvscoqBzh3@skinsburskii.localdomain/T/#m0871d2cae9b297fd397ddb8459e534981307c7dc Signed-off-by: Michael Kelley <mhklinux@outlook.com> --- drivers/hv/mshv_root_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index 681b58154d5e..bc738ff4508e 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -1389,6 +1389,20 @@ mshv_partition_ioctl_set_memory(struct mshv_partition *partition, if (mem.flags & BIT(MSHV_SET_MEM_BIT_UNMAP)) return mshv_unmap_user_memory(partition, mem); + /* + * If the userspace_addr and the guest physical address (as derived + * from the guest_pfn) have the same alignment modulo PMD huge page + * size, the MSHV driver can map any PMD huge pages to the guest + * physical address space as PMD huge pages. If the alignments do + * not match, PMD huge pages must be mapped as single pages in the + * guest physical address space. The MSHV driver does not enforce + * that the alignments match, and it invokes the hypervisor to set + * up correct functional mappings either way. See mshv_chunk_stride(). + * The caller of the ioctl is responsible for providing userspace_addr + * and guest_pfn values with matching alignments if it wants the guest + * to get the performance benefits of PMD huge page mappings of its + * physical address space to real system memory. + */ return mshv_map_user_memory(partition, mem); } -- 2.25.1
From: Stanislav Kinsburskii <skinsburskii@linux.microsoft.com> Sent: Monday, February 2, 2026 9:18 AM In general, I'm very much an advocate of putting a bit more detail into code comments, so that someone new reading the code has a chance of figuring out what's going on without having to search through the commit history and read commit messages. The commit history is certainly useful for the historical record, and especially how things have changed over time. But for "how non-obvious things work now", I like to see that in the code comments. As for where to put the comment, I'm flexible. I thought about placing it outside the function as a "header" (which is what I think you mean by the "function description"), but the function handles both "map" and "unmap" operations, and this comment applies only to "map". Hence I put it after the test for whether we're doing "map" vs. "unmap". But I wouldn't object to it being placed as a function description, though the text would need to be enhanced to more broadly be a function description instead of just a comment about a specific aspect of "map" behavior. Michael
{ "author": "Michael Kelley <mhklinux@outlook.com>", "date": "Mon, 2 Feb 2026 18:26:42 +0000", "thread_id": "SN6PR02MB41570BBE17C50675E94789FDD49AA@SN6PR02MB4157.namprd02.prod.outlook.com.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Mon, Feb 2, 2026 at 1:47 AM Kairui Song <ryncsn@gmail.com> wrote: LGTM, thanks! Reviewed-by: Barry Song <baohua@kernel.org>
{ "author": "Barry Song <21cnbao@gmail.com>", "date": "Mon, 2 Feb 2026 00:46:32 +0800", "thread_id": "h334qa735tm7ejbamm4ki2zw73j2juvc4jg5xqxogcyqqvju5p@f4e73b3gqjlo.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Sun, Feb 1, 2026 at 9:47 AM Kairui Song <ryncsn@gmail.com> wrote: Acked-by: Chris Li <chrisl@kernel.org> Chris
{ "author": "Chris Li <chrisl@kernel.org>", "date": "Mon, 2 Feb 2026 10:22:45 -0800", "thread_id": "h334qa735tm7ejbamm4ki2zw73j2juvc4jg5xqxogcyqqvju5p@f4e73b3gqjlo.mbox.gz" }
lkml
[PATCH] mm/zswap: remove SWP_SYNCHRONOUS_IO swapcache bypass workaround
From: Kairui Song <kasong@tencent.com> Since commit f1879e8a0c60 ("mm, swap: never bypass the swap cache even for SWP_SYNCHRONOUS_IO"), all swap-in operations go through the swap cache, including those from SWP_SYNCHRONOUS_IO devices like zram. Which means the workaround for swap cache bypassing introduced by commit 25cd241408a2 ("mm: zswap: fix data loss on SWP_SYNCHRONOUS_IO devices") is no longer needed. Remove it, but keep the comments that are still helpful. Suggested-by: Yosry Ahmed <yosry.ahmed@linux.dev> Signed-off-by: Kairui Song <kasong@tencent.com> --- mm/zswap.c | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 3d2d59ac3f9c..8cd61603ff79 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1589,11 +1589,11 @@ int zswap_load(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); - bool swapcache = folio_test_swapcache(folio); struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); if (zswap_never_enabled()) return -ENOENT; @@ -1624,22 +1624,15 @@ int zswap_load(struct folio *folio) count_objcg_events(entry->objcg, ZSWPIN, 1); /* - * When reading into the swapcache, invalidate our entry. The - * swapcache can be the authoritative owner of the page and + * We are reading into the swapcache, invalidate zswap entry. + * The swapcache is the authoritative owner of the page and * its mappings, and the pressure that results from having two * in-memory copies outweighs any benefits of caching the * compression work. - * - * (Most swapins go through the swapcache. The notable - * exception is the singleton fault on SWP_SYNCHRONOUS_IO - * files, which reads into a private page and may free it if - * the fault fails. We remain the primary owner of the entry.) */ - if (swapcache) { - folio_mark_dirty(folio); - xa_erase(tree, offset); - zswap_entry_free(entry); - } + folio_mark_dirty(folio); + xa_erase(tree, offset); + zswap_entry_free(entry); folio_unlock(folio); return 0; --- base-commit: 2c263046cbe6d9d5fce3dfeba063f199f7e6298f change-id: 20251226-zswap-syncio-cleanup-a05b7fc6180f Best regards, -- Kairui Song <kasong@tencent.com>
On Mon, Feb 02, 2026 at 01:47:32AM +0800, Kairui Song wrote: Acked-by: Yosry Ahmed <yosry.ahmed@linux.dev> Thanks!
{ "author": "Yosry Ahmed <yosry.ahmed@linux.dev>", "date": "Mon, 2 Feb 2026 18:32:04 +0000", "thread_id": "h334qa735tm7ejbamm4ki2zw73j2juvc4jg5xqxogcyqqvju5p@f4e73b3gqjlo.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
On Mon, Feb 02, 2026 at 06:30:44PM +0530, Piyush Patle wrote: This link doesn't work. And the commit log has zero details of what's happening either.
{ "author": "Christoph Hellwig <hch@infradead.org>", "date": "Mon, 2 Feb 2026 06:48:50 -0800", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
On Mon, Feb 02, 2026 at 06:48:50AM -0800, Christoph Hellwig wrote: Looks like this one: https://syzkaller.appspot.com/bug?extid=bd5ca596a01d01bfa083 but there's no reproducer. Looks like it's through the blockdev rather than a filesystem being involved.
{ "author": "Matthew Wilcox <willy@infradead.org>", "date": "Mon, 2 Feb 2026 15:35:39 +0000", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
{ "author": "Piyush Patle <piyushpatle228@gmail.com>", "date": "Mon, 2 Feb 2026 21:10:30 +0530", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
iomap_iter_done() expects that the iterator position always lies within the current iomap range. However, during buffered writes combined with truncate or overwrite operations, the iterator position can advance past the end of the current iomap without the mapping being invalidated. When this happens, iomap_iter_done() triggers a warning because iomap.offset + iomap.length no longer covers iter->pos, even though this state can legitimately occur due to extent invalidation or write completion advancing the iterator position. Detect this condition immediately after iomap_begin(), mark the mapping as stale, reset the iterator state, and retry mapping from the current position. This ensures that iomap_end() invariants are preserved and prevents spurious warnings. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
{ "author": "Piyush Patle <piyushpatle228@gmail.com>", "date": "Mon, 2 Feb 2026 21:14:53 +0530", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
On Mon, Feb 02, 2026 at 03:35:39PM +0000, Matthew Wilcox wrote: Let's wait for a reproducer. The fix looks incorrect for anything I could think of, so I'd rather fix a real bug. Given that lack of reproducer I'm also not confident that it fixes anything. The fact that the Fixes tag points to a merge commit doesn't really increase the trust I have in it either.
{ "author": "Christoph Hellwig <hch@infradead.org>", "date": "Mon, 2 Feb 2026 08:05:48 -0800", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] iomap: handle iterator position advancing beyond current mapping
syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes. This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range. Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position. Fixes: a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation") Tested-by: Piyush Patle <piyushpatle288@gmail.com> Signed-off-by: Piyush Patle <piyushpatle228@gmail.com> Reported-by: syzbot+bd5ca596a01d01bfa083@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=bd5ca596a01d01bfa083 --- fs/iomap/iter.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/iomap/iter.c b/fs/iomap/iter.c index c04796f6e57f..466a12b0c094 100644 --- a/fs/iomap/iter.c +++ b/fs/iomap/iter.c @@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops) &iter->iomap, &iter->srcmap); if (ret < 0) return ret; + if (iter->iomap.length && + iter->iomap.offset + iter->iomap.length <= iter->pos) { + iter->iomap.flags |= IOMAP_F_STALE; + iomap_iter_reset_iomap(iter); + return 1; + } + iomap_iter_done(iter); return 1; } -- 2.34.1
On Mon, Feb 02, 2026 at 08:05:48AM -0800, Christoph Hellwig wrote: +1 to this, FWIW. I've had that syzbot report marked in my inbox expecting (hoping..) it would eventually spit out a reproducer to help better characterize the cause. This patch just appears to copy the warning check and force a lookup cycle before we trigger it, which I don't think is doing us any favors. At minimum we should have an understanding of precisely how this happens. Brian
{ "author": "Brian Foster <bfoster@redhat.com>", "date": "Mon, 2 Feb 2026 13:34:11 -0500", "thread_id": "aYDuI3EqwCmnc9uq@bfoster.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
Am Freitag, 30. Januar 2026, 09:41:31 CET schrieb ming.qian@oss.nxp.com: If I read the Datasheet correctly 600 MHz is only supported by overdrive mode (also depending on the VDD_VPU). Is this frequency really correct? Best regards, Alexander
{ "author": "Alexander Stein <alexander.stein@ew.tq-group.com>", "date": "Fri, 30 Jan 2026 10:09:46 +0100", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
Hi, Le vendredi 30 janvier 2026 à 16:41 +0800, ming.qian@oss.nxp.com a écrit : Tested on EVK, with the downstream DCSS driver, and this change triggers DCSS underrun (which is related to the DRAM QoS erratas on this SoC). It also sometimes trigger the "not all macroblock decoded" warning I added recently, and we can empty IRQs, but these are handled now. That probably only true with the upstream DCSS + a small resolution embedded panel ? Can you clarify this setup, because the display drivers mainline are very minimal. Would be nice to show you average DDR read/write bandwidth utilization during this run for comparision. Another information that bugs me, in the BSP code, the G2 voltage is increased too, which you didn't do here. They also use the thermal 2 zone to kick it down to 300 until it cools down. Nicolas
{ "author": "Nicolas Dufresne <nicolas@ndufresne.ca>", "date": "Fri, 30 Jan 2026 09:47:34 -0500", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
On Fri, Jan 30, 2026 at 10:09:46AM +0100, Alexander Stein wrote: G1 and BUS clk were already set as Overdrive frequency. This change is to only upgrading G2 from 300M to 600M. So if your question is should we downgrade all to Nominal mode, I think no. The freq could be override in board dts, or adding a new dts as arch/arm64/boot/dts/freescale/imx8mp-nominal.dtsi Regards Peng
{ "author": "Peng Fan <peng.fan@oss.nxp.com>", "date": "Mon, 2 Feb 2026 10:41:49 +0800", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
Hi Alexander, On 2/2/2026 10:41 AM, Peng Fan wrote: Yes, you are right, 600MHz is the Overdriver frequency. However, to achieve the 4K 60fps target, we set the VPU to run in overdrive mode by default, just as Peng said. Regards, Ming
{ "author": "\"Ming Qian(OSS)\" <ming.qian@oss.nxp.com>", "date": "Mon, 2 Feb 2026 13:56:47 +0800", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
Hi Nicolas, On 1/30/2026 10:47 PM, Nicolas Dufresne wrote: This doesn't sound like just a VPU issue; it's related to the display or DDR. If not displayed, do the fluster test cases yield different results at 600MHz and 300MHz? My display is hdmi, I'll try the DCSS. And the DDR bandwidth results measured by perf are as follows: Performance counter stats for 'system wide': 113303664278 imx8_ddr0/read-cycles/ 82457075530 imx8_ddr0/write-cycles/ 634.892101865 seconds time elapsed In our internal code, whenever the frequency of either g1 or g2 reaches 600MHz, the voltage is adjusted to 1.0V. Since g1 is already set to 600 MHz in the upstream DTS, I believe the default version is already 1.0v. And do you mean vpu-thermal? But it doesn't define the cooling-map, I'm not sure how it works. vpu-thermal { polling-delay-passive = <250>; polling-delay = <2000>; thermal-sensors = <&tmu 2>; trips { vpu-crit { temperature = <90000>; hysteresis = <2000>; type = "critical"; }; }; }; Regards, Ming
{ "author": "\"Ming Qian(OSS)\" <ming.qian@oss.nxp.com>", "date": "Mon, 2 Feb 2026 15:44:37 +0800", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH] arm64: dts: imx8mq: Restore VPU G2 clock to 600MHz for 4K60fps decoding
From: Ming Qian <ming.qian@oss.nxp.com> The VPU G2 clock was reduced from 600MHz to 300MHz in commit b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") to address pixel errors with high-resolution HEVC postprocessor output. However, testing shows the 300MHz clock rate is insufficient for 4K60fps decoding and the original pixel errors no longer occur at 600MHz with current drivers. Test results with 3840x2160@60fps HEVC stream decoded to NV12 (the same scenario that exhibited pixel errors previously): 300MHz performance: - Severe frame dropping throughout playback - Only 336 frames rendered in 11:53 (0.471 fps) - Continuous "A lot of buffers are being dropped" warnings - Completely unusable for 4K video 600MHz performance: - Smooth playback with only 1 frame dropped at startup - 37981 frames rendered in 10:34 (59.857 fps) - Achieves target 60fps performance - No pixel errors or artifacts observed Restore the clock to 600MHz to enable proper 4K60fps decoding capability while maintaining stability. Test pipeline: gst-launch-1.0 filesrc location=<4K60_HEVC.mkv> ! \ video/x-matroska ! aiurdemux ! h265parse ! \ v4l2slh265dec ! video/x-raw,format=NV12 ! \ queue ! waylandsink Fixes: b27bfc5103c7 ("arm64: dts: freescale: Fix VPU G2 clock") Signed-off-by: Ming Qian <ming.qian@oss.nxp.com> --- arch/arm64/boot/dts/freescale/imx8mq.dtsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/freescale/imx8mq.dtsi b/arch/arm64/boot/dts/freescale/imx8mq.dtsi index 607962f807be..731142176625 100644 --- a/arch/arm64/boot/dts/freescale/imx8mq.dtsi +++ b/arch/arm64/boot/dts/freescale/imx8mq.dtsi @@ -960,7 +960,7 @@ pgc_vpu: power-domain@6 { <&clk IMX8MQ_SYS1_PLL_800M>, <&clk IMX8MQ_VPU_PLL>; assigned-clock-rates = <600000000>, - <300000000>, + <600000000>, <800000000>, <0>; }; base-commit: c824345288d11e269ce41b36c105715bc2286050 prerequisite-patch-id: 0000000000000000000000000000000000000000 -- 2.52.0
Le lundi 02 février 2026 à 15:44 +0800, Ming Qian(OSS) a écrit : Didn't you run these tests before sending ? I can try again, but in my internal notes, I wrote: > Tested that, and everything becomes unstable That was before I figure-out the IRQ handler didn't handle exception bits that didn't stop the decoder (or dry IRQ, which strangely is common from the G2). Its not: $> cat /sys/kernel/debug/regulator/regulator_summary | grep SW1C SW1C 1 1 0 unknown 900mV 0mA 825mV 1100 Before I gave up on 60Hz on this SoC, I did test raising it to 1v with this patch (hopefully there is a way to do that in DT, would be more elegant): diff --git a/drivers/pmdomain/imx/gpcv2.c b/drivers/pmdomain/imx/gpcv2.c index 4b828d74a606..2f2b85ca6fd2 100644 --- a/drivers/pmdomain/imx/gpcv2.c +++ b/drivers/pmdomain/imx/gpcv2.c @@ -639,6 +639,7 @@ static const struct imx_pgc_domain imx8m_pgc_domains[] = { }, .pgc = BIT(IMX8M_PGC_VPU), .keep_clocks = true, + .voltage = 1000000, }, [IMX8M_POWER_DOMAIN_DISP] = { I would also like to remind you your own erratas, in the errata document you state that DRAM QoS is broken, and all transactions are treated with the same priority. If you overload the bandwidth, it becomes fatal for the display controller. We tried to workaround with changing the NoC configuration, but it did not work. It feels like that NoC granularity is not enough to prevent underrun of the display controller (where the QoS would work, since its done at transaction level, not by measuring bandwidth). Nicolas
{ "author": "Nicolas Dufresne <nicolas@ndufresne.ca>", "date": "Mon, 02 Feb 2026 13:44:28 -0500", "thread_id": "169eba79e8e1f906b1a0b59e22a531dfc7e57a1f.camel@ndufresne.ca.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Change '(x - 1) + x' to '2 * (x - 1) + 1' to avoid expanding the non-trivial __type_half_max() twice. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/overflow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/overflow.h b/include/linux/overflow.h index 736f633b2d5f..4f014d55ab25 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h @@ -31,7 +31,7 @@ * credit to Christian Biere. */ #define __type_half_max(type) ((type)1 << (8*sizeof(type) - 1 - is_signed_type(type))) -#define __type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) +#define __type_max(T) ((T)(2 * (__type_half_max(T) - 1) + 1)) #define type_max(t) __type_max(typeof(t)) #define __type_min(T) ((T)((T)-type_max(T)-(T)1)) #define type_min(t) __type_min(typeof(t)) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:18 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Since the type is always unsigned (T)-1 is always the correct value so there is no need to use type_max(). Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index a40cc861b3a7..697318f2a47d 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -45,8 +45,7 @@ */ #define GENMASK_TYPE(t, h, l) \ ((t)(GENMASK_INPUT_CHECK(h, l) + \ - (type_max(t) << (l) & \ - type_max(t) >> (BITS_PER_TYPE(t) - 1 - (h))))) + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h))))) #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:25 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. Change the BIT(PLANE_INDEX_BITS) != VIDEO_MAX_PLANES test to use static_assert() so the code compiles. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- drivers/media/common/videobuf2/videobuf2-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 2df566f409b6..90dedab2aeb2 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -37,9 +37,9 @@ #define MAX_BUFFER_INDEX BIT_MASK(30 - PLANE_INDEX_SHIFT) #define BUFFER_INDEX_MASK (MAX_BUFFER_INDEX - 1) -#if BIT(PLANE_INDEX_BITS) != VIDEO_MAX_PLANES -#error PLANE_INDEX_BITS order must be equal to VIDEO_MAX_PLANES -#endif + +static_assert(BIT(PLANE_INDEX_BITS) == VIDEO_MAX_PLANES, + "PLANE_INDEX_BITS order must be equal to VIDEO_MAX_PLANES"); static int debug; module_param(debug, int, 0644); -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:20 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The check for invalid 'compile time constant' parameters can easily be changed to return 'failed' rather than generating a compile time error. Add some tests for negative, swapped and overlarge values. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- lib/tests/test_bits.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 4d3a895f490c..9642c55f5487 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -144,6 +144,22 @@ static void genmask_input_check_test(struct kunit *test) BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0); BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0); BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0); + + /* + * Invalid input + * Change GENMASK_INPUT_CHECK() return 'fail' rather than + * generating a compile-time error. + */ +#define GENMASK_INPUT_CHECK_FAIL() 1 + z = 0; + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 31, -1, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 0, 1, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 8, 0, 8) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 16, 0, 16) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 32, 0, 32) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 64, 0, 64) == 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z + 128, 0, 128) == 0); +#undef GENMASK_INPUT_CHECK_FAIL } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:31 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Some compile time checks significantly bloat the pre-processor output (particularly when the get nested). Since the checks aren't really needed on every compilation enable with W=c (adds -DKBUILD_EXTRA_WARNc) so the checks can be enabled per-build. Make W=1 imply W=c so the build-bot includes the checks. As well as reducing the bloat from existing checks (like those in GENMASK() and FIELD_PREP()) it lets additional checks be added while there are still 'false positives' without breaking normal builds. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- scripts/Makefile.warn | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/Makefile.warn b/scripts/Makefile.warn index 68e6fafcb80c..e8a799850973 100644 --- a/scripts/Makefile.warn +++ b/scripts/Makefile.warn @@ -2,8 +2,9 @@ # ========================================================================== # make W=... settings # -# There are four warning groups enabled by W=1, W=2, W=3, and W=e -# They are independent, and can be combined like W=12 or W=123e. +# There are five warning groups enabled by W=c, W=1, W=2, W=3, and W=e +# They are independent, and can be combined like W=12 or W=123e, +# except that W=1 implies W=c. # ========================================================================== # Default set of warnings, always enabled @@ -109,6 +110,13 @@ KBUILD_CFLAGS += $(call cc-option,-Wenum-conversion) KBUILD_CFLAGS += -Wunused +# +# W=c - Expensive compile-time checks, implied by W=1 +# +ifneq ($(findstring c, $(KBUILD_EXTRA_WARN))$(findstring 1, $(KBUILD_EXTRA_WARN)),) +KBUILD_CPPFLAGS += -DKBUILD_EXTRA_WARNc +endif + # # W=1 - warnings which may be relevant and do not occur too often # -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:19 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. Change the FRAC_ACC != BDS_UNIT test to use static_assert() so the code compiles. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- .../kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h b/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h index f7e5669d5125..31bce7b2650e 100644 --- a/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h +++ b/drivers/staging/media/atomisp/pci/isp/kernels/fixedbds/fixedbds_1.0/ia_css_fixedbds_param.h @@ -13,9 +13,8 @@ #define BDS_UNIT 8 #define FRAC_LOG 3 #define FRAC_ACC BIT(FRAC_LOG) -#if FRAC_ACC != BDS_UNIT -#error "FRAC_ACC and BDS_UNIT need to be merged into one define" -#endif +static_assert(FRAC_ACC == BDS_UNIT, + "FRAC_ACC and BDS_UNIT need to be merged into one define"); struct sh_css_isp_bds_params { int baf_strength; -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:21 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> asm/tlb.h isn't part of the vdso, use the linux/bits.h header. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- arch/x86/include/asm/tlb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/tlb.h b/arch/x86/include/asm/tlb.h index 866ea78ba156..e61c6de73e70 100644 --- a/arch/x86/include/asm/tlb.h +++ b/arch/x86/include/asm/tlb.h @@ -7,7 +7,7 @@ static inline void tlb_flush(struct mmu_gather *tlb); #include <asm-generic/tlb.h> #include <linux/kernel.h> -#include <vdso/bits.h> +#include <linux/bits.h> #include <vdso/page.h> static inline void tlb_flush(struct mmu_gather *tlb) -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:24 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Casting the value of BIT_U*() and GENMASK_U8() to (u8) is pointless. Although it changes what typeof(BIT_U8()) returns the value will always be promoted to 'signed int' before it is used. Instead force the expression to be an unsigned type. Avoids unexpected sign extension from, for example: u64 v = BIT_U8(7) << 24; Fix the KUNIT tests to match. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 6 +++--- lib/tests/test_bits.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 697318f2a47d..23bc94815569 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -44,8 +44,8 @@ * - GENMASK_U32(33, 15): doesn't fit in a u32 */ #define GENMASK_TYPE(t, h, l) \ - ((t)(GENMASK_INPUT_CHECK(h, l) + \ - ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h))))) + ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ + ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) @@ -67,7 +67,7 @@ #define BIT_INPUT_CHECK(type, nr) \ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) -#define BIT_TYPE(type, nr) ((type)(BIT_INPUT_CHECK(type, nr) + BIT_ULL(nr))) +#define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index ab88e50d2edf..55be8230f9e7 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -9,20 +9,20 @@ #define assert_type(t, x) _Generic(x, t: x, default: 0) -static_assert(assert_type(u8, BIT_U8(0)) == 1u); -static_assert(assert_type(u16, BIT_U16(0)) == 1u); +static_assert(assert_type(unsigned int, BIT_U8(0)) == 1u); +static_assert(assert_type(unsigned int, BIT_U16(0)) == 1u); static_assert(assert_type(u32, BIT_U32(0)) == 1u); static_assert(assert_type(u64, BIT_U64(0)) == 1ull); -static_assert(assert_type(u8, BIT_U8(7)) == 0x80u); -static_assert(assert_type(u16, BIT_U16(15)) == 0x8000u); +static_assert(assert_type(unsigned int, BIT_U8(7)) == 0x80u); +static_assert(assert_type(unsigned int, BIT_U16(15)) == 0x8000u); static_assert(assert_type(u32, BIT_U32(31)) == 0x80000000u); static_assert(assert_type(u64, BIT_U64(63)) == 0x8000000000000000ull); static_assert(assert_type(unsigned long, GENMASK(31, 0)) == U32_MAX); static_assert(assert_type(unsigned long long, GENMASK_ULL(63, 0)) == U64_MAX); -static_assert(assert_type(u8, GENMASK_U8(7, 0)) == U8_MAX); -static_assert(assert_type(u16, GENMASK_U16(15, 0)) == U16_MAX); +static_assert(assert_type(unsigned int, GENMASK_U8(7, 0)) == U8_MAX); +static_assert(assert_type(unsigned int, GENMASK_U16(15, 0)) == U16_MAX); static_assert(assert_type(u32, GENMASK_U32(31, 0)) == U32_MAX); static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX); -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:26 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> thread_info_tif.h isn't part of the vdso, use the linux/bits.h header. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/asm-generic/thread_info_tif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/asm-generic/thread_info_tif.h b/include/asm-generic/thread_info_tif.h index da1610a78f92..afdc23204674 100644 --- a/include/asm-generic/thread_info_tif.h +++ b/include/asm-generic/thread_info_tif.h @@ -2,7 +2,7 @@ #ifndef _ASM_GENERIC_THREAD_INFO_TIF_H_ #define _ASM_GENERIC_THREAD_INFO_TIF_H_ -#include <vdso/bits.h> +#include <linux/bits.h> /* Bits 16-31 are reserved for architecture specific purposes */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:23 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The assembler only supports one type of signed integers, so expressions using BITS_PER_LONG (etc) cannot be guaranteed to be correct. Use ((2 << (h)) - (1 << (l))) for all assembler GENMASK() expansions and add definitions of BIT_Uxx() as (1 << (nr)). Note that 64bit results are (probably) only correct for 64bit builds and 128bits results will never be valid. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 23bc94815569..43631a334314 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -19,14 +19,6 @@ */ #if !defined(__ASSEMBLY__) -/* - * Missing asm support - * - * GENMASK_U*() and BIT_U*() depend on BITS_PER_TYPE() which relies on sizeof(), - * something not available in asm. Nevertheless, fixed width integers is a C - * concept. Assembly code can rely on the long and long long versions instead. - */ - #include <linux/build_bug.h> #include <linux/compiler.h> #include <linux/overflow.h> @@ -46,6 +38,7 @@ #define GENMASK_TYPE(t, h, l) \ ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) +#endif #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) #define GENMASK_ULL(h, l) GENMASK_TYPE(unsigned long long, h, l) @@ -56,9 +49,10 @@ #define GENMASK_U64(h, l) GENMASK_TYPE(u64, h, l) #define GENMASK_U128(h, l) GENMASK_TYPE(u128, h, l) +#if !defined(__ASSEMBLY__) /* - * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). The - * following examples generate compiler warnings due to -Wshift-count-overflow: + * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). + * The following examples generate compiler warnings from BIT_INPUT_CHECK(). * * - BIT_U8(8) * - BIT_U32(-1) @@ -68,21 +62,28 @@ BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) #define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) +#endif /* defined(__ASSEMBLY__) */ #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) #define BIT_U32(nr) BIT_TYPE(u32, nr) #define BIT_U64(nr) BIT_TYPE(u64, nr) -#else /* defined(__ASSEMBLY__) */ +#if defined(__ASSEMBLY__) /* - * BUILD_BUG_ON_ZERO is not available in h files included from asm files, - * disable the input check if that is the case. + * The assmebler only supports one size of signed integer rather than + * the fixed width integer types of C. + * There is also no method for reported invalid input. + * Error in .h files will usually be picked up when compiled into C files. + * + * Define type-size agnostic definitions that generate the correct value + * provided it can be represented by the assembler. */ -#define GENMASK(h, l) __GENMASK(h, l) -#define GENMASK_ULL(h, l) __GENMASK_ULL(h, l) -#endif /* !defined(__ASSEMBLY__) */ +#define GENMASK_TYPE(t, h, l) ((2 << (h)) - (1 << (l))) +#define BIT_TYPE(type, nr) (1 << (nr)) + +#endif /* defined(__ASSEMBLY__) */ #endif /* __LINUX_BITS_H */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:27 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Compile-time tests being added to BIT() make it an 'integer constant expression' rather than a pre-processor expression for W=1 builds. This means BIT() can't be used in pre-processor conditional that checks 'PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD'. Change to use a normal 'if' statement, the compiler will optimise away the unwanted code. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c index d5ce20f47def..65dd5834d0cf 100644 --- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c +++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c @@ -4166,9 +4166,6 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb, u32 tx_flags = 0; u16 count = TXD_USE_COUNT(skb_headlen(skb)); struct ixgbevf_ipsec_tx_data ipsec_tx = { 0 }; -#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD - unsigned short f; -#endif u8 hdr_len = 0; u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL); @@ -4183,15 +4180,15 @@ static int ixgbevf_xmit_frame_ring(struct sk_buff *skb, * + 1 desc for context descriptor, * otherwise try next time */ -#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD - for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { - skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; + if (PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD) { + for (unsigned int f = 0; f < skb_shinfo(skb)->nr_frags; f++) { + skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; - count += TXD_USE_COUNT(skb_frag_size(frag)); + count += TXD_USE_COUNT(skb_frag_size(frag)); + } + } else { + count += skb_shinfo(skb)->nr_frags; } -#else - count += skb_shinfo(skb)->nr_frags; -#endif if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) { tx_ring->tx_stats.tx_busy++; return NETDEV_TX_BUSY; -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:22 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The current checks in GENMASK/BIT (eg reversed high/low) only work for 'integer constant expressions' not 'compile-time constants'. This is true for const_true() and -Wshift-count-overflow/negative. While compile-time constants may be unusual, they can happen through function inlining. This isn't too bad with gcc, but if clang detects a negative/over-large shift it treats it as 'undefined behaviour' and silently discards all code that would use the result, so: int f(u32 x) {int n = 32; return x >> n; } generates a function that just contains a 'return' instruction. If 'n' was a variable that happened to be 32, most modern cpu mask the count - so would return 'x', some might return 0. Add extra checks for arguments that pass __builtin_constant_p() but are not 'integer constant expressions. __builtin_choose_expr() isn't strong enough to allow _Static_assert() or ({ ... }) in the other branch so non-standard schemes are used to report the errors. To reduce pre-processor bloat the checks are only enabled for W=c (implied by W=1) builds (where they are errors). Update the unit tests to match. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 45 +++++++++++++++++++++++++++++++++---------- lib/tests/test_bits.c | 34 +++++++++++++++++++------------- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 43631a334314..0f559038981d 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -23,20 +23,35 @@ #include <linux/compiler.h> #include <linux/overflow.h> -#define GENMASK_INPUT_CHECK(h, l) BUILD_BUG_ON_ZERO(const_true((l) > (h))) +#ifndef KBUILD_EXTRA_WARNc +#define GENMASK_INPUT_CHECK(h, l, width) 0 +#else +int GENMASK_INPUT_CHECK_FAIL(void) __compiletime_error("Invalid bit numbers"); +#define GENMASK_INPUT_CHECK(h, l, width) \ + (__builtin_choose_expr(__is_constexpr((l) > (h)), \ + sizeof(struct { char low_bit_greater_than_high[-((l) > (h))];}), \ + __builtin_constant_p((l) | (h)) && \ + ((l) < 0 || (l) > (h) || (h) >= width) && \ + GENMASK_INPUT_CHECK_FAIL())) +#endif /* - * Generate a mask for the specified type @t. Additional checks are made to - * guarantee the value returned fits in that type, relying on - * -Wshift-count-overflow compiler check to detect incompatible arguments. + * Generate a mask for the specified type @t. + * Checks are made to guarantee the value returned fits in that type. + * The compiler's -Wshift-count-overflow/negative check detects invalid values + * from 'constant integer expressions' but not other compile time constants. + * Clang treats out of value constants as 'undefined behaviour' and stops + * generating code - so explicit checks are needed. + * Neither BUILD_BUG() nor BUILD_BUG_ON_ZERO() can be used. + * * For example, all these create build errors or warnings: * * - GENMASK(15, 20): wrong argument order * - GENMASK(72, 15): doesn't fit unsigned long * - GENMASK_U32(33, 15): doesn't fit in a u32 */ -#define GENMASK_TYPE(t, h, l) \ - ((unsigned int)GENMASK_INPUT_CHECK(h, l) + \ +#define GENMASK_TYPE(t, h, l) \ + ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ((t)-1 << (l) & (t)-1 >> (BITS_PER_TYPE(t) - 1 - (h)))) #endif @@ -52,16 +67,26 @@ #if !defined(__ASSEMBLY__) /* * Fixed-type variants of BIT(), with additional checks like GENMASK_TYPE(). - * The following examples generate compiler warnings from BIT_INPUT_CHECK(). + * The following examples generate compiler errors from BIT_INPUT_CHECK(). * * - BIT_U8(8) * - BIT_U32(-1) * - BIT_U32(40) */ -#define BIT_INPUT_CHECK(type, nr) \ - BUILD_BUG_ON_ZERO(const_true((nr) >= BITS_PER_TYPE(type))) -#define BIT_TYPE(type, nr) ((unsigned int)BIT_INPUT_CHECK(type, nr) + ((type)1 << (nr))) +#ifndef KBUILD_EXTRA_WARNc +#define BIT_INPUT_CHECK(nr, width) 0 +#else +int BIT_INPUT_CHECK_FAIL(void) __compiletime_error("Bit number out of range"); +#define BIT_INPUT_CHECK(nr, width) \ + (__builtin_choose_expr(__is_constexpr(nr), \ + sizeof(struct { char bit_number_too_big[-((nr) >= (width))];}), \ + __builtin_constant_p(nr) && ((nr) < 0 || (nr) >= width) && \ + BIT_INPUT_CHECK_FAIL())) +#endif + +#define BIT_TYPE(type, nr) \ + ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) #endif /* defined(__ASSEMBLY__) */ #define BIT_U8(nr) BIT_TYPE(u8, nr) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 55be8230f9e7..36eb4661e78b 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -3,6 +3,8 @@ * Test cases for functions and macros in bits.h */ +#define KBUILD_EXTRA_WARNc 1 + #include <kunit/test.h> #include <linux/bits.h> #include <linux/types.h> @@ -118,24 +120,30 @@ static void genmask_u128_test(struct kunit *test) static void genmask_input_check_test(struct kunit *test) { - unsigned int x, y; - int z, w; + unsigned int x = 1, y = 2; + int z = 1, w = 2; + + OPTIMIZER_HIDE_VAR(x); + OPTIMIZER_HIDE_VAR(y); + OPTIMIZER_HIDE_VAR(z); + OPTIMIZER_HIDE_VAR(w); /* Unknown input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w, 32)); /* Valid input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1, 32)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21, 64)); + + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80, 128)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65, 128)); + KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0, 128)); } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:28 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> Since all the GENMASK() values are compile-time constants they can be tested with BUILD_BUG_ON() rather than KUNIT_EXPECT_EQ(). Signed-off-by: David Laight <david.laight.linux@gmail.com> --- lib/tests/test_bits.c | 90 +++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c index 36eb4661e78b..4d3a895f490c 100644 --- a/lib/tests/test_bits.c +++ b/lib/tests/test_bits.c @@ -32,30 +32,30 @@ static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX); static void __genmask_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ul, __GENMASK(0, 0)); - KUNIT_EXPECT_EQ(test, 3ul, __GENMASK(1, 0)); - KUNIT_EXPECT_EQ(test, 6ul, __GENMASK(2, 1)); - KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, __GENMASK(31, 0)); + BUILD_BUG_ON(__GENMASK(0, 0) != 1ul); + BUILD_BUG_ON(__GENMASK(1, 0) != 3ul); + BUILD_BUG_ON(__GENMASK(2, 1) != 6ul); + BUILD_BUG_ON(__GENMASK(31, 0) != 0xFFFFFFFFul); } static void __genmask_ull_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ull, __GENMASK_ULL(0, 0)); - KUNIT_EXPECT_EQ(test, 3ull, __GENMASK_ULL(1, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, __GENMASK_ULL(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, __GENMASK_ULL(63, 0)); + BUILD_BUG_ON(__GENMASK_ULL(0, 0) != 1ull); + BUILD_BUG_ON(__GENMASK_ULL(1, 0) != 3ull); + BUILD_BUG_ON(__GENMASK_ULL(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(__GENMASK_ULL(63, 0) != 0xffffffffffffffffull); } static void genmask_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ul, GENMASK(0, 0)); - KUNIT_EXPECT_EQ(test, 3ul, GENMASK(1, 0)); - KUNIT_EXPECT_EQ(test, 6ul, GENMASK(2, 1)); - KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, GENMASK(31, 0)); + BUILD_BUG_ON(GENMASK(0, 0) != 1ul); + BUILD_BUG_ON(GENMASK(1, 0) != 3ul); + BUILD_BUG_ON(GENMASK(2, 1) != 6ul); + BUILD_BUG_ON(GENMASK(31, 0) != 0xFFFFFFFFul); - KUNIT_EXPECT_EQ(test, 1u, GENMASK_U8(0, 0)); - KUNIT_EXPECT_EQ(test, 3u, GENMASK_U16(1, 0)); - KUNIT_EXPECT_EQ(test, 0x10000, GENMASK_U32(16, 16)); + BUILD_BUG_ON(GENMASK_U8(0, 0) != 1u); + BUILD_BUG_ON(GENMASK_U16(1, 0) != 3u); + BUILD_BUG_ON(GENMASK_U32(16, 16) != 0x10000); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ @@ -75,10 +75,10 @@ static void genmask_test(struct kunit *test) static void genmask_ull_test(struct kunit *test) { - KUNIT_EXPECT_EQ(test, 1ull, GENMASK_ULL(0, 0)); - KUNIT_EXPECT_EQ(test, 3ull, GENMASK_ULL(1, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, GENMASK_ULL(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_ULL(63, 0)); + BUILD_BUG_ON(GENMASK_ULL(0, 0) != 1ull); + BUILD_BUG_ON(GENMASK_ULL(1, 0) != 3ull); + BUILD_BUG_ON(GENMASK_ULL(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(GENMASK_ULL(63, 0) != 0xffffffffffffffffull); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ @@ -92,23 +92,23 @@ static void genmask_u128_test(struct kunit *test) { #ifdef CONFIG_ARCH_SUPPORTS_INT128 /* Below 64 bit masks */ - KUNIT_EXPECT_EQ(test, 0x0000000000000001ull, GENMASK_U128(0, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000003ull, GENMASK_U128(1, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000006ull, GENMASK_U128(2, 1)); - KUNIT_EXPECT_EQ(test, 0x00000000ffffffffull, GENMASK_U128(31, 0)); - KUNIT_EXPECT_EQ(test, 0x000000ffffe00000ull, GENMASK_U128(39, 21)); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(63, 0)); + BUILD_BUG_ON(GENMASK_U128(0, 0) != 0x0000000000000001ull); + BUILD_BUG_ON(GENMASK_U128(1, 0) != 0x0000000000000003ull); + BUILD_BUG_ON(GENMASK_U128(2, 1) != 0x0000000000000006ull); + BUILD_BUG_ON(GENMASK_U128(31, 0) != 0x00000000ffffffffull); + BUILD_BUG_ON(GENMASK_U128(39, 21) != 0x000000ffffe00000ull); + BUILD_BUG_ON(GENMASK_U128(63, 0) != 0xffffffffffffffffull); /* Above 64 bit masks - only 64 bit portion can be validated once */ - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(64, 0) >> 1); - KUNIT_EXPECT_EQ(test, 0x00000000ffffffffull, GENMASK_U128(81, 50) >> 50); - KUNIT_EXPECT_EQ(test, 0x0000000000ffffffull, GENMASK_U128(87, 64) >> 64); - KUNIT_EXPECT_EQ(test, 0x0000000000ff0000ull, GENMASK_U128(87, 80) >> 64); - - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, GENMASK_U128(127, 0) >> 64); - KUNIT_EXPECT_EQ(test, 0xffffffffffffffffull, (u64)GENMASK_U128(127, 0)); - KUNIT_EXPECT_EQ(test, 0x0000000000000003ull, GENMASK_U128(127, 126) >> 126); - KUNIT_EXPECT_EQ(test, 0x0000000000000001ull, GENMASK_U128(127, 127) >> 127); + BUILD_BUG_ON(GENMASK_U128(64, 0) >> 1 != 0xffffffffffffffffull); + BUILD_BUG_ON(GENMASK_U128(81, 50) >> 50 != 0x00000000ffffffffull); + BUILD_BUG_ON(GENMASK_U128(87, 64) >> 64 != 0x0000000000ffffffull); + BUILD_BUG_ON(GENMASK_U128(87, 80) >> 64 != 0x0000000000ff0000ull); + + BUILD_BUG_ON(GENMASK_U128(127, 0) >> 64 != 0xffffffffffffffffull); + BUILD_BUG_ON((u64)GENMASK_U128(127, 0) != 0xffffffffffffffffull); + BUILD_BUG_ON(GENMASK_U128(127, 126) >> 126 != 0x0000000000000003ull); + BUILD_BUG_ON(GENMASK_U128(127, 127) >> 127 != 0x0000000000000001ull); #ifdef TEST_GENMASK_FAILURES /* these should fail compilation */ GENMASK_U128(0, 1); @@ -129,21 +129,21 @@ static void genmask_input_check_test(struct kunit *test) OPTIMIZER_HIDE_VAR(w); /* Unknown input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, 0, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, x, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(x, y, 32)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(x, 0, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(0, x, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(x, y, 32) != 0); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, 0, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(0, z, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(z, w, 32)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z, 0, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(0, z, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(z, w, 32) != 0); /* Valid input */ - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(1, 1, 32)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(39, 21, 64)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(1, 1, 32) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(39, 21, 64) != 0); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(100, 80, 128)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(110, 65, 128)); - KUNIT_EXPECT_EQ(test, 0, GENMASK_INPUT_CHECK(127, 0, 128)); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(100, 80, 128) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(110, 65, 128) != 0); + BUILD_BUG_ON(GENMASK_INPUT_CHECK(127, 0, 128) != 0); } -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:30 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
From: David Laight <david.laight.linux@gmail.com> The definition of BIT() was moved from linux/bits.h to vdso/bits.h to isolate the vdso from 'normal' kernel headers. BIT_ULL() was then moved to be defined in the same place for consistency. Since then linux/bits.h had gained BIT_Unn() and it really makes sense for BIT() and BIT_ULL() to be defined in the same place. Move BIT_ULL() and make code that include both headers use the definition of BIT() from linux/bits.h Add BIT_U128() for completness. This lets BIT() pick up the extra compile time checks for W=[1c] builds that detect errors like: long foo(void) { int x = 64; return BIT(x); } For which clang (silently) just generates a 'return' instruction. Note that nothing the the x86-64 build relies on the definition in vdso/bits.h, linux/bits.h is always included. Signed-off-by: David Laight <david.laight.linux@gmail.com> --- include/linux/bits.h | 7 ++++++- include/vdso/bits.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/linux/bits.h b/include/linux/bits.h index 0f559038981d..3dd32b9eef35 100644 --- a/include/linux/bits.h +++ b/include/linux/bits.h @@ -2,7 +2,6 @@ #ifndef __LINUX_BITS_H #define __LINUX_BITS_H -#include <vdso/bits.h> #include <uapi/linux/bits.h> #define BIT_MASK(nr) (UL(1) << ((nr) % BITS_PER_LONG)) @@ -89,10 +88,16 @@ int BIT_INPUT_CHECK_FAIL(void) __compiletime_error("Bit number out of range"); ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) #endif /* defined(__ASSEMBLY__) */ +/* Prefer this definition of BIT() to the one in vdso/bits.h */ +#undef BIT +#define __VDSO_BITS_H +#define BIT(nr) BIT_TYPE(unsigned long, nr) +#define BIT_ULL(nr) BIT_TYPE(unsigned long long, nr) #define BIT_U8(nr) BIT_TYPE(u8, nr) #define BIT_U16(nr) BIT_TYPE(u16, nr) #define BIT_U32(nr) BIT_TYPE(u32, nr) #define BIT_U64(nr) BIT_TYPE(u64, nr) +#define BIT_U128(nr) BIT_TYPE(u128, nr) #if defined(__ASSEMBLY__) diff --git a/include/vdso/bits.h b/include/vdso/bits.h index 388b212088ea..a6ac1e6b637c 100644 --- a/include/vdso/bits.h +++ b/include/vdso/bits.h @@ -4,7 +4,7 @@ #include <vdso/const.h> +/* Most code picks up BIT() from linux/bits.h */ #define BIT(nr) (UL(1) << (nr)) -#define BIT_ULL(nr) (ULL(1) << (nr)) #endif /* __VDSO_BITS_H */ -- 2.39.5
{ "author": "david.laight.linux@gmail.com", "date": "Wed, 21 Jan 2026 14:57:29 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:29PM +0000, david.laight.linux@gmail.com wrote: This is ugly. Why can't the vDSO code make use of those checks, too? Or use _BITUL() from the UAPI in the vDSO and remove vdso/bits.h.
{ "author": "Thomas =?utf-8?Q?Wei=C3=9Fschuh?= <thomas.weissschuh@linutronix.de>", "date": "Wed, 21 Jan 2026 16:17:18 +0100", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On 21/01/2026 at 15:57, david.laight.linux@gmail.com wrote: Did those new checks actually found any real problem in the code? This adds a lot of complexity so I am not sure whether this is a winning trade-off. But then, you only solve that shift problem for GENMASK() and BIT(). Any other usage of the left/right shifts are not diagnosed unless your check get copy pasted all over the place. I think that such a check belongs to a static analyzer. Speaking of which: $ cat test.c typedef unsigned int u32; static int f(u32 x) {int n = 32; return x >> n; } $ sparse test.c test.c:2:46: warning: shift too big (32) for type unsigned int$ cat test.c So here, I would rather keep relying on sparse rather that introducing the W=c logic and all that macro complexity. Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Wed, 21 Jan 2026 19:43:07 +0100", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, 21 Jan 2026 19:43:07 +0100 Vincent Mailhol <mailhol@kernel.org> wrote: Not in an x86-64 allmodconfig build. They might in a 32bit one where there have definitely been issues. I suspect the compiler test will find more than sparse. I liked getting that to work, but maybe it is OTT. But the W=c is more generally useful. As well as removing all the compile-time tests from GENMASK() and (in another patch FIELD_PREP()) which really do bloat the .i file, I'd like to add some new tests to min/max/clamp to try to get rid of the more dodgy (and likely buggy) cases without breaking everyone's build - just failing the W=1 builds is better. Using a separate flag means you can use W=ce to stop the build, doing a W=1e build is hopeless. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Wed, 21 Jan 2026 19:14:48 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, 21 Jan 2026 16:17:18 +0100 Thomas Weißschuh <thomas.weissschuh@linutronix.de> wrote: It works :-) I could have put an #ifndef BIT in vdso/bits.h instead. I didn't actually find anything that just needed vdso/bits.h linux/bits.h would get included - eg (IIRC) because of warn_on_once(). I'm not that sure why it got separated, it isn't as though it defines anything that is code version specific. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Wed, 21 Jan 2026 19:24:51 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 02:57:18PM +0000, david.laight.linux@gmail.com wrote: Sure! Reviewed-by: Kees Cook <kees@kernel.org> -- Kees Cook
{ "author": "Kees Cook <kees@kernel.org>", "date": "Wed, 21 Jan 2026 12:59:36 -0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-13-david.laight.linux%40gmail.com patch subject: [PATCH next 12/14] bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h config: arm-allnoconfig (https://download.01.org/0day-ci/archive/20260122/202601220832.NJbHlnXC-lkp@intel.com/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 9b8addffa70cee5b2acc5454712d9cf78ce45710) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220832.NJbHlnXC-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220832.NJbHlnXC-lkp@intel.com/ All errors (new ones prefixed by >>): 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:139:8: note: expanded from macro '_SIG_SET_BINOP' 139 | b3 = b->sig[3]; b2 = b->sig[2]; \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 2 is past the end of the array (that has type 'const unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:139:24: note: expanded from macro '_SIG_SET_BINOP' 139 | b3 = b->sig[3]; b2 = b->sig[2]; \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:140:3: note: expanded from macro '_SIG_SET_BINOP' 140 | r->sig[3] = op(a3, b3); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:163:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 163 | _SIG_SET_BINOP(sigandnsets, _sig_andn) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:141:3: note: expanded from macro '_SIG_SET_BINOP' 141 | r->sig[2] = op(a2, b2); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:174:27: note: expanded from macro '_SIG_SET_OP' 174 | case 4: set->sig[3] = op(set->sig[3]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 3 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:174:10: note: expanded from macro '_SIG_SET_OP' 174 | case 4: set->sig[3] = op(set->sig[3]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:20: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: In file included from include/linux/mm.h:36: In file included from include/linux/rcuwait.h:6: In file included from include/linux/sched/signal.h:6: include/linux/signal.h:187:1: warning: array index 2 is past the end of the array (that has type 'unsigned long[2]') [-Warray-bounds] 187 | _SIG_SET_OP(signotset, _sig_not) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/signal.h:175:3: note: expanded from macro '_SIG_SET_OP' 175 | set->sig[2] = op(set->sig[2]); \ | ^ ~ arch/arm/include/asm/signal.h:17:2: note: array 'sig' declared here 17 | unsigned long sig[_NSIG_WORDS]; | ^ In file included from arch/arm/kernel/asm-offsets.c:14: 994 | const vm_flags_t mask = BIT((__force int)bit); | ^ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^ include/linux/bits.h:88:17: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ^ include/linux/bits.h:82:24: note: expanded from macro 'BIT_INPUT_CHECK' 82 | sizeof(struct { char bit_number_too_big[-((nr) >= (width))];}), \ | ^ 28 warnings and 16 errors generated. make[3]: *** [scripts/Makefile.build:182: arch/arm/kernel/asm-offsets.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1330: prepare0] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +994 include/linux/mm.h bc292ab00f6c7a6 Suren Baghdasaryan 2023-01-26 990 568822502383acd Lorenzo Stoakes 2025-11-18 991 static inline bool __vma_flag_atomic_valid(struct vm_area_struct *vma, 2b6a3f061f11372 Lorenzo Stoakes 2025-11-25 992 vma_flag_t bit) 568822502383acd Lorenzo Stoakes 2025-11-18 993 { 2b6a3f061f11372 Lorenzo Stoakes 2025-11-25 @994 const vm_flags_t mask = BIT((__force int)bit); 568822502383acd Lorenzo Stoakes 2025-11-18 995 568822502383acd Lorenzo Stoakes 2025-11-18 996 /* Only specific flags are permitted */ 568822502383acd Lorenzo Stoakes 2025-11-18 997 if (WARN_ON_ONCE(!(mask & VM_ATOMIC_SET_ALLOWED))) 568822502383acd Lorenzo Stoakes 2025-11-18 998 return false; 568822502383acd Lorenzo Stoakes 2025-11-18 999 568822502383acd Lorenzo Stoakes 2025-11-18 1000 return true; 568822502383acd Lorenzo Stoakes 2025-11-18 1001 } 568822502383acd Lorenzo Stoakes 2025-11-18 1002 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 08:50:22 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-12-david.laight.linux%40gmail.com patch subject: [PATCH next 11/14] bit: Strengthen compile-time tests in GENMASK() and BIT() config: s390-randconfig-001-20260122 (https://download.01.org/0day-ci/archive/20260122/202601220829.MgTMeqqN-lkp@intel.com/config) compiler: s390-linux-gcc (GCC) 8.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220829.MgTMeqqN-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220829.MgTMeqqN-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from arch/s390/include/asm/bug.h:60, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from arch/s390/include/asm/cmpxchg.h:11, from arch/s390/include/asm/atomic.h:16, from include/linux/atomic.h:7, from include/asm-generic/bitops/atomic.h:5, from arch/s390/include/asm/bitops.h:75, from include/linux/bitops.h:67, from include/linux/kernel.h:23, from net/core/page_pool.c:10: In function 'netmem_clear_pp_magic', inlined from 'page_pool_clear_pp_info' at net/core/page_pool.c:721:2: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/asm-generic/bug.h:120:25: note: in definition of macro 'WARN_ON_ONCE' int __ret_warn_on = !!(condition); \ ^~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:18:52: note: in expansion of macro 'PP_DMA_INDEX_MASK' WARN_ON_ONCE(netmem_to_nmdesc(netmem)->pp_magic & PP_DMA_INDEX_MASK); ^~~~~~~~~~~~~~~~~ -- In file included from include/linux/bitops.h:6, from arch/s390/include/asm/machine.h:25, from arch/s390/include/asm/lowcore.h:13, from arch/s390/include/asm/current.h:13, from arch/s390/include/asm/preempt.h:5, from include/linux/preempt.h:79, from arch/s390/include/asm/timex.h:13, from include/linux/timex.h:67, from include/linux/time32.h:13, from include/linux/time.h:60, from include/linux/stat.h:19, from include/linux/module.h:13, from net/core/skbuff.c:37: In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'napi_pp_put_page' at net/core/skbuff.c:1027:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ In function 'netmem_get_pp_magic', inlined from 'netmem_is_pp' at net/core/netmem_priv.h:25:10, inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ net/core/netmem_priv.h:8:47: note: in expansion of macro 'PP_DMA_INDEX_MASK' return netmem_to_nmdesc(netmem)->pp_magic & ~PP_DMA_INDEX_MASK; ^~~~~~~~~~~~~~~~~ In function 'netmem_is_pp', inlined from 'skb_pp_frag_ref' at net/core/skbuff.c:1067:7, inlined from 'skb_try_coalesce' at net/core/skbuff.c:6203:6: GENMASK_INPUT_CHECK_FAIL())) ^~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:54:17: note: in expansion of macro 'GENMASK_INPUT_CHECK' ((unsigned int)GENMASK_INPUT_CHECK(h, l, BITS_PER_TYPE(t)) + \ ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:58:24: note: in expansion of macro 'GENMASK_TYPE' #define GENMASK(h, l) GENMASK_TYPE(unsigned long, h, l) ^~~~~~~~~~~~ include/linux/mm.h:4641:27: note: in expansion of macro 'GENMASK' #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ ^~~~~~~ include/linux/mm.h:4650:25: note: in expansion of macro 'PP_DMA_INDEX_MASK' #define PP_MAGIC_MASK ~(PP_DMA_INDEX_MASK | 0x3UL) ^~~~~~~~~~~~~~~~~ net/core/netmem_priv.h:25:40: note: in expansion of macro 'PP_MAGIC_MASK' return (netmem_get_pp_magic(netmem) & PP_MAGIC_MASK) == PP_SIGNATURE; ^~~~~~~~~~~~~ vim +/GENMASK_INPUT_CHECK_FAIL +35 include/linux/bits.h 25 26 #ifndef KBUILD_EXTRA_WARNc 27 #define GENMASK_INPUT_CHECK(h, l, width) 0 28 #else 29 int GENMASK_INPUT_CHECK_FAIL(void) __compiletime_error("Invalid bit numbers"); 30 #define GENMASK_INPUT_CHECK(h, l, width) \ 31 (__builtin_choose_expr(__is_constexpr((l) > (h)), \ 32 sizeof(struct { char low_bit_greater_than_high[-((l) > (h))];}), \ 33 __builtin_constant_p((l) | (h)) && \ 34 ((l) < 0 || (l) > (h) || (h) >= width) && \ > 35 GENMASK_INPUT_CHECK_FAIL())) 36 #endif 37 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 09:11:53 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build errors: [auto build test ERROR on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-13-david.laight.linux%40gmail.com patch subject: [PATCH next 12/14] bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h config: arm64-allmodconfig (https://download.01.org/0day-ci/archive/20260122/202601220951.7C4YG7hB-lkp@intel.com/config) compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601220951.7C4YG7hB-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601220951.7C4YG7hB-lkp@intel.com/ All error/warnings (new ones prefixed by >>): In file included from kernel/bounds.c:14: In file included from include/linux/log2.h:12: In file included from include/linux/bitops.h:28: In file included from include/asm-generic/bitops/generic-non-atomic.h:7: In file included from arch/arm64/include/asm/barrier.h:14: 18 | #if ARM64_NCAPS >= ARM64_CB_BIT | ^ arch/arm64/include/asm/alternative-macros.h:16:22: note: expanded from macro 'ARM64_CB_BIT' 16 | #define ARM64_CB_BIT BIT(ARM64_CB_SHIFT) | ^ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^ include/linux/bits.h:88:4: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ^ In file included from kernel/bounds.c:14: In file included from include/linux/log2.h:12: In file included from include/linux/bitops.h:28: In file included from include/asm-generic/bitops/generic-non-atomic.h:7: In file included from arch/arm64/include/asm/barrier.h:14: 18 | #if ARM64_NCAPS >= ARM64_CB_BIT | ^~~~~~~~~~~~ arch/arm64/include/asm/alternative-macros.h:16:22: note: expanded from macro 'ARM64_CB_BIT' 16 | #define ARM64_CB_BIT BIT(ARM64_CB_SHIFT) | ^~~~~~~~~~~~~~~~~~~ include/linux/bits.h:94:18: note: expanded from macro 'BIT' 94 | #define BIT(nr) BIT_TYPE(unsigned long, nr) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ include/linux/bits.h:88:13: note: expanded from macro 'BIT_TYPE' 88 | ((unsigned int)BIT_INPUT_CHECK(+(nr), BITS_PER_TYPE(type)) + ((type)1 << (nr))) | ~~~~~~~~ ^ 1 warning and 1 error generated. make[3]: *** [scripts/Makefile.build:182: kernel/bounds.s] Error 1 make[3]: Target 'prepare' not remade because of errors. make[2]: *** [Makefile:1330: prepare0] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:248: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:248: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. vim +18 arch/arm64/include/asm/alternative-macros.h 4c0bd995d73ed8 Mark Rutland 2022-09-12 17 4c0bd995d73ed8 Mark Rutland 2022-09-12 @18 #if ARM64_NCAPS >= ARM64_CB_BIT 4c0bd995d73ed8 Mark Rutland 2022-09-12 19 #error "cpucaps have overflown ARM64_CB_BIT" 4c0bd995d73ed8 Mark Rutland 2022-09-12 20 #endif 7cda23da52ad79 Will Deacon 2020-06-30 21 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 09:23:16 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Hi, kernel test robot noticed the following build warnings: [auto build test WARNING on next-20260120] url: https://github.com/intel-lab-lkp/linux/commits/david-laight-linux-gmail-com/overflow-Reduce-expansion-of-__type_max/20260122-013456 base: next-20260120 patch link: https://lore.kernel.org/r/20260121145731.3623-12-david.laight.linux%40gmail.com patch subject: [PATCH next 11/14] bit: Strengthen compile-time tests in GENMASK() and BIT() config: mips-randconfig-r132-20260122 (https://download.01.org/0day-ci/archive/20260122/202601221237.soiAkwkN-lkp@intel.com/config) compiler: mips64-linux-gcc (GCC) 10.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260122/202601221237.soiAkwkN-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202601221237.soiAkwkN-lkp@intel.com/ sparse warnings: (new ones prefixed by >>) kernel/kthread.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- kernel/reboot.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- lib/idr.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- lib/xarray.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. lib/xarray.c: note: in included file: lib/xarray.c: note: in included file (through include/linux/bitmap.h): -- lib/find_bit.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. include/linux/find.h:238:46: sparse: sparse: Variable length array is used. -- lib/bitmap-str.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. lib/bitmap-str.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- lib/genalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- mm/oom_kill.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/vmscan.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/shmem.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- mm/percpu.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:409:45: sparse: sparse: Variable length array is used. include/linux/find.h:188:32: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. mm/percpu.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- mm/vmalloc.c: note: in included file (through arch/mips/include/asm/page.h, include/linux/shm.h, include/linux/sched.h, ...): include/asm-generic/memory_model.h:30:23: sparse: sparse: unsigned value that used to be signed checked against zero? mm/vmalloc.c:554:21: sparse: signed value source mm/vmalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. mm/vmalloc.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. mm/vmalloc.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. -- mm/slub.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- mm/hugetlb.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- mm/huge_memory.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- arch/mips/kernel/cmpxchg.c:61:16: sparse: sparse: Variable length array is used. -- arch/mips/kernel/cpu-probe.c:712:45: sparse: sparse: Variable length array is used. arch/mips/kernel/cpu-probe.c:214:9: sparse: sparse: cast truncates bits from constant value (3fffffffffffe000 becomes ffffe000) arch/mips/kernel/cpu-probe.c:214:9: sparse: sparse: cast truncates bits from constant value (3fffffffffffe000 becomes ffffe000) -- -- net/ethtool/ioctl.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- net/ethtool/bitset.c: note: in included file (through include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, include/linux/ethtool_netlink.h): -- net/ethtool/linkmodes.c: note: in included file (through include/linux/bitmap.h, include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, ...): -- net/ethtool/fec.c: note: in included file (through include/linux/bitmap.h, include/linux/ethtool.h, include/uapi/linux/ethtool_netlink.h, ...): -- drivers/clk/clk-multiplier.c:141:17: sparse: sparse: Variable length array is used. -- drivers/clk/clk-fractional-divider.c:90:17: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:146:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:147:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:195:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:196:25: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:205:17: sparse: sparse: Variable length array is used. drivers/clk/clk-fractional-divider.c:206:17: sparse: sparse: Variable length array is used. -- -- -- drivers/clocksource/ingenic-timer.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:188:32: sparse: sparse: Variable length array is used. -- -- drivers/base/regmap/regcache-rbtree.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): -- drivers/base/regmap/regcache-flat.c: note: in included file: -- drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): drivers/crypto/marvell/octeontx/otx_cptpf_ucode.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): -- -- -- drivers/gpio/gpiolib.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): drivers/gpio/gpiolib.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:188:32: sparse: sparse: Variable length array is used. drivers/gpio/gpiolib.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/gpio/gpio-nomadik.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- kernel/sched/build_utility.c: note: in included file: kernel/sched/debug.c:624:17: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/debug.c:624:17: sparse: expected struct sched_domain *[assigned] sd kernel/sched/debug.c:624:17: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/debug.c:952:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] __rcu *curr @@ kernel/sched/debug.c:952:9: sparse: expected struct task_struct *tsk kernel/sched/debug.c:952:9: sparse: got struct task_struct [noderef] __rcu *curr kernel/sched/debug.c:952:9: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct task_struct *tsk @@ got struct task_struct [noderef] __rcu *curr @@ kernel/sched/debug.c:952:9: sparse: expected struct task_struct *tsk kernel/sched/debug.c:952:9: sparse: got struct task_struct [noderef] __rcu *curr kernel/sched/build_utility.c: note: in included file: kernel/sched/topology.c:115:56: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:115:56: sparse: expected struct sched_domain *sd kernel/sched/topology.c:115:56: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:134:60: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:134:60: sparse: expected struct sched_domain *sd kernel/sched/topology.c:134:60: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:157:20: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:157:20: sparse: expected struct sched_domain *sd kernel/sched/topology.c:157:20: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:468:19: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct perf_domain *pd @@ got struct perf_domain [noderef] __rcu *pd @@ kernel/sched/topology.c:468:19: sparse: expected struct perf_domain *pd kernel/sched/topology.c:468:19: sparse: got struct perf_domain [noderef] __rcu *pd kernel/sched/topology.c:638:49: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *parent @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:638:49: sparse: expected struct sched_domain *parent kernel/sched/topology.c:638:49: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:723:50: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *parent @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:723:50: sparse: expected struct sched_domain *parent kernel/sched/topology.c:723:50: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:731:55: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain [noderef] __rcu *[noderef] __rcu child @@ got struct sched_domain *[assigned] tmp @@ kernel/sched/topology.c:731:55: sparse: expected struct sched_domain [noderef] __rcu *[noderef] __rcu child kernel/sched/topology.c:731:55: sparse: got struct sched_domain *[assigned] tmp kernel/sched/topology.c:744:29: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] tmp @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:744:29: sparse: expected struct sched_domain *[assigned] tmp kernel/sched/topology.c:744:29: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:749:20: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:749:20: sparse: expected struct sched_domain *sd kernel/sched/topology.c:749:20: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:770:13: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] tmp @@ got struct sched_domain [noderef] __rcu *sd @@ kernel/sched/topology.c:770:13: sparse: expected struct sched_domain *[assigned] tmp kernel/sched/topology.c:770:13: sparse: got struct sched_domain [noderef] __rcu *sd kernel/sched/topology.c:932:70: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:932:70: sparse: expected struct sched_domain *sd kernel/sched/topology.c:932:70: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:961:59: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:961:59: sparse: expected struct sched_domain *sd kernel/sched/topology.c:961:59: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1007:57: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1007:57: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1007:57: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1009:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sibling @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1009:25: sparse: expected struct sched_domain *sibling kernel/sched/topology.c:1009:25: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1017:55: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1017:55: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1017:55: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1019:25: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *sibling @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1019:25: sparse: expected struct sched_domain *sibling kernel/sched/topology.c:1019:25: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1089:62: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct sched_domain *sd @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1089:62: sparse: expected struct sched_domain *sd kernel/sched/topology.c:1089:62: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1193:40: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *child @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:1193:40: sparse: expected struct sched_domain *child kernel/sched/topology.c:1193:40: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1331:9: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:1331:9: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:1331:9: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:1680:43: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain [noderef] __rcu *child @@ got struct sched_domain *child @@ kernel/sched/topology.c:1680:43: sparse: expected struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:1680:43: sparse: got struct sched_domain *child kernel/sched/topology.c:2470:31: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain [noderef] __rcu *parent @@ got struct sched_domain *sd @@ kernel/sched/topology.c:2470:31: sparse: expected struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2470:31: sparse: got struct sched_domain *sd kernel/sched/topology.c:2591:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2591:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2591:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2612:56: sparse: sparse: incorrect type in initializer (different address spaces) @@ expected struct sched_domain *child @@ got struct sched_domain [noderef] __rcu *child @@ kernel/sched/topology.c:2612:56: sparse: expected struct sched_domain *child kernel/sched/topology.c:2612:56: sparse: got struct sched_domain [noderef] __rcu *child kernel/sched/topology.c:2611:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2611:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2611:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/topology.c:2666:57: sparse: sparse: incorrect type in assignment (different address spaces) @@ expected struct sched_domain *[assigned] sd @@ got struct sched_domain [noderef] __rcu *parent @@ kernel/sched/topology.c:2666:57: sparse: expected struct sched_domain *[assigned] sd kernel/sched/topology.c:2666:57: sparse: got struct sched_domain [noderef] __rcu *parent kernel/sched/build_utility.c: note: in included file: kernel/sched/build_utility.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. kernel/sched/build_utility.c: note: in included file: kernel/sched/sched.h:2360:25: sparse: sparse: incompatible types in comparison expression (different address spaces): kernel/sched/sched.h:2360:25: sparse: struct task_struct [noderef] __rcu * kernel/sched/sched.h:2360:25: sparse: struct task_struct * -- drivers/clk/ingenic/cgu.c:97:42: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:102:27: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:224:18: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:227:18: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:231:26: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:345:26: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:389:24: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:423:31: sparse: sparse: Variable length array is used. drivers/clk/ingenic/cgu.c:553:24: sparse: sparse: Variable length array is used. -- kernel/irq/chip.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): -- kernel/irq/irq_sim.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- drivers/input/rmi4/rmi_driver.c: note: in included file (through include/linux/bitmap.h): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/input/rmi4/rmi_driver.c: note: in included file: include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. drivers/input/rmi4/rmi_driver.c: note: in included file (through include/linux/bitmap.h): -- -- drivers/mfd/atmel-smc.c:57:32: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:120:27: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:159:25: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:198:25: sparse: sparse: Variable length array is used. drivers/mfd/atmel-smc.c:236:25: sparse: sparse: Variable length array is used. -- -- drivers/mtd/nand/bbt.c:111:38: sparse: sparse: Variable length array is used. drivers/mtd/nand/bbt.c:116:20: sparse: sparse: Variable length array is used. drivers/mtd/nand/bbt.c:122:28: sparse: sparse: Variable length array is used. -- drivers/opp/cpu.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- drivers/pci/pci.c:1157:36: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1157:36: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1157:36: sparse: got int drivers/pci/pci.c:1336:15: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [assigned] [usertype] state @@ got int @@ drivers/pci/pci.c:1336:15: sparse: expected restricted pci_power_t [assigned] [usertype] state drivers/pci/pci.c:1336:15: sparse: got int drivers/pci/pci.c:1338:50: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1338:69: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1391:28: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1391:28: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1391:28: sparse: got int drivers/pci/pci.c:1481:16: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:35: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:52: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1481:70: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1506:15: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:1506:15: sparse: left side has type unsigned short drivers/pci/pci.c:1506:15: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:1518:28: sparse: sparse: incorrect type in assignment (different base types) @@ expected restricted pci_power_t [usertype] current_state @@ got int @@ drivers/pci/pci.c:1518:28: sparse: expected restricted pci_power_t [usertype] current_state drivers/pci/pci.c:1518:28: sparse: got int drivers/pci/pci.c:1535:13: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1535:21: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1537:18: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1537:26: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1560:13: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1560:22: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:1865:38: sparse: sparse: array of flexible structures drivers/pci/pci.c:2343:44: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2662:60: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2663:30: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2834:20: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2834:38: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2857:49: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:2857:67: sparse: sparse: restricted pci_power_t degrades to integer drivers/pci/pci.c:4486:13: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:4486:13: sparse: left side has type unsigned short drivers/pci/pci.c:4486:13: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:4491:13: sparse: sparse: invalid assignment: |= drivers/pci/pci.c:4491:13: sparse: left side has type unsigned short drivers/pci/pci.c:4491:13: sparse: right side has type restricted pci_power_t drivers/pci/pci.c:1112:24: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted pci_power_t [usertype] @@ drivers/pci/pci.c:1112:24: sparse: expected int drivers/pci/pci.c:1112:24: sparse: got restricted pci_power_t [usertype] drivers/pci/pci.c:1112:24: sparse: sparse: incorrect type in return expression (different base types) @@ expected int @@ got restricted pci_power_t [usertype] @@ drivers/pci/pci.c:1112:24: sparse: expected int drivers/pci/pci.c:1112:24: sparse: got restricted pci_power_t [usertype] drivers/pci/pci.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/perf/xgene_pmu.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:388:46: sparse: sparse: Variable length array is used. include/linux/find.h:69:31: sparse: sparse: Variable length array is used. -- -- -- drivers/mtd/nand/raw/nand_macronix.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/clk/spacemit/ccu_mix.c:193:16: sparse: sparse: Variable length array is used. -- -- -- drivers/clk/sprd/pll.c:116:13: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:120:34: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:121:31: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:124:14: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:125:32: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:127:24: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:128:21: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:129:32: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:131:24: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:164:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:170:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:181:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:186:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:192:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:198:16: sparse: sparse: Variable length array is used. drivers/clk/sprd/pll.c:210:16: sparse: sparse: Variable length array is used. -- -- drivers/pinctrl/renesas/core.c:942:34: sparse: sparse: Variable length array is used. drivers/pinctrl/renesas/core.c:1241:34: sparse: sparse: Variable length array is used. -- drivers/pinctrl/renesas/pinctrl.c:527:17: sparse: sparse: Variable length array is used. -- drivers/pci/controller/pcie-xilinx-dma-pl.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, arch/mips/include/asm/processor.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/pci/controller/pcie-xilinx-dma-pl.c: note: in included file (through include/linux/cpumask.h, arch/mips/include/asm/processor.h, arch/mips/include/asm/thread_info.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. -- drivers/pci/controller/dwc/pcie-designware-host.c: note: in included file (through include/linux/bitmap.h, include/linux/cpumask.h, include/linux/smp.h, ...): include/linux/find.h:69:31: sparse: sparse: Variable length array is used. drivers/pci/controller/dwc/pcie-designware-host.c: note: in included file (through include/linux/cpumask.h, include/linux/smp.h, arch/mips/include/asm/cpu-type.h, ...): include/linux/bitmap.h:488:25: sparse: sparse: Variable length array is used. vim +209 include/linux/find.h c56f97c5c71f17 include/linux/find.h Yury Norov [NVIDIA] 2025-06-19 48 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 49 #ifndef find_next_bit d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 50 /** d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 51 * find_next_bit - find the next set bit in a memory region d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 52 * @addr: The address to base the search on d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 53 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 54 * @offset: The bitnumber to start searching at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 55 * ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 56 * Returns the bit number for the next set bit ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 57 * If no bits are set, returns @size. d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 58 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 59 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 60 unsigned long find_next_bit(const unsigned long *addr, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 61 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 62 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 63 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 64 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 65 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 66 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 67 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 68 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 @69 val = *addr & GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 70 return val ? __ffs(val) : size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 71 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 72 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 73 return _find_next_bit(addr, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 74 } 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 75 #endif c7f612cdf091de include/asm-generic/bitops/find.h Akinobu Mita 2006-03-26 76 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 77 #ifndef find_next_and_bit 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 78 /** 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 79 * find_next_and_bit - find the next set bit in both memory regions 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 80 * @addr1: The first address to base the search on 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 81 * @addr2: The second address to base the search on 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 82 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 83 * @offset: The bitnumber to start searching at 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 84 * 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 85 * Returns the bit number for the next set bit 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 86 * If no bits are set, returns @size. 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 87 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 88 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 89 unsigned long find_next_and_bit(const unsigned long *addr1, 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 90 const unsigned long *addr2, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 91 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 92 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 93 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 94 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 95 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 96 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 97 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 98 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 99 val = *addr1 & *addr2 & GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 100 return val ? __ffs(val) : size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 101 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 102 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 103 return _find_next_and_bit(addr1, addr2, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 104 } 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 105 #endif 0ade34c37012ea include/asm-generic/bitops/find.h Clement Courbet 2018-02-06 106 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 107 #ifndef find_next_andnot_bit 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 108 /** 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 109 * find_next_andnot_bit - find the next set bit in *addr1 excluding all the bits 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 110 * in *addr2 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 111 * @addr1: The first address to base the search on 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 112 * @addr2: The second address to base the search on 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 113 * @size: The bitmap size in bits 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 114 * @offset: The bitnumber to start searching at 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 115 * 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 116 * Returns the bit number for the next set bit 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 117 * If no bits are set, returns @size. 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 118 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 119 static __always_inline 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 120 unsigned long find_next_andnot_bit(const unsigned long *addr1, 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 121 const unsigned long *addr2, unsigned long size, 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 122 unsigned long offset) 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 123 { 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 124 if (small_const_nbits(size)) { 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 125 unsigned long val; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 126 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 127 if (unlikely(offset >= size)) 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 128 return size; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 129 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 130 val = *addr1 & ~*addr2 & GENMASK(size - 1, offset); 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 131 return val ? __ffs(val) : size; 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 132 } 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 133 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 134 return _find_next_andnot_bit(addr1, addr2, size, offset); 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 135 } 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 136 #endif 90d482908eedd5 include/linux/find.h Valentin Schneider 2022-10-03 137 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 138 #ifndef find_next_or_bit 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 139 /** 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 140 * find_next_or_bit - find the next set bit in either memory regions 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 141 * @addr1: The first address to base the search on 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 142 * @addr2: The second address to base the search on 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 143 * @size: The bitmap size in bits 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 144 * @offset: The bitnumber to start searching at 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 145 * 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 146 * Returns the bit number for the next set bit 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 147 * If no bits are set, returns @size. 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 148 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 149 static __always_inline 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 150 unsigned long find_next_or_bit(const unsigned long *addr1, 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 151 const unsigned long *addr2, unsigned long size, 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 152 unsigned long offset) 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 153 { 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 154 if (small_const_nbits(size)) { 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 155 unsigned long val; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 156 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 157 if (unlikely(offset >= size)) 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 158 return size; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 159 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 160 val = (*addr1 | *addr2) & GENMASK(size - 1, offset); 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 161 return val ? __ffs(val) : size; 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 162 } 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 163 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 164 return _find_next_or_bit(addr1, addr2, size, offset); 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 165 } 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 166 #endif 1470afefc3c42d include/linux/find.h Dave Chinner 2023-03-15 167 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 168 #ifndef find_next_zero_bit d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 169 /** d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 170 * find_next_zero_bit - find the next cleared bit in a memory region d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 171 * @addr: The address to base the search on d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 172 * @size: The bitmap size in bits 6d7131bd52b3e0 include/linux/find.h Anna-Maria Behnsen 2022-04-11 173 * @offset: The bitnumber to start searching at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 174 * ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 175 * Returns the bit number of the next zero bit ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 176 * If no bits are zero, returns @size. d852a6afd91fc9 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 177 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 178 static __always_inline 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 179 unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 180 unsigned long offset) 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 181 { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 182 if (small_const_nbits(size)) { 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 183 unsigned long val; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 184 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 185 if (unlikely(offset >= size)) 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 186 return size; 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 187 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 188 val = *addr | ~GENMASK(size - 1, offset); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 189 return val == ~0UL ? size : ffz(val); 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 190 } 277a20a498d307 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 191 e79864f3164c57 include/linux/find.h Yury Norov 2022-09-14 192 return _find_next_zero_bit(addr, size, offset); 5c88af59f9abc2 include/asm-generic/bitops/find.h Yury Norov 2021-05-06 193 } 19de85ef574c3a include/asm-generic/bitops/find.h Akinobu Mita 2011-05-26 194 #endif c7f612cdf091de include/asm-generic/bitops/find.h Akinobu Mita 2006-03-26 195 b7ec62d7ee0f0b include/asm-generic/bitops/find.h Yury Norov 2021-08-14 196 #ifndef find_first_bit 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 197 /** 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 198 * find_first_bit - find the first set bit in a memory region 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 199 * @addr: The address to start the search at ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 200 * @size: The maximum number of bits to search 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 201 * 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 202 * Returns the bit number of the first set bit. ec778edf97dcaa include/asm-generic/bitops/find.h Cody P Schafer 2013-11-12 203 * If no bits are set, returns @size. 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 204 */ fda1dd3c54ef3c include/linux/find.h Yury Norov 2024-07-18 205 static __always_inline 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 206 unsigned long find_first_bit(const unsigned long *addr, unsigned long size) 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 207 { 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 208 if (small_const_nbits(size)) { 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 @209 unsigned long val = *addr & GENMASK(size - 1, 0); 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 210 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 211 return val ? __ffs(val) : size; 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 212 } 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 213 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 214 return _find_first_bit(addr, size); 2cc7b6a44ac21d include/asm-generic/bitops/find.h Yury Norov 2021-05-06 215 } b7ec62d7ee0f0b include/asm-generic/bitops/find.h Yury Norov 2021-08-14 216 #endif 708ff2a0097b02 include/asm-generic/bitops/find.h Akinobu Mita 2010-09-29 217 -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
{ "author": "kernel test robot <lkp@intel.com>", "date": "Thu, 22 Jan 2026 12:41:22 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Wed, Jan 21, 2026 at 07:24:51PM +0000, David Laight wrote: The #ifndef in vdso/bits.h is not much better IMO. Given that there a multiple nicer options why not use on of those? That is a bug. The vdso code should only include the vdso/ namespace. Right now the inclusions are all over the place. I'd like to clean that up at some point. I don't understand "code version specific". There are various issues with including normal kernel headers from the vDSO. Symbols defined in terms of kconfig options, like BITS_PER_LONG using CONFIG_64BIT are wrong in a compat vDSO.
{ "author": "Thomas =?utf-8?Q?Wei=C3=9Fschuh?= <thomas.weissschuh@linutronix.de>", "date": "Thu, 22 Jan 2026 08:39:42 +0100", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 09:11:53 +0800 kernel test robot <lkp@intel.com> wrote: ... This might be a real bug. The bit of mm.h is: #define PP_DMA_INDEX_SHIFT (1 + __fls(PP_SIGNATURE - POISON_POINTER_DELTA)) #if POISON_POINTER_DELTA > 0 /* PP_SIGNATURE includes POISON_POINTER_DELTA, so limit the size of the DMA * index to not overlap with that if set */ #define PP_DMA_INDEX_BITS MIN(32, __ffs(POISON_POINTER_DELTA) - PP_DMA_INDEX_SHIFT) #else /* Use the lowest bit of PAGE_OFFSET if there's at least 8 bits available; see above */ #define PP_DMA_INDEX_MIN_OFFSET (1 << (PP_DMA_INDEX_SHIFT + 8)) #define PP_DMA_INDEX_BITS ((__builtin_constant_p(PAGE_OFFSET) && \ PAGE_OFFSET >= PP_DMA_INDEX_MIN_OFFSET && \ !(PAGE_OFFSET & (PP_DMA_INDEX_MIN_OFFSET - 1))) ? \ MIN(32, __ffs(PAGE_OFFSET) - PP_DMA_INDEX_SHIFT) : 0) #endif #define PP_DMA_INDEX_MASK GENMASK(PP_DMA_INDEX_BITS + PP_DMA_INDEX_SHIFT - 1, \ PP_DMA_INDEX_SHIFT) I've no idea what the values are, but the 'hi' bit number must exceed that of 'long'. The __ffs() probably stop it being an 'integer constant expression' making it just a 'compile time constant' - which I added a test for. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:25:54 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 09:23:16 +0800 kernel test robot <lkp@intel.com> wrote: ... Unless I change BIT() back I'll change that to a static_assert(). David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:30:29 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 12:41:22 +0800 kernel test robot <lkp@intel.com> wrote: Can we stop sparse complaining about sizeof(VLA) ? David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 10:33:37 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 10:33:37AM +0000, David Laight wrote: First of all, the LKP should install the fork of sparse by Al Viro. That will fix tons of warnings that are related to modules and speed up the process itself. -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Thu, 22 Jan 2026 16:26:44 +0200", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 16:26:44 +0200 Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: The problem I have is I want to generate a compile time error inside: __builtin_choose_expr(__is_constexpr(x), x && error_a(), statically_true(y) && error_b()); Neither static_assert() nor a negative bitfield can be used in error_a() because they are errors when x isn't isn't a 'constexpr', There is less of a problem for error_b() it can contain a function call, but can't contain {( ...)}. One of the compiler complained about sizeof (char [-!!(expr)]) as well. I'm not sure of anything else that can be use to get an error. I could use 0 >> -1 but that is only a warning, at least the error message is related to the bug. Any other ideas? David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 14:55:56 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, 22 Jan 2026 10:25:54 +0000 David Laight <david.laight.linux@gmail.com> wrote: I've managed to do an s390 cross build. It is all quite obvious really. For s390 PAGE_OFFSET is usually zero (I think kernel and user mappings are separate?). This make PP_DMA_INDEX_BITS 0. PP_SIGNATURE is 64 - so PP_DMA_INDEX_SHIFT is 7. So it is doing GENMASK(6, 7) and, I think, expecting to get zero. But that is taken a mistyped GENMASK(7, 6) and treated as an error. If I rewrite __fls() and __ffs() to return 'integer constant expressions' when the input is one I think it would always have failed. A comment a few lines higher suggests that the code expects the mask to be zero in this case - and handles it properly. David
{ "author": "David Laight <david.laight.linux@gmail.com>", "date": "Thu, 22 Jan 2026 20:10:20 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 10:33:37AM +0000, David Laight wrote: Got it, we will avoid the direct report this 'sparse: Variable length array is used' warning.
{ "author": "Philip Li <philip.li@intel.com>", "date": "Fri, 23 Jan 2026 09:24:50 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Thu, Jan 22, 2026 at 04:26:44PM +0200, Andy Shevchenko wrote: Thanks Andy, i will switch to the repo from Al Viro for sparse.
{ "author": "Philip Li <philip.li@intel.com>", "date": "Fri, 23 Jan 2026 09:25:36 +0800", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
Adding the relevant parties to the discussion: +To: Al Viro +To: Chris Li On 23/01/2026 at 02:25, Philip Li wrote: Al Viro's fork just adds 8 commit on top of the upstream sparse repo. Wouldn't it be possible to just merge those? That would be much less confusing. Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Fri, 23 Jan 2026 09:01:04 +0100", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 09:01:04AM +0100, Vincent Mailhol wrote: Ideally yes, but you also should kick the distro's asses to update it, and the sparse should bump its version... Seems Al become a sparse maintainer de facto :-) -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Fri, 23 Jan 2026 10:11:19 +0200", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 10:11:19AM +0200, Andy Shevchenko wrote: Huh? What happened to Chris? FWIW, I do have some followups to that series sitting locally; need to get that finished (mostly for proper __VA_OPT__ handling; that got stalled on the lovely corner cases where the interplay with side effects of macro expansion is really nasty - gcc and clang do not agree and gcc is arguably buggy) and posted. I've done quite a bit of sparse work over the years, but I would rather prefer somebody else as overall maintainer, TYVM...
{ "author": "Al Viro <viro@zeniv.linux.org.uk>", "date": "Fri, 23 Jan 2026 08:20:27 +0000", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On Fri, Jan 23, 2026 at 08:20:27AM +0000, Al Viro wrote: I don't know, but upstream sparse haven't applied any solution for MODULE*("FOO") stuff, nor reaction on my ping in that discussion (I did it like week or so ago). Thanks for doing all this! -- With Best Regards, Andy Shevchenko
{ "author": "Andy Shevchenko <andriy.shevchenko@linux.intel.com>", "date": "Fri, 23 Jan 2026 10:24:01 +0200", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }
lkml
[PATCH next 00/14] bits: De-bloat expansion of GENMASK()
From: David Laight <david.laight.linux@gmail.com> The expansion of GENMASK() is a few hundred bytes, this is often multiplied when the value is passed to other #defines (eg FIELD_PREP). Part of the size is due to the compile-type check (for reversed arguments), the rest from the way the value is defined. Nothing in these patches changes the code the compiler sees - just the way the constants get defined. Changing GENMASK(hi, lo) to (2 << hi) - (1 << lo) is left for further study. I looked at getting the compiler to check for reversed arguments using (0 >> (hi - lo)) instead of const_true(lo > hi). While checking that it was always optimised away I discovered that you don't get an error message if the values are only 'compile time constants', worse clang starts throwing code away, generation an empty function for: int f(u32 x) {int n = 32; return x >> n; } (Shifts by more than width are 'undefined behaviour', so what clang does is technically valid - but not friendly or expected.) So I added extra checks to both GENMASK() and BITxxx() to detect this at compile time. But this bloats the output - the opposite of what I was trying to achieve. However these are all compile-time checks that are actually unlikely to detect anything, they don't need to be done on every build. I've mitigated this by adding W=c (cf W=[123e]) to the main Makefile (adding -DKBUILD_EXTRA_WARNc) and defaulting to W=c for W=1 builds. Adding checks to BIT() makes it no longer a pre-processor constant so can no longer be used in #if statements (when W=c) is set. This required minor changes to 3 files. At some point the definition of BIT() was moved to vdso/bits.h (followed by that for BIT_ULL()), but then the fixed size BIT_Unn() were added to bits.h. I've moved BIT_ULL() back to linux/bits.h and made the version of BIT() in linux/bits.h be preferred if both files get included. Note that the x86-64 allmodconfig build suceeds if vdso/bits.h is empty - everything includes linux/bits.h first. I found two non-vdso files that included vdso/bits.h and changed them to use linux/bits.h. GENMASK_U8() and BIT_U8() cast their result to (u8), this isn't a good idea. While the 'type of the expression' is 'u8', integer promotion makes the 'type of the value' 'signed int'. This means that in code like: u64 v = BIT_U8(7) << 24; the value is sign extended and all the high bits are set. Instead change the type of the xxx_U8/U16 macros to 'unsigned int' so that the sign extension cannot happen. The compile-time check on the bit number is still present. For assembler files where GENMASK() can be used for constants the expansions from uapi/linux/bits.h were used. However these contain BITS_PER_LONG and BITS_PER_LONG_LONG which make no sense since the assembler doesn't have sized arithmetic. Replace with GENMASK(hi, lo) (2 << (hi)) - (1 << (lo)) which has the correct value without knowing the size of the integers. The kunit tests all check compile-time values. I've changed them to use BUILD_BUG_ON(). David Laight (14): overflow: Reduce expansion of __type_max() kbuild: Add W=c for additional compile time checks media: videobuf2-core: Use static_assert() for sanity check media: atomisp: Use static_assert() for sanity check ixgbevf: Use C test for PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD asm-generic: include linux/bits.h not vdso/bits.h x86/tlb: include linux/bits.h not vdso/bits.h bits: simplify GENMASK_TYPE() bits: Change BIT_U8/16() and GENMASK_U8/16() to have unsigned values bits: Fix assmebler expansions of GENMASK_Uxx() and BIT_Uxx() bit: Strengthen compile-time tests in GENMASK() and BIT() bits: move the defitions of BIT() and BIT_ULL() back to linux/bits.h test_bits: Change all the tests to be compile-time tests test_bits: include some invalid input tests for GENMASK_INPUT_CHECK() arch/x86/include/asm/tlb.h | 2 +- .../media/common/videobuf2/videobuf2-core.c | 6 +- .../net/ethernet/intel/ixgbevf/ixgbevf_main.c | 17 +-- .../fixedbds_1.0/ia_css_fixedbds_param.h | 5 +- include/asm-generic/thread_info_tif.h | 2 +- include/linux/bits.h | 88 ++++++++---- include/linux/overflow.h | 2 +- include/vdso/bits.h | 2 +- lib/tests/test_bits.c | 130 +++++++++++------- scripts/Makefile.warn | 12 +- 10 files changed, 162 insertions(+), 104 deletions(-) -- 2.39.5
On 23/01/2026 at 09:24, Andy Shevchenko wrote: After the project hiatus, I can imagine that there is some confusion :) But Chris is back in his role of maintainer since September 2025. See: - https://lore.kernel.org/linux-sparse/CACePvbXDO1ZybDu3RaFhED9D-9gC6LTMpWrxoh5xD+ZO5SLdzA@mail.gmail.com/ - https://git.kernel.org/pub/scm/devel/sparse/sparse.git/commit/?id=67f0a03cee4637e495151c48a02be642a158cbbb I am out of context here, but were the correct people CCed? Yours sincerely, Vincent Mailhol
{ "author": "Vincent Mailhol <mailhol@kernel.org>", "date": "Fri, 23 Jan 2026 09:32:39 +0100", "thread_id": "aYDt8gLSRbFHwVpn@yury.mbox.gz" }