Received: by 10.223.185.116 with SMTP id b49csp1027257wrg; Wed, 21 Feb 2018 10:48:50 -0800 (PST) X-Google-Smtp-Source: AH8x225gQxjXGb4BN/ri5WXvVdYFdJMRpWhBTlzI8CJ0ChsUXTYYh7DZk7RU0NjVv6UJAqfSeNnT X-Received: by 10.98.16.147 with SMTP id 19mr3524878pfq.84.1519238930295; Wed, 21 Feb 2018 10:48:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238930; cv=none; d=google.com; s=arc-20160816; b=pvp2MCFudaBDw+kHsg62oK7DDFPrdrvTXB0MDeJ7FnKM1kAnsbRBkKulnl7ej/t4nl 1NBSysuVMj2l1u0MiUMiMl3C8UOPrEqUCgT32fWECQZslZaGxlt8t27qO+m8buMT5WJa JUWyDOiM/5ygG0I5U7W6QtPJ/lA4GzaWJLHe4rOT2tzP5QqoJnD4FMFtzmk01Rul0oRN U7QsZXXPPRLDCy/RkcXPH61ULumLtxMJvngr8q6AvENqK0xbTvXyaxRNB9YWNWlGzfHE gWNw+gw5AKBVJULJfliFJMwgr3UPqvi8zR+s59DH5pDAC5IledVJpW/UJCEctyl8gayg fc1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=6b4aJQzGadtM/GkBDzlTt1xVOGGBa7fG6uUudvYzlSY=; b=tCrEITS6eSr1DShqA02SP+89KecA0fnlinDfgjiR/W2Adqw1u7eG9z9m+l6THyxBrf WMa5jiFWh4+KsZ0ki9EG5nYuTqF1hpZIj/eIsfp0cXT/23gFO4VdCYDu9tJ1KimdzWzf QYQBcZE6rdRO13cB+6Pb/inETRv2+pHzxc3Q3EjLOajKrQxlXktjoWK2OwYKJPQ3z4PU BwfdxmplAzqpyfsErZNiQhWYlsX6iQ7SyJQkPOh9ikKOr8EIg5f9JtVNqQw72zP7hOW1 8KB8h+AXtR/sXLaWKqRjciWRAQ2O8KpMbbOKH8TdFjj5YmQoEL+9bJCPgTUBjFHfiHGM ivAA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z5si1867004pfb.355.2018.02.21.10.48.36; Wed, 21 Feb 2018 10:48:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S937142AbeBUOAc (ORCPT + 99 others); Wed, 21 Feb 2018 09:00:32 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39606 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935757AbeBUNDg (ORCPT ); Wed, 21 Feb 2018 08:03:36 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9814110B2; Wed, 21 Feb 2018 13:03:35 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michal Kalderon , Chuck Lever , Anna Schumaker Subject: [PATCH 4.14 128/167] xprtrdma: Fix calculation of ri_max_send_sges Date: Wed, 21 Feb 2018 13:48:59 +0100 Message-Id: <20180221124531.595333431@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124524.639039577@linuxfoundation.org> References: <20180221124524.639039577@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chuck Lever commit 1179e2c27efe21167ec9d882b14becefba2ee990 upstream. Commit 16f906d66cd7 ("xprtrdma: Reduce required number of send SGEs") introduced the rpcrdma_ia::ri_max_send_sges field. This fixes a problem where xprtrdma would not work if the device's max_sge capability was small (low single digits). At least RPCRDMA_MIN_SEND_SGES are needed for the inline parts of each RPC. ri_max_send_sges is set to this value: ia->ri_max_send_sges = max_sge - RPCRDMA_MIN_SEND_SGES; Then when marshaling each RPC, rpcrdma_args_inline uses that value to determine whether the device has enough Send SGEs to convey an NFS WRITE payload inline, or whether instead a Read chunk is required. More recently, commit ae72950abf99 ("xprtrdma: Add data structure to manage RDMA Send arguments") used the ri_max_send_sges value to calculate the size of an array, but that commit erroneously assumed ri_max_send_sges contains a value similar to the device's max_sge, and not one that was reduced by the minimum SGE count. This assumption results in the calculated size of the sendctx's Send SGE array to be too small. When the array is used to marshal an RPC, the code can write Send SGEs into the following sendctx element in that array, corrupting it. When the device's max_sge is large, this issue is entirely harmless; but it results in an oops in the provider's post_send method, if dev.attrs.max_sge is small. So let's straighten this out: ri_max_send_sges will now contain a value with the same meaning as dev.attrs.max_sge, which makes the code easier to understand, and enables rpcrdma_sendctx_create to calculate the size of the SGE array correctly. Reported-by: Michal Kalderon Fixes: 16f906d66cd7 ("xprtrdma: Reduce required number of send SGEs") Signed-off-by: Chuck Lever Tested-by: Michal Kalderon Cc: stable@vger.kernel.org # v4.10+ Signed-off-by: Anna Schumaker Signed-off-by: Greg Kroah-Hartman --- net/sunrpc/xprtrdma/rpc_rdma.c | 2 +- net/sunrpc/xprtrdma/verbs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/net/sunrpc/xprtrdma/rpc_rdma.c +++ b/net/sunrpc/xprtrdma/rpc_rdma.c @@ -142,7 +142,7 @@ static bool rpcrdma_args_inline(struct r if (xdr->page_len) { remaining = xdr->page_len; offset = offset_in_page(xdr->page_base); - count = 0; + count = RPCRDMA_MIN_SEND_SGES; while (remaining) { remaining -= min_t(unsigned int, PAGE_SIZE - offset, remaining); --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -523,7 +523,7 @@ rpcrdma_ep_create(struct rpcrdma_ep *ep, pr_warn("rpcrdma: HCA provides only %d send SGEs\n", max_sge); return -ENOMEM; } - ia->ri_max_send_sges = max_sge - RPCRDMA_MIN_SEND_SGES; + ia->ri_max_send_sges = max_sge; if (ia->ri_device->attrs.max_qp_wr <= RPCRDMA_BACKWARD_WRS) { dprintk("RPC: %s: insufficient wqe's available\n",