Commit 7402e635 authored by Linus Torvalds's avatar Linus Torvalds

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
parents 7ccc3ebf 4b9c2eda
...@@ -315,12 +315,11 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter, ...@@ -315,12 +315,11 @@ static int bio_map_user_iov(struct request *rq, struct iov_iter *iter,
n = bytes; n = bytes;
if (!bio_add_hw_page(rq->q, bio, page, n, offs, if (!bio_add_hw_page(rq->q, bio, page, n, offs,
max_sectors, &same_page)) { max_sectors, &same_page))
if (same_page)
bio_release_page(bio, page);
break; break;
}
if (same_page)
bio_release_page(bio, page);
bytes -= n; bytes -= n;
offs = 0; offs = 0;
} }
......
...@@ -697,11 +697,41 @@ static bool throtl_slice_used(struct throtl_grp *tg, bool rw) ...@@ -697,11 +697,41 @@ static bool throtl_slice_used(struct throtl_grp *tg, bool rw)
return true; return true;
} }
static unsigned int calculate_io_allowed(u32 iops_limit,
unsigned long jiffy_elapsed)
{
unsigned int io_allowed;
u64 tmp;
/*
* jiffy_elapsed should not be a big value as minimum iops can be
* 1 then at max jiffy elapsed should be equivalent of 1 second as we
* will allow dispatch after 1 second and after that slice should
* have been trimmed.
*/
tmp = (u64)iops_limit * jiffy_elapsed;
do_div(tmp, HZ);
if (tmp > UINT_MAX)
io_allowed = UINT_MAX;
else
io_allowed = tmp;
return io_allowed;
}
static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
{
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
}
/* Trim the used slices and adjust slice start accordingly */ /* Trim the used slices and adjust slice start accordingly */
static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
{ {
unsigned long nr_slices, time_elapsed, io_trim; unsigned long time_elapsed;
u64 bytes_trim, tmp; long long bytes_trim;
int io_trim;
BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw])); BUG_ON(time_before(tg->slice_end[rw], tg->slice_start[rw]));
...@@ -723,67 +753,38 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw) ...@@ -723,67 +753,38 @@ static inline void throtl_trim_slice(struct throtl_grp *tg, bool rw)
throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice); throtl_set_slice_end(tg, rw, jiffies + tg->td->throtl_slice);
time_elapsed = jiffies - tg->slice_start[rw]; time_elapsed = rounddown(jiffies - tg->slice_start[rw],
tg->td->throtl_slice);
nr_slices = time_elapsed / tg->td->throtl_slice; if (!time_elapsed)
if (!nr_slices)
return; return;
tmp = tg_bps_limit(tg, rw) * tg->td->throtl_slice * nr_slices;
do_div(tmp, HZ);
bytes_trim = tmp;
io_trim = (tg_iops_limit(tg, rw) * tg->td->throtl_slice * nr_slices) / bytes_trim = calculate_bytes_allowed(tg_bps_limit(tg, rw),
HZ; time_elapsed) +
tg->carryover_bytes[rw];
if (!bytes_trim && !io_trim) io_trim = calculate_io_allowed(tg_iops_limit(tg, rw), time_elapsed) +
tg->carryover_ios[rw];
if (bytes_trim <= 0 && io_trim <= 0)
return; return;
if (tg->bytes_disp[rw] >= bytes_trim) tg->carryover_bytes[rw] = 0;
if ((long long)tg->bytes_disp[rw] >= bytes_trim)
tg->bytes_disp[rw] -= bytes_trim; tg->bytes_disp[rw] -= bytes_trim;
else else
tg->bytes_disp[rw] = 0; tg->bytes_disp[rw] = 0;
if (tg->io_disp[rw] >= io_trim) tg->carryover_ios[rw] = 0;
if ((int)tg->io_disp[rw] >= io_trim)
tg->io_disp[rw] -= io_trim; tg->io_disp[rw] -= io_trim;
else else
tg->io_disp[rw] = 0; tg->io_disp[rw] = 0;
tg->slice_start[rw] += nr_slices * tg->td->throtl_slice; tg->slice_start[rw] += time_elapsed;
throtl_log(&tg->service_queue, throtl_log(&tg->service_queue,
"[%c] trim slice nr=%lu bytes=%llu io=%lu start=%lu end=%lu jiffies=%lu", "[%c] trim slice nr=%lu bytes=%lld io=%d start=%lu end=%lu jiffies=%lu",
rw == READ ? 'R' : 'W', nr_slices, bytes_trim, io_trim, rw == READ ? 'R' : 'W', time_elapsed / tg->td->throtl_slice,
tg->slice_start[rw], tg->slice_end[rw], jiffies); bytes_trim, io_trim, tg->slice_start[rw], tg->slice_end[rw],
} jiffies);
static unsigned int calculate_io_allowed(u32 iops_limit,
unsigned long jiffy_elapsed)
{
unsigned int io_allowed;
u64 tmp;
/*
* jiffy_elapsed should not be a big value as minimum iops can be
* 1 then at max jiffy elapsed should be equivalent of 1 second as we
* will allow dispatch after 1 second and after that slice should
* have been trimmed.
*/
tmp = (u64)iops_limit * jiffy_elapsed;
do_div(tmp, HZ);
if (tmp > UINT_MAX)
io_allowed = UINT_MAX;
else
io_allowed = tmp;
return io_allowed;
}
static u64 calculate_bytes_allowed(u64 bps_limit, unsigned long jiffy_elapsed)
{
return mul_u64_u64_div_u64(bps_limit, (u64)jiffy_elapsed, (u64)HZ);
} }
static void __tg_update_carryover(struct throtl_grp *tg, bool rw) static void __tg_update_carryover(struct throtl_grp *tg, bool rw)
...@@ -816,7 +817,7 @@ static void tg_update_carryover(struct throtl_grp *tg) ...@@ -816,7 +817,7 @@ static void tg_update_carryover(struct throtl_grp *tg)
__tg_update_carryover(tg, WRITE); __tg_update_carryover(tg, WRITE);
/* see comments in struct throtl_grp for meaning of these fields. */ /* see comments in struct throtl_grp for meaning of these fields. */
throtl_log(&tg->service_queue, "%s: %llu %llu %u %u\n", __func__, throtl_log(&tg->service_queue, "%s: %lld %lld %d %d\n", __func__,
tg->carryover_bytes[READ], tg->carryover_bytes[WRITE], tg->carryover_bytes[READ], tg->carryover_bytes[WRITE],
tg->carryover_ios[READ], tg->carryover_ios[WRITE]); tg->carryover_ios[READ], tg->carryover_ios[WRITE]);
} }
...@@ -825,7 +826,7 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio ...@@ -825,7 +826,7 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
u32 iops_limit) u32 iops_limit)
{ {
bool rw = bio_data_dir(bio); bool rw = bio_data_dir(bio);
unsigned int io_allowed; int io_allowed;
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
if (iops_limit == UINT_MAX) { if (iops_limit == UINT_MAX) {
...@@ -838,9 +839,8 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio ...@@ -838,9 +839,8 @@ static unsigned long tg_within_iops_limit(struct throtl_grp *tg, struct bio *bio
jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice); jiffy_elapsed_rnd = roundup(jiffy_elapsed + 1, tg->td->throtl_slice);
io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd) + io_allowed = calculate_io_allowed(iops_limit, jiffy_elapsed_rnd) +
tg->carryover_ios[rw]; tg->carryover_ios[rw];
if (tg->io_disp[rw] + 1 <= io_allowed) { if (io_allowed > 0 && tg->io_disp[rw] + 1 <= io_allowed)
return 0; return 0;
}
/* Calc approx time to dispatch */ /* Calc approx time to dispatch */
jiffy_wait = jiffy_elapsed_rnd - jiffy_elapsed; 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, ...@@ -851,7 +851,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
u64 bps_limit) u64 bps_limit)
{ {
bool rw = bio_data_dir(bio); bool rw = bio_data_dir(bio);
u64 bytes_allowed, extra_bytes; long long bytes_allowed;
u64 extra_bytes;
unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd; unsigned long jiffy_elapsed, jiffy_wait, jiffy_elapsed_rnd;
unsigned int bio_size = throtl_bio_data_size(bio); unsigned int bio_size = throtl_bio_data_size(bio);
...@@ -869,9 +870,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio, ...@@ -869,9 +870,8 @@ static unsigned long tg_within_bps_limit(struct throtl_grp *tg, struct bio *bio,
jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice); jiffy_elapsed_rnd = roundup(jiffy_elapsed_rnd, tg->td->throtl_slice);
bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) + bytes_allowed = calculate_bytes_allowed(bps_limit, jiffy_elapsed_rnd) +
tg->carryover_bytes[rw]; tg->carryover_bytes[rw];
if (tg->bytes_disp[rw] + bio_size <= bytes_allowed) { if (bytes_allowed > 0 && tg->bytes_disp[rw] + bio_size <= bytes_allowed)
return 0; return 0;
}
/* Calc approx time to dispatch */ /* Calc approx time to dispatch */
extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed; extra_bytes = tg->bytes_disp[rw] + bio_size - bytes_allowed;
......
...@@ -127,8 +127,8 @@ struct throtl_grp { ...@@ -127,8 +127,8 @@ struct throtl_grp {
* bytes/ios are waited already in previous configuration, and they will * bytes/ios are waited already in previous configuration, and they will
* be used to calculate wait time under new configuration. * be used to calculate wait time under new configuration.
*/ */
uint64_t carryover_bytes[2]; long long carryover_bytes[2];
unsigned int carryover_ios[2]; int carryover_ios[2];
unsigned long last_check_time; unsigned long last_check_time;
......
...@@ -671,10 +671,6 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) ...@@ -671,10 +671,6 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
iov_iter_truncate(from, size); iov_iter_truncate(from, size);
} }
ret = file_remove_privs(file);
if (ret)
return ret;
ret = file_update_time(file); ret = file_update_time(file);
if (ret) if (ret)
return ret; return ret;
......
...@@ -20,6 +20,8 @@ static int blkpg_do_ioctl(struct block_device *bdev, ...@@ -20,6 +20,8 @@ static int blkpg_do_ioctl(struct block_device *bdev,
struct blkpg_partition p; struct blkpg_partition p;
long long start, length; long long start, length;
if (disk->flags & GENHD_FL_NO_PART)
return -EINVAL;
if (!capable(CAP_SYS_ADMIN)) if (!capable(CAP_SYS_ADMIN))
return -EACCES; return -EACCES;
if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) if (copy_from_user(&p, upart, sizeof(struct blkpg_partition)))
......
...@@ -1557,7 +1557,7 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa ...@@ -1557,7 +1557,7 @@ static int _drbd_send_page(struct drbd_peer_device *peer_device, struct page *pa
do { do {
int sent; int sent;
bvec_set_page(&bvec, page, offset, len); bvec_set_page(&bvec, page, len, offset);
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len); iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, len);
sent = sock_sendmsg(socket, &msg); sent = sock_sendmsg(socket, &msg);
......
...@@ -1643,9 +1643,12 @@ static int null_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob) ...@@ -1643,9 +1643,12 @@ static int null_poll(struct blk_mq_hw_ctx *hctx, struct io_comp_batch *iob)
struct nullb_queue *nq = hctx->driver_data; struct nullb_queue *nq = hctx->driver_data;
LIST_HEAD(list); LIST_HEAD(list);
int nr = 0; int nr = 0;
struct request *rq;
spin_lock(&nq->poll_lock); spin_lock(&nq->poll_lock);
list_splice_init(&nq->poll_list, &list); list_splice_init(&nq->poll_list, &list);
list_for_each_entry(rq, &list, queuelist)
blk_mq_set_request_complete(rq);
spin_unlock(&nq->poll_lock); spin_unlock(&nq->poll_lock);
while (!list_empty(&list)) { while (!list_empty(&list)) {
...@@ -1671,16 +1674,21 @@ static enum blk_eh_timer_return null_timeout_rq(struct request *rq) ...@@ -1671,16 +1674,21 @@ static enum blk_eh_timer_return null_timeout_rq(struct request *rq)
struct blk_mq_hw_ctx *hctx = rq->mq_hctx; struct blk_mq_hw_ctx *hctx = rq->mq_hctx;
struct nullb_cmd *cmd = blk_mq_rq_to_pdu(rq); struct nullb_cmd *cmd = blk_mq_rq_to_pdu(rq);
pr_info("rq %p timed out\n", rq);
if (hctx->type == HCTX_TYPE_POLL) { if (hctx->type == HCTX_TYPE_POLL) {
struct nullb_queue *nq = hctx->driver_data; struct nullb_queue *nq = hctx->driver_data;
spin_lock(&nq->poll_lock); spin_lock(&nq->poll_lock);
/* The request may have completed meanwhile. */
if (blk_mq_request_completed(rq)) {
spin_unlock(&nq->poll_lock);
return BLK_EH_DONE;
}
list_del_init(&rq->queuelist); list_del_init(&rq->queuelist);
spin_unlock(&nq->poll_lock); spin_unlock(&nq->poll_lock);
} }
pr_info("rq %p timed out\n", rq);
/* /*
* If the device is marked as blocking (i.e. memory backed or zoned * If the device is marked as blocking (i.e. memory backed or zoned
* device), the submission path may be blocked waiting for resources * device), the submission path may be blocked waiting for resources
......
...@@ -1378,16 +1378,12 @@ static ssize_t dasd_vendor_show(struct device *dev, ...@@ -1378,16 +1378,12 @@ static ssize_t dasd_vendor_show(struct device *dev,
static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL); static DEVICE_ATTR(vendor, 0444, dasd_vendor_show, NULL);
#define UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 +\
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 +\
/* vduit */ 32 + 1)
static ssize_t static ssize_t
dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf) dasd_uid_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
char uid_string[DASD_UID_STRLEN];
struct dasd_device *device; struct dasd_device *device;
struct dasd_uid uid; struct dasd_uid uid;
char uid_string[UID_STRLEN];
char ua_string[3]; char ua_string[3];
device = dasd_device_from_cdev(to_ccwdev(dev)); device = dasd_device_from_cdev(to_ccwdev(dev));
......
...@@ -1079,12 +1079,12 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf, ...@@ -1079,12 +1079,12 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
create_uid(conf, &uid); create_uid(conf, &uid);
if (strlen(uid.vduit) > 0) if (strlen(uid.vduit) > 0)
snprintf(print_uid, sizeof(*print_uid), snprintf(print_uid, DASD_UID_STRLEN,
"%s.%s.%04x.%02x.%s", "%s.%s.%04x.%02x.%s",
uid.vendor, uid.serial, uid.ssid, uid.vendor, uid.serial, uid.ssid,
uid.real_unit_addr, uid.vduit); uid.real_unit_addr, uid.vduit);
else else
snprintf(print_uid, sizeof(*print_uid), snprintf(print_uid, DASD_UID_STRLEN,
"%s.%s.%04x.%02x", "%s.%s.%04x.%02x",
uid.vendor, uid.serial, uid.ssid, uid.vendor, uid.serial, uid.ssid,
uid.real_unit_addr); uid.real_unit_addr);
...@@ -1093,8 +1093,8 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf, ...@@ -1093,8 +1093,8 @@ static void dasd_eckd_get_uid_string(struct dasd_conf *conf,
static int dasd_eckd_check_cabling(struct dasd_device *device, static int dasd_eckd_check_cabling(struct dasd_device *device,
void *conf_data, __u8 lpm) void *conf_data, __u8 lpm)
{ {
char print_path_uid[DASD_UID_STRLEN], print_device_uid[DASD_UID_STRLEN];
struct dasd_eckd_private *private = device->private; struct dasd_eckd_private *private = device->private;
char print_path_uid[60], print_device_uid[60];
struct dasd_conf path_conf; struct dasd_conf path_conf;
path_conf.data = conf_data; path_conf.data = conf_data;
...@@ -1293,9 +1293,9 @@ static void dasd_eckd_path_available_action(struct dasd_device *device, ...@@ -1293,9 +1293,9 @@ static void dasd_eckd_path_available_action(struct dasd_device *device,
__u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE]; __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
__u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm; __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
struct dasd_conf_data *conf_data; struct dasd_conf_data *conf_data;
char print_uid[DASD_UID_STRLEN];
struct dasd_conf path_conf; struct dasd_conf path_conf;
unsigned long flags; unsigned long flags;
char print_uid[60];
int rc, pos; int rc, pos;
opm = 0; opm = 0;
...@@ -5855,8 +5855,8 @@ static void dasd_eckd_dump_sense(struct dasd_device *device, ...@@ -5855,8 +5855,8 @@ static void dasd_eckd_dump_sense(struct dasd_device *device,
static int dasd_eckd_reload_device(struct dasd_device *device) static int dasd_eckd_reload_device(struct dasd_device *device)
{ {
struct dasd_eckd_private *private = device->private; struct dasd_eckd_private *private = device->private;
char print_uid[DASD_UID_STRLEN];
int rc, old_base; int rc, old_base;
char print_uid[60];
struct dasd_uid uid; struct dasd_uid uid;
unsigned long flags; unsigned long flags;
......
...@@ -259,6 +259,10 @@ struct dasd_uid { ...@@ -259,6 +259,10 @@ struct dasd_uid {
char vduit[33]; char vduit[33];
}; };
#define DASD_UID_STRLEN ( /* vendor */ 3 + 1 + /* serial */ 14 + 1 + \
/* SSID */ 4 + 1 + /* unit addr */ 2 + 1 + \
/* vduit */ 32 + 1)
/* /*
* PPRC Status data * PPRC Status data
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment