linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] brd: Refuse improperly aligned discard requests
@ 2015-11-04 16:13 Jan Kara
  2015-11-05  4:18 ` Elliott, Robert (Persistent Memory)
  2015-11-05 20:11 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Kara @ 2015-11-04 16:13 UTC (permalink / raw)
  To: axboe; +Cc: LKML, linux-fsdevel, Christoph Hellwig, Jan Kara

Currently when improperly aligned discard request is submitted, we just
silently discard more / less data which results in filesystem corruption
in some cases. Refuse such misaligned requests.

Signed-off-by: Jan Kara <jack@suse.com>
---
 drivers/block/brd.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index b9794aeeb878..4ef4cdf67ede 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -337,6 +337,9 @@ static void brd_make_request(struct request_queue *q, struct bio *bio)
 		goto io_error;
 
 	if (unlikely(bio->bi_rw & REQ_DISCARD)) {
+		if (sector & ((PAGE_SIZE >> SECTOR_SHIFT) - 1) ||
+		    bio->bi_iter.bi_size & PAGE_MASK)
+			goto io_error;
 		discard_from_brd(brd, sector, bio->bi_iter.bi_size);
 		goto out;
 	}
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] brd: Refuse improperly aligned discard requests
  2015-11-04 16:13 [PATCH] brd: Refuse improperly aligned discard requests Jan Kara
@ 2015-11-05  4:18 ` Elliott, Robert (Persistent Memory)
  2015-11-05  8:06   ` Jan Kara
  2015-11-05 20:11 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: Elliott, Robert (Persistent Memory) @ 2015-11-05  4:18 UTC (permalink / raw)
  To: Jan Kara, axboe; +Cc: LKML, linux-fsdevel, Christoph Hellwig


> -----Original Message-----
> From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
> owner@vger.kernel.org] On Behalf Of Jan Kara
> Sent: Wednesday, November 4, 2015 10:14 AM
> To: axboe@kernel.dk
> Cc: LKML <linux-kernel@vger.kernel.org>; linux-fsdevel@vger.kernel.org;
> Christoph Hellwig <hch@infradead.org>; Jan Kara <jack@suse.com>
> Subject: [PATCH] brd: Refuse improperly aligned discard requests
> 
> Currently when improperly aligned discard request is submitted, we just
> silently discard more / less data which results in filesystem corruption
> in some cases. Refuse such misaligned requests.

I agree discarding more than requested is very bad.

If they are routed to SCSI or ATA devices, though, the discard commands
(SCSI UNMAP or ATA DATA SET MANAGEMENT/TRIM) are just hints, so there 
is no guarantee the discard will do anything.  Are you finding 
filesystems that still don't understand that?   dm-raid held that
mistaken assumption for a long time.

---
Robert Elliott, HP Server Storage


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] brd: Refuse improperly aligned discard requests
  2015-11-05  4:18 ` Elliott, Robert (Persistent Memory)
@ 2015-11-05  8:06   ` Jan Kara
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Kara @ 2015-11-05  8:06 UTC (permalink / raw)
  To: Elliott, Robert (Persistent Memory)
  Cc: Jan Kara, axboe, LKML, linux-fsdevel, Christoph Hellwig

On Thu 05-11-15 04:18:49, Elliott, Robert (Persistent Memory) wrote:
> 
> > -----Original Message-----
> > From: linux-kernel-owner@vger.kernel.org [mailto:linux-kernel-
> > owner@vger.kernel.org] On Behalf Of Jan Kara
> > Sent: Wednesday, November 4, 2015 10:14 AM
> > To: axboe@kernel.dk
> > Cc: LKML <linux-kernel@vger.kernel.org>; linux-fsdevel@vger.kernel.org;
> > Christoph Hellwig <hch@infradead.org>; Jan Kara <jack@suse.com>
> > Subject: [PATCH] brd: Refuse improperly aligned discard requests
> > 
> > Currently when improperly aligned discard request is submitted, we just
> > silently discard more / less data which results in filesystem corruption
> > in some cases. Refuse such misaligned requests.
> 
> I agree discarding more than requested is very bad.
> 
> If they are routed to SCSI or ATA devices, though, the discard commands
> (SCSI UNMAP or ATA DATA SET MANAGEMENT/TRIM) are just hints, so there 
> is no guarantee the discard will do anything.  Are you finding 
> filesystems that still don't understand that?   dm-raid held that
> mistaken assumption for a long time.

So there is blkdev_issue_zeroout() which uses blkdev_issue_discard() if
'discard_zeroes_data' is set. I'd hope that in that case zeroing really
happens as submitted or error is returned... Filesystems definitely depend
on blkdev_issue_zeroout() doing what it is told.

								Honza
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] brd: Refuse improperly aligned discard requests
  2015-11-04 16:13 [PATCH] brd: Refuse improperly aligned discard requests Jan Kara
  2015-11-05  4:18 ` Elliott, Robert (Persistent Memory)
@ 2015-11-05 20:11 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2015-11-05 20:11 UTC (permalink / raw)
  To: Jan Kara; +Cc: LKML, linux-fsdevel, Christoph Hellwig

On 11/04/2015 09:13 AM, Jan Kara wrote:
> Currently when improperly aligned discard request is submitted, we just
> silently discard more / less data which results in filesystem corruption
> in some cases. Refuse such misaligned requests.

Applied, thanks Jan.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-11-05 20:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-04 16:13 [PATCH] brd: Refuse improperly aligned discard requests Jan Kara
2015-11-05  4:18 ` Elliott, Robert (Persistent Memory)
2015-11-05  8:06   ` Jan Kara
2015-11-05 20:11 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).