From patchwork Fri Jan 5 22:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135766 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 CB83C432AF; Fri, 5 Jan 2024 23:29:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FF8A40649; Fri, 5 Jan 2024 23:29:22 +0100 (CET) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mails.dpdk.org (Postfix) with ESMTP id BE793402DC for ; Fri, 5 Jan 2024 23:29:20 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-6d9c2db82b0so72151b3a.1 for ; Fri, 05 Jan 2024 14:29:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1704493760; x=1705098560; 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=5aTBSFgrPOMO/R+MqX00UU/ZOVeyHrEUd3EFwe2r7FI=; b=BMElINwOCKvo7gCjkWlX2ic7ASYCe4bnWZ/tQ53cvBU7LdrX0KD1ligcm5yJK2+q3V U7cfkM00gL2eAfGFHVlJoVda00B4Xn/Nd74hJKn9CBrTkZN/bzNVFTzYdQ+s1EvLx+MJ 9CKd88vPjElhv6B2A6kWo84gGSYKJungjEL+1W7RvpQZZwTjFUnau/WJgi1UjpN+tDeU 9r7lj8e3nYB43RvL8p7LRx+9/YJY1TezpWx6i/HzbxuODBLBdjjvP2satOVloX6A1T7s D2nELmDQOSSprj8lsfacYCJqNlf3m+h6KWIqcP3B8VikYOXWfO5z6gFDZtRoXvJNb98P 3PmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493760; x=1705098560; 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=5aTBSFgrPOMO/R+MqX00UU/ZOVeyHrEUd3EFwe2r7FI=; b=lsan6yz8grdXDCwleHzZPcaIXnMUzabJzuH2xNZtOKT3Dvv5jrL3p+e+MUG+04/m8j h4ttDXtrLWkZsApyawKxZvpdzY2kE8lVHJNI3mjgTVIPD2kL6pfTeZMM/0avdmD9Z0Nd Z4Z5I1VWKfaaxRMT9MKrxLzyrcmo8JCD2uNbmsXw7B9fRpt3Su56KL5cofDhSE2yNnDL pI7J5SZo6yNrCUZwNLTInAnMelCuFIdLaDlD3WdcVIf0fYdifU9NAljx6/qFArDMdnkG HlON74b++f6SQnhs4gJh56uXYbJ0jK7eA5MWGYBWC+ZG3rcpwNVHCfHJsVVP9/tUA6kX BR5w== X-Gm-Message-State: AOJu0YybgsAhvkpMIBApti0cTto8mVcFt84f5E6r6uoGT+9C7N3Xh63z BO/qePijKB9Iz1uR28T+p5gpddIGaj8Sc98RXykJ+akMaRk= X-Google-Smtp-Source: AGHT+IHMHFcnxfyno5ZKTKxxCMVRg3Y5SCF8CzPhQk5yRs7rS6akNbz7rqsmkyCiyhCYgo5JgOCYMg== X-Received: by 2002:a05:6a21:6d96:b0:196:b157:a0a3 with SMTP id wl22-20020a056a216d9600b00196b157a0a3mr47245pzb.62.1704493759944; Fri, 05 Jan 2024 14:29:19 -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.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:29:19 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 1/5] tap: move forward declaration of bpf_load Date: Fri, 5 Jan 2024 14:28:07 -0800 Message-ID: <20240105222909.139674-2-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 local function bpf_load forward declaration should be in the one file using it. Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_bpf.h | 3 --- drivers/net/tap/tap_bpf_api.c | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/tap/tap_bpf.h b/drivers/net/tap/tap_bpf.h index 0d38bc111fe0..aa5a733525e1 100644 --- a/drivers/net/tap/tap_bpf.h +++ b/drivers/net/tap/tap_bpf.h @@ -115,7 +115,4 @@ enum { BPF_MAP_ID_SIMPLE, }; -static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns, - size_t insns_cnt, const char *license); - #endif /* __TAP_BPF_H__ */ diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index 15283f8917ed..a6adec855dda 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -15,6 +15,9 @@ #include #include +static int bpf_load(enum bpf_prog_type type, const struct bpf_insn *insns, + size_t insns_cnt, const char *license); + /** * Load BPF program (section cls_q) into the kernel and return a bpf fd * From patchwork Fri Jan 5 22:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135767 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 EB1EC432AF; Fri, 5 Jan 2024 23:29:32 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A46E04067C; Fri, 5 Jan 2024 23:29:23 +0100 (CET) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by mails.dpdk.org (Postfix) with ESMTP id 466FF40608 for ; Fri, 5 Jan 2024 23:29:21 +0100 (CET) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1d4c27cd502so256255ad.0 for ; Fri, 05 Jan 2024 14:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1704493760; x=1705098560; 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=oHHRZ/j+OCFdnV0SJbRo04U6hX3EuEMvbdmx20NspBs=; b=1oUt4i4ihZB84hmrQKkv8g06RuxVV7LcHQzY/h0sgWGD0zze1eJe++knOADvExgWRx TjxFqKzlv8epAPibPGhKWoVTiuhgMnYD5W90GC1WObrTikVILXS58Nx07o43nl+6txAT G8LHl7P3a1pPEDMUCvNmvGhqjiA9d32uwWXHZzTmt1166UoOcjLnuo7oJig+PW9jrNbx dwbWulLL8S8Awcw/Tq4o7VrzoBAFi1mY3eIFBVAFAMXDxpKg3rljKTsCmfWHnbLKWdzq l2gcrx6mbCdbxdBlUl5qqG2S1tpPQ/X5hVPUl/w3mX6djFR6n8VfVC8O5rbmnAXHVm99 BDlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493760; x=1705098560; 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=oHHRZ/j+OCFdnV0SJbRo04U6hX3EuEMvbdmx20NspBs=; b=BphEKY+70dgd7eQRZCzfHaNxy5z1mrb37d9DbCgmZGyluEQW9I5C7gpMk4F7jYpLZn MC+3uijL1YXGseWuarYb3e1za2hyERnP/Oqmd4yZBBqRUp7zMyQ1UipL6K8vcYFJ9nXj PIDpOGKPKZJpq8O7ErQ3M/ODWS0gRl5u+aXShu07TEgmKFEvUsw5Y8vYYaH7SEtJXoYX DFIGwgftvJC44pUaoIidhTeXchviFf5+nBGumKfFDv6WnZlWlXeMVHxUD5AHnSE6FZ5u 4ebi2YYcWwZrY4IyoYCXXy7WryhX7NyeWm/49OpblcbCL0c9u+AxQzqVBhQ2gFuYNwWh +SuQ== X-Gm-Message-State: AOJu0YzRnEnPDamLZGVAzFr+3vTgNTLKckuu1avx0bjBRTMisSO9QYxJ ryj1eTZBwepeOpjOQjx3t/DZ/ot8ivKh/m8AwcPUfyQduFo= X-Google-Smtp-Source: AGHT+IEV5Go8JL+2i8ecezs37gQz/HjwVESMm9Z6Ljw5FHidH6posEU8ly87X3vkMwAj2OIn93Sb4A== X-Received: by 2002:a17:902:a384:b0:1d4:2f1c:825a with SMTP id x4-20020a170902a38400b001d42f1c825amr136185pla.102.1704493760745; Fri, 05 Jan 2024 14:29:20 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:29:20 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 2/5] tap: remove unnecessary bzero() calls in bpf api Date: Fri, 5 Jan 2024 14:28:08 -0800 Message-ID: <20240105222909.139674-3-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 structures are already fully initialized, bzero() or memset is redundant. Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_bpf_api.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index a6adec855dda..d176da0802eb 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -120,7 +120,6 @@ static int bpf_load(enum bpf_prog_type type, { union bpf_attr attr = {}; - bzero(&attr, sizeof(attr)); attr.prog_type = type; attr.insn_cnt = (__u32)insns_cnt; attr.insns = ptr_to_u64(insns); @@ -153,7 +152,6 @@ int tap_flow_bpf_rss_map_create(unsigned int key_size, { union bpf_attr attr = {}; - bzero(&attr, sizeof(attr)); attr.map_type = BPF_MAP_TYPE_HASH; attr.key_size = key_size; attr.value_size = value_size; @@ -181,8 +179,6 @@ int tap_flow_bpf_update_rss_elem(int fd, void *key, void *value) { union bpf_attr attr = {}; - bzero(&attr, sizeof(attr)); - attr.map_type = BPF_MAP_TYPE_HASH; attr.map_fd = fd; attr.key = ptr_to_u64(key); From patchwork Fri Jan 5 22:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135768 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 B2A9C432AF; Fri, 5 Jan 2024 23:29:38 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DC10A40693; Fri, 5 Jan 2024 23:29:24 +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 40D67402EF for ; Fri, 5 Jan 2024 23:29:22 +0100 (CET) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1d4a2526a7eso165805ad.3 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=1704493761; x=1705098561; 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=zLOGIWMvdexhVl/qwatdOQVvHl1sQTCLAwQmH8hthNI=; b=N+FQOX9rNo78WmOrrcNhwASNdeM3z7rO8vbWPYSvKszaBVjM5+ilskIrqv2k9RbogE eEqcu0PB9zhaB8Lak80YZj6ndHXAos2yfcWDpzTZXLJeUBvTV7h/lawbRF1ZSiJbPz0J zXuVqTMh1XqnRp0IJmkm8rSqUohLpS4s3efdR/HJS/t8Rfd4VQoCec6Mod6LofPOtLuW 7Dg8MHEklrO1WvaCqyXEZg7dNN7LMsnjT2R4x1oOX87nWnRZfkRvlMm7dDLLeffBEsis L2IQmnrXZq3psruCrXvFEYKJ0KfOwbvgmPkE+J5UWirPtUiWMsKGAPOTHGtyTo2lbWK6 JPDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493761; x=1705098561; 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=zLOGIWMvdexhVl/qwatdOQVvHl1sQTCLAwQmH8hthNI=; b=Bw4Ucy9axS1Mcu2McUz7/99AMxqziM08ju3e3RkPy7AHzeom5ARgypfOmfdxU2JIQF crceBoLDdLwnH0UdSdd7XR4ay8Qv07kL2Ue5bPGO8GGC3/J+j9G6ebjlP/l/ql8I+KUm ykAeLFePXgIDoOBnPRyc+kkIUeIMdfioTlHJFctSVxj9Ay2iYWCE+DqTpCon0KgMv0UX I2l850XTF2zt7uULiy7am+7H1AJbWbgtbRJLBtRYjtn1/relFqPFr2WIP1YN7BYpnE4a P1bWjZWNzy23xDO90qtj2gdzB+xR+0fKBuC3OuBs++ZP7uDtdjov1InJLovOUv1BSjc0 xSZA== X-Gm-Message-State: AOJu0YyAf0oqFZk75SHrUs6TTEdbgSQ8H6sPGlnlD5dJitDMImL1JtH4 3EMgY6qLu3rTaLOqiIcujpwo7N0RknUn9jmddWaZiIJFPsE= X-Google-Smtp-Source: AGHT+IG2FPYLh4ARtwRmbUE3ZoEbV46R8NMgEJ50OwBHVCRAl6Uyf26iaDU6moOnjfvsfrv6o2gGMg== X-Received: by 2002:a17:902:ef85:b0:1d4:9dd9:9cb4 with SMTP id iz5-20020a170902ef8500b001d49dd99cb4mr136253plb.92.1704493761488; Fri, 05 Jan 2024 14:29:21 -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.20 (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 3/5] tap: remove unnecessary cast in call to bpf_load Date: Fri, 5 Jan 2024 14:28:09 -0800 Message-ID: <20240105222909.139674-4-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 callers already have the correct data type. Signed-off-by: Stephen Hemminger --- drivers/net/tap/tap_bpf_api.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index d176da0802eb..c754c167a764 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -32,9 +32,8 @@ int tap_flow_bpf_cls_q(__u32 queue_idx) cls_q_insns[1].imm = queue_idx; return bpf_load(BPF_PROG_TYPE_SCHED_CLS, - (struct bpf_insn *)cls_q_insns, - RTE_DIM(cls_q_insns), - "Dual BSD/GPL"); + cls_q_insns, RTE_DIM(cls_q_insns), + "Dual BSD/GPL"); } /** @@ -55,9 +54,8 @@ int tap_flow_bpf_calc_l3_l4_hash(__u32 key_idx, int map_fd) l3_l4_hash_insns[9].imm = map_fd; return bpf_load(BPF_PROG_TYPE_SCHED_ACT, - (struct bpf_insn *)l3_l4_hash_insns, - RTE_DIM(l3_l4_hash_insns), - "Dual BSD/GPL"); + l3_l4_hash_insns, RTE_DIM(l3_l4_hash_insns), + "Dual BSD/GPL"); } /** 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); From patchwork Fri Jan 5 22:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 135770 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 1FB21432AF; Fri, 5 Jan 2024 23:29:49 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3BE21406BC; Fri, 5 Jan 2024 23:29:27 +0100 (CET) Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) by mails.dpdk.org (Postfix) with ESMTP id C959B402DC for ; Fri, 5 Jan 2024 23:29:23 +0100 (CET) Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-6d9b050e88cso77935b3a.0 for ; Fri, 05 Jan 2024 14:29:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1704493763; x=1705098563; 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=iQL4L6ns3Xe6mFFN+tqfCxERNNRh960NjE05P1HTAnc=; b=fmT0Y0YQArCEhcDO/Xs8RYHh4lOlj0Z+oUmW9EKTSt7uGncAAN/GCEVK1tTJkEzBz8 3Te2yk0iFhkHQ+adLa80DmhJrWr1i/PWpByr1HJPl4+OHEMYNfIYuryTj8DxpaCm46mC 8/eTmmVRUBtokMCTZlfv/hcYpjGdALFxHRTB1GHGLNt6Ty7fDJuQFLeNIIXSJEmqHZHl xn8tXBvIb5szFpBBa57+A21tbisjWqTI9GuDS6cXiVReCFcPPJd7jebehkpjc8PY+d9t t+hFttohSEMaMwL1VqVO9nGyOVDkF5DZsuts2EHkb/v6jPFe7u+w1UgAa7HEm8j7mVai hhSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704493763; x=1705098563; 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=iQL4L6ns3Xe6mFFN+tqfCxERNNRh960NjE05P1HTAnc=; b=epwpDK+Rzmx8jR4YmZVpzl1cWPwbTk3hPKeASqkGxyFl+caeg8OLa0wh5IvhXuYgYU YDSRO8Bj0agjJtU8YvWeRTLOFHKqkLiynG/sR1s/eLPQX4OpYgHssk76VTdQUphQ84bo AI/a3tga+G/1fYf1tSg+1v3OBLuIuQRAQmiuDOREYH6T3zAfOaIJJpcBSgWwNA+L67Q6 HFIw+Kn0B/8RwTwULI+y1TwQuTVQOJDTL4CJ/IdM7cm68iY4yW2qgyXjjRN84fI0X5K9 FmXTos4L4jcpydr/qc067v0afmW9fdNNfQa0WQMmseMBFQPV/rzxQuoyCQ+QpsLnJDk0 y7zg== X-Gm-Message-State: AOJu0YyDEEir6r/vuWj/bXk6dE4YbeJ0/5uozCpFeW2VT4jGDGjLqiht 1AR60prOEGck3Il7Xqo9dA6NFwrvzuxfDAe5nsZsCX6GUdI= X-Google-Smtp-Source: AGHT+IF5DEaHQpJrOsqGWR18pWr+GpXrtvfuhjv4O9EdRkLvNVWbA9HTgb5yJdjLmyzoXlMc8K7wxg== X-Received: by 2002:a05:6a20:1044:b0:195:192c:e5a5 with SMTP id gt4-20020a056a20104400b00195192ce5a5mr38254pzc.56.1704493763040; Fri, 05 Jan 2024 14:29:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jan 2024 14:29:22 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Subject: [RFC 5/5] tap: stop "vendoring" linux bpf header Date: Fri, 5 Jan 2024 14:28:11 -0800 Message-ID: <20240105222909.139674-6-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 proper place for finding bpf structures and functions is in linux/bpf.h. The original version was trying to workaround the case where the build environment was running on old pre BPF version of Glibc, but the target environment had BPF. This is not a supportable build method, and not how rest of DPDK works. Having own private (and divergent) version headers leads to future problems when BPF definitions evolve. Signed-off-by: Stephen Hemminger --- drivers/net/tap/bpf/bpf_extract.py | 1 - drivers/net/tap/tap_bpf.h | 118 ----------------------------- drivers/net/tap/tap_bpf_api.c | 16 ++-- drivers/net/tap/tap_bpf_insns.h | 1 - 4 files changed, 9 insertions(+), 127 deletions(-) delete mode 100644 drivers/net/tap/tap_bpf.h diff --git a/drivers/net/tap/bpf/bpf_extract.py b/drivers/net/tap/bpf/bpf_extract.py index b630c42b809f..73c4dafe4eca 100644 --- a/drivers/net/tap/bpf/bpf_extract.py +++ b/drivers/net/tap/bpf/bpf_extract.py @@ -65,7 +65,6 @@ def write_header(out, source): print(f' * Auto-generated from {source}', file=out) print(" * This not the original source file. Do NOT edit it.", file=out) print(" */\n", file=out) - print("#include ", file=out) def main(): diff --git a/drivers/net/tap/tap_bpf.h b/drivers/net/tap/tap_bpf.h deleted file mode 100644 index aa5a733525e1..000000000000 --- a/drivers/net/tap/tap_bpf.h +++ /dev/null @@ -1,118 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 - * Copyright 2017 Mellanox Technologies, Ltd - */ - -#ifndef __TAP_BPF_H__ -#define __TAP_BPF_H__ - -#include - -/* Do not #include since eBPF must compile on different - * distros which may include partial definitions for eBPF (while the - * kernel itself may support eBPF). Instead define here all that is needed - */ - -/* BPF_MAP_UPDATE_ELEM command flags */ -#define BPF_ANY 0 /* create a new element or update an existing */ - -/* BPF architecture instruction struct */ -struct bpf_insn { - __u8 code; - __u8 dst_reg:4; - __u8 src_reg:4; - __s16 off; - __s32 imm; /* immediate value */ -}; - -/* BPF program types */ -enum bpf_prog_type { - BPF_PROG_TYPE_UNSPEC, - BPF_PROG_TYPE_SOCKET_FILTER, - BPF_PROG_TYPE_KPROBE, - BPF_PROG_TYPE_SCHED_CLS, - BPF_PROG_TYPE_SCHED_ACT, -}; - -/* BPF commands types */ -enum bpf_cmd { - BPF_MAP_CREATE, - BPF_MAP_LOOKUP_ELEM, - BPF_MAP_UPDATE_ELEM, - BPF_MAP_DELETE_ELEM, - BPF_MAP_GET_NEXT_KEY, - BPF_PROG_LOAD, -}; - -/* BPF maps types */ -enum bpf_map_type { - BPF_MAP_TYPE_UNSPEC, - BPF_MAP_TYPE_HASH, -}; - -/* union of anonymous structs used with TAP BPF commands */ -union bpf_attr { - /* BPF_MAP_CREATE command */ - struct { - __u32 map_type; - __u32 key_size; - __u32 value_size; - __u32 max_entries; - __u32 map_flags; - __u32 inner_map_fd; - }; - - /* BPF_MAP_UPDATE_ELEM, BPF_MAP_DELETE_ELEM commands */ - struct { - __u32 map_fd; - __aligned_u64 key; - union { - __aligned_u64 value; - __aligned_u64 next_key; - }; - __u64 flags; - }; - - /* BPF_PROG_LOAD command */ - struct { - __u32 prog_type; - __u32 insn_cnt; - __aligned_u64 insns; - __aligned_u64 license; - __u32 log_level; - __u32 log_size; - __aligned_u64 log_buf; - __u32 kern_version; - __u32 prog_flags; - }; -} __rte_aligned(8); - -#ifndef __NR_bpf -# if defined(__i386__) -# define __NR_bpf 357 -# elif defined(__x86_64__) -# define __NR_bpf 321 -# elif defined(__arm__) -# define __NR_bpf 386 -# elif defined(__aarch64__) -# define __NR_bpf 280 -# elif defined(__sparc__) -# define __NR_bpf 349 -# elif defined(__s390__) -# define __NR_bpf 351 -# elif defined(__powerpc__) -# define __NR_bpf 361 -# elif defined(__riscv) -# define __NR_bpf 280 -# elif defined(__loongarch__) -# define __NR_bpf 280 -# else -# error __NR_bpf not defined -# endif -#endif - -enum { - BPF_MAP_ID_KEY, - BPF_MAP_ID_SIMPLE, -}; - -#endif /* __TAP_BPF_H__ */ diff --git a/drivers/net/tap/tap_bpf_api.c b/drivers/net/tap/tap_bpf_api.c index 29223b7f0ea7..54e469ebf5ff 100644 --- a/drivers/net/tap/tap_bpf_api.c +++ b/drivers/net/tap/tap_bpf_api.c @@ -2,17 +2,13 @@ * Copyright 2017 Mellanox Technologies, Ltd */ -#include -#include #include -#include +#include +#include -#include -#include #include #include -#include -#include + #include static int bpf_load(enum bpf_prog_type type, @@ -106,7 +102,13 @@ static inline __u64 ptr_to_u64(const void *ptr) static inline int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, unsigned int size) { +#ifdef __NR_bpf return syscall(__NR_bpf, cmd, attr, size); +#else + fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); + errno = ENOSYS; + return -1; +#endif } /** diff --git a/drivers/net/tap/tap_bpf_insns.h b/drivers/net/tap/tap_bpf_insns.h index 53fa76c4e6b0..88aec6885a06 100644 --- a/drivers/net/tap/tap_bpf_insns.h +++ b/drivers/net/tap/tap_bpf_insns.h @@ -3,7 +3,6 @@ * This not the original source file. Do NOT edit it. */ -#include static struct bpf_insn cls_q_insns[] = { {0x61, 2, 1, 52, 0x00000000},