linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Rob Herring <robh+dt@kernel.org>
Cc: linux-kernel@vger.kernel.org, Alexander Graf <graf@amazon.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Andy Lutomirski <luto@kernel.org>,
	Anthony Yznaga <anthony.yznaga@oracle.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Ashish Kalra <ashish.kalra@amd.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Borislav Petkov <bp@alien8.de>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Eric Biederman <ebiederm@xmission.com>,
	Ingo Molnar <mingo@redhat.com>, James Gowans <jgowans@amazon.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Krzysztof Kozlowski <krzk@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Pasha Tatashin <pasha.tatashin@soleen.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Pratyush Yadav <ptyadav@amazon.de>,
	Saravana Kannan <saravanak@google.com>,
	Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Usama Arif <usama.arif@bytedance.com>,
	Will Deacon <will@kernel.org>,
	devicetree@vger.kernel.org, kexec@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org,
	linux-mm@kvack.org, x86@kernel.org
Subject: Re: [PATCH v4 13/14] memblock: Add KHO support for reserve_mem
Date: Wed, 12 Feb 2025 18:30:08 +0200	[thread overview]
Message-ID: <Z6zMkLhu0ALC8MfG@kernel.org> (raw)
In-Reply-To: <CAL_JsqLBf1Vv6K5mK6x9JRqegvScSNFpAEE2iJOkJ4JuBTLsCw@mail.gmail.com>

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@kernel.org> wrote:
> >
> > From: Alexander Graf <graf@amazon.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@amazon.com>
> > Co-developed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.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.


  reply	other threads:[~2025-02-12 16:30 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-06 13:27 [PATCH v4 00/14] kexec: introduce Kexec HandOver (KHO) Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 01/14] mm/mm_init: rename init_reserved_page to init_deferred_page Mike Rapoport
2025-02-18 14:59   ` Wei Yang
2025-02-19  7:13     ` Mike Rapoport
2025-02-20  8:36       ` Wei Yang
2025-02-20 14:54         ` Mike Rapoport
2025-02-25  7:40         ` Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 02/14] memblock: add MEMBLOCK_RSRV_KERN flag Mike Rapoport
2025-02-18 15:50   ` Wei Yang
2025-02-19  7:24     ` Mike Rapoport
2025-02-23  0:22       ` Wei Yang
2025-03-10  9:51         ` Wei Yang
2025-03-11  5:27           ` Mike Rapoport
2025-03-11 13:41             ` Wei Yang
2025-03-12  5:22               ` Mike Rapoport
2025-02-24  1:31       ` Wei Yang
2025-02-25  7:46         ` Mike Rapoport
2025-02-26  2:09           ` Wei Yang
2025-03-10  7:56             ` Wei Yang
2025-03-10  8:28               ` Mike Rapoport
2025-03-10  9:42                 ` Wei Yang
2025-02-26  1:53   ` Changyuan Lyu
2025-03-13 15:41     ` Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 03/14] memblock: Add support for scratch memory Mike Rapoport
2025-02-24  2:50   ` Wei Yang
2025-02-25  7:47     ` Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 04/14] memblock: introduce memmap_init_kho_scratch() Mike Rapoport
2025-02-24  3:02   ` Wei Yang
2025-02-06 13:27 ` [PATCH v4 05/14] kexec: Add Kexec HandOver (KHO) generation helpers Mike Rapoport
2025-02-10 20:22   ` Jason Gunthorpe
2025-02-10 20:58     ` Pasha Tatashin
2025-02-11 12:49       ` Jason Gunthorpe
2025-02-11 16:14         ` Pasha Tatashin
2025-02-11 16:37           ` Jason Gunthorpe
2025-02-12 15:23             ` Jason Gunthorpe
2025-02-12 16:39               ` Mike Rapoport
2025-02-12 17:43                 ` Jason Gunthorpe
2025-02-23 18:51                   ` Mike Rapoport
2025-02-24 14:28                     ` Jason Gunthorpe
2025-02-12 12:29   ` Thomas Weißschuh
2025-02-06 13:27 ` [PATCH v4 06/14] kexec: Add KHO parsing support Mike Rapoport
2025-02-10 20:50   ` Jason Gunthorpe
2025-03-10 16:20   ` Pratyush Yadav
2025-03-10 17:08     ` Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 07/14] kexec: Add KHO support to kexec file loads Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 08/14] kexec: Add config option for KHO Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 09/14] kexec: Add documentation " Mike Rapoport
2025-02-10 19:26   ` Jason Gunthorpe
2025-02-06 13:27 ` [PATCH v4 10/14] arm64: Add KHO support Mike Rapoport
2025-02-09 10:38   ` Krzysztof Kozlowski
2025-02-06 13:27 ` [PATCH v4 11/14] x86/setup: use memblock_reserve_kern for memory used by kernel Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 12/14] x86: Add KHO support Mike Rapoport
2025-02-24  7:13   ` Wei Yang
2025-02-24 14:36     ` Mike Rapoport
2025-02-25  0:00       ` Wei Yang
2025-02-06 13:27 ` [PATCH v4 13/14] memblock: Add KHO support for reserve_mem Mike Rapoport
2025-02-10 16:03   ` Rob Herring
2025-02-12 16:30     ` Mike Rapoport [this message]
2025-02-17  4:04   ` Wei Yang
2025-02-19  7:25     ` Mike Rapoport
2025-02-06 13:27 ` [PATCH v4 14/14] Documentation: KHO: Add memblock bindings Mike Rapoport
2025-02-09 10:29   ` Krzysztof Kozlowski
2025-02-09 15:10     ` Mike Rapoport
2025-02-09 15:23       ` Krzysztof Kozlowski
2025-02-09 20:41         ` Mike Rapoport
2025-02-09 20:49           ` Krzysztof Kozlowski
2025-02-09 20:50             ` Krzysztof Kozlowski
2025-02-10 19:15               ` Jason Gunthorpe
2025-02-10 19:27                 ` Krzysztof Kozlowski
2025-02-10 20:20                   ` Jason Gunthorpe
2025-02-12 16:00                     ` Mike Rapoport
2025-02-07  0:29 ` [PATCH v4 00/14] kexec: introduce Kexec HandOver (KHO) Andrew Morton
2025-02-07  1:28   ` Pasha Tatashin
2025-02-08  1:38     ` Baoquan He
2025-02-08  8:41       ` Mike Rapoport
2025-02-08 11:13         ` Baoquan He
2025-02-09  0:23       ` Pasha Tatashin
2025-02-09  3:07         ` Baoquan He
2025-02-07  8:06   ` Mike Rapoport
2025-02-09 10:33   ` Krzysztof Kozlowski
2025-02-07  4:50 ` Andrew Morton
2025-02-07  8:01   ` Mike Rapoport
2025-02-08 23:39 ` Cong Wang
2025-02-09  0:13   ` Pasha Tatashin
2025-02-09  1:00     ` Cong Wang
2025-02-09  0:51 ` Cong Wang
2025-02-17  3:19 ` RuiRui Yang
2025-02-19  7:32   ` Mike Rapoport
2025-02-19 12:49     ` Dave Young
2025-02-19 13:54       ` Alexander Graf
2025-02-20  1:49         ` Dave Young
2025-02-20 16:43           ` Alexander Gordeev
2025-02-23 17:54             ` Mike Rapoport
2025-02-26 20:08 ` Pratyush Yadav
2025-02-28 20:20   ` Mike Rapoport
2025-02-28 23:04     ` Pratyush Yadav
2025-03-02  9:52       ` Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Z6zMkLhu0ALC8MfG@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=anthony.yznaga@oracle.com \
    --cc=arnd@arndb.de \
    --cc=ashish.kalra@amd.com \
    --cc=benh@kernel.crashing.org \
    --cc=bp@alien8.de \
    --cc=catalin.marinas@arm.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=ebiederm@xmission.com \
    --cc=graf@amazon.com \
    --cc=hpa@zytor.com \
    --cc=jgowans@amazon.com \
    --cc=kexec@lists.infradead.org \
    --cc=krzk@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=pasha.tatashin@soleen.com \
    --cc=pbonzini@redhat.com \
    --cc=peterz@infradead.org \
    --cc=ptyadav@amazon.de \
    --cc=robh+dt@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=saravanak@google.com \
    --cc=skinsburskii@linux.microsoft.com \
    --cc=tglx@linutronix.de \
    --cc=thomas.lendacky@amd.com \
    --cc=usama.arif@bytedance.com \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox