Skip to content

Commit 7402e63

Browse files
committed
Merge tag 'block-6.6-2023-09-08' of git://git.kernel.dk/linux
Pull block fixes from Jens Axboe: - Fix null_blk polled IO timeout handling (Chengming) - Regression fix for swapped arguments in drbd bvec_set_page() (Christoph) - String length handling fix for s390 dasd (Heiko) - Fixes for blk-throttle accounting (Yu) - Fix page pinning issue for same page segments (Christoph) - Remove redundant file_remove_privs() call (Christoph) - Fix a regression in partition handling for devices not supporting partitions (Li) * tag 'block-6.6-2023-09-08' of git://git.kernel.dk/linux: drbd: swap bvec_set_page len and offset block: fix pin count management when merging same-page segments null_blk: fix poll request timeout handling s390/dasd: fix string length handling block: don't add or resize partition on the disk with GENHD_FL_NO_PART block: remove the call to file_remove_privs in blkdev_write_iter blk-throttle: consider 'carryover_ios/bytes' in throtl_trim_slice() blk-throttle: use calculate_io/bytes_allowed() for throtl_trim_slice() blk-throttle: fix wrong comparation while 'carryover_ios/bytes' is negative blk-throttle: print signed value 'carryover_bytes/ios' for user
2 parents 7ccc3eb + 4b9c2ed commit 7402e63

File tree

10 files changed

+84
-79
lines changed

10 files changed

+84
-79
lines changed

block/blk-map.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,11 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
315315
n = bytes;
316316

317317
if (!bio_add_hw_page(rq->q, bio, page, n, offs,
318-
max_sectors, &same_page)) {
319-
if (same_page)
320-
bio_release_page(bio, page);
318+
max_sectors, &same_page))
321319
break;
322-
}
323320

321+
if (same_page)
322+
bio_release_page(bio, page);
324323
bytes -= n;
325324
offs = 0;
326325
}

block/blk-throttle.c

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,41 @@ static bool throtl_slice_used(struct throtl_grp *tg, bool rw)
697697
return true;
698698
}
699699

700+
static unsigned int calculate_io_allowed(u32 iops_limit,
701+
unsigned long jiffy_elapsed)
702+
{
703+
unsigned int io_allowed;
704+
u64 tmp;
705+
706+
/*
707+
* jiffy_elapsed should not be a big value as minimum iops can be
708+
* 1 then at max jiffy elapsed should be equivalent of 1 second as we
709+
* will allow dispatch after 1 second and after that slice should
710+
* have been trimmed.
711+
*/
712+
713+
tmp = (u64)iops_limit * jiffy_elapsed;
714+
do_div(tmp, HZ);
715+
716+
if (tmp > UINT_MAX)
717+
io_allowed = UINT_MAX;
718+
else
719+
io_allowed = tmp;
720+
721+
return io_allowed;
722+
}
723+
724+
static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
725+
{
726+
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
727+
}
728+
700729
/* Trim the used slices and adjust slice start accordingly */
701730
static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
702731
{
703-
unsigned long nr_slices, time_elapsed, io_trim;
704-
u64 bytes_trim, tmp;
732+
unsigned long time_elapsed;
733+
long long bytes_trim;
734+
int io_trim;
705735

706736
BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
707737

@@ -723,67 +753,38 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
723753

724754
throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
725755

726-
time_elapsed = jiffies - tg->slice_start[rw];
727-
728-
nr_slices = time_elapsed / tg->td->throtl_slice;
729-
730-
if (!nr_slices)
756+
time_elapsed = rounddown(jiffies - tg->slice_start[rw],
757+
tg->td->throtl_slice);
758+
if (!time_elapsed)
731759
return;
732-
tmp = tg_bps_limit(tg, rw) * tg->td->throtl_slice * nr_slices;
733-
do_div(tmp, HZ);
734-
bytes_trim = tmp;
735760

736-
io_trim = (tg_iops_limit(tg, rw) * tg->td->throtl_slice * nr_slices) /
737-
HZ;
738-
739-
if (!bytes_trim && !io_trim)
761+
bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
762+
time_elapsed) +
763+
tg->carryover_bytes[rw];
764+
io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) +
765+
tg->carryover_ios[rw];
766+
if (bytes_trim <= 0 && io_trim <= 0)
740767
return;
741768

742-
if (tg->bytes_disp[rw] >= bytes_trim)
769+
tg->carryover_bytes[rw] = 0;
770+
if ((long long)tg->bytes_disp[rw] >= bytes_trim)
743771
tg->bytes_disp[rw] -= bytes_trim;
744772
else
745773
tg->bytes_disp[rw] = 0;
746774

747-
if (tg->io_disp[rw] >= io_trim)
775+
tg->carryover_ios[rw] = 0;
776+
if ((int)tg->io_disp[rw] >= io_trim)
748777
tg->io_disp[rw] -= io_trim;
749778
else
750779
tg->io_disp[rw] = 0;
751780

