From nobody Mon Apr 6 10:43:23 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA2B519CD19 for ; Sun, 22 Mar 2026 01:46:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774143963; cv=none; b=UHFp7Kn1Vvz+NRKn1iwBmjB2ZLtWmABbYWBKcR59BPZ9IICvzLVzUikAOhQfuDFmqQ2ZNRgSRH/vFR/+dFFpMpDWZps9SkOnfQVZcyVHMxuwC9Y3ssL9JtPLcn0MjcObtYNjc554LRgq6D2+1EKaHxm0GsUxdpUFj8NWIO2D0TE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774143963; c=relaxed/simple; bh=pmAjCVodGJSLBePhsyOw8FKCOcP1pDL6atUspo9KOyw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PoP4f9NLTHi1c5KhRlG04VXQaQJeu9wBXJOmgmGDuqVDPL96WTTx7p5KFq6rw0jqyjzrOPtKY+nsAPYiH8FoHfn0qxRnQ7gL05iRjXZPagE4tu4Tm7V0mFSEuL8VCz1/4ivNm9dxs6dRhHYjQOOJFl8iPNcGy5If32RJ8kOlJO8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=D5ErhEj5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="D5ErhEj5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774143960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q0yOeqibN7XflIQPgK3OVma/nUGOvOfi7m24NVY99u0=; b=D5ErhEj5n4q5KtkrYSE+K7R0noIyuzYKTHsrzzft3yjtn0kDHblXvkefznutDLYu0vAzKU LGaBG8A9vTnisBy7gFd3coWXJYQMeVpLcyzAe0lHv1G9kE7BuL5QLOh2Lf9NSTjFYtxljI TqHjolD0ES/wuxu56reU7/0pJh5BH6Q= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-683-m1NarEj3M--uXAdcyh1NsA-1; Sat, 21 Mar 2026 21:45:57 -0400 X-MC-Unique: m1NarEj3M--uXAdcyh1NsA-1 X-Mimecast-MFC-AGG-ID: m1NarEj3M--uXAdcyh1NsA_1774143954 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8A84F180047F; Sun, 22 Mar 2026 01:45:54 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.22]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2A6B6300019F; Sun, 22 Mar 2026 01:45:42 +0000 (UTC) From: Pingfan Liu To: kexec@lists.infradead.org Cc: Pingfan Liu , "David S. Miller" , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , Jeremy Linton , Catalin Marinas , Will Deacon , Ard Biesheuvel , Simon Horman , Gerd Hoffmann , Vitaly Kuznetsov , Philipp Rudo , Viktor Malik , Jan Hendrik Farr , Baoquan He , Dave Young , Andrew Morton , bpf@vger.kernel.org, systemd-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCHv7 06/13] kexec_file: Chain the stages into a pipeline Date: Sun, 22 Mar 2026 09:43:55 +0800 Message-ID: <20260322014402.8815-7-piliu@redhat.com> In-Reply-To: <20260322014402.8815-1-piliu@redhat.com> References: <20260322014402.8815-1-piliu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Images may consist of multiple layers, each with a distinct format. For example, an AArch64 UKI image typically embeds a zboot image in the .linux section. The parser therefore determines whether its output should be forwarded to the next stage. Intermediate results are stored in next_parsing_buf and then promoted to parsing_buf for the subsequent stage. Signed-off-by: Pingfan Liu Cc: Baoquan He Cc: Dave Young Cc: Andrew Morton Cc: Philipp Rudo To: kexec@lists.infradead.org --- kernel/kexec_bpf_loader.c | 47 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/kernel/kexec_bpf_loader.c b/kernel/kexec_bpf_loader.c index af16f7b685d9a..7f7884411e2c7 100644 --- a/kernel/kexec_bpf_loader.c +++ b/kernel/kexec_bpf_loader.c @@ -41,6 +41,8 @@ struct kexec_context { bool parsed; char *parsing_buf[MAX_PARSING_BUF_NUM]; unsigned long parsing_buf_sz[MAX_PARSING_BUF_NUM]; + char *next_parsing_buf[MAX_PARSING_BUF_NUM]; + unsigned long next_parsing_buf_sz[MAX_PARSING_BUF_NUM]; =20 char *kernel; unsigned long kernel_sz; @@ -278,8 +280,9 @@ static int kexec_buff_parser(struct bpf_parser_context = *parser) struct bpf_parser_buf *pbuf =3D parser->buf; struct kexec_context *ctx =3D (struct kexec_context *)parser->data; struct cmd_hdr *cmd =3D (struct cmd_hdr *)pbuf->buf; - char *decompressed_buf, *buf, *p; + char *decompressed_buf, *buf, *p, *pn; unsigned long decompressed_sz; + bool fill_pipeline =3D false; int ret =3D 0; =20 buf =3D pbuf->buf + sizeof(struct cmd_hdr); @@ -288,6 +291,7 @@ static int kexec_buff_parser(struct bpf_parser_context = *parser) cmd->payload_len, pbuf->size); return -EINVAL; } + fill_pipeline =3D cmd->pipeline_flag & KEXEC_BPF_PIPELINE_FILL; switch (cmd->cmd) { case KEXEC_BPF_CMD_DONE: ctx->parsed =3D true; @@ -301,6 +305,23 @@ static int kexec_buff_parser(struct bpf_parser_context= *parser) vfree(ctx->kernel); ctx->kernel =3D decompressed_buf; ctx->kernel_sz =3D decompressed_sz; + if (fill_pipeline) { + int i; + + for (i =3D 0; i < MAX_PARSING_BUF_NUM; i++) { + if (ctx->next_parsing_buf[i]) + continue; + ctx->next_parsing_buf[i] =3D decompressed_buf; + ctx->next_parsing_buf_sz[i] =3D decompressed_sz; + break; + } + /* No enough parsing slot */ + if (i =3D=3D MAX_PARSING_BUF_NUM) { + ctx->kernel =3D NULL; + vfree(decompressed_buf); + return -ENOMEM; + } + } break; default: vfree(decompressed_buf); @@ -313,6 +334,22 @@ static int kexec_buff_parser(struct bpf_parser_context= *parser) if (!p) return -ENOMEM; memcpy(p, buf, cmd->payload_len); + if (fill_pipeline) { + pn =3D __vmalloc(cmd->payload_len, GFP_KERNEL | __GFP_ACCOUNT); + if (!pn) { + vfree(p); + return -ENOMEM; + } + memcpy(pn, buf, cmd->payload_len); + for (int i =3D 0; i < MAX_PARSING_BUF_NUM; i++) { + if (!ctx->next_parsing_buf[i]) { + ctx->next_parsing_buf[i] =3D pn; + ctx->next_parsing_buf_sz[i] =3D cmd->payload_len; + break; + } + } + } + switch (cmd->subcmd) { case KEXEC_BPF_SUBCMD_KERNEL: vfree(ctx->kernel); @@ -637,6 +674,14 @@ static int process_bpf_parsers_container(const char *e= lf_buf, size_t elf_sz, context->parsing_buf[i] =3D NULL; context->parsing_buf_sz[i] =3D 0; } + for (int i =3D 0; i < MAX_PARSING_BUF_NUM; i++) { + if (!context->next_parsing_buf[i]) + break; + context->parsing_buf[i] =3D context->next_parsing_buf[i]; + context->parsing_buf_sz[i] =3D context->next_parsing_buf_sz[i]; + context->next_parsing_buf[i] =3D NULL; + context->next_parsing_buf_sz[i] =3D 0; + } =20 put_bpf_parser_context(bpf); /* If the bpf-prog success, it flags by KEXEC_BPF_CMD_DONE */ --=20 2.49.0