From patchwork Fri Jan 5 22:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135769 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id D0DCB432AF; Fri, 5 Jan 2024 23:29:43 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1CF6D406A2; Fri, 5 Jan 2024 23:29:26 +0100 (CET) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by mails.dpdk.org (Postfix) with ESMTP id 060CE4064A for ; Fri, 5 Jan 2024 23:29:23 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d4df66529bso196665ad.1 for ; Fri, 05 Jan 2024 14:29:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1704493762; x=1705098562; darn=dpdk.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=EMC2hvIAOiy3/mrk7PXiBIowfoclk5LfwLADKkfaubM=; b=xSdXrcqySL70MbbWtL02lQM8UGn37w1kLasTpR15Z34bFma3EbjBZMn015m/CoUU+y qBUXzE6C8HUWWXIyRvxq/wjWRTni+TjOEieVuaCqnjG1ryl6FzMuY4CPfR5wZ4p8ONkM fJKFk2cTUWGPaiekn9uqs1fX7RD9pb80oT9Q2PyxNkws3tI/iZWwYyp+RvmVURO91j7C GP9gcU3Q5q5dbpq1jbeRe5gDJSKWBcOJ3EOh6ei59GgBrB85uECY+yQhThkpwHfVkbRl JVtIMS/AvxrMF0C2A5WREpmHtktZLpmdliOZvOqO7GSn8w3Ixqx4PGOkvyQJHe2dGMzQ U7CA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493762; x=1705098562; 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=EMC2hvIAOiy3/mrk7PXiBIowfoclk5LfwLADKkfaubM=; b=NzXmHlSYB3ptFuikazhN3PnJ8XkA1ldR3F3RxFOcTiGInK2puGyFkr1h4VhrVPgK2X tTV77GxTlyvW720zHuXXYs+fU9aVJG9M7LBPFLWlJlLucP3KDRBuejkdtOPMzEj7Pcfz 44xrtcF9UDa52wXS4OmHGYRY8MCtGmrbjNEeCSyVpIREnxQQZl4Yf0hoDQ1dWuQo/EIp iQSSiN7+s3hvSTbO1otO9aOHhbeOdfdiDTMwJZZBIhBJK9crdrFIRAo7LbGx+yHLPi/2 HCZt3wJj2i0N/zZ9uVjl39n9zDLIpOhL1FLbPMxQfer8WECAJvNsieWm+NtF/HBSFl8B W7xg== X-Gm-Message-State: AOJu0YxDsKGhEQB6tw5nzBlGiHv0Hek6VRL+0O8q1z6ZmraHSerTZ3Mh KnMXYxVHp0eBfgDv7AZ5fLyECQcd7yFM7ds1pjuDrV+8OjM= X-Google-Smtp-Source: AGHT+IG7lUd8g9WYRqyFP6YPA5kUq/bBj7FoSj3acBGyOAD9LKBPyAou5zhcpWKDID6kEgOz0CEmvA== X-Received: by 2002:a17:903:40d0:b0:1d3:ef79:4a2e with SMTP id t16-20020a17090340d000b001d3ef794a2emr128219pld.87.1704493762276; Fri, 05 Jan 2024 14:29:22 -0800 (PST) Received: from hermes.local (204-195-123-141.wavecable.com. [204.195.123.141]) by smtp.gmail.com with ESMTPSA id b11-20020a170902d50b00b001d3e2578e66sm1871132plg.243.2024.01.05.14.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:29:21 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 4/5] tap: get errors from kernel on bpf load failure Date: Fri, 5 Jan 2024 14:28:10 -0800 Message-ID: <20240105222909.139674-5-stephen@networkplumber.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240105222909.139674-1-stephen@networkplumber.org> References: <20240105222909.139674-1-stephen@networkplumber.org> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The bpf load kernel API can provide some useful diagnostics on failure. Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_bpf_api.c | 44 +++++++++++++++++++++++++++-------- drivers/net/tap/tap_flow.c | 16 ++++++++----- drivers/net/tap/tap_flow.h | 4 ++-- 3 files changed, 46 insertions(+), 18 deletions(-) diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index c754c167a764..29223b7f0ea7 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -15,8 +15,10 @@ #include #include -static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns, - size_t insns_cnt, const char *license); +static int bpf_load(enum bpf_prog_type type, + const struct bpf_insn *insns, size_t insns_cnt, + char *log_buf, size_t log_size, + const char *license); /** * Load BPF program (section cls_q) into the kernel and return a bpf fd @@ -24,15 +26,22 @@ static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns, * @param queue_idx * Queue index matching packet cb * + * @param log_buf + * Buffer to place resulting error message (optional) + * + * @param log_size + * Size of log_buf + * * @return * -1 if the BPF program couldn't be loaded. An fd (int) otherwise. */ -int tap_flow_bpf_cls_q(__u32 queue_idx) +int tap_flow_bpf_cls_q(__u32 queue_idx, char *log_buf, size_t log_size) { cls_q_insns[1].imm = queue_idx; return bpf_load(BPF_PROG_TYPE_SCHED_CLS, cls_q_insns, RTE_DIM(cls_q_insns), + log_buf, log_size, "Dual BSD/GPL"); } @@ -45,16 +54,23 @@ int tap_flow_bpf_cls_q(__u32 queue_idx) * @param[in] map_fd * BPF RSS map file descriptor * + * @param log_buf + * Buffer to place resulting error message (optional) + * + * @param log_size + * Size of log_buf + * * @return * -1 if the BPF program couldn't be loaded. An fd (int) otherwise. */ -int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd) +int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd, char *log_buf, size_t log_size) { l3_l4_hash_insns[4].imm = key_idx; l3_l4_hash_insns[9].imm = map_fd; return bpf_load(BPF_PROG_TYPE_SCHED_ACT, l3_l4_hash_insns, RTE_DIM(l3_l4_hash_insns), + log_buf, log_size, "Dual BSD/GPL"); } @@ -105,6 +121,12 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, * @param[in] insns_cnt * Number of BPF instructions (size of array) * + * @param[out] log_buf + * Space for log message + * + * @param[in] log_size + * Number of characters available in log_buf + * * @param[in] license * License string that must be acknowledged by the kernel * @@ -112,9 +134,8 @@ static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, * -1 if the BPF program couldn't be loaded, fd (file descriptor) otherwise */ static int bpf_load(enum bpf_prog_type type, - const struct bpf_insn *insns, - size_t insns_cnt, - const char *license) + const struct bpf_insn *insns, size_t insns_cnt, + char *log_buf, size_t log_size, const char *license) { union bpf_attr attr = {}; @@ -122,9 +143,12 @@ static int bpf_load(enum bpf_prog_type type, attr.insn_cnt = (__u32)insns_cnt; attr.insns = ptr_to_u64(insns); attr.license = ptr_to_u64(license); - attr.log_buf = ptr_to_u64(NULL); - attr.log_level = 0; - attr.kern_version = 0; + + if (log_size > 0) { + attr.log_level = 2; + attr.log_buf = ptr_to_u64(log_buf); + attr.log_size = log_size; + } return sys_bpf(BPF_PROG_LOAD, &attr, sizeof(attr)); } diff --git a/drivers/net/tap/tap_flow.c b/drivers/net/tap/tap_flow.c index ed4d42f92f9f..897d71acbad1 100644 --- a/drivers/net/tap/tap_flow.c +++ b/drivers/net/tap/tap_flow.c @@ -18,6 +18,8 @@ #include #include +#define BPF_LOG_BUFSIZ 1024 + #ifndef HAVE_TC_FLOWER /* * For kernels < 4.2, this enum is not defined. Runtime checks will be made to @@ -1885,11 +1887,13 @@ static int rss_enable(struct pmd_internals *pmd, * the correct queue. */ for (i = 0; i < pmd->dev->data->nb_rx_queues; i++) { - pmd->bpf_fd[i] = tap_flow_bpf_cls_q(i); + char log_buf[BPF_LOG_BUFSIZ]; + + pmd->bpf_fd[i] = tap_flow_bpf_cls_q(i, log_buf, sizeof(log_buf)); if (pmd->bpf_fd[i] < 0) { TAP_LOG(ERR, - "Failed to load BPF section %s for queue %d", - SEC_NAME_CLS_Q, i); + "Failed to load BPF section %s for queue %u: %s", + SEC_NAME_CLS_Q, i, log_buf); rte_flow_error_set( error, ENOTSUP, RTE_FLOW_ERROR_TYPE_HANDLE, NULL, @@ -2074,6 +2078,7 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, /* 4096 is the maximum number of instructions for a BPF program */ unsigned int i; int err; + char log_buf[BPF_LOG_BUFSIZ]; struct rss_key rss_entry = { .hash_fields = 0, .key_size = 0 }; @@ -2124,9 +2129,8 @@ static int rss_add_actions(struct rte_flow *flow, struct pmd_internals *pmd, /* * Load bpf rules to calculate hash for this key_idx */ - - flow->bpf_fd[SEC_L3_L4] = - tap_flow_bpf_calc_l3_l4_hash(flow->key_idx, pmd->map_fd); + flow->bpf_fd[SEC_L3_L4] = tap_flow_bpf_calc_l3_l4_hash(flow->key_idx, pmd->map_fd, + log_buf, sizeof(log_buf)); if (flow->bpf_fd[SEC_L3_L4] < 0) { TAP_LOG(ERR, "Failed to load BPF section %s (%d): %s", diff --git a/drivers/net/tap/tap_flow.h b/drivers/net/tap/tap_flow.h index 240fbc3dfaef..fb30b495fda1 100644 --- a/drivers/net/tap/tap_flow.h +++ b/drivers/net/tap/tap_flow.h @@ -57,8 +57,8 @@ int tap_flow_implicit_destroy(struct pmd_internals *pmd, int tap_flow_implicit_flush(struct pmd_internals *pmd, struct rte_flow_error *error); -int tap_flow_bpf_cls_q(__u32 queue_idx); -int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd); +int tap_flow_bpf_cls_q(__u32 queue_idx, char *log_buf, size_t log_size); +int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd, char *log_buf, size_t log_size); int tap_flow_bpf_rss_map_create(unsigned int key_size, unsigned int value_size, unsigned int max_entries); int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value);