Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp3309884rwb; Sun, 30 Jul 2023 05:13:21 -0700 (PDT) X-Google-Smtp-Source: APBJJlGFsu1SYXYrnoWC3neFyuhNahldW+gOzUEQwXfpFyAI9ddZnJzHpdgQsLJ2Pz+QIhgh8Arv X-Received: by 2002:a17:902:6b88:b0:1b8:16c7:a786 with SMTP id p8-20020a1709026b8800b001b816c7a786mr6187731plk.4.1690719201351; Sun, 30 Jul 2023 05:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690719201; cv=none; d=google.com; s=arc-20160816; b=q7kDJ8v+zb7s8PMxfnpOKhKirMq27u1oP0NjOtV10m1RJf9LvuA7rBcJR2F8BbSDg8 KIl197PTYhwJ2BCLqWcvw2qEMwMZ2sMU5iuzRAXwbI5ZYLjz+Tj2ck+7pZixxddglt8N lhuLV4XkJzOuteNJZAVpTuQLvkc5kbfNwxcLPjYuHMIkQ6PqwrnOvysymtUZSQf7gnrh b7AUZX+ffTGwvxOS1NpnzXfkf/3bE5aRlB0RRT+bC/2xR8V2sIIe+APYf4B0MGDCBSMG /BbzrHr7J+GXD8N4V2mc/L1ySqUO9N99GDmPG/lSQ7aCoW0dmJnhJGsWGvDPp81NIBNJ MapA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZHtQADxWGfF7hnz/vUvRDC9nByJ/dzs4+97gI1+O1CE=; fh=dPpUGA0jyjzTGDXygTzwmpGFnPmihl7bgrKI6H4XaXo=; b=SgPXs4I9ULwSf18wD3DAFVAOcpsa9uDoPdL9GMIAwdb9UYN2qnLENBBmuDSMArc46H Plny83+klXg+zDmQW9rTuilNGcsUv0liKZIUDjMQJ8R7I63yBUTdESKfb9dhlRILmVHw cWJc4QQXoMRWzpI0luIZLmvhakd27i/VInwKrm6GF7Hsb15pr6BfeMhrEPZXcOb5aKof JY8VyrWpPp/LmlpFGGgx+OJ+9RBNH+1wCo0nTZEiodWNP/mTbxTS71mNE+t3OIlp983k hhhC8scEFn3Nd9F1OoOZ6XcIMOZQTQuZvlX73GCIXShJRsVUddbZu6Ahdr7yrZ0gdrpF +WAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gCzPYiH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h9-20020a17090a130900b00268137c2f12si3024379pja.2.2023.07.30.05.13.09; Sun, 30 Jul 2023 05:13:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gCzPYiH4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbjG3LuP (ORCPT + 99 others); Sun, 30 Jul 2023 07:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230027AbjG3LuO (ORCPT ); Sun, 30 Jul 2023 07:50:14 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD3C10C8; Sun, 30 Jul 2023 04:50:13 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-686ed1d2594so3530685b3a.2; Sun, 30 Jul 2023 04:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690717812; x=1691322612; 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=ZHtQADxWGfF7hnz/vUvRDC9nByJ/dzs4+97gI1+O1CE=; b=gCzPYiH4mX814sxszirQr4PUNl5yEgo+oIa4ETrHS7M6DNGAwjdBRu0aZ9ehkAWOXd /TS66FABEb9zf5+VQCtBFbMgOrPqZyCGZITlb+By7RCR+8kfhp0kcMyJigvSLZeUjF6+ eLgvmzOUBP+pKMZH9i7pW1rHn9at5+tqWGgoUlNnJaMRPe6LdIohjnIXqk6FwmhO7cEn thG21pJbwJCItYo4/0iZBi88I5nHhVs1psUyOQSWNToyBgcl4xhTnMnpMOVKu8GExS/U 4LWIBxXGUEwloZ53axUNNPrGtnIGNeSlnivMX7VJoOn78zhFH9U7ud99pPEUQ7HY+I2v XWtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690717812; x=1691322612; 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=ZHtQADxWGfF7hnz/vUvRDC9nByJ/dzs4+97gI1+O1CE=; b=Mu59LBa286gYkUZHKrNEM+BXRwJb1IGWKHUpo/uo/MtjcjsnX/eZRZJx/ORD8BX6Qq lupf6EL2O0QQfTw3P0ImYmqeOxLkbh1kIELvBlNWILRZDYP2ng2fm79WTF+4+kkq8Fva T4SqhfzLyMgWx2PPtxiB+gpCySy/EmlzfebKnlwuForhH5KRrGba5IDB8KjQPwqoaue7 gg/wGOOQhLg+WgJI9IZ+D38fbtckzk7C6/xLnv2ex0jt5EP5ZwOh4JFqEDNcaFmZ9Sg7 Z6jx1M0Nv1nW/PK0UVCjnZuh9jY7b7xetyLN2rvQrMdvUF12pxEbmIIZGmIw1vZ+3lKw 3Tdg== X-Gm-Message-State: ABy/qLarAmO2WbKHodASTBk8zglWU4a9jfRs9L2eTlz0PWDa9xJ017fN FOpNizn8/m3QLJk4lHXBZYw= X-Received: by 2002:a05:6a00:14c5:b0:67e:45ab:b86b with SMTP id w5-20020a056a0014c500b0067e45abb86bmr9272804pfu.28.1690717812507; Sun, 30 Jul 2023 04:50:12 -0700 (PDT) Received: from localhost.localdomain (bb219-74-209-211.singnet.com.sg. [219.74.209.211]) by smtp.gmail.com with ESMTPSA id z9-20020aa791c9000000b00640dbbd7830sm6044479pfa.18.2023.07.30.04.50.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Jul 2023 04:50:12 -0700 (PDT) From: Leon Hwang To: ast@kernel.org Cc: daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, jolsa@kernel.org, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, hawk@kernel.org, rostedt@goodmis.org, mhiramat@kernel.org, mykolal@fb.com, shuah@kernel.org, hffilwlqm@gmail.com, tangyeechou@gmail.com, kernel-patches-bot@fb.com, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v4 1/2] bpf, xdp: Add tracepoint to xdp attaching failure Date: Sun, 30 Jul 2023 19:49:50 +0800 Message-ID: <20230730114951.74067-2-hffilwlqm@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230730114951.74067-1-hffilwlqm@gmail.com> References: <20230730114951.74067-1-hffilwlqm@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HK_RANDOM_ENVFROM, HK_RANDOM_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When error happens in dev_xdp_attach(), it should have a way to tell users the error message like the netlink approach. To avoid breaking uapi, adding a tracepoint in bpf_xdp_link_attach() is an appropriate way to notify users the error message. Hence, bpf libraries are able to retrieve the error message by this tracepoint, and then report the error message to users. Signed-off-by: Leon Hwang --- include/trace/events/xdp.h | 17 +++++++++++++++++ net/core/dev.c | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/include/trace/events/xdp.h b/include/trace/events/xdp.h index c40fc97f94171..cd89f1d5ce7b8 100644 --- a/include/trace/events/xdp.h +++ b/include/trace/events/xdp.h @@ -404,6 +404,23 @@ TRACE_EVENT(mem_return_failed, ) ); +TRACE_EVENT(bpf_xdp_link_attach_failed, + + TP_PROTO(const char *msg), + + TP_ARGS(msg), + + TP_STRUCT__entry( + __string(msg, msg) + ), + + TP_fast_assign( + __assign_str(msg, msg); + ), + + TP_printk("errmsg=%s", __get_str(msg)) +); + #endif /* _TRACE_XDP_H */ #include diff --git a/net/core/dev.c b/net/core/dev.c index 8e7d0cb540cdb..49bed890f807e 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -133,6 +133,7 @@ #include #include #include +#include #include #include #include @@ -9472,6 +9473,7 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) struct bpf_link_primer link_primer; struct bpf_xdp_link *link; struct net_device *dev; + struct netlink_ext_ack extack; int err, fd; rtnl_lock(); @@ -9497,12 +9499,13 @@ int bpf_xdp_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) goto unlock; } - err = dev_xdp_attach_link(dev, NULL, link); + err = dev_xdp_attach_link(dev, &extack, link); rtnl_unlock(); if (err) { link->dev = NULL; bpf_link_cleanup(&link_primer); + trace_bpf_xdp_link_attach_failed(extack._msg); goto out_put_dev; } -- 2.41.0