From patchwork Mon Sep 30 16:46:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13816709 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 501681946AA for ; Mon, 30 Sep 2024 16:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714810; cv=none; b=Ht0lWWRmrc98nVb/DP03s/LcYHfwjg/n4AUmTIHr8OX9CmjfvwnSOKs0sFHNQWipiPbQwXw4Y29FhPS8oiG8oPuELMzdxr9YGWkmlOISlWnqmXNhtzH3WrhPdKekzDM9pnSIsOAb+Y8w6PxLabrHMs8f1KgbMV9w6fEKjZxcSew= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714810; c=relaxed/simple; bh=Zb7197YfQ1LtCHlCEuSs83CLgWL9vDqTe3kpj30t1aU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K0iMxhNmTPlgD+e8aKn0qJX1oJ9tmhovrXxYZmpyzJORHBsxm/r5zUF4imcywiSVLGxanIT73iH7BcSpQINdHk1b79sVrFqayuuzv79yQpfP/wh3KhK7Qc6zWTPOOZ1ZQinh7Fi/h8BPyvXn/0HRii7EXTiyAm9cs9cm9YM9GwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.222.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-7ae491dacaeso216966785a.0 for ; Mon, 30 Sep 2024 09:46:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727714805; x=1728319605; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Jaa8pTMl+D82RaEzEBQKGKge5rXQ6ce3oiw9nF6IRA=; b=DgizOqStw+XxW18Jh527W1Ue6xS8SVbL0YNek8vIZ0dplfmkSAqFDcRpqAmLqqFac2 Woz0ADKEiXK3G2O8J9eHeBJ48rm/HjM+H/suhcO9amPhCCeUAR6apW3hhycJGCmQlnME oozwVGvfO0eC6wU3JCWp7847TMMQu1Vf+sSockB86kAwTp5BwjpEhp5dhnf8w4aVgYik CKwDcD15gbfutrJIy+A5GTaS07fii+249SeGRoNhCHZ2VGsgLjLQ00pZzUbgofl95zM9 Bfm+YBBIb4snBuF378HUzcofOaMZ6vGDGTKvjwmsQ51d/imBAykfAkLp/cqOKrIYCO2o TRnQ== X-Gm-Message-State: AOJu0Ywj4TJAO5aILzDfRi5/aNZLCI0F1L1KRxTQLlm+4d60HZgsLeoH jkDvd11iG1F+IqZWfPDqYx4fx7UQPR8AF8gjQfUHGDRrZS3d2sOkwtlk+HR3M18cgBgaY23HFyh 9WIrnrzk7Am973e42VKpq3AEv+AVOphGNiz8uclkks67t9kWYx9u918cWBdYQnAQ9Q6Ad1bI57z CEwPd7so30NOKWlodQt0f0pcHmibNg8hnmv2iJs+w= X-Google-Smtp-Source: AGHT+IGB18ynqGISsGgKTtC35akWh+vg6ooGj5uOLlF18K2l4OEdE7rKdeDCXOKznZpSSONKzO4P/w== X-Received: by 2002:a05:620a:2544:b0:7a9:ac2d:597d with SMTP id af79cd13be357-7ae378dd8fbmr1875268185a.56.1727714805146; Mon, 30 Sep 2024 09:46:45 -0700 (PDT) Received: from localhost (pool-68-160-145-92.bstnma.fios.verizon.net. [68.160.145.92]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7ae377f0a29sm427096385a.63.2024.09.30.09.46.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 09:46:42 -0700 (PDT) From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Anna Schumaker , Trond Myklebust , NeilBrown , Matthew Wilcox Subject: [6.12-rc2 PATCH 1/5] nfs_common: fix race in NFS calls to nfsd_file_put_local() and nfsd_serv_put() Date: Mon, 30 Sep 2024 12:46:33 -0400 Message-ID: <20240930164637.8300-2-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240930164637.8300-1-snitzer@kernel.org> References: <20240930164637.8300-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add nfs_to_nfsd_file_put_local() interface to fix race with nfsd module unload. Similarly, use RCU around nfs_open_local_fh()'s error path call to nfs_to->nfsd_serv_put(). Holding RCU ensures that NFS will safely _call and return_ from its nfs_to calls into the NFSD functions nfsd_file_put_local() and nfsd_serv_put(). Otherwise, if RCU isn't used then there is a narrow window when NFS's reference for the nfsd_file and nfsd_serv are dropped and the NFSD module could be unloaded, which could result in a crash from the return instruction for either nfs_to->nfsd_file_put_local() or nfs_to->nfsd_serv_put(). Reported-by: NeilBrown Signed-off-by: Mike Snitzer --- fs/nfs/localio.c | 6 +++--- fs/nfs_common/nfslocalio.c | 5 ++++- fs/nfsd/filecache.c | 2 +- fs/nfsd/localio.c | 2 +- fs/nfsd/nfssvc.c | 4 ++-- include/linux/nfslocalio.h | 15 +++++++++++++++ 6 files changed, 26 insertions(+), 8 deletions(-) diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index c29cdf51c458..d124c265b8fd 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -341,7 +341,7 @@ nfs_local_pgio_release(struct nfs_local_kiocb *iocb) { struct nfs_pgio_header *hdr = iocb->hdr; - nfs_to->nfsd_file_put_local(iocb->localio); + nfs_to_nfsd_file_put_local(iocb->localio); nfs_local_iocb_free(iocb); nfs_local_hdr_release(hdr, hdr->task.tk_ops); } @@ -622,7 +622,7 @@ int nfs_local_doio(struct nfs_client *clp, struct nfsd_file *localio, } out: if (status != 0) { - nfs_to->nfsd_file_put_local(localio); + nfs_to_nfsd_file_put_local(localio); hdr->task.tk_status = status; nfs_local_hdr_release(hdr, call_ops); } @@ -673,7 +673,7 @@ nfs_local_release_commit_data(struct nfsd_file *localio, struct nfs_commit_data *data, const struct rpc_call_ops *call_ops) { - nfs_to->nfsd_file_put_local(localio); + nfs_to_nfsd_file_put_local(localio); call_ops->rpc_call_done(&data->task, data); call_ops->rpc_release(data); } diff --git a/fs/nfs_common/nfslocalio.c b/fs/nfs_common/nfslocalio.c index 42b479b9191f..5c8ce5066c16 100644 --- a/fs/nfs_common/nfslocalio.c +++ b/fs/nfs_common/nfslocalio.c @@ -142,8 +142,11 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *uuid, /* We have an implied reference to net thanks to nfsd_serv_try_get */ localio = nfs_to->nfsd_open_local_fh(net, uuid->dom, rpc_clnt, cred, nfs_fh, fmode); - if (IS_ERR(localio)) + if (IS_ERR(localio)) { + rcu_read_lock(); nfs_to->nfsd_serv_put(net); + rcu_read_unlock(); + } return localio; } EXPORT_SYMBOL_GPL(nfs_open_local_fh); diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 19bb88c7eebd..53070e1de3d9 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -398,7 +398,7 @@ nfsd_file_put(struct nfsd_file *nf) * reference to the associated nn->nfsd_serv. */ void -nfsd_file_put_local(struct nfsd_file *nf) +nfsd_file_put_local(struct nfsd_file *nf) __must_hold(rcu) { struct net *net = nf->nf_net; diff --git a/fs/nfsd/localio.c b/fs/nfsd/localio.c index 291e9c69cae4..f441cb9f74d5 100644 --- a/fs/nfsd/localio.c +++ b/fs/nfsd/localio.c @@ -53,7 +53,7 @@ void nfsd_localio_ops_init(void) * * On successful return, returned nfsd_file will have its nf_net member * set. Caller (NFS client) is responsible for calling nfsd_serv_put and - * nfsd_file_put (via nfs_to->nfsd_file_put_local). + * nfsd_file_put (via nfs_to_nfsd_file_put_local). */ struct nfsd_file * nfsd_open_local_fh(struct net *net, struct auth_domain *dom, diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c index e236135ddc63..47172b407be8 100644 --- a/fs/nfsd/nfssvc.c +++ b/fs/nfsd/nfssvc.c @@ -214,14 +214,14 @@ int nfsd_minorversion(struct nfsd_net *nn, u32 minorversion, enum vers_op change return 0; } -bool nfsd_serv_try_get(struct net *net) +bool nfsd_serv_try_get(struct net *net) __must_hold(rcu) { struct nfsd_net *nn = net_generic(net, nfsd_net_id); return (nn && percpu_ref_tryget_live(&nn->nfsd_serv_ref)); } -void nfsd_serv_put(struct net *net) +void nfsd_serv_put(struct net *net) __must_hold(rcu) { struct nfsd_net *nn = net_generic(net, nfsd_net_id); diff --git a/include/linux/nfslocalio.h b/include/linux/nfslocalio.h index b353abe00357..b0dd9b1eef4f 100644 --- a/include/linux/nfslocalio.h +++ b/include/linux/nfslocalio.h @@ -65,10 +65,25 @@ struct nfsd_file *nfs_open_local_fh(nfs_uuid_t *, struct rpc_clnt *, const struct cred *, const struct nfs_fh *, const fmode_t); +static inline void nfs_to_nfsd_file_put_local(struct nfsd_file *localio) +{ + /* + * Once reference to nfsd_serv is dropped, NFSD could be + * unloaded, so ensure safe return from nfsd_file_put_local() + * by always taking RCU. + */ + rcu_read_lock(); + nfs_to->nfsd_file_put_local(localio); + rcu_read_unlock(); +} + #else /* CONFIG_NFS_LOCALIO */ static inline void nfsd_localio_ops_init(void) { } +static inline void nfs_to_nfsd_file_put_local(struct nfsd_file *localio) +{ +} #endif /* CONFIG_NFS_LOCALIO */ #endif /* __LINUX_NFSLOCALIO_H */ From patchwork Mon Sep 30 16:46:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13816710 Received: from mail-qv1-f54.google.com (mail-qv1-f54.google.com [209.85.219.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 68DEC195805 for ; Mon, 30 Sep 2024 16:46:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714813; cv=none; b=mhcmHr6BRAVBYGOHjKh1YsJ7eAlDDHsK1swfWuygm/rT4jCrmXHvSnHoV9+vkgbVhC+GXUA/KX6u6y3D2eMwoVzf3Ku2VTw7I4GqetJBRP13HfR9n4QTAgOpNQY2qTfzRGWL8fy391z/fgZsZdyM+XU0FvJxJyS771/IQefxQ/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714813; c=relaxed/simple; bh=dO9gozPdQl2OhaD5p9iHUgs5avHYX0qx6mcdaqSzgvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Csc0O3KJuiixusBMk57xTbGem8UZMll6VMaGqATiGNxne6HXwJhM/FqwPdNYOjFEe9ukCiqFTx3AkWHAllFELOZI1Dgk5EcplEInueLcRMmovqCSasLs1oJeRExQ4HgXesrw8OVtCQOAzNRMDQ/h+K1JXbjaJy8aKJ3PNArqlEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.219.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-qv1-f54.google.com with SMTP id 6a1803df08f44-6cb399056b4so34454836d6.0 for ; Mon, 30 Sep 2024 09:46:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727714809; x=1728319609; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yYd3ZPfO1PQXNlVSLH8W9udmGwHGxWcACHmAcODqJLM=; b=rAh+0xyqjyEciHSHa2Siy6XhFvWXwBAH+Zv0KWEdgiCXNtTtz7tKP5p/Lrlr6n1POQ 8pT88WoNF7vru9yTkpBev5HGFWbGspYFS0/RuX63hnIjI7UqwzFWXQDspgYoPtMI9zEP rteAFBrqdXqh9fxmOjjmI3kZpe1jEh6/iT6M1LHVrB0aHWGRTAYjRqo+00B5abH6qB0g OrtLhJKI73PWwPDk4qR4uDoo73iscwG1ZZuZpJaArCkimAOKXIdrhuRLT6ggyMdutkZ0 uFfBY0qmCFKlXXHSh8pFYb8fLm+bwIqyt99zAqE+00jUj2PfYL5z4ydteyjjMQ8+yf5G tajQ== X-Gm-Message-State: AOJu0Yy+ZfBPeKTDn1zEGIV5gL+t8RhJzXChB62avqJr7VNdmfOhGJBX eIZRRYn6ldPEtBX5nWzo3+F9ene+CGibaAF3iXfbXwVBG2mz/qSKkWAPEVOzFRgeWhaYDt2qlZ+ 4hr2wOXK6R50ZlLhBP+TqRkQJPILGW45J/VMcZ2cMMrTrGfnSAmvYyrarE2NEjKGDY9FfhK2QZU HDygaf7s/toaxu99mD+zX4SJC/HOBikYUW4K+AH48= X-Google-Smtp-Source: AGHT+IFj47mqr6DVEXs2TLgsan/Hd2OR1wD4l7fdxY8pYFTxR/4V3ypHwlLSpM8KeDZxVvTb40AhLw== X-Received: by 2002:a05:6214:5902:b0:6cb:4625:983 with SMTP id 6a1803df08f44-6cb462513a5mr197908666d6.7.1727714808710; Mon, 30 Sep 2024 09:46:48 -0700 (PDT) Received: from localhost (pool-68-160-145-92.bstnma.fios.verizon.net. [68.160.145.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb3b68e7fesm41324516d6.132.2024.09.30.09.46.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 09:46:46 -0700 (PDT) From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Anna Schumaker , Trond Myklebust , NeilBrown , Matthew Wilcox Subject: [6.12-rc2 PATCH 2/5] nfs/localio: remove redundant suid/sgid handling Date: Mon, 30 Sep 2024 12:46:34 -0400 Message-ID: <20240930164637.8300-3-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240930164637.8300-1-snitzer@kernel.org> References: <20240930164637.8300-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mike Snitzer nfs_writeback_done() will take care of suid/sgid corner case. Signed-off-by: Mike Snitzer --- fs/nfs/localio.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index d124c265b8fd..88b6658b93fc 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -521,12 +521,7 @@ nfs_local_write_done(struct nfs_local_kiocb *iocb, long status) } if (status < 0) nfs_reset_boot_verifier(inode); - else if (nfs_should_remove_suid(inode)) { - /* Deal with the suid/sgid bit corner case */ - spin_lock(&inode->i_lock); - nfs_set_cache_invalid(inode, NFS_INO_INVALID_MODE); - spin_unlock(&inode->i_lock); - } + nfs_local_pgio_done(hdr, status); } From patchwork Mon Sep 30 16:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13816711 Received: from mail-qt1-f174.google.com (mail-qt1-f174.google.com [209.85.160.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 894AC18EB0 for ; Mon, 30 Sep 2024 16:46:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714816; cv=none; b=CDrAqmFB2qAUDVLHWvwpcIUD3212Vw1iIMhl/wTh8s/TBiR9RMRSbnUbYvpEIZMDqdiZFw7D2EfF12yAJO61EgwlSd0yr0sHGW9NYjCthWj1jPj2KsI+jYjadlsiWUXV8NWj40YKjrt/vc/PIj7S4yEhQZHZDFTro/FK55TSrxc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714816; c=relaxed/simple; bh=7ldDcdObu85WuKTz+1DDacI/L7k70lt+f+X9H03hq7M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sy86qV9Rk6VHplf5OL2a2zFDCqJKQGqdkkXzxXNtXL24y3UxWdKNhhD1EHTITMvHXxN8EUW4Fh47v4AsHfTA9UGXI4R8GSaOGIteCHSGPWq1fMEN89LYsNVkLPfyu+Y8dY+y1K/R6Q60JVVYduP0WOhR66xO1UgBBEoS+fi2b/o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.160.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-qt1-f174.google.com with SMTP id d75a77b69052e-4582face04dso42712221cf.1 for ; Mon, 30 Sep 2024 09:46:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727714812; x=1728319612; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zSVobspXebR8qHRQIs3lV5zVmfvjvUl8vp8qouzXXDM=; b=rBrAsnUUdUBCgmwVOQgYzpbAVV/m2V8aqQoAoF+ZCDQJ/PoE2Ib4Be7z/5kh2JYVGd bJuKZ/QUz43AsxxX4ZwXl5POL2ChBDaMlL0pGHl1nNH6bmx2Yan15s7ngKolnaSxVZLo KFp+ytjV1WZFaxTlWSVPSx15QYEyaHsNkqhH6MSQ0jeBOr1tNgGCYkMtb0K648ze21Td 9XUF2ceDF+vcXlhlOyKjvo7Zz49rq6NprRVsnUIL08dTtIVqFSxuv27m18WyGU/iYtf4 viNp53zHQUPcCakcce5Lon7aqunGFzIxO49d58+VaB8kv7IXU/mXaX6Eg/E9bGCE2vq6 E0Mw== X-Gm-Message-State: AOJu0YwYK+B+RBacFOU0Xr7mty97fUaO/RjFxKM9hJRGvx6V0eTEsgt7 Pa1jwFQc3YVkYcM1o7nbXoTjRlQa0CElFku8xfozIttxn8MeOh9q97efCFQ7KsTLGhcLodZKvtS MSrPmeeHeU0HDpPeajGh1+kZBiD/nPUfGLdgiXS6ys/eCmJZzYDxCh88WyAvCKvGO4K2T9V5jTC YTKVn2OU6i9Lk8M46a+alzfv3BGFhb7SnI37pyt50= X-Google-Smtp-Source: AGHT+IEonzlFKAkvwWK91j/VlQMr4rnogSCQ/cn0uhNFZ+mwd7Wv/pvl/vc0/5AXb0hRmm6oiHIA3g== X-Received: by 2002:ac8:5250:0:b0:45d:7416:1636 with SMTP id d75a77b69052e-45d74161665mr660241cf.2.1727714812521; Mon, 30 Sep 2024 09:46:52 -0700 (PDT) Received: from localhost (pool-68-160-145-92.bstnma.fios.verizon.net. [68.160.145.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45c9f2b6dabsm37744601cf.27.2024.09.30.09.46.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 09:46:50 -0700 (PDT) From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Anna Schumaker , Trond Myklebust , NeilBrown , Matthew Wilcox Subject: [6.12-rc2 PATCH 3/5] nfs/localio: eliminate unnecessary kref in nfs_local_fsync_ctx Date: Mon, 30 Sep 2024 12:46:35 -0400 Message-ID: <20240930164637.8300-4-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240930164637.8300-1-snitzer@kernel.org> References: <20240930164637.8300-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 nfs_local_commit() doesn't need async cleanup of nfs_local_fsync_ctx, so there is no need to use a kref. Signed-off-by: Mike Snitzer --- fs/nfs/localio.c | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index 88b6658b93fc..2f302b03b253 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -43,7 +43,6 @@ struct nfs_local_fsync_ctx { struct nfsd_file *localio; struct nfs_commit_data *data; struct work_struct work; - struct kref kref; struct completion *done; }; static void nfs_local_fsync_work(struct work_struct *work); @@ -683,30 +682,17 @@ nfs_local_fsync_ctx_alloc(struct nfs_commit_data *data, ctx->localio = localio; ctx->data = data; INIT_WORK(&ctx->work, nfs_local_fsync_work); - kref_init(&ctx->kref); ctx->done = NULL; } return ctx; } -static void -nfs_local_fsync_ctx_kref_free(struct kref *kref) -{ - kfree(container_of(kref, struct nfs_local_fsync_ctx, kref)); -} - -static void -nfs_local_fsync_ctx_put(struct nfs_local_fsync_ctx *ctx) -{ - kref_put(&ctx->kref, nfs_local_fsync_ctx_kref_free); -} - static void nfs_local_fsync_ctx_free(struct nfs_local_fsync_ctx *ctx) { nfs_local_release_commit_data(ctx->localio, ctx->data, ctx->data->task.tk_ops); - nfs_local_fsync_ctx_put(ctx); + kfree(ctx); } static void @@ -739,7 +725,7 @@ int nfs_local_commit(struct nfsd_file *localio, } nfs_local_init_commit(data, call_ops); - kref_get(&ctx->kref); + if (how & FLUSH_SYNC) { DECLARE_COMPLETION_ONSTACK(done); ctx->done = &done; @@ -747,6 +733,6 @@ int nfs_local_commit(struct nfsd_file *localio, wait_for_completion(&done); } else queue_work(nfsiod_workqueue, &ctx->work); - nfs_local_fsync_ctx_put(ctx); + return 0; } From patchwork Mon Sep 30 16:46:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13816712 Received: from mail-oo1-f44.google.com (mail-oo1-f44.google.com [209.85.161.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FA5C1925B8 for ; Mon, 30 Sep 2024 16:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714820; cv=none; b=EFeqQ/w7HjbCdzAEOlpTYfzU4iOZr0VtHVugUL/rtcRiknX23tubk7tYsfqilpN6aERdWgQ6MCQeofYHl+ET0yXX71/ue4iZxTV9KNtMZo7job/FpCSSmZ/gEvyHNTOfqa8vJX1ecNxeSVFPmloQbawTusFiiJ4I2KzXsWFOLAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714820; c=relaxed/simple; bh=g4o1E9ZHJpVvV8UBqlxcay2i9cSQlVEOIAKY8yV+YOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Er9eoN6non19uTQnDnM2sIg1z8tD+DQx8lGjkDw01LwNoPhvYXgqAhucHNb8ftEQTJDWj6tKi/AhDdJEz7xYblUYgwUFeDdTg6fds8xa+5+Ol4xpiI1XjA+44rU26w1pVnHO+iTdqjcI6gsIPODQBumYAimCu+26FmJs+CaBW3Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.161.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-oo1-f44.google.com with SMTP id 006d021491bc7-5e5a0519d00so1967388eaf.3 for ; Mon, 30 Sep 2024 09:46:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727714816; x=1728319616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AuxEtvCgukHFh6jS8SFvx09qDMSBGl7szdlF1CL/XHs=; b=TpdrSEheoaHMQO0KP2tZwQjv+OWUK+oulrktMmmNkYjgBpZYbwaeZ8jkGObVBSJidJ JaA5yG8zddNmVWF+uXOCyqJsL3wCROeZpV+re3p716+qAG+/vJcTuS0F6T+0i1WBkFUG ckiv/Adow3zOCCtglbmIus+40I1D6ojhWOLnTq/9ZvQZ3mOUsLaEpcpNZ9jcAYG1mNmu BBxDfHI9IlMpDeoGUeyLZD86pPU+yC5yq3jNPSfrnuUY2XN2V94EGHTCgcUDQ+tFcyNd HgqQqakY0UaNe8tQxbx0isU5sF2Vem+57VGQs0hYuiSVcOP1mYZ90WAdO0iQyPeGF5Ll hqIQ== X-Gm-Message-State: AOJu0YxuyWnLUa8RI08lszGfcbpKseJ4mTLF/g1yGkYVUQiM34eDhntC GFzBKB5SkGDhvPYGEIH0zSAfCWiRqIgtbcXB2dnRa8j/CFL4LXoUdsC12AGfDFtzO+pPceLZMrn h9HhFexJ+v8ERHiihW+8o7O7410FBS56x03l94FRsoz+SPOVocz2QvWBt5zSv3LauP5z4JlR0gX A5YLWBLgcPvwZDZqsklpcWcR3IlWpkg2yEWHtj4ZM= X-Google-Smtp-Source: AGHT+IHWaD5jRZjbNuRnDtyZMrwEEULCWIT/oUkQp8k4yLe4yh7H5HeDalrNszt9N8t2foTJKEXyVQ== X-Received: by 2002:a05:6358:54a6:b0:1af:7e6e:4bbc with SMTP id e5c5f4694b2df-1becbb67813mr354913355d.10.1727714816112; Mon, 30 Sep 2024 09:46:56 -0700 (PDT) Received: from localhost (pool-68-160-145-92.bstnma.fios.verizon.net. [68.160.145.92]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-45c9f2b6dabsm37745051cf.27.2024.09.30.09.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 09:46:54 -0700 (PDT) From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Anna Schumaker , Trond Myklebust , NeilBrown , Matthew Wilcox Subject: [6.12-rc2 PATCH 4/5] nfs/localio: remove extra indirect nfs_to call to check {read,write}_iter Date: Mon, 30 Sep 2024 12:46:36 -0400 Message-ID: <20240930164637.8300-5-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240930164637.8300-1-snitzer@kernel.org> References: <20240930164637.8300-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Push the read_iter and write_iter availability checks down to nfs_do_local_read and nfs_do_local_write respectively. This eliminates a redundant nfs_to->nfsd_file_file() call. Signed-off-by: Mike Snitzer --- fs/nfs/localio.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index 2f302b03b253..12d3e200156c 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -273,7 +273,7 @@ nfs_local_iocb_free(struct nfs_local_kiocb *iocb) static struct nfs_local_kiocb * nfs_local_iocb_alloc(struct nfs_pgio_header *hdr, - struct nfsd_file *localio, gfp_t flags) + struct file *file, gfp_t flags) { struct nfs_local_kiocb *iocb; @@ -286,9 +286,8 @@ nfs_local_iocb_alloc(struct nfs_pgio_header *hdr, kfree(iocb); return NULL; } - init_sync_kiocb(&iocb->kiocb, nfs_to->nfsd_file_file(localio)); + init_sync_kiocb(&iocb->kiocb, file); iocb->kiocb.ki_pos = hdr->args.offset; - iocb->localio = localio; iocb->hdr = hdr; iocb->kiocb.ki_flags &= ~IOCB_APPEND; return iocb; @@ -389,13 +388,19 @@ nfs_do_local_read(struct nfs_pgio_header *hdr, const struct rpc_call_ops *call_ops) { struct nfs_local_kiocb *iocb; + struct file *file = nfs_to->nfsd_file_file(localio); + + /* Don't support filesystems without read_iter */ + if (!file->f_op->read_iter) + return -EAGAIN; dprintk("%s: vfs_read count=%u pos=%llu\n", __func__, hdr->args.count, hdr->args.offset); - iocb = nfs_local_iocb_alloc(hdr, localio, GFP_KERNEL); + iocb = nfs_local_iocb_alloc(hdr, file, GFP_KERNEL); if (iocb == NULL) return -ENOMEM; + iocb->localio = localio; nfs_local_pgio_init(hdr, call_ops); hdr->res.eof = false; @@ -558,14 +563,20 @@ nfs_do_local_write(struct nfs_pgio_header *hdr, const struct rpc_call_ops *call_ops) { struct nfs_local_kiocb *iocb; + struct file *file = nfs_to->nfsd_file_file(localio); + + /* Don't support filesystems without write_iter */ + if (!file->f_op->write_iter) + return -EAGAIN; dprintk("%s: vfs_write count=%u pos=%llu %s\n", __func__, hdr->args.count, hdr->args.offset, (hdr->args.stable == NFS_UNSTABLE) ? "unstable" : "stable"); - iocb = nfs_local_iocb_alloc(hdr, localio, GFP_NOIO); + iocb = nfs_local_iocb_alloc(hdr, file, GFP_NOIO); if (iocb == NULL) return -ENOMEM; + iocb->localio = localio; switch (hdr->args.stable) { default: @@ -591,16 +602,9 @@ int nfs_local_doio(struct nfs_client *clp, struct nfsd_file *localio, const struct rpc_call_ops *call_ops) { int status = 0; - struct file *filp = nfs_to->nfsd_file_file(localio); if (!hdr->args.count) return 0; - /* Don't support filesystems without read_iter/write_iter */ - if (!filp->f_op->read_iter || !filp->f_op->write_iter) { - nfs_local_disable(clp); - status = -EAGAIN; - goto out; - } switch (hdr->rw_mode) { case FMODE_READ: @@ -614,8 +618,10 @@ int nfs_local_doio(struct nfs_client *clp, struct nfsd_file *localio, hdr->rw_mode); status = -EINVAL; } -out: + if (status != 0) { + if (status == -EAGAIN) + nfs_local_disable(clp); nfs_to_nfsd_file_put_local(localio); hdr->task.tk_status = status; nfs_local_hdr_release(hdr, call_ops); From patchwork Mon Sep 30 16:46:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Snitzer X-Patchwork-Id: 13816713 Received: from mail-vs1-f43.google.com (mail-vs1-f43.google.com [209.85.217.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 778BB18EB0 for ; Mon, 30 Sep 2024 16:47:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.217.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714823; cv=none; b=N2ftyvAd8ZeHp5Id3qoOjDdKuK0VeFEFqPQpCPnRVsEzDXscvd6cOYealB/XzHB1TlAJVpRcixOPAdxW7rBdlFLjm9HhOVX+LkGsXrWluMeTYP7yDydd8absM0WyCcw4dXdM4vhBHKuB2BEfbkOL8E9MgNOwYEldbwsMN1NR6dU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727714823; c=relaxed/simple; bh=wf+uxwVhQ23mgHRQ1/toeoe9veu4h6XUqaiUyiHud5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CSmg6OtZj5kFeu+T4+Ye5pMl5QXVUGxMso2NbxY9shv6PX51N/YpRk5reVq5HHK7u2TEtyeyZRh7SJAGWjLaCESaNwwAY8VpIKJLxThLwHDBnjXsDmITh63MH9IMcEGw3ZXd0kL2qrzWfDgUGihlz/QKDacuxCHfSVr5C1m09Bk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.217.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-vs1-f43.google.com with SMTP id ada2fe7eead31-4a3a8cef4d2so846748137.0 for ; Mon, 30 Sep 2024 09:47:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727714819; x=1728319619; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LWDhj2bMDWCX0Wn/uG71cVjb4CiZW/kucpfpijmbd7Q=; b=jQV7a0+ptnY1mLt8YRE0HPA/iLtb/xgm3i2B3di22dRXxjovw6sWdF8fLrcEaW5J+I gFkYm4/8DTiMxrQugyu68YsiiMI5d+3U55MXYj1rc41RYXxucV0AloLcxLXaipJ2EyWi qsaLNJ6ZVJBbFO+kl74kvSU/6Ahn+WD1Cgz3dUQ0hmkI5CZWHEjcW3dK+S6CxFcWulaM j41jf+rA/W/yJmdQjG5ifwClRWDvVPZ4Bv9jsmAYDICNqu8KvGz0o9qXjalKo+amQrLH F3ZKVSk1V4abNJEHBaNYK+ZvJ/X7WITCI4I0vdco3SwwAfd+jgO9xYydNeh87xlhEY98 vS4Q== X-Gm-Message-State: AOJu0YwX7ISDRQeT7TfQ01NPno/nE7Ta9GvTITC/i2iITv7Xw2YukZTQ PS/0N3PwC5z5aA8iDFhak6vKRajJbRNBmOVJknVUxCp/0TuN/jGC99sp29uoWIujkknBzZj21vq /Js7CMWvoWE0l67ymlzXarnl1iav6hY/MampmK2p/Dh0YeLhh0bixO/7dGPC4prCYUStdEGae/c j80WLvhirewWOOmLF96tx00Y4cE0KZsjKbF1z0zcY= X-Google-Smtp-Source: AGHT+IEAahnuyoWmalkgMw4fQvQGtXxDyDwVPaJ9B7LccR2Lu+nE64jGm7VHdll8UZhOYUvAkev7kg== X-Received: by 2002:a05:6102:41a3:b0:4a3:cdfb:5926 with SMTP id ada2fe7eead31-4a3cdfb5d80mr2002251137.4.1727714818708; Mon, 30 Sep 2024 09:46:58 -0700 (PDT) Received: from localhost (pool-68-160-145-92.bstnma.fios.verizon.net. [68.160.145.92]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cb3b610b12sm41363436d6.39.2024.09.30.09.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2024 09:46:57 -0700 (PDT) From: Mike Snitzer To: linux-nfs@vger.kernel.org Cc: Jeff Layton , Chuck Lever , Anna Schumaker , Trond Myklebust , NeilBrown , Matthew Wilcox Subject: [6.12-rc2 PATCH 5/5] nfs/localio: eliminate need for nfs_local_fsync_work forward declaration Date: Mon, 30 Sep 2024 12:46:37 -0400 Message-ID: <20240930164637.8300-6-snitzer@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240930164637.8300-1-snitzer@kernel.org> References: <20240930164637.8300-1-snitzer@kernel.org> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move nfs_local_fsync_ctx_alloc() after nfs_local_fsync_work(). Signed-off-by: Mike Snitzer --- fs/nfs/localio.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/fs/nfs/localio.c b/fs/nfs/localio.c index 12d3e200156c..98cd572426b4 100644 --- a/fs/nfs/localio.c +++ b/fs/nfs/localio.c @@ -45,7 +45,6 @@ struct nfs_local_fsync_ctx { struct work_struct work; struct completion *done; }; -static void nfs_local_fsync_work(struct work_struct *work); static bool localio_enabled __read_mostly = true; module_param(localio_enabled, bool, 0644); @@ -678,21 +677,6 @@ nfs_local_release_commit_data(struct nfsd_file *localio, call_ops->rpc_release(data); } -static struct nfs_local_fsync_ctx * -nfs_local_fsync_ctx_alloc(struct nfs_commit_data *data, - struct nfsd_file *localio, gfp_t flags) -{ - struct nfs_local_fsync_ctx *ctx = kmalloc(sizeof(*ctx), flags); - - if (ctx != NULL) { - ctx->localio = localio; - ctx->data = data; - INIT_WORK(&ctx->work, nfs_local_fsync_work); - ctx->done = NULL; - } - return ctx; -} - static void nfs_local_fsync_ctx_free(struct nfs_local_fsync_ctx *ctx) { @@ -717,6 +701,21 @@ nfs_local_fsync_work(struct work_struct *work) nfs_local_fsync_ctx_free(ctx); } +static struct nfs_local_fsync_ctx * +nfs_local_fsync_ctx_alloc(struct nfs_commit_data *data, + struct nfsd_file *localio, gfp_t flags) +{ + struct nfs_local_fsync_ctx *ctx = kmalloc(sizeof(*ctx), flags); + + if (ctx != NULL) { + ctx->localio = localio; + ctx->data = data; + INIT_WORK(&ctx->work, nfs_local_fsync_work); + ctx->done = NULL; + } + return ctx; +} + int nfs_local_commit(struct nfsd_file *localio, struct nfs_commit_data *data, const struct rpc_call_ops *call_ops, int how)