get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/810304/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 810304,
    "url": "http://patchwork.ozlabs.org/api/patches/810304/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/20170905223551.27925-3-ppenkov@google.com/",
    "project": {
        "id": 7,
        "url": "http://patchwork.ozlabs.org/api/projects/7/?format=api",
        "name": "Linux network development",
        "link_name": "netdev",
        "list_id": "netdev.vger.kernel.org",
        "list_email": "netdev@vger.kernel.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20170905223551.27925-3-ppenkov@google.com>",
    "list_archive_url": null,
    "date": "2017-09-05T22:35:51",
    "name": "[net-next,RFC,2/2] tun: enable napi_gro_frags() for TUN/TAP driver",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": true,
    "hash": "267a09336f4b3f65976a1a528f1a5584d5aac46f",
    "submitter": {
        "id": 72299,
        "url": "http://patchwork.ozlabs.org/api/people/72299/?format=api",
        "name": "Petar Penkov",
        "email": "ppenkov@google.com"
    },
    "delegate": {
        "id": 34,
        "url": "http://patchwork.ozlabs.org/api/users/34/?format=api",
        "username": "davem",
        "first_name": "David",
        "last_name": "Miller",
        "email": "davem@davemloft.net"
    },
    "mbox": "http://patchwork.ozlabs.org/project/netdev/patch/20170905223551.27925-3-ppenkov@google.com/mbox/",
    "series": [
        {
            "id": 1659,
            "url": "http://patchwork.ozlabs.org/api/series/1659/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/netdev/list/?series=1659",
            "date": "2017-09-05T22:35:50",
            "name": "Improve code coverage of syzkaller",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/1659/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/810304/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/810304/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<netdev-owner@vger.kernel.org>",
        "X-Original-To": "patchwork-incoming@ozlabs.org",
        "Delivered-To": "patchwork-incoming@ozlabs.org",
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=google.com header.i=@google.com\n\theader.b=\"NrcdK0ks\"; dkim-atps=neutral"
        ],
        "Received": [
            "from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xn1mD3j1Zz9sP3\n\tfor <patchwork-incoming@ozlabs.org>;\n\tWed,  6 Sep 2017 08:36:44 +1000 (AEST)",
            "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1754401AbdIEWgm (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tTue, 5 Sep 2017 18:36:42 -0400",
            "from mail-pf0-f173.google.com ([209.85.192.173]:34580 \"EHLO\n\tmail-pf0-f173.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1754335AbdIEWgh (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Tue, 5 Sep 2017 18:36:37 -0400",
            "by mail-pf0-f173.google.com with SMTP id m1so9953089pfk.1\n\tfor <netdev@vger.kernel.org>; Tue, 05 Sep 2017 15:36:37 -0700 (PDT)",
            "from localhost ([2620:15c:2cb:1:183d:cea1:ba48:3c2f])\n\tby smtp.gmail.com with ESMTPSA id\n\tm24sm27655pfj.28.2017.09.05.15.36.35\n\t(version=TLS1_2 cipher=AES128-SHA bits=128/128);\n\tTue, 05 Sep 2017 15:36:35 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=google.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=82UhMC7nimQhrlrTSNW/yf4qr6rwnYlY1kKyl9O0znE=;\n\tb=NrcdK0ksfFR3gJclk72JdGXBy2LW7jSQjgIf8rCdQJ3qYPyFBz0vU9yyaBemNhANh7\n\tZQj6djnvOglkXV52kG8U7SRhGFCt6RwlAkxxAtEuIsjgMPiprtZaciH97AuuvhJkdfbw\n\tiob5x+yd3v00+YBbm45XLwJ1yvb5ga5HT0S+EbHtnuQJ2nGLKj8YXr4/cvdi/b+DRA9W\n\toamRjzs7MSEZX4l8rXOdKw+Kf4e3BnEqjzFqtpVhXLD3XCS4UwTRjYBU/96uX04vVbUt\n\tPp9GqdZd1r64f5Qz4TTNidCIiw9ol/x4GwI1bSqs8WkEKLvhqUX5kZDJ7RznWner654B\n\tOEAg==",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=82UhMC7nimQhrlrTSNW/yf4qr6rwnYlY1kKyl9O0znE=;\n\tb=q0tO8bo+ENHkyRM7pTX27dLirp+fmVCUu5l1ulrFo2FJNnv5pvMyrVyEXBTewuwTUP\n\t8qmO7/aG2hzXl2UNE7OpBb9p4FwADNxCsphOa2dMLPJ95Zac5ke2GG8OxyOihCgy5qLG\n\tsc1j/LvihYhv96ROTeM8MQFoKlNkQN6kaHWm8zK4nfLuwtTRkGUiaW7O4hp+EQaTbnVB\n\tYXL5ULKDni3KWeyqf0nz75h4Ns+VD1rxsiuPgk2/A8K50EGmBL6h9zl+f1Xw1EHClxk/\n\tPD/JiCAC4h0lyXh4GmdowOhG8l2wsWQ2uM8wXn69svVnpH+FGPAM/YhwypvLVRJzG09X\n\t46EA==",
        "X-Gm-Message-State": "AHPjjUicMQ5QF/c7FHaZJy0qsCUocTaWtgo2A1qcDK2Ro6PcHsuLbh/t\n\tcJBKtJgiIhChq++SIJirymZt",
        "X-Google-Smtp-Source": "ADKCNb6AxgnIYQ3LvnUagFGFRT4Ovw9O9tSqM1l/Bm+7iXvtKupVA9Hh8WgMR9jNBVmaDafqKh/fmA==",
        "X-Received": "by 10.99.7.205 with SMTP id 196mr5541096pgh.356.1504650995771;\n\tTue, 05 Sep 2017 15:36:35 -0700 (PDT)",
        "From": "Petar Penkov <ppenkov@google.com>",
        "To": "netdev@vger.kernel.org",
        "Cc": "Petar Penkov <ppenkov@google.com>, Eric Dumazet <edumazet@google.com>,\n\tMahesh Bandewar <maheshb@google.com>,\n\tWillem de Bruijn <willemb@google.com>, davem@davemloft.net,\n\tppenkov@stanford.edu",
        "Subject": "[PATCH net-next RFC 2/2] tun: enable napi_gro_frags() for TUN/TAP\n\tdriver",
        "Date": "Tue,  5 Sep 2017 15:35:51 -0700",
        "Message-Id": "<20170905223551.27925-3-ppenkov@google.com>",
        "X-Mailer": "git-send-email 2.14.1.581.gf28d330327-goog",
        "In-Reply-To": "<20170905223551.27925-1-ppenkov@google.com>",
        "References": "<20170905223551.27925-1-ppenkov@google.com>",
        "Sender": "netdev-owner@vger.kernel.org",
        "Precedence": "bulk",
        "List-ID": "<netdev.vger.kernel.org>",
        "X-Mailing-List": "netdev@vger.kernel.org"
    },
    "content": "Add a TUN/TAP receive mode that exercises the napi_gro_frags()\ninterface. This mode is available only in TAP mode, as the interface\nexpects packets with Ethernet headers.\n\nFurthermore, packets follow the layout of the iovec_iter that was\nreceived. The first iovec is the linear data, and every one after the\nfirst is a fragment. If there are more fragments than the max number,\ndrop the packet. Additionally, invoke eth_get_headlen() to exercise flow\ndissector code and to verify that the header resides in the linear data.\n\nThe napi_gro_frags() mode requires setting the IFF_NAPI_FRAGS option.\nThis is imposed because this mode is intended for testing via tools like\nsyzkaller and packetdrill, and the increased flexibility it provides can\nintroduce security vulnerabilities.\n\nSigned-off-by: Petar Penkov <ppenkov@google.com>\nCc: Eric Dumazet <edumazet@google.com>\nCc: Mahesh Bandewar <maheshb@google.com>\nCc: Willem de Bruijn <willemb@google.com>\nCc: davem@davemloft.net\nCc: ppenkov@stanford.edu\n---\n drivers/net/tun.c           | 135 ++++++++++++++++++++++++++++++++++++++++++--\n include/uapi/linux/if_tun.h |   1 +\n 2 files changed, 130 insertions(+), 6 deletions(-)",
    "diff": "diff --git a/drivers/net/tun.c b/drivers/net/tun.c\nindex d5c824e3ec42..2ba9809ab6cd 100644\n--- a/drivers/net/tun.c\n+++ b/drivers/net/tun.c\n@@ -75,6 +75,7 @@\n #include <linux/skb_array.h>\n #include <linux/bpf.h>\n #include <linux/bpf_trace.h>\n+#include <linux/mutex.h>\n \n #include <linux/uaccess.h>\n \n@@ -120,8 +121,15 @@ do {\t\t\t\t\t\t\t\t\\\n #define TUN_VNET_LE     0x80000000\n #define TUN_VNET_BE     0x40000000\n \n+#if IS_ENABLED(CONFIG_TUN_NAPI)\n+#define TUN_FEATURES_EXTRA IFF_NAPI_FRAGS\n+#else\n+#define TUN_FEATURES_EXTRA 0\n+#endif\n+\n #define TUN_FEATURES (IFF_NO_PI | IFF_ONE_QUEUE | IFF_VNET_HDR | \\\n-\t\t      IFF_MULTI_QUEUE)\n+\t\t      IFF_MULTI_QUEUE | TUN_FEATURES_EXTRA)\n+\n #define GOODCOPY_LEN 128\n \n #define FLT_EXACT_COUNT 8\n@@ -173,6 +181,7 @@ struct tun_file {\n \t\tunsigned int ifindex;\n \t};\n \tstruct napi_struct napi;\n+\tstruct mutex napi_mutex;\t/* Protects access to the above napi */\n \tstruct list_head next;\n \tstruct tun_struct *detached;\n \tstruct skb_array tx_array;\n@@ -276,6 +285,7 @@ static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile)\n \t\tnetif_napi_add(tun->dev, &tfile->napi, tun_napi_poll,\n \t\t\t       NAPI_POLL_WEIGHT);\n \t\tnapi_enable(&tfile->napi);\n+\t\tmutex_init(&tfile->napi_mutex);\n \t}\n }\n \n@@ -291,6 +301,11 @@ static void tun_napi_del(struct tun_file *tfile)\n \t\tnetif_napi_del(&tfile->napi);\n }\n \n+static bool tun_napi_frags_enabled(const struct tun_struct *tun)\n+{\n+\treturn READ_ONCE(tun->flags) & IFF_NAPI_FRAGS;\n+}\n+\n #ifdef CONFIG_TUN_VNET_CROSS_LE\n static inline bool tun_legacy_is_little_endian(struct tun_struct *tun)\n {\n@@ -1034,7 +1049,8 @@ static void tun_poll_controller(struct net_device *dev)\n \t * supports polling, which enables bridge devices in virt setups to\n \t * still use netconsole\n \t * If NAPI is enabled, however, we need to schedule polling for all\n-\t * queues.\n+\t * queues unless we are using napi_gro_frags(), which we call in\n+\t * process context and not in NAPI context.\n \t */\n \n \tif (IS_ENABLED(CONFIG_TUN_NAPI)) {\n@@ -1042,6 +1058,9 @@ static void tun_poll_controller(struct net_device *dev)\n \t\tstruct tun_file *tfile;\n \t\tint i;\n \n+\t\tif (tun_napi_frags_enabled(tun))\n+\t\t\treturn;\n+\n \t\trcu_read_lock();\n \t\tfor (i = 0; i < tun->numqueues; i++) {\n \t\t\ttfile = rcu_dereference(tun->tfiles[i]);\n@@ -1264,6 +1283,64 @@ static unsigned int tun_chr_poll(struct file *file, poll_table *wait)\n \treturn mask;\n }\n \n+static struct sk_buff *tun_napi_alloc_frags(struct tun_file *tfile,\n+\t\t\t\t\t    size_t len,\n+\t\t\t\t\t    const struct iov_iter *it)\n+{\n+\tstruct sk_buff *skb;\n+\tsize_t linear;\n+\tint err;\n+\tint i;\n+\n+\tif (it->nr_segs > MAX_SKB_FRAGS + 1)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tlocal_bh_disable();\n+\tskb = napi_get_frags(&tfile->napi);\n+\tlocal_bh_enable();\n+\tif (!skb)\n+\t\treturn ERR_PTR(-ENOMEM);\n+\n+\tlinear = iov_iter_single_seg_count(it);\n+\terr = __skb_grow(skb, linear);\n+\tif (err)\n+\t\tgoto free;\n+\n+\tskb->len = len;\n+\tskb->data_len = len - linear;\n+\tskb->truesize += skb->data_len;\n+\n+\tfor (i = 1; i < it->nr_segs; i++) {\n+\t\tsize_t fragsz = it->iov[i].iov_len;\n+\t\tunsigned long offset;\n+\t\tstruct page *page;\n+\t\tvoid *data;\n+\n+\t\tif (fragsz == 0 || fragsz > PAGE_SIZE) {\n+\t\t\terr = -EINVAL;\n+\t\t\tgoto free;\n+\t\t}\n+\n+\t\tlocal_bh_disable();\n+\t\tdata = napi_alloc_frag(fragsz);\n+\t\tlocal_bh_enable();\n+\t\tif (!data) {\n+\t\t\terr = -ENOMEM;\n+\t\t\tgoto free;\n+\t\t}\n+\n+\t\tpage = virt_to_page(data);\n+\t\toffset = offset_in_page(data);\n+\t\tskb_fill_page_desc(skb, i - 1, page, offset, fragsz);\n+\t}\n+\n+\treturn skb;\n+free:\n+\t/* frees skb and all frags allocated with napi_alloc_frag() */\n+\tnapi_free_frags(&tfile->napi);\n+\treturn ERR_PTR(err);\n+}\n+\n /* prepad is the amount to reserve at front.  len is length after that.\n  * linear is a hint as to how much to copy (usually headers). */\n static struct sk_buff *tun_alloc_skb(struct tun_file *tfile,\n@@ -1466,6 +1543,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \tint err;\n \tu32 rxhash;\n \tint generic_xdp = 1;\n+\tbool frags = tun_napi_frags_enabled(tun);\n \n \tif (!(tun->dev->flags & IFF_UP))\n \t\treturn -EIO;\n@@ -1523,7 +1601,7 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\t\tzerocopy = true;\n \t}\n \n-\tif (tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {\n+\tif (!frags && tun_can_build_skb(tun, tfile, len, noblock, zerocopy)) {\n \t\tskb = tun_build_skb(tun, tfile, from, &gso, len, &generic_xdp);\n \t\tif (IS_ERR(skb)) {\n \t\t\tthis_cpu_inc(tun->pcpu_stats->rx_dropped);\n@@ -1540,10 +1618,24 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\t\t\tlinear = tun16_to_cpu(tun, gso.hdr_len);\n \t\t}\n \n-\t\tskb = tun_alloc_skb(tfile, align, copylen, linear, noblock);\n+\t\tif (frags) {\n+\t\t\tmutex_lock(&tfile->napi_mutex);\n+\t\t\tskb = tun_napi_alloc_frags(tfile, copylen, from);\n+\t\t\t/* tun_napi_alloc_frags() enforces a layout for the skb.\n+\t\t\t * If zerocopy is enabled, then this layout will be\n+\t\t\t * overwritten by zerocopy_sg_from_iter().\n+\t\t\t */\n+\t\t\tzerocopy = false;\n+\t\t} else {\n+\t\t\tskb = tun_alloc_skb(tfile, align, copylen, linear,\n+\t\t\t\t\t    noblock);\n+\t\t}\n+\n \t\tif (IS_ERR(skb)) {\n \t\t\tif (PTR_ERR(skb) != -EAGAIN)\n \t\t\t\tthis_cpu_inc(tun->pcpu_stats->rx_dropped);\n+\t\t\tif (frags)\n+\t\t\t\tmutex_unlock(&tfile->napi_mutex);\n \t\t\treturn PTR_ERR(skb);\n \t\t}\n \n@@ -1555,6 +1647,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\tif (err) {\n \t\t\tthis_cpu_inc(tun->pcpu_stats->rx_dropped);\n \t\t\tkfree_skb(skb);\n+\t\t\tif (frags) {\n+\t\t\t\ttfile->napi.skb = NULL;\n+\t\t\t\tmutex_unlock(&tfile->napi_mutex);\n+\t\t\t}\n+\n \t\t\treturn -EFAULT;\n \t\t}\n \t}\n@@ -1562,6 +1659,11 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \tif (virtio_net_hdr_to_skb(skb, &gso, tun_is_little_endian(tun))) {\n \t\tthis_cpu_inc(tun->pcpu_stats->rx_frame_errors);\n \t\tkfree_skb(skb);\n+\t\tif (frags) {\n+\t\t\ttfile->napi.skb = NULL;\n+\t\t\tmutex_unlock(&tfile->napi_mutex);\n+\t\t}\n+\n \t\treturn -EINVAL;\n \t}\n \n@@ -1587,7 +1689,8 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t\tskb->dev = tun->dev;\n \t\tbreak;\n \tcase IFF_TAP:\n-\t\tskb->protocol = eth_type_trans(skb, tun->dev);\n+\t\tif (!frags)\n+\t\t\tskb->protocol = eth_type_trans(skb, tun->dev);\n \t\tbreak;\n \t}\n \n@@ -1622,7 +1725,23 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \n \trxhash = __skb_get_hash_symmetric(skb);\n \n-\tif (IS_ENABLED(CONFIG_TUN_NAPI)) {\n+\tif (frags) {\n+\t\t/* Exercise flow dissector code path. */\n+\t\tu32 headlen = eth_get_headlen(skb->data, skb_headlen(skb));\n+\n+\t\tif (headlen > skb_headlen(skb) || headlen < ETH_HLEN) {\n+\t\t\tthis_cpu_inc(tun->pcpu_stats->rx_dropped);\n+\t\t\tnapi_free_frags(&tfile->napi);\n+\t\t\tmutex_unlock(&tfile->napi_mutex);\n+\t\t\tWARN_ON(1);\n+\t\t\treturn -ENOMEM;\n+\t\t}\n+\n+\t\tlocal_bh_disable();\n+\t\tnapi_gro_frags(&tfile->napi);\n+\t\tlocal_bh_enable();\n+\t\tmutex_unlock(&tfile->napi_mutex);\n+\t} else if (IS_ENABLED(CONFIG_TUN_NAPI)) {\n \t\tstruct sk_buff_head *queue = &tfile->sk.sk_write_queue;\n \t\tint queue_len;\n \n@@ -2168,6 +2287,10 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)\n \ttun->flags = (tun->flags & ~TUN_FEATURES) |\n \t\t(ifr->ifr_flags & TUN_FEATURES);\n \n+\tif (!IS_ENABLED(CONFIG_TUN_NAPI) ||\n+\t    (tun->flags & TUN_TYPE_MASK) != IFF_TAP)\n+\t\ttun->flags = tun->flags & ~IFF_NAPI_FRAGS;\n+\n \t/* Make sure persistent devices do not get stuck in\n \t * xoff state.\n \t */\ndiff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h\nindex 3cb5e1d85ddd..1eb1eb42f151 100644\n--- a/include/uapi/linux/if_tun.h\n+++ b/include/uapi/linux/if_tun.h\n@@ -60,6 +60,7 @@\n /* TUNSETIFF ifr flags */\n #define IFF_TUN\t\t0x0001\n #define IFF_TAP\t\t0x0002\n+#define IFF_NAPI_FRAGS\t0x0010\n #define IFF_NO_PI\t0x1000\n /* This flag has no real effect */\n #define IFF_ONE_QUEUE\t0x2000\n",
    "prefixes": [
        "net-next",
        "RFC",
        "2/2"
    ]
}