From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 07630C27C5E for ; Tue, 11 Jun 2024 05:57:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=z+H3uNbYSeK/mxae9mzh3xtI0y86B/zC0dwoo8aCxCU=; b=tLH7NVOvBPQ5/v9jVU2lFFFsbW sasOvfxRNGfEUkmpddplxkrinI5E3He2Tn15jAZgrQnpcx0ys2tggJb+PFzyZ1+c3GZAkSeeor9iS M1lKMqJwLiOra/4geydu/tOlHKSsBLHGcPuuZpGCtc36ssgPo3gPTdXV0lqrpC6kx4Euj+vobnUz5 Xc3KaV3WmOnbCwBLFEfcALZ9C4tAHLM43D2KZUmal9pCkLglFoib9WKp/pWmow8Kj/e4g/8CrZ5Ka VbwAwXUoyIf7vSdZ2SmiRCXYyrOIKagYiwXCao7KCZKQ3ASaiydpp3gap6Kf9wTVsFPw3ACQ51ICB KJ5z4WkA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGuVR-00000007bGv-2GM7; Tue, 11 Jun 2024 05:57:17 +0000 Received: from sin.source.kernel.org ([2604:1380:40e1:4800::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sGuVI-00000007bG6-35eg; Tue, 11 Jun 2024 05:57:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id CA4B3CE0B9B; Tue, 11 Jun 2024 05:57:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7C4CBC2BD10; Tue, 11 Jun 2024 05:57:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718085426; bh=xFN1h7CLNOVeSD1DVq7Y6t3Bb5KlL582IrHJpAfOI+I=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=fv21i4LDKBohOjAMc7pIwhaiiTsAlafv5K+jqxJasBRtlliGgCtTrXsT0H8yV5+9T njwksi1EuST41csRG3Vqsp2L+QlP+t8YOn8e3W08JXRiXRq8hhVj8Dagc3+6nbt30R F+mIQhqmSwNPdFOouK0TdZvzzsTWzz1Lqs4jPTNbQ0Jw2LrEoRIpZD54zKPNaLm1HA t4c032+2B98Y3f+oLMEONdKDXJVupqzzbghc2EZK18tDOe6HzPnnhx/GWgADRWFlM4 oxYC9o2lrFo6wnGlsgbujf5T6gsAVdypUTxeMWDRMSrvLMxkDZnNQFg5hAvDm4J/fA kYvXmValPXY/Q== Message-ID: Date: Tue, 11 Jun 2024 14:56:59 +0900 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 05/26] loop: regularize upgrading the lock size for direct I/O To: Christoph Hellwig , Jens Axboe Cc: Geert Uytterhoeven , Richard Weinberger , Philipp Reisner , Lars Ellenberg , =?UTF-8?Q?Christoph_B=C3=B6hmwalder?= , Josef Bacik , Ming Lei , "Michael S. Tsirkin" , Jason Wang , =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= , Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Song Liu , Yu Kuai , Vineeth Vijayan , "Martin K. Petersen" , linux-m68k@lists.linux-m68k.org, linux-um@lists.infradead.org, drbd-dev@lists.linbit.com, nbd@other.debian.org, linuxppc-dev@lists.ozlabs.org, ceph-devel@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev, linux-raid@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org, nvdimm@lists.linux.dev, linux-nvme@lists.infradead.org, linux-s390@vger.kernel.org, linux-scsi@vger.kernel.org, linux-block@vger.kernel.org References: <20240611051929.513387-1-hch@lst.de> <20240611051929.513387-6-hch@lst.de> Content-Language: en-US From: Damien Le Moal Organization: Western Digital Research In-Reply-To: <20240611051929.513387-6-hch@lst.de> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240610_225709_224478_7D06AAF6 X-CRM114-Status: GOOD ( 21.09 ) X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+linux-um=archiver.kernel.org@lists.infradead.org On 6/11/24 2:19 PM, Christoph Hellwig wrote: > The LOOP_CONFIGURE path automatically upgrades the block size to that > of the underlying file for O_DIRECT file descriptors, but the > LOOP_SET_BLOCK_SIZE path does not. Fix this by lifting the code to > pick the block size into common code. s/lock/block in the commit title. > > Signed-off-by: Christoph Hellwig > --- > drivers/block/loop.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index c658282454af1b..4f6d8514d19bd6 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -975,10 +975,24 @@ loop_set_status_from_info(struct loop_device *lo, > return 0; > } > > +static unsigned short loop_default_blocksize(struct loop_device *lo, > + struct block_device *backing_bdev) > +{ > + /* In case of direct I/O, match underlying block size */ > + if ((lo->lo_backing_file->f_flags & O_DIRECT) && backing_bdev) > + return bdev_logical_block_size(backing_bdev); > + return 512; Nit: SECTOR_SIZE ? > +} > + > static int loop_reconfigure_limits(struct loop_device *lo, unsigned short bsize) > { > + struct file *file = lo->lo_backing_file; > + struct inode *inode = file->f_mapping->host; > struct queue_limits lim; > > + if (!bsize) > + bsize = loop_default_blocksize(lo, inode->i_sb->s_bdev); If bsize is specified and there is a backing dev used with direct IO, should it be checked that bsize is a multiple of bdev_logical_block_size(backing_bdev) ? > + > lim = queue_limits_start_update(lo->lo_queue); > lim.logical_block_size = bsize; > lim.physical_block_size = bsize; > @@ -997,7 +1011,6 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, > int error; > loff_t size; > bool partscan; > - unsigned short bsize; > bool is_loop; > > if (!file) > @@ -1076,15 +1089,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode, > if (!(lo->lo_flags & LO_FLAGS_READ_ONLY) && file->f_op->fsync) > blk_queue_write_cache(lo->lo_queue, true, false); > > - if (config->block_size) > - bsize = config->block_size; > - else if ((lo->lo_backing_file->f_flags & O_DIRECT) && inode->i_sb->s_bdev) > - /* In case of direct I/O, match underlying block size */ > - bsize = bdev_logical_block_size(inode->i_sb->s_bdev); > - else > - bsize = 512; > - > - error = loop_reconfigure_limits(lo, bsize); > + error = loop_reconfigure_limits(lo, config->block_size); > if (WARN_ON_ONCE(error)) > goto out_unlock; > -- Damien Le Moal Western Digital Research