From patchwork Wed Jan 3 14:59:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13510161 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 8682DC47077 for ; Wed, 3 Jan 2024 15:00:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 056106B0389; Wed, 3 Jan 2024 10:00:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F20F16B038C; Wed, 3 Jan 2024 09:59:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9C816B038F; Wed, 3 Jan 2024 09:59:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BE29C6B0389 for ; Wed, 3 Jan 2024 09:59:59 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 6400B120931 for ; Wed, 3 Jan 2024 14:59:59 +0000 (UTC) X-FDA: 81638309718.08.F535B4D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 9239E40026 for ; Wed, 3 Jan 2024 14:59:56 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hlTmFtm2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704293996; 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=SdFCD8YJUNnwtU5qwz/M+xF7ih7tS/QW8qR9RpiR7QY=; b=rj6wrk7LrtlqBGkgST9BlsbIzUyjAgPHJcBK3/H/J1RSKCr4rS2sXi2olQ+B6WbJ4x0FEB Spt2cBrIBLIE+rwHPHqMDVOlG+ogefBodB/lpXZohHGRRA53LZEQOly46Umz1i/7w6U11Z LfbI8JeXq136mevX280MRrAuqO3LDJ0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hlTmFtm2; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf11.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704293996; a=rsa-sha256; cv=none; b=sD0lu8aUzmGBFu2uIhtbD7Yn52K9h5o1IpKkNdkr8sW/5UQOsfaEjfWlh43DZHRHv8cd/L Fox6eYxYXpWWb0HYkqW3oq1z5PjaZxppcXIj7NWzasSIsBaU60PTrNu4dflKzeia7r4unD /KyuWa7K5eCbiUhGYsO6L4DQpim98jU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704293995; 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=SdFCD8YJUNnwtU5qwz/M+xF7ih7tS/QW8qR9RpiR7QY=; b=hlTmFtm2JAPatbFNtzg35SlztGKjfiQwqVSLRrR4uQbXx0Qwn4J/uIdZP4AY1HI1Q1G0+P V5wGFzXE4OWFmbskcaAUCUwhtdchSghTd014pUm9wkdPd7yfnftpMXVa7MyoajEedXdKSr QMh/9hy6DdWREQA2wW/5nF1PIS1nQdY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-369-l-ZawQD_NwSxVHuoSJh8mg-1; Wed, 03 Jan 2024 09:59:54 -0500 X-MC-Unique: l-ZawQD_NwSxVHuoSJh8mg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 450EB83B826; Wed, 3 Jan 2024 14:59:53 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 45F673C27; Wed, 3 Jan 2024 14:59:49 +0000 (UTC) From: David Howells To: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet Cc: David Howells , Steve French , Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Eric Van Hensbergen , Ilya Dryomov , linux-cachefs@redhat.com, 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, Yiqun Leng , Jia Zhu Subject: [PATCH 1/5] cachefiles: Fix __cachefiles_prepare_write() Date: Wed, 3 Jan 2024 14:59:25 +0000 Message-ID: <20240103145935.384404-2-dhowells@redhat.com> In-Reply-To: <20240103145935.384404-1-dhowells@redhat.com> References: <20240103145935.384404-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.1 X-Rspamd-Queue-Id: 9239E40026 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: sf5uttcgf49cce3wzikmazpwy5izx5ax X-HE-Tag: 1704293996-358308 X-HE-Meta: U2FsdGVkX18DL7c3GL0C4BO6G9sMBVsbZ7EGo1Pnx7bKnZfHTB9egI06LxWXZKcZaPhZq2rIKTuz0WaRU1LVbnfs606ruqTvYxWeB/11cUx5njKqJXD4tOHw8fis085won46ZWQ7zpXb7NvMXGDEkql3Dy7++0DBgJvhN2Zo5//sGDB0Wp/FHMWexRGMQ8VRjxWvzisXe3wzPTxXQkpUI/HrGCr1RJraVMw7beA8O5zXbjyqxI+8+ROFYeR/+sFFO6aDDtTrRdnUS6Vc2f3nwHlJ/wL5hUMeEE9w73zW1ZJlkf+IFA7S8BtcTNypoQoVbZnxXTkRePKmCwXngQZliuXUA+aztkitW/ISK2A0LveJb4jp5YhuE3qG+8/Rr2ZxY2NJlL7HTlt2KX0mY06QXE1Z2k3WEK8tcjepg04gHPX6WNd+qcSNsI+3pQrDgWkYTFnJzjE6c24LwYbENdV84NajhwxQarcA4Scd5Y34WhwTDqzSB9UrPPpB22wPl35gysMmCnLQLKak7/9M/lqjhmAxQVeMnXWCmNBumj5W/jviD9c0jBDom8GARZ7NZOA3/IlIQeWFfF8uzRYxxducABTRC+toeqZym0hemgRXpyzdfyuroDC0r7maz5QROduQ48XpgULJBBkuGf8u4NBler1fRaNLjKe3baRwTZJ1QsI4rQ91FxPkg/k0Kh8gC0K64QubbBAWsNrpfkRV6XjTDMaG3cuRCmYbfl+fCj6rB7bb3bWG3eO9vLEVIRQye3VHnx4Cii5r7C4x47hy4bnBe9SGamc4lfgvFFhm5/MEnTcgREyH4oYrNxCQxqTKkXKOw8cR8kTHE69efxk09bnSKVmDkntdxjsvrSUoTHPXdbC3heGnotw1fYNwt+SAcA3e8xTq8c7fVlesyT4cAINHAAsexhsWW2EOKDrXy6zBE0v/yQY60z2mFKUlbpv9egtd2PE1G5kee/17g5yiQp3 OJzdUSrz +NMYvSyzc1jPyFauzQfQ08+MeZM9GU2ZyWfxjm+IKrpho7wmQkLeXOc6iW628v66phMe05T70ExSKM+g/vG1NlTfPy3/hkPuEv1AcUbWQypb2n2zFxtl+ReAvcsPa5L3AQxhGx8y5dLI2b6/w7A1vhtTu5HVmyBhqcYB6FEeeVtCEnlHxiILCTA1UTL2h5FrYL5DlsnJGFQpqAN+8Oh/AX8UfgaxCxrioTIIVArnCpyhPGIRbCQjpLNBCUnf0N/KcsOGzLL4tAJd7uq7Q7tAVMfO4tRqc7mkuEREe28nAHXTOrA+nKBbFvPlBHNbH+cIWO33XkzzUSkwwXFBoiLMkChAC4bk71Q//a1gnpOQjT5SMkM9lCINb6rwS6802iOW7EYV1BGs5lzHYhCByzOtd9+Y8AwFur/NIp/MwFsTb2O+9CH8IENG2k5k/TGOEOb8ANrPVnGusRZ0MOc5U+LSio3ggCPh6QuwPpakr 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: Fix __cachefiles_prepare_write() to correctly determine whether the requested write will fit correctly with the DIO alignment. Reported-by: Gao Xiang Signed-off-by: David Howells Tested-by: Yiqun Leng Tested-by: Jia Zhu cc: Jeff Layton cc: linux-cachefs@redhat.com cc: linux-erofs@lists.ozlabs.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Reported-by: Simon Horman Reported-by: kernel test robot Signed-off-by: David Howells Reviewed-by: Simon Horman --- fs/cachefiles/io.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/fs/cachefiles/io.c b/fs/cachefiles/io.c index bffffedce4a9..7529b40bc95a 100644 --- a/fs/cachefiles/io.c +++ b/fs/cachefiles/io.c @@ -522,16 +522,22 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, bool no_space_allocated_yet) { struct cachefiles_cache *cache = object->volume->cache; - loff_t start = *_start, pos; - size_t len = *_len, down; + unsigned long long start = *_start, pos; + size_t len = *_len; int ret; /* Round to DIO size */ - down = start - round_down(start, PAGE_SIZE); - *_start = start - down; - *_len = round_up(down + len, PAGE_SIZE); - if (down < start || *_len > upper_len) + start = round_down(*_start, PAGE_SIZE); + if (start != *_start) { + kleave(" = -ENOBUFS [down]"); + return -ENOBUFS; + } + if (*_len > upper_len) { + kleave(" = -ENOBUFS [up]"); return -ENOBUFS; + } + + *_len = round_up(len, PAGE_SIZE); /* We need to work out whether there's sufficient disk space to perform * the write - but we can skip that check if we have space already @@ -542,7 +548,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, pos = cachefiles_inject_read_error(); if (pos == 0) - pos = vfs_llseek(file, *_start, SEEK_DATA); + pos = vfs_llseek(file, start, SEEK_DATA); if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) { if (pos == -ENXIO) goto check_space; /* Unallocated tail */ @@ -550,7 +556,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, cachefiles_trace_seek_error); return pos; } - if ((u64)pos >= (u64)*_start + *_len) + if (pos >= start + *_len) goto check_space; /* Unallocated region */ /* We have a block that's at least partially filled - if we're low on @@ -563,13 +569,13 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, pos = cachefiles_inject_read_error(); if (pos == 0) - pos = vfs_llseek(file, *_start, SEEK_HOLE); + pos = vfs_llseek(file, start, SEEK_HOLE); if (pos < 0 && pos >= (loff_t)-MAX_ERRNO) { trace_cachefiles_io_error(object, file_inode(file), pos, cachefiles_trace_seek_error); return pos; } - if ((u64)pos >= (u64)*_start + *_len) + if (pos >= start + *_len) return 0; /* Fully allocated */ /* Partially allocated, but insufficient space: cull. */ @@ -577,7 +583,7 @@ int __cachefiles_prepare_write(struct cachefiles_object *object, ret = cachefiles_inject_remove_error(); if (ret == 0) ret = vfs_fallocate(file, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - *_start, *_len); + start, *_len); if (ret < 0) { trace_cachefiles_io_error(object, file_inode(file), ret, cachefiles_trace_fallocate_error);