752-
tg->slice_start[rw] += nr_slices * tg->td->throtl_slice;
781+
tg->slice_start[rw] += time_elapsed;
753782

754783
throtl_log(&tg->service_queue,
755-
"[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu",
756-
rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim,
757-
tg->slice_start[rw], tg->slice_end[rw], jiffies);
758-
}
759-
760-
static unsigned int calculate_io_allowed(u32 iops_limit,
761-
unsigned long jiffy_elapsed)
762-
{
763-
unsigned int io_allowed;
764-
u64 tmp;
765-
766-
/*
767-
* jiffy_elapsed should not be a big value as minimum iops can be
768-
* 1 then at max jiffy elapsed should be equivalent of 1 second as we
769-
* will allow dispatch after 1 second and after that slice should
770-
* have been trimmed.
771-
*/
772-
773-
tmp = (u64)iops_limit * jiffy_elapsed;
774-
do_div(tmp, HZ);
775-
776-
if (tmp > UINT_MAX)
777-
io_allowed = UINT_MAX;
778-
else
779-
io_allowed = tmp;
780-
781-
return io_allowed;
782-
}
783-
784-
static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
785-
{
786-
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
784+
"[%c] trim slice nr=%lu bytes=%lld io=%d start=%lu end=%lu jiffies=%lu",
785+
rw == READ ? 'R' : 'W', time_elapsed / tg->td->throtl_slice,
786+
bytes_trim, io_trim, tg->slice_start[rw], tg->slice_end[rw],
787+
jiffies);
787788
}
788789

789790
static void __tg_update_carryover(struct throtl_grp *tg, bool rw)
@@ -816,7 +817,7 @@ static void tg_update_carryover(struct throtl_grp *tg)
816817
__tg_update_carryover(tg, WRITE);
817818

818819
/* see comments in struct throtl_grp for meaning of these fields. */
819-
throtl_log(&tg->service_queue, "%s: %llu %llu %u %u\n", __func__,
820+
throtl_log(&tg->service_queue, "%s: %lld %lld %d %d\n", __func__,
820821
tg->carryover_bytes[READ], tg->carryover_bytes[WRITE],
821822
tg->carryover_ios[READ], tg->carryover_ios[WRITE]);
822823
}
@@ -825,7 +826,7 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
825826
u32 iops_limit)
826827
{
827828
bool rw = bio_data_dir(bio);
828-
unsigned int io_allowed;
829+
int io_allowed;
829830
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
830831

831832
if (iops_limit == UINT_MAX) {
@@ -838,9 +839,8 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
838839
jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
839840
io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd) +
840841
tg->carryover_ios[rw];
841-
if (tg->io_disp[rw] + 1 <= io_allowed) {
842+
if (io_allowed > 0 && tg->io_disp[rw] + 1 <= io_allowed)
842843
return 0;
843-
}
844844

845845
/* Calc approx time to dispatch */
846846
jiffy_wait = jiffy_elapsed_rnd - jiffy_elapsed;
@@ -851,7 +851,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
851851
u64 bps_limit)
852852
{
853853
bool rw = bio_data_dir(bio);
854-
u64 bytes_allowed, extra_bytes;
854+
long long bytes_allowed;
855+
u64 extra_bytes;
855856
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
856857
unsigned int bio_size = throtl_bio_data_size(bio);
857858

@@ -869,9 +870,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
869870
jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
870871
bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) +
871872
tg->carryover_bytes[rw];
872-
if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) {
873+
if (bytes_allowed > 0 && tg->bytes_disp[rw] + bio_size <= bytes_allowed)
873874
return 0;
874-
}
875875

876876
/* Calc approx time to dispatch */
877877
extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;

block/blk-throttle.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ struct throtl_grp {
127127
* bytes/ios are waited already in previous configuration, and they will
128128
* be used to calculate wait time under new configuration.
129129
*/
130-
uint64_t carryover_bytes[2];
131-
unsigned int carryover_ios[2];
130+
long long carryover_bytes[2];
131+
int carryover_ios[2];
132132

133133
unsigned long last_check_time;
134134

block/fops.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,6 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
671671
iov_iter_truncate(from, size);
672672
}
673673

674-
ret = file_remove_privs(file);
675-
if (ret)
676-
return ret;
677-
678674
ret = file_update_time(file);
679675
if (ret)
680676
return ret;

block/ioctl.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static int blkpg_do_ioctl(struct block_device *bdev,
2020
struct blkpg_partition p;
2121
long long start, length;
2222

23+
if (disk->flags & GENHD_FL_NO_PART)
24+
return -EINVAL;
2325
if (!capable(CAP_SYS_ADMIN))
2426
return -EACCES;
2527
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))

drivers/block/drbd/drbd_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa
15571557
do {
15581558
int sent;
15591559

1560-
bvec_set_page(&bvec, page, offset, len);
1560+
bvec_set_page(&bvec, page, len, offset);
15611561
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len);
15621562

