linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Karim Eshapa <karim.eshapa@gmail.com>
To: ast@kernel.org
Cc: daniel@iogearbox.net, davem@davemloft.net, ecree@solarflare.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Karim Eshapa <karim.eshapa@gmail.com>
Subject: [PATCH] Remove structure passing and assignment to save stack and no coping structures.
Date: Sat, 13 Jan 2018 21:26:48 +0200	[thread overview]
Message-ID: <1515871608-11351-1-git-send-email-karim.eshapa@gmail.com> (raw)

Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>

Thanks,
Karim
---
 include/linux/tnum.h  |  2 +-
 kernel/bpf/tnum.c     | 13 +++++++------
 kernel/bpf/verifier.c | 12 ++++++++----
 3 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/include/linux/tnum.h b/include/linux/tnum.h
index 0d2d3da..ddb1250 100644
--- a/include/linux/tnum.h
+++ b/include/linux/tnum.h
@@ -26,7 +26,7 @@ struct tnum tnum_lshift(struct tnum a, u8 shift);
 /* Shift a tnum right (by a fixed shift) */
 struct tnum tnum_rshift(struct tnum a, u8 shift);
 /* Add two tnums, return @a + @b */
-struct tnum tnum_add(struct tnum a, struct tnum b);
+void tnum_add(struct tnum *res, struct tnum *a, struct tnum *b);
 /* Subtract two tnums, return @a - @b */
 struct tnum tnum_sub(struct tnum a, struct tnum b);
 /* Bitwise-AND, return @a & @b */
diff --git a/kernel/bpf/tnum.c b/kernel/bpf/tnum.c
index 1f4bf68..f7f8b10 100644
--- a/kernel/bpf/tnum.c
+++ b/kernel/bpf/tnum.c
@@ -43,16 +43,17 @@ struct tnum tnum_rshift(struct tnum a, u8 shift)
 	return TNUM(a.value >> shift, a.mask >> shift);
 }
 
-struct tnum tnum_add(struct tnum a, struct tnum b)
+void tnum_add(struct tnum *res, struct tnum *a, struct tnum *b)
 {
 	u64 sm, sv, sigma, chi, mu;
 
-	sm = a.mask + b.mask;
-	sv = a.value + b.value;
+	sm = a->mask + b->mask;
+	sv = a->value + b->value;
 	sigma = sm + sv;
 	chi = sigma ^ sv;
-	mu = chi | a.mask | b.mask;
-	return TNUM(sv & ~mu, mu);
+	mu = chi | a->mask | b->mask;
+	res->value = (sv & ~mu);
+	res->mask = mu;
 }
 
 struct tnum tnum_sub(struct tnum a, struct tnum b)
@@ -102,7 +103,7 @@ static struct tnum hma(struct tnum acc, u64 value, u64 mask)
 {
 	while (mask) {
 		if (mask & 1)
-			acc = tnum_add(acc, TNUM(0, value));
+			tnum_add(&acc, &acc, &TNUM(0, value));
 		mask >>= 1;
 		value <<= 1;
 	}
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index b414d6b..4acc16c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -999,7 +999,8 @@ static int check_pkt_ptr_alignment(struct bpf_verifier_env *env,
 	 */
 	ip_align = 2;
 
-	reg_off = tnum_add(reg->var_off, tnum_const(ip_align + reg->off + off));
+	tnum_add(&reg_off, &reg->var_off,
+		&tnum_const(ip_align + reg->off + off));
 	if (!tnum_is_aligned(reg_off, size)) {
 		char tn_buf[48];
 
@@ -1024,7 +1025,8 @@ static int check_generic_ptr_alignment(struct bpf_verifier_env *env,
 	if (!strict || size == 1)
 		return 0;
 
-	reg_off = tnum_add(reg->var_off, tnum_const(reg->off + off));
+	tnum_add(&reg_off, &reg->var_off,
+		&tnum_const(reg->off + off));
 	if (!tnum_is_aligned(reg_off, size)) {
 		char tn_buf[48];
 
@@ -1971,7 +1973,8 @@ static int adjust_ptr_min_max_vals(struct bpf_verifier_env *env,
 			dst_reg->umin_value = umin_ptr + umin_val;
 			dst_reg->umax_value = umax_ptr + umax_val;
 		}
-		dst_reg->var_off = tnum_add(ptr_reg->var_off, off_reg->var_off);
+		tnum_add(&dst_reg->var_off, &ptr_reg->var_off,
+			&off_reg->var_off);
 		dst_reg->off = ptr_reg->off;
 		if (reg_is_pkt_pointer(ptr_reg)) {
 			dst_reg->id = ++env->id_gen;
@@ -2108,7 +2111,8 @@ static int adjust_scalar_min_max_vals(struct bpf_verifier_env *env,
 			dst_reg->umin_value += umin_val;
 			dst_reg->umax_value += umax_val;
 		}
-		dst_reg->var_off = tnum_add(dst_reg->var_off, src_reg.var_off);
+		tnum_add(&dst_reg->var_off, &dst_reg->var_off,
+			&src_reg.var_off);
 		break;
 	case BPF_SUB:
 		if (signed_sub_overflows(dst_reg->smin_value, smax_val) ||
-- 
2.7.4

             reply	other threads:[~2018-01-13 19:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-13 19:26 Karim Eshapa [this message]
2018-01-16  6:57 ` [PATCH] Remove structure passing and assignment to save stack and no coping structures kbuild test robot
  -- strict thread matches above, loose matches on Subject: below --
2018-01-13 18:48 Karim Eshapa

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=1515871608-11351-1-git-send-email-karim.eshapa@gmail.com \
    --to=karim.eshapa@gmail.com \
    --cc=ast@kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.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 NNTP newsgroup(s).