From: Chuck Lever III <chuck.lever@oracle.com>
To: Jeff Layton <jlayton@kernel.org>, Dai Ngo <dai.ngo@oracle.com>
Cc: Olga Kornievskaia <aglo@umich.edu>,
Linux NFS Mailing List <linux-nfs@vger.kernel.org>
Subject: Re: [PATCH v2 1/1] NFSD: fix problems with cleanup on errors in nfsd4_copy
Date: Tue, 31 Jan 2023 14:27:14 +0000 [thread overview]
Message-ID: <E130FEB9-BAC4-42FF-8DC6-9769A0933832@oracle.com> (raw)
In-Reply-To: <3a2684bf63a044bf2a9f349c28b2b2ea5b9e1016.camel@kernel.org>
> On Jan 31, 2023, at 8:36 AM, Jeff Layton <jlayton@kernel.org> wrote:
>
> On Sat, 2023-01-28 at 20:44 -0800, Dai Ngo wrote:
>> When nfsd4_copy fails to allocate memory for async_copy->cp_src, or
>> nfs4_init_copy_state fails, it calls cleanup_async_copy to do the
>> cleanup for the async_copy which causes page fault since async_copy
>> is not yet initialized.
>>
>> This patch rearranges the order of initializing the fields in
>> async_copy and adds checks in cleanup_async_copy to skip un-initialized
>> fields.
>>
>> Fixes: ce0887ac96d3 ("NFSD add nfs4 inter ssc to nfsd4_copy")
>> Fixes: 87689df69491 ("NFSD: Shrink size of struct nfsd4_copy")
>> Signed-off-by: Dai Ngo <dai.ngo@oracle.com>
>> ---
>> fs/nfsd/nfs4proc.c | 12 ++++++++----
>> fs/nfsd/nfs4state.c | 5 +++--
>> 2 files changed, 11 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
>> index 57f791899de3..0754b38d3a43 100644
>> --- a/fs/nfsd/nfs4proc.c
>> +++ b/fs/nfsd/nfs4proc.c
>> @@ -1687,9 +1687,12 @@ static void cleanup_async_copy(struct nfsd4_copy *copy)
>> {
>> nfs4_free_copy_state(copy);
>> release_copy_files(copy);
>> - spin_lock(©->cp_clp->async_lock);
>> - list_del(©->copies);
>> - spin_unlock(©->cp_clp->async_lock);
>> + if (copy->cp_clp) {
>> + spin_lock(©->cp_clp->async_lock);
>> + if (!list_empty(©->copies))
>> + list_del(©->copies);
>
> Can we make this a list_del_init? If cleanup_async_copy were called on
> this twice, then the second time could end up corrupting the
> async_copies list. The cost difference is negligible here.
I noticed this yesterday and made the change in my tree.
>> + spin_unlock(©->cp_clp->async_lock);
>> + }
>> nfs4_put_copy(copy);
>> }
>>
>> @@ -1786,12 +1789,13 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
>> async_copy = kzalloc(sizeof(struct nfsd4_copy), GFP_KERNEL);
>> if (!async_copy)
>> goto out_err;
>> + INIT_LIST_HEAD(&async_copy->copies);
>> + refcount_set(&async_copy->refcount, 1);
>> async_copy->cp_src = kmalloc(sizeof(*async_copy->cp_src), GFP_KERNEL);
>> if (!async_copy->cp_src)
>> goto out_err;
>> if (!nfs4_init_copy_state(nn, copy))
>> goto out_err;
>> - refcount_set(&async_copy->refcount, 1);
>> memcpy(©->cp_res.cb_stateid, ©->cp_stateid.cs_stid,
>> sizeof(copy->cp_res.cb_stateid));
>> dup_copy_fields(copy, async_copy);
>> diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
>> index ace02fd0d590..c39e43742dd6 100644
>> --- a/fs/nfsd/nfs4state.c
>> +++ b/fs/nfsd/nfs4state.c
>> @@ -975,7 +975,6 @@ static int nfs4_init_cp_state(struct nfsd_net *nn, copy_stateid_t *stid,
>>
>> stid->cs_stid.si_opaque.so_clid.cl_boot = (u32)nn->boot_time;
>> stid->cs_stid.si_opaque.so_clid.cl_id = nn->s2s_cp_cl_id;
>> - stid->cs_type = cs_type;
>>
>> idr_preload(GFP_KERNEL);
>> spin_lock(&nn->s2s_cp_lock);
>> @@ -986,6 +985,7 @@ static int nfs4_init_cp_state(struct nfsd_net *nn, copy_stateid_t *stid,
>> idr_preload_end();
>> if (new_id < 0)
>> return 0;
>> + stid->cs_type = cs_type;
>> return 1;
>> }
>>
>> @@ -1019,7 +1019,8 @@ void nfs4_free_copy_state(struct nfsd4_copy *copy)
>> {
>> struct nfsd_net *nn;
>>
>> - WARN_ON_ONCE(copy->cp_stateid.cs_type != NFS4_COPY_STID);
>> + if (copy->cp_stateid.cs_type != NFS4_COPY_STID)
>> + return;
>
> It's probably fine to keep the WARN_ON_ONCE here. You're testing the
> condition anyway so you can do:
>
> if (WARN_ON_ONCE(copy->cp_stateid.cs_type != NFS4_COPY_STID))
Six of one...
I'm OK leaving the WARN out, it doesn't seem high value to me.
>> nn = net_generic(copy->cp_clp->net, nfsd_net_id);
>> spin_lock(&nn->s2s_cp_lock);
>> idr_remove(&nn->s2s_cp_stateids,
>
> --
> Jeff Layton <jlayton@kernel.org>
--
Chuck Lever
prev parent reply other threads:[~2023-01-31 14:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-29 4:44 [PATCH v2 1/1] NFSD: fix problems with cleanup on errors in nfsd4_copy Dai Ngo
2023-01-31 13:36 ` Jeff Layton
2023-01-31 14:27 ` Chuck Lever III [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E130FEB9-BAC4-42FF-8DC6-9769A0933832@oracle.com \
--to=chuck.lever@oracle.com \
--cc=aglo@umich.edu \
--cc=dai.ngo@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox