Skip to content
/ linux Public

Commit f15b4e9

Browse files
Luke WangSasha Levin
authored andcommitted
block: decouple secure erase size limit from discard size limit
[ Upstream commit ee81212 ] Secure erase should use max_secure_erase_sectors instead of being limited by max_discard_sectors. Separate the handling of REQ_OP_SECURE_ERASE from REQ_OP_DISCARD to allow each operation to use its own size limit. Signed-off-by: Luke Wang <ziniu.wang_1@nxp.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent ea53119 commit f15b4e9

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

block/blk-merge.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,9 @@ static struct bio *bio_submit_split(struct bio *bio, int split_sectors)
158158
return bio;
159159
}
160160

161-
struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
162-
unsigned *nsegs)
161+
static struct bio *__bio_split_discard(struct bio *bio,
162+
const struct queue_limits *lim, unsigned *nsegs,
163+
unsigned int max_sectors)
163164
{
164165
unsigned int max_discard_sectors, granularity;
165166
sector_t tmp;
@@ -169,8 +170,7 @@ struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
169170

170171
granularity = max(lim->discard_granularity >> 9, 1U);
171172

172-
max_discard_sectors =
173-
min(lim->max_discard_sectors, bio_allowed_max_sectors(lim));
173+
max_discard_sectors = min(max_sectors, bio_allowed_max_sectors(lim));
174174
max_discard_sectors -= max_discard_sectors % granularity;
175175
if (unlikely(!max_discard_sectors))
176176
return bio;
@@ -194,6 +194,19 @@ struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
194194
return bio_submit_split(bio, split_sectors);
195195
}
196196

197+
struct bio *bio_split_discard(struct bio *bio, const struct queue_limits *lim,
198+
unsigned *nsegs)
199+
{
200+
unsigned int max_sectors;
201+
202+
if (bio_op(bio) == REQ_OP_SECURE_ERASE)
203+
max_sectors = lim->max_secure_erase_sectors;
204+
else
205+
max_sectors = lim->max_discard_sectors;
206+
207+
return __bio_split_discard(bio, lim, nsegs, max_sectors);
208+
}
209+
197210
static inline unsigned int blk_boundary_sectors(const struct queue_limits *lim,
198211
bool is_atomic)
199212
{

block/blk.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,14 @@ static inline unsigned int blk_queue_get_max_sectors(struct request *rq)
208208
struct request_queue *q = rq->q;
209209
enum req_op op = req_op(rq);
210210

211-
if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
211+
if (unlikely(op == REQ_OP_DISCARD))
212212
return min(q->limits.max_discard_sectors,
213213
UINT_MAX >> SECTOR_SHIFT);
214214

215+
if (unlikely(op == REQ_OP_SECURE_ERASE))
216+
return min(q->limits.max_secure_erase_sectors,
217+
UINT_MAX >> SECTOR_SHIFT);
218+
215219
if (unlikely(op == REQ_OP_WRITE_ZEROES))
216220
return q->limits.max_write_zeroes_sectors;
217221

0 commit comments

Comments
 (0)