Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp1505632rdb; Mon, 19 Feb 2024 19:51:58 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUtmp6a/sflBpi2LD9VPnFafpD3hO7J2SslzQifUouSS+HCUDQBF9p3n15VUbTyjQaS+jYSk6YabR+IcLLBd+bdiNr2Wp4lERiYtQR6rg== X-Google-Smtp-Source: AGHT+IHW1iCJP0gS3d0jCiil1re0QZvkBSi1uZUCYGTPUoS9YBHpO8wp0wx3afozkzcbdLIWokZx X-Received: by 2002:a17:903:41c2:b0:1db:dd24:9940 with SMTP id u2-20020a17090341c200b001dbdd249940mr9654069ple.40.1708401117840; Mon, 19 Feb 2024 19:51:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708401117; cv=pass; d=google.com; s=arc-20160816; b=URHb60RYKVPHm9peP4JlGSn86xWv4dfZaT+VN9rroE8o3ATpN2YbyUsa7GQ8NwQ7Ew jvEw+9xc0eU2LtuOPetCnebPc1/kiSvbsBvtiAYVyp2UrzpMnWP5ko5tXHy588VqBxmV jrXXi5xarkHMs+PHj5RDMIkUIWzAJNLW0wFT6KLhw4TzCPsO5hPOPJoNEchb7J4uLGAk KPj1x2mvBCeaJVwYwEt8acHZ9ubTLSAvTLyyGz6yGt7OM0Piwuypqieg2puEh9MxatLO kyTs2aYN/hxGwFQobb/wIYY3YsMnlB81Q1kQed0HqSifzBi5KZifi7gidJ9SxIV/gTtS Cmtg== 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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72292-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 4-20020a170902c14400b001db5d0901e0si5479690plj.98.2024.02.19.19.51.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 19:51:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-72292-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::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-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-72292-linux.lists.archive=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8543E2823E4 for ; Tue, 20 Feb 2024 03:51:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15AF757337; Tue, 20 Feb 2024 03:51:27 +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 Content-Transfer-Encoding: 8bit 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; -- 2.39.2