[RFC bpf-next v0 7/7] (WIP) Add helper functions that transform wrange32 to and from smin/smax/umin/umax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To check how wrange32 logic interacts with current verifier codebase, it
is necessary to try integrating it as soon as possible in order to take
advantange of the selftests we have. One way for this to be done is by
adding a helper function that takes smin/smax/umin/umax from
bpf_reg_state and turn them into wrange32, then do calculation in
wrange32_{add,sub,mul} instead of scalar32_min_max_{add,sub,mul}, and
turn the resulting wrange32 back into smin/smax/umin/umax with another
helper function.

wrange32_to_min_max() is easy and readily available, however I'm still
working on wrange32_from_min_max(), which is trickier.

Signed-off-by: Shung-Hsi Yu <shung-hsi.yu@xxxxxxxx>
---
 include/linux/wrange.h |  6 ++++++
 kernel/bpf/wrange.c    | 16 ++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/wrange.h b/include/linux/wrange.h
index 45d3db3f518b..cecdecefab53 100644
--- a/include/linux/wrange.h
+++ b/include/linux/wrange.h
@@ -11,6 +11,12 @@ struct wrange32 {
 	u32 end;
 };
 
+/* Create wrange32 from bpf_reg_state's s32_min/s32_max/u32_min/u32_max */
+struct wrange32 wrange32_from_min_max(s32 s32_min, s32 s32_max,
+		                      u32 u32_min, u32 u32_max);
+/* Turn wrange32 back into s32_min/s32_max/u32_min/u32_max */
+void wrange32_to_min_max(struct wrange32 w, s32 *s32_min, s32 *s32_max,
+			 u32 *u32_min, u32 *u32_max);
 struct wrange32 wrange32_add(struct wrange32 a, struct wrange32 b);
 struct wrange32 wrange32_sub(struct wrange32 a, struct wrange32 b);
 struct wrange32 wrange32_mul(struct wrange32 a, struct wrange32 b);
diff --git a/kernel/bpf/wrange.c b/kernel/bpf/wrange.c
index 4ca253e55743..c150efb42cd2 100644
--- a/kernel/bpf/wrange.c
+++ b/kernel/bpf/wrange.c
@@ -3,6 +3,22 @@
 
 #define WRANGE32(_s, _e) ((struct wrange32) {.start = _s, .end = _e})
 
+struct wrange32 wrange32_from_min_max(s32 s32_min, s32 s32_max,
+				      u32 u32_min, u32 u32_max)
+{
+	/* To be implemented */
+	return WRANGE32(U32_MIN, U32_MAX);
+}
+
+void wrange32_to_min_max(struct wrange32 w, s32 *s32_min, s32 *s32_max,
+			 u32 *u32_min, u32 *u32_max)
+{
+	*s32_min = wrange32_smin(w);
+	*s32_max = wrange32_smax(w);
+	*u32_min = wrange32_umin(w);
+	*u32_max = wrange32_umax(w);
+}
+
 struct wrange32 wrange32_add(struct wrange32 a, struct wrange32 b)
 {
 	u32 a_len = a.end - a.start;
-- 
2.42.0





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux