From patchwork Wed Nov 21 16:24:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olga Kornievskaia X-Patchwork-Id: 10692797 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 C47F114BD for ; Wed, 21 Nov 2018 16:24:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4A652C345 for ; Wed, 21 Nov 2018 16:24:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A944C2C344; Wed, 21 Nov 2018 16:24:25 +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 838012C330 for ; Wed, 21 Nov 2018 16:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731718AbeKVC7a (ORCPT ); Wed, 21 Nov 2018 21:59:30 -0500 Received: from mail-oi1-f193.google.com ([209.85.167.193]:40629 "EHLO mail-oi1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730375AbeKVC7a (ORCPT ); Wed, 21 Nov 2018 21:59:30 -0500 Received: by mail-oi1-f193.google.com with SMTP id t204so5001433oie.7 for ; Wed, 21 Nov 2018 08:24:22 -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=I5BHecX1v6dAd3BBBjLLZ212UReh+sg3coXoT+ACBIE=; b=qU3HRWs8m3zUPYSfYtYblObAXxaDCZ56LVgBcRh2mVq1SVP+Mv3C8rU/RTbFsz/IMd cLq/hKOB49qiGezlYsfOJiQ+T2pmlCKkMzWrzzye0UwYqvXB424X4Y99l+3drIzg9zWT jeIG35A0ql6lnou1ykueToOdRaMVvxpWwNyF4vuje7JPFqwefy0LZGUcynMvip1co5FD YVP4H3aQjcIowziAHr3Ac4qEhVwQT+ivzRb7HxDjnFPV+hJN/kb84W/tB2Wpf9NeD/S8 jxty0401/BUWtcXxep06VC2MG9vinbwDd4We7eFPHmlHStuAsRCHCWtd+po0v6rOUIz/ PXBQ== 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=I5BHecX1v6dAd3BBBjLLZ212UReh+sg3coXoT+ACBIE=; b=lwKIZTZTfKC1LgMxSvHfrWG319z54i1q7/uS4UJHo/NJXYEQDXlZq0OmuHx42W6QXy gjezuLRIvM6l5E7KI9uQwRZhY9uTvba4consTuMCIguO4ItFRKLTUaMVtg2GsqdCHGW7 8YyNPEj8RpYiaecNYwztETEWCZ3PPmGSu0IdE3aW/fag0V12CsaJnMvp6Avje0+7mSUW wl8RNJsohdo6IYb9rSJuo9s5FGNnlRum1bFdYqA91X0HznOAAHCfhqk6HQKTMcFjMWNA Ba0eT698iBpv3UagJoEW84DX/tadGKUF6SyyXo+rmr4DrEcvxwIpuvDtIOWq0RoYQHVZ A+5Q== X-Gm-Message-State: AGRZ1gJ0+sWCj18lXWSUDZUIgHgcm3MdIVDijzbF96Bf5IsgPXAm1lJ6 rgPHaXYz1Spu2D57qtILk7I= X-Google-Smtp-Source: AJdET5dBy6/9QzWYll64SNbApS/M+zW+NobCs+TQxy082KrWrsEA/mqwf4mz5ClLN2DMJgXZDsawbg== X-Received: by 2002:aca:bd41:: with SMTP id n62-v6mr4168845oif.336.1542817462197; Wed, 21 Nov 2018 08:24:22 -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 a201sm25762824oii.27.2018.11.21.08.24.20 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 21 Nov 2018 08:24:21 -0800 (PST) From: Olga Kornievskaia To: trond.myklebust@hammerspace.com, anna.schumaker@netapp.com Cc: linux-nfs@vger.kernel.org Subject: [PATCH v4 1/1] NFSv4.2 copy do not allocate memory under the lock Date: Wed, 21 Nov 2018 11:24:22 -0500 Message-Id: <20181121162422.53774-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 in the nfs4_callback_offload() and handle_async_copy() that deal with a racing CB_OFFLOAD and reply to COPY case. Signed-off-by: Olga Kornievskaia --- fs/nfs/callback_proc.c | 22 +++++++++++----------- fs/nfs/nfs42proc.c | 19 ++++++++++--------- 2 files changed, 21 insertions(+), 20 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; diff --git a/fs/nfs/nfs42proc.c b/fs/nfs/nfs42proc.c index c7c2ffa..5cd02a2 100644 --- a/fs/nfs/nfs42proc.c +++ b/fs/nfs/nfs42proc.c @@ -158,31 +158,32 @@ static int handle_async_copy(struct nfs42_copy_res *res, struct file *dst, nfs4_stateid *src_stateid) { - struct nfs4_copy_state *copy; + struct nfs4_copy_state *copy, *tmp_copy; int status = NFS4_OK; bool found_pending = false; struct nfs_open_context *ctx = nfs_file_open_context(dst); + copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS); + if (!copy) + return -ENOMEM; + spin_lock(&server->nfs_client->cl_lock); - list_for_each_entry(copy, &server->nfs_client->pending_cb_stateids, + list_for_each_entry(tmp_copy, &server->nfs_client->pending_cb_stateids, copies) { - if (memcmp(&res->write_res.stateid, ©->stateid, + if (memcmp(&res->write_res.stateid, &tmp_copy->stateid, NFS4_STATEID_SIZE)) continue; found_pending = true; - list_del(©->copies); + list_del(&tmp_copy->copies); break; } if (found_pending) { spin_unlock(&server->nfs_client->cl_lock); + kfree(copy); + copy = tmp_copy; goto out; } - copy = kzalloc(sizeof(struct nfs4_copy_state), GFP_NOFS); - if (!copy) { - spin_unlock(&server->nfs_client->cl_lock); - return -ENOMEM; - } memcpy(©->stateid, &res->write_res.stateid, NFS4_STATEID_SIZE); init_completion(©->completion); copy->parent_state = ctx->state;