lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 10 Mar 2014 11:01:32 -0700
From:	Frank Mayhar <fmayhar@...gle.com>
To:	Jens Axboe <axboe@...nel.dk>
Cc:	linux-kernel <linux-kernel@...r.kernel.org>
Subject: [PATCH] block:  Force sector and nr_sects to device alignment and
 granularity.

block:  Force sector and nr_sects to device alignment and granularity.

In blkdev_issue_discard(), rather than sending an improperly-
aligned discard to the device (where it may get an error),
adjust the start and length to the block device alignment and
granularity.  Don't fail if this leaves nothing to discard.

Without this change, certain flash drivers can report invalid
trim parameters (and will fail the command).  Per tytso, "given
that discards are advisory, any part of the storage stack is
free to drop discard requests silently."

Signed-off-by: Frank Mayhar <fmayhar@...gle.com>
Reviewed-by: "Theodore Ts'o" <tytso@....edu>

 block/blk-lib.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/block/blk-lib.c b/block/blk-lib.c
index 97a733c..a4472cd 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -61,6 +61,21 @@ int blkdev_issue_discard(struct block_device *bdev,
sector_t sector,
 	alignment = (bdev_discard_alignment(bdev) >> 9) % granularity;
 
 	/*
+	 * Force sector and nr_sects to block device alignment and
+	 * granularity.
+	 */
+	if (alignment && (sector % alignment)) {
+		sector_t adj = alignment - (sector % alignment);
+
+		sector += adj;
+		nr_sects -= adj;
+	}
+	if (nr_sects % granularity)
+		nr_sects -= nr_sects % granularity;
+	if (!nr_sects)
+		return ret;
+
+	/*
 	 * Ensure that max_discard_sectors is of the proper
 	 * granularity, so that requests stay aligned after a split.
 	 */


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists