Re: [PATCH] drivers/virtio: delayed configuration descriptor flags

2024-04-08 Thread Chaitanya Kulkarni
On 4/8/24 10:02, ni.liqiang wrote:
> In our testing of the virtio hardware accelerator, we found that
> configuring the flags of the descriptor after addr and len,
> as implemented in DPDK, seems to be more friendly to the hardware.
please describe in detail "friendly to the hardware" means ..

> In our Virtio hardware implementation tests, using the default
> open-source code, the hardware's bulk reads ensure performance
> but correctness is compromised. If we refer to the implementation code
> of DPDK, placing the flags configuration of the descriptor
> after addr and len, virtio backend can function properly based on
> our hardware accelerator.

you are not specifying how the correctness is compromised ..
again what the "properly" mean here ? what is the exact failure that
you are seeing ? please document ..

> I am somewhat puzzled by this. From a software process perspective,
> it seems that there should be no difference whether
> the flags configuration of the descriptor is before or after addr and len.
> However, this is not the case according to experimental test results.
> We would like to know if such a change in the configuration order
> is reasonable and acceptable?

where are the experimental results ? any particular reason those
results are not documented here ?

>
> Thanks.
>
> Signed-off-by: ni.liqiang 
> Reviewed-by: jin.qi 
> Tested-by: jin.qi 
> Cc: ni.liqiang 
> ---
>   drivers/virtio/virtio_ring.c | 9 +
>   1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index 6f7e5010a673..bea2c2fb084e 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -1472,15 +1472,16 @@ static inline int virtqueue_add_packed(struct 
> virtqueue *_vq,
>   flags = cpu_to_le16(vq->packed.avail_used_flags |
>   (++c == total_sg ? 0 : VRING_DESC_F_NEXT) |
>   (n < out_sgs ? 0 : VRING_DESC_F_WRITE));
> - if (i == head)
> - head_flags = flags;
> - else
> - desc[i].flags = flags;
>   
>   desc[i].addr = cpu_to_le64(addr);
>   desc[i].len = cpu_to_le32(sg->length);
>   desc[i].id = cpu_to_le16(id);
>   
> + if (i == head)
> + head_flags = flags;
> + else
> + desc[i].flags = flags;
> +
>   if (unlikely(vq->use_dma_api)) {
>   vq->packed.desc_extra[curr].addr = addr;
>   vq->packed.desc_extra[curr].len = sg->length;

-ck




Re: [PATCH -next] PCI: remove unused variable rdev

2021-04-17 Thread Chaitanya Kulkarni
On 4/17/21 04:44, Bixuan Cui wrote:
> Fix the build warning:
>
> drivers/pci/quirks.c: In function ‘quirk_amd_nvme_fixup’:
> drivers/pci/quirks.c:312:18: warning: unused variable ‘rdev’ 
> [-Wunused-variable]
>   struct pci_dev *rdev;
>   ^~~~
>
> Fixes: 9597624ef606 ('nvme: put some AMD PCIE downstream NVME device to 
> simple suspend/resume path')
> Signed-off-by: Bixuan Cui 


Looks good.

Reviewed-by: Chaitanya Kulkarni 




Re: [RFC PATCH v5 0/4] add simple copy support

2021-04-13 Thread Chaitanya Kulkarni
On 4/13/21 11:26, Javier González wrote:
>>> I believe there is space for extensions to simple copy. But given the
>>> experience with XCOPY, I can imagine that changes will be incremental,
>>> based on very specific use cases.
>>>
>>> I think getting support upstream and bringing deployed cases is a very
>>> good start.
>> Copying data (files) within the controller/subsystem from ns_A to ns_B 
>> using NVMf will reduce network BW and memory BW in the host server.
>>
>> This feature is well known and the use case is well known.
> Definitely.
>

I've a working code for nvmet for simple copy, I'm waiting to resolve
the host interface for REQ_OP_COPY so I can post it with this series.

Let me know if someone wants to collaborate offline on that.

IMHO we first need to sort out the host side interface which is
a challenge for years and it is not that easy to get it right
based on the history.




Re: [PATCH] gdrom: fix compilation error

2021-04-12 Thread Chaitanya Kulkarni
On 4/11/21 18:33, Jens Axboe wrote:
>>>   586 |  __raw_writel(page_to_phys(bio_page(req->bio)) + 
>>> bio_offset(rq->bio),
>>>   | ^~
>> How about adding a Fixes: tag?
> Indeed, that's definitely missing. I've added it and applied it.
>
> -- 

Sorry about that, thanks for fixing it.




[PATCH] gdrom: fix compilation error

2021-04-11 Thread Chaitanya Kulkarni
Use the right name for the struct request variable that removes the
following compilation error :-

make --silent --keep-going --jobs=8
O=/home/tuxbuild/.cache/tuxmake/builds/1/tmp ARCH=sh
CROSS_COMPILE=sh4-linux-gnu- 'CC=sccache sh4-linux-gnu-gcc'
'HOSTCC=sccache gcc'

In file included from /builds/linux/include/linux/scatterlist.h:9,
 from /builds/linux/include/linux/dma-mapping.h:10,
 from /builds/linux/drivers/cdrom/gdrom.c:16:
/builds/linux/drivers/cdrom/gdrom.c: In function 'gdrom_readdisk_dma':
/builds/linux/drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared
(first use in this function)
  586 |  __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
  | ^~

Reported-by: Naresh Kamboju 
Tested-by: Naresh Kamboju 
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/cdrom/gdrom.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index e7717d090868..742b4a0932e3 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -583,7 +583,7 @@ static blk_status_t gdrom_readdisk_dma(struct request *req)
read_command->cmd[1] = 0x20;
block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET;
block_cnt = blk_rq_sectors(req)/GD_TO_BLK;
-   __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
+   __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(req->bio),
GDROM_DMA_STARTADDR_REG);
__raw_writel(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
__raw_writel(1, GDROM_DMA_DIRECTION_REG);
-- 
2.22.1



Re: [RFC PATCH v5 0/4] add simple copy support

2021-04-09 Thread Chaitanya Kulkarni
On 4/9/21 17:22, Max Gurtovoy wrote:
> On 2/19/2021 2:45 PM, SelvaKumar S wrote:
>> This patchset tries to add support for TP4065a ("Simple Copy Command"),
>> v2020.05.04 ("Ratified")
>>
>> The Specification can be found in following link.
>> https://nvmexpress.org/wp-content/uploads/NVM-Express-1.4-Ratified-TPs-1.zip
>>
>> Simple copy command is a copy offloading operation and is  used to copy
>> multiple contiguous ranges (source_ranges) of LBA's to a single destination
>> LBA within the device reducing traffic between host and device.
>>
>> This implementation doesn't add native copy offload support for stacked
>> devices rather copy offload is done through emulation. Possible use
>> cases are F2FS gc and BTRFS relocation/balance.
>>
>> *blkdev_issue_copy* takes source bdev, no of sources, array of source
>> ranges (in sectors), destination bdev and destination offset(in sectors).
>> If both source and destination block devices are same and copy_offload = 1,
>> then copy is done through native copy offloading. Copy emulation is used
>> in other cases.
>>
>> As SCSI XCOPY can take two different block devices and no of source range is
>> equal to 1, this interface can be extended in future to support SCSI XCOPY.
> Any idea why this TP wasn't designed for copy offload between 2 
> different namespaces in the same controller ?

Yes, it was the first attempt so to keep it simple.

Further work is needed to add incremental TP so that we can also do a copy
between the name-spaces of same controller (if we can't already) and to the
namespaces that belongs to the different controller.

> And a simple copy will be the case where the src_nsid == dst_nsid ?
>
> Also why there are multiple source ranges and only one dst range ? We 
> could add a bit to indicate if this range is src or dst..
>
>





Re: [next] drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared (first use in this function)

2021-04-09 Thread Chaitanya Kulkarni
On 4/8/21 23:24, Naresh Kamboju wrote:
>> bio_offset(req->bio),
>> GDROM_DMA_STARTADDR_REG);
>> __raw_writel(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
>> __raw_writel(1, GDROM_DMA_DIRECTION_REG);
> Thanks for your patch.
> After applying this typo fix, the build pass now.
>
> - Naresh
>

are you okay if I add your tested by tag to the official patch ?

Or you want to send it as a reply to that patch ?

plz let me know...






Re: [next] drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared (first use in this function)

2021-04-08 Thread Chaitanya Kulkarni
Naresh,

On 4/8/21 22:31, Chaitanya Kulkarni wrote:
> On 4/8/21 22:21, Naresh Kamboju wrote:
>> Linux next tag 20210408 architecture sh builds failed due to these errors.
>>
>> # to reproduce this build locally:
>>
>> make --silent --keep-going --jobs=8
>> O=/home/tuxbuild/.cache/tuxmake/builds/1/tmp ARCH=sh
>> CROSS_COMPILE=sh4-linux-gnu- 'CC=sccache sh4-linux-gnu-gcc'
>> 'HOSTCC=sccache gcc'
>>
>>
>> In file included from /builds/linux/include/linux/scatterlist.h:9,
>>  from /builds/linux/include/linux/dma-mapping.h:10,
>>  from /builds/linux/drivers/cdrom/gdrom.c:16:
>> /builds/linux/drivers/cdrom/gdrom.c: In function 'gdrom_readdisk_dma':
>> /builds/linux/drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared
>> (first use in this function)
>>   586 |  __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
>>   | ^~
>>
>> Reported-by: Naresh Kamboju 
>>
>> Regressions found on sh:
>>   - build/gcc-9-dreamcast_defconfig
>>   - build/gcc-10-dreamcast_defconfig
>>   - build/gcc-8-dreamcast_defconfig
>>
>> --
>> Linaro LKFT
>> https://lkft.linaro.org
>>

You can try following fix and see if the error goes away.

> This can be fixed by following :-
>
> diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
> index e7717d090868..742b4a0932e3 100644
> --- a/drivers/cdrom/gdrom.c
> +++ b/drivers/cdrom/gdrom.c
> @@ -583,7 +583,7 @@ static blk_status_t gdrom_readdisk_dma(struct
> request *req)
> read_command->cmd[1] = 0x20;
> block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET;
> block_cnt = blk_rq_sectors(req)/GD_TO_BLK;
> -   __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
> +   __raw_writel(page_to_phys(bio_page(req->bio)) +
> bio_offset(req->bio),
> GDROM_DMA_STARTADDR_REG);
> __raw_writel(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
> __raw_writel(1, GDROM_DMA_DIRECTION_REG);
>



Re: [next] drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared (first use in this function)

2021-04-08 Thread Chaitanya Kulkarni
On 4/8/21 22:21, Naresh Kamboju wrote:
> Linux next tag 20210408 architecture sh builds failed due to these errors.
>
> # to reproduce this build locally:
>
> make --silent --keep-going --jobs=8
> O=/home/tuxbuild/.cache/tuxmake/builds/1/tmp ARCH=sh
> CROSS_COMPILE=sh4-linux-gnu- 'CC=sccache sh4-linux-gnu-gcc'
> 'HOSTCC=sccache gcc'
>
>
> In file included from /builds/linux/include/linux/scatterlist.h:9,
>  from /builds/linux/include/linux/dma-mapping.h:10,
>  from /builds/linux/drivers/cdrom/gdrom.c:16:
> /builds/linux/drivers/cdrom/gdrom.c: In function 'gdrom_readdisk_dma':
> /builds/linux/drivers/cdrom/gdrom.c:586:61: error: 'rq' undeclared
> (first use in this function)
>   586 |  __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
>   | ^~
>
> Reported-by: Naresh Kamboju 
>
> Regressions found on sh:
>   - build/gcc-9-dreamcast_defconfig
>   - build/gcc-10-dreamcast_defconfig
>   - build/gcc-8-dreamcast_defconfig
>
> --
> Linaro LKFT
> https://lkft.linaro.org
>

This can be fixed by following :-

diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index e7717d090868..742b4a0932e3 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -583,7 +583,7 @@ static blk_status_t gdrom_readdisk_dma(struct
request *req)
read_command->cmd[1] = 0x20;
block = blk_rq_pos(req)/GD_TO_BLK + GD_SESSION_OFFSET;
block_cnt = blk_rq_sectors(req)/GD_TO_BLK;
-   __raw_writel(page_to_phys(bio_page(req->bio)) + bio_offset(rq->bio),
+   __raw_writel(page_to_phys(bio_page(req->bio)) +
bio_offset(req->bio),
GDROM_DMA_STARTADDR_REG);
__raw_writel(block_cnt * GDROM_HARD_SECTOR, GDROM_DMA_LENGTH_REG);
__raw_writel(1, GDROM_DMA_DIRECTION_REG);


Re: [PATCH][next] nvmet: Fix spelling mistake "nubmer" -> "number"

2021-04-07 Thread Chaitanya Kulkarni
On 4/7/21 04:10, Colin King wrote:
> From: Colin Ian King 
>
> There is a spelling mistake in a pr_err error message. Fix it.
>
> Signed-off-by: Colin Ian King 
> ---

Looks good.

Reviewed-by: Chaitanya Kulkarni 




Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs

2021-03-31 Thread Chaitanya Kulkarni
Daniel,

On 3/31/21 06:12, Daniel Wagner wrote:
> Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device")
> introduced fast_io_fail_tmo but didn't export the value to sysfs. That
> means the value is hard coded during compile time. Export the timeout
> value to user space via sysfs to allow runtime configuration.
>
> Cc: Victor Gladkov 
> Signed-off-by: Daniel Wagner 
> ---
>
> This patch is against nvme-5.13
>
> BTW, checkpatch complains with
>
>   WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not preferred. 
> Consider using octal permissions '0644'.

For now keep the current style.

>
> Is this something we want to adapt to?
>
>  drivers/nvme/host/core.c | 31 +++
>  1 file changed, 31 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 40215a0246e4..c8de0e37c7d9 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3696,6 +3696,36 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct 
> device *dev,
>  static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
>   nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store);
>  
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
> + struct device_attribute *attr, char *buf)
> +{
> + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> + if (ctrl->opts->fast_io_fail_tmo == -1)
> + return sprintf(buf, "off\n");
> + return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);

do we need snprintf() for 2nd ?

> +}
> +
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
> + struct device_attribute *attr, const char *buf, size_t count)
> +{
> + struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> + struct nvmf_ctrl_options *opts = ctrl->opts;
> + int fast_io_fail_tmo, err;
> +
> + err = kstrtoint(buf, 10, _io_fail_tmo);
> + if (err)
> + return -EINVAL;
> +

since you are returning an error, you can remove next else if, this also
removes the extra line after above return. Something like this on the top
of yours totally untested :-

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c8de0e37c7d9..afa0a6790b52 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3717,7 +3717,7 @@ static ssize_t
nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
if (err)
return -EINVAL;
 
-   else if (fast_io_fail_tmo < 0)
+   if (fast_io_fail_tmo < 0)
opts->fast_io_fail_tmo = -1;
else
opts->fast_io_fail_tmo = fast_io_fail_tmo;

> + else if (fast_io_fail_tmo < 0)
> + opts->fast_io_fail_tmo = -1;
> + else
> + opts->fast_io_fail_tmo = fast_io_fail_tmo;
> + return count;
> +}
> +static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
> + nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
> +
>  static struct attribute *nvme_dev_attrs[] = {
>   _attr_reset_controller.attr,
>   _attr_rescan_controller.attr,
> @@ -3715,6 +3745,7 @@ static struct attribute *nvme_dev_attrs[] = {
>   _attr_hostid.attr,
>   _attr_ctrl_loss_tmo.attr,
>   _attr_reconnect_delay.attr,
> + _attr_fast_io_fail_tmo.attr,
>   NULL
>  };
>  
> -- 2.29.2




Re: [PATCH] nvme-fc: Few trivial spelling fixes

2021-03-22 Thread Chaitanya Kulkarni
On 3/20/21 13:45, Bhaskar Chowdhury wrote:
> s/boundarys/boundaries/ . two different places
> s/assocated/associated/
> s/compeletion/completion/
> s/tranferred/transferred/
> s/subsytem/subsystem/
>
> Signed-off-by: Bhaskar Chowdhury 

Patch looks fine but commit log could be better.





Re: [mm/highmem] 61b205f579: WARNING:at_mm/highmem.c:#__kmap_local_sched_out

2021-03-09 Thread Chaitanya Kulkarni
Ira,

On 3/4/21 00:23, kernel test robot wrote:
> Greeting,
>
> FYI, we noticed the following commit (built with gcc-9):
>
> commit: 61b205f579911a11f0b576f73275eca2aed0d108 ("mm/highmem: Convert 
> memcpy_[to|from]_page() to kmap_local_page()")
> https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git master
>
>
> in testcase: trinity
> version: trinity-static-i386-x86_64-f93256fb_2019-08-28
> with following parameters:
>
>   runtime: 300s
>
> test-description: Trinity is a linux system call fuzz tester.
> test-url: http://codemonkey.org.uk/projects/trinity/
>
>
> on test machine: qemu-system-i386 -enable-kvm -cpu SandyBridge -smp 2 -m 8G
>
> caused below changes (please refer to attached dmesg/kmsg for entire 
> log/backtrace):

Is the fix for this been posted yet ?

(asking since I didn't see the fix and my mailer is dropping emails from
 lkml).


Re: [PATCH] nvme: Switch to using the new API kobj_to_dev()

2021-03-04 Thread Chaitanya Kulkarni
On 3/4/21 01:58, Jiapeng Chong wrote:
> Fix the following coccicheck warnings:
>
> ./drivers/nvme/host/core.c:3714:60-61: WARNING opportunity for
> kobj_to_dev().
>
> ./drivers/nvme/host/core.c:3475:60-61: WARNING opportunity for
> kobj_to_dev().
>
> Reported-by: Abaci Robot 
> Signed-off-by: Jiapeng Chong 
This patch is already NACKED.


Re: [PATCH] mm/compaction: remove unused variable sysctl_compact_memory

2021-03-03 Thread Chaitanya Kulkarni
On 3/2/21 22:21, Pintu Kumar wrote:
> The sysctl_compact_memory is mostly unsed in mm/compaction.c
> It just acts as a place holder for sysctl.
>
> Thus we can remove it from here and move the declaration directly
> in kernel/sysctl.c itself.
> This will also eliminate the extern declaration from header file.
> No functionality is broken or changed this way.
>
> Signed-off-by: Pintu Kumar 
> Signed-off-by: Pintu Agarwal 

You need to specify the first commit which added sysctl_compact_memory
variable and if exists the last commit which removed the last access
of the same variable in the file mm/compaction.c in for completeness
of the commit log.




Re: [blktrace] c055908abe: WARNING:at_kernel/trace/trace.c:#create_trace_option_files

2021-02-27 Thread Chaitanya Kulkarni
On 2/27/21 06:49, Steven Rostedt wrote:
> On Sat, 27 Feb 2021 19:44:40 +0800
> kernel test robot  wrote:
>
>> [   20.216017] WARNING: CPU: 0 PID: 1 at kernel/trace/trace.c:8370 
>> create_trace_option_files (kbuild/src/consumer/kernel/trace/trace.c:8370 
>> (discriminator 1)) 
>> [   20.218480] Modules linked in:
>> [   20.219395] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 
>> 5.11.0-09341-gc055908abe0d #1
>> [   20.221182] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
>> 1.12.0-1 04/01/2014
>> [   20.224540] EIP: create_trace_option_files 
>> (kbuild/src/consumer/kernel/trace/trace.c:8370 (discriminator 1)) 
>> [ 20.225816] Code: d5 01 83 15 2c b7 08 d5 00 83 c0 01 39 c8 0f 84 c7 00 00 
>> 00 8b 14 c7 39 72 44 75 df 83 05 10 b7 08 d5 01 83 15 14 b7 08 d5 00 <0f> 0b 
>> 83 05 18 b7 08 d5 01 83 15 1c b7 08 d5 00 83 05 20 b7 08 d5
> Looks to be from this:
>
>> +static struct tracer blk_tracer_ext __read_mostly = {
>> +.name   = "blkext",
>> +.init   = blk_tracer_init,
>> +.reset  = blk_tracer_reset,
>> +.start  = blk_tracer_start,
>> +.stop   = blk_tracer_stop,
>> +.print_header   = blk_tracer_print_header,
>> +.print_line = blk_tracer_print_line_ext,
>> +.flags  = _tracer_flags,
>   ^^^
>
> As blk_tracer already registers those flags, when it gets registered as
> a tracer, and flag names can not be duplicated.
>
> I could fix the infrastructure to detect the same set of flags being
> registered by two different tracers, but in the mean time, it may still
> work to use the blk_trace_flags from blk_tracer, and keep .flags NULL
> here.
>
> -- Steve
Thanks for the reply Steve. This is still under currently discussion and
I'm still
waiting formore people to reply on this approach, if we end up having
this as
a part of final implementation we may need to fix that.

>
>> +.set_flag   = blk_tracer_set_flag,
>> +};
>> +



Re: [PATCH v2] block: Add bio_max_segs

2021-02-26 Thread Chaitanya Kulkarni
On 2/26/21 12:39, Matthew Wilcox wrote:
> This seems to have missed the merge window ;-(
>
> On Fri, Jan 29, 2021 at 04:38:57AM +, Matthew Wilcox (Oracle) wrote:
>> It's often inconvenient to use BIO_MAX_PAGES due to min() requiring the
>> sign to be the same.  Introduce bio_max_segs() and change BIO_MAX_PAGES to
>> be unsigned to make it easier for the users.
>>
>> Signed-off-by: Matthew Wilcox (Oracle) 
>> ---
>> v2:
>>  - Rename from bio_limit() to bio_max_segs()
>>  - Rebase on next-20210128
>>  - Use DIV_ROUND_UP in dm-log-writes.c
>>  - Use DIV_ROUND_UP in iomap/buffered-io.c
Looks good.

Reviewed-by: Chaitanya Kulkarni 


Re: [RFC PATCH] blk-core: remove blk_put_request()

2021-02-24 Thread Chaitanya Kulkarni
On 2/24/21 10:56, Christoph Hellwig wrote:
> On Wed, Feb 24, 2021 at 09:48:21AM -0700, Jens Axboe wrote:
>> Would make sense to rename blk_get_request() to blk_mq_alloc_request()
>> and then we have API symmetry. The get/put don't make sense when there
>> are no references involved.
>>
>> But it's a lot of churn for very little reward, which is always kind
>> of annoying. Especially for the person that has to carry the patches.
> Let's do the following:
>
>  - move the initialize_rq_fn call from blk_get_request into
>blk_mq_alloc_request and make the former a trivial alias for the
>latter
>  - migrate to the blk_mq_* versions on a per-driver/subsystem basis.
>The scsi migration depends on the first item above, so it will have
>to go with that or wait for the next merge window
>  - don't migrate the legacy ide driver, as it is about to be removed and
>has a huge number of blk_get_request calls
>

Okay, thanks for the feedback, will try and get something together.


Re: linux-next: build warning after merge of the block tree

2021-02-24 Thread Chaitanya Kulkarni
Randy,

On 2/24/21 13:45, Randy Dunlap wrote:
> On 2/24/21 1:41 PM, Chaitanya Kulkarni wrote:
>> On 2/24/21 02:43, Stephen Rothwell wrote:
>>>> I'll setup doc generation using sphinx on my machine, is there
>>>> a particular command line that you have used for these warnings ?
>>> I just do a "make htmldocs"
>> I did that, please have a look at the test log.
>>
> Hi,
>
> Where is the test log?
>

I sent out the following patch yesterday @ 23:16 PST with Stephen in CC
on linux-block :- https://marc.info/?l=linux-block=161415113122092=2

It has the test log.



Re: linux-next: build warning after merge of the block tree

2021-02-24 Thread Chaitanya Kulkarni
On 2/24/21 02:43, Stephen Rothwell wrote:
>> I'll setup doc generation using sphinx on my machine, is there
>> a particular command line that you have used for these warnings ?
> I just do a "make htmldocs"
I did that, please have a look at the test log.


Re: linux-next: build warning after merge of the block tree

2021-02-23 Thread Chaitanya Kulkarni
On 2/23/21 21:33, Stephen Rothwell wrote:
>>>   1f83bb4b4914 ("blktrace: add blk_fill_rwbs documentation comment")
>>>
>>> -- Cheers, Stephen Rothwell  
>> I've failed to understand this warning as rwbs is present in the doc header
>> and in the function parameter :-
> I presume it is the missing ':' after @rwbs in the comment.
I've sent a fix with your reported by, it will be great if you can provide
reviewed-by tag.
> -- Cheers, Stephen Rothwell



Re: linux-next: build warning after merge of the block tree

2021-02-23 Thread Chaitanya Kulkarni
On 2/23/21 21:33, Stephen Rothwell wrote:
>> I've failed to understand this warning as rwbs is present in the doc header
>> and in the function parameter :-
> I presume it is the missing ':' after @rwbs in the comment.
Thanks, I was looking at the wrong places all this time, will send a fix.

I'll setup doc generation using sphinx on my machine, is there
a particular command line that you have used for these warnings ?


Re: linux-next: build warning after merge of the block tree

2021-02-23 Thread Chaitanya Kulkarni
Stephen,

On 2/23/21 18:31, Stephen Rothwell wrote:
> Hi all,
>
> After merging the block tree, today's linux-next build (htmldocs)
> produced this warning:
>
> kernel/trace/blktrace.c:1878: warning: Function parameter or member 'rwbs' 
> not described in 'blk_fill_rwbs'`
>
> Introduced by commit
>
>   1f83bb4b4914 ("blktrace: add blk_fill_rwbs documentation comment")
>
> -- Cheers, Stephen Rothwell
I've failed to understand this warning as rwbs is present in the doc header
and in the function parameter :-

/** 
  

 * blk_fill_rwbs - Fill the buffer rwbs by mapping op to character string.
 * @rwbsbuffer to be filled
 * @op: REQ_OP_XXX for the tracepoint
 *
 * Description:
 * Maps the REQ_OP_XXX to character and fills the buffer provided by the
 * caller with resulting string.
 *
 **/
void blk_fill_rwbs(char *rwbs, unsigned int op)
{
int i = 0;

if (op & REQ_PREFLUSH)
rwbs[i++] = 'F';

switch (op & REQ_OP_MASK) {
case REQ_OP_WRITE:
case REQ_OP_WRITE_SAME:
rwbs[i++] = 'W';
break;
case REQ_OP_DISCARD:
rwbs[i++] = 'D';
break;
case REQ_OP_SECURE_ERASE:
rwbs[i++] = 'D';
rwbs[i++] = 'E';
break;
case REQ_OP_FLUSH:
rwbs[i++] = 'F';
break;
case REQ_OP_READ:
rwbs[i++] = 'R';
break;
default:
rwbs[i++] = 'N';
}

if (op & REQ_FUA)
rwbs[i++] = 'F';
if (op & REQ_RAHEAD)
rwbs[i++] = 'A';
if (op & REQ_SYNC)
rwbs[i++] = 'S';
if (op & REQ_META)
rwbs[i++] = 'M';

rwbs[i] = '\0';
}
EXPORT_SYMBOL_GPL(blk_fill_rwbs);



Re: linux-next: build warning after merge of the block tree

2021-02-23 Thread Chaitanya Kulkarni
On 2/23/21 18:31, Stephen Rothwell wrote:
> Hi all,
>
> After merging the block tree, today's linux-next build (htmldocs)
> produced this warning:
>
> kernel/trace/blktrace.c:1878: warning: Function parameter or member 'rwbs' 
> not described in 'blk_fill_rwbs'`
>
> Introduced by commit
>
>   1f83bb4b4914 ("blktrace: add blk_fill_rwbs documentation comment")
>
Thanks for reporting, I'll send a fix soon.


Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-23 Thread Chaitanya Kulkarni
On 2/23/21 07:09, Christoph Hellwig wrote:
> I assume you are sending this patch, let me know otherwise.
> If you do please add, looks good.

I'll split the gfp_mask cleanup out, and will submit it with your as
the author if that is ok.  I'll need a signoff, though.

Okay, here it is :-

Signed-off-by: Chaitanya Kulkarni .

I'll review the patch(es) once you post again.



Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-22 Thread Chaitanya Kulkarni
On 2/22/21 23:10, Christoph Hellwig wrote:
> On Tue, Feb 23, 2021 at 03:51:23AM +0000, Chaitanya Kulkarni wrote:
>> Looking at the other call sites do we need something like following ?
>> Since __blk_queue_bounce() passes the NULL for the passthru case as a
>> bio_set value ?
> Well, that is a somewhat odd calling convention.  What about the patch below
> instead?  That being we really need to kill this bouncing code off..
I assume you are sending this patch, let me know otherwise.
If you do please add, looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-22 Thread Chaitanya Kulkarni
On 2/22/21 23:10, Christoph Hellwig wrote:
> Well, that is a somewhat odd calling convention.  What about the patch below
> instead?  That being we really need to kill this bouncing code off..
If we can kill it off soon it will be great.
>
> diff --git a/block/bounce.c b/block/bounce.c
> index fc55314aa4269a..789fbcacb1e92a 100644
> --- a/block/bounce.c
> +++ b/block/bounce.c
> @@ -214,9 +214,9 @@ static void bounce_end_io_read_isa(struct bio *bio)
>   __bounce_end_io_read(bio, _page_pool);
>  }
>  
> -static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask,
> - struct bio_set *bs)
> +static struct bio *bounce_clone_bio(struct bio *bio_src, bool passthrough)
>  {
> + unsigned int nr_vecs = bio_segments(bio_src);
>   struct bvec_iter iter;
>   struct bio_vec bv;
>   struct bio *bio;
> @@ -242,8 +242,10 @@ static struct bio *bounce_clone_bio(struct bio *bio_src, 
> gfp_t gfp_mask,
>*asking for trouble and would force extra work on
>*__bio_clone_fast() anyways.
>*/
> -
> - bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs);
> + if (passthrough)
> + bio = bio_kmalloc(GFP_NOIO, nr_vecs);
> + else
> + bio = bio_alloc_bioset(GFP_NOIO, nr_vecs, _bio_set);
>   if (!bio)
>   return NULL;
>   bio->bi_bdev= bio_src->bi_bdev;
> @@ -269,11 +271,11 @@ static struct bio *bounce_clone_bio(struct bio 
> *bio_src, gfp_t gfp_mask,
>   break;
>   }
>  
> - if (bio_crypt_clone(bio, bio_src, gfp_mask) < 0)
> + if (bio_crypt_clone(bio, bio_src, GFP_NOIO) < 0)
>   goto err_put;
>  
>   if (bio_integrity(bio_src) &&
> - bio_integrity_clone(bio, bio_src, gfp_mask) < 0)
> + bio_integrity_clone(bio, bio_src, GFP_NOIO) < 0)
>   goto err_put;
>  
>   bio_clone_blkg_association(bio, bio_src);
> @@ -313,8 +315,7 @@ static void __blk_queue_bounce(struct request_queue *q, 
> struct bio **bio_orig,
>   submit_bio_noacct(*bio_orig);
>   *bio_orig = bio;
>   }
> - bio = bounce_clone_bio(*bio_orig, GFP_NOIO, passthrough ? NULL :
> - _bio_set);
> + bio = bounce_clone_bio(*bio_orig, passthrough);
>  
>   /*
>* Bvec table can't be updated by bio_for_each_segment_all(),
>
Seems like this fixes the issue and does the cleanup in one patch, looks
good.



Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-22 Thread Chaitanya Kulkarni
On 2/22/21 20:22, John Stultz wrote:
> On Mon, Feb 22, 2021 at 7:39 PM Chaitanya Kulkarni
>  wrote:
>> On 2/22/21 19:07, John Stultz wrote:
>>> [   34.784901] ueventd: LoadWithAliases was unable to load 
>>> platform:regulatory
>>> [   34.785313]  bio_alloc_bioset+0x14/0x230
>>> [   34.796189]  bio_clone_fast+0x28/0x80
>>> [   34.799848]  bio_split+0x50/0xd0
>>> [   34.803072]  blk_crypto_fallback_encrypt_bio+0x2ec/0x5e8
>>> [   34.808384]  blk_crypto_fallback_bio_prep+0xfc/0x140
>>> [   34.813345]  __blk_crypto_bio_prep+0x13c/0x150
>>> [   34.817784]  submit_bio_noacct+0x3c0/0x548
>>> [   34.821880]  submit_bio+0x48/0x200
>>> [   34.825278]  ext4_io_submit+0x50/0x68
>>> [   34.828939]  ext4_writepages+0x558/0xca8
>>> [   34.832860]  do_writepages+0x58/0x108
>>> [   34.836522]  __writeback_single_inode+0x44/0x510
>>> [   34.841137]  writeback_sb_inodes+0x1e0/0x4a8
>>> [   34.845404]  __writeback_inodes_wb+0x78/0xe8
>>> [   34.849670]  wb_writeback+0x274/0x3e8
>>> [   34.853328]  wb_workfn+0x308/0x5f0
>>> [   34.856726]  process_one_work+0x1ec/0x4d0
>>> [   34.860734]  worker_thread+0x44/0x478
>>> [   34.864392]  kthread+0x140/0x150
>>> [   34.867618]  ret_from_fork+0x10/0x30
>>> [   34.871197] Code: a9ba7bfd 910003fd f9000bf3 7900bfa1 (f9403441)
>>> [   34.877289] ---[ end trace e6c2a3ab108278f0 ]---
>>> [   34.893636] Kernel panic - not syncing: Oops: Fatal exception
>>>
>> If you have time then until you get the reply from others, can you try
>> following patch ?
>>
>> diff --git a/block/bio.c b/block/bio.c
>> index a1c4d2900c7a..9976400ec66a 100644
>> --- a/block/bio.c
>> +++ b/block/bio.c
>> @@ -663,7 +663,10 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t
>> gfp_mask, struct bio_set *bs)
>>  {
>> struct bio *b;
>>
>> -   b = bio_alloc_bioset(gfp_mask, 0, bs);
>> +   if (bs)
>> +   b = bio_alloc_bioset(gfp_mask, 0, bs);
>> +   else
>> +   b = bio_kmalloc(gfp_mask, 0);
>> if (!b)
>> return NULL;
>>
>> P.S.This is purely based on the code inspection and it may not solve your
>> issue. Proceed with the caution as it may *break* your system.
> So with an initial quick test, this patch (along with the follow-on
> one you sent) seems to avoid the issue.
Thanks for bisecting, the patch you are referring to is with the similar
fix for bio bounce ? 
> I'm wondering if given there are multiple call sites, that in
> bio_alloc_bioset() would something like the following make more sense?
> (apologies, copy pasted so this is whitespace corrupted)
> thanks
> -john
I've asked Christoph about how we can go about this issue, based on his
reply I can send a patch.

I think having kmalloc is what we want to avoid in the fast path, with
that in
mind in my opinion we need to fix the call sites with kmalloc call if number
is small,  which I think it is. Let's wait.

Meanwhile it will be great if you can share the result of the thorough
testing.

> diff --git a/block/bio.c b/block/bio.c
> index a1c4d2900c7a..391d5cde79fc 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -402,6 +402,9 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask,
> unsigned short nr_iovecs,
> struct bio *bio;
> void *p;
>
> +   if(!bs)
> +   return bio_kmalloc(gfp_mask, 0);
it may not work since nr_iovecs needs to be passed
> +
> /* should not use nobvec bioset for nr_iovecs > 0 */
> if (WARN_ON_ONCE(!mempool_initialized(>bvec_pool) && nr_iovecs > 
> 0))
> return NULL;
>



Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-22 Thread Chaitanya Kulkarni
Christoph,

On 2/22/21 19:07, John Stultz wrote:
> [   34.785313]  bio_alloc_bioset+0x14/0x230
> [   34.796189]  bio_clone_fast+0x28/0x80
> [   34.799848]  bio_split+0x50/0xd0
> [   34.803072]  blk_crypto_fallback_encrypt_bio+0x2ec/0x5e8
> [   34.808384]  blk_crypto_fallback_bio_prep+0xfc/0x140
> [   34.813345]  __blk_crypto_bio_prep+0x13c/0x150
> [   34.817784]  submit_bio_noacct+0x3c0/0x548
> [   34.821880]  submit_bio+0x48/0x200
> [   34.825278]  ext4_io_submit+0x50/0x68
> [   34.828939]  ext4_writepages+0x558/0xca8
> [   34.832860]  do_writepages+0x58/0x108
> [   34.836522]  __writeback_single_inode+0x44/0x510
> [   34.841137]  writeback_sb_inodes+0x1e0/0x4a8
> [   34.845404]  __writeback_inodes_wb+0x78/0xe8
> [   34.849670]  wb_writeback+0x274/0x3e8
> [   34.853328]  wb_workfn+0x308/0x5f0
> [   34.856726]  process_one_work+0x1ec/0x4d0
> [   34.860734]  worker_thread+0x44/0x478
> [   34.864392]  kthread+0x140/0x150
> [   34.867618]  ret_from_fork+0x10/0x30
> [   34.871197] Code: a9ba7bfd 910003fd f9000bf3 7900bfa1 (f9403441)
> [   34.877289] ---[ end trace e6c2a3ab108278f0 ]---
> [   34.893636] Kernel panic - not syncing: Oops: Fatal exception
>
Looking at the other call sites do we need something like following ?

diff --git a/block/bounce.c b/block/bounce.c
index fc55314aa426..f8a3656e89c3 100644
--- a/block/bounce.c
+++ b/block/bounce.c
@@ -217,6 +217,7 @@ static void bounce_end_io_read_isa(struct bio *bio)
 static struct bio *bounce_clone_bio(struct bio *bio_src, gfp_t gfp_mask,
struct bio_set *bs)
 {
+   unsigned int nr_iovecs = bio_segments(bio_src);
struct bvec_iter iter;
struct bio_vec bv;
struct bio *bio;
@@ -243,7 +244,11 @@ static struct bio *bounce_clone_bio(struct bio
*bio_src, gfp_t gfp_mask,
 *__bio_clone_fast() anyways.
 */
 
-   bio = bio_alloc_bioset(gfp_mask, bio_segments(bio_src), bs);
+   if (bs)
+   bio = bio_alloc_bioset(gfp_mask, nr_iovecs, bs);
+   else
+   bio = bio_kmalloc(gfp_mask, nr_iovecs);
+
if (!bio)
return NULL;
bio->bi_bdev= bio_src->bi_bdev;

Since __blk_queue_bounce() passes the NULL for the passthru case as a
bio_set value ?



Re: [REGRESSION] "split bio_kmalloc from bio_alloc_bioset" causing crash shortly after bootup

2021-02-22 Thread Chaitanya Kulkarni
On 2/22/21 19:07, John Stultz wrote:
> [   34.784901] ueventd: LoadWithAliases was unable to load platform:regulatory
> [   34.785313]  bio_alloc_bioset+0x14/0x230
> [   34.796189]  bio_clone_fast+0x28/0x80
> [   34.799848]  bio_split+0x50/0xd0
> [   34.803072]  blk_crypto_fallback_encrypt_bio+0x2ec/0x5e8
> [   34.808384]  blk_crypto_fallback_bio_prep+0xfc/0x140
> [   34.813345]  __blk_crypto_bio_prep+0x13c/0x150
> [   34.817784]  submit_bio_noacct+0x3c0/0x548
> [   34.821880]  submit_bio+0x48/0x200
> [   34.825278]  ext4_io_submit+0x50/0x68
> [   34.828939]  ext4_writepages+0x558/0xca8
> [   34.832860]  do_writepages+0x58/0x108
> [   34.836522]  __writeback_single_inode+0x44/0x510
> [   34.841137]  writeback_sb_inodes+0x1e0/0x4a8
> [   34.845404]  __writeback_inodes_wb+0x78/0xe8
> [   34.849670]  wb_writeback+0x274/0x3e8
> [   34.853328]  wb_workfn+0x308/0x5f0
> [   34.856726]  process_one_work+0x1ec/0x4d0
> [   34.860734]  worker_thread+0x44/0x478
> [   34.864392]  kthread+0x140/0x150
> [   34.867618]  ret_from_fork+0x10/0x30
> [   34.871197] Code: a9ba7bfd 910003fd f9000bf3 7900bfa1 (f9403441)
> [   34.877289] ---[ end trace e6c2a3ab108278f0 ]---
> [   34.893636] Kernel panic - not syncing: Oops: Fatal exception
>

If you have time then until you get the reply from others, can you try
following patch ?

diff --git a/block/bio.c b/block/bio.c
index a1c4d2900c7a..9976400ec66a 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -663,7 +663,10 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t
gfp_mask, struct bio_set *bs)
 {
struct bio *b;
 
-   b = bio_alloc_bioset(gfp_mask, 0, bs);
+   if (bs)
+   b = bio_alloc_bioset(gfp_mask, 0, bs);
+   else
+   b = bio_kmalloc(gfp_mask, 0);
if (!b)
return NULL;

P.S.This is purely based on the code inspection and it may not solve your
issue. Proceed with the caution as it may *break* your system.



Re: linux-next: Fixes tag needs some work in the block tree

2021-02-22 Thread Chaitanya Kulkarni
On 2/22/21 13:01, Stephen Rothwell wrote:
> Hi all,
>
> In commit
>
>   179d16007236 ("block: remove superfluous param in blk_fill_rwbs()")
>
> Fixes tag
>
>   Fixes: 1b9a9ab78b0 ("blktrace: use op accessors")
>
> has these problem(s):
>
>   - SHA1 should be at least 12 digits long
> Can be fixed by setting core.abbrev to 12 (or more) or (for git v2.11
> or later) just making sure it is not set (or set to "auto").
>
> -- Cheers, Stephen Rothwell

Yes, it was my fault it should be 1b9a9ab78b0a the last 'a' is missing.



[RFC PATCH] blk-core: remove blk_put_request()

2021-02-22 Thread Chaitanya Kulkarni
The function blk_put_request() is just a wrapper to
blk_mq_free_request(), remove the unnecessary wrapper.

Any feedback is welcome on this RFC.

Signed-off-by: Chaitanya Kulkarni 
---
 block/blk-core.c   |  6 --
 block/blk-merge.c  |  2 +-
 block/bsg-lib.c|  4 ++--
 block/bsg.c|  4 ++--
 block/scsi_ioctl.c |  6 +++---
 drivers/block/paride/pd.c  |  2 +-
 drivers/block/pktcdvd.c|  2 +-
 drivers/block/virtio_blk.c |  2 +-
 drivers/cdrom/cdrom.c  |  4 ++--
 drivers/ide/ide-atapi.c|  2 +-
 drivers/ide/ide-cd.c   |  4 ++--
 drivers/ide/ide-cd_ioctl.c |  2 +-
 drivers/ide/ide-devsets.c  |  2 +-
 drivers/ide/ide-disk.c |  2 +-
 drivers/ide/ide-ioctls.c   |  4 ++--
 drivers/ide/ide-park.c |  2 +-
 drivers/ide/ide-pm.c   |  4 ++--
 drivers/ide/ide-tape.c |  2 +-
 drivers/ide/ide-taskfile.c |  2 +-
 drivers/md/dm-mpath.c  |  2 +-
 drivers/mmc/core/block.c   | 10 +-
 drivers/scsi/scsi_error.c  |  2 +-
 drivers/scsi/scsi_lib.c|  2 +-
 drivers/scsi/sg.c  |  6 +++---
 drivers/scsi/st.c  |  4 ++--
 drivers/scsi/ufs/ufshcd.c  |  6 +++---
 drivers/target/target_core_pscsi.c |  4 ++--
 fs/nfsd/blocklayout.c  |  4 ++--
 include/linux/blkdev.h |  1 -
 29 files changed, 46 insertions(+), 53 deletions(-)

diff --git a/block/blk-core.c b/block/blk-core.c
index fc60ff208497..1754f5e7cc80 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -642,12 +642,6 @@ struct request *blk_get_request(struct request_queue *q, 
unsigned int op,
 }
 EXPORT_SYMBOL(blk_get_request);
 
-void blk_put_request(struct request *req)
-{
-   blk_mq_free_request(req);
-}
-EXPORT_SYMBOL(blk_put_request);
-
 static void handle_bad_sector(struct bio *bio, sector_t maxsector)
 {
char b[BDEVNAME_SIZE];
diff --git a/block/blk-merge.c b/block/blk-merge.c
index ffb4aa0ea68b..f3493ee243fd 100644
--- a/block/blk-merge.c
+++ b/block/blk-merge.c
@@ -845,7 +845,7 @@ int blk_attempt_req_merge(struct request_queue *q, struct 
request *rq,
 
free = attempt_merge(q, rq, next);
if (free) {
-   blk_put_request(free);
+   blk_mq_free_request(free);
return 1;
}
 
diff --git a/block/bsg-lib.c b/block/bsg-lib.c
index 330fede77271..8ea2b33783fb 100644
--- a/block/bsg-lib.c
+++ b/block/bsg-lib.c
@@ -67,7 +67,7 @@ static int bsg_transport_fill_hdr(struct request *rq, struct 
sg_io_v4 *hdr,
 
 out_free_bidi_rq:
if (job->bidi_rq)
-   blk_put_request(job->bidi_rq);
+   blk_mq_free_request(job->bidi_rq);
 out:
kfree(job->request);
return ret;
@@ -128,7 +128,7 @@ static void bsg_transport_free_rq(struct request *rq)
 
if (job->bidi_rq) {
blk_rq_unmap_user(job->bidi_bio);
-   blk_put_request(job->bidi_rq);
+   blk_mq_free_request(job->bidi_rq);
}
 
kfree(job->request);
diff --git a/block/bsg.c b/block/bsg.c
index bd10922d5cbb..4ddc84aebecf 100644
--- a/block/bsg.c
+++ b/block/bsg.c
@@ -158,7 +158,7 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, 
void __user *uarg)
 
ret = q->bsg_dev.ops->fill_hdr(rq, , mode);
if (ret) {
-   blk_put_request(rq);
+   blk_mq_free_request(rq);
return ret;
}
 
@@ -189,7 +189,7 @@ static int bsg_sg_io(struct request_queue *q, fmode_t mode, 
void __user *uarg)
 
 out_free_rq:
rq->q->bsg_dev.ops->free_rq(rq);
-   blk_put_request(rq);
+   blk_mq_free_request(rq);
if (!ret && copy_to_user(uarg, , sizeof(hdr)))
return -EFAULT;
return ret;
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 6599bac0a78c..52cd3fd924fc 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -366,7 +366,7 @@ static int sg_io(struct request_queue *q, struct gendisk 
*bd_disk,
 out_free_cdb:
scsi_req_free_cmd(req);
 out_put_request:
-   blk_put_request(rq);
+   blk_mq_free_request(rq);
return ret;
 }
 
@@ -509,7 +509,7 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk 
*disk, fmode_t mode,
}

 error:
-   blk_put_request(rq);
+   blk_mq_free_request(rq);
 
 error_free_buffer:
kfree(buffer);
@@ -534,7 +534,7 @@ static int __blk_send_generic(struct request_queue *q, 
struct gendisk *bd_disk,
scsi_req(rq)->cmd_len = 6;
blk_execute_rq(bd_disk, rq, 0);
err = scsi_req(rq)->result ? -EIO : 0;
-   blk_put_request(rq);
+   blk_mq_free_request(rq);
 
return err;
 }
diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c
index 897acda20ac8..381fc0cf0b35 10

Re: [PATCH] nvme-core: Switch to using the new API kobj_to_dev()

2021-02-20 Thread Chaitanya Kulkarni
On 2/20/21 01:15, Yang Li wrote:
> fixed the following coccicheck:
> ./drivers/nvme/host/core.c:3440:60-61: WARNING opportunity for
> kobj_to_dev()
> ./drivers/nvme/host/core.c:3679:60-61: WARNING opportunity for
> kobj_to_dev()
>
> Reported-by: Abaci Robot 
> Signed-off-by: Yang Li 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [RFC PATCH 29/34] power/swap: use bio_new in hib_submit_io

2021-02-17 Thread Chaitanya Kulkarni
On 2/17/21 14:03, Pavel Machek wrote:
> Hi!
>> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
>> index c73f2e295167..e92e36c053a6 100644
>> --- a/kernel/power/swap.c
>> +++ b/kernel/power/swap.c
>> @@ -271,13 +271,12 @@ static int hib_submit_io(int op, int op_flags, pgoff_t 
>> page_off, void *addr,
>>  struct hib_bio_batch *hb)
>>  {
>>  struct page *page = virt_to_page(addr);
>> +sector_t sect = page_off * (PAGE_SIZE >> 9);
>>  struct bio *bio;
>>  int error = 0;
>>  
>> -bio = bio_alloc(GFP_NOIO | __GFP_HIGH, 1);
>> -bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
>> -bio_set_dev(bio, hib_resume_bdev);
>> -bio_set_op_attrs(bio, op, op_flags);
>> +bio = bio_new(hib_resume_bdev, sect, op, op_flags, 1,
>> +  GFP_NOIO | __GFP_HIGH);
>>  
> C function with 6 arguments... dunno. Old version looks comparable or
> even more readable...
>
> Best regards,
>   Pavel
The library functions that are in the kernel tree which are used
in different file-systems and fabrics drivers do take 6 arguments.

Plus what is the point of duplicating code for mandatory
parameters all over the kernel ?



Re: [PATCH v3 1/1] exfat: add support ioctl and FITRIM function

2021-02-17 Thread Chaitanya Kulkarni
On 2/16/21 22:07, Hyeongseok Kim wrote:
> Add FITRIM ioctl to enable discarding unused blocks while mounted.
> As current exFAT doesn't have generic ioctl handler, add empty ioctl
> function first, and add FITRIM handler.
>
> Signed-off-by: Hyeongseok Kim 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH v2 1/2] exfat: add initial ioctl function

2021-02-16 Thread Chaitanya Kulkarni
On 2/16/21 16:13, Hyeongseok Kim wrote:
> Sorry, I don't understand exactly.
> You're saying that these 2 patch should be merged to a single patch?
> Would it be better?
I think so unless there is a specific reason for this to keep it isolated.


Re: [PATCH v2 2/2] exfat: add support FITRIM ioctl

2021-02-16 Thread Chaitanya Kulkarni
On 2/16/21 14:36, Hyeongseok Kim wrote:
> +static int exfat_ioctl_fitrim(struct inode *inode, unsigned long arg)
> +{
> + struct super_block *sb = inode->i_sb;
Do you really need sb variable ? it is only used once if I'm not wrong.
> + struct request_queue *q = bdev_get_queue(sb->s_bdev);
> + struct fstrim_range range;
> + int ret = 0;



Re: [PATCH v2 1/2] exfat: add initial ioctl function

2021-02-16 Thread Chaitanya Kulkarni
On 2/16/21 14:36, Hyeongseok Kim wrote:
> Initialize empty ioctl function
>
> Signed-off-by: Hyeongseok Kim 
This patch doesn't do much, but this commit log could be better.

Also from my experience there is not point in introducing an empty
function.


Re: [PATCH 2/2] exfat: add support FITRIM ioctl

2021-02-15 Thread Chaitanya Kulkarni
On 2/14/21 20:28, Hyeongseok Kim wrote:
> add FITRIM ioctl to support trimming mounted filesystem
>
> Signed-off-by: Hyeongseok Kim 
> ---
>  fs/exfat/balloc.c   | 89 +
>  fs/exfat/exfat_fs.h |  1 +
>  fs/exfat/file.c | 33 +
>  3 files changed, 123 insertions(+)
>
> diff --git a/fs/exfat/balloc.c b/fs/exfat/balloc.c
> index 761c79c3a4ba..edd0f6912e8e 100644
> --- a/fs/exfat/balloc.c
> +++ b/fs/exfat/balloc.c
> @@ -273,3 +273,92 @@ int exfat_count_used_clusters(struct super_block *sb, 
> unsigned int *ret_count)
>   *ret_count = count;
>   return 0;
>  }
> +
> +int exfat_trim_fs(struct inode *inode, struct fstrim_range *range)
> +{
> + struct super_block *sb = inode->i_sb;
Reverse tree style for function variable declaration would be nice which you
partially have it here.
> + struct exfat_sb_info *sbi = EXFAT_SB(sb);
> + u64 clu_start, clu_end, trim_minlen, trimmed_total = 0;
> + unsigned int trim_begin, trim_end, count;
> + unsigned int next_free_clu;
> + int err = 0;
> +
> + clu_start = max_t(u64, range->start >> sbi->cluster_size_bits,
> + EXFAT_FIRST_CLUSTER);
> + clu_end = clu_start + (range->len >> sbi->cluster_size_bits) - 1;
> + trim_minlen = range->minlen >> sbi->cluster_size_bits;
> +
> + if (clu_start >= sbi->num_clusters || range->len < sbi->cluster_size)
> + return -EINVAL;
> +
> + if (clu_end >= sbi->num_clusters)
> + clu_end = sbi->num_clusters - 1;
> +
> + mutex_lock(_SB(inode->i_sb)->s_lock);
> +
> + trim_begin = trim_end = exfat_find_free_bitmap(sb, clu_start);
> + if (trim_begin == EXFAT_EOF_CLUSTER)
> + goto unlock;
> +
> + next_free_clu = exfat_find_free_bitmap(sb, trim_end + 1);
> + if (next_free_clu == EXFAT_EOF_CLUSTER)
> + goto unlock;
> +
> + do {
> + if (next_free_clu == trim_end + 1)
> + /* extend trim range for continuous free cluster */
> + trim_end++;
> + else {
> + /* trim current range if it's larger than trim_minlen */
> + count = trim_end - trim_begin + 1;
> + if (count >= trim_minlen) {
> + err = sb_issue_discard(sb,
> + exfat_cluster_to_sector(sbi, 
> trim_begin),
> + count * sbi->sect_per_clus, GFP_NOFS, 
> 0);
You are specifying the last argument as 0 to sb_issue_disacrd() i.e.
flags == 0 this will propagate to :-

sb_issue_discard()
blkdev_issue_discard()
__blkdev__issue_discard()

Now blkdev_issue_disacrd() returns -ENOTSUPP in 3 cases :-

1. If flags arg is set to BLKDEV_DISCARD_SECURE and queue doesn't support
   secure erase. In this case you have not set BLKDEV_DISCARD_SECURE that.
   So it should not return -EOPNOTSUPP.
2. If queue doesn't support discard. In this case caller of this function
   already set that. So it should not return -EOPNOTSUPP.
3. If q->limits.discard_granularity is not but LLD which I think caller of
   this function already used that to calculate the range->minlen.

If above is true then err will not have value of -EOPNOTSUPP ?

> + if (err && err != -EOPNOTSUPP)
> + goto unlock;
> + if (!err)
> + trimmed_total += count;
> + }
> +
> + /* set next start point of the free hole */
> + trim_begin = trim_end = next_free_clu;
> + }
> +
> + if (next_free_clu >= clu_end)
> + break;
> +
> + if (fatal_signal_pending(current)) {
> + err = -ERESTARTSYS;
> + goto unlock;
> + }
> +
> + if (need_resched()) {
> + mutex_unlock(_SB(inode->i_sb)->s_lock);
sb_issue_discard() ->blkdev_issue_discard() will call cond_resced().
1. The check for need_resched() will ever be true since
blkdev_issue_discard()
   is already calling cond_sched() ?
2. If so do you still need to drop the mutex before calling
   sb_issue_discard() ?
> + cond_resched();
> + mutex_lock(_SB(inode->i_sb)->s_lock);
> + }
> +
> + next_free_clu = exfat_find_free_bitmap(sb, next_free_clu + 1);
> +
> + } while (next_free_clu != EXFAT_EOF_CLUSTER &&
> + next_free_clu > trim_end);
> +
> + /* try to trim remainder */
> + count = trim_end - trim_begin + 1;
> + if (count >= trim_minlen) {
> + err = sb_issue_discard(sb, exfat_cluster_to_sector(sbi, 
> trim_begin),
> + count * sbi->sect_per_clus, GFP_NOFS, 0);
> + if (err && err != -EOPNOTSUPP)
> + goto unlock;
> +
> + 

Re: [PATCH] xfs: fix boolreturn.cocci warnings

2021-02-10 Thread Chaitanya Kulkarni
On 2/10/21 12:11 PM, kernel test robot wrote:
> From: kernel test robot 
>
> fs/xfs/xfs_log.c:1062:9-10: WARNING: return of 0/1 in function 
> 'xfs_log_need_covered' with return type bool
>
>  Return statements in functions returning bool should use
>  true/false instead of 1/0.
> Generated by: scripts/coccinelle/misc/boolreturn.cocci
>
> Fixes: 37444fc4cc39 ("xfs: lift writable fs check up into log worker task")
> CC: Brian Foster 
> Reported-by: kernel test robot 
> Signed-off-by: kernel test robot 
> ---
>
> tree:   https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux.git 
> xfs-5.12-merge
> head:   560ab6c0d12ebccabb83638abe23a7875b946f9a
> commit: 37444fc4cc398266fe0f71a9c0925620d44fb76a [25/36] xfs: lift writable 
> fs check up into log worker task
Looks good.

Reviewed-by: Chaitanya Kulkarni 


Re: [PATCH][next] io_uring: remove redundant initialization of variable ret

2021-02-10 Thread Chaitanya Kulkarni
On 2/10/21 12:02, Colin King wrote:
> From: Colin Ian King 
>
> The variable ret is being initialized with a value that is never read
> and it is being updated later with a new value.  The initialization is
> redundant and can be removed.
>
> Addresses-Coverity: ("Unused value")
> Fixes: b63534c41e20 ("io_uring: re-issue block requests that failed because 
> of resources")
> Signed-off-by: Colin Ian King 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH V2 4/8] mm/highmem: Add VM_BUG_ON() to mem*_page() calls

2021-02-09 Thread Chaitanya Kulkarni
On 2/9/21 22:25, ira.we...@intel.com wrote:
> From: Ira Weiny 
>
> Add VM_BUG_ON bounds checks to ensure the newly lifted and created page
> memory operations do not result in corrupted data in neighbor pages and
> to make them consistent with zero_user().[1][2]
>
I did not understand this, in my tree :-

zero_user()
 -> zero_user_segments()

which uses BUG_ON(), the commit log says add VM_BUG_ON(), isn't that
inconsistent withwhat is there in zero_user_segments() which uses BUG_ON() ?

Also, this patch uses BUG_ON() which doesn't match the commit log that says
ADD VM_BUG_ON(),

Did I interpret the commit log wrong ?

[1]
 void zero_user_segments(struct page *page, unsigned start1, unsigned end1,
365 unsigned start2, unsigned end2)
366 {
367 unsigned int
i;   

368
369 BUG_ON(end1 > page_size(page) || end2 > page_size(page));
370
371 for (i = 0; i < compound_nr(page); i++) {
372 void *kaddr = NULL;
373 
374 if (start1 < PAGE_SIZE || start2 < PAGE_SIZE)
375 kaddr = kmap_atomic(page + i);
376
377 if (start1 >= PAGE_SIZE) {
378 start1 -= PAGE_SIZE;
379 end1 -= PAGE_SIZE;
380 } else {
381 unsigned this_end = min_t(unsigned, end1,
PAGE_SIZE);
382
383 if (end1 > start1)
384 memset(kaddr + start1, 0, this_end -
start1);
385 end1 -= this_end;
386 start1 = 0;
387 }
388
389 if (start2 >= PAGE_SIZE) {
390 start2 -= PAGE_SIZE;
391 end2 -= PAGE_SIZE;
392 } else {
393 unsigned this_end = min_t(unsigned, end2,
PAGE_SIZE);
394 
395 if (end2 > start2)
396 memset(kaddr + start2, 0, this_end -
start2);
397 end2 -= this_end;
398 start2 = 0;
399 }
400
401 if (kaddr) {
402 kunmap_atomic(kaddr);
403 flush_dcache_page(page + i);
404 }
405
406 if (!end1 && !end2)
407 break;
408 }
409
410 BUG_ON((start1 | start2 | end1 | end2) != 0);
411 }
412 EXPORT_SYMBOL(zero_user_segments);





Re: [PATCH V2 3/8] mm/highmem: Introduce memcpy_page(), memmove_page(), and memset_page()

2021-02-09 Thread Chaitanya Kulkarni
On 2/9/21 22:25, ira.we...@intel.com wrote:
> From: Ira Weiny 
>
> 3 more common kmap patterns are kmap/memcpy/kunmap, kmap/memmove/kunmap.
> and kmap/memset/kunmap.
>
> Add helper functions for those patterns which use kmap_local_page().
>
> Cc: Andrew Morton 
> Cc: Christoph Hellwig 
> Signed-off-by: Ira Weiny 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH V2 2/8] mm/highmem: Convert memcpy_[to|from]_page() to kmap_local_page()

2021-02-09 Thread Chaitanya Kulkarni
On 2/9/21 22:25, ira.we...@intel.com wrote:
> From: Ira Weiny 
>
> kmap_local_page() is more efficient and is well suited for these calls.
> Convert the kmap() to kmap_local_page()
>
> Cc: Andrew Morton 
> Cc: Christoph Hellwig 
> Signed-off-by: Ira Weiny 
Looks good.

Reviewed-by: Chaitanya Kulkarni 






Re: [PATCH V2 1/8] mm/highmem: Lift memcpy_[to|from]_page to core

2021-02-09 Thread Chaitanya Kulkarni
On 2/9/21 22:25, ira.we...@intel.com wrote:
> From: Ira Weiny 
>
> Working through a conversion to a call kmap_local_page() instead of
> kmap() revealed many places where the pattern kmap/memcpy/kunmap
> occurred.
>
> Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al
> Viro all suggested putting this code into helper functions.  Al Viro
> further pointed out that these functions already existed in the iov_iter
> code.[1]
>
> Various locations for the lifted functions were considered.
>
> Headers like mm.h or string.h seem ok but don't really portray the
> functionality well.  pagemap.h made some sense but is for page cache
> functionality.[2]
>
> Another alternative would be to create a new header for the promoted
> memcpy functions, but it masks the fact that these are designed to copy
> to/from pages using the kernel direct mappings and complicates matters
> with a new header.
>
> Placing these functions in 'highmem.h' is suboptimal especially with the
> changes being proposed in the functionality of kmap.  From a caller
> perspective including/using 'highmem.h' implies that the functions
> defined in that header are only required when highmem is in use which is
> increasingly not the case with modern processors.  However, highmem.h is
> where all the current functions like this reside (zero_user(),
> clear_highpage(), clear_user_highpage(), copy_user_highpage(), and
> copy_highpage()).  So it makes the most sense even though it is
> distasteful for some.[3]
>
> Lift memcpy_to_page() and memcpy_from_page() to pagemap.h.
>
> [1] https://lore.kernel.org/lkml/20201013200149.gi3576...@zeniv.linux.org.uk/
> https://lore.kernel.org/lkml/20201013112544.ga5...@infradead.org/
>
> [2] https://lore.kernel.org/lkml/20201208122316.gh7...@casper.infradead.org/
>
> [3] 
> https://lore.kernel.org/lkml/20201013200149.gi3576...@zeniv.linux.org.uk/#t
> 
> https://lore.kernel.org/lkml/20201208163814.gn1563...@iweiny-desk2.sc.intel.com/
>
> Cc: Boris Pismenny 
> Cc: Or Gerlitz 
> Cc: Dave Hansen 
> Suggested-by: Matthew Wilcox 
> Suggested-by: Christoph Hellwig 
> Suggested-by: Dan Williams 
> Suggested-by: Al Viro 
> Suggested-by: Eric Biggers 
> Signed-off-by: Ira Weiny 

Thanks for adding a new line in the new calls after variable declaration.
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH 1/4] mm/highmem: Lift memcpy_[to|from]_page to core

2021-02-07 Thread Chaitanya Kulkarni
On 2/7/21 19:13, Ira Weiny wrote:
>>> +static inline void memcpy_from_page(char *to, struct page *page, size_t 
>>> offset, size_t len)
>> How about following ?
>> static inline void memcpy_from_page(char *to, struct page *page, size_t
>> offset,
>> size_t len)  
> It is an easy change and It is up to Andrew.  But I thought we were making the
> line length limit longer now.
>
> Ira
>
True, not sure what is the right thing going forward especially when new
changes
are mixed with the old ones, I'll leave it to the maintainer to decide.


Re: [PATCH 1/4] mm/highmem: Lift memcpy_[to|from]_page to core

2021-02-06 Thread Chaitanya Kulkarni
On 2/5/21 18:35, ira.we...@intel.com wrote:
> +static inline void memmove_page(struct page *dst_page, size_t dst_off,
> +struct page *src_page, size_t src_off,
> +size_t len)
> +{
> + char *dst = kmap_local_page(dst_page);
> + char *src = kmap_local_page(src_page);
> +
> + BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
> + memmove(dst + dst_off, src + src_off, len);
> + kunmap_local(src);
> + kunmap_local(dst);
> +}
> +
> +static inline void memcpy_from_page(char *to, struct page *page, size_t 
> offset, size_t len)
How about following ?
static inline void memcpy_from_page(char *to, struct page *page, size_t
offset,
size_t len)  
> +{
> + char *from = kmap_local_page(page);
> +
> + BUG_ON(offset + len > PAGE_SIZE);
> + memcpy(to, from + offset, len);
> + kunmap_local(from);
> +}
> +
> +static inline void memcpy_to_page(struct page *page, size_t offset, const 
> char *from, size_t len)
How about following ?
static inline void memcpy_to_page(struct page *page, size_t offset,
  const char *from, size_t len)
> +{
> + char *to = kmap_local_page(page);
> +
> + BUG_ON(offset + len > PAGE_SIZE);
> + memcpy(to + offset, from, len);
> + kunmap_local(to);
> +}
> +
> +static inline void memset_page(struct page *page, size_t offset, int val, 
> size_t len)
How about following ?
static inline void memset_page(struct page *page, size_t offset, int val,
   size_t len)  
> +{
> + char *addr = kmap_local_page(page);
> +
> + BUG_ON(offset + len > PAGE_SIZE);
> + memset(addr + offset, val, len);
> + kunmap_local(addr);
> +}
> +


Re: [PATCH 1/3] fs/efs: Use correct brace styling for statements

2021-02-04 Thread Chaitanya Kulkarni
On 2/4/21 21:01, Amy Parker wrote:
>> Commit message is too long. Follow the style present in the tree.
> Are you referring to the per-line length? That was supposed to have
> been broken up, my apologies. Or is it the overall length that is the
> issue?
>
>-Amy IP
>
Per line length. I think it should be < 73.


Re: [PATCH 1/3] fs/efs: Use correct brace styling for statements

2021-02-04 Thread Chaitanya Kulkarni
On 2/4/21 20:55, Amy Parker wrote:
> Many single-line statements have unnecessary braces, and some statement pairs 
> have mismatched braces. This is a clear violation of the kernel style guide, 
> which mandates that single line statements have no braces and that pairs with 
> at least one multi-line block maintain their braces.
>
> This patch fixes these style violations. Single-line statements that have 
> braces have had their braces stripped. Pair single-line statements have been 
> formatted per the style guide. Pair mixed-line statements have had their 
> braces updated to conform.
>
> Signed-off-by: Amy Parker 
Commit message is too long. Follow the style present in the tree.



Re: [PATCH] xfs: fix unused variable build warning in xfs_log.c

2021-02-04 Thread Chaitanya Kulkarni
On 2/4/21 19:20, John Hubbard wrote:
> Delete the unused "log" variable in xfs_log_cover().
>
> Fixes: 303591a0a9473 ("xfs: cover the log during log quiesce")
> Cc: Brian Foster 
> Cc: Christoph Hellwig 
> Cc: Darrick J. Wong 
> Cc: Allison Henderson 
> Signed-off-by: John Hubbard 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH] block: recalculate segment count for multi-segment discard requests correctly

2021-02-02 Thread Chaitanya Kulkarni
On 2/2/21 18:39, Ming Lei wrote:
> + struct bio *bio = rq->bio;
> + for_each_bio(bio)
> + nr_phys_segs++;
> + return nr_phys_segs;
> + }
Also, you need to add a new line after declaration of bio in the above
code block.


Re: [PATCH] block: recalculate segment count for multi-segment discard requests correctly

2021-02-02 Thread Chaitanya Kulkarni
On 2/2/21 18:39, Ming Lei wrote:
> + /* fall through */
>   case REQ_OP_WRITE_ZEROES:
> - return 0;
I don't think returning 1 for write-zeroes is right,
did you test this patch with write-zeores enabled controller with
the right fs that triggers this behavior ?


Re: [PATCH] scsi: target: remove unneeded semicolon

2021-02-02 Thread Chaitanya Kulkarni
On 2/2/21 17:52, Yang Li wrote:
> Eliminate the following coccicheck warning:
> ./drivers/target/sbp/sbp_target.c:1009:2-3: Unneeded semicolon
>
> Reported-by: Abaci Robot 
> Signed-off-by: Yang Li 
> ---
>  drivers/target/sbp/sbp_target.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
> index e4a9b9f..2a6165f 100644
> --- a/drivers/target/sbp/sbp_target.c
> +++ b/drivers/target/sbp/sbp_target.c
> @@ -1006,7 +1006,7 @@ static void tgt_agent_fetch_work(struct work_struct 
> *work)
>   agent->state = AGENT_STATE_SUSPENDED;
>  
>   spin_unlock_bh(>lock);
> - };
> + }
>  }
>  
>  static struct sbp_target_agent *sbp_target_agent_register(
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH] nvme: convert sysfs sprintf/snprintf family to sysfs_emit

2021-02-02 Thread Chaitanya Kulkarni
On 2/1/21 23:12, Jiapeng Chong wrote:
> Fix the following coccicheck warning:
>
> ./drivers/nvme/host/core.c:3580:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/nvme/host/core.c:3570:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/nvme/host/core.c:3560:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/nvme/host/core.c:3526:8-16: WARNING: use scnprintf or sprintf.
> ./drivers/nvme/host/core.c:2833:8-16: WARNING: use scnprintf or sprintf.
>
> Reported-by: Abaci Robot
> Signed-off-by: Jiapeng Chong 
Looks good.

Reviewed-by: Chaitanya Kulkarni 



Re: [PATCH V2 3/3] Adding device_dma_parameters->offset_preserve_mask to NVMe driver.

2021-02-01 Thread Chaitanya Kulkarni
On 2/1/21 13:27, Jianxiong Gao wrote:
>> Why is this setting being done and undone on each IO? Wouldn't it be
>> more efficient to set it once during device initialization?
>>
>> And more importantly, this isn't thread safe: one CPU may be setting the
>> device's dma alignment mask to 0 while another CPU is expecting it to be
>> NVME_CTRL_PAGE_SIZE - 1.
>  I was having trouble getting the OS booted when setting it once during
>  initialization. However when I rebased to the latest rc6 this morning it
>  seems to be working with setting the mask on probe. I am still testing out
>  and will appreciate any idea what may cause the nvme driver to fail
>  with a single mask.
Based on the Keith's comment it needs to be completely avoided in hot path.

Did you get a chance to bisect the problem in the rc6 ? We need to know the
root cause otherwise it might happen again after we add this patch.


[RFC PATCH 02/34] block: introduce and use bio_new

2021-01-28 Thread Chaitanya Kulkarni
Introduce bio_new() helper and use it in blk-lib.c to allocate and
initialize various non-optional or semi-optional members of the bio
along with bio allocation done with bio_alloc(). Here we also calmp the
max_bvecs for bio with BIO_MAX_PAGES before we pass to bio_alloc().

Signed-off-by: Chaitanya Kulkarni 
---
 block/blk-lib.c |  6 +-
 include/linux/bio.h | 25 +
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index fb486a0bdb58..ec29415f00dd 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -14,17 +14,13 @@ struct bio *blk_next_bio(struct bio *bio, struct 
block_device *bdev,
sector_t sect, unsigned op, unsigned opf,
unsigned int nr_pages, gfp_t gfp)
 {
-   struct bio *new = bio_alloc(gfp, nr_pages);
+   struct bio *new = bio_new(bdev, sect, op, opf, gfp, nr_pages);
 
if (bio) {
bio_chain(bio, new);
submit_bio(bio);
}
 
-   new->bi_iter.bi_sector = sect;
-   bio_set_dev(new, bdev);
-   bio_set_op_attrs(new, op, opf);
-
return new;
 }
 
diff --git a/include/linux/bio.h b/include/linux/bio.h
index c74857cf1252..2a09ba100546 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -826,5 +826,30 @@ static inline void bio_set_polled(struct bio *bio, struct 
kiocb *kiocb)
if (!is_sync_kiocb(kiocb))
bio->bi_opf |= REQ_NOWAIT;
 }
+/**
+ * bio_new -   allcate and initialize new bio
+ * @bdev:  blockdev to issue discard for
+ * @sector:start sector
+ * @op:REQ_OP_XXX from enum req_opf
+ * @op_flags:  REQ_XXX from enum req_flag_bits
+ * @max_bvecs: maximum bvec to be allocated for this bio
+ * @gfp_mask:  memory allocation flags (for bio_alloc)
+ *
+ * Description:
+ *Allocates, initializes common members, and returns a new bio.
+ */
+static inline struct bio *bio_new(struct block_device *bdev, sector_t sector,
+ unsigned int op, unsigned int op_flags,
+ unsigned int max_bvecs, gfp_t gfp_mask)
+{
+   unsigned nr_bvec = clamp_t(unsigned int, max_bvecs, 0, BIO_MAX_PAGES);
+   struct bio *bio = bio_alloc(gfp_mask, nr_bvec);
+
+   bio_set_dev(bio, bdev);
+   bio->bi_iter.bi_sector = sector;
+   bio_set_op_attrs(bio, op, op_flags);
+
+   return bio;
+}
 
 #endif /* __LINUX_BIO_H */
-- 
2.22.1



[RFC PATCH 00/34] block: introduce bio_new()

2021-01-27 Thread Chaitanya Kulkarni
Hi,

This is a *compile only RFC* which adds a generic helper to initialize
the various fields of the bio that is repeated all the places in
file-systems, block layer, and drivers.

The new helper allows callers to initialize non-optional members of bio
such as bdev, sector, op, opflags, max_bvecs and gfp_mask by
encapsulating new bio allocation with bio alloc with initialization
at one place.

The objective of this RFC is to only start a discussion, this it not 
completely tested at all.

-ck 

Chaitanya Kulkarni (34):
  block: move common code into blk_next_bio()
  block: introduce and use bio_new
  drdb: use bio_new in drdb
  drdb: use bio_new() in submit_one_flush
  xen-blkback: use bio_new
  zram: use bio_new
  dm: use bio_new in dm-log-writes
  dm-zoned: use bio_new in get_mblock_slow
  dm-zoned: use bio_new in dmz_write_mblock
  dm-zoned: use bio_new in dmz_rdwr_block
  nvmet: use bio_new in nvmet_bdev_execute_rw
  scsi: target/iblock: use bio_new
  block: use bio_new in __blkdev_direct_IO
  fs/buffer: use bio_new in submit_bh_wbc
  fscrypt: use bio_new in fscrypt_zeroout_range
  fs/direct-io: use bio_new in dio_bio_alloc
  iomap: use bio_new in iomap_dio_zero
  iomap: use bio_new in iomap_dio_bio_actor
  fs/jfs/jfs_logmgr.c: use bio_new in lbmRead
  fs/jfs/jfs_logmgr.c: use bio_new in lbmStartIO
  fs/jfs/jfs_metapage.c: use bio_new in metapage_writepage
  fs/jfs/jfs_metapage.c: use bio_new in metapage_readpage
  fs/mpage.c: use bio_new mpage_alloc
  fs/nilfs: use bio_new nilfs_alloc_seg_bio
  ocfs/cluster: use bio_new in dm-log-writes
  xfs: use bio_new in xfs_rw_bdev
  xfs: use bio_new in xfs_buf_ioapply_map
  zonefs: use bio_new
  power/swap: use bio_new in hib_submit_io
  hfsplus: use bio_new in hfsplus_submit_bio()
  iomap: use bio_new in iomap_readpage_actor
  mm: use bio_new in __swap_writepage
  mm: use bio_new in swap_readpage
  mm: add swap_bio_new common bio helper

 block/blk-lib.c | 34 ++---
 block/blk-zoned.c   |  4 +---
 block/blk.h |  5 +++--
 drivers/block/drbd/drbd_receiver.c  | 12 +-
 drivers/block/xen-blkback/blkback.c | 20 +++--
 drivers/block/zram/zram_drv.c   |  5 ++---
 drivers/md/dm-log-writes.c  | 30 +
 drivers/md/dm-zoned-metadata.c  | 18 +--
 drivers/nvme/target/io-cmd-bdev.c   |  9 +++-
 drivers/target/target_core_iblock.c |  5 ++---
 fs/block_dev.c  |  6 ++---
 fs/buffer.c | 16 ++
 fs/crypto/bio.c |  5 ++---
 fs/direct-io.c  |  6 ++---
 fs/hfsplus/wrapper.c|  5 +
 fs/iomap/buffered-io.c  | 12 +-
 fs/iomap/direct-io.c| 11 --
 fs/jfs/jfs_logmgr.c | 13 ---
 fs/jfs/jfs_metapage.c   | 15 +
 fs/mpage.c  | 18 +--
 fs/nilfs2/segbuf.c  | 10 ++---
 fs/ocfs2/cluster/heartbeat.c|  6 ++---
 fs/xfs/xfs_bio_io.c |  7 ++
 fs/xfs/xfs_buf.c|  6 ++---
 fs/zonefs/super.c   |  6 ++---
 include/linux/bio.h | 25 +
 kernel/power/swap.c |  7 +++---
 mm/page_io.c| 30 +
 28 files changed, 151 insertions(+), 195 deletions(-)

-- 
2.22.1



[RFC PATCH 05/34] xen-blkback: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Create a wrapper on the tio of the bio_new() named get_new_bio() & use
it in the dispatch_rw_block_io().
p
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/xen-blkback/blkback.c | 20 +---
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/block/xen-blkback/blkback.c 
b/drivers/block/xen-blkback/blkback.c
index 9ebf53903d7b..3760278f0ee6 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -1174,6 +1174,15 @@ do_block_io_op(struct xen_blkif_ring *ring, unsigned int 
*eoi_flags)
 
return more_to_do;
 }
+
+static struct bio *
+get_new_bio(struct phys_req *preq, unsigned int op, unsigned int op_flags,
+   gfp_t gfp_mask, unsigned int nr_bvec)
+{
+   return bio_new(preq->bdev, preq->sector_number, op, op_flags, nr_bvec,
+  gfp_mask);
+
+}
 /*
  * Transmutation of the 'struct blkif_request' to a proper 'struct bio'
  * and call the 'submit_bio' to pass it to the underlying storage.
@@ -1324,16 +1333,14 @@ static int dispatch_rw_block_io(struct xen_blkif_ring 
*ring,
 seg[i].offset) == 0)) {
 
int nr_iovecs = min_t(int, (nseg-i), BIO_MAX_PAGES);
-   bio = bio_alloc(GFP_KERNEL, nr_iovecs);
+   bio = get_new_bio(, operation, operation_flags,
+ GFP_KERNEL, nr_iovecs);
if (unlikely(bio == NULL))
goto fail_put_bio;
 
biolist[nbio++] = bio;
-   bio_set_dev(bio, preq.bdev);
bio->bi_private = pending_req;
bio->bi_end_io  = end_block_io_op;
-   bio->bi_iter.bi_sector  = preq.sector_number;
-   bio_set_op_attrs(bio, operation, operation_flags);
}
 
preq.sector_number += seg[i].nsec;
@@ -1343,15 +1350,14 @@ static int dispatch_rw_block_io(struct xen_blkif_ring 
*ring,
if (!bio) {
BUG_ON(operation_flags != REQ_PREFLUSH);
 
-   bio = bio_alloc(GFP_KERNEL, 0);
+   bio = get_new_bio(, operation, operation_flags,
+ GFP_KERNEL, 0);
if (unlikely(bio == NULL))
goto fail_put_bio;
 
biolist[nbio++] = bio;
-   bio_set_dev(bio, preq.bdev);
bio->bi_private = pending_req;
bio->bi_end_io  = end_block_io_op;
-   bio_set_op_attrs(bio, operation, operation_flags);
}
 
atomic_set(_req->pendcnt, nbio);
-- 
2.22.1



[RFC PATCH 06/34] zram: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/zram/zram_drv.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index d7018543842e..5d744e528d4f 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -587,12 +587,11 @@ static int read_from_bdev_async(struct zram *zram, struct 
bio_vec *bvec,
 {
struct bio *bio;
 
-   bio = bio_alloc(GFP_ATOMIC, 1);
+   bio = bio_alloc(zram->bdev, entry * (PAGE_SIZE >> 9), 0, 0,
+   1, GFP_ATOMIC);
if (!bio)
return -ENOMEM;
 
-   bio->bi_iter.bi_sector = entry * (PAGE_SIZE >> 9);
-   bio_set_dev(bio, zram->bdev);
if (!bio_add_page(bio, bvec->bv_page, bvec->bv_len, bvec->bv_offset)) {
bio_put(bio);
return -EIO;
-- 
2.22.1



[RFC PATCH 11/34] nvmet: use bio_new in nvmet_bdev_execute_rw

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/nvme/target/io-cmd-bdev.c | 9 +++--
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/nvme/target/io-cmd-bdev.c 
b/drivers/nvme/target/io-cmd-bdev.c
index bf6e0ac9ad28..f5fd93a796a6 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -225,6 +225,7 @@ static int nvmet_bdev_alloc_bip(struct nvmet_req *req, 
struct bio *bio,
 
 static void nvmet_bdev_execute_rw(struct nvmet_req *req)
 {
+   struct block_device *bdev = req->ns->bdev;
int sg_cnt = req->sg_cnt;
struct bio *bio;
struct scatterlist *sg;
@@ -265,7 +266,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
} else {
bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
}
-   bio_set_dev(bio, req->ns->bdev);
+   bio_set_dev(bio, bdev);
bio->bi_iter.bi_sector = sector;
bio->bi_private = req;
bio->bi_end_io = nvmet_bio_done;
@@ -290,11 +291,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
}
}
 
-   bio = bio_alloc(GFP_KERNEL, min(sg_cnt, BIO_MAX_PAGES));
-   bio_set_dev(bio, req->ns->bdev);
-   bio->bi_iter.bi_sector = sector;
-   bio->bi_opf = op;
-
+   bio = bio_new(bdev, sector, op, 0, sg_cnt, GFP_KERNEL);
bio_chain(bio, prev);
submit_bio(prev);
}
-- 
2.22.1



[RFC PATCH 10/34] dm-zoned: use bio_new in dmz_rdwr_block

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index fa0ee732c6e9..5b5ed5fce2ed 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -755,13 +755,11 @@ static int dmz_rdwr_block(struct dmz_dev *dev, int op,
if (dmz_bdev_is_dying(dev))
return -EIO;
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), op,
+ REQ_SYNC | REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio)
return -ENOMEM;
 
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
-   bio_set_op_attrs(bio, op, REQ_SYNC | REQ_META | REQ_PRIO);
bio_add_page(bio, page, DMZ_BLOCK_SIZE, 0);
ret = submit_bio_wait(bio);
bio_put(bio);
-- 
2.22.1



[RFC PATCH 14/34] fs/buffer: use bio_new in submit_bh_wbc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/buffer.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/fs/buffer.c b/fs/buffer.c
index 32647d2011df..fcbea667fa04 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3023,12 +3023,16 @@ static int submit_bh_wbc(int op, int op_flags, struct 
buffer_head *bh,
if (test_set_buffer_req(bh) && (op == REQ_OP_WRITE))
clear_buffer_write_io_error(bh);
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   if (buffer_meta(bh))
+   op_flags |= REQ_META;
+   if (buffer_prio(bh))
+   op_flags |= REQ_PRIO;
+
+   bio = bio_new(bh->b_bdev,  bh->b_blocknr * (bh->b_size >> 9), op,
+ op_flags, GFP_NOIO, 1);
 
fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO);
 
-   bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9);
-   bio_set_dev(bio, bh->b_bdev);
bio->bi_write_hint = write_hint;
 
bio_add_page(bio, bh->b_page, bh->b_size, bh_offset(bh));
@@ -3037,12 +3041,6 @@ static int submit_bh_wbc(int op, int op_flags, struct 
buffer_head *bh,
bio->bi_end_io = end_bio_bh_io_sync;
bio->bi_private = bh;
 
-   if (buffer_meta(bh))
-   op_flags |= REQ_META;
-   if (buffer_prio(bh))
-   op_flags |= REQ_PRIO;
-   bio_set_op_attrs(bio, op, op_flags);
-
/* Take care of bh's that straddle the end of the device */
guard_bio_eod(bio);
 
-- 
2.22.1



[RFC PATCH 07/34] dm: use bio_new in dm-log-writes

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-log-writes.c | 30 ++
 1 file changed, 10 insertions(+), 20 deletions(-)

diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c
index e3d35c6c9f71..7ca9af407647 100644
--- a/drivers/md/dm-log-writes.c
+++ b/drivers/md/dm-log-writes.c
@@ -217,18 +217,15 @@ static int write_metadata(struct log_writes_c *lc, void 
*entry,
void *ptr;
size_t ret;
 
-   bio = bio_alloc(GFP_KERNEL, 1);
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0, 1, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = (sector == WRITE_LOG_SUPER_SECTOR) ?
  log_end_super : log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
page = alloc_page(GFP_KERNEL);
if (!page) {
@@ -264,7 +261,7 @@ static int write_inline_data(struct log_writes_c *lc, void 
*entry,
 size_t entrylen, void *data, size_t datalen,
 sector_t sector)
 {
-   int num_pages, bio_pages, pg_datalen, pg_sectorlen, i;
+   int num_pages, pg_datalen, pg_sectorlen, i;
struct page *page;
struct bio *bio;
size_t ret;
@@ -272,24 +269,21 @@ static int write_inline_data(struct log_writes_c *lc, 
void *entry,
 
while (datalen) {
num_pages = ALIGN(datalen, PAGE_SIZE) >> PAGE_SHIFT;
-   bio_pages = min(num_pages, BIO_MAX_PAGES);
 
atomic_inc(>io_blocks);
 
-   bio = bio_alloc(GFP_KERNEL, bio_pages);
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0,
+ num_pages, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc inline data bio");
goto error;
}
 
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
-   for (i = 0; i < bio_pages; i++) {
+   for (i = 0; i < bio->bi_max_vecs; i++) {
pg_datalen = min_t(int, datalen, PAGE_SIZE);
pg_sectorlen = ALIGN(pg_datalen, lc->sectorsize);
 
@@ -317,7 +311,7 @@ static int write_inline_data(struct log_writes_c *lc, void 
*entry,
}
submit_bio(bio);
 
-   sector += bio_pages * PAGE_SECTORS;
+   sector += bio->bi_max_vecs * PAGE_SECTORS;
}
return 0;
 error_bio:
@@ -364,17 +358,15 @@ static int log_one_block(struct log_writes_c *lc,
goto out;
 
atomic_inc(>io_blocks);
-   bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt, BIO_MAX_PAGES));
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE, 0,
+   block->vec_cnt, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
for (i = 0; i < block->vec_cnt; i++) {
/*
@@ -386,17 +378,15 @@ static int log_one_block(struct log_writes_c *lc,
if (ret != block->vecs[i].bv_len) {
atomic_inc(>io_blocks);
submit_bio(bio);
-   bio = bio_alloc(GFP_KERNEL, min(block->vec_cnt - i, 
BIO_MAX_PAGES));
+   bio = bio_new(lc->logdev->bdev, sector, REQ_OP_WRITE,
+   0, block->vec_cnt - i, GFP_KERNEL);
if (!bio) {
DMERR("Couldn't alloc log bio");
goto error;
}
bio->bi_iter.bi_size = 0;
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, lc->logdev->bdev);
bio->bi_end_io = log_end_io;
bio->bi_private = lc;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
ret = bio_add_page(bio, block->vecs[i].bv_page,
   block->vecs[i].bv_len, 0);
-- 
2.22.1



[RFC PATCH 19/34] fs/jfs/jfs_logmgr.c: use bio_new in lbmRead

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_logmgr.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 9330eff210e0..4481f3e33a3f 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -1979,17 +1979,14 @@ static int lbmRead(struct jfs_log * log, int pn, struct 
lbuf ** bpp)
 
bp->l_flag |= lbmREAD;
 
-   bio = bio_alloc(GFP_NOFS, 1);
-
-   bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
-   bio_set_dev(bio, log->bdev);
+   bio = bio_new(log->bdev, bp->l_blkno << (log->l2bsize - 9),
+   REQ_OP_READ, 0, 1, GFP_NOFS);
 
bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
 
bio->bi_end_io = lbmIODone;
bio->bi_private = bp;
-   bio->bi_opf = REQ_OP_READ;
/*check if journaling to disk has been disabled*/
if (log->no_integrity) {
bio->bi_iter.bi_size = 0;
-- 
2.22.1



[RFC PATCH 16/34] fs/direct-io: use bio_new in dio_bio_alloc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/crypto/bio.c | 2 +-
 fs/direct-io.c  | 6 ++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index 20dab9bdf098..28cd62ce853e 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -148,7 +148,7 @@ int fscrypt_zeroout_range(const struct inode *inode, 
pgoff_t lblk,
return -EINVAL;
 
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
-   bio = bio_alloc(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
+   bio = bio_new(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
GFP_NOFS);
 
do {
diff --git a/fs/direct-io.c b/fs/direct-io.c
index aa1083ecd623..6aab1bd167bc 100644
--- a/fs/direct-io.c
+++ b/fs/direct-io.c
@@ -397,11 +397,9 @@ dio_bio_alloc(struct dio *dio, struct dio_submit *sdio,
 * bio_alloc() is guaranteed to return a bio when allowed to sleep and
 * we request a valid number of vectors.
 */
-   bio = bio_alloc(GFP_KERNEL, nr_vecs);
+   bio = bio_new(bdev, first_sector, dio->op, dio->op_flags, nr_vecs,
+ GFP_KERNEL);
 
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = first_sector;
-   bio_set_op_attrs(bio, dio->op, dio->op_flags);
if (dio->is_async)
bio->bi_end_io = dio_bio_end_aio;
else
-- 
2.22.1



[RFC PATCH 17/34] iomap: use bio_new in iomap_dio_zero

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/direct-io.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index ea1e8f696076..f6c557a1bd25 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -189,15 +189,13 @@ iomap_dio_zero(struct iomap_dio *dio, struct iomap 
*iomap, loff_t pos,
int flags = REQ_SYNC | REQ_IDLE;
struct bio *bio;
 
-   bio = bio_alloc(GFP_KERNEL, 1);
-   bio_set_dev(bio, iomap->bdev);
-   bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
+   bio = bio_new(iomap->bdev, iomap_sector(iomap, pos), REQ_OP_WRITE,
+ flags, 1, GFP_KERNEL);
bio->bi_private = dio;
bio->bi_end_io = iomap_dio_bio_end_io;
 
get_page(page);
__bio_add_page(bio, page, len, 0);
-   bio_set_op_attrs(bio, REQ_OP_WRITE, flags);
iomap_dio_submit_bio(dio, iomap, bio, pos);
 }
 
-- 
2.22.1



[RFC PATCH 18/34] iomap: use bio_new in iomap_dio_bio_actor

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/direct-io.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c
index f6c557a1bd25..0737192f7e5c 100644
--- a/fs/iomap/direct-io.c
+++ b/fs/iomap/direct-io.c
@@ -267,9 +267,8 @@ iomap_dio_bio_actor(struct inode *inode, loff_t pos, loff_t 
length,
goto out;
}
 
-   bio = bio_alloc(GFP_KERNEL, nr_pages);
-   bio_set_dev(bio, iomap->bdev);
-   bio->bi_iter.bi_sector = iomap_sector(iomap, pos);
+   bio = bio_new(iomap->bdev, iomap_sector(iomap, pos), 0, 0,
+ nr_pages, GFP_KERNEL);
bio->bi_write_hint = dio->iocb->ki_hint;
bio->bi_ioprio = dio->iocb->ki_ioprio;
bio->bi_private = dio;
-- 
2.22.1



[RFC PATCH 21/34] fs/jfs/jfs_metapage.c: use bio_new in metapage_writepage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_metapage.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 176580f54af9..3fa09d9a0b94 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -416,12 +416,11 @@ static int metapage_writepage(struct page *page, struct 
writeback_control *wbc)
}
len = min(xlen, (int)JFS_SBI(inode->i_sb)->nbperpage);
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio_set_dev(bio, inode->i_sb->s_bdev);
-   bio->bi_iter.bi_sector = pblock << (inode->i_blkbits - 9);
+   bio = bio_new(inode->i_sb->s_bdev,
+ pblock << (inode->i_blkbits - 9), REQ_OP_WRITE,
+ 0, 1, GFP_NOFS);
bio->bi_end_io = metapage_write_end_io;
bio->bi_private = page;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
/* Don't call bio_add_page yet, we may add to this vec */
bio_offset = offset;
-- 
2.22.1



[RFC PATCH 24/34] fs/nilfs: use bio_new nilfs_alloc_seg_bio

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/nilfs2/segbuf.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 1e75417bfe6e..df352cab7a93 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -383,15 +383,9 @@ static int nilfs_segbuf_submit_bio(struct 
nilfs_segment_buffer *segbuf,
 static struct bio *nilfs_alloc_seg_bio(struct the_nilfs *nilfs, sector_t start,
   int nr_vecs)
 {
-   struct bio *bio;
+   sector_t sect = start << (nilfs->ns_blocksize_bits - 9);
 
-   bio = bio_alloc(GFP_NOIO, nr_vecs);
-   if (likely(bio)) {
-   bio_set_dev(bio, nilfs->ns_bdev);
-   bio->bi_iter.bi_sector =
-   start << (nilfs->ns_blocksize_bits - 9);
-   }
-   return bio;
+   return bio_new(nilfs->ns_bdev, sect, 0, 0, nr_vecs, GFP_NOIO);
 }
 
 static void nilfs_segbuf_prepare_write(struct nilfs_segment_buffer *segbuf,
-- 
2.22.1



[RFC PATCH 23/34] fs/mpage.c: use bio_new mpage_alloc

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/mpage.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/fs/mpage.c b/fs/mpage.c
index 830e6cc2a9e7..01725126e81f 100644
--- a/fs/mpage.c
+++ b/fs/mpage.c
@@ -68,25 +68,21 @@ static struct bio *mpage_bio_submit(int op, int op_flags, 
struct bio *bio)
 }
 
 static struct bio *
-mpage_alloc(struct block_device *bdev,
-   sector_t first_sector, int nr_vecs,
-   gfp_t gfp_flags)
+mpage_alloc(struct block_device *bdev, sector_t first_sector, int nr_vecs,
+   gfp_t gfp_flags)
 {
struct bio *bio;
 
/* Restrict the given (page cache) mask for slab allocations */
gfp_flags &= GFP_KERNEL;
-   bio = bio_alloc(gfp_flags, nr_vecs);
+   bio = bio_new(bdev, first_sector, 0, 0, nr_vecs, gfp_flags);
 
if (bio == NULL && (current->flags & PF_MEMALLOC)) {
while (!bio && (nr_vecs /= 2))
-   bio = bio_alloc(gfp_flags, nr_vecs);
+   bio = bio_new(bdev, first_sector, 0, 0, nr_vecs,
+   gfp_flags);
}
 
-   if (bio) {
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = first_sector;
-   }
return bio;
 }
 
@@ -304,9 +300,7 @@ static struct bio *do_mpage_readpage(struct 
mpage_readpage_args *args)
goto out;
}
args->bio = mpage_alloc(bdev, blocks[0] << (blkbits - 9),
-   min_t(int, args->nr_pages,
- BIO_MAX_PAGES),
-   gfp);
+   args->nr_pages, gfp);
if (args->bio == NULL)
goto confused;
}
-- 
2.22.1



[RFC PATCH 26/34] xfs: use bio_new in xfs_rw_bdev

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/xfs/xfs_bio_io.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/fs/xfs/xfs_bio_io.c b/fs/xfs/xfs_bio_io.c
index e2148f2d5d6b..e4644f22ebe6 100644
--- a/fs/xfs/xfs_bio_io.c
+++ b/fs/xfs/xfs_bio_io.c
@@ -26,11 +26,8 @@ xfs_rw_bdev(
if (is_vmalloc && op == REQ_OP_WRITE)
flush_kernel_vmap_range(data, count);
 
-   bio = bio_alloc(GFP_KERNEL, bio_max_vecs(left));
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = sector;
-   bio->bi_opf = op | REQ_META | REQ_SYNC;
-
+   bio = bio_new(bdev, sector, op, REQ_META | REQ_SYNC, bio_max_vecs(left),
+ GFP_KERNEL);
do {
struct page *page = kmem_to_page(data);
unsigned intoff = offset_in_page(data);
-- 
2.22.1



[RFC PATCH 27/34] xfs: use bio_new in xfs_buf_ioapply_map

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/xfs/xfs_buf.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c
index f8400bbd6473..3ff6235e4f94 100644
--- a/fs/xfs/xfs_buf.c
+++ b/fs/xfs/xfs_buf.c
@@ -1507,12 +1507,10 @@ xfs_buf_ioapply_map(
atomic_inc(>b_io_remaining);
nr_pages = min(total_nr_pages, BIO_MAX_PAGES);
 
-   bio = bio_alloc(GFP_NOIO, nr_pages);
-   bio_set_dev(bio, bp->b_target->bt_bdev);
-   bio->bi_iter.bi_sector = sector;
+   bio = bio_new(bp->b_target->bt_bdev, sector, op, 0, nr_pages,
+ GFP_NOIO);
bio->bi_end_io = xfs_buf_bio_end_io;
bio->bi_private = bp;
-   bio->bi_opf = op;
 
for (; size && nr_pages; nr_pages--, page_index++) {
int rbytes, nbytes = PAGE_SIZE - offset;
-- 
2.22.1



[RFC PATCH 30/34] hfsplus: use bio_new in hfsplus_submit_bio()

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/hfsplus/wrapper.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/fs/hfsplus/wrapper.c b/fs/hfsplus/wrapper.c
index 0350dc7821bf..8341ee6c9b31 100644
--- a/fs/hfsplus/wrapper.c
+++ b/fs/hfsplus/wrapper.c
@@ -64,10 +64,7 @@ int hfsplus_submit_bio(struct super_block *sb, sector_t 
sector,
offset = start & (io_size - 1);
sector &= ~((io_size >> HFSPLUS_SECTOR_SHIFT) - 1);
 
-   bio = bio_alloc(GFP_NOIO, 1);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, sb->s_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
+   bio = bio_new(sb->s_bdev, sector, op, op_flags, 1, GFP_NOIO);
 
if (op != WRITE && data)
*data = (u8 *)buf + offset;
-- 
2.22.1



[RFC PATCH 32/34] mm: use bio_new in __swap_writepage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 92f7941c6d01..25b321489703 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -342,10 +342,8 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_alloc(GFP_NOIO, 1);
-   bio_set_dev(bio, sis->bdev);
-   bio->bi_iter.bi_sector = swap_page_sector(page);
-   bio->bi_opf = REQ_OP_WRITE | REQ_SWAP | wbc_to_write_flags(wbc);
+   bio = bio_alloc(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
+   REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
bio->bi_end_io = end_write_func;
bio_add_page(bio, page, thp_size(page), 0);
 
-- 
2.22.1



[RFC PATCH 34/34] mm: add swap_bio_new common bio helper

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 26 --
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 7579485ccb5e..cc30c9a0b0a7 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -287,6 +287,17 @@ static void bio_associate_blkg_from_page(struct bio *bio, 
struct page *page)
 #define bio_associate_blkg_from_page(bio, page)do { } while (0)
 #endif /* CONFIG_MEMCG && CONFIG_BLK_CGROUP */
 
+static inline struct bio *swap_bio_new(struct block_device *dev,
+   unsigned op, unsigned opf, gfp_t gfp, struct page *p,
+   bio_end_io_t *end_io)
+{
+   struct bio *bio = bio_new(dev, swap_page_sector(p), op, opf, 1, gfp);
+
+   bio->bi_end_io = end_io;
+   bio_add_page(bio, p, thp_size(p), 0);
+   return bio;
+}
+
 int __swap_writepage(struct page *page, struct writeback_control *wbc,
bio_end_io_t end_write_func)
 {
@@ -342,11 +353,9 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
-   REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
-   bio->bi_end_io = end_write_func;
-   bio_add_page(bio, page, thp_size(page), 0);
-
+   bio = swap_bio_new(sis->bdev, REQ_OP_WRITE,
+   REQ_SWAP | wbc_to_write_flags(wbc), GFP_KERNEL,
+   page, end_write_func);
bio_associate_blkg_from_page(bio, page);
count_swpout_vm_event(page);
set_page_writeback(page);
@@ -406,11 +415,8 @@ int swap_readpage(struct page *page, bool synchronous)
}
 
ret = 0;
-   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_READ, 0, 1,
-   GFP_KERNEL);
-   bio->bi_end_io = end_swap_bio_read;
-   bio_add_page(bio, page, thp_size(page), 0);
-
+   bio = swap_bio_new(sis->bdev, REQ_OP_READ, 0, GFP_KERNEL, page,
+   end_swap_bio_read);
disk = bio->bi_bdev->bd_disk;
/*
 * Keep this task valid during swap readpage because the oom killer may
-- 
2.22.1



[RFC PATCH 33/34] mm: use bio_new in swap_readpage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 mm/page_io.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/mm/page_io.c b/mm/page_io.c
index 25b321489703..7579485ccb5e 100644
--- a/mm/page_io.c
+++ b/mm/page_io.c
@@ -342,7 +342,7 @@ int __swap_writepage(struct page *page, struct 
writeback_control *wbc,
return 0;
}
 
-   bio = bio_alloc(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
+   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_WRITE,
REQ_SWAP | wbc_to_write_flags(wbc), 1, GFP_NOIO);
bio->bi_end_io = end_write_func;
bio_add_page(bio, page, thp_size(page), 0);
@@ -406,10 +406,8 @@ int swap_readpage(struct page *page, bool synchronous)
}
 
ret = 0;
-   bio = bio_alloc(GFP_KERNEL, 1);
-   bio_set_dev(bio, sis->bdev);
-   bio->bi_opf = REQ_OP_READ;
-   bio->bi_iter.bi_sector = swap_page_sector(page);
+   bio = bio_new(sis->bdev, swap_page_sector(page), REQ_OP_READ, 0, 1,
+   GFP_KERNEL);
bio->bi_end_io = end_swap_bio_read;
bio_add_page(bio, page, thp_size(page), 0);
 
-- 
2.22.1



[RFC PATCH 31/34] iomap: use bio_new in iomap_readpage_actor

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/iomap/buffered-io.c | 12 +---
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c
index 16a1e82e3aeb..08d119b62cf5 100644
--- a/fs/iomap/buffered-io.c
+++ b/fs/iomap/buffered-io.c
@@ -241,6 +241,9 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, 
loff_t length, void *data,
struct page *page = ctx->cur_page;
struct iomap_page *iop = iomap_page_create(inode, page);
bool same_page = false, is_contig = false;
+   struct block_device *bdev = iomap->bdev;
+   unsigned opf = ctx->rac ? REQ_RAHEAD : 0;
+   unsigned op = REQ_OP_READ;
loff_t orig_pos = pos;
unsigned poff, plen;
sector_t sector;
@@ -285,19 +288,14 @@ iomap_readpage_actor(struct inode *inode, loff_t pos, 
loff_t length, void *data,
 
if (ctx->rac) /* same as readahead_gfp_mask */
gfp |= __GFP_NORETRY | __GFP_NOWARN;
-   ctx->bio = bio_alloc(gfp, min(BIO_MAX_PAGES, nr_vecs));
+   ctx->bio = bio_new(bdev, sector, op, opf, gfp, nr_vecs);
/*
 * If the bio_alloc fails, try it again for a single page to
 * avoid having to deal with partial page reads.  This emulates
 * what do_mpage_readpage does.
 */
if (!ctx->bio)
-   ctx->bio = bio_alloc(orig_gfp, 1);
-   ctx->bio->bi_opf = REQ_OP_READ;
-   if (ctx->rac)
-   ctx->bio->bi_opf |= REQ_RAHEAD;
-   ctx->bio->bi_iter.bi_sector = sector;
-   bio_set_dev(ctx->bio, iomap->bdev);
+   ctx->bio = bio_new(bdev, sector, op, opf, orig_gfp, 1);
ctx->bio->bi_end_io = iomap_read_end_io;
}
 
-- 
2.22.1



[RFC PATCH 29/34] power/swap: use bio_new in hib_submit_io

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 kernel/power/swap.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/kernel/power/swap.c b/kernel/power/swap.c
index c73f2e295167..e92e36c053a6 100644
--- a/kernel/power/swap.c
+++ b/kernel/power/swap.c
@@ -271,13 +271,12 @@ static int hib_submit_io(int op, int op_flags, pgoff_t 
page_off, void *addr,
struct hib_bio_batch *hb)
 {
struct page *page = virt_to_page(addr);
+   sector_t sect = page_off * (PAGE_SIZE >> 9);
struct bio *bio;
int error = 0;
 
-   bio = bio_alloc(GFP_NOIO | __GFP_HIGH, 1);
-   bio->bi_iter.bi_sector = page_off * (PAGE_SIZE >> 9);
-   bio_set_dev(bio, hib_resume_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
+   bio = bio_new(hib_resume_bdev, sect, op, op_flags, 1,
+ GFP_NOIO | __GFP_HIGH);
 
if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) {
pr_err("Adding page to bio failed at %llu\n",
-- 
2.22.1



[RFC PATCH 25/34] ocfs/cluster: use bio_new in dm-log-writes

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/ocfs2/cluster/heartbeat.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index 0179a73a3fa2..b34518036446 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -515,12 +515,13 @@ static struct bio *o2hb_setup_one_bio(struct o2hb_region 
*reg,
unsigned int cs = *current_slot;
struct bio *bio;
struct page *page;
+   sector_t sect = (reg->hr_start_block + cs) << (bits - 9);
 
/* Testing has shown this allocation to take long enough under
 * GFP_KERNEL that the local node can get fenced. It would be
 * nicest if we could pre-allocate these bios and avoid this
 * all together. */
-   bio = bio_alloc(GFP_ATOMIC, 16);
+   bio = bio_new(reg->hr_bdev, sect, op, op_flags, 16, GFP_ATOMIC);
if (!bio) {
mlog(ML_ERROR, "Could not alloc slots BIO!\n");
bio = ERR_PTR(-ENOMEM);
@@ -528,11 +529,8 @@ static struct bio *o2hb_setup_one_bio(struct o2hb_region 
*reg,
}
 
/* Must put everything in 512 byte sectors for the bio... */
-   bio->bi_iter.bi_sector = (reg->hr_start_block + cs) << (bits - 9);
-   bio_set_dev(bio, reg->hr_bdev);
bio->bi_private = wc;
bio->bi_end_io = o2hb_bio_end_io;
-   bio_set_op_attrs(bio, op, op_flags);
 
vec_start = (cs << bits) % PAGE_SIZE;
while(cs < max_slots) {
-- 
2.22.1



[RFC PATCH 28/34] zonefs: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/zonefs/super.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c
index ab68e27bb322..620d67965a22 100644
--- a/fs/zonefs/super.c
+++ b/fs/zonefs/super.c
@@ -661,6 +661,7 @@ static const struct iomap_dio_ops zonefs_write_dio_ops = {
 
 static ssize_t zonefs_file_dio_append(struct kiocb *iocb, struct iov_iter 
*from)
 {
+   unsigned int op = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
struct inode *inode = file_inode(iocb->ki_filp);
struct zonefs_inode_info *zi = ZONEFS_I(inode);
struct block_device *bdev = inode->i_sb->s_bdev;
@@ -678,15 +679,12 @@ static ssize_t zonefs_file_dio_append(struct kiocb *iocb, 
struct iov_iter *from)
if (!nr_pages)
return 0;
 
-   bio = bio_alloc(GFP_NOFS, nr_pages);
+   bio = bio_new(bdev, zi->i_zsector, op, 0, GFP_NOFS, nr_pages);
if (!bio)
return -ENOMEM;
 
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = zi->i_zsector;
bio->bi_write_hint = iocb->ki_hint;
bio->bi_ioprio = iocb->ki_ioprio;
-   bio->bi_opf = REQ_OP_ZONE_APPEND | REQ_SYNC | REQ_IDLE;
if (iocb->ki_flags & IOCB_DSYNC)
bio->bi_opf |= REQ_FUA;
 
-- 
2.22.1



[RFC PATCH 22/34] fs/jfs/jfs_metapage.c: use bio_new in metapage_readpage

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_metapage.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/fs/jfs/jfs_metapage.c b/fs/jfs/jfs_metapage.c
index 3fa09d9a0b94..c7be3a2773bf 100644
--- a/fs/jfs/jfs_metapage.c
+++ b/fs/jfs/jfs_metapage.c
@@ -495,13 +495,11 @@ static int metapage_readpage(struct file *fp, struct page 
*page)
if (bio)
submit_bio(bio);
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio_set_dev(bio, inode->i_sb->s_bdev);
-   bio->bi_iter.bi_sector =
-   pblock << (inode->i_blkbits - 9);
+   bio = bio_new(inode->i_sb->s_bdev,
+   pblock << (inode->i_blkbits - 9),
+   REQ_OP_READ, 0, 1, GFP_NOFS);
bio->bi_end_io = metapage_read_end_io;
bio->bi_private = page;
-   bio_set_op_attrs(bio, REQ_OP_READ, 0);
len = xlen << inode->i_blkbits;
offset = block_offset << inode->i_blkbits;
if (bio_add_page(bio, page, len, offset) < len)
-- 
2.22.1



[RFC PATCH 15/34] fscrypt: use bio_new in fscrypt_zeroout_range

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/crypto/bio.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/crypto/bio.c b/fs/crypto/bio.c
index b048a0e38516..20dab9bdf098 100644
--- a/fs/crypto/bio.c
+++ b/fs/crypto/bio.c
@@ -148,12 +148,11 @@ int fscrypt_zeroout_range(const struct inode *inode, 
pgoff_t lblk,
return -EINVAL;
 
/* This always succeeds since __GFP_DIRECT_RECLAIM is set. */
-   bio = bio_alloc(GFP_NOFS, nr_pages);
+   bio = bio_alloc(inode->i_sb->s_bdev, 0, REQ_OP_WRITE, 0, nr_pages,
+   GFP_NOFS);
 
do {
-   bio_set_dev(bio, inode->i_sb->s_bdev);
bio->bi_iter.bi_sector = pblk << (blockbits - 9);
-   bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
 
i = 0;
offset = 0;
-- 
2.22.1



[RFC PATCH 20/34] fs/jfs/jfs_logmgr.c: use bio_new in lbmStartIO

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/jfs/jfs_logmgr.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
index 4481f3e33a3f..bb25737d52f6 100644
--- a/fs/jfs/jfs_logmgr.c
+++ b/fs/jfs/jfs_logmgr.c
@@ -2121,16 +2121,14 @@ static void lbmStartIO(struct lbuf * bp)
 
jfs_info("lbmStartIO");
 
-   bio = bio_alloc(GFP_NOFS, 1);
-   bio->bi_iter.bi_sector = bp->l_blkno << (log->l2bsize - 9);
-   bio_set_dev(bio, log->bdev);
+   bio = bio_new(log->bdev, bp->l_blkno << (log->l2bsize - 9),
+   REQ_OP_WRITE | REQ_SYNC, 0, 1, GFP_NOFS);
 
bio_add_page(bio, bp->l_page, LOGPSIZE, bp->l_offset);
BUG_ON(bio->bi_iter.bi_size != LOGPSIZE);
 
bio->bi_end_io = lbmIODone;
bio->bi_private = bp;
-   bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
 
/* check if journaling to disk has been disabled */
if (log->no_integrity) {
-- 
2.22.1



[RFC PATCH 12/34] scsi: target/iblock: use bio_new

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/target/target_core_iblock.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_iblock.c 
b/drivers/target/target_core_iblock.c
index 8ed93fd205c7..f1264918aee1 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -379,10 +379,9 @@ iblock_execute_sync_cache(struct se_cmd *cmd)
if (immed)
target_complete_cmd(cmd, SAM_STAT_GOOD);
 
-   bio = bio_alloc(GFP_KERNEL, 0);
+   bio = bio_new(ib_dev->ibd_bd, 0, REQ_OP_WRITE, REQ_PREFLUSH, 0,
+ GFP_KERNEL);
bio->bi_end_io = iblock_end_io_flush;
-   bio_set_dev(bio, ib_dev->ibd_bd);
-   bio->bi_opf = REQ_OP_WRITE | REQ_PREFLUSH;
if (!immed)
bio->bi_private = cmd;
submit_bio(bio);
-- 
2.22.1



[RFC PATCH 13/34] block: use bio_new in __blkdev_direct_IO

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/block_dev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 9d4b1a884d76..f3e3247894d7 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -367,6 +367,8 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
return -EINVAL;
 
bio = bio_alloc_bioset(GFP_KERNEL, nr_pages, _dio_pool);
+   bio_set_dev(bio, bdev);
+   bio->bi_iter.bi_sector = pos >> 9;
 
dio = container_of(bio, struct blkdev_dio, bio);
dio->is_sync = is_sync = is_sync_kiocb(iocb);
@@ -389,8 +391,6 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
blk_start_plug();
 
for (;;) {
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = pos >> 9;
bio->bi_write_hint = iocb->ki_hint;
bio->bi_private = dio;
bio->bi_end_io = blkdev_bio_end_io;
@@ -446,7 +446,7 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
}
 
submit_bio(bio);
-   bio = bio_alloc(GFP_KERNEL, nr_pages);
+   bio = bio_new(bdev, pos >> 9, 0, 0, nr_pages, GFP_KERNEL);
}
 
if (!is_poll)
-- 
2.22.1



[RFC PATCH 08/34] dm-zoned: use bio_new in get_mblock_slow

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index 039d17b28938..e6252f48a49c 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -550,7 +550,8 @@ static struct dmz_mblock *dmz_get_mblock_slow(struct 
dmz_metadata *zmd,
if (!mblk)
return ERR_PTR(-ENOMEM);
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), REQ_OP_READ,
+ REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio) {
dmz_free_mblock(zmd, mblk);
return ERR_PTR(-ENOMEM);
@@ -577,11 +578,8 @@ static struct dmz_mblock *dmz_get_mblock_slow(struct 
dmz_metadata *zmd,
spin_unlock(>mblk_lock);
 
/* Submit read BIO */
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
bio->bi_private = mblk;
bio->bi_end_io = dmz_mblock_bio_end_io;
-   bio_set_op_attrs(bio, REQ_OP_READ, REQ_META | REQ_PRIO);
bio_add_page(bio, mblk->page, DMZ_BLOCK_SIZE, 0);
submit_bio(bio);
 
-- 
2.22.1



[RFC PATCH 09/34] dm-zoned: use bio_new in dmz_write_mblock

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/md/dm-zoned-metadata.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/md/dm-zoned-metadata.c b/drivers/md/dm-zoned-metadata.c
index e6252f48a49c..fa0ee732c6e9 100644
--- a/drivers/md/dm-zoned-metadata.c
+++ b/drivers/md/dm-zoned-metadata.c
@@ -723,7 +723,8 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, 
struct dmz_mblock *mblk,
if (dmz_bdev_is_dying(dev))
return -EIO;
 
-   bio = bio_alloc(GFP_NOIO, 1);
+   bio = bio_new(dev->bdev, dmz_blk2sect(block), REQ_OP_WRITE,
+ REQ_META | REQ_PRIO, 1, GFP_NOIO);
if (!bio) {
set_bit(DMZ_META_ERROR, >state);
return -ENOMEM;
@@ -731,11 +732,8 @@ static int dmz_write_mblock(struct dmz_metadata *zmd, 
struct dmz_mblock *mblk,
 
set_bit(DMZ_META_WRITING, >state);
 
-   bio->bi_iter.bi_sector = dmz_blk2sect(block);
-   bio_set_dev(bio, dev->bdev);
bio->bi_private = mblk;
bio->bi_end_io = dmz_mblock_bio_end_io;
-   bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_META | REQ_PRIO);
bio_add_page(bio, mblk->page, DMZ_BLOCK_SIZE, 0);
submit_bio(bio);
 
-- 
2.22.1



[RFC PATCH 03/34] drdb: use bio_new in drdb

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/drbd/drbd_receiver.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c 
b/drivers/block/drbd/drbd_receiver.c
index 09c86ef3f0fd..e1cd3427b28b 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1643,6 +1643,7 @@ int drbd_submit_peer_request(struct drbd_device *device,
struct bio *bio;
struct page *page = peer_req->pages;
sector_t sector = peer_req->i.sector;
+   struct block_device *bdev = device->ldev->backing_bdev;
unsigned data_size = peer_req->i.size;
unsigned n_bios = 0;
unsigned nr_pages = (data_size + PAGE_SIZE -1) >> PAGE_SHIFT;
@@ -1687,15 +1688,12 @@ int drbd_submit_peer_request(struct drbd_device *device,
 * generated bio, but a bio allocated on behalf of the peer.
 */
 next_bio:
-   bio = bio_alloc(GFP_NOIO, nr_pages);
+   bio = bio_new(bdev, sector, op, op_flags, GFP_NOIO, nr_pages);
if (!bio) {
drbd_err(device, "submit_ee: Allocation of a bio failed 
(nr_pages=%u)\n", nr_pages);
goto fail;
}
/* > peer_req->i.sector, unless this is the first bio */
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, device->ldev->backing_bdev);
-   bio_set_op_attrs(bio, op, op_flags);
bio->bi_private = peer_req;
bio->bi_end_io = drbd_peer_request_endio;
 
-- 
2.22.1



[RFC PATCH 04/34] drdb: use bio_new() in submit_one_flush

2021-01-27 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/drbd/drbd_receiver.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/block/drbd/drbd_receiver.c 
b/drivers/block/drbd/drbd_receiver.c
index e1cd3427b28b..b86bbf725cbd 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -1277,8 +1277,10 @@ static void one_flush_endio(struct bio *bio)
 
 static void submit_one_flush(struct drbd_device *device, struct 
issue_flush_context *ctx)
 {
-   struct bio *bio = bio_alloc(GFP_NOIO, 0);
+   struct block_device *bdev = device->ldev->backing_bdev;
+   struct bio *bio = bio_new(bdev, 0, REQ_OP_FLUSH, REQ_PREFLUSH, 0, 
GFP_NOIO);
struct one_flush_context *octx = kmalloc(sizeof(*octx), GFP_NOIO);
+
if (!bio || !octx) {
drbd_warn(device, "Could not allocate a bio, CANNOT ISSUE 
FLUSH\n");
/* FIXME: what else can I do now?  disconnecting or detaching
@@ -1296,10 +1298,8 @@ static void submit_one_flush(struct drbd_device *device, 
struct issue_flush_cont
 
octx->device = device;
octx->ctx = ctx;
-   bio_set_dev(bio, device->ldev->backing_bdev);
bio->bi_private = octx;
bio->bi_end_io = one_flush_endio;
-   bio->bi_opf = REQ_OP_FLUSH | REQ_PREFLUSH;
 
device->flush_jif = jiffies;
set_bit(FLUSH_PENDING, >flags);
-- 
2.22.1



[RFC PATCH 01/34] block: move common code into blk_next_bio()

2021-01-27 Thread Chaitanya Kulkarni
blk_next_bio() is the central function which allocates the bios for
discard, write-same, write-zeroes and zone-mgmt. The initialization of
various bio members is duplicated in disacrd, write-same, write-zeores.
In this preparation patch we add bdev, sector, op, and opf arguments to
the blk_next_bio() to reduce the duplication. 

In the next patch we introduce bio_new(), this prepration patch allows
us to call it inside blk_next_bio().

Signed-off-by: Chaitanya Kulkarni 
---
 block/blk-lib.c   | 36 +++-
 block/blk-zoned.c |  4 +---
 block/blk.h   |  5 +++--
 3 files changed, 19 insertions(+), 26 deletions(-)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 752f9c722062..fb486a0bdb58 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -10,7 +10,9 @@
 
 #include "blk.h"
 
-struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp)
+struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
+   sector_t sect, unsigned op, unsigned opf,
+   unsigned int nr_pages, gfp_t gfp)
 {
struct bio *new = bio_alloc(gfp, nr_pages);
 
@@ -19,6 +21,10 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int 
nr_pages, gfp_t gfp)
submit_bio(bio);
}
 
+   new->bi_iter.bi_sector = sect;
+   bio_set_dev(new, bdev);
+   bio_set_op_attrs(new, op, opf);
+
return new;
 }
 
@@ -94,11 +100,7 @@ int __blkdev_issue_discard(struct block_device *bdev, 
sector_t sector,
 
WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
 
-   bio = blk_next_bio(bio, 0, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
-   bio_set_op_attrs(bio, op, 0);
-
+   bio = blk_next_bio(bio, bdev, sector, op, 0, 0, gfp_mask);
bio->bi_iter.bi_size = req_sects << 9;
sector += req_sects;
nr_sects -= req_sects;
@@ -168,6 +170,7 @@ static int __blkdev_issue_write_same(struct block_device 
*bdev, sector_t sector,
 {
struct request_queue *q = bdev_get_queue(bdev);
unsigned int max_write_same_sectors;
+   unsigned int op = REQ_OP_WRITE_SAME;
struct bio *bio = *biop;
sector_t bs_mask;
 
@@ -188,14 +191,11 @@ static int __blkdev_issue_write_same(struct block_device 
*bdev, sector_t sector,
max_write_same_sectors = bio_allowed_max_sectors(q);
 
while (nr_sects) {
-   bio = blk_next_bio(bio, 1, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
+   bio = blk_next_bio(bio, bdev, sector, op, 0, 1, gfp_mask);
bio->bi_vcnt = 1;
bio->bi_io_vec->bv_page = page;
bio->bi_io_vec->bv_offset = 0;
bio->bi_io_vec->bv_len = bdev_logical_block_size(bdev);
-   bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0);
 
if (nr_sects > max_write_same_sectors) {
bio->bi_iter.bi_size = max_write_same_sectors << 9;
@@ -249,7 +249,9 @@ static int __blkdev_issue_write_zeroes(struct block_device 
*bdev,
 {
struct bio *bio = *biop;
unsigned int max_write_zeroes_sectors;
+   unsigned int op = REQ_OP_WRITE_ZEROES;
struct request_queue *q = bdev_get_queue(bdev);
+   unsigned int opf = flags & BLKDEV_ZERO_NOUNMAP ? REQ_NOUNMAP : 0;
 
if (!q)
return -ENXIO;
@@ -264,13 +266,7 @@ static int __blkdev_issue_write_zeroes(struct block_device 
*bdev,
return -EOPNOTSUPP;
 
while (nr_sects) {
-   bio = blk_next_bio(bio, 0, gfp_mask);
-   bio->bi_iter.bi_sector = sector;
-   bio_set_dev(bio, bdev);
-   bio->bi_opf = REQ_OP_WRITE_ZEROES;
-   if (flags & BLKDEV_ZERO_NOUNMAP)
-   bio->bi_opf |= REQ_NOUNMAP;
-
+   bio = blk_next_bio(bio, bdev, sector, op, opf, 0, gfp_mask);
if (nr_sects > max_write_zeroes_sectors) {
bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;
nr_sects -= max_write_zeroes_sectors;
@@ -303,6 +299,7 @@ static int __blkdev_issue_zero_pages(struct block_device 
*bdev,
sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
struct bio **biop)
 {
+   unsigned int nr_pages = __blkdev_sectors_to_bio_pages(nr_sects);
struct request_queue *q = bdev_get_queue(bdev);
struct bio *bio = *biop;
int bi_size = 0;
@@ -315,11 +312,8 @@ static int __blkdev_issue_zero_pages(struct block_device 
*bdev,
return -EPERM;
 
while (nr_sects != 0) {
-   bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects),
+   bio = blk_next_bio(bio, bdev, s

[COMPILE ONLY RFC PATCH] loop: avoid page allocation in the fast path

2021-01-27 Thread Chaitanya Kulkarni
The functions lo_write_transfer() and lo_read_transfer() allocte and
free the page everytime it is called from the do_req_filebacked().

Add a member to the loop_cmd structure and use that page in read/write
transfer functions.

This is *compile only* RFC, if this is accepted I'll send tested
version.

Signed-off-by: Chaitanya Kulkarni 
---
 drivers/block/loop.c | 22 --
 drivers/block/loop.h |  1 +
 2 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 578fc034db3f..08bd17afbdff 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -318,14 +318,13 @@ static int lo_write_simple(struct loop_device *lo, struct 
request *rq,
  * access to the destination pages of the backing file.
  */
 static int lo_write_transfer(struct loop_device *lo, struct request *rq,
-   loff_t pos)
+struct loop_cmd *cmd, loff_t pos)
 {
-   struct bio_vec bvec, b;
+   struct page *page = >page;
struct req_iterator iter;
-   struct page *page;
+   struct bio_vec bvec, b;
int ret = 0;
 
-   page = alloc_page(GFP_NOIO);
if (unlikely(!page))
return -ENOMEM;
 
@@ -343,7 +342,6 @@ static int lo_write_transfer(struct loop_device *lo, struct 
request *rq,
break;
}
 
-   __free_page(page);
return ret;
 }
 
@@ -377,19 +375,15 @@ static int lo_read_simple(struct loop_device *lo, struct 
request *rq,
 }
 
 static int lo_read_transfer(struct loop_device *lo, struct request *rq,
-   loff_t pos)
+   struct loop_cmd *cmd, loff_t pos)
 {
-   struct bio_vec bvec, b;
+   struct page *page = >page;
struct req_iterator iter;
+   struct bio_vec bvec, b;
struct iov_iter i;
-   struct page *page;
ssize_t len;
int ret = 0;
 
-   page = alloc_page(GFP_NOIO);
-   if (unlikely(!page))
-   return -ENOMEM;
-
rq_for_each_segment(bvec, rq, iter) {
loff_t offset = pos;
 
@@ -622,14 +616,14 @@ static int do_req_filebacked(struct loop_device *lo, 
struct request *rq)
return lo_fallocate(lo, rq, pos, FALLOC_FL_PUNCH_HOLE);
case REQ_OP_WRITE:
if (lo->transfer)
-   return lo_write_transfer(lo, rq, pos);
+   return lo_write_transfer(lo, rq, cmd, pos);
else if (cmd->use_aio)
return lo_rw_aio(lo, cmd, pos, WRITE);
else
return lo_write_simple(lo, rq, pos);
case REQ_OP_READ:
if (lo->transfer)
-   return lo_read_transfer(lo, rq, pos);
+   return lo_read_transfer(lo, rq, cmd, pos);
else if (cmd->use_aio)
return lo_rw_aio(lo, cmd, pos, READ);
else
diff --git a/drivers/block/loop.h b/drivers/block/loop.h
index a3c04f310672..dd949b22e9c9 100644
--- a/drivers/block/loop.h
+++ b/drivers/block/loop.h
@@ -71,6 +71,7 @@ struct loop_cmd {
atomic_t ref; /* only for aio */
long ret;
struct kiocb iocb;
+   struct page page;
struct bio_vec *bvec;
struct cgroup_subsys_state *css;
 };
-- 
2.22.1



Re: [PATCH 1/2] mtip32xx: use PCI #defines instead of numbers

2021-01-27 Thread Chaitanya Kulkarni


> On Jan 26, 2021, at 11:41 PM, Chaitanya Kulkarni  
> wrote:
> 
> On 1/26/21 14:14, Bjorn Helgaas wrote:
>> From: Bjorn Helgaas 
>> 
>> Use PCI #defines for PCIe Device Control register values instead of
>> hard-coding bit positions.  No functional change intended.
>> 
>> Signed-off-by: Bjorn Helgaas 
> 
> I've verified the values present in the include/uapi/linux/pci_regs.h
> matches open coded bit shift values. LGTM.
> 
> Reviewed-by: Chaitanya Kulkarni 
> 
Something is seriously wrong. I sent out this in the morning and it got 
delivered right now. 
> 


Re: [PATCH 1/2] mtip32xx: use PCI #defines instead of numbers

2021-01-26 Thread Chaitanya Kulkarni
On 1/26/21 14:14, Bjorn Helgaas wrote:
> From: Bjorn Helgaas 
>
> Use PCI #defines for PCIe Device Control register values instead of
> hard-coding bit positions.  No functional change intended.
>
> Signed-off-by: Bjorn Helgaas 

I've verified the values present in the include/uapi/linux/pci_regs.h
matches open coded bit shift values. LGTM.

Reviewed-by: Chaitanya Kulkarni 



Re: Getting a new fs in the kernel

2021-01-26 Thread Chaitanya Kulkarni
Amy,

On 1/26/21 8:26 AM, Amy Parker wrote:
> Kernel development newcomer here. I've begun creating a concept for a
> new filesystem, and ideally once it's completed, rich, and stable I'd
> try to get it into the kernel.
>
> What would be the process for this? I'd assume a patch sequence, but
> they'd all be dependent on each other, and sending in tons of
> dependent patches doesn't sound like a great idea. I've seen requests
> for pulls, but since I'm new here I don't really know what to do.
>
> Thank you for guidance!
>
> Best regards,
> Amy Parker
> she/her/hers
>
>From what I've seen you can post the long patch-series as an RFC and get the

discussion started.

The priority should be ease of review and not the total patch-count.




Re: [PATCH v4 0/1] scale loop device lock

2021-01-26 Thread Chaitanya Kulkarni
Pavel,

On 1/26/21 6:48 AM, Pavel Tatashin wrote:
> Changelog
> v4
>   - Added review-by Petr Vorel
>   - Addressed comments from Chaitanya Kulkarni


Thanks a lot for making these changes, detail commit log helps everyone
in the community and not just to the owner.


Re: [PATCH v3 1/1] loop: scale loop device by introducing per device lock

2021-01-26 Thread Chaitanya Kulkarni
On 1/25/21 12:15 PM, Pavel Tatashin wrote:
> Currently, loop device has only one global lock:
> loop_ctl_mutex.
Above line can be :-
Currently, loop device has only one global lock: loop_ctl_mutex.

Also please provide a complete discretion what are the members it protects,
i.e. how big the size of the current locking is, helps the reviewers &
maintainer.
> This becomes hot in scenarios where many loop devices are used.
>
> Scale it by introducing per-device lock: lo_mutex that protects the
> fields in struct loop_device. Keep loop_ctl_mutex to protect global
> data such as loop_index_idr, loop_lookup, loop_add.
When it comes to scaling, lockstat data is more descriptive and useful along
with thetotal time of execution which has contention numbers with increasing
number of threads/devices/users on logarithmic scale, at-least that is
how I've
solved the some of file-systems scaling issues in the past.
>
> Lock ordering: loop_ctl_mutex > lo_mutex.
The above statement needs a in-detail commit log description. Usually >
sort of statements are not a good practice for something as important as
lock priority which was not present in the original code.
> Signed-off-by: Pavel Tatashin 
> Reviewed-by: Tyler Hicks 
> ---
>  drivers/block/loop.c | 92 +---
>
>
>  
>   /*
> -  * Need not hold loop_ctl_mutex to fput backing file.
> -  * Calling fput holding loop_ctl_mutex triggers a circular
> +  * Need not hold lo_mutex to fput backing file.
> +  * Calling fput holding lo_mutex triggers a circular
>* lock dependency possibility warning as fput can take
> -  * bd_mutex which is usually taken before loop_ctl_mutex.
> +  * bd_mutex which is usually taken before lo_mutex.
>*/
This is not in your patch, but since you are touching this comment can you
please consider this, it save an entire line and the wasted space:-
   /*  
* Need not hold lo_mutex to fput backing file. Calling fput holding
* lo_mutex triggers a circular lock dependency possibility
warning as
* fput can take bd_mutex which is usually take before lo_mutex.
*/

> @@ -1879,27 +1879,33 @@ static int lo_open(struct block_device *bdev, fmode_t 
> mode)
>   struct loop_device *lo;
>   int err;
>  
> + /*
> +  * take loop_ctl_mutex to protect lo pointer from race with
> +  * loop_control_ioctl(LOOP_CTL_REMOVE), however, to reduce
> +  * contention release it prior to updating lo->lo_refcnt.
> +  */

The above comment could be :-

/*  
 * Take loop_ctl_mutex to protect lo pointer from race with
 * loop_control_ioctl(LOOP_CTL_REMOVE), however, to reduce
contention
 * release it prior to updating lo->lo_refcnt.
 */
>   err = mutex_lock_killable(_ctl_mutex);
>   if (err)


Re: [RFC PATCH 00/37] block: introduce bio_init_fields()

2021-01-21 Thread Chaitanya Kulkarni
On 1/20/21 7:01 PM, Julian Calaby wrote:
> Hi Chaitanya,
>
> On Tue, Jan 19, 2021 at 5:01 PM Chaitanya Kulkarni
>  wrote:
>> Hi,
>>
>> This is a *compile only RFC* which adds a generic helper to initialize
>> the various fields of the bio that is repeated all the places in
>> file-systems, block layer, and drivers.
>>
>> The new helper allows callers to initialize various members such as
>> bdev, sector, private, end io callback, io priority, and write hints.
>>
>> The objective of this RFC is to only start a discussion, this it not
>> completely tested at all.
>> Following diff shows code level benefits of this helper :-
>>  38 files changed, 124 insertions(+), 236 deletions(-)
> On a more abstract note, I don't think this diffstat is actually
> illustrating the benefits of this as much as you think it is.
>
> Yeah, we've reduced the code by 112 lines, but that's barely half the
> curn here. It looks, from the diffstat, that you've effectively
> reduced 2 lines into 1. That isn't much of a saving.
>
> Thanks,
The diff stat is not the only measure since every component fs/driver
has a different style and nested call it just to show the effect.
Thanks for your comment, we have decided to go with the bio_new approach.




Re: [RFC PATCH 31/37] eros: use bio_init_fields in data

2021-01-19 Thread Chaitanya Kulkarni
On 1/19/21 20:06, Gao Xiang wrote:
> Hi Chaitanya,
>
> (drop in-person Cc..)
>
> On Mon, Jan 18, 2021 at 09:06:25PM -0800, Chaitanya Kulkarni wrote:
>
> ...it would be nice if you could update the subject line to
> "erofs: use bio_init_fields "
Sure, if new helper is accepted and can be used in erosfs
then I'll make that change. Thanks for pointing out.
> The same to the following patch [RFC PATCH 32/37]... Also, IMHO,
> these two patches could be merged as one patch if possible,
> although just my own thoughts.
>
> Thanks,
> Gao Xiang



Re: [RFC PATCH 00/37] block: introduce bio_init_fields()

2021-01-19 Thread Chaitanya Kulkarni
On 1/18/21 21:06, Chaitanya Kulkarni wrote:
> Hi,
>
> This is a *compile only RFC* which adds a generic helper to initialize
> the various fields of the bio that is repeated all the places in
> file-systems, block layer, and drivers.
>
> The new helper allows callers to initialize various members such as
> bdev, sector, private, end io callback, io priority, and write hints.
>
> The objective of this RFC is to only start a discussion, this it not 
> completely tested at all. 
>
> Following diff shows code level benefits of this helper :-
>  38 files changed, 124 insertions(+), 236 deletions(-)
>
> -ck
Thanks for replying Mike, Josef and Christoph.

I'll move forward with Christoph's suggestion and get rid of
optional parameters which is making this API hard to use.


[RFC PATCH 02/37] fs: use bio_init_fields in block_dev

2021-01-18 Thread Chaitanya Kulkarni
Signed-off-by: Chaitanya Kulkarni 
---
 fs/block_dev.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/fs/block_dev.c b/fs/block_dev.c
index 3e5b02f6606c..44b992976ee5 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -239,12 +239,9 @@ __blkdev_direct_IO_simple(struct kiocb *iocb, struct 
iov_iter *iter,
}
 
bio_init(, vecs, nr_pages);
-   bio_set_dev(, bdev);
-   bio.bi_iter.bi_sector = pos >> 9;
-   bio.bi_write_hint = iocb->ki_hint;
-   bio.bi_private = current;
-   bio.bi_end_io = blkdev_bio_end_io_simple;
-   bio.bi_ioprio = iocb->ki_ioprio;
+   bio_init_fields(, bdev, pos >> 9, current, blkdev_bio_end_io_simple,
+   iocb->ki_ioprio, iocb->ki_hint);
+
 
ret = bio_iov_iter_get_pages(, iter);
if (unlikely(ret))
@@ -390,12 +387,8 @@ __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter 
*iter, int nr_pages)
blk_start_plug();
 
for (;;) {
-   bio_set_dev(bio, bdev);
-   bio->bi_iter.bi_sector = pos >> 9;
-   bio->bi_write_hint = iocb->ki_hint;
-   bio->bi_private = dio;
-   bio->bi_end_io = blkdev_bio_end_io;
-   bio->bi_ioprio = iocb->ki_ioprio;
+   bio_init_fields(bio, bdev, pos >> 9, dio, blkdev_bio_end_io,
+   iocb->ki_ioprio, iocb->ki_hint);
 
ret = bio_iov_iter_get_pages(bio, iter);
if (unlikely(ret)) {
-- 
2.22.1



  1   2   3   >