Message ID | 20210225125921.13147-1-will@kernel.org |
---|---|
Headers | show |
Series | Fix CMDLINE_EXTEND handling for FDT "bootargs" | expand |
On Thu, 25 Feb 2021 12:59:20 +0000, Will Deacon <will@kernel.org> wrote: > > The built-in kernel commandline (CONFIG_CMDLINE) can be configured in > three different ways: > > 1. CMDLINE_FORCE: Use CONFIG_CMDLINE instead of any bootloader args > 2. CMDLINE_EXTEND: Append the bootloader args to CONFIG_CMDLINE > 3. CMDLINE_FROM_BOOTLOADER: Only use CONFIG_CMDLINE if there aren't > any bootloader args. > > The early cmdline parsing to detect idreg overrides gets (2) and (3) > slightly wrong: in the case of (2) the bootloader args are parsed first > and in the case of (3) the CMDLINE is always parsed. > > Fix these issues by moving the bootargs parsing out into a helper > function and following the same logic as that used by the EFI stub. > > Cc: Marc Zyngier <maz@kernel.org> > Fixes: 33200303553d ("arm64: cpufeature: Add an early command-line cpufeature override facility") > Signed-off-by: Will Deacon <will@kernel.org> > --- > arch/arm64/kernel/idreg-override.c | 44 +++++++++++++++++------------- > 1 file changed, 25 insertions(+), 19 deletions(-) > > diff --git a/arch/arm64/kernel/idreg-override.c b/arch/arm64/kernel/idreg-override.c > index dffb16682330..cc071712c6f9 100644 > --- a/arch/arm64/kernel/idreg-override.c > +++ b/arch/arm64/kernel/idreg-override.c > @@ -163,33 +163,39 @@ static __init void __parse_cmdline(const char *cmdline, bool parse_aliases) > } while (1); > } > > -static __init void parse_cmdline(void) > +static __init const u8 *get_bootargs_cmdline(void) > { > - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { > - const u8 *prop; > - void *fdt; > - int node; > + const u8 *prop; > + void *fdt; > + int node; > > - fdt = get_early_fdt_ptr(); > - if (!fdt) > - goto out; > + fdt = get_early_fdt_ptr(); > + if (!fdt) > + return NULL; > > - node = fdt_path_offset(fdt, "/chosen"); > - if (node < 0) > - goto out; > + node = fdt_path_offset(fdt, "/chosen"); > + if (node < 0) > + return NULL; > > - prop = fdt_getprop(fdt, node, "bootargs", NULL); > - if (!prop) > - goto out; > + prop = fdt_getprop(fdt, node, "bootargs", NULL); > + if (!prop) > + return NULL; > > - __parse_cmdline(prop, true); > + return strlen(prop) ? prop : NULL; > +} > > - if (!IS_ENABLED(CONFIG_CMDLINE_EXTEND)) > - return; > +static __init void parse_cmdline(void) > +{ > + const u8 *prop = get_bootargs_cmdline(); > + > + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || > + IS_ENABLED(CONFIG_CMDLINE_FORCE) || > + !prop) { The logic hurts, but I think I grok it now. The last term is actually a reduction of (IS_ENABLED(CONFIG_CMDLINE_FROM_BOOTLOADER) && !prop) and we know for sure that if none of the other two terms are true, then CMDLINE_FROM_BOOTLOADER *must* be enabled. > + __parse_cmdline(CONFIG_CMDLINE, true); > } > > -out: > - __parse_cmdline(CONFIG_CMDLINE, true); > + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE) && prop) > + __parse_cmdline(prop, true); > } > > /* Keep checkers quiet */ I don't think we need to backport anything to stable for the nokaslr handling, do we? Otherwise, Reviewed-by: Marc Zyngier <maz@kernel.org> Thanks, M.
On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: > > Hi folks, > > We recently [1] enabled support for CMDLINE_EXTEND on arm64, however > when I started looking at replacing Android's out-of-tree implementation [2] Did anyone go read the common, reworked version of all this I referenced that supports prepend and append. Here it is again[1]. Maybe I should have been more assertive there and said 'extend' is ambiguous. > with the upstream version, I noticed that the two behave significantly > differently: Android follows the Kconfig help text of appending the > bootloader arguments to the kernel command line, whereas upstream appends > the kernel command line to the bootloader arguments. That is, except for > the EFI stub, which follows the documented behaviour. > > I think the documented behaviour is more useful, so this patch series > reworks the FDT code to follow that and updates the very recently merged > arm64 idreg early command-line parsing as well. I can just as easily argue that the kernel having the last say makes sense. Regardless, I'm pretty sure there's someone out there relying on current behavior. What is the impact of this change to other arches? Rob [1] https://lore.kernel.org/lkml/20190319232448.45964-2-danielwa@cisco.com/
On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: > On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: > > We recently [1] enabled support for CMDLINE_EXTEND on arm64, however > > when I started looking at replacing Android's out-of-tree implementation [2] > > Did anyone go read the common, reworked version of all this I > referenced that supports prepend and append. Here it is again[1]. > Maybe I should have been more assertive there and said 'extend' is > ambiguous. I tried reading that, but (a) most of the series is not in the mailing list archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. Right now the code in mainline does the opposite of what it's documented to do. > > with the upstream version, I noticed that the two behave significantly > > differently: Android follows the Kconfig help text of appending the > > bootloader arguments to the kernel command line, whereas upstream appends > > the kernel command line to the bootloader arguments. That is, except for > > the EFI stub, which follows the documented behaviour. > > > > I think the documented behaviour is more useful, so this patch series > > reworks the FDT code to follow that and updates the very recently merged > > arm64 idreg early command-line parsing as well. > > I can just as easily argue that the kernel having the last say makes > sense. Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing against both the documentation and the EFI stub implementation. > Regardless, I'm pretty sure there's someone out there relying on current > behavior. What is the impact of this change to other arches? On arm64, I doubt it, as Android is the main user of this (where it's been supported for 9 years with the documented behaviour). The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is figured out. I think that's preferable to having divergent behaviour. As for other architectures, I think the ATAGs-based solution on arch/arm/ gets it right: static int __init parse_tag_cmdline(const struct tag *tag) { #if defined(CONFIG_CMDLINE_EXTEND) strlcat(default_command_line, " ", COMMAND_LINE_SIZE); strlcat(default_command_line, tag->u.cmdline.cmdline, COMMAND_LINE_SIZE); For now I think we have two options for arm64: either fix the fdt code, or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which do you prefer? Will
+PPC folks and Daniel W On Mon, Mar 1, 2021 at 8:42 AM Will Deacon <will@kernel.org> wrote: > > On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: > > On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: > > > We recently [1] enabled support for CMDLINE_EXTEND on arm64, however > > > when I started looking at replacing Android's out-of-tree implementation [2] > > > > Did anyone go read the common, reworked version of all this I > > referenced that supports prepend and append. Here it is again[1]. > > Maybe I should have been more assertive there and said 'extend' is > > ambiguous. > > I tried reading that, but (a) most of the series is not in the mailing list > archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. > Right now the code in mainline does the opposite of what it's documented to > do. Actually, there is a newer version I found: https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danielwa@cisco.com/ https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danielwa@cisco.com/ https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danielwa@cisco.com/ (Once again, there's some weird threading going on) > > > with the upstream version, I noticed that the two behave significantly > > > differently: Android follows the Kconfig help text of appending the > > > bootloader arguments to the kernel command line, whereas upstream appends > > > the kernel command line to the bootloader arguments. That is, except for > > > the EFI stub, which follows the documented behaviour. > > > > > > I think the documented behaviour is more useful, so this patch series > > > reworks the FDT code to follow that and updates the very recently merged > > > arm64 idreg early command-line parsing as well. > > > > I can just as easily argue that the kernel having the last say makes > > sense. > > Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing > against both the documentation and the EFI stub implementation. CMDLINE_FORCE is a complete override, not a merging of command lines. > > Regardless, I'm pretty sure there's someone out there relying on current > > behavior. What is the impact of this change to other arches? > > On arm64, I doubt it, as Android is the main user of this (where it's been > supported for 9 years with the documented behaviour). > > The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is > figured out. I think that's preferable to having divergent behaviour. > > As for other architectures, I think the ATAGs-based solution on arch/arm/ > gets it right: > > static int __init parse_tag_cmdline(const struct tag *tag) > { > #if defined(CONFIG_CMDLINE_EXTEND) > strlcat(default_command_line, " ", COMMAND_LINE_SIZE); > strlcat(default_command_line, tag->u.cmdline.cmdline, > COMMAND_LINE_SIZE); The question is really whether any arm32 DT based platform depends on the current behavior. RiscV could also be relying on current behavior. Powerpc also uses the current behavior (and the documentation is also wrong there). Changing the behavior in the FDT code means the powerpc early PROM code and the FDT code do the opposite. Arm32 has had current behaviour for 5 years. Powerpc for 1.5 years and Risc-V for 2 years. Then there's MIPS which has its own Kconfig symbols for this and is its own kind of mess. Either we assume existing users didn't really care about the order or we have to support both prepend and append. > For now I think we have two options for arm64: either fix the fdt code, > or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which > do you prefer? Like anything copied across arches, I want someone to look at this across all architectures and make this common instead of just copying to new arches. The prepend/append series is the closest we've come. Rob
Le 01/03/2021 à 18:26, Rob Herring a écrit : > +PPC folks and Daniel W > > On Mon, Mar 1, 2021 at 8:42 AM Will Deacon <will@kernel.org> wrote: >> >> On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: >>> On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: >>>> We recently [1] enabled support for CMDLINE_EXTEND on arm64, however >>>> when I started looking at replacing Android's out-of-tree implementation [2] >>> >>> Did anyone go read the common, reworked version of all this I >>> referenced that supports prepend and append. Here it is again[1]. >>> Maybe I should have been more assertive there and said 'extend' is >>> ambiguous. >> >> I tried reading that, but (a) most of the series is not in the mailing list >> archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. >> Right now the code in mainline does the opposite of what it's documented to >> do. > > Actually, there is a newer version I found: > > https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danielwa@cisco.com/ > https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danielwa@cisco.com/ > https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danielwa@cisco.com/ This was seen as too much intrusive into powerpc. I proposed an alternative at https://patchwork.ozlabs.org/project/linuxppc-dev/cover/cover.1554195798.git.christophe.leroy@c-s.fr/ but never got any feedback. > > (Once again, there's some weird threading going on) > >>>> with the upstream version, I noticed that the two behave significantly >>>> differently: Android follows the Kconfig help text of appending the >>>> bootloader arguments to the kernel command line, whereas upstream appends >>>> the kernel command line to the bootloader arguments. That is, except for >>>> the EFI stub, which follows the documented behaviour. >>>> >>>> I think the documented behaviour is more useful, so this patch series >>>> reworks the FDT code to follow that and updates the very recently merged >>>> arm64 idreg early command-line parsing as well. >>> >>> I can just as easily argue that the kernel having the last say makes >>> sense. >> >> Dunno, I'd say that's what CMDLINE_FORCE is for. Plus you'd be arguing >> against both the documentation and the EFI stub implementation. > > CMDLINE_FORCE is a complete override, not a merging of command lines. > >>> Regardless, I'm pretty sure there's someone out there relying on current >>> behavior. What is the impact of this change to other arches? >> >> On arm64, I doubt it, as Android is the main user of this (where it's been >> supported for 9 years with the documented behaviour). >> >> The other option, then, is reverting CMDLINE_EXTEND from arm64 until this is >> figured out. I think that's preferable to having divergent behaviour. >> >> As for other architectures, I think the ATAGs-based solution on arch/arm/ >> gets it right: >> >> static int __init parse_tag_cmdline(const struct tag *tag) >> { >> #if defined(CONFIG_CMDLINE_EXTEND) >> strlcat(default_command_line, " ", COMMAND_LINE_SIZE); >> strlcat(default_command_line, tag->u.cmdline.cmdline, >> COMMAND_LINE_SIZE); > > The question is really whether any arm32 DT based platform depends on > the current behavior. RiscV could also be relying on current behavior. > Powerpc also uses the current behavior (and the documentation is also > wrong there). Changing the behavior in the FDT code means the powerpc > early PROM code and the FDT code do the opposite. > > Arm32 has had current behaviour for 5 years. Powerpc for 1.5 years and > Risc-V for 2 years. Then there's MIPS which has its own Kconfig > symbols for this and is its own kind of mess. Either we assume > existing users didn't really care about the order or we have to > support both prepend and append. > >> For now I think we have two options for arm64: either fix the fdt code, >> or revert CMDLINE_EXTEND until the PREPEND/APPEND series is merged. Which >> do you prefer? > > Like anything copied across arches, I want someone to look at this > across all architectures and make this common instead of just copying > to new arches. The prepend/append series is the closest we've come. > > Rob > Christophe
On Mon, Mar 1, 2021 at 11:45 AM Christophe Leroy <christophe.leroy@csgroup.eu> wrote: > > > > Le 01/03/2021 à 18:26, Rob Herring a écrit : > > +PPC folks and Daniel W > > > > On Mon, Mar 1, 2021 at 8:42 AM Will Deacon <will@kernel.org> wrote: > >> > >> On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: > >>> On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: > >>>> We recently [1] enabled support for CMDLINE_EXTEND on arm64, however > >>>> when I started looking at replacing Android's out-of-tree implementation [2] > >>> > >>> Did anyone go read the common, reworked version of all this I > >>> referenced that supports prepend and append. Here it is again[1]. > >>> Maybe I should have been more assertive there and said 'extend' is > >>> ambiguous. > >> > >> I tried reading that, but (a) most of the series is not in the mailing list > >> archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. > >> Right now the code in mainline does the opposite of what it's documented to > >> do. > > > > Actually, there is a newer version I found: > > > > https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danielwa@cisco.com/ > > https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danielwa@cisco.com/ > > https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danielwa@cisco.com/ > > This was seen as too much intrusive into powerpc. It looked like the main issue was string functions for KASAN? As far as being too complex, I think that will be needed if you look at all architectures and non-DT cases. > I proposed an alternative at > https://patchwork.ozlabs.org/project/linuxppc-dev/cover/cover.1554195798.git.christophe.leroy@c-s.fr/ but > never got any feedback. Didn't go to a list I subscribe to. In particular, if it had gone to DT list and into PW you would have gotten a reply from me. Rob
Le 02/03/2021 à 15:56, Rob Herring a écrit : > On Mon, Mar 1, 2021 at 11:45 AM Christophe Leroy > <christophe.leroy@csgroup.eu> wrote: >> >> >> >> Le 01/03/2021 à 18:26, Rob Herring a écrit : >>> +PPC folks and Daniel W >>> >>> On Mon, Mar 1, 2021 at 8:42 AM Will Deacon <will@kernel.org> wrote: >>>> >>>> On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: >>>>> On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: >>>>>> We recently [1] enabled support for CMDLINE_EXTEND on arm64, however >>>>>> when I started looking at replacing Android's out-of-tree implementation [2] >>>>> >>>>> Did anyone go read the common, reworked version of all this I >>>>> referenced that supports prepend and append. Here it is again[1]. >>>>> Maybe I should have been more assertive there and said 'extend' is >>>>> ambiguous. >>>> >>>> I tried reading that, but (a) most of the series is not in the mailing list >>>> archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. >>>> Right now the code in mainline does the opposite of what it's documented to >>>> do. >>> >>> Actually, there is a newer version I found: >>> >>> https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danielwa@cisco.com/ >>> https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danielwa@cisco.com/ >>> https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danielwa@cisco.com/ >> >> This was seen as too much intrusive into powerpc. > > It looked like the main issue was string functions for KASAN? This is one issue yes, > > As far as being too complex, I think that will be needed if you look > at all architectures and non-DT cases. As far as I remember, I could't understand why we absolutely need to define the command line string in the common part of the code, leading to being obliged to use macros in order to allow the architecture to specify in which section it wants the string. Why not leave the definition of the string to the architecture and just declare it in the common code, allowing the architecture to put it where it suits it and reducing opacity and allowing use of standard static inline functions instead of uggly macros. > >> I proposed an alternative at >> https://patchwork.ozlabs.org/project/linuxppc-dev/cover/cover.1554195798.git.christophe.leroy@c-s.fr/ but >> never got any feedback. > > Didn't go to a list I subscribe to. In particular, if it had gone to > DT list and into PW you would have gotten a reply from me. > Sorry for that. Original series from Daniel (https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20190319232448.45964-2-danielwa@cisco.com/) was sent only to linuxppc-dev list, and Michael suggested to also send it to linux-arch list, and I also always copy linux-kernel. If there is new interest for that functionnality, I can try and rebase my series. Christophe
On Mon, Mar 01, 2021 at 11:26:14AM -0600, Rob Herring wrote: > +PPC folks and Daniel W > > On Mon, Mar 1, 2021 at 8:42 AM Will Deacon <will@kernel.org> wrote: > > > > On Mon, Mar 01, 2021 at 08:19:32AM -0600, Rob Herring wrote: > > > On Thu, Feb 25, 2021 at 6:59 AM Will Deacon <will@kernel.org> wrote: > > > > We recently [1] enabled support for CMDLINE_EXTEND on arm64, however > > > > when I started looking at replacing Android's out-of-tree implementation [2] > > > > > > Did anyone go read the common, reworked version of all this I > > > referenced that supports prepend and append. Here it is again[1]. > > > Maybe I should have been more assertive there and said 'extend' is > > > ambiguous. > > > > I tried reading that, but (a) most of the series is not in the mailing list > > archives and (b) the patch that _is_ doesn't touch CMDLINE_EXTEND at all. > > Right now the code in mainline does the opposite of what it's documented to > > do. > > Actually, there is a newer version I found: > > https://lore.kernel.org/linuxppc-dev/1551469472-53043-1-git-send-email-danielwa@cisco.com/ > https://lore.kernel.org/linuxppc-dev/1551469472-53043-2-git-send-email-danielwa@cisco.com/ > https://lore.kernel.org/linuxppc-dev/1551469472-53043-3-git-send-email-danielwa@cisco.com/ > > (Once again, there's some weird threading going on) > I'm happy to work with anyone to resubmit the changes. We currently use the changes in Cisco, and we have used them for many years. I was planning to update and resubmit since someone has recently inquired about why it wasn't upstream. Daniel