From patchwork Tue Feb 20 03:51:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5qKm6b6Z6JGj?= X-Patchwork-Id: 203401 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp177408dyc; Mon, 19 Feb 2024 19:52:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVMnn4ewpX45mU5ZpTuOxXHycZvi21soX667VkNkyg9R7dxedCDdSrjafSAJrDIlQMI8b/XfmtijhqEfIw/GgWBsnzk5A== X-Google-Smtp-Source: AGHT+IFyVtFHbtYg0Kdt0J0yLPEYjONeCpfPg3rcp1dYfQMpOAllmYapBXHMZOzF8LeGkav/FyTM X-Received: by 2002:a81:b3c7:0:b0:607:9a30:3428 with SMTP id r190-20020a81b3c7000000b006079a303428mr11464236ywh.36.1708401124294; Mon, 19 Feb 2024 19:52:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708401124; cv=pass; d=google.com; s=arc-20160816; b=tSYL3iXpm4435QfPqs9Q3vQX4Lp6YYwF0qkwtPmk5Gd6Q0OaWTVSnSknFfCSFLYOhv ZMruhZsAREBXbxqHSQl04E0ry7XFoEqdQyISMxJOcEyAg3XeJYUxNzvuPHlSl69uImdR uU4pBdR7PoeK2n8cdFptyQDzb5pln4HCo6WAm75unQ4NvHic50ovGFU02VcIv+12fi+q KkknCzgPLXBAD4CtnCtZKduPQOAkiBM/0cp8bAWv+MxHsTfLF9dViBJdNP9M/+sPet54 +Pg7bncaNEFTGeFKp+O5thIWLaUuELvQ3X1ULOjtizOiG3lzFzCKaj94ixAWNvEML4M1 Memg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=uAc3ZPxMOkJPGWpWg+vGXamMVExiMG/0L8fGFtmgr8k=; fh=WiMyBfJwosJPExI0ItqnFyetn6yLDnvYzAuBS2mrOBk=; b=AGxLyWAIejFmzTYg50um0vzjq9KHNqnxGUL0h4RvUIQtceZ8UJFrQG4iVQygju+Z9V L1579WxFed8PwGrnIa7+vaiN/LAC4uIzVHMvMo4RfEZ6EVpMUmynGJc2ih5TrQSHTjmP /UDWMxW3wSqbbcXStfLrkiEkhSnRfHMkd0Iv5q9WGdbGw/iheTx3oxYeQ4LPuoUkHbia /9MzXpY2NjW/GdfXOCzuo7rD14Yyu5rnBn/MqHkNNAaypyn5ZGqK6JFKwGsRZ6twgvPH AQqLOvBCLAYJAf7IQ/VotC29cxCDsJSxxciKBEf5fw51srwiFC4uWzm+CrqUotzGDFGU dVGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ie7uavN8; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-72292-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72292-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d2-20020a37c402000000b007873af533f2si7534072qki.508.2024.02.19.19.52.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:52:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72292-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=ie7uavN8; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-72292-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72292-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id EBD9A1C21599 for ; Tue, 20 Feb 2024 03:52:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E8B9E51009; Tue, 20 Feb 2024 03:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="ie7uavN8" Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4CAD57318 for ; Tue, 20 Feb 2024 03:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401086; cv=none; b=DN+5iAPqMDVd9iGacxJLXaaiENa/aRlzFrnAtulXbRkZVNBgaIEzu7/l1ryWSYOJD7OYfbmUFMCyudjk9nhGqJKQEkGFEvivPLV0byyEVb9XmyBmwqhp0CLGa/aUjf9P2c9lAr7LcNRyw3BzhJ2POXRB8Mh0u9TbFeqe0vWGP/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708401086; c=relaxed/simple; bh=xa6vI2/sky4WmfzJ7YKtx++yDTvsili9mip7x/cutc4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y/bXJJFGL7EikfM0BiRxkBTvy+Hll/Z6nl5HaIBqG3Ge1tQ++75+e52dbiRN87AhNaRSTe6Lou/GzX7YJWiAQzSSYGeP5E7JxBRh4XzEJ8Bu7MyHw7WOoR0xXm/kxqgqDL0yPE0UKm6NuVTswU07SFbV0Tpla3W5PjFaGc8kRNU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=ie7uavN8; arc=none smtp.client-ip=209.85.214.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1d7354ba334so45491595ad.1 for ; Mon, 19 Feb 2024 19:51:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708401084; x=1709005884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uAc3ZPxMOkJPGWpWg+vGXamMVExiMG/0L8fGFtmgr8k=; b=ie7uavN8uSClt/TGncDB3TdnAw4Tvf0txv0yIiJdcQX+NgPVCwqTL/kmpM0V8tslCa 3YbV2X87SVV7njw4CNJDujdr4miqy1hvBOXajkNH0D+GQwuYsJ5SggFntej9nv+xyGFM 1CUSgRfg+JiAABgmaO8RV8GZ1KLuBlmHM/uTSHK+sj2AWb5xjuURqjzdW2qukDp2tBqg YD9m9/vprWf+oEnHrhRN1lAt0RA1cBTX3EKq7I6Vg44BtQlsn2D3AX3HMQJEuadhnNtd EhFd7gS17z5nob6bA2g1lBr4gAXTBQKQBzyzj961GpxarQCe8Q3g7E81ykCjstua4ugD 2bJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708401084; x=1709005884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uAc3ZPxMOkJPGWpWg+vGXamMVExiMG/0L8fGFtmgr8k=; b=s/M4WmAYuiEWdShFT+DrhE9Vd0+Gl5XYnKax4UOsuzFMgXHFCqU0mFUmG1d12AIawp 28KIx2+4xkSpWuSyjvATriJ3htOfNvy1Jw1ct2oIXPV+9PKRAXbqD8Fv9KZpqbmRpGRc DKVicNocZuWVLkBlbll/iYTxDMwZi2tNsxgy4KRbUono9JHomnvGP4wL1cwGckDY0Bl5 7hr4qVUcK/mtjSzIr1qOuHVe9q7YKN3DeKb4TRv5Ca18S9X4l1GB9Ddwv257tj3ZfsXr 8SCjTd/+H+BBnv8VK63jVFkayzEJUNpT7DOqEdGN2G16+W5wJ+tTF4JneEcJBxWv/6xy xMSw== X-Forwarded-Encrypted: i=1; AJvYcCU3e/VWZDpyhYDww0Prq6kJC4j0+fSjfeeEPyCLZkJHpnpCO2xTH/rNzFoeKhIzhByZmdVSQUDUCjvFJcf+Ev8f+DTkSBLTcs/rijt6 X-Gm-Message-State: AOJu0YxAbHR2R7vxJbAQVi0yaj1HGSSfgo8myDyKO6EFbHL4BdU5rbG5 MNY78kXu8qVgt0G2t2BiVD2aFyxldwX80bqbvP0hXg8swg8ModeOekNaBufDbIw= X-Received: by 2002:a17:902:e744:b0:1d9:c367:201b with SMTP id p4-20020a170902e74400b001d9c367201bmr18728920plf.29.1708401084154; Mon, 19 Feb 2024 19:51:24 -0800 (PST) Received: from localhost.localdomain ([43.129.25.208]) by smtp.gmail.com with ESMTPSA id jz7-20020a170903430700b001d94678a76csm5131723plb.117.2024.02.19.19.51.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:23 -0800 (PST) From: Menglong Dong To: andrii@kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, shuah@kernel.org, mcoquelin.stm32@gmail.com, alexandre.torgue@foss.st.com, thinker.li@gmail.com, dongmenglong.8@bytedance.com, zhoufeng.zf@bytedance.com, davemarchevsky@fb.com, dxu@dxuuu.xyz, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH bpf-next 3/5] libbpf: allow to set coookie when target_btf_id is set in bpf_link_create Date: Tue, 20 Feb 2024 11:51:03 +0800 Message-Id: <20240220035105.34626-4-dongmenglong.8@bytedance.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240220035105.34626-1-dongmenglong.8@bytedance.com> References: <20240220035105.34626-1-dongmenglong.8@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791388417358030725 X-GMAIL-MSGID: 1791388417358030725 As now we support to attach the tracing program to multiple target, we can set the bpf cookie even if the target btf id is offered in bpf_link_create(). Signed-off-by: Menglong Dong --- tools/lib/bpf/bpf.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 97ec005c3c47..0ca7c8375b40 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -737,23 +737,15 @@ int bpf_link_create(int prog_fd, int target_fd, target_btf_id = OPTS_GET(opts, target_btf_id, 0); /* validate we don't have unexpected combinations of non-zero fields */ - if (iter_info_len || target_btf_id) { - if (iter_info_len && target_btf_id) - return libbpf_err(-EINVAL); - if (!OPTS_ZEROED(opts, target_btf_id)) - return libbpf_err(-EINVAL); - } + if (iter_info_len && target_btf_id) + return libbpf_err(-EINVAL); memset(&attr, 0, attr_sz); attr.link_create.prog_fd = prog_fd; attr.link_create.target_fd = target_fd; attr.link_create.attach_type = attach_type; attr.link_create.flags = OPTS_GET(opts, flags, 0); - - if (target_btf_id) { - attr.link_create.target_btf_id = target_btf_id; - goto proceed; - } + attr.link_create.target_btf_id = target_btf_id; switch (attach_type) { case BPF_TRACE_ITER: @@ -834,11 +826,10 @@ int bpf_link_create(int prog_fd, int target_fd, return libbpf_err(-EINVAL); break; default: - if (!OPTS_ZEROED(opts, flags)) + if (!target_btf_id && !OPTS_ZEROED(opts, flags)) return libbpf_err(-EINVAL); break; } -proceed: fd = sys_bpf_fd(BPF_LINK_CREATE, &attr, attr_sz); if (fd >= 0) return fd;