Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6766659rdb; Tue, 2 Jan 2024 12:37:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGvg5nKV2Xp0pblOBMa5ZI5raXm20I1GtIAswau77GQP5VxBJ8SIE4Lp/N3EY+GFliKW9nP X-Received: by 2002:a2e:98d4:0:b0:2cc:dbcf:9311 with SMTP id s20-20020a2e98d4000000b002ccdbcf9311mr4139710ljj.96.1704227864524; Tue, 02 Jan 2024 12:37:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704227864; cv=none; d=google.com; s=arc-20160816; b=JKOTaqA2kp7OphrX1D4+Di9zwD7sc+ZAwV00rxQ5Kj+Or1a72x7SktRY8xPoF8sI+2 F9Nauz4kG2CztfG7PtC5fzc+y53aElqMKO9peF5Yxq5pNuu/SrKt5SuqBRMatrJf8g7K MsnykFxIrjnxQrEGcerWCoxhgiSgaxTjLH0rug03dRab72EUujAsEGNe4BMqfs9wekSC gXz9IRI0Vaecb25kYexJWfgca/KF0F1/W+fi7T6V7qRY/QKnVA4yq7hWY5SuVBdYxF63 m1lxcwqv4MbBv4ArZ3XFJLRYIHPip4wGcYuwRqSNTrTfscTtJFrYx7SwaInByALvucQh UuUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:date:message-id; bh=Ecs7Pd1oZ0RMqk2CqEFJ9DnjS0hihONiLG8VLGRjLJU=; fh=d3twwIWvUzgInBVeRX0AbjlMDCtvckludHFnbJQrQ98=; b=YFMtEP0EtPfpVyizclABfdnY8vipz9gYMHFY8/wb2PVXx+zAN24b7yUx+SEGT7NuTG /KLOPFWr9gfOoZsPktRKjWNAlBrJcLmUnOqbrmyrDtuR+v8xghQE3UloCOfDztzoBlGX jG+6kk4/9vG+dDtSYWVa0iKbXovUVIbl8IeE62imb1sytF5l2CcwYu/Q+0HtvhDTHXaM PYtLrs94d4yKyd2DU1ka930yWBZ/KIWLb7tpicxMWYUzK3wkL2wHGL1TWrz+YGCav3ky Ffwi+BqV6mrrNYmWqeBBTlJoAumHJMHOByYy9h8SNCz8m/LDGxPZgo3ncFPU1LyXlSBJ JW1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id dm7-20020a05640222c700b005567f769042si1240410edb.275.2024.01.02.12.37.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:37:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs+bounces-865-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-nfs+bounces-865-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 343FA1F23540 for ; Tue, 2 Jan 2024 20:37:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5539C1641B; Tue, 2 Jan 2024 20:37:38 +0000 (UTC) X-Original-To: linux-nfs@vger.kernel.org Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 E0FC516402; Tue, 2 Jan 2024 20:37:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R951e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=26;SR=0;TI=SMTPD_---0VzrTmRn_1704227842; Received: from 30.25.242.23(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0VzrTmRn_1704227842) by smtp.aliyun-inc.com; Wed, 03 Jan 2024 04:37:25 +0800 Message-ID: Date: Wed, 3 Jan 2024 04:37:22 +0800 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 33/40] netfs, cachefiles: Pass upper bound length to allow expansion To: David Howells Cc: Matthew Wilcox , Marc Dionne , Paulo Alcantara , Shyam Prasad N , Tom Talpey , Dominique Martinet , Eric Van Hensbergen , Ilya Dryomov , Christian Brauner , 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-fsdevel@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeff Layton , Steve French , Jeffle Xu , Jia Zhu , Xin Yin , Yiqun Leng References: <750e8251-ba30-4f53-a17b-73c79e3739ce@linux.alibaba.com> <20231221132400.1601991-1-dhowells@redhat.com> <20231221132400.1601991-34-dhowells@redhat.com> <198744.1704215477@warthog.procyon.org.uk> From: Gao Xiang In-Reply-To: <198744.1704215477@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/1/3 01:11, David Howells wrote: > Gao Xiang wrote: > >>> down = start - round_down(start, PAGE_SIZE); >>> *_start = start - down; >>> *_len = round_up(down + len, PAGE_SIZE); >>> + if (down < start || *_len > upper_len) >>> + return -ENOBUFS; >> >> Sorry for bothering. We just found some strange when testing >> today-next EROFS over fscache. >> >> I'm not sure the meaning of >> if (down < start >> >> For example, if start is page-aligned, down == 0. >> >> so as long as start > 0 and page-aligned, it will return >> -ENOBUFS. Does it an intended behavior? > > Yeah, I think that's wrong. > > Does the attached help? (+cc more people for testing) Will test and feedback later. Thanks, Gao Xiang > > David > --- > > 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); >