* [PATCH 1/1] target: fix max_unmap_lba_count calc overflow
@ 2016-06-03 1:12 mchristi
2016-06-03 21:15 ` Bart Van Assche
2016-06-09 5:20 ` Nicholas A. Bellinger
0 siblings, 2 replies; 3+ messages in thread
From: mchristi @ 2016-06-03 1:12 UTC (permalink / raw)
To: target-devel; +Cc: bart.vanassche, Mike Christie, stable
From: Mike Christie <mchristi@redhat.com>
max_discard_sectors only 32bits, and some non scsi backend
devices will set this to the max 0xffffffff, so we can end up
overflowing during the max_unmap_lba_count calculation.
This fixes a regression caused by my patch:
commit 8a9ebe717a133ba7bc90b06047f43cc6b8bcb8b3
Author: Mike Christie <mchristi@redhat.com>
Date: Mon Jan 18 14:09:27 2016 -0600
target: Fix WRITE_SAME/DISCARD conversion to linux 512b sectors
which can result in extra discards being sent to due the overflow
causing max_unmap_lba_count to be smaller than what the backing
device can actually support.
Signed-off-by: Mike Christie <mchristi@redhat.com>
Cc: stable@vger.kernel.org
---
drivers/target/target_core_device.c | 8 +++++---
drivers/target/target_core_file.c | 3 +--
drivers/target/target_core_iblock.c | 3 +--
include/target/target_core_backend.h | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index a4046ca..6b42348 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -821,13 +821,15 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
* in ATA and we need to set TPE=1
*/
bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
- struct request_queue *q, int block_size)
+ struct request_queue *q)
{
+ int block_size = queue_logical_block_size(q);
+
if (!blk_queue_discard(q))
return false;
- attrib->max_unmap_lba_count = (q->limits.max_discard_sectors << 9) /
- block_size;
+ attrib->max_unmap_lba_count =
+ q->limits.max_discard_sectors >> (ilog2(block_size) - 9);
/*
* Currently hardcoded to 1 in Linux/SCSI code..
*/
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 75f0f08..7929186 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -161,8 +161,7 @@ static int fd_configure_device(struct se_device *dev)
dev_size, div_u64(dev_size, fd_dev->fd_block_size),
fd_dev->fd_block_size);
- if (target_configure_unmap_from_queue(&dev->dev_attrib, q,
- fd_dev->fd_block_size))
+ if (target_configure_unmap_from_queue(&dev->dev_attrib, q))
pr_debug("IFILE: BLOCK Discard support available,"
" disabled by default\n");
/*
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 7c4efb4..2077bc2 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -121,8 +121,7 @@ static int iblock_configure_device(struct se_device *dev)
dev->dev_attrib.hw_max_sectors = queue_max_hw_sectors(q);
dev->dev_attrib.hw_queue_depth = q->nr_requests;
- if (target_configure_unmap_from_queue(&dev->dev_attrib, q,
- dev->dev_attrib.hw_block_size))
+ if (target_configure_unmap_from_queue(&dev->dev_attrib, q))
pr_debug("IBLOCK: BLOCK Discard support available,"
" disabled by default\n");
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index d8ab510..f6f3bc5 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -95,6 +95,6 @@ sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd,
bool target_sense_desc_format(struct se_device *dev);
sector_t target_to_linux_sector(struct se_device *dev, sector_t lb);
bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
- struct request_queue *q, int block_size);
+ struct request_queue *q);
#endif /* TARGET_CORE_BACKEND_H */
--
2.7.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] target: fix max_unmap_lba_count calc overflow
2016-06-03 1:12 [PATCH 1/1] target: fix max_unmap_lba_count calc overflow mchristi
@ 2016-06-03 21:15 ` Bart Van Assche
2016-06-09 5:20 ` Nicholas A. Bellinger
1 sibling, 0 replies; 3+ messages in thread
From: Bart Van Assche @ 2016-06-03 21:15 UTC (permalink / raw)
To: mchristi, target-devel; +Cc: bart.vanassche, stable
On 06/02/2016 06:12 PM, mchristi@redhat.com wrote:
> max_discard_sectors only 32bits, and some non scsi backend
> devices will set this to the max 0xffffffff, so we can end up
> overflowing during the max_unmap_lba_count calculation.
Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/1] target: fix max_unmap_lba_count calc overflow
2016-06-03 1:12 [PATCH 1/1] target: fix max_unmap_lba_count calc overflow mchristi
2016-06-03 21:15 ` Bart Van Assche
@ 2016-06-09 5:20 ` Nicholas A. Bellinger
1 sibling, 0 replies; 3+ messages in thread
From: Nicholas A. Bellinger @ 2016-06-09 5:20 UTC (permalink / raw)
To: mchristi; +Cc: target-devel, bart.vanassche, stable
On Thu, 2016-06-02 at 20:12 -0500, mchristi@redhat.com wrote:
> From: Mike Christie <mchristi@redhat.com>
>
> max_discard_sectors only 32bits, and some non scsi backend
> devices will set this to the max 0xffffffff, so we can end up
> overflowing during the max_unmap_lba_count calculation.
>
> This fixes a regression caused by my patch:
>
> commit 8a9ebe717a133ba7bc90b06047f43cc6b8bcb8b3
> Author: Mike Christie <mchristi@redhat.com>
> Date: Mon Jan 18 14:09:27 2016 -0600
>
> target: Fix WRITE_SAME/DISCARD conversion to linux 512b sectors
>
> which can result in extra discards being sent to due the overflow
> causing max_unmap_lba_count to be smaller than what the backing
> device can actually support.
>
> Signed-off-by: Mike Christie <mchristi@redhat.com>
> Cc: stable@vger.kernel.org
>
Applied to target-pending/master.
Thanks MNC + Bart.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-09 5:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-03 1:12 [PATCH 1/1] target: fix max_unmap_lba_count calc overflow mchristi
2016-06-03 21:15 ` Bart Van Assche
2016-06-09 5:20 ` Nicholas A. Bellinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox