From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from cvsmtppost01.nmdf.navercorp.com (cvsmtppost01.nmdf.navercorp.com [114.111.35.57]) (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 9CB0A3793A8 for ; Mon, 22 Jun 2026 07:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.111.35.57 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782114448; cv=none; b=MDo7NHWywhW57ETVCbym7CyFZYQ2fSW3fShxDdS7zk7MpSvvb57Y1wq8wIlFJ1aKC2cztPJl9xH9gCYLcl58KvKg6x1DWuz4xx30Q8vGrKZ+pboc79/GDW/w0f8WJytWEOFMIXDJ/ZDcLGgrOZGfcDlxVVJY544n1cmhirP0Wmk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782114448; c=relaxed/simple; bh=z/cFibn1bQGfsWd6sEKBUE+7Caj17UOCdL5MGEGC7kI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HU5Uh25oqdA69nIkMUMe8bHhLgatL7RESnUQC9a5tfP0o1dv/7dLwjpRO2kv5EW+05Pd97rwTC32BgQvJsEDXUn/b5clbHXRqTnTVGkPlRxm3xDNi3HNlP5pb73CMrQ6XG3YHfcGw61FVf9ax9jzgAKxH/7iD3CB4+Qf2ZVAxWE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=navercorp.com; spf=pass smtp.mailfrom=navercorp.com; dkim=pass (2048-bit key) header.d=navercorp.com header.i=@navercorp.com header.b=XzFNAfSD; arc=none smtp.client-ip=114.111.35.57 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=navercorp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=navercorp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=navercorp.com header.i=@navercorp.com header.b="XzFNAfSD" Received: from kr0m-real-1 ([10.111.46.243]) by cvsmtppost01.nmdf.navercorp.com with ESMTP id c3-9me2uTeq16SwxbXrh8g for ; Mon, 22 Jun 2026 07:17:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=navercorp.com; s=s20171120; t=1782112620; bh=z/cFibn1bQGfsWd6sEKBUE+7Caj17UOCdL5MGEGC7kI=; h=From:To:Subject:Date:Message-Id:From:Subject:Feedback-ID: X-Works-Security; b=XzFNAfSDINkgVOtcSzL5N1DM46z1VUWWquk/P7H/CarqT7yTrV8KvGZznQ80DDtCH h/hav4Y1lbW7BucmFWIufp3SOuw4MeeWgtHs+SowMFEJEoipdISJLyg4fR/dE5d3Q/ hBxNQwA6hHdVhRIN0NNZDLhS91PDoi3sNV34NpQrRbU1ejt3IX0PrLJKoxAniHTvIy +RvHPt9Wgo/d1Y1pYwthRDeVyPsA6/iZSg1b67B/V8rvqOkdHr9rVo+NtiWFBxIMlt BQzyAZgWkBoJU+po+dAAhmBhXTe8aFazGvzlPBQ3xnC6uEXpDl2Kh3MBsyRmJf1i9R nOWttK8Sg/SDw== X-Session-ID: DdIOxQejRgSKkF4yUeKqew X-Works-Send-Opt: T9YwjAumKAumKAbZjAgmKqKXKoJYFHmwFBwYjHmm X-Works-Smtp-Source: PZK/KAU/FqJZ+HmlKxUm+6E= Received: from localhost.localdomain ([10.25.121.184]) by cvnsmtp02.nmdf.navercorp.com with ESMTP id DdIOxQejRgSKkF4yUeKqew for (version=TLSv1.3 cipher=TLS_CHACHA20_POLY1305_SHA256); Mon, 22 Jun 2026 07:16:59 -0000 From: Gyutae Bae To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , bpf@vger.kernel.org Cc: John Fastabend , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Shuah Khan , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Minsu Jeon , Siwan Kim , Jonghyeon Kim , Gyutae Bae Subject: [RFC bpf-next 1/3] bpf: add BPF_F_COMPARE flag and compare fields to map elem UAPI Date: Mon, 22 Jun 2026 16:16:47 +0900 Message-Id: <20260622071649.31541-2-gyutae.opensource@navercorp.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20260622071649.31541-1-gyutae.opensource@navercorp.com> References: <20260622071649.31541-1-gyutae.opensource@navercorp.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Gyutae Bae 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 Signed-off-by: Minsu Jeon Co-developed-by: Siwan Kim Signed-off-by: Siwan Kim Co-developed-by: Jonghyeon Kim Signed-off-by: Jonghyeon Kim Signed-off-by: Gyutae Bae --- 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)