From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3B7D0CCF9E0 for ; Tue, 28 Oct 2025 17:07:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 95E0580187; Tue, 28 Oct 2025 13:07:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C06B8013F; Tue, 28 Oct 2025 13:07:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 787F480187; Tue, 28 Oct 2025 13:07:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5DAE78013F for ; Tue, 28 Oct 2025 13:07:18 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2BBD1160530 for ; Tue, 28 Oct 2025 17:07:18 +0000 (UTC) X-FDA: 84048153756.03.5F30DB0 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) by imf09.hostedemail.com (Postfix) with ESMTP id 7C11014000B for ; Tue, 28 Oct 2025 17:07:16 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iGxR66ac; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1761671236; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=mSDMZEnhQraFtTVM8HTNniThlkRiXJWMYrj8+oAXJIw=; b=bVX/QRtquyxucBOeVjWQbIn6e24iB71yZGPFm7ZSvub6Xt4Rw+U0qEjaDh4KkZ45Mhg4gK LLZZfcZom7cDwo0d3OOw//PGw4sohQZZFp9gwq6kh7RzTB7wAga1XN6G2sZIaQNRqz8NW9 6SClgy8rb6ExSbGoDPf4wbsdxR++VVI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1761671236; a=rsa-sha256; cv=none; b=RzSSVs2HKR5ZBsPtC8E7Sw5kWX8YPFdsOW63f+6ADfeuUl4KoMZDTc3f7QkRWt8HUB1GUY hhR0vW9bVf8raiyIHh824h2YvRnce/OHjFBoKDwOGrOmGq5RAUjqJ3LhIPOr072kOvkH+y JdzQS/VTJZT6CXtwoBn7Zcv99siWWns= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=iGxR66ac; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf09.hostedemail.com: domain of roman.gushchin@linux.dev designates 91.218.175.183 as permitted sender) smtp.mailfrom=roman.gushchin@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1761671234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mSDMZEnhQraFtTVM8HTNniThlkRiXJWMYrj8+oAXJIw=; b=iGxR66acQyngyL2qi4BOBXGsUCyP+daS9iWon0hZ5r54kQTcFpt1nd7l8KG7fvUyvbTnrF 6CAST3vIF1ZJw/DoUvX3lIWScgV8oH3hAUfGma8ixVXV42n02K8zOB71ozkNkyG51Z8DOE XN6ucICOhHoRAiQoqsOffgPkp3aWf/M= From: Roman Gushchin To: bot+bpf-ci@kernel.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, ast@kernel.org, surenb@google.com, mhocko@kernel.org, shakeel.butt@linux.dev, hannes@cmpxchg.org, andrii@kernel.org, inwardvessel@gmail.com, linux-mm@kvack.org, cgroups@vger.kernel.org, bpf@vger.kernel.org, martin.lau@kernel.org, song@kernel.org, memxor@gmail.com, tj@kernel.org, daniel@iogearbox.net, eddyz87@gmail.com, yonghong.song@linux.dev, clm@meta.com, ihor.solodrai@linux.dev Subject: Re: [PATCH v2 16/23] libbpf: introduce bpf_map__attach_struct_ops_opts() In-Reply-To: <5e97ecea6574f100385cb21507076c6efb2667eb9def24f322306be038e98165@mail.kernel.org> (bot's message of "Mon, 27 Oct 2025 23:48:10 +0000 (UTC)") References: <20251027232206.473085-6-roman.gushchin@linux.dev> <5e97ecea6574f100385cb21507076c6efb2667eb9def24f322306be038e98165@mail.kernel.org> Date: Tue, 28 Oct 2025 10:07:04 -0700 Message-ID: <87o6pruf9j.fsf@linux.dev> MIME-Version: 1.0 Content-Type: text/plain X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Queue-Id: 7C11014000B X-Rspamd-Server: rspam02 X-Stat-Signature: xzhf1zizayaw8oy9fu4e4qiz67rjfc8o X-HE-Tag: 1761671236-594389 X-HE-Meta: U2FsdGVkX1/gozvujzopeds5nWAeK5wYV01PHpVWvsnE+x5XM2pEFIYtzPSgUaBKaDGCMzuKA8aRxal9m41eY1EfxvbPUM24cchEsZpWxG+KiHY+uU4PxHqcixGKKshireLfvP9HW7MtaB7ykYElShiiIv9ErMnYCIci7//zU8Q/e6Jk2TkuFWgCXxdwKlezm3tN+SZUSBpQp4flMgfs1E4ZHTnEeN/kSj+Lv04g2ermAQ1SiDNBT8MYi4GksqBMQCK9fJciAmzHR4CJacigxxhj90VliMvDHcAtcnWW2tHJLH+t+WLrggI2MG/hbJmtJa6W9o2EqQsMIISuBvwmMNqO1XFkiqEwzw7jfbNqeUCx053vnfGhQE4495bXYHCpSmTCuBhM7ET4gKi+mKbBvQuw5UvM6FTCoUT/p/cZ6OJwYApI2Gz8Fwuii8HjPnxdnqHukzt2siG3O+ArmV0cEtUnxqWksV6g4Nm57TP7X+1PjzZDlZ0QNJMq82mwBTIBgXUu4NThLNtSa0VhvQj5SmEiD0qYtY+NzpXLlK2hhHBJ+7c6oEKmaAIsol7refjeL6dXOgQOiCPyI9TZrG+qbJRTZEX66UEryoKtC2f+4WZ2pOh03QTO3BZ9Kp3sXnrxRyAMbxLSOjq3t/F9JISIyBNROvJQWCZ/7kqq7FIHytihfVDxCOekaOMOeMvU9jiG1iX0r6SU5DREpvqQc1VJTGkwwHiCL69U3RFnps97qC96p8JlHiWCDDqmJO0ucPg2o/Yd0S8ApIeOwH8eiicSRJBqFkVlcFt5z2DiHERjKt2XxYx/bbDvOixIRF5SLjFlB/cmZZA599KNIAVXpAIJAYsguI4h9gTlDmAivWc8OjUzV0XStV7T4BXCOl002fqHkO6tTEfwawjk3VtXoT56aiBOFy0DfEXR/KfEGcPYnlcL3oVQYSxpgTXqIbNLDNfTDVCVGN6TwfKUfL/79fC 43Odnlpc r5ripoyb9UNoRHBrVmZlKmhV2jQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: bot+bpf-ci@kernel.org writes: > ``` > commit b58d54ed56054e3a550e02c324982feb20a2671e > Author: Roman Gushchin > > libbpf: introduce bpf_map__attach_struct_ops_opts() > > This commit introduces a new API function that extends the existing > bpf_map__attach_struct_ops() to accept additional options, specifically > allowing attachment of struct_ops maps to cgroups via a relative_fd. > >> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c >> index b90574f39..be56a5dee 100644 >> --- a/tools/lib/bpf/libbpf.c >> +++ b/tools/lib/bpf/libbpf.c >> @@ -13196,12 +13196,19 @@ static int bpf_link__detach_struct_ops(struct bpf_link *link) >> return close(link->fd); >> } >> >> -struct bpf_link *bpf_map__attach_struct_ops(const struct bpf_map *map) >> +struct bpf_link *bpf_map__attach_struct_ops_opts(const struct bpf_map *map, >> + const struct bpf_struct_ops_opts *opts) >> { >> + DECLARE_LIBBPF_OPTS(bpf_link_create_opts, link_opts); >> struct bpf_link_struct_ops *link; >> __u32 zero = 0; >> int err, fd; >> >> + if (!OPTS_VALID(opts, bpf_struct_ops_opts)) { >> + pr_warn("map '%s': invalid opts\n", map->name); >> + return libbpf_err_ptr(-EINVAL); >> + } >> + >> if (!bpf_map__is_struct_ops(map)) { >> pr_warn("map '%s': can't attach non-struct_ops map\n", map->name); >> return libbpf_err_ptr(-EINVAL); > > [ ... ] > >> link = calloc(1, sizeof(*link)); >> if (!link) >> return libbpf_err_ptr(-EINVAL); > > Should this return -ENOMEM instead of -EINVAL? All other calloc failures > in libbpf.c return -ENOMEM (see lines 11006, 11802, 12288, 12746, 12829, > 12891, 13089, 13129 in the same file). This code was introduced by e9fc3ce99b34 ("libbpf: Streamline error reporting for high-level APIs"), so it's new. I agree that ENOMEM is correct, however it might be too late to fix. I'll let libbpf maintainers to decide. > > [ ... ] > >> - fd = bpf_link_create(map->fd, 0, BPF_STRUCT_OPS, NULL); >> + link_opts.cgroup.relative_fd = OPTS_GET(opts, relative_fd, 0); >> + >> + fd = bpf_link_create(map->fd, 0, BPF_STRUCT_OPS, &link_opts); > > Is the expected_revision field being propagated correctly? The new > bpf_struct_ops_opts structure includes an expected_revision field > (see libbpf.h), and bpf_link_create() with BPF_STRUCT_OPS reads > opts->cgroup.expected_revision (see bpf.c line 889), but this code only > sets relative_fd in link_opts. Should it also include: > > link_opts.cgroup.expected_revision = OPTS_GET(opts, > expected_revision, 0); Correct, fixed. Thanks!