From: Gyutae Bae <[email protected]>

Introduce the UAPI surface for a compare-and-delete primitive: a new map
flag BPF_F_COMPARE plus compare/compare_offset/compare_size fields let
a delete request name an expected value region.  Behaviour is wired up in
the following patch; this adds the flag and fields (kernel + tools/ copy)
only.

Co-developed-by: Minsu Jeon <[email protected]>
Signed-off-by: Minsu Jeon <[email protected]>
Co-developed-by: Siwan Kim <[email protected]>
Signed-off-by: Siwan Kim <[email protected]>
Co-developed-by: Jonghyeon Kim <[email protected]>
Signed-off-by: Jonghyeon Kim <[email protected]>
Signed-off-by: Gyutae Bae <[email protected]>
---
 include/uapi/linux/bpf.h       | 6 +++++-
 tools/include/uapi/linux/bpf.h | 6 +++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 89b36de5fdbb..4705b02fb6a4 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1397,7 +1397,7 @@ enum bpf_addr_space_cast {
        BPF_ADDR_SPACE_CAST = 1,
 };
 
-/* flags for BPF_MAP_UPDATE_ELEM command */
+/* flags for BPF_MAP_UPDATE_ELEM / BPF_MAP_DELETE_ELEM commands */
 enum {
        BPF_ANY         = 0, /* create new element or update existing */
        BPF_NOEXIST     = 1, /* create new element if it didn't exist */
@@ -1405,6 +1405,7 @@ enum {
        BPF_F_LOCK      = 4, /* spin_lock-ed map_lookup/map_update */
        BPF_F_CPU       = 8, /* cpu flag for percpu maps, upper 32-bit of flags 
is a cpu number */
        BPF_F_ALL_CPUS  = 16, /* update value across all CPUs for percpu maps */
+       BPF_F_COMPARE   = 32, /* compare-and-delete: delete elem only if value 
region == compare */
 };
 
 /* flags for BPF_MAP_CREATE command */
@@ -1586,6 +1587,9 @@ union bpf_attr {
                        __aligned_u64 next_key;
                };
                __u64           flags;
+               __aligned_u64   compare;        /* user ptr to expected bytes 
(BPF_F_COMPARE) */
+               __u32           compare_offset; /* start offset within value */
+               __u32           compare_size;   /* bytes to compare; 0 == whole 
value */
        };
 
        struct { /* struct used by BPF_MAP_*_BATCH commands */
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 89b36de5fdbb..4705b02fb6a4 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -1397,7 +1397,7 @@ enum bpf_addr_space_cast {
        BPF_ADDR_SPACE_CAST = 1,
 };
 
-/* flags for BPF_MAP_UPDATE_ELEM command */
+/* flags for BPF_MAP_UPDATE_ELEM / BPF_MAP_DELETE_ELEM commands */
 enum {
        BPF_ANY         = 0, /* create new element or update existing */
        BPF_NOEXIST     = 1, /* create new element if it didn't exist */
@@ -1405,6 +1405,7 @@ enum {
        BPF_F_LOCK      = 4, /* spin_lock-ed map_lookup/map_update */
        BPF_F_CPU       = 8, /* cpu flag for percpu maps, upper 32-bit of flags 
is a cpu number */
        BPF_F_ALL_CPUS  = 16, /* update value across all CPUs for percpu maps */
+       BPF_F_COMPARE   = 32, /* compare-and-delete: delete elem only if value 
region == compare */
 };
 
 /* flags for BPF_MAP_CREATE command */
@@ -1586,6 +1587,9 @@ union bpf_attr {
                        __aligned_u64 next_key;
                };
                __u64           flags;
+               __aligned_u64   compare;        /* user ptr to expected bytes 
(BPF_F_COMPARE) */
+               __u32           compare_offset; /* start offset within value */
+               __u32           compare_size;   /* bytes to compare; 0 == whole 
value */
        };
 
        struct { /* struct used by BPF_MAP_*_BATCH commands */
-- 
2.39.5 (Apple Git-154)


Reply via email to