Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1204020rdb; Sun, 7 Jan 2024 08:09:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFLrix8Z+g2LVWrMrU5JBYOpXnto9kuurFVkp9bHZWVfyQK9qjV8EbJT/Rf1fU3bkwn9e1/ X-Received: by 2002:a05:622a:1393:b0:429:94c1:9e8c with SMTP id o19-20020a05622a139300b0042994c19e8cmr550171qtk.45.1704643788722; Sun, 07 Jan 2024 08:09:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704643788; cv=none; d=google.com; s=arc-20160816; b=c5zbBklsuRl9IWyBYGX1CkKFOcAh0FxmD8C3IMef06m9JwxIqizSVC/r7KT3kcvAZX /zdZeErlx/IRtY66/LyznkqqaYYtjkt9lH/UfzndqQ6Hu4fpd3jSLoJwYrMh+E4A/OiP GUTvjbhK6YgQ36AINnDDKSzKkDZD3AyQbN1g6irlzLOXjOlEhN7VjZfTpu9NJnkimicB FEj74nTfRNNhhTXNp789QwzTsd/1lYQPZSIEsHAttoJbwmuXSTjGOJctdRQ6ksCntlw1 /gM6o2INv0xGUnbqdMpf6laefBWYIhmaP0kzM+/sojhahy7/67EnrjZ1nd0sDvcFumtd dUFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=h+oasDXAXyPeTpE3l+Jn7vwU0OtsAxsVNH6ZS+6AoWI=; fh=rRBQn6UFnQKVZ0BxRwHZFR+x+WUqUQCQsbxdbrDabCE=; b=eBmVwlnhi3Ioz76SghKncDNpu4P3tHJ9HtnJCpVx0yXBhrPWqPqxfzCOEsIR/2KDhF LOnBgLsA8CTx65alHeWG0hQhqSMra9knCQ5oj4MeQYC4ZCFa5buXIH+8XrN9UhsEJmWI 8LisUUBYq9TjeJ2qfCOxZnlJN5NT6mXHII+l8URTASQVZ9VHvG7PqfK5jhNDC8oUng7e notg6ArOhKA4ZN1A7pZTIETCp7IkMjE/x/Dg/vLotZBoxBg4prDSwrHfjAh8Bch/Ryts FJwaK2IfnEvzI22qR1CEUdNA1VOUe4BXitINt9wudbDO1Glm+WqkYd1XJsAzt3kzuPfd Ti2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Je4QSk1X; spf=pass (google.com: domain of linux-kernel+bounces-18905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a21-20020ac85b95000000b004283c22c1a7si5992267qta.578.2024.01.07.08.09.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 08:09:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Je4QSk1X; spf=pass (google.com: domain of linux-kernel+bounces-18905-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18905-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 671471C20B4B for ; Sun, 7 Jan 2024 16:09:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 297FF13AFC; Sun, 7 Jan 2024 16:09:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Je4QSk1X" X-Original-To: linux-kernel@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B17513AD1; Sun, 7 Jan 2024 16:09:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CDAAC433C8; Sun, 7 Jan 2024 16:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704643764; bh=vtEdJ8x0t9Cig7F/OQ58765CvJpN5U3pnuPNn8bEtX0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Je4QSk1Xsi5jvomPOikxCGlVFwk8iqkAbNF6aVYGaBGYI1jkUw+CADMBs0/wZQr36 xy22SDkRZMP5sMid5EvoeH3h/Kwf68Tcbn77GX8EDm+cjFQlFTs6TguY93Et6BFDPv UlIs+e2Jheeb2/ck0biFbtZrf0Vw9LMCbIX3TaJmqJZgdrEhhfSfxUMIfjU8lZxJF7 Q+aCdvG3kA6VLZkjLHS+Vga8pwGe2Z6VghL3LobYtAq3sM2rUGAW8uNlztGT7uqIEc x+WdUyce0Wh+SeZcYOdm2MG39rO2B8pkIyqp3viKoDClILrK1BwA1eJJXlvP2hGICM kq7yyH7rMCZgg== Date: Sun, 7 Jan 2024 16:09:16 +0000 From: Simon Horman To: David Howells Cc: Christian Brauner , Jeff Layton , Gao Xiang , Dominique Martinet , 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: Re: [PATCH 1/5] cachefiles: Fix __cachefiles_prepare_write() Message-ID: <20240107160916.GA129355@kernel.org> References: <20240103145935.384404-1-dhowells@redhat.com> <20240103145935.384404-2-dhowells@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240103145935.384404-2-dhowells@redhat.com> On Wed, Jan 03, 2024 at 02:59:25PM +0000, David Howells wrote: > 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 > --- > 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) { Hi David, I realise these patches have been accepted, but I have a minor nit: pos is now unsigned, and so cannot be less than zero. Flagged by Smatch and Coccinelle. > 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) { Ditto. > 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); >