[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Z6zMkLhu0ALC8MfG@kernel.org>
Date: Wed, 12 Feb 2025 18:30:08 +0200
From: Mike Rapoport <rppt@...nel.org>
To: Rob Herring <robh+dt@...nel.org>
Cc: linux-kernel@...r.kernel.org, Alexander Graf <graf@...zon.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Andy Lutomirski <luto@...nel.org>,
Anthony Yznaga <anthony.yznaga@...cle.com>,
Arnd Bergmann <arnd@...db.de>, Ashish Kalra <ashish.kalra@....com>,
Benjamin Herrenschmidt <benh@...nel.crashing.org>,
Borislav Petkov <bp@...en8.de>,
Catalin Marinas <catalin.marinas@....com>,
Dave Hansen <dave.hansen@...ux.intel.com>,
David Woodhouse <dwmw2@...radead.org>,
Eric Biederman <ebiederm@...ssion.com>,
Ingo Molnar <mingo@...hat.com>, James Gowans <jgowans@...zon.com>,
Jonathan Corbet <corbet@....net>,
Krzysztof Kozlowski <krzk@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Paolo Bonzini <pbonzini@...hat.com>,
Pasha Tatashin <pasha.tatashin@...een.com>,
"H. Peter Anvin" <hpa@...or.com>,
Peter Zijlstra <peterz@...radead.org>,
Pratyush Yadav <ptyadav@...zon.de>,
Saravana Kannan <saravanak@...gle.com>,
Stanislav Kinsburskii <skinsburskii@...ux.microsoft.com>,
Steven Rostedt <rostedt@...dmis.org>,
Thomas Gleixner <tglx@...utronix.de>,
Tom Lendacky <thomas.lendacky@....com>,
Usama Arif <usama.arif@...edance.com>,
Will Deacon <will@...nel.org>, devicetree@...r.kernel.org,
kexec@...ts.infradead.org, linux-arm-kernel@...ts.infradead.org,
linux-doc@...r.kernel.org, linux-mm@...ck.org, x86@...nel.org
Subject: Re: [PATCH v4 13/14] memblock: Add KHO support for reserve_mem
On Mon, Feb 10, 2025 at 10:03:58AM -0600, Rob Herring wrote:
> On Thu, Feb 6, 2025 at 7:30 AM Mike Rapoport <rppt@...nel.org> wrote:
> >
> > From: Alexander Graf <graf@...zon.com>
> >
> > Linux has recently gained support for "reserve_mem": A mechanism to
> > allocate a region of memory early enough in boot that we can cross our
> > fingers and hope it stays at the same location during most boots, so we
> > can store for example ftrace buffers into it.
> >
> > Thanks to KASLR, we can never be really sure that "reserve_mem"
> > allocations are static across kexec. Let's teach it KHO awareness so
> > that it serializes its reservations on kexec exit and deserializes them
> > again on boot, preserving the exact same mapping across kexec.
> >
> > This is an example user for KHO in the KHO patch set to ensure we have
> > at least one (not very controversial) user in the tree before extending
> > KHO's use to more subsystems.
> >
> > Signed-off-by: Alexander Graf <graf@...zon.com>
> > Co-developed-by: Mike Rapoport (Microsoft) <rppt@...nel.org>
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@...nel.org>
> > ---
> > mm/memblock.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 131 insertions(+)
> >
> > diff --git a/mm/memblock.c b/mm/memblock.c
> > index 84df96efca62..fdb08b60efc1 100644
> > --- a/mm/memblock.c
> > +++ b/mm/memblock.c
> > @@ -16,6 +16,9 @@
> > #include <linux/kmemleak.h>
> > #include <linux/seq_file.h>
> > #include <linux/memblock.h>
> > +#include <linux/kexec_handover.h>
> > +#include <linux/kexec.h>
> > +#include <linux/libfdt.h>
> >
> > #include <asm/sections.h>
> > #include <linux/io.h>
> > @@ -2423,6 +2426,70 @@ int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *
> > }
> > EXPORT_SYMBOL_GPL(reserve_mem_find_by_name);
> >
> > +static bool __init reserve_mem_kho_revive(const char *name, phys_addr_t size,
> > + phys_addr_t align)
> > +{
> > + const void *fdt = kho_get_fdt();
> > + const char *path = "/reserve_mem";
> > + int node, child, err;
> > +
> > + if (!IS_ENABLED(CONFIG_KEXEC_HANDOVER))
> > + return false;
> > +
> > + if (!fdt)
> > + return false;
> > +
> > + node = fdt_path_offset(fdt, "/reserve_mem");
> > + if (node < 0)
> > + return false;
> > +
> > + err = fdt_node_check_compatible(fdt, node, "reserve_mem-v1");
> > + if (err) {
> > + pr_warn("Node '%s' has unknown compatible", path);
> > + return false;
> > + }
> > +
> > + fdt_for_each_subnode(child, fdt, node) {
> > + const struct kho_mem *mem;
> > + const char *child_name;
> > + int len;
> > +
> > + /* Search for old kernel's reserved_mem with the same name */
> > + child_name = fdt_get_name(fdt, child, NULL);
> > + if (strcmp(name, child_name))
> > + continue;
> > +
> > + err = fdt_node_check_compatible(fdt, child, "reserve_mem_map-v1");
>
> It really seems you all are trying to have things both ways. It's not
> Devicetree, just the FDT file format, but then here you use
> "compatible" which *is* Devicetree. At best, it's all just confusing
> for folks. At worst, you're just picking and choosing what you want to
> use.
>
> I'm not saying don't use "compatible" just for the sake of looking
> less like DT, but perhaps your versioning should be done differently.
> You are reading the 'mem' property straight into a struct. Maybe the
> struct should have a version. Or the size of the struct is the version
> much like the userspace ABI is handled for structs.
The idea is to have high level compatibility notion for node level and up
rather than verify that for each and every struct like uABI does.
For that "compatible" seems just a perfect fit.
> > + if (err) {
> > + pr_warn("Node '%s/%s' has unknown compatible", path, name);
> > + continue;
> > + }
> > +
> > + mem = fdt_getprop(fdt, child, "mem", &len);
> > + if (!mem || len != sizeof(*mem))
> > + continue;
> > +
> > + if (mem->addr & (align - 1)) {
>
> It's stated somewhere in this that the FDT data is LE, but here you
> are assuming the FDT is the same endianness as the CPU not that it's
> LE. Arm64 can do BE. PowerPC does both. I'm not sure if kexec from one
> endianness to another is possible. I would guess in theory it is and
> in practice it's broken already (because kexec is always an
> afterthought). Either you need to guarantee that native endianness
> will never be an issue for any arch or you need to make the endianness
> fixed.
I believe Alex mentioned little endian in the sense of native endianness
for practical purposes :)
Since arm64 does seem to support kexec from one endianness to another in
certain circumstances, but I believe that we can limit KHO only to work
when both kernels have the same endianness.
> Rob
--
Sincerely yours,
Mike.
Powered by blists - more mailing lists