From patchwork Wed Aug 14 20:38:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13763951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9392AC52D7F for ; Wed, 14 Aug 2024 20:39:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4FF276B008C; Wed, 14 Aug 2024 16:39:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37B676B0095; Wed, 14 Aug 2024 16:39:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1303F6B0092; Wed, 14 Aug 2024 16:39:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DEE776B008A for ; Wed, 14 Aug 2024 16:39:34 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 61B471C3F9A for ; Wed, 14 Aug 2024 20:39:34 +0000 (UTC) X-FDA: 82452016668.15.111EC4A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id AD1352000D for ; Wed, 14 Aug 2024 20:39:32 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cAkrRz5j; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723667876; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Wvz9YBrTPFQ9wVYP2d1umk84aV9uv83ek2O7Ma2LSP4=; b=aFoYzrfTjSjuhfxtRNC53jkr2qndgB7VjpwkzDbLcQq/KpxbXCz9RjWU3Z3amOKJVZoioO Y/IbR8xY9q79gL2E0LHFjKUA2SqGDp0sAr/hYkuYJqReOGmkkeJ4vkt/9qmVPgx+do0tcu ourxi2NRq7HFVD6Y6ucAHiJUZYewEU4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cAkrRz5j; spf=pass (imf13.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723667876; a=rsa-sha256; cv=none; b=11vK5kJKSS2gmZhzzwNRFRW6RUQ9BchjKuOjb8j5cr5R2OCX388UPxv8zAPFDEhp/fEFhm P/YVsBmdL/c/vmOiYDzvlTU8rZB+sLx7fdd/g/vB+pfreccx8MXcJA/Aw8qVX34Xfx+Dq8 OUD1QW47+mQeJoo0dL7Fg1j7OjnJZi8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723667971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Wvz9YBrTPFQ9wVYP2d1umk84aV9uv83ek2O7Ma2LSP4=; b=cAkrRz5jeFml2lKkjtHKRChufNeWs++hy+FNWdL2brKaIjsTw71tQDNRii0C5XDubAMbAF Q0eXg3JBBnY3epLV4pcnt6DPg/DJjByWVUDReix32Lds23ZFbviiwKAFLGEq0NLFlYPWZR JvmFwUB6iOZbnmNkU8mG1ZFF+aIfQlc= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-8-9QbQ7aiUNXWL2QCGcnXXHA-1; Wed, 14 Aug 2024 16:39:26 -0400 X-MC-Unique: 9QbQ7aiUNXWL2QCGcnXXHA-1 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4AA841954B10; Wed, 14 Aug 2024 20:39:19 +0000 (UTC) Received: from warthog.procyon.org.uk.com (unknown [10.42.28.30]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90C961955E8C; Wed, 14 Aug 2024 20:39:11 +0000 (UTC) From: David Howells To: Christian Brauner , Steve French , Matthew Wilcox Cc: David Howells , Jeff Layton , Gao Xiang , Dominique Martinet , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , netfs@lists.linux.dev, linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org, ceph-devel@vger.kernel.org, v9fs@lists.linux.dev, linux-erofs@lists.ozlabs.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Brauner , Gao Xiang Subject: [PATCH v2 02/25] cachefiles: Fix non-taking of sb_writers around set/removexattr Date: Wed, 14 Aug 2024 21:38:22 +0100 Message-ID: <20240814203850.2240469-3-dhowells@redhat.com> In-Reply-To: <20240814203850.2240469-1-dhowells@redhat.com> References: <20240814203850.2240469-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AD1352000D X-Stat-Signature: ewh58u3jdnxwz59s3itdkmj6wpnki1wg X-Rspam-User: X-HE-Tag: 1723667972-523499 X-HE-Meta: U2FsdGVkX1+6sxgSXUVBq8VccKcyDq2GD/tYQRlqZ+46X+TJ70JkV2ATxYDsYbD/IKnh3nFrvDwk86Bqd8n6fO//x5yrQnbU1bTllFEr6UG5g/bhXxgav7LwWKNwNfGOfgltvY/P5LYjZBlKeBpGoBMOWIYGoQ3I/zPMn9yKpUH49ZXzX0tASmiPgPa+Jq3n65KGKXJedABvOjgj+n58jr//UQRD+HzfjWtKw2Zv7cyVmUs1gMSmUjZjcN+n5ipanw9OOURPlTlytxABq0HBOJhknzX6JsZXyoEvWP2IGct20Dg87VHSQw353ExXLZlyHoFAhAJhIr1Hc9pPpvT6GGr7YMmh7mRV6K1chcKlejFbededvWf2+EuXp9UDJWd61jv14+j11++5VgNj6CzFd2F0o0awccN710wGRZEPFRBku9AMKpyRtmG1h7JyVdoxgPx0cePX4aMsi9ahK9iKXrLACl1gj9S5Aeh3S81f7w9FwWAL2xuO64Abshks8Q8pCU/jPX4iArVUA3MKzdHmrxACv0xbpJ31rQuAPvcVqocxYFhmxKpmOSpU5INPe5C+6h1yoxWT0K5bM/CoAxH5qd6L0pYSrMfwki5fV2KaLwIw5bypk+zEInJ55UXn4mPtFG9pQcMeFtwuLgs7D4oZ2rYYL5H6UGPyhC0FPol1Z278Wz8HceFMGchU9gAkbZlJDWycltQDsdZ3lHOTbHSrHYhyTSrRotUp3TTAax+N9zDo24C4iNK0NAZkzy4dhPzwLIE2ZuaYWJnxpMPy7q8lrCJEd4UWP4tXRuSscWH0wuDNUZiInGEvr4NEhHaKilwLzivctQlOYBlDRnKphKoa2HiX45GeQ7nILu8H7T48Z1IGXI06Yr6ImsfdYifc/wivqz7H6ya4Ij0+baN4rE826fnGSGlnrezpqyOwHLHJRYZb1C66S60FeAQ7PFDvCv2d4FgXPRYieP4EBdETKdY ht3jw2YR GoKOvHsaYlEcNNoa/ihgG147iGIwHjUwxvJkdpkv2B5b5E7mEc9Fp5TUY02HAtct6S51UQJoUO7SP/oS8NTFsoosXjz3j0yVQfjcaMQq4Vgh6cglR03cXZotV79+jbnZ2aPe4VALjIHldEwzgZfk8uuaC4xKtg4WicKGIQ0GdFCvX/Tw5WpuAbQTftyftIhd5b8yUL7cfI1b+3Sl76E2gUBN/i72OzWxhsp5PpliMr5X1bCPQF71RFwidfdIb1KlKQOZ56cOiOu+p8JbZG4PnZwnq3zlYUgUy/9VF1k3mPZqkM2Tj4G/LlJh2kvCUr9gxSKYmggmGHyhSr1W5zgb527pKuporBZQdSDFhTrnwOr5sxPm7GLaf76T1XOBk3o6Ly2BGRbZTpfA8/V2JqZrCXEPXjqZ2aoOOwB6W8T4VX5ua/kyAVUnWotMsXPKksWXGFmxFZb+MzqwphDKl0tIt9ewWIw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Unlike other vfs_xxxx() calls, vfs_setxattr() and vfs_removexattr() don't take the sb_writers lock, so the caller should do it for them. Fix cachefiles to do this. Fixes: 9ae326a69004 ("CacheFiles: A cache that backs onto a mounted filesystem") Signed-off-by: David Howells cc: Christian Brauner cc: Gao Xiang cc: netfs@lists.linux.dev cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org --- fs/cachefiles/xattr.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c index 4dd8a993c60a..7c6f260a3be5 100644 --- a/fs/cachefiles/xattr.c +++ b/fs/cachefiles/xattr.c @@ -64,9 +64,15 @@ int cachefiles_set_object_xattr(struct cachefiles_object *object) memcpy(buf->data, fscache_get_aux(object->cookie), len); ret = cachefiles_inject_write_error(); - if (ret == 0) - ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, - buf, sizeof(struct cachefiles_xattr) + len, 0); + if (ret == 0) { + ret = mnt_want_write_file(file); + if (ret == 0) { + ret = vfs_setxattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache, buf, + sizeof(struct cachefiles_xattr) + len, 0); + mnt_drop_write_file(file); + } + } if (ret < 0) { trace_cachefiles_vfs_error(object, file_inode(file), ret, cachefiles_trace_setxattr_error); @@ -151,8 +157,14 @@ int cachefiles_remove_object_xattr(struct cachefiles_cache *cache, int ret; ret = cachefiles_inject_remove_error(); - if (ret == 0) - ret = vfs_removexattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache); + if (ret == 0) { + ret = mnt_want_write(cache->mnt); + if (ret == 0) { + ret = vfs_removexattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache); + mnt_drop_write(cache->mnt); + } + } if (ret < 0) { trace_cachefiles_vfs_error(object, d_inode(dentry), ret, cachefiles_trace_remxattr_error); @@ -208,9 +220,15 @@ bool cachefiles_set_volume_xattr(struct cachefiles_volume *volume) memcpy(buf->data, p, volume->vcookie->coherency_len); ret = cachefiles_inject_write_error(); - if (ret == 0) - ret = vfs_setxattr(&nop_mnt_idmap, dentry, cachefiles_xattr_cache, - buf, len, 0); + if (ret == 0) { + ret = mnt_want_write(volume->cache->mnt); + if (ret == 0) { + ret = vfs_setxattr(&nop_mnt_idmap, dentry, + cachefiles_xattr_cache, + buf, len, 0); + mnt_drop_write(volume->cache->mnt); + } + } if (ret < 0) { trace_cachefiles_vfs_error(NULL, d_inode(dentry), ret, cachefiles_trace_setxattr_error);