From patchwork Fri Nov 16 16:47:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10686695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 701E917DE for ; Fri, 16 Nov 2018 16:47:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3A22CE6F for ; Fri, 16 Nov 2018 16:47:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5057E2CE71; Fri, 16 Nov 2018 16:47:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F12D92CE6F for ; Fri, 16 Nov 2018 16:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729036AbeKQDAY (ORCPT ); Fri, 16 Nov 2018 22:00:24 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:46681 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728684AbeKQDAY (ORCPT ); Fri, 16 Nov 2018 22:00:24 -0500 Received: by mail-oi1-f196.google.com with SMTP id x202so8743739oif.13 for ; Fri, 16 Nov 2018 08:47:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=TlfQf5F5tIj+4OFCYOTCzYvSv6sQaVjis+B3G7oFlWs=; b=l6LBhH5Qyi/urPryckf+vxzdWC1a+z7R7jAHeYY3nuAHE8RZBjThs4mWqV2kS1f3fv v0Daj0K5+O01U9oV9S6NR80vDuXHXa9RTYOOml57MuqqQslkk6gIiTZ7jSWmvLer6W/W Ct7ULT/rgZb9QdMRPpVEtiges0O3coeH4nc/hS4XKZGLOhZlrRbmcjsbeSmCuY0xn1p0 IRaKXRat5BXblNsYxNNdUB16x4MUgPYM3ZZXXe1P2p8xiTSSEJVthsuykwdNl7VbcwXp XpA1Rli8f6ozFDSp6dG5Trx4KBIHMglMiDf7ePz86qO926mUoMgSyezszvwmAsBRjU6X 8UzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TlfQf5F5tIj+4OFCYOTCzYvSv6sQaVjis+B3G7oFlWs=; b=c4hZHm/fYO07hn7h5n1Y99VVVkKucrdahGLY/P2dI0bHHLDKQL71ctoi5az0J2Ej4s 5tNgie0emcCB0ZvB9i+I9zWE3W+Na4GlJ/3cpnVQqQOOFDlzaf+Bzg9Z6/rGcfknQhTd gWTkqaDHGqtOaxAACXca9J4rMaYMDjxpqh8D7JiCIC/MXo4hMY2YtIjTgwtCNoxjTcZn Frr2vWq2jqp+P7Vz4mCDshk+mAeRwAjT7W+8fzZAj1b0qF9l47jyZSLzXItm9swzX0tq Ya5BldLJ3b5dedL5fG+7gcRakx36H7dylPDd/LW+TorSochk26+cRYVivUo3zZW8hTem F4xw== X-Gm-Message-State: AGRZ1gIDoxUD+9DxRGszlS9xmGu7mZjz+ycaMlpZGLgYEi+tVQ/HqCkJ PjOyHJdwVXDkomMlKNf/DwLHlSRb X-Google-Smtp-Source: AJdET5cWmkoCF4aysDwT4B0KASScmbFFCC9yUb+7o8If2BGS6Sy0UP8szfzgnfGT8bSYXpvuFO4NuQ== X-Received: by 2002:a54:418a:: with SMTP id 10mr1476832oiy.128.1542386836597; Fri, 16 Nov 2018 08:47:16 -0800 (PST) Received: from Olgas-MBP-195.attlocal.net (172-10-226-31.lightspeed.livnmi.sbcglobal.net. [172.10.226.31]) by smtp.gmail.com with ESMTPSA id e24sm13101402otd.63.2018.11.16.08.47.15 (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 16 Nov 2018 08:47:15 -0800 (PST) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 1/1] NFSv4.2 do not allocate memory under the lock Date: Fri, 16 Nov 2018 11:47:17 -0500 Message-Id: <20181116164717.50576-1-olga.kornievskaia@gmail.com> X-Mailer: git-send-email 2.10.1 (Apple Git-78) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Olga Kornievskaia Bruce pointed out that we shouldn't allocate memory while holding a lock. Signed-off-by: Olga Kornievskaia --- fs/nfs/callback_proc.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c index fa515d5..48b2e90 100644 --- a/fs/nfs/callback_proc.c +++ b/fs/nfs/callback_proc.c @@ -686,20 +686,24 @@ __be32 nfs4_callback_offload(void *data, void *dummy, { struct cb_offloadargs *args = data; struct nfs_server *server; - struct nfs4_copy_state *copy; + struct nfs4_copy_state *copy, *tmp_copy; bool found = false; + copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS); + if (!copy) + return htonl(NFS4ERR_SERVERFAULT); + spin_lock(&cps->clp->cl_lock); rcu_read_lock(); list_for_each_entry_rcu(server, &cps->clp->cl_superblocks, client_link) { - list_for_each_entry(copy, &server->ss_copies, copies) { + list_for_each_entry(tmp_copy, &server->ss_copies, copies) { if (memcmp(args->coa_stateid.other, - copy->stateid.other, + tmp_copy->stateid.other, sizeof(args->coa_stateid.other))) continue; - nfs4_copy_cb_args(copy, args); - complete(©->completion); + nfs4_copy_cb_args(tmp_copy, args); + complete(&tmp_copy->completion); found = true; goto out; } @@ -707,15 +711,11 @@ __be32 nfs4_callback_offload(void *data, void *dummy, out: rcu_read_unlock(); if (!found) { - copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS); - if (!copy) { - spin_unlock(&cps->clp->cl_lock); - return htonl(NFS4ERR_SERVERFAULT); - } memcpy(©->stateid, &args->coa_stateid, NFS4_STATEID_SIZE); nfs4_copy_cb_args(copy, args); list_add_tail(©->copies, &cps->clp->pending_cb_stateids); - } + } else + kfree(copy); spin_unlock(&cps->clp->cl_lock); return 0;