From patchwork Thu Oct 6 14:47:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9364933 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 16D386077E for ; Thu, 6 Oct 2016 15:11:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0831929072 for ; Thu, 6 Oct 2016 15:11:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F007F2908C; Thu, 6 Oct 2016 15:11:07 +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 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 A96A229072 for ; Thu, 6 Oct 2016 15:11:03 +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 1bsAGk-000494-9T; Thu, 06 Oct 2016 15:07:34 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bsAGi-00048y-VD for xen-devel@lists.xenproject.org; Thu, 06 Oct 2016 15:07:33 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id 3F/91-29579-4B866F75; Thu, 06 Oct 2016 15:07:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrOLMWRWlGSWpSXmKPExsXitHRDpO7mjG/ hBl0PRC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozVk7ewFhyQqzj0tp29gXGuZBcjJ4eEgL/E 0/ebmUBsNgEdialPL7GC2CICdhKXNh9g72Lk4GAW8JTouWUOEhYWiJTo3noWrJxFQEXiwOLbz CA2r4C7xNs3TxghRspJnD/+EywuBFSzfuosNogaQYmTM5+wgNjMAhISB1+8YAYZLyHALfG323 4CI88sJFWzkFQtYGRaxahRnFpUllqka2iql1SUmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5y fu4kRGCAMQLCDcc12z0OMkhxMSqK865m+hQvxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4D2TDpQT LEpNT61Iy8wBhipMWoKDR0mEtw8kzVtckJhbnJkOkTrFqCglzjsJJCEAksgozYNrg8XHJUZZK WFeRqBDhHgKUotyM0tQ5V8xinMwKgnzFoNM4cnMK4Gb/gpoMRPQ4vylX0AWlyQipKQaGEVWaN QGBfA5pASoO1UlV6++97CI7dTBJee2/sw4F1/qvuacJX8xH+/RJQtWq39aZ7yuJXmXxjqWrzO 2yBXoXd+5QWeNkGnytcdB2ss9Xn6eM4e14tZ1Ph41TYe5m+cVSVxrzFpwm1ut9LR98PZDp2va /M36nz4/15f1rCRX317XfdH2bwbnniqxFGckGmoxFxUnAgD1lpmbigIAAA== X-Env-Sender: prvs=08044579e=Paul.Durrant@citrix.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1475766449!9345920!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34704 invoked from network); 6 Oct 2016 15:07:31 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-9.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 6 Oct 2016 15:07:31 -0000 X-IronPort-AV: E=Sophos;i="5.31,454,1473120000"; d="scan'208";a="382794003" From: Paul Durrant To: , Date: Thu, 6 Oct 2016 15:47:10 +0100 Message-ID: <1475765230-11936-1-git-send-email-paul.durrant@citrix.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-DLP: MIA1 Cc: Paul Durrant , Wei Liu Subject: [Xen-devel] [PATCH net] xen-netback: make sure that hashes are not send to unaware frontends 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In the case when a frontend only negotiates a single queue with xen- netback it is possible for a skbuff with a s/w hash to result in a hash extra_info segment being sent to the frontend even when no hash algorithm has been configured. (The ndo_select_queue() entry point makes sure the hash is not set if no algorithm is configured, but this entry point is not called when there is only a single queue). This can result in a frontend that isunable to handle extra_info segments being given such a segment, causing it to crash. This patch fixes the problem by gating whether the extra_info is sent not only on the presence of a s/w hash, but also on whether the hash algorithm has been configured. Signed-off-by: Paul Durrant Cc: Wei Liu --- drivers/net/xen-netback/interface.c | 13 ++----------- drivers/net/xen-netback/netback.c | 23 ++++++++++++++--------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/drivers/net/xen-netback/interface.c b/drivers/net/xen-netback/interface.c index fb50c6d..1034139 100644 --- a/drivers/net/xen-netback/interface.c +++ b/drivers/net/xen-netback/interface.c @@ -149,17 +149,8 @@ static u16 xenvif_select_queue(struct net_device *dev, struct sk_buff *skb, struct xenvif *vif = netdev_priv(dev); unsigned int size = vif->hash.size; - if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE) { - u16 index = fallback(dev, skb) % dev->real_num_tx_queues; - - /* Make sure there is no hash information in the socket - * buffer otherwise it would be incorrectly forwarded - * to the frontend. - */ - skb_clear_hash(skb); - - return index; - } + if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE) + return fallback(dev, skb) % dev->real_num_tx_queues; xenvif_set_skb_hash(vif, skb); diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c index 3d0c989..2cd4a8e 100644 --- a/drivers/net/xen-netback/netback.c +++ b/drivers/net/xen-netback/netback.c @@ -168,6 +168,10 @@ static bool xenvif_rx_ring_slots_available(struct xenvif_queue *queue) needed = DIV_ROUND_UP(skb->len, XEN_PAGE_SIZE); if (skb_is_gso(skb)) needed++; + /* Assume the frontend is capable of handling the hash + * extra_info at this point. This will only ever lead to an + * accurate value or over-estimation. + */ if (skb->sw_hash) needed++; @@ -378,9 +382,8 @@ static void xenvif_gop_frag_copy(struct xenvif_queue *queue, struct sk_buff *skb .npo = npo, .head = *head, .gso_type = XEN_NETIF_GSO_TYPE_NONE, - /* xenvif_set_skb_hash() will have either set a s/w - * hash or cleared the hash depending on - * whether the the frontend wants a hash for this skb. + /* xenvif_rx_action() will have cleared any hash if + * the frontend is not capable of handling it. */ .hash_present = skb->sw_hash, }; @@ -593,6 +596,14 @@ static void xenvif_rx_action(struct xenvif_queue *queue) && (skb = xenvif_rx_dequeue(queue)) != NULL) { queue->last_rx_time = jiffies; + /* If there is no hash algorithm configured make sure + * there is no hash information in the socket buffer + * otherwise it would be incorrectly forwarded to the + * frontend. + */ + if (vif->hash.alg == XEN_NETIF_CTRL_HASH_ALGORITHM_NONE) + skb_clear_hash(skb); + XENVIF_RX_CB(skb)->meta_slots_used = xenvif_gop_skb(skb, &npo, queue); __skb_queue_tail(&rxq, skb); @@ -667,12 +678,6 @@ static void xenvif_rx_action(struct xenvif_queue *queue) } if (skb->sw_hash) { - /* Since the skb got here via xenvif_select_queue() - * we know that the hash has been re-calculated - * according to a configuration set by the frontend - * and therefore we know that it is legitimate to - * pass it to the frontend. - */ if (resp->flags & XEN_NETRXF_extra_info) extra->flags |= XEN_NETIF_EXTRA_FLAG_MORE; else