From patchwork Tue Jan 12 19:41:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED42DC4332D for ; Tue, 12 Jan 2021 19:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CF0632310A for ; Tue, 12 Jan 2021 19:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2406791AbhALTnB (ORCPT ); Tue, 12 Jan 2021 14:43:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436549AbhALTnB (ORCPT ); Tue, 12 Jan 2021 14:43:01 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B312C0617A5 for ; Tue, 12 Jan 2021 11:41:59 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id r4so3221185wmh.5 for ; Tue, 12 Jan 2021 11:41:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+hdtHCSFxGXzmG9zcdLMtsA9CM+yy9a1rXrTwefd0k4=; b=uDUgsIFWkCAbgZpUVsXjZnHVBtT5AU2g2Tu3bHmPpimoSMu5Pt0D9DUupyK66NiDmr SFEsFzaU9DeZGgsQNEmiMdYaft+Prt2oiSZp3IwXkNZcxt/HhMRiefuYPbdbHk207Kqk Ox0YHcUONluOucMlOfT29PUY08TWwE4IG1a6SaLfcUzRQriJ5ZteB9zJYi6UG87ywCfN JJHQnkpHwdqQk0KZ4i9o+jUIFEziT+WLlSsXAP0tJN8Igphnx/Aqlr/nyFJ/mvZPN5MB EXwGgSs6GpQKpUPrMqOtt2NwAzA19W1ixaml8FgEQbVfWvbklv/rk1W2DIbuFaxQ7f41 yRmQ== 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=+hdtHCSFxGXzmG9zcdLMtsA9CM+yy9a1rXrTwefd0k4=; b=XFujJKByghg70EUjXz94CcLH5Swis9dSmeMQihI5eOCfOWH5MNTrBuaQ+oanowQrzC jD79VWLsr1nJGUEWKFe3xCVuvuAL+mNoYW1ac2NTm/j+efJkbG0Etykn2ZWKxmOePm0v wZm67pcQ5KqKJbqnONQWWdg5xMTZbkrZwqG7Y0evJPKXjUPY9sxsjrOdpTr/nI5+Jc7l BjzErXv9jgBXvFlzSPezPt1lCax+4qMLqYhopCsfWGaMAKg1vn/51j2DRGIU/ih7W6jC mFeyOfdEOmAL9JKeOKIWf2X/GrT9qPSAYCpt4d0PoIyEKzhnHoKL1sQOEc77VazxjjER 2ycA== X-Gm-Message-State: AOAM532j7uwCguhHaO3QTUazxlhJjXs4WXAFyuIl/ORuUDB/SpvP0LRb KfyxuuLs9JwYhTAuvjoT9WMaoA== X-Google-Smtp-Source: ABdhPJx/0woun/MhI7lJlAwq65ikInzHiKo9rw3lXUFvfj5s5Qs3xrAuB3tgEtBp9fISRu7oCo34FA== X-Received: by 2002:a05:600c:2255:: with SMTP id a21mr809749wmm.122.1610480517946; Tue, 12 Jan 2021 11:41:57 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.41.54 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:41:57 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 1/7] skbuff: define field for hash report type Date: Tue, 12 Jan 2021 21:41:37 +0200 Message-Id: <20210112194143.1494-2-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-State: RFC Used by virtio-net receive side scaling Signed-off-by: Yuri Benditovich --- include/linux/skbuff.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 416bf95cd5f2..36cf40ec0259 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -510,7 +510,7 @@ int skb_zerocopy_iter_stream(struct sock *sk, struct sk_buff *skb, * the end of the header data, ie. at skb->end. */ struct skb_shared_info { - __u8 __unused; + __u8 hash_report_type; /* virtio-net rss */ __u8 meta_len; __u8 nr_frags; __u8 tx_flags; @@ -1430,6 +1430,11 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb) return &skb_shinfo(skb)->hwtstamps; } +static inline __u8 *skb_hash_report_type(struct sk_buff *skb) +{ + return &skb_shinfo(skb)->hash_report_type; +} + static inline struct ubuf_info *skb_zcopy(struct sk_buff *skb) { bool is_zcopy = skb && skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY; From patchwork Tue Jan 12 19:41:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014731 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E4D6C433E9 for ; Tue, 12 Jan 2021 19:43:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DF83323117 for ; Tue, 12 Jan 2021 19:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436625AbhALTnR (ORCPT ); Tue, 12 Jan 2021 14:43:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436612AbhALTnR (ORCPT ); Tue, 12 Jan 2021 14:43:17 -0500 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50FD3C0617A7 for ; Tue, 12 Jan 2021 11:42:02 -0800 (PST) Received: by mail-wr1-x42f.google.com with SMTP id y17so3718635wrr.10 for ; Tue, 12 Jan 2021 11:42:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=95fcQ7XOzwxPXY92PHMXKGjY9iDFTd+3y3erYQ9GO9s=; b=1tCRinMHamPfSeGT7m65Y3aJyKfckJHdtuiPmHaE4Z5fAN3CngoISCY+eCrh3zIQAv EGhkjV84NQPvJCJxVOwNd9CE0wSnFoOAftnadDX8xYXaBW7qtglM9h/6WoA8pAgW+nL6 4m82MlTv/1REnteWu+i3oDfcivx2yXiBbLVQWzMi+Tcckw3PucDqFLBtRMqasUzDWGmC Sab3HyYsjdlZjK/iK3QQ6jEyOIcH0Klo4LqQ2m33gvyaXOOJMwsc5ulFxyUXulZD4eRp /4MJfbr5A2VW61mdnl9hQIzqkj44NmcfjRN0ccLFjp1aO5yzGHEm11Np5MWflBTL9Wtv SGVg== 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=95fcQ7XOzwxPXY92PHMXKGjY9iDFTd+3y3erYQ9GO9s=; b=QiXzLd/lSfInTBvH2LUnnJ28DQPtYTeDWiVc8NrilpBulV8o0FyFwY/5mguULjhXlg 5CiWi6mERzr+rU4FVQb9tElrOrEeKGwXdn9Z/xM17ibhEHbMmycScPVIxoc/gfk9c0cq muUkeQm0HQIZY49cJGfus/C5pKPWgA5ys/+B10DfyudR7c6Ha7AMLx8yGo5luYHMU/w0 UxcX2EK/4vw88O9Dt7YeYIDNW0b8jpsRSAhLizT+O7+fGUq3gk7wsJAPgD0mEizuegCJ QkC6rSqhPVxpfJWqXWu7G6Ymd0L1QxyE2drJo93/UeN2xPdL2MnJsZB0FAI083TBPhF6 fFfQ== X-Gm-Message-State: AOAM5303SXcnAyTx2OQo+DjU3n28GD3gELNw7F43GIcfU5zVcPDQBuSK QNTW1ExFsQodJ78uDZzCIdz4vw== X-Google-Smtp-Source: ABdhPJwozaYVSn8b891ub9ZvGIip49TMHv9Wa+1fM6bn8ZY9QZR52VX9j+xhhl/b0ZukWBXo7jRRLw== X-Received: by 2002:a5d:6c66:: with SMTP id r6mr446833wrz.86.1610480521047; Tue, 12 Jan 2021 11:42:01 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.41.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:00 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 2/7] vhost: support for hash report virtio-net feature Date: Tue, 12 Jan 2021 21:41:38 +0200 Message-Id: <20210112194143.1494-3-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-State: RFC According to the virtio specification if VIRTIO_NET_F_HASH_REPORT feature acked the virtio-net header is extended to hold the hash value and hash report type. Signed-off-by: Yuri Benditovich --- drivers/vhost/net.c | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 531a00d703cd..31a894b9a992 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -73,7 +73,8 @@ enum { VHOST_NET_FEATURES = VHOST_FEATURES | (1ULL << VHOST_NET_F_VIRTIO_NET_HDR) | (1ULL << VIRTIO_NET_F_MRG_RXBUF) | - (1ULL << VIRTIO_F_ACCESS_PLATFORM) + (1ULL << VIRTIO_F_ACCESS_PLATFORM) | + (1ULL << VIRTIO_NET_F_HASH_REPORT) }; enum { @@ -1108,14 +1109,16 @@ static void handle_rx(struct vhost_net *net) .msg_controllen = 0, .msg_flags = MSG_DONTWAIT, }; - struct virtio_net_hdr hdr = { - .flags = 0, - .gso_type = VIRTIO_NET_HDR_GSO_NONE + struct virtio_net_hdr_v1_hash hdrv1 = { + { + .flags = 0, + .gso_type = VIRTIO_NET_HDR_GSO_NONE + } }; size_t total_len = 0; int err, mergeable; s16 headcount; - size_t vhost_hlen, sock_hlen; + size_t vhost_hlen, sock_hlen, extra_hlen; size_t vhost_len, sock_len; bool busyloop_intr = false; struct socket *sock; @@ -1137,9 +1140,12 @@ static void handle_rx(struct vhost_net *net) vhost_hlen = nvq->vhost_hlen; sock_hlen = nvq->sock_hlen; + vq_log = unlikely(vhost_has_feature(vq, VHOST_F_LOG_ALL)) ? vq->log : NULL; mergeable = vhost_has_feature(vq, VIRTIO_NET_F_MRG_RXBUF); + extra_hlen = vhost_has_feature(vq, VIRTIO_NET_F_HASH_REPORT) ? + sizeof(hdrv1) - sizeof(hdrv1.hdr) : 0; do { sock_len = vhost_net_rx_peek_head_len(net, sock->sk, @@ -1201,8 +1207,8 @@ static void handle_rx(struct vhost_net *net) } /* Supply virtio_net_hdr if VHOST_NET_F_VIRTIO_NET_HDR */ if (unlikely(vhost_hlen)) { - if (copy_to_iter(&hdr, sizeof(hdr), - &fixup) != sizeof(hdr)) { + if (copy_to_iter(&hdrv1, sizeof(struct virtio_net_hdr), + &fixup) != sizeof(struct virtio_net_hdr)) { vq_err(vq, "Unable to write vnet_hdr " "at addr %p\n", vq->iov->iov_base); goto out; @@ -1211,7 +1217,7 @@ static void handle_rx(struct vhost_net *net) /* Header came from socket; we'll need to patch * ->num_buffers over if VIRTIO_NET_F_MRG_RXBUF */ - iov_iter_advance(&fixup, sizeof(hdr)); + iov_iter_advance(&fixup, sizeof(struct virtio_net_hdr)); } /* TODO: Should check and handle checksum. */ @@ -1223,6 +1229,18 @@ static void handle_rx(struct vhost_net *net) vhost_discard_vq_desc(vq, headcount); goto out; } + if (unlikely(extra_hlen)) { + if (unlikely(vhost_hlen)) { + if (copy_to_iter(&hdrv1.hash_value, extra_hlen, + &fixup) != extra_hlen) { + vq_err(vq, "Unable to write extra_hdr " + "at addr %p\n", vq->iov->iov_base); + goto out; + } + } else { + iov_iter_advance(&fixup, extra_hlen); + } + } nvq->done_idx += headcount; if (nvq->done_idx > VHOST_NET_BATCH) vhost_net_signal_used(nvq); @@ -1624,6 +1642,9 @@ static int vhost_net_set_features(struct vhost_net *n, u64 features) (1ULL << VIRTIO_F_VERSION_1))) ? sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr); + if (features & (1ULL << VIRTIO_NET_F_HASH_REPORT)) { + hdr_len = sizeof(struct virtio_net_hdr_v1_hash); + } if (features & (1 << VHOST_NET_F_VIRTIO_NET_HDR)) { /* vhost provides vnet_hdr */ vhost_hlen = hdr_len; From patchwork Tue Jan 12 19:41:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014737 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 926C8C4360C for ; Tue, 12 Jan 2021 19:43:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AE152310A for ; Tue, 12 Jan 2021 19:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436811AbhALTnl (ORCPT ); Tue, 12 Jan 2021 14:43:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436805AbhALTnk (ORCPT ); Tue, 12 Jan 2021 14:43:40 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A1D1C0617BA for ; Tue, 12 Jan 2021 11:42:05 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id a12so3736858wrv.8 for ; Tue, 12 Jan 2021 11:42:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=RENS1yiCoqDoLkKN/GRTnjThUIFO+qOBX6TnsDEXMJ4=; b=M/GX6JJ7p2H2eTx80N54RrcrNovJmEJksJOoBQDaMLSzid6cmcZm7fhz67QqX1fL5P IdT39n+3quPjJon55Yrm52XJi48JC4N264PIWrap0CYeK86yDZZ+zEJcTwiKudRaOcu3 wXoQ+xjsPaLtUxHrXSVu9o7ZzQRgJuokj+6KBtBcm0Zx+B7h8aZiYqFXJ3KjMQQyb1JP VOmGW/qJxnsFSZUkpX//QYy9P3sHgwODGlbccFdfwVkGYWPx3MNPz+nieZ4tlIyY6yLl osKVjKeNCMT8VtZGL5mmwM64fXLfHfr+b+cGMxg0fdz/BywiQ1W/2QgZOf6jp8KNqTTi Chyw== 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=RENS1yiCoqDoLkKN/GRTnjThUIFO+qOBX6TnsDEXMJ4=; b=qBzTC4aMwsyBKBMpf+gyM+QL3LmqcHQlgWt2fZM0p1XSjIUV2UbKB23OSzA7LWLcgZ S3FDydqjVAEBxLe4G4pfw4DYYQv0DZmLMrJp9lL7DtnukOvBzCscG1BqQlZB2YHusQVO 8/fFB/Nz3561zkd4VdtU4y8exxP+E4HC/Q4w61SgjDTcq3baHJA7Eoy3yFB2JAjSKLBB xK6Dz/i73Ud7fVanO25vl+EulWub6EvBE3FlIUWLzHTlUdsiBmHp/6jvx7QS28+gO4Tu dKve89UpIuxQ69VkcpO64Q6Btz2ELp3v0mVDSkx/ttq56zRrqez4sZ9+Ca55FyIcVKDF iTVg== X-Gm-Message-State: AOAM533sWEk45mSKFVM3bhd3M+fYT5X0CvALKWW5YSGeQ7jJB78OPYGj dYjXM0Pu3xq0Si1ghyRseiQyww== X-Google-Smtp-Source: ABdhPJy88KkYeCfk/twqMv7qxLAVLrtcCRDSJ2F4RxIb3LJRD8cqoUZ55scrlMHcmG48qxh7J7CDhQ== X-Received: by 2002:a5d:604b:: with SMTP id j11mr437008wrt.406.1610480524252; Tue, 12 Jan 2021 11:42:04 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.42.01 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:03 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 3/7] tun: allow use of BPF_PROG_TYPE_SCHED_CLS program type Date: Tue, 12 Jan 2021 21:41:39 +0200 Message-Id: <20210112194143.1494-4-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC This program type can set skb hash value. It will be useful when the tun will support hash reporting feature if virtio-net. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 7959b5c2d11f..455f7afc1f36 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2981,6 +2981,8 @@ static int tun_set_ebpf(struct tun_struct *tun, struct tun_prog __rcu **prog_p, prog = NULL; } else { prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SOCKET_FILTER); + if (IS_ERR(prog)) + prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SCHED_CLS); if (IS_ERR(prog)) return PTR_ERR(prog); } From patchwork Tue Jan 12 19:41:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014729 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E58B8C433E0 for ; Tue, 12 Jan 2021 19:43:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A362B2310A for ; Tue, 12 Jan 2021 19:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436609AbhALTnQ (ORCPT ); Tue, 12 Jan 2021 14:43:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436600AbhALTnQ (ORCPT ); Tue, 12 Jan 2021 14:43:16 -0500 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68422C0617BE for ; Tue, 12 Jan 2021 11:42:08 -0800 (PST) Received: by mail-wr1-x436.google.com with SMTP id y17so3718899wrr.10 for ; Tue, 12 Jan 2021 11:42:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=u0kBDkZSof0LwbMWuYCOPhj4hHVMvwb36KmGU51ii7Y=; b=qXPm6RRC85TTK9KaSiUv157OWNC4uLnK5R55zCcddSz/OH6u6hYx1S9F76b6fwU3/m L5598+Ur8w96+Gg+RoiczvrXtQYRI8O+fGupwlj+IkNmOGSHUsW9Tf1BtX3kiNe71Rgx WKTBblBdOSXaDLvovQo/HLN7qCMsRVlCKSDg9YBktWJQB59pnUT8dN+HdiYyVYBkhQuJ CvKCRk6Kcw/A1SvK/Qud7BzT6mgq06tzFkvkVxffAFW66gfIBLQhmu6VrRnGc6K1j6UJ Fl4DWwsqoJ4iK+vFlmlYQCh6SYdu4g5kQNpVx2IBQVS/3tq45sNhLUGPnbg8Ifcy6piT l22A== 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=u0kBDkZSof0LwbMWuYCOPhj4hHVMvwb36KmGU51ii7Y=; b=PI2imvrngmH72exXAp0xOmI9p8USAx2zFRS0tTcwFEgIjqG3sRzxNirltEyDs3/2Nq xfps+inRtZXSEpZutw8KNUkvs2bRryYsor4c8HjnLeiqx+iDpLM2lOXDhWTfpKoQ7lo9 sC4JMMQh3qHgltzKtCgQM0l+iM1nVb5fRhchhAcwLCMrz5gs+Iuwb0RU6mcsA3OTheCS higTtglnhTNetoaPXykq+Itxn6N3621YkgtkEoKDc1AbcoxsSixaLHkAM9eFZOP6UbI6 ipiPaigmZcLhVdq89WUgatIHspdKCouiq1X3gUMYJwkRtBEqoBffn77Huwvxxgv7T5iq Aq1g== X-Gm-Message-State: AOAM533OfgT6VlTlwiME8fv5BrZBFvPjHvaZ6y6oVjqmaWg0ZKy+xQc7 /fsMhU3iRPparnJ6MQZZNggG3w== X-Google-Smtp-Source: ABdhPJwQIJTkLLUDMFNxy3mBWVt2sZtp82KzceRnAi/2Dy2UB4frEHQodHJV577V0ALRuxgqVPsWHg== X-Received: by 2002:a5d:674b:: with SMTP id l11mr423783wrw.247.1610480527197; Tue, 12 Jan 2021 11:42:07 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.42.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:06 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 4/7] tun: free bpf_program by bpf_prog_put instead of bpf_prog_destroy Date: Tue, 12 Jan 2021 21:41:40 +0200 Message-Id: <20210112194143.1494-5-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC The module never creates the bpf program with bpf_prog_create so it shouldn't free it with bpf_prog_destroy. The program is obtained by bpf_prog_get and should be freed by bpf_prog_put. For BPF_PROG_TYPE_SOCKET_FILTER both methods do the same but for other program types they don't. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 455f7afc1f36..18c1baf1a6c1 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2218,7 +2218,7 @@ static void tun_prog_free(struct rcu_head *rcu) { struct tun_prog *prog = container_of(rcu, struct tun_prog, rcu); - bpf_prog_destroy(prog->prog); + bpf_prog_put(prog->prog); kfree(prog); } From patchwork Tue Jan 12 19:41:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014735 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6447FC4321A for ; Tue, 12 Jan 2021 19:43:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 479BB2310E for ; Tue, 12 Jan 2021 19:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436829AbhALTnn (ORCPT ); Tue, 12 Jan 2021 14:43:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436825AbhALTnl (ORCPT ); Tue, 12 Jan 2021 14:43:41 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01EF2C0617BF for ; Tue, 12 Jan 2021 11:42:12 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id a6so2970185wmc.2 for ; Tue, 12 Jan 2021 11:42:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZIRhmzhJTza1eg/duDC8aSWDJ8wELCNq6nzGwLtOGgE=; b=d9NxmNZSQNFWQVyP7EOF6ws9upmBjMm7Uu4vcCvAagQcJvjqLbg5+r9m2RsQFFiJis Phmfncl8NVLjetiCUd7//m3Bmb/XboSynU2+TTlz7fnQQrc7Jpxc4hbmaw8FZqV5TH7y sRRNBzmxv6jAlGIonq5UpuL7dMdRW+ftT3cnGIa3N0L2U2c/1jaGnLRqD4+8bMh4rAPo vOvc7I+Tm890KsTLrvzdfciGgT5p7v9XHa51iZ9aT1MwsRe8bYEEqZSNxG/W4qodptly zpZ2A26Vz1arJqMbfke1ek2319CmQxsbEOY6yJmN8LiK+JJsd/aLYiWW1hD2hgKV/tZM NhXw== 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=ZIRhmzhJTza1eg/duDC8aSWDJ8wELCNq6nzGwLtOGgE=; b=NSmcWJajvWdOQfVI4uqgAt6qKHTexLuD8ArHvD8wV8yibnIXXiVkfdVw7e+Lgt95A1 SPv1N0WhHbko71/YRFyPbUwOAylQjYdzUr1OGObU/6VIiaY2g4oq1Fvu0nsyg5E8PMwS fOXIpJfggp/j0wEKNdfWACZDJeEBrvpBtEnENUjEymgJt4wfZ3oCd/H9Pjol27JNjxs/ BeiGs3xOYGvwSJijR9eZL9n8Fm9H/i9KPliKyZ8OzcBZyXNMRl09vkh0sfw5D6ySTJh6 //zNKBAM8is4sWrHRSMVGvxqFm4FZUVhOQXu3omTULBr6Pp/sAv+YvLmFpkCZYo5JYfq 2xOA== X-Gm-Message-State: AOAM530MAmU9RqqZ+d1/IDuLy87K+pQx2TaWTtiD33ab8VjWUGbhYOq6 FRylTL7WEyZGiTHVAaIOu2Qo9w== X-Google-Smtp-Source: ABdhPJxgkunWSUTHmZ71tMmXeTXU/QgKZnSQGKYYciKcgoVgRx0jy5oBLeyU4zrM4dUfJdLaLRdw1g== X-Received: by 2002:a7b:c45a:: with SMTP id l26mr755038wmi.91.1610480530694; Tue, 12 Jan 2021 11:42:10 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.42.07 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:09 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 5/7] tun: add ioctl code TUNSETHASHPOPULATION Date: Tue, 12 Jan 2021 21:41:41 +0200 Message-Id: <20210112194143.1494-6-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC User mode program calls this ioctl before loading of BPF program to inform the tun that the BPF program has extended functionality, i.e. sets hash value and returns the virtqueue number in the lower 16 bits and the type of the hash report in the upper 16 bits. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 12 +++++++++++- include/uapi/linux/if_tun.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 18c1baf1a6c1..45f4f04a4a3e 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -197,6 +197,7 @@ struct tun_struct { struct sock_fprog fprog; /* protected by rtnl lock */ bool filter_attached; + bool bpf_populates_hash; u32 msg_enable; spinlock_t lock; struct hlist_head flows[TUN_NUM_FLOW_ENTRIES]; @@ -2765,6 +2766,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) tun->align = NET_SKB_PAD; tun->filter_attached = false; + tun->bpf_populates_hash = false; tun->sndbuf = tfile->socket.sk->sk_sndbuf; tun->rx_batched = 0; RCU_INIT_POINTER(tun->steering_prog, NULL); @@ -2997,7 +2999,7 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, struct net *net = sock_net(&tfile->sk); struct tun_struct *tun; void __user* argp = (void __user*)arg; - unsigned int ifindex, carrier; + unsigned int ifindex, carrier, populate_hash; struct ifreq ifr; kuid_t owner; kgid_t group; @@ -3298,6 +3300,14 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd, ret = open_related_ns(&net->ns, get_net_ns); break; + case TUNSETHASHPOPULATION: + ret = -EFAULT; + if (copy_from_user(&populate_hash, argp, sizeof(populate_hash))) + goto unlock; + tun->bpf_populates_hash = !!populate_hash; + ret = 0; + break; + default: ret = -EINVAL; break; diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 454ae31b93c7..0fd43533da26 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -61,6 +61,7 @@ #define TUNSETFILTEREBPF _IOR('T', 225, int) #define TUNSETCARRIER _IOW('T', 226, int) #define TUNGETDEVNETNS _IO('T', 227) +#define TUNSETHASHPOPULATION _IOR('T', 228, int) /* TUNSETIFF ifr flags */ #define IFF_TUN 0x0001 From patchwork Tue Jan 12 19:41:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014739 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3A8D6C4332D for ; Tue, 12 Jan 2021 19:44:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0BFB82310E for ; Tue, 12 Jan 2021 19:44:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732196AbhALToN (ORCPT ); Tue, 12 Jan 2021 14:44:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2406803AbhALTn4 (ORCPT ); Tue, 12 Jan 2021 14:43:56 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14AEFC061386 for ; Tue, 12 Jan 2021 11:42:15 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id 91so3740826wrj.7 for ; Tue, 12 Jan 2021 11:42:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vbacyc4brsO7fCWWmN34VX2kLRLEZOENYLDCsoU/LjI=; b=frDPSNM1J/dOImSb6yTvFEc5DFfgGXbEaLLgKaM0mONN1LJTeaMDvsD7N43EhUuKwM OzKSpdv9zyp8xkewtP83v/WGTWyMClGmamwcnslMUaaz1lav+C2aXiTjba4BdOhqxWXs YOItPqRzhgs4NU2YffFSmcJDQxMpi6pdbU7itsTGkKpcxuOJWziSQooRJUBKdpBzUYxD xIoivLmBPS3zxn3DPlnmaHb6St45vGGHON4Tw0XUnv4jTlfHbt6WSZPGEcTHqdLKQA8A oh9+TRaqxpOgBEf5HrtBEHkkj3ACTaqZOa/BiIncvZJTrHDMblqXE+TF/HZ3Eh4T7R9X TU4w== 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=vbacyc4brsO7fCWWmN34VX2kLRLEZOENYLDCsoU/LjI=; b=oECAMdZWd4JM26Dyw87x4rPLrtNy9kK37Kjumb/y2nDNCPHkRNYXxPeQOHMCmeF+nF jwh+Kx/FKJKce9yaWJ0krhQFPeSmyt3RE6bguYze49Dk2quUhlZyZC54VdP0fTL7ipW5 hiCCwp5NwIuOqlNx1NwIkZGfEwwR/WKH9HtA2R9dkRLu6SIPkJ8OUXaY2GIOBL7Dh47g 0d3gJRqpqW3w11h2xTYHN0diC0Yf4NsWqvR87qbakQkRCGwpD5uSDEpCRTYcbTpIdYUo g2x49w8CGP7QNTUT5apzx4PKYhQcx13/PaKYawYPkVAIJyIr6KALcyVt5X52O8pWQahw OP6A== X-Gm-Message-State: AOAM532A2oJD3IG9lDOMBU2qLXfp/Nuo5RbfMPSopdBXAAq7zMriHFDQ YCchd6hp/sC0sS8VE+jac4KmAw== X-Google-Smtp-Source: ABdhPJzR2K4OZsCoyd0N4J9iZegxzvR23ddSEOzUWZ1flur5F4V7qRoMhDvf+/K03T/6v7gHKGCucw== X-Received: by 2002:adf:df08:: with SMTP id y8mr431800wrl.278.1610480533859; Tue, 12 Jan 2021 11:42:13 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.42.10 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:13 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 6/7] tun: populate hash in virtio-net header when needed Date: Tue, 12 Jan 2021 21:41:42 +0200 Message-Id: <20210112194143.1494-7-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC If the BPF program populated the hash in the skb the tun propagates the hash value and hash report type to the respective fields of virtio-net header. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 45f4f04a4a3e..214feb0b16fb 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -556,15 +556,20 @@ static u16 tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb) { struct tun_prog *prog; u32 numqueues; - u16 ret = 0; + u32 ret = 0; numqueues = READ_ONCE(tun->numqueues); if (!numqueues) return 0; prog = rcu_dereference(tun->steering_prog); - if (prog) + if (prog) { ret = bpf_prog_run_clear_cb(prog->prog, skb); + if (tun->bpf_populates_hash) { + *skb_hash_report_type(skb) = (__u8)(ret >> 16); + ret &= 0xffff; + } + } return ret % numqueues; } @@ -2062,6 +2067,7 @@ static ssize_t tun_put_user(struct tun_struct *tun, if (vnet_hdr_sz) { struct virtio_net_hdr gso; + __u16 extra_copy = 0; if (iov_iter_count(iter) < vnet_hdr_sz) return -EINVAL; @@ -2085,7 +2091,20 @@ static ssize_t tun_put_user(struct tun_struct *tun, if (copy_to_iter(&gso, sizeof(gso), iter) != sizeof(gso)) return -EFAULT; - iov_iter_advance(iter, vnet_hdr_sz - sizeof(gso)); + if (tun->bpf_populates_hash && + vnet_hdr_sz >= sizeof(struct virtio_net_hdr_v1_hash)) { + struct virtio_net_hdr_v1_hash hdr; + + hdr.hdr.num_buffers = 0; + hdr.hash_value = cpu_to_le32(skb_get_hash(skb)); + hdr.hash_report = cpu_to_le16(*skb_hash_report_type(skb)); + hdr.padding = 0; + extra_copy = sizeof(hdr) - sizeof(gso); + if (copy_to_iter(&hdr.hdr.num_buffers, extra_copy, iter) != extra_copy) + return -EFAULT; + } + + iov_iter_advance(iter, vnet_hdr_sz - sizeof(gso) - extra_copy); } if (vlan_hlen) { From patchwork Tue Jan 12 19:41:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuri Benditovich X-Patchwork-Id: 12014733 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FC94C432C3 for ; Tue, 12 Jan 2021 19:43:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 01DE22310E for ; Tue, 12 Jan 2021 19:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436775AbhALTne (ORCPT ); Tue, 12 Jan 2021 14:43:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436746AbhALTnc (ORCPT ); Tue, 12 Jan 2021 14:43:32 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B325C061389 for ; Tue, 12 Jan 2021 11:42:18 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id d26so3713457wrb.12 for ; Tue, 12 Jan 2021 11:42:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vUG4KrkwS/48VCqb3gPEYEavBv7WJyPV6SrQz/KaLAM=; b=xXVp4dUFwGopoDHrk5N2q6tlpNzp6UcAVfATe6wqsrEI6AsT8zMquFk3s5PrenaRNS HsXPG8kYC0iqaJhsbWLQQVLvJzZ9fyG5MMwDHgKfhYHzVUADW8tULfPsAXPKdSzmExXs xGkgY8UjXhz4pr/tWYY6LIg0OPuFo4/wilerVoD5vOLJ7+xE3zVBI8l4tgeDUNGcSQS2 w9lpFADgtL5YNaNmRW34ldPIRi8yBgvDVWpenxM8ASJiWwqp+czbRrxXsd0c45UYufcX ORCyuOBerYo0JFSjBUJNikFQv/KEcc3YsnoAYO8aGPrCVo2pExXlWpwTZijTWq2Ccxf6 uguA== 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=vUG4KrkwS/48VCqb3gPEYEavBv7WJyPV6SrQz/KaLAM=; b=MSdebTbyDGtZCwGVmTqlrghjKZkudoKxu07JqWPYy1y60Ht89bhA8F9VFAcSx0ZgIj sIHrjPQZWmg4XrIzRpaAsSLmGD6Bb3/I38RdLhpxAfIwsaVd9aDyxCk8wXGPMp3t3v8V JMQzsSk+n7l36jbv6lDu23NuYmTnTFjEBUA+elcZOzUBGhXRydBN1XA0993rXgbAICwx TBMcVq747JYgUELrxC4P/TYa65tPVLT3qIoWmSqxSnaXAdSLtmmiio3NEry8f08Js9rz jYrMmItJQkpOLcLwOGNcRHyWJFwwf5YU12qw4czMk2yQIXGan3GuP4QtN+EBN/faKwkD 7/5A== X-Gm-Message-State: AOAM532pPiTAXxt+rBxjdjiRE1oHPLb4/AGyGRKbJxbYrCiWDoPW9VOM pjjexRiOoplF7mzk2BwOefHdRA== X-Google-Smtp-Source: ABdhPJzCa62kAiSj5dwvAhD+eWjgsemDiqG4ohfKFPsazH9lExZh5CateUK1KDaOpknKxeSQxHaBJA== X-Received: by 2002:a5d:69c2:: with SMTP id s2mr454259wrw.36.1610480536897; Tue, 12 Jan 2021 11:42:16 -0800 (PST) Received: from f2.redhat.com (bzq-79-183-72-147.red.bezeqint.net. [79.183.72.147]) by smtp.gmail.com with ESMTPSA id z63sm4885315wme.8.2021.01.12.11.42.13 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Jan 2021 11:42:16 -0800 (PST) From: Yuri Benditovich To: davem@davemloft.net, kuba@kernel.org, mst@redhat.com, jasowang@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, rdunlap@infradead.org, willemb@google.com, gustavoars@kernel.org, herbert@gondor.apana.org.au, steffen.klassert@secunet.com, nogikh@google.com, pablo@netfilter.org, decui@microsoft.com, cai@lca.pw, jakub@cloudflare.com, elver@google.com, pabeni@redhat.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf@vger.kernel.org Cc: yan@daynix.com Subject: [RFC PATCH 7/7] tun: report new tun feature IFF_HASH Date: Tue, 12 Jan 2021 21:41:43 +0200 Message-Id: <20210112194143.1494-8-yuri.benditovich@daynix.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210112194143.1494-1-yuri.benditovich@daynix.com> References: <20210112194143.1494-1-yuri.benditovich@daynix.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC IFF_HASH feature indicates that the tun supports TUNSETHASHPOPULATION ioctl and can propagate the hash data to the virtio-net packet. Signed-off-by: Yuri Benditovich --- drivers/net/tun.c | 2 +- include/uapi/linux/if_tun.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 214feb0b16fb..b46aa8941a9d 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -88,7 +88,7 @@ static void tun_default_link_ksettings(struct net_device *dev, #define TUN_VNET_LE 0x80000000 #define TUN_VNET_BE 0x40000000 -#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \ +#define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | IFF_HASH |\ IFF_MULTI_QUEUE | IFF_NAPI | IFF_NAPI_FRAGS) #define GOODCOPY_LEN 128 diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h index 0fd43533da26..116b84ede3a0 100644 --- a/include/uapi/linux/if_tun.h +++ b/include/uapi/linux/if_tun.h @@ -73,6 +73,7 @@ #define IFF_ONE_QUEUE 0x2000 #define IFF_VNET_HDR 0x4000 #define IFF_TUN_EXCL 0x8000 +#define IFF_HASH 0x0080 #define IFF_MULTI_QUEUE 0x0100 #define IFF_ATTACH_QUEUE 0x0200 #define IFF_DETACH_QUEUE 0x0400