Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7034809rdb; Wed, 3 Jan 2024 02:15:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpmU4tKjbUU3RrxOaMWDNVZPXQcvEi41gpp+EuQT9QX3QMynWvFHN08SncAGo+TB7MyZnC X-Received: by 2002:a05:622a:130e:b0:428:20c4:419d with SMTP id v14-20020a05622a130e00b0042820c4419dmr5679670qtk.66.1704276937845; Wed, 03 Jan 2024 02:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704276937; cv=none; d=google.com; s=arc-20160816; b=zVmf8Rv4nhagt/lJDG9o+FpZ0M4ATI0cpEalaawiArg6OB3zUsM5GtnyW3zfSTjWWu kGPOdIAFm4LyjIyLukQehJWQ6gK31jcX7+OnRLmjE8IskpkXZbgOYJjxdFc/go/wFGB5 xi8Fop9vGc2bN1mFQvwzI9OE5EbyLX3pxxQE/cUEY2B1QLpWUxtI76Zx2rUGJC1UsAH2 Gukwxq+a2jaYYRxxQTEzJnceAy5f8mnqgn37qM9gEJqWNntSeoK7vqKkAIfz96SeSpw6 wXgrPgt8I3ol7Ila3Fa+hzN5OBuNCFMu4CoEhvMUIR+QRLBsq7ivb+LpKUDhoNHN9lb4 0vzw== 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:dkim-signature; bh=r9kSoFv/7+pD3aWATl3d1Zz/zNpbqJdAmBC+qKH73H4=; fh=tIZT9om+erupAiq+lEdIavXdMDS/r59uB2/b6xkEPgU=; b=cLsM79xR+tYwzocqTRuBRNn/0W0g14hr8v962YCGIBEVm3kuwZrrXB/eg4VAXgJ5jT EIXxFj0YF/SROhZ1lk4veYqCBJ8sSLGqd+vyHvi3c4fAxs9am4T3aAyPYjCnfSIV9NDJ 6JB5FXXPDWP0ERFtTfT0naV31vXbkS9Bq/BL6a7B4nwaHPHMuyMXisTcgJ3bXPcO1sO0 bWO4nWWcz/vkzJSznvqKu2q844Pjm18oWayebuEUNDmDDC+OfWGMeC1oE05QpCsjN6JJ Ustt+ae5Xb0xAc1PLQoS8hQgOABT3Pe/e+0YCPcvRqNucV76GRuX8FwJvNECUBtTFd+7 9/WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="b/IH5pIU"; spf=pass (google.com: domain of linux-nfs+bounces-870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d17-20020a05622a05d100b00427772c3694si28602743qtb.677.2024.01.03.02.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 02:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="b/IH5pIU"; spf=pass (google.com: domain of linux-nfs+bounces-870-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-nfs+bounces-870-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 88B8D1C22E52 for ; Wed, 3 Jan 2024 10:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5703D18650; Wed, 3 Jan 2024 10:15:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="b/IH5pIU" X-Original-To: linux-nfs@vger.kernel.org Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 6E43818657 for ; Wed, 3 Jan 2024 10:15:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1d3f29fea66so41504355ad.3 for ; Wed, 03 Jan 2024 02:15:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1704276918; x=1704881718; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=r9kSoFv/7+pD3aWATl3d1Zz/zNpbqJdAmBC+qKH73H4=; b=b/IH5pIUzffcArbA4NKho9QxpN6XCff2kves6QqQSkA+28J9lX4QXxmeZxJpBndmnL 29JvwxXvfzLBgn7eKfRPs3i0ckbK9rpmRYsYjXY64GrWZjEuOyGA4fPfHs4Por0Ku8jU XNhco8bevs5HIpq2Zz99k3Y407lIkgH8ZOzSMNf9rgEJXp6pZefCO+Zmw5OrrhxaALQ8 EVW7cy0zdZ2+WbpN84B4m0R2HS8mLSd1/khQy/9xmPDooHFwjK2zJzA16FbKEi46xC2a L/fAMdVi4A82kd/IdsdGf7iCkt6nic0irxA8creFtCzfBaGXTlqrB9mKOyMImsBW38Gw MmYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704276918; x=1704881718; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=r9kSoFv/7+pD3aWATl3d1Zz/zNpbqJdAmBC+qKH73H4=; b=atc5Jjj0CSho8JvcuOVZ7qPtc4U49K5HGtP3yHI1JrO02Hi7nD3/WZsUUORDNYB9nW 7KUIQK7bRnyDYtrVRQXmnrRX5L346QDY+t4RHxRAOvFONrPDc+DLVsfVH+fDNiPeYeDY kxpRq2spX+9F7HaOBQKVEDtwuw8pN3NWqwphsxOw5a42ddoqA6syiUyCA63/SNAEUIsS 0kj9gk2aDZLNfK5sTpYZvONUl0vYOrYz4LNdw37j6r8s9uJP4nCVgImIRmmS0rLDAwvt 6GSDzhR7dJor/5YkBbo7mx0eMvrTiPteM4c2ELSjx0cbU4NxIkLxPuKg2azxp8deVVZg w9Lw== X-Gm-Message-State: AOJu0YweyQwhX0xIjGp6AG1GAFXtYzTaWuJBF431iCZP/Amb70psReS3 NjoUrYEPnf//Sk89nFCYJ+b5BdqoJPNvzw== X-Received: by 2002:a17:903:11c3:b0:1d4:75c6:9560 with SMTP id q3-20020a17090311c300b001d475c69560mr6941145plh.59.1704276917712; Wed, 03 Jan 2024 02:15:17 -0800 (PST) Received: from [10.3.158.72] ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id bh10-20020a170902a98a00b001d4160c4f97sm21615997plb.188.2024.01.03.02.15.11 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 03 Jan 2024 02:15:17 -0800 (PST) Message-ID: <42dd77c4-8842-4f96-958a-0d9407362b9d@bytedance.com> Date: Wed, 3 Jan 2024 18:15:09 +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: Re: [PATCH v5 33/40] netfs, cachefiles: Pass upper bound length to allow expansion To: David Howells , Gao Xiang 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 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: Jia Zhu In-Reply-To: <198744.1704215477@warthog.procyon.org.uk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 在 2024/1/3 01:11, David Howells 写道: > 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? > > David > --- Tested-by: Jia Zhu > > 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); >