From patchwork Thu Nov 2 18:06:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joao Martins X-Patchwork-Id: 10039133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 97831600C5 for ; Thu, 2 Nov 2017 18:09:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 905A4290DE for ; Thu, 2 Nov 2017 18:09:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 841B629235; Thu, 2 Nov 2017 18:09:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6738329202 for ; Thu, 2 Nov 2017 18:09:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAJtM-0005Gy-CS; Thu, 02 Nov 2017 18:07:00 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eAJtK-0005EJ-SL for xen-devel@lists.xen.org; Thu, 02 Nov 2017 18:06:58 +0000 Received: from [85.158.137.68] by server-4.bemta-3.messagelabs.com id 56/FE-10698-2CE5BF95; Thu, 02 Nov 2017 18:06:58 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42LpnVTnqnsw7ne kwf1n0hZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8ap7mmMBS99K3YvaGBpYGx16GLk4hASmMAk 0bnlHCuE84tR4szCKcwQzgZGieMzX0NluhglFq6cxdbFyMnBJqAn0Xr+MzOILSJgJNF2fCI7i M0sUC0x6RFEXFjATuL08kYwm0VAVeLjjmYWEJsXKN60DGQdJ4eEgLzErraLQDYHB6eAvcSEGQ UgYSGgku41W9ghSgwlTj/cxjiBkW8BI8MqRvXi1KKy1CJdU72kosz0jJLcxMwcXUMDY73c1OL ixPTUnMSkYr3k/NxNjMBAqWdgYNzBePmr0yFGSQ4mJVHeuxt/RQrxJeWnVGYkFmfEF5XmpBYf YpTh4FCS4N0Y+ztSSLAoNT21Ii0zBxiyMGkJDh4lEd65IGne4oLE3OLMdIjUKUZjjo6bd/8wc Tyb+bqBWYglLz8vVUqcNwOkVACkNKM0D24QLJYuMcpKCfMyMjAwCPEUpBblZpagyr9iFOdgVB LmPQIyhSczrwRu3yugU5iATvGS+AFySkkiQkqqgfHx21JPo5tHWw82H1wQLrYhXvqK2HKFg9N kmxkWHlu+eGdEW/PfyHOfwsvsC2Qagx6eKlu2uv5Zs/ImteO5SYVruyIX8sws+r6Gw1a1dXJZ eujdp2v8OO/uziuoX/zo4aczQl0yNltSVr3csj6l9DHL/eWPTl6Izpkgdu/nSUe1LUuspX1n5 PUrsRRnJBpqMRcVJwIAiFVvgqACAAA= X-Env-Sender: joao.m.martins@oracle.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1509646015!105633053!1 X-Originating-IP: [141.146.126.69] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTQxLjE0Ni4xMjYuNjkgPT4gMjc3MjE4\n X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 33957 invoked from network); 2 Nov 2017 18:06:57 -0000 Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by server-7.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Nov 2017 18:06:57 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA2I6r4B018603 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:53 GMT Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6rQ5028999 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Nov 2017 18:06:53 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vA2I6qs2010351; Thu, 2 Nov 2017 18:06:52 GMT Received: from paddy.uk.oracle.com (/10.175.173.7) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 02 Nov 2017 11:06:52 -0700 From: Joao Martins To: Xen Development List Date: Thu, 2 Nov 2017 18:06:16 +0000 Message-Id: <20171102180616.24084-9-joao.m.martins@oracle.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171102180616.24084-1-joao.m.martins@oracle.com> References: <20171102180616.24084-1-joao.m.martins@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: Joao Martins , Paul Durrant , Wei Liu Subject: [Xen-devel] [PATCH RFC 8/8] xen-netback: frontend feature control X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Toolstack may write values to the "require" subdirectory in the backend main xenstore directory (e.g. backend/vif/X/Y/). Read these values and use them when announcing those to the frontend. When backend scans frontend features the values set in the require directory take precedence, hence making no significant changes in feature parsing. This is achieved by using the newly introduced helper (xenbus_printf_feature()) which reads from require subdirectory and prints that value and otherwise printing a default_val in the entry. We then replace all instances of xenbus_printf by this new helper. A backend_features struct is introduced and all values set there are used in place of the module parameters being used. Note, however that feature-rx-copy, feature-rx-flip aren't probed because first two aren't implemented the full set of possibilities. Additionally probe to for 'feature-no-csum-offload' to allow toolstack to control per device checksum offloading. Signed-off-by: Joao Martins --- drivers/net/xen-netback/xenbus.c | 122 +++++++++++++++++++++++++++++++-------- 1 file changed, 99 insertions(+), 23 deletions(-) diff --git a/drivers/net/xen-netback/xenbus.c b/drivers/net/xen-netback/xenbus.c index a56d3eab35dd..391f1f2e1af2 100644 --- a/drivers/net/xen-netback/xenbus.c +++ b/drivers/net/xen-netback/xenbus.c @@ -22,9 +22,25 @@ #include #include +#define REQUIRE_PATH_LEN (256) + +struct backend_features { + unsigned int max_queues; + unsigned int split_evtchn:1; + unsigned int ctrl_ring:1; + unsigned int can_sg:1; + unsigned int gso_v4:1; + unsigned int gso_v6:1; + unsigned int mcast_ctrl:1; + unsigned int dyn_mcast_ctrl:1; + unsigned int ip_no_csum:1; + unsigned int ipv6_csum:1; +}; + struct backend_info { struct xenbus_device *dev; struct xenvif *vif; + struct backend_features features; /* This is the state that will be reflected in xenstore when any * active hotplug script completes. @@ -48,6 +64,17 @@ static void xen_unregister_watchers(struct xenvif *vif); static void set_backend_state(struct backend_info *be, enum xenbus_state state); +static int xenbus_read_feature(const char *dir, const char *node, + unsigned int default_val) +{ + char reqnode[REQUIRE_PATH_LEN]; + unsigned int val; + + snprintf(reqnode, REQUIRE_PATH_LEN, "%s/require", dir); + val = xenbus_read_unsigned(reqnode, node, default_val); + return val; +} + #ifdef CONFIG_DEBUG_FS struct dentry *xen_netback_dbg_root = NULL; @@ -280,6 +307,32 @@ static int netback_remove(struct xenbus_device *dev) return 0; } +static void netback_probe_features(struct xenbus_device *dev, + struct backend_info *be) +{ + struct backend_features *ft = &be->features; + + ft->can_sg = xenbus_read_feature(dev->nodename, "feature-sg", 1); + ft->gso_v4 = xenbus_read_feature(dev->nodename, "feature-gso-v4", 1); + ft->gso_v6 = xenbus_read_feature(dev->nodename, "feature-gso-v6", 1); + ft->gso_v6 = xenbus_read_feature(dev->nodename, "feature-gso-v6", 1); + ft->ipv6_csum = xenbus_read_feature(dev->nodename, + "feature-ipv6-csum-offload", 1); + ft->ip_no_csum = xenbus_read_feature(dev->nodename, + "feature-no-csum-offload", 0); + ft->mcast_ctrl = xenbus_read_feature(dev->nodename, + "feature-multicast-control", 1); + ft->dyn_mcast_ctrl = xenbus_read_feature(dev->nodename, + "feature-dynamic-multicast-control", 1); + ft->split_evtchn = xenbus_read_feature(dev->nodename, + "feature-split-event-channels", + separate_tx_rx_irq); + ft->max_queues = xenbus_read_feature(dev->nodename, + "multi-queue-max-queues", + xenvif_max_queues); + ft->ctrl_ring = xenbus_read_feature(dev->nodename, "feature-ctrl-ring", + 1); +} /** * Entry point to this code when a new device is created. Allocate the basic @@ -291,8 +344,8 @@ static int netback_probe(struct xenbus_device *dev, const char *message; struct xenbus_transaction xbt; int err; - int sg; const char *script; + struct backend_features *ft; struct backend_info *be = kzalloc(sizeof(struct backend_info), GFP_KERNEL); if (!be) { @@ -309,7 +362,8 @@ static int netback_probe(struct xenbus_device *dev, if (err) goto fail; - sg = 1; + netback_probe_features(dev, be); + ft = &be->features; do { err = xenbus_transaction_start(&xbt); @@ -318,21 +372,22 @@ static int netback_probe(struct xenbus_device *dev, goto fail; } - err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", sg); + err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", + ft->can_sg); if (err) { message = "writing feature-sg"; goto abort_transaction; } err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", - "%d", sg); + "%d", ft->gso_v4); if (err) { message = "writing feature-gso-tcpv4"; goto abort_transaction; } err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv6", - "%d", sg); + "%d", ft->gso_v6); if (err) { message = "writing feature-gso-tcpv6"; goto abort_transaction; @@ -341,12 +396,21 @@ static int netback_probe(struct xenbus_device *dev, /* We support partial checksum setup for IPv6 packets */ err = xenbus_printf(xbt, dev->nodename, "feature-ipv6-csum-offload", - "%d", 1); + "%d", ft->ipv6_csum); if (err) { message = "writing feature-ipv6-csum-offload"; goto abort_transaction; } + /* We support partial checksum setup for IPv4 packets */ + err = xenbus_printf(xbt, dev->nodename, + "feature-no-csum-offload", + "%d", ft->ip_no_csum); + if (err) { + message = "writing feature-no-csum-offload"; + goto abort_transaction; + } + /* We support rx-copy path. */ err = xenbus_printf(xbt, dev->nodename, "feature-rx-copy", "%d", 1); @@ -368,7 +432,8 @@ static int netback_probe(struct xenbus_device *dev, /* We support dynamic multicast-control. */ err = xenbus_printf(xbt, dev->nodename, - "feature-multicast-control", "%d", 1); + "feature-multicast-control", "%d", + ft->mcast_ctrl); if (err) { message = "writing feature-multicast-control"; goto abort_transaction; @@ -376,7 +441,7 @@ static int netback_probe(struct xenbus_device *dev, err = xenbus_printf(xbt, dev->nodename, "feature-dynamic-multicast-control", - "%d", 1); + "%d", ft->dyn_mcast_ctrl); if (err) { message = "writing feature-dynamic-multicast-control"; goto abort_transaction; @@ -396,19 +461,19 @@ static int netback_probe(struct xenbus_device *dev, */ err = xenbus_printf(XBT_NIL, dev->nodename, "feature-split-event-channels", - "%u", separate_tx_rx_irq); + "%u", ft->split_evtchn); if (err) pr_debug("Error writing feature-split-event-channels\n"); /* Multi-queue support: This is an optional feature. */ err = xenbus_printf(XBT_NIL, dev->nodename, - "multi-queue-max-queues", "%u", xenvif_max_queues); + "multi-queue-max-queues", "%u", ft->max_queues); if (err) pr_debug("Error writing multi-queue-max-queues\n"); err = xenbus_printf(XBT_NIL, dev->nodename, "feature-ctrl-ring", - "%u", true); + "%u", ft->ctrl_ring); if (err) pr_debug("Error writing feature-ctrl-ring\n"); @@ -904,6 +969,9 @@ static int connect_ctrl_ring(struct backend_info *be) unsigned int evtchn; int err; + if (!be->features.ctrl_ring) + goto done; + err = xenbus_scanf(XBT_NIL, dev->otherend, "ctrl-ring-ref", "%u", &val); if (err < 0) @@ -951,11 +1019,11 @@ static void connect(struct backend_info *be) */ requested_num_queues = xenbus_read_unsigned(dev->otherend, "multi-queue-num-queues", 1); - if (requested_num_queues > xenvif_max_queues) { + if (requested_num_queues > be->features.max_queues) { /* buggy or malicious guest */ xenbus_dev_fatal(dev, -EINVAL, "guest requested %u queues, exceeding the maximum of %u.", - requested_num_queues, xenvif_max_queues); + requested_num_queues, be->features.max_queues); return; } @@ -1110,10 +1178,13 @@ static int connect_data_rings(struct backend_info *be, goto err; } + err = -EOPNOTSUPP; /* Try split event channels first, then single event channel. */ - err = xenbus_gather(XBT_NIL, xspath, - "event-channel-tx", "%u", &tx_evtchn, - "event-channel-rx", "%u", &rx_evtchn, NULL); + if (be->features.split_evtchn) + err = xenbus_gather(XBT_NIL, xspath, + "event-channel-tx", "%u", &tx_evtchn, + "event-channel-rx", "%u", &rx_evtchn, NULL); + if (err < 0) { err = xenbus_scanf(XBT_NIL, xspath, "event-channel", "%u", &tx_evtchn); @@ -1173,21 +1244,26 @@ static int read_xenbus_vif_flags(struct backend_info *be) be->vif->stall_timeout = 0; } - vif->can_sg = !!xenbus_read_unsigned(dev->otherend, "feature-sg", 0); + vif->can_sg = be->features.can_sg && + !!xenbus_read_unsigned(dev->otherend, "feature-sg", 0); vif->gso_mask = 0; - if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv4", 0)) + if (be->features.gso_v4 && + xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv4", 0)) vif->gso_mask |= GSO_BIT(TCPV4); - if (xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv6", 0)) + if (be->features.gso_v6 && + xenbus_read_unsigned(dev->otherend, "feature-gso-tcpv6", 0)) vif->gso_mask |= GSO_BIT(TCPV6); - vif->ip_csum = !xenbus_read_unsigned(dev->otherend, - "feature-no-csum-offload", 0); + vif->ip_csum = !be->features.ip_no_csum && + !xenbus_read_unsigned(dev->otherend, + "feature-no-csum-offload", 0); - vif->ipv6_csum = !!xenbus_read_unsigned(dev->otherend, - "feature-ipv6-csum-offload", 0); + vif->ipv6_csum = be->features.ipv6_csum && + !!xenbus_read_unsigned(dev->otherend, + "feature-ipv6-csum-offload", 0); return 0; }