Received: by 10.223.185.116 with SMTP id b49csp1019288wrg; Wed, 21 Feb 2018 10:40:11 -0800 (PST) X-Google-Smtp-Source: AH8x224UyK1MuTamDR02LQ1JgZtg1F2IJuvSrUSj8zkmRtretfpkvO4CDv9NG/SIAlVcCKMPP1vn X-Received: by 10.101.101.204 with SMTP id y12mr3504552pgv.450.1519238411043; Wed, 21 Feb 2018 10:40:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519238411; cv=none; d=google.com; s=arc-20160816; b=wVDZu+i/wqQC6hY2DwXk0OqNTF8qHTsqDIzjruIbfOpWSggh45eNFnhPyMp+mmYWfk 6bPx1V43f91TeMivoD6g7Wo3z8RXHu9/GUdUzZZOg/OG0opDQr9+CNgc1Mnl65eB33eP c1lnVOckLXvjM3xz/Cr4Hw5zgs+drNSlO+EaDSNYMuOv9iM000vwiFbnOgz1Ff3m0h1h P7AqvWZ7TcQ24x6/0woIvBakfs8phwx/Hpa4ywzxbobjrhqcV9wG51ACVgslTlB0JlOX FgS0Hz2MoS+IvaDFIvjLamVkG7cn2OusFvCbOdU1JbPnkG8Se66+2q11ptM1R9waMCnb nFeQ== 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=O9DPCyTsY3vqHtNmCu2CMvnWekK7mTkRpyWSOYgeiWg=; b=SXSkIsyk90VpG5oDt87R2eQtyC/5huEqX2b4cf0gV04EyHYEKmJk0hMGztCg0W53iK tLeQzhzxwQhqhLUECvaaKN6K/z8yX/911GFAGt9fz64qxOwJjmZhjatqg+9xw7cqjIRJ 8fHBk9abKbDJK5S2+U8zqs0zZYuPI5IjN5UDu73uwtFu/Hffsaeltov+KcKG8AXJwDfY wxtMQ7qRW7EDN08aiEsB2OQ6FZdUlSRzmXK/r8u8Upt/M+t9y46Rxp/LEU2IBJxfvJG9 t5QPQ80B0aG8remC1L9ricNkPV7jKAXUuEJTFW1YsM++9qy/1PhsTfDTQhrwSqx2U8nT ac2g== 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 d3-v6si1089807pll.517.2018.02.21.10.39.56; Wed, 21 Feb 2018 10:40:11 -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 S1754582AbeBUNNd (ORCPT + 99 others); Wed, 21 Feb 2018 08:13:33 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:46068 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965740AbeBUNNb (ORCPT ); Wed, 21 Feb 2018 08:13:31 -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 41E4410BA; Wed, 21 Feb 2018 13:13:30 +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.15 129/163] xprtrdma: Fix calculation of ri_max_send_sges Date: Wed, 21 Feb 2018 13:49:18 +0100 Message-Id: <20180221124537.261537429@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180221124529.931834518@linuxfoundation.org> References: <20180221124529.931834518@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.15-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 @@ -143,7 +143,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 @@ -509,7 +509,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",