15631563
sent = sock_sendmsg(socket, &msg);

drivers/block/null_blk/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,9 +1643,12 @@ static int null_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob)
16431643
struct nullb_queue *nq = hctx->driver_data;
16441644
LIST_HEAD(list);
16451645
int nr = 0;
1646+
struct request *rq;
16461647

16471648
spin_lock(&nq->poll_lock);
16481649
list_splice_init(&nq->poll_list, &list);
1650+
list_for_each_entry(rq, &list, queuelist)
1651+
blk_mq_set_request_complete(rq);
16491652
spin_unlock(&nq->poll_lock);
16501653

16511654
while (!list_empty(&list)) {
@@ -1671,16 +1674,21 @@ static enum blk_eh_timer_return null_timeout_rq(struct request *rq)
16711674
struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
16721675
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(rq);
16731676

1674-
pr_info("rq %p timed out\n", rq);
1675-
16761677
if (hctx->type == HCTX_TYPE_POLL) {
16771678
struct nullb_queue *nq = hctx->driver_data;
16781679

16791680
spin_lock(&nq->poll_lock);
1681+
/* The request may have completed meanwhile. */
1682+
if (blk_mq_request_completed(rq)) {
1683+
spin_unlock(&nq->poll_lock);
1684+
return BLK_EH_DONE;
1685+
}
16801686
list_del_init(&rq->queuelist);
16811687
spin_unlock(&nq->poll_lock);
16821688
}
16831689

1690+
pr_info("rq %p timed out\n", rq);
1691+
16841692
/*
16851693
* If the device is marked as blocking (i.e. memory backed or zoned
16861694
* device), the submission path may be blocked waiting for resources

drivers/s390/block/dasd_devmap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,16 +1378,12 @@ static ssize_t dasd_vendor_show(struct device *dev,
13781378

13791379
static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
13801380

1381-
#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
1382-
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
1383-
/* vduit */ 32 + 1)
1384-
13851381
static ssize_t
13861382
dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
13871383
{
1384+
char uid_string[DASD_UID_STRLEN];
13881385
struct dasd_device *device;
13891386
struct dasd_uid uid;
1390-
char uid_string[UID_STRLEN];
13911387
char ua_string[3];
13921388

13931389
device = dasd_device_from_cdev(to_ccwdev(dev));

drivers/s390/block/dasd_eckd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,12 +1079,12 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
10791079

10801080
create_uid(conf, &uid);
10811081
if (strlen(uid.vduit) > 0)
1082-
snprintf(print_uid, sizeof(*print_uid),
1082+
snprintf(print_uid, DASD_UID_STRLEN,
10831083
"%s.%s.%04x.%02x.%s",
10841084
uid.vendor, uid.serial, uid.ssid,
10851085
uid.real_unit_addr, uid.vduit);
10861086
else
1087-
snprintf(print_uid, sizeof(*print_uid),
1087+
snprintf(print_uid, DASD_UID_STRLEN,
10881088
"%s.%s.%04x.%02x",
10891089
uid.vendor, uid.serial, uid.ssid,
10901090
uid.real_unit_addr);
@@ -1093,8 +1093,8 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
10931093
static int dasd_eckd_check_cabling(struct dasd_device *device,
10941094
void *conf_data, __u8 lpm)
10951095
{
1096+
char print_path_uid[DASD_UID_STRLEN], print_device_uid[DASD_UID_STRLEN];
10961097
struct dasd_eckd_private *private = device->private;
1097-
char print_path_uid[60], print_device_uid[60];
10981098
struct dasd_conf path_conf;
10991099

11001100
path_conf.data = conf_data;
@@ -1293,9 +1293,9 @@ static void dasd_eckd_path_available_action(struct dasd_device *device,
12931293
__u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
12941294
__u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
12951295
struct dasd_conf_data *conf_data;
1296+
char print_uid[DASD_UID_STRLEN];
12961297
struct dasd_conf path_conf;
12971298
unsigned long flags;
1298-
char print_uid[60];
12991299
int rc, pos;
13001300

13011301
opm = 0;
@@ -5855,8 +5855,8 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
58555855
static int dasd_eckd_reload_device(struct dasd_device *device)
58565856
{
58575857
struct dasd_eckd_private *private = device->private;
5858+
char print_uid[DASD_UID_STRLEN];
58585859
int rc, old_base;
5859-
char print_uid[60];
58605860
struct dasd_uid uid;
58615861
unsigned long flags;
58625862

drivers/s390/block/dasd_int.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ struct dasd_uid {
259259
char vduit[33];
260260
};
261261

262+
#define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 + \
263+
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 + \
264+
/* vduit */ 32 + 1)
265+
262266
/*
263267
* PPRC Status data
264268
*/

0 commit comments

Comments
 (0)