Page MenuHomeFreeBSD

riscv: honor the environment set via the kernel config file
ClosedPublic

Authored by mhorne on May 28 2020, 6:26 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 8:59 AM
Unknown Object (File)
Fri, Dec 6, 6:05 AM
Unknown Object (File)
Wed, Dec 4, 7:31 PM
Unknown Object (File)
Tue, Dec 3, 4:53 AM
Unknown Object (File)
Thu, Nov 21, 6:31 AM
Unknown Object (File)
Tue, Nov 19, 2:00 AM
Unknown Object (File)
Mon, Nov 18, 10:48 PM
Unknown Object (File)
Mon, Nov 18, 6:48 PM
Subscribers

Details

Summary

Initialize the static kernel boot environment, which makes the riscv boot process honor the environment set via the kernel config file

Sponsored by: Axiado

Test Plan

Compile & boot a riscv system/kernel, with some read only tunables set in the kernel config file, e.g.

envvar         "net.fibs=5"
envvar         "net.pf.source_nodes_hashsize=16384"

Verify the read only tunables' values have been correctly applied.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 34698
Build 31761: arc lint + arc unit

Event Timeline

This looks good -- and is known to work. The size of the environment should probably be a constant rather than a magic number though.

sys/riscv/riscv/machdep.c
133

Can this be a defined constant rather than a magic number?

mhorne added inline comments.
sys/riscv/riscv/machdep.c
133

Would you consider a different name? This has nothing to do with boot1.

955

If the only goal is to honor the environment variables from the config, then there is no need to provide a buffer at all; you can simply call init_static_kenv(NULL, 0) and it will perform the initialization. The buffer is useful only if we wanted to manually set some environment variables via calls to kern_setenv().

sys/riscv/riscv/machdep.c
133

arm calls it static_kenv (and also uses 4096 as its size).
It may make sense to just use PAGE_SIZE.

955

I believe we currently don't have a need for kern_setenv() during boot.

I'd keep the buffer for two reasons:

  • It's what the arm and mips platforms do as well
  • We may load drivers or other code that does call kern_setenv(). For example, the nfs boot code calls kern_setenv("boot.netif.name", ifctx->ifp->if_xname);.
sys/riscv/riscv/machdep.c
955

Sorry, I should have clarified: the buffer is only useful for calls to kern_setenv() that occur early in boot, such as in initriscv.

At SI_SUB_KMEM + 1 we switch to a dynamic kenv, after which the two static environments (one from config and the one we would be creating here) are no longer used. This occurs before any driver code is loaded. You can see what I mean in init_dynamic_kenv.

sys/riscv/riscv/machdep.c
133

static char static_kenv[PAGE_SIZE]; perhaps?

955

Ideally, at some point we should support setting those values via entries in the device tree blob for example, or some u-boot environment area perhaps; for that we need the static buffer if I understand correctly

I could remove the buffer and call init_static_kenv(NULL, 0) so we have at least the kernel envvar config option to modify the read-only tunables during kernel build without modifying the source code, and add those other options, incl. the buffer in a later patch...

sys/riscv/riscv/machdep.c
955

Those features would be useful, and if you intend on adding them soon then it's up to you if you want to include the buffer in this patch or later.

sys/riscv/riscv/machdep.c
955

By the way, I have some pending changes to this section of the code in D24912 that will conflict with this. It might be better to place the call to init_static_kenv() in fake_preload_metadata.

mhorne added a reviewer: syrinx.

I've discovered this change should have gone in before rS363345, and is now required to avoid an early panic when trying to parse kenv variables from bootargs. Taking over the review so I can update with a rebased version.

mhorne retitled this revision from riscv: honor the environment set via the kernel config file to riscv: honor the environment set via the kernel config file.
mhorne edited the test plan for this revision. (Show Details)

Rebase the patch. Change the buffer name and use PAGE_SIZE instead of 4096.

Ping. Are we okay with this patch as is?

arm64 puts this in parse_fdt_bootargs

arm64 puts this in parse_fdt_bootargs

It does. I find this placement slightly more intuitive, but if you disagree then I can move it to that function.

I'm happy with it as-is.

This revision is now accepted and ready to land.Nov 19 2020, 4:25 PM