Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp715902lqp; Wed, 12 Jun 2024 14:11:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeVW/XQf1KG0BHYV61OwZXQrRiasWyN4U3M5NqLs78oCxnM2CTy69OaZUromEyjnntozi4haq+IKlq95OpZ9EsHoN698A1ZqoCu142sA== X-Google-Smtp-Source: AGHT+IG/gM9MNuEXtdm/vOcQ4CxR4LZISdxxh9I3cqLDLq/GFzDF1GkWhkjKLCoQcrgOfkrPMHsH X-Received: by 2002:ac2:5191:0:b0:52b:c292:f7c with SMTP id 2adb3069b0e04-52c9a40523fmr1667805e87.62.1718226667769; Wed, 12 Jun 2024 14:11:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718226667; cv=pass; d=google.com; s=arc-20160816; b=aKN7xdK3nn+/l3snqJMWisUw4/u5813mOsSu6g0ES+k156xovmvUc24ILij13xS7q3 Zf/Eapu22jEXdWiC36S5JzRDYjhFtCRO0DPD4EYgisUSsYr6o+TXK3R4dUhxUECQ4GJQ CEErcO3b8RDDKq2nf9eTAN1bRLsbXiHHoPP7kLxmsLpubf9RE5o1S+cit5jzNFBd9EjI h+4iyiZXgp89GY53reuYDYU6oolhDHshuzfct4cX6Spw1NNiOz+7cZnVZqhfPuWObPPs zEnukMxFrjechL5j3azAdT0mOrsv6VV1ddVaYaJtSzxts6fykMakw/+fifUayanTlmct +21Q== ARC-Message-Signature: i=2; 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=tk+0evWAJUKV29rlC2BjFdRCanYtMLPO40GvQMFdqPo=; fh=8oCTMr0qt6Kgxk81TwhqkU9vbk0lw2Bs7BhULvosVF0=; b=m6A2ThVRMYJus0ZzkvexfwL/fwkyTp4M7SqVlPnMX32X2q5rUr4Gvj28YUBONc5eXR SMnGM12++0WDXFyZ+XRjWwn1ixC4qo2hlQBzJCQA6kySrDPe8r4ZPh6P9disHd8xRIsg BeyZRJebUmvVyil2lLcurbMks8eZFwDrNN+5bX6lUL6DUDVUAvGsI6yP+MZNwER/pHcf jLizDtRCXxyRNG0i7y0fDgLfMU3OAIfjZROIbA55ylsfny4+ca2jN7cF67VMnMRDj7fH Ce9ob93EJ5l5G8+fKYxXORIDkvfaZXdDnCCtVlw+ITP5JkaJhMeQDnx5VDB5VWTiGJcT SzAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIXhgPtR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212265-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a640c23a62f3a-a6e3564e0eesi596772566b.519.2024.06.12.14.11.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 14:11:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212265-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DIXhgPtR; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-212265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212265-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 79F5A1F2263B for ; Wed, 12 Jun 2024 21:11:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF07D126F32; Wed, 12 Jun 2024 21:10:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DIXhgPtR" 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 C7C0E381D1; Wed, 12 Jun 2024 21:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226642; cv=none; b=unwALY3nChCQ4TJL2QTm1d4wAZMOjlzEps4wFLs+2mZtn69DpJxx4ssp8Qbm1Py1TVvf3d2Tshq9JNl05+4n6Mw8eQLvzQ6B/zuzd5fH7hEnOzpdpyhqtYwXq4f1K0UJlrAITEEMVnAQm82e32yKyf9oOnF1sfGXGCJuPzakm8w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718226642; c=relaxed/simple; bh=dqLO371b1vPErmMYi4CgWyvSUCQn8of4qGwTdEMzEhk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cYZRf0uCnWnQSM6TjSEoHLMs122iF4srQ6UIWWY6tlZGY2zzjxOBufoGz5aBDXYlfPzjFuT64Rc6jiFc5i6DgyX6PG2Cyg8FM1oAUJpPCgT4/XXJzf+IgFdGvf3RBq/mQfjFrVBVcScBUyPyUrUzOw1NG4rXyIVHMVCeFjq0yt8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DIXhgPtR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A2F4C116B1; Wed, 12 Jun 2024 21:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718226641; bh=dqLO371b1vPErmMYi4CgWyvSUCQn8of4qGwTdEMzEhk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DIXhgPtR71kSyV6/epJDyqhWKsEQEX5yhhZda5PPHpZ+0ARYCCiAtnRSNR1FnlC7P nPXkJq/SepET7ym8thpR7yujnnQ7ZHn3iRsMoIfGobXMy1OJxAIzKKtD9ftmAGl8KN kUltI84OFlF1WwDhedAy43xrdUjP8vTB+P26BCEb3a2HConB/TZUMHytqEARmpH8ln QCY5BssR28eFz1T409YzepxwR+K2C6Zp7Uo+S9MDDNObxIJC8bTjFUTi06cTVT7OeC lTnaI5hdCh11uuYSK3xj94QxhxrNjmNwqI7uE46+z3EGyJoGClyLogjejeb9r2ihDk QMYN4T27nFHOw== Date: Wed, 12 Jun 2024 14:10:40 -0700 From: "Darrick J. Wong" To: John Garry Cc: axboe@kernel.dk, tytso@mit.edu, dchinner@redhat.com, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.com, chandan.babu@oracle.com, hch@lst.de, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-erofs@lists.ozlabs.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, gfs2@lists.linux.dev, linux-xfs@vger.kernel.org, catherine.hoang@oracle.com, ritesh.list@gmail.com, mcgrof@kernel.org, mikulas@artax.karlin.mff.cuni.cz, agruenba@redhat.com, miklos@szeredi.hu, martin.petersen@oracle.com Subject: Re: [PATCH v4 01/22] fs: Add generic_atomic_write_valid_size() Message-ID: <20240612211040.GJ2764752@frogsfrogsfrogs> References: <20240607143919.2622319-1-john.g.garry@oracle.com> <20240607143919.2622319-2-john.g.garry@oracle.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: <20240607143919.2622319-2-john.g.garry@oracle.com> On Fri, Jun 07, 2024 at 02:38:58PM +0000, John Garry wrote: > Add a generic helper for FSes to validate that an atomic write is > appropriately sized (along with the other checks). > > Signed-off-by: John Garry > --- > include/linux/fs.h | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/include/linux/fs.h b/include/linux/fs.h > index 069cbab62700..e13d34f8c24e 100644 > --- a/include/linux/fs.h > +++ b/include/linux/fs.h > @@ -3645,4 +3645,16 @@ bool generic_atomic_write_valid(loff_t pos, struct iov_iter *iter) > return true; > } > > +static inline > +bool generic_atomic_write_valid_size(loff_t pos, struct iov_iter *iter, > + unsigned int unit_min, unsigned int unit_max) > +{ > + size_t len = iov_iter_count(iter); > + > + if (len < unit_min || len > unit_max) > + return false; > + > + return generic_atomic_write_valid(pos, iter); > +} Now that I look back at "fs: Initial atomic write support" I wonder why not pass the iocb and the iov_iter instead of pos and the iov_iter? And can these be collapsed into a single generic_atomic_write_checks() function? --D > + > #endif /* _LINUX_FS_H */ > -- > 2.31.1 > >