All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pingfan Liu <piliu@redhat.com>
To: Philipp Rudo <prudo@redhat.com>
Cc: kexec@lists.infradead.org, Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	John Fastabend <john.fastabend@gmail.com>,
	Andrii Nakryiko <andrii@kernel.org>,
	Martin KaFai Lau <martin.lau@linux.dev>,
	Eduard Zingerman <eddyz87@gmail.com>, Song Liu <song@kernel.org>,
	Yonghong Song <yonghong.song@linux.dev>,
	Jeremy Linton <jeremy.linton@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>, Ard Biesheuvel <ardb@kernel.org>,
	Simon Horman <horms@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Vitaly Kuznetsov <vkuznets@redhat.com>,
	Viktor Malik <vmalik@redhat.com>,
	Jan Hendrik Farr <kernel@jfarr.cc>, Baoquan He <bhe@redhat.com>,
	Dave Young <dyoung@redhat.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	bpf@vger.kernel.org, systemd-devel@lists.freedesktop.org
Subject: Re: [PATCHv5 06/12] kexec: Integrate with the introduced bpf kfuncs
Date: Tue, 16 Sep 2025 14:52:38 +0800	[thread overview]
Message-ID: <aMkJNuORiqSZfpok@fedora> (raw)
In-Reply-To: <20250901163042.721db92d@rotkaeppchen>

On Mon, Sep 01, 2025 at 04:30:42PM +0200, Philipp Rudo wrote:
> Hi Pingfan,
> 
> 
> On Tue, 19 Aug 2025 09:24:22 +0800
> Pingfan Liu <piliu@redhat.com> wrote:
> 
> > This patch does two things:
> > First, register as a listener on bpf_copy_to_kernel()
> > Second, in order that the hooked bpf-prog can call the sleepable kfuncs,
> > bpf_handle_pefile and bpf_post_handle_pefile are marked as
> > KF_SLEEPABLE.
> > 
> > Signed-off-by: Pingfan Liu <piliu@redhat.com>
> > Cc: Alexei Starovoitov <ast@kernel.org>
> > Cc: Philipp Rudo <prudo@redhat.com>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Dave Young <dyoung@redhat.com>
> > Cc: Andrew Morton <akpm@linux-foundation.org>
> > Cc: bpf@vger.kernel.org
> > To: kexec@lists.infradead.org
> > ---
> >  kernel/kexec_pe_image.c | 67 +++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 67 insertions(+)
> > 
> > diff --git a/kernel/kexec_pe_image.c b/kernel/kexec_pe_image.c
> > index b0cf9942e68d2..f8debcde6b516 100644
> > --- a/kernel/kexec_pe_image.c
> > +++ b/kernel/kexec_pe_image.c
> > @@ -38,6 +38,51 @@ static struct kexec_res parsed_resource[3] = {
> >  	{ KEXEC_RES_CMDLINE_NAME, },
> >  };
> >  
> > +/*
> > + * @name should be one of : kernel, initrd, cmdline
> > + */
> > +static int bpf_kexec_carrier(const char *name, struct mem_range_result *r)
> > +{
> > +	struct kexec_res *res;
> > +	int i;
> > +
> > +	if (!r || !name)
> > +		return -EINVAL;
> > +
> > +	for (i = 0; i < 3; i++) {
> > +		if (!strcmp(parsed_resource[i].name, name))
> > +			break;
> > +	}
> > +	if (i >= 3)
> > +		return -EINVAL;
> 
> Can you please replace the magic '3' by ARRAY_SIZE, just like you did
> below when (un-)registering the listener.
> 

Yes, I will introduce a macro KEXEC_RES_ARRAY_SIZE to unify all of them.

Thanks,

Pingfan

> Thanks
> Philipp
> 
> > +
> > +	res = &parsed_resource[i];
> > +	/*
> > +	 * Replace the intermediate resource generated by the previous step.
> > +	 */
> > +	if (!!res->r)
> > +		mem_range_result_put(res->r);
> > +	mem_range_result_get(r);
> > +	res->r = r;
> > +	return 0;
> > +}
> > +
> > +static struct carrier_listener kexec_res_listener[3] = {
> > +	{ .name = KEXEC_RES_KERNEL_NAME,
> > +	  .alloc_type = 1,
> > +	  .handler = bpf_kexec_carrier,
> > +	},
> > +	{ .name = KEXEC_RES_INITRD_NAME,
> > +	  .alloc_type = 1,
> > +	  .handler = bpf_kexec_carrier,
> > +	},
> > +	{ .name = KEXEC_RES_CMDLINE_NAME,
> > +	  /* kmalloc-ed */
> > +	  .alloc_type = 0,
> > +	  .handler = bpf_kexec_carrier,
> > +	},
> > +};
> > +
> >  static bool pe_has_bpf_section(const char *file_buf, unsigned long pe_sz);
> >  
> >  static bool is_valid_pe(const char *kernel_buf, unsigned long kernel_len)
> > @@ -159,6 +204,22 @@ __attribute__((used, optimize("O0"))) void bpf_post_handle_pefile(struct kexec_c
> >  	dummy += 2;
> >  }
> >  
> > +BTF_KFUNCS_START(kexec_modify_return_ids)
> > +BTF_ID_FLAGS(func, bpf_handle_pefile, KF_SLEEPABLE)
> > +BTF_ID_FLAGS(func, bpf_post_handle_pefile, KF_SLEEPABLE)
> > +BTF_KFUNCS_END(kexec_modify_return_ids)
> > +
> > +static const struct btf_kfunc_id_set kexec_modify_return_set = {
> > +	.owner = THIS_MODULE,
> > +	.set = &kexec_modify_return_ids,
> > +};
> > +
> > +static int __init kexec_bpf_prog_run_init(void)
> > +{
> > +	return register_btf_fmodret_id_set(&kexec_modify_return_set);
> > +}
> > +late_initcall(kexec_bpf_prog_run_init);
> > +
> >  /*
> >   * PE file may be nested and should be unfold one by one.
> >   * Query 'kernel', 'initrd', 'cmdline' in cur_phase, as they are inputs for the
> > @@ -213,6 +274,9 @@ static void *pe_image_load(struct kimage *image,
> >  	cmdline_start = cmdline;
> >  	cmdline_sz = cmdline_len;
> >  
> > +	for (int i = 0; i < ARRAY_SIZE(kexec_res_listener); i++)
> > +		register_carrier_listener(&kexec_res_listener[i]);
> > +
> >  	while (is_valid_format(linux_start, linux_sz) &&
> >  	       pe_has_bpf_section(linux_start, linux_sz)) {
> >  		struct kexec_context context;
> > @@ -250,6 +314,9 @@ static void *pe_image_load(struct kimage *image,
> >  		disarm_bpf_prog();
> >  	}
> >  
> > +	for (int i = 0; i < ARRAY_SIZE(kexec_res_listener); i++)
> > +		unregister_carrier_listener(kexec_res_listener[i].name);
> > +
> >  	/*
> >  	 * image's kernel_buf, initrd_buf, cmdline_buf are set. Now they should
> >  	 * be updated to the new content.
> 


  reply	other threads:[~2025-09-16  6:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-19  1:24 [PATCHv5 00/12] kexec: Use BPF lskel to enable kexec to load PE format boot image Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 01/12] kexec_file: Make kexec_image_load_default global visible Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 02/12] lib/decompress: Keep decompressor when CONFIG_KEEP_COMPRESSOR Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 03/12] bpf: Introduce bpf_copy_to_kernel() to buffer the content from bpf-prog Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 04/12] bpf: Introduce decompressor kfunc Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 05/12] kexec: Introduce kexec_pe_image to parse and load PE file Pingfan Liu
2025-09-01 14:30   ` Philipp Rudo
2025-09-17 13:04     ` Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 06/12] kexec: Integrate with the introduced bpf kfuncs Pingfan Liu
2025-09-01 14:30   ` Philipp Rudo
2025-09-16  6:52     ` Pingfan Liu [this message]
2025-09-18 13:43       ` Philipp Rudo
2025-09-19  1:26         ` Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 07/12] kexec: Introduce a bpf-prog lskel to parse PE file Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 08/12] kexec: Factor out routine to find a symbol in ELF Pingfan Liu
2025-09-01 14:31   ` Philipp Rudo
2025-09-16  1:27     ` Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 09/12] kexec: Integrate bpf light skeleton to load zboot image Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 10/12] arm64/kexec: Add PE image format support Pingfan Liu
2025-08-19 18:23   ` kernel test robot
2025-08-19 18:54   ` kernel test robot
2025-08-20  3:09   ` Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 11/12] tools/kexec: Introduce a bpf-prog to parse zboot image format Pingfan Liu
2025-08-19  1:24 ` [PATCHv5 12/12] tools/kexec: Add a zboot image building tool Pingfan Liu
2025-09-01 14:29 ` [PATCHv5 00/12] kexec: Use BPF lskel to enable kexec to load PE format boot image Philipp Rudo
2025-09-16  2:00   ` Pingfan Liu
2025-09-18 13:43     ` Philipp Rudo

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=aMkJNuORiqSZfpok@fedora \
    --to=piliu@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrii@kernel.org \
    --cc=ardb@kernel.org \
    --cc=ast@kernel.org \
    --cc=bhe@redhat.com \
    --cc=bpf@vger.kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=daniel@iogearbox.net \
    --cc=dyoung@redhat.com \
    --cc=eddyz87@gmail.com \
    --cc=horms@kernel.org \
    --cc=jeremy.linton@arm.com \
    --cc=john.fastabend@gmail.com \
    --cc=kernel@jfarr.cc \
    --cc=kexec@lists.infradead.org \
    --cc=kraxel@redhat.com \
    --cc=martin.lau@linux.dev \
    --cc=prudo@redhat.com \
    --cc=song@kernel.org \
    --cc=systemd-devel@lists.freedesktop.org \
    --cc=vkuznets@redhat.com \
    --cc=vmalik@redhat.com \
    --cc=will@kernel.org \
    --cc=yonghong.song@linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.