Linux SNPS ARC Archive mirror
 help / color / mirror / Atom feed
From: Shahab Vahedi <list+bpf@vahedi.org>
To: "Björn Töpel" <bjorn@kernel.org>
Cc: Shahab Vahedi <list+bpf@vahedi.org>,
	Shahab Vahedi <shahab@synopsys.com>,
	Vineet Gupta <vgupta@kernel.org>,
	linux-snps-arc@lists.infradead.org
Subject: [PATCH 7/7] v2: Check "bpf_jit_binary_lock_ro()" return value
Date: Tue, 30 Apr 2024 17:09:37 +0200	[thread overview]
Message-ID: <20240430150937.39793-8-list+bpf@vahedi.org> (raw)
In-Reply-To: <20240430150937.39793-1-list+bpf@vahedi.org>

From: Shahab Vahedi <shahab@synopsys.com>

...after the rebase.
---
 arch/arc/net/bpf_jit_core.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/arch/arc/net/bpf_jit_core.c b/arch/arc/net/bpf_jit_core.c
index 00c99b339b4a..6f6b4ffccf2c 100644
--- a/arch/arc/net/bpf_jit_core.c
+++ b/arch/arc/net/bpf_jit_core.c
@@ -1218,15 +1218,10 @@ static int jit_compile(struct jit_context *ctx)
  *
  * prog->jited=1, prog->jited_len=..., prog->bpf_func=...
  */
-static void jit_finalize(struct jit_context *ctx)
+static int jit_finalize(struct jit_context *ctx)
 {
 	struct bpf_prog *prog = ctx->prog;
 
-	ctx->success = true;
-	prog->bpf_func = (void *)ctx->jit.buf;
-	prog->jited_len = ctx->jit.len;
-	prog->jited = 1;
-
 	/* We're going to need this information for the "do_extra_pass()". */
 	if (ctx->need_extra_pass) {
 		ctx->jit_data->bpf_header = ctx->bpf_header;
@@ -1237,7 +1232,10 @@ static void jit_finalize(struct jit_context *ctx)
 		 * If things seem finalised, then mark the JITed memory
 		 * as R-X and flush it.
 		 */
-		bpf_jit_binary_lock_ro(ctx->bpf_header);
+		if (bpf_jit_binary_lock_ro(ctx->bpf_header)) {
+			pr_err("bpf-jit: Could not lock the JIT memory.\n");
+			return -EFAULT;
+		}
 		flush_icache_range((unsigned long)ctx->bpf_header,
 				   (unsigned long)
 				   BUF(ctx->jit.buf, ctx->jit.len));
@@ -1245,8 +1243,15 @@ static void jit_finalize(struct jit_context *ctx)
 		bpf_prog_fill_jited_linfo(prog, ctx->bpf2insn);
 	}
 
+	ctx->success = true;
+	prog->bpf_func = (void *)ctx->jit.buf;
+	prog->jited_len = ctx->jit.len;
+	prog->jited = 1;
+
 	jit_ctx_cleanup(ctx);
 	jit_dump(ctx);
+
+	return 0;
 }
 
 /*
@@ -1354,7 +1359,10 @@ static struct bpf_prog *do_normal_pass(struct bpf_prog *prog)
 		return prog;
 	}
 
-	jit_finalize(&ctx);
+	if (jit_finalize(&ctx)) {
+		jit_ctx_cleanup(&ctx);
+		return prog;
+	}
 
 	return ctx.prog;
 }
@@ -1389,7 +1397,10 @@ static struct bpf_prog *do_extra_pass(struct bpf_prog *prog)
 		return prog;
 	}
 
-	jit_finalize(&ctx);
+	if (jit_finalize(&ctx)) {
+		jit_ctx_cleanup(&ctx);
+		return prog;
+	}
 
 	return ctx.prog;
 }
-- 
2.35.8


_______________________________________________
linux-snps-arc mailing list
linux-snps-arc@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-snps-arc

      parent reply	other threads:[~2024-04-30 15:10 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-30 15:09 [off-list] [PATCH 0/7 bpf-next v2] ARC: Add eBPF JIT support Shahab Vahedi
2024-04-30 15:09 ` [PATCH 1/7] v2: Turn "emit" from global into a context var Shahab Vahedi
2024-04-30 15:09 ` [PATCH 2/7] v2: Turn "zext_thyself" " Shahab Vahedi
2024-04-30 15:09 ` [PATCH 3/7] v2: Use memset() in jit_ctx_init() Shahab Vahedi
2024-04-30 15:09 ` [PATCH 4/7] v2: MAINTAINERS: Add "BPF JIT for ARC" entry Shahab Vahedi
2024-04-30 15:09 ` [PATCH 5/7] v2: Fix typos Shahab Vahedi
2024-04-30 15:09 ` [PATCH 6/7] v2: Fix most of the "Checks" from "checkpatch.pl" Shahab Vahedi
2024-04-30 15:09 ` Shahab Vahedi [this message]

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=20240430150937.39793-8-list+bpf@vahedi.org \
    --to=list+bpf@vahedi.org \
    --cc=bjorn@kernel.org \
    --cc=linux-snps-arc@lists.infradead.org \
    --cc=shahab@synopsys.com \
    --cc=vgupta@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).