Received: by 10.213.65.68 with SMTP id h4csp2159919imn; Sun, 8 Apr 2018 21:16:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx49jsIDAwop69Nj5WYlyp5jeX5oP9LhtCDPlFCtIsR6jlmjks71eUYUI1dPjOifaMqOz0vS3 X-Received: by 10.98.152.17 with SMTP id q17mr27878150pfd.67.1523247371040; Sun, 08 Apr 2018 21:16:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523247371; cv=none; d=google.com; s=arc-20160816; b=N/f83tjCSvCSUrvtwLIPp+E5biTynGWuuRb/mZwE204L/oaU7NwrhPCRtdplI0G/Ba ByUK36lT/JpoF722UqU4vJcCUVUlqYgF+wNNWuvuIFJya2qO9/dxbQTh0ig9UXaNmF26 cvUZYVJWOclLbK51AhcgOsDWSdzg/h3XF+2LVyLE0uFO0sZKQfi7Z+Kq0LETtwmDf+oU Cn/Tqkt2WFeXmXj/YJ8X9BhStr7bqbUYC6vKkrGF2+U9+l+aj+age3OVXTP/HstSo/5i ZzNEInYIKSqdFyt1sBi7Lm3BnpKW3xi4DCZqWHSmwKYxQxlE/aN9NQf8IhFyTrZWirn5 1wKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kaZp7ERR86G1X4grMJn9j113W9g1yAh8aikwX96x6sY=; b=P2eun4wRG5PioX/6V/GlUiQLLzfxyspUMVpJKjaGMebdLFv6t18IwFhD31avhI+Eqn qk4JJvMbmxXSUJtdkt/HTY0c/8fH/e0ZJ2re2jLrGUX3X16HOQuLmp+AZbwev4t5ul9S 0B0N8jpgSV97cvLahVLdGiOMns82W7K8n2E+WCpPTtsbe78g4W1u3cHYT2avu+wVxf3J yGyqirqfdtdJFtB1cN7IQoHcntBwMBrjl+3xnvSbV20LNPRACnaZ9+L3KGJLbonzOzqH Vqp+cO0p1QcJHAPiHNOSJYUXE8VqQ18aPPmrkF9oM8sizjj4UFCG4sp2RBZ3PMurtw0y kdSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=A1HaAyRG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1-v6si15291975plt.265.2018.04.08.21.15.33; Sun, 08 Apr 2018 21:16:11 -0700 (PDT) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=A1HaAyRG; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754104AbeDIEKi (ORCPT + 99 others); Mon, 9 Apr 2018 00:10:38 -0400 Received: from mail-co1nam03on0128.outbound.protection.outlook.com ([104.47.40.128]:49080 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752995AbeDIARC (ORCPT ); Sun, 8 Apr 2018 20:17:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kaZp7ERR86G1X4grMJn9j113W9g1yAh8aikwX96x6sY=; b=A1HaAyRG7DhhQTPABNuW+56WOJaUhhIOr8mGlqtg14Uad+UKBZI+bCorVEMhPApvyRiPOUJjjee7pVt6YrHWZmE2lpCV00vlYlEg//ftJk5mMUeRqRnUV2ua7UXbejdPhRjCor/U22zVy1bpZkqhtwQ/bgnLKp5reDULyGh+1MI= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1127.namprd21.prod.outlook.com (52.132.132.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:16:57 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:16:57 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Chuck Lever , Anna Schumaker , Sasha Levin Subject: [PATCH AUTOSEL for 4.15 017/189] xprtrdma: Fix backchannel allocation of extra rpcrdma_reps Thread-Topic: [PATCH AUTOSEL for 4.15 017/189] xprtrdma: Fix backchannel allocation of extra rpcrdma_reps Thread-Index: AQHTz5gSzjNeZZVx2EO47IImEBzoWw== Date: Mon, 9 Apr 2018 00:16:57 +0000 Message-ID: <20180409001637.162453-17-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1127;7:2BSQyQwWJ1oVRS8aM7AZF9SiHB10NCmPYOMlenGOXVX064/PWRSkQcQtuD2kuycejuELqQTJwK8JiOvrigUz+FrDJCgbDT2YVDmBggE2x4Gvn3IE5QV3hwBWxwTN7WFEvTPNM1CVEV4m9L4rzyuhGzdHVbqHKYLwx4TLKhIHap+pARizce/JKP63bFuVq3eM7IawaV24OBfydZB2xFbjWFBCQpn32nJBXZKd6OuAzvzFFPs8isb6LxqJ47jiLhn3;20:YMb0O3yVOhG7e2pdPTIU5o+zeUGGJIcHRI9LKZmktVZkv+8J8zYoLD5RimMuzGz7PuigdUgg2hya1A2uHfSE1QlH1JTrHjV3CeC5NgCF004+PXJbKjhs1AKz1hjC+KPk/+6qBKQW6eeFQu9AvqriS/tT87SobPW1Ltszakjnf/A= x-ms-exchange-antispam-srfa-diagnostics: SOS; x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 9a36720a-1850-4e75-da02-08d59daf3528 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1127; x-ms-traffictypediagnostic: DM5PR2101MB1127: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123560045)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:DM5PR2101MB1127;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1127; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39380400002)(39860400002)(376002)(346002)(366004)(189003)(199004)(105586002)(186003)(66066001)(6486002)(54906003)(7736002)(26005)(575784001)(86362001)(316002)(305945005)(110136005)(478600001)(3280700002)(86612001)(10290500003)(25786009)(5250100002)(2616005)(99286004)(22452003)(5660300001)(3660700001)(2900100001)(81166006)(3846002)(2906002)(106356001)(6506007)(59450400001)(107886003)(486006)(8676002)(81156014)(14454004)(10090500001)(68736007)(4326008)(6116002)(1076002)(72206003)(102836004)(97736004)(11346002)(8936002)(476003)(2501003)(6436002)(6512007)(446003)(76176011)(36756003)(53936002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1127;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: j154mWEUsBqmcGotgAzxd1tLsFPR6ziR5PlIb8CqFWjefaf3WMyY0LjSPZ6WoBcYbFAPVwU1l/W4C1DjW2krM5QTI9IlZOkL7gvI/buWkA1c7O/a4PZaDIMv4P2uEaEpMR2abAsjY7ilS4ANQK2DSJFLAwerQAXu9Q4phnhlHVJsQ2T6NZnhJxPtoTwkLcPsIdBl+buVLrbaffdTheY7Yw03eerra8Y2KMxJMkNHn9t99CjDuhrWHWsF9rT+Jx7kQOfaQV5NaaeTYO1TbylSM3QT0A0tlMCrW37tfn/UICfqivhPyYLHtTHtH56xmLOIhZhkjSs8rVC6llEfLXxfTeyXbZEXKyohq+RoBYXQDmElPyfYRlza2uUSs44gApumnKG2Dw5MFnrQzgml9W+YRJCXH+ykfaGeMvAIJe3PRH0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9a36720a-1850-4e75-da02-08d59daf3528 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:16:57.7313 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1127 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Chuck Lever [ Upstream commit d698c4a02ee02053bbebe051322ff427a2dad56a ] The backchannel code uses rpcrdma_recv_buffer_put to add new reps to the free rep list. This also decrements rb_recv_count, which spoofs the receive overrun logic in rpcrdma_buffer_get_rep. Commit 9b06688bc3b9 ("xprtrdma: Fix additional uses of spin_lock_irqsave(rb_lock)") replaced the original open-coded list_add with a call to rpcrdma_recv_buffer_put(), but then a year later, commit 05c974669ece ("xprtrdma: Fix receive buffer accounting") added rep accounting to rpcrdma_recv_buffer_put. It was an oversight to let the backchannel continue to use this function. The fix this, let's combine the "add to free list" logic with rpcrdma_create_rep. Also, do not allocate RPCRDMA_MAX_BC_REQUESTS rpcrdma_reps in rpcrdma_buffer_create and then allocate additional rpcrdma_reps in rpcrdma_bc_setup_reps. Allocating the extra reps during backchannel set-up is sufficient. Fixes: 05c974669ece ("xprtrdma: Fix receive buffer accounting") Signed-off-by: Chuck Lever Signed-off-by: Anna Schumaker Signed-off-by: Sasha Levin --- net/sunrpc/xprtrdma/backchannel.c | 12 ++---------- net/sunrpc/xprtrdma/verbs.c | 32 +++++++++++++++++++------------- net/sunrpc/xprtrdma/xprt_rdma.h | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/net/sunrpc/xprtrdma/backchannel.c b/net/sunrpc/xprtrdma/backch= annel.c index 8b818bb3518a..256c67b433c1 100644 --- a/net/sunrpc/xprtrdma/backchannel.c +++ b/net/sunrpc/xprtrdma/backchannel.c @@ -74,21 +74,13 @@ out_fail: static int rpcrdma_bc_setup_reps(struct rpcrdma_xprt *r_xprt, unsigned int count) { - struct rpcrdma_rep *rep; int rc =3D 0; =20 while (count--) { - rep =3D rpcrdma_create_rep(r_xprt); - if (IS_ERR(rep)) { - pr_err("RPC: %s: reply buffer alloc failed\n", - __func__); - rc =3D PTR_ERR(rep); + rc =3D rpcrdma_create_rep(r_xprt); + if (rc) break; - } - - rpcrdma_recv_buffer_put(rep); } - return rc; } =20 diff --git a/net/sunrpc/xprtrdma/verbs.c b/net/sunrpc/xprtrdma/verbs.c index 8cd7ee4fa0cd..371fbd9b55bb 100644 --- a/net/sunrpc/xprtrdma/verbs.c +++ b/net/sunrpc/xprtrdma/verbs.c @@ -1093,10 +1093,17 @@ rpcrdma_create_req(struct rpcrdma_xprt *r_xprt) return req; } =20 -struct rpcrdma_rep * +/** + * rpcrdma_create_rep - Allocate an rpcrdma_rep object + * @r_xprt: controlling transport + * + * Returns 0 on success or a negative errno on failure. + */ +int rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt) { struct rpcrdma_create_data_internal *cdata =3D &r_xprt->rx_data; + struct rpcrdma_buffer *buf =3D &r_xprt->rx_buf; struct rpcrdma_rep *rep; int rc; =20 @@ -1121,12 +1128,18 @@ rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt) rep->rr_recv_wr.wr_cqe =3D &rep->rr_cqe; rep->rr_recv_wr.sg_list =3D &rep->rr_rdmabuf->rg_iov; rep->rr_recv_wr.num_sge =3D 1; - return rep; + + spin_lock(&buf->rb_lock); + list_add(&rep->rr_list, &buf->rb_recv_bufs); + spin_unlock(&buf->rb_lock); + return 0; =20 out_free: kfree(rep); out: - return ERR_PTR(rc); + dprintk("RPC: %s: reply buffer %d alloc failed\n", + __func__, rc); + return rc; } =20 int @@ -1167,17 +1180,10 @@ rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt) } =20 INIT_LIST_HEAD(&buf->rb_recv_bufs); - for (i =3D 0; i < buf->rb_max_requests + RPCRDMA_MAX_BC_REQUESTS; i++) { - struct rpcrdma_rep *rep; - - rep =3D rpcrdma_create_rep(r_xprt); - if (IS_ERR(rep)) { - dprintk("RPC: %s: reply buffer %d alloc failed\n", - __func__, i); - rc =3D PTR_ERR(rep); + for (i =3D 0; i <=3D buf->rb_max_requests; i++) { + rc =3D rpcrdma_create_rep(r_xprt); + if (rc) goto out; - } - list_add(&rep->rr_list, &buf->rb_recv_bufs); } =20 rc =3D rpcrdma_sendctxs_create(r_xprt); diff --git a/net/sunrpc/xprtrdma/xprt_rdma.h b/net/sunrpc/xprtrdma/xprt_rdm= a.h index 1342f743f1c4..3b63e61feae2 100644 --- a/net/sunrpc/xprtrdma/xprt_rdma.h +++ b/net/sunrpc/xprtrdma/xprt_rdma.h @@ -564,8 +564,8 @@ int rpcrdma_ep_post_recv(struct rpcrdma_ia *, struct rp= crdma_rep *); * Buffer calls - xprtrdma/verbs.c */ struct rpcrdma_req *rpcrdma_create_req(struct rpcrdma_xprt *); -struct rpcrdma_rep *rpcrdma_create_rep(struct rpcrdma_xprt *); void rpcrdma_destroy_req(struct rpcrdma_req *); +int rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt); int rpcrdma_buffer_create(struct rpcrdma_xprt *); void rpcrdma_buffer_destroy(struct rpcrdma_buffer *); struct rpcrdma_sendctx *rpcrdma_sendctx_get_locked(struct rpcrdma_buffer *= buf); --=20 2.15.1