From patchwork Wed Jun 27 02:46:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 935239 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=dev.mellanox.co.il Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=dev-mellanox-co-il.20150623.gappssmtp.com header.i=@dev-mellanox-co-il.20150623.gappssmtp.com header.b="OaJUzL6y"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41FnPJ4hpBz9s0n for ; Wed, 27 Jun 2018 12:47:00 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754079AbeF0Cqx (ORCPT ); Tue, 26 Jun 2018 22:46:53 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:43559 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932186AbeF0Cqq (ORCPT ); Tue, 26 Jun 2018 22:46:46 -0400 Received: by mail-pf0-f196.google.com with SMTP id y8-v6so269013pfm.10 for ; Tue, 26 Jun 2018 19:46:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dev-mellanox-co-il.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DJ7cGyRbugq9xhJ2UW7uRaQumNTMGTIpGMv/rVkSO8s=; b=OaJUzL6yj2zN31UMS85E6QaIkQNqOWP2VLmomzDWLKfv6LIzbbMPAexS0cmEHKrE4O sgVV5QjziGBf0lKmfXaub8v2GALbl/Qra3AZNP8J+QT1koneYxFdC1Jz0wadsn92iU3a ldKuk7+kfb24mf4IZ61kOYrtDZQ374pxF+EVdmgdfBKl9vJWfIlGHSGfXUMKY1xplqf9 TfOR+Z4SdsbtGA/v5fjim6Qq9xNqsaLQZLRzOTb3eLnhC9vPWjdtzZ38UUMI2zQ3p63S J6JbWnLHVYx/fZQ0AxbqBaoddjA3Z3tGAiC+FxVJXgGJw/OPs8J3dy2MrOWSo+E2kE7k bifg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=DJ7cGyRbugq9xhJ2UW7uRaQumNTMGTIpGMv/rVkSO8s=; b=dsym/kKMprVQnvDJHHeqYmEDM7HgJccpyhpt4gxUHNA2eIxn8xiEQNLme8SP+UEWMt cOVs9tBE9+O5mR5eIpyeTQQCua9agTB8M8YPI8JymhmcYT2bzM6DGQeLSuVaMbrS446E TeT9UnHE/MuixASolbeu3ka1kNTpf61XxqmBE2xqYsvzl2+fjlae7QNTIEnFnGxxYWfW FP5J2nhFYWnbooaPVhuOC43Tul5XB/hAamzBgnclySNi9VYQGiD9lZYSlPoyTx025jKd QkIVXqErHrwVQCOz+NxCJxOD8DNRL3eylVeG8kSbG84zXItyBivt0s4tXiyOtb74I2mJ /n9g== X-Gm-Message-State: APt69E2HoiknBLme8YR9UxZC0BuL4GOnKW9OiUd6Rn5JxrI1kLaOvB4g OThY23ebXMPe8ylG3/MQnfkR5Q== X-Google-Smtp-Source: ADUXVKI40+Uqnmbqh59e+9fj77LWRPSOnFlFtLR647i6k+iOVSzmScZfi10vVTYt0RB1Ps2AKs2BBQ== X-Received: by 2002:a65:6612:: with SMTP id w18-v6mr3457813pgv.38.1530067605587; Tue, 26 Jun 2018 19:46:45 -0700 (PDT) Received: from stpd.hsd1.ca.comcast.net ([2601:647:4000:4586::4088]) by smtp.gmail.com with ESMTPSA id j21-v6sm3950904pfn.121.2018.06.26.19.46.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Jun 2018 19:46:44 -0700 (PDT) From: Saeed Mahameed X-Google-Original-From: Saeed Mahameed To: Jesper Dangaard Brouer , Alexei Starovoitov , Daniel Borkmann Cc: neerav.parikh@intel.com, pjwaskiewicz@gmail.com, ttoukan.linux@gmail.com, Tariq Toukan , alexander.h.duyck@intel.com, peter.waskiewicz.jr@intel.com, Opher Reviv , Rony Efraim , netdev@vger.kernel.org, Saeed Mahameed Subject: [RFC bpf-next 6/6] samples/bpf: Add meta data hash example to xdp_redirect_cpu Date: Tue, 26 Jun 2018 19:46:15 -0700 Message-Id: <20180627024615.17856-7-saeedm@mellanox.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180627024615.17856-1-saeedm@mellanox.com> References: <20180627024615.17856-1-saeedm@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add a new program (prog_num = 4) that will not parse packets and will use the meta data hash to spread/redirect traffic into different cpus. For the new program we set on bpf_set_link_xdp_fd: xdp_flags |= XDP_FLAGS_META_HASH | XDP_FLAGS_META_VLAN; On mlx5 it will succeed since mlx5 already supports these flags. The new program will read the value of the hash from the data_meta pointer from the xdp_md and will use it to compute the destination cpu. Note: I didn't test this patch to show redirect works with the hash! I only used it to see that the hash and vlan values are set correctly by the driver and can be seen by the xdp program. * I faced some difficulties to read the hash value using the helper functions defined in the previous patches, but once i used the same logic with out these functions it worked ! Will have to figure this out later. Signed-off-by: Saeed Mahameed --- samples/bpf/xdp_redirect_cpu_kern.c | 67 +++++++++++++++++++++++++++++ samples/bpf/xdp_redirect_cpu_user.c | 7 +++ 2 files changed, 74 insertions(+) diff --git a/samples/bpf/xdp_redirect_cpu_kern.c b/samples/bpf/xdp_redirect_cpu_kern.c index 303e9e7161f3..d6b3f55f342a 100644 --- a/samples/bpf/xdp_redirect_cpu_kern.c +++ b/samples/bpf/xdp_redirect_cpu_kern.c @@ -376,6 +376,73 @@ int xdp_prognum3_proto_separate(struct xdp_md *ctx) return bpf_redirect_map(&cpu_map, cpu_dest, 0); } +#if 0 +xdp_md_info_arr mdi = { + [XDP_DATA_META_HASH] = {.offset = 0, .present = 1}, + [XDP_DATA_META_VLAN] = {.offset = sizeof(struct xdp_md_hash), .present = 1}, +}; +#endif + +SEC("xdp_cpu_map4_hash_separate") +int xdp_prognum4_hash_separate(struct xdp_md *ctx) +{ + void *data_meta = (void *)(long)ctx->data_meta; + void *data_end = (void *)(long)ctx->data_end; + void *data = (void *)(long)ctx->data; + struct xdp_md_hash *hash; + struct xdp_md_vlan *vlan; + struct datarec *rec; + u32 cpu_dest = 0; + u32 cpu_idx = 0; + u32 *cpu_lookup; + u32 key = 0; + + /* Count RX packet in map */ + rec = bpf_map_lookup_elem(&rx_cnt, &key); + if (!rec) + return XDP_ABORTED; + rec->processed++; + + /* for some reason this code fails to be verified */ +#if 0 + hash = xdp_data_meta_get_hash(mdi, data_meta); + if (hash + 1 > data) + return XDP_ABORTED; + + vlan = xdp_data_meta_get_vlan(mdi, data_meta); + if (vlan + 1 > data) + return XDP_ABORTED; +#endif + + /* Work around for the above code */ + hash = data_meta; /* since we know hash will appear first */ + if (hash + 1 > data) + return XDP_ABORTED; + +#if 0 + // Just for testing + /* We know that vlan will appear after the hash */ + vlan = (void *)((char *)data_meta + sizeof(*hash)); + if (vlan + 1 > data) { + return XDP_ABORTED; + } +#endif + + cpu_idx = reciprocal_scale(hash->hash, MAX_CPUS); + + cpu_lookup = bpf_map_lookup_elem(&cpus_available, &cpu_idx); + if (!cpu_lookup) + return XDP_ABORTED; + cpu_dest = *cpu_lookup; + + if (cpu_dest >= MAX_CPUS) { + rec->issue++; + return XDP_ABORTED; + } + + return bpf_redirect_map(&cpu_map, cpu_dest, 0); +} + SEC("xdp_cpu_map4_ddos_filter_pktgen") int xdp_prognum4_ddos_filter_pktgen(struct xdp_md *ctx) { diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c index f6efaefd485b..3429215d5a7b 100644 --- a/samples/bpf/xdp_redirect_cpu_user.c +++ b/samples/bpf/xdp_redirect_cpu_user.c @@ -679,6 +679,13 @@ int main(int argc, char **argv) return EXIT_FAIL_OPTION; } + /* + * prog_num 4 requires xdp meta data hash + * Vlan is not required but added just for testing.. + */ + if (prog_num == 4) + xdp_flags |= XDP_FLAGS_META_HASH | XDP_FLAGS_META_VLAN; + /* Remove XDP program when program is interrupted */ signal(SIGINT, int_exit);