get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 817288,
    "url": "http://patchwork.ozlabs.org/api/patches/817288/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/20170922021715.2618-2-peterpenkov96@gmail.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": "<20170922021715.2618-2-peterpenkov96@gmail.com>",
    "list_archive_url": null,
    "date": "2017-09-22T02:17:14",
    "name": "[v2,net-next,1/2] tun: enable NAPI for TUN/TAP driver",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "dd5f964b2958a567222cc4733174d53ab6694fa0",
    "submitter": {
        "id": 72387,
        "url": "http://patchwork.ozlabs.org/api/people/72387/?format=api",
        "name": "Petar Penkov",
        "email": "peterpenkov96@gmail.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/20170922021715.2618-2-peterpenkov96@gmail.com/mbox/",
    "series": [
        {
            "id": 4526,
            "url": "http://patchwork.ozlabs.org/api/series/4526/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/netdev/list/?series=4526",
            "date": "2017-09-22T02:17:13",
            "name": "Improve code coverage of syzkaller",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/4526/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/817288/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/817288/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=gmail.com header.i=@gmail.com\n\theader.b=\"LaC0iRW9\"; dkim-atps=neutral"
        ],
        "Received": [
            "from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyxvY4kQcz9t33\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri, 22 Sep 2017 12:17:29 +1000 (AEST)",
            "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751823AbdIVCRZ (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tThu, 21 Sep 2017 22:17:25 -0400",
            "from mail-pf0-f193.google.com ([209.85.192.193]:35473 \"EHLO\n\tmail-pf0-f193.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751653AbdIVCRX (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Thu, 21 Sep 2017 22:17:23 -0400",
            "by mail-pf0-f193.google.com with SMTP id i23so3189973pfi.2\n\tfor <netdev@vger.kernel.org>; Thu, 21 Sep 2017 19:17:22 -0700 (PDT)",
            "from petey-VirtualBox ([128.12.253.5])\n\tby smtp.gmail.com with ESMTPSA id\n\to128sm4545166pga.5.2017.09.21.19.17.22\n\t(version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tThu, 21 Sep 2017 19:17:22 -0700 (PDT)"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=YFgVe40GqDaE2SI2VvUwTRbfNXrY93kKkG9kn7tGZHg=;\n\tb=LaC0iRW9mi7OPgDEWK6dT3YymbCqMe/9b8CmNjpQw0myZtaKTYCgLmB2+t42VAa/YH\n\t9l96MLwHTpFzdldO13q7qTicVQp5uqx0nBvuheccEqffR/vutbUovc9SujCWbHRHiEOp\n\tKf5OIyYpLwSvOZvD/Rr/88VAjvLBYNFG0MaFoxrIT+gO9JzR+aD8Nn9xVqRQdcWUCwpB\n\tSHzv/L+unE/TDJpKl3Te8bbJ2hz52KUnu6DgkCXz8PAxgaPhW+InyrWKGsJ6oGOvlPO6\n\tUAAplIAcoaknvPxxU9v2d2spxZhPSyQpJA9kItv8SkiGlThZ1UoRnSwXq8HEnhPrpfrk\n\t8IwA==",
        "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=YFgVe40GqDaE2SI2VvUwTRbfNXrY93kKkG9kn7tGZHg=;\n\tb=mkqlhfyuQCTTQv/Qzbiz3iti8SZ9ZHH5mysUj/B2l76ZZi81fXNltH16pJY8Berhvc\n\toSUTQ5b6fen4PPWAD90a61HHr8iZNtDOAuVlR7KTeThqG0ESY00HJeQPy2ym+aMNS2Pp\n\tbqMluWtvh5P3AmEIwl8JrvLRgthuig6yZ0VzzOYwQFXUhVly8PDwgDi668eDFoVXSgKj\n\t7HrtCgLmmRk+yD1ExEpcn21pX2SNeVfuz7sxT5flqjpz9RYwNkqaWL7ATh3bj2tS6eeu\n\tD72N5tQDOVsfeuJBfug3G1/S9xIuX2ZUQjESOQj2oribwi7e6H7KCOcfpV2Q+QSVCHE/\n\tOosg==",
        "X-Gm-Message-State": "AHPjjUg7wPdrSXAh1JxrCSbhEdNvAz9M2uRyVGchumA6iBKlSUZVVvVs\n\tCzKS5ayLNRTP0b+gEKKKDrc=",
        "X-Google-Smtp-Source": "AOwi7QBxsFD1fsk+hIGvt2lujAHQ6jTtY/jWusRaYXe41+erqxrXnx0Edo8hwJi846ZH2d8TWQiShA==",
        "X-Received": "by 10.99.142.196 with SMTP id k187mr8008502pge.14.1506046642600; \n\tThu, 21 Sep 2017 19:17:22 -0700 (PDT)",
        "From": "Petar Penkov <peterpenkov96@gmail.com>",
        "To": "netdev@vger.kernel.org",
        "Cc": "Petar Penkov <peterpenkov96@gmail.com>,\n\tEric Dumazet <edumazet@google.com>, Mahesh Bandewar <maheshb@google.com>,\n\tWillem de Bruijn <willemb@google.com>, davem@davemloft.net,\n\tppenkov@stanford.edu",
        "Subject": "[PATCH,v2,net-next 1/2] tun: enable NAPI for TUN/TAP driver",
        "Date": "Thu, 21 Sep 2017 19:17:14 -0700",
        "Message-Id": "<20170922021715.2618-2-peterpenkov96@gmail.com>",
        "X-Mailer": "git-send-email 2.11.0",
        "In-Reply-To": "<20170922021715.2618-1-peterpenkov96@gmail.com>",
        "References": "<20170922021715.2618-1-peterpenkov96@gmail.com>",
        "Sender": "netdev-owner@vger.kernel.org",
        "Precedence": "bulk",
        "List-ID": "<netdev.vger.kernel.org>",
        "X-Mailing-List": "netdev@vger.kernel.org"
    },
    "content": "Changes TUN driver to use napi_gro_receive() upon receiving packets\nrather than netif_rx_ni(). Adds flag IFF_NAPI that enables these\nchanges and operation is not affected if the flag is disabled.  SKBs\nare constructed upon packet arrival and are queued to be processed\nlater.\n\nThe new path was evaluated with a benchmark with the following setup:\nOpen two tap devices and a receiver thread that reads in a loop for\neach device. Start one sender thread and pin all threads to different\nCPUs. Send 1M minimum UDP packets to each device and measure sending\ntime for each of the sending methods:\n\tnapi_gro_receive():\t4.90s\n\tnetif_rx_ni():\t\t4.90s\n\tnetif_receive_skb():\t7.20s\n\nSigned-off-by: Petar Penkov <peterpenkov96@gmail.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           | 133 +++++++++++++++++++++++++++++++++++++++-----\n include/uapi/linux/if_tun.h |   1 +\n 2 files changed, 119 insertions(+), 15 deletions(-)",
    "diff": "diff --git a/drivers/net/tun.c b/drivers/net/tun.c\nindex 3c9985f29950..f16407242b18 100644\n--- a/drivers/net/tun.c\n+++ b/drivers/net/tun.c\n@@ -121,7 +121,7 @@ do {\t\t\t\t\t\t\t\t\\\n #define TUN_VNET_BE     0x40000000\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 | IFF_NAPI)\n #define GOODCOPY_LEN 128\n \n #define FLT_EXACT_COUNT 8\n@@ -172,6 +172,7 @@ struct tun_file {\n \t\tu16 queue_index;\n \t\tunsigned int ifindex;\n \t};\n+\tstruct napi_struct napi;\n \tstruct list_head next;\n \tstruct tun_struct *detached;\n \tstruct skb_array tx_array;\n@@ -229,6 +230,68 @@ struct tun_struct {\n \tstruct bpf_prog __rcu *xdp_prog;\n };\n \n+static int tun_napi_receive(struct napi_struct *napi, int budget)\n+{\n+\tstruct tun_file *tfile = container_of(napi, struct tun_file, napi);\n+\tstruct sk_buff_head *queue = &tfile->sk.sk_write_queue;\n+\tstruct sk_buff_head process_queue;\n+\tstruct sk_buff *skb;\n+\tint received = 0;\n+\n+\t__skb_queue_head_init(&process_queue);\n+\n+\tspin_lock(&queue->lock);\n+\tskb_queue_splice_tail_init(queue, &process_queue);\n+\tspin_unlock(&queue->lock);\n+\n+\twhile (received < budget && (skb = __skb_dequeue(&process_queue))) {\n+\t\tnapi_gro_receive(napi, skb);\n+\t\t++received;\n+\t}\n+\n+\tif (!skb_queue_empty(&process_queue)) {\n+\t\tspin_lock(&queue->lock);\n+\t\tskb_queue_splice(&process_queue, queue);\n+\t\tspin_unlock(&queue->lock);\n+\t}\n+\n+\treturn received;\n+}\n+\n+static int tun_napi_poll(struct napi_struct *napi, int budget)\n+{\n+\tunsigned int received;\n+\n+\treceived = tun_napi_receive(napi, budget);\n+\n+\tif (received < budget)\n+\t\tnapi_complete_done(napi, received);\n+\n+\treturn received;\n+}\n+\n+static void tun_napi_init(struct tun_struct *tun, struct tun_file *tfile,\n+\t\t\t  bool napi_en)\n+{\n+\tif (napi_en) {\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}\n+}\n+\n+static void tun_napi_disable(struct tun_struct *tun, struct tun_file *tfile)\n+{\n+\tif (tun->flags & IFF_NAPI)\n+\t\tnapi_disable(&tfile->napi);\n+}\n+\n+static void tun_napi_del(struct tun_struct *tun, struct tun_file *tfile)\n+{\n+\tif (tun->flags & IFF_NAPI)\n+\t\tnetif_napi_del(&tfile->napi);\n+}\n+\n #ifdef CONFIG_TUN_VNET_CROSS_LE\n static inline bool tun_legacy_is_little_endian(struct tun_struct *tun)\n {\n@@ -541,6 +604,11 @@ static void __tun_detach(struct tun_file *tfile, bool clean)\n \n \ttun = rtnl_dereference(tfile->tun);\n \n+\tif (tun && clean) {\n+\t\ttun_napi_disable(tun, tfile);\n+\t\ttun_napi_del(tun, tfile);\n+\t}\n+\n \tif (tun && !tfile->detached) {\n \t\tu16 index = tfile->queue_index;\n \t\tBUG_ON(index >= tun->numqueues);\n@@ -598,6 +666,7 @@ static void tun_detach_all(struct net_device *dev)\n \tfor (i = 0; i < n; i++) {\n \t\ttfile = rtnl_dereference(tun->tfiles[i]);\n \t\tBUG_ON(!tfile);\n+\t\ttun_napi_disable(tun, tfile);\n \t\ttfile->socket.sk->sk_shutdown = RCV_SHUTDOWN;\n \t\ttfile->socket.sk->sk_data_ready(tfile->socket.sk);\n \t\tRCU_INIT_POINTER(tfile->tun, NULL);\n@@ -613,6 +682,7 @@ static void tun_detach_all(struct net_device *dev)\n \tsynchronize_net();\n \tfor (i = 0; i < n; i++) {\n \t\ttfile = rtnl_dereference(tun->tfiles[i]);\n+\t\ttun_napi_del(tun, tfile);\n \t\t/* Drop read queue */\n \t\ttun_queue_purge(tfile);\n \t\tsock_put(&tfile->sk);\n@@ -631,7 +701,8 @@ static void tun_detach_all(struct net_device *dev)\n \t\tmodule_put(THIS_MODULE);\n }\n \n-static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filter)\n+static int tun_attach(struct tun_struct *tun, struct file *file,\n+\t\t      bool skip_filter, bool napi)\n {\n \tstruct tun_file *tfile = file->private_data;\n \tstruct net_device *dev = tun->dev;\n@@ -677,10 +748,12 @@ static int tun_attach(struct tun_struct *tun, struct file *file, bool skip_filte\n \trcu_assign_pointer(tun->tfiles[tun->numqueues], tfile);\n \ttun->numqueues++;\n \n-\tif (tfile->detached)\n+\tif (tfile->detached) {\n \t\ttun_enable_queue(tfile);\n-\telse\n+\t} else {\n \t\tsock_hold(&tfile->sk);\n+\t\ttun_napi_init(tun, tfile, napi);\n+\t}\n \n \ttun_set_real_num_queues(tun);\n \n@@ -956,13 +1029,28 @@ static void tun_poll_controller(struct net_device *dev)\n \t * Tun only receives frames when:\n \t * 1) the char device endpoint gets data from user space\n \t * 2) the tun socket gets a sendmsg call from user space\n-\t * Since both of those are synchronous operations, we are guaranteed\n-\t * never to have pending data when we poll for it\n-\t * so there is nothing to do here but return.\n+\t * If NAPI is not enabled, since both of those are synchronous\n+\t * operations, we are guaranteed never to have pending data when we poll\n+\t * for it so there is nothing to do here but return.\n \t * We need this though so netpoll recognizes us as an interface that\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 */\n+\tstruct tun_struct *tun = netdev_priv(dev);\n+\n+\tif (tun->flags & IFF_NAPI) {\n+\t\tstruct tun_file *tfile;\n+\t\tint i;\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+\t\t\tnapi_schedule(&tfile->napi);\n+\t\t}\n+\t\trcu_read_unlock();\n+\t}\n \treturn;\n }\n #endif\n@@ -1549,11 +1637,25 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,\n \t}\n \n \trxhash = __skb_get_hash_symmetric(skb);\n-#ifndef CONFIG_4KSTACKS\n-\ttun_rx_batched(tun, tfile, skb, more);\n-#else\n-\tnetif_rx_ni(skb);\n-#endif\n+\n+\tif (tun->flags & IFF_NAPI) {\n+\t\tstruct sk_buff_head *queue = &tfile->sk.sk_write_queue;\n+\t\tint queue_len;\n+\n+\t\tspin_lock_bh(&queue->lock);\n+\t\t__skb_queue_tail(queue, skb);\n+\t\tqueue_len = skb_queue_len(queue);\n+\t\tspin_unlock(&queue->lock);\n+\n+\t\tif (!more || queue_len > NAPI_POLL_WEIGHT)\n+\t\t\tnapi_schedule(&tfile->napi);\n+\n+\t\tlocal_bh_enable();\n+\t} else if (!IS_ENABLED(CONFIG_4KSTACKS)) {\n+\t\ttun_rx_batched(tun, tfile, skb, more);\n+\t} else {\n+\t\tnetif_rx_ni(skb);\n+\t}\n \n \tstats = get_cpu_ptr(tun->pcpu_stats);\n \tu64_stats_update_begin(&stats->syncp);\n@@ -1980,7 +2082,8 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)\n \t\tif (err < 0)\n \t\t\treturn err;\n \n-\t\terr = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER);\n+\t\terr = tun_attach(tun, file, ifr->ifr_flags & IFF_NOFILTER,\n+\t\t\t\t ifr->ifr_flags & IFF_NAPI);\n \t\tif (err < 0)\n \t\t\treturn err;\n \n@@ -2066,7 +2169,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)\n \t\t\t\t       NETIF_F_HW_VLAN_STAG_TX);\n \n \t\tINIT_LIST_HEAD(&tun->disabled);\n-\t\terr = tun_attach(tun, file, false);\n+\t\terr = tun_attach(tun, file, false, ifr->ifr_flags & IFF_NAPI);\n \t\tif (err < 0)\n \t\t\tgoto err_free_flow;\n \n@@ -2216,7 +2319,7 @@ static int tun_set_queue(struct file *file, struct ifreq *ifr)\n \t\tret = security_tun_dev_attach_queue(tun->security);\n \t\tif (ret < 0)\n \t\t\tgoto unlock;\n-\t\tret = tun_attach(tun, file, false);\n+\t\tret = tun_attach(tun, file, false, tun->flags & IFF_NAPI);\n \t} else if (ifr->ifr_flags & IFF_DETACH_QUEUE) {\n \t\ttun = rtnl_dereference(tfile->tun);\n \t\tif (!tun || !(tun->flags & IFF_MULTI_QUEUE) || tfile->detached)\ndiff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h\nindex 3cb5e1d85ddd..30b6184884eb 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\t0x0010\n #define IFF_NO_PI\t0x1000\n /* This flag has no real effect */\n #define IFF_ONE_QUEUE\t0x2000\n",
    "prefixes": [
        "v2",
        "net-next",
        "1/2"
    ]
}