Commit bc893f74 authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'block-6.7-2023-11-23' of git://git.kernel.dk/linux

Pull block fixes from Jens Axboe:
 "A bit bigger than usual at this time, but nothing really earth
  shattering:

   - NVMe pull request via Keith:
       - TCP TLS fixes (Hannes)
       - Authentifaction fixes (Mark, Hannes)
       - Properly terminate target names (Christoph)

   - MD pull request via Song, fixing a raid5 corruption issue

   - Disentanglement of the dependency mess in nvme introduced with the
     tls additions. Now it should actually build on all configs (Arnd)

   - Series of bcache fixes (Coly)

   - Removal of a dead helper (Damien)

   - s390 dasd fix (Muhammad, Jan)

   - lockdep blk-cgroup fixes (Ming)"

* tag 'block-6.7-2023-11-23' of git://git.kernel.dk/linux: (33 commits)
  nvme: tcp: fix compile-time checks for TLS mode
  nvme: target: fix Kconfig select statements
  nvme: target: fix nvme_keyring_id() references
  nvme: move nvme_stop_keep_alive() back to original position
  nbd: pass nbd_sock to nbd_read_reply() instead of index
  s390/dasd: protect device queue against concurrent access
  s390/dasd: resolve spelling mistake
  block/null_blk: Fix double blk_mq_start_request() warning
  nvmet-tcp: always initialize tls_handshake_tmo_work
  nvmet: nul-terminate the NQNs passed in the connect command
  nvme: blank out authentication fabrics options if not configured
  nvme: catch errors from nvme_configure_metadata()
  nvme-tcp: only evaluate 'tls' option if TLS is selected
  nvme-auth: set explanation code for failure2 msgs
  nvme-auth: unlock mutex in one place only
  block: Remove blk_set_runtime_active()
  nbd: fix null-ptr-dereference while accessing 'nbd->config'
  nbd: factor out a helper to get nbd_config without holding 'config_lock'
  nbd: fold nbd config initialization into nbd_alloc_config()
  bcache: avoid NULL checking to c->root in run_cache_set()
  ...
parents 00444238 0e6c4fe7
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -577,6 +577,7 @@ static void blkg_destroy_all(struct gendisk *disk)
	struct request_queue *q = disk->queue;
	struct blkcg_gq *blkg, *n;
	int count = BLKG_DESTROY_BATCH_SIZE;
	int i;

restart:
	spin_lock_irq(&q->queue_lock);
@@ -602,6 +603,18 @@ static void blkg_destroy_all(struct gendisk *disk)
		}
	}

	/*
	 * Mark policy deactivated since policy offline has been done, and
	 * the free is scheduled, so future blkcg_deactivate_policy() can
	 * be bypassed
	 */
	for (i = 0; i < BLKCG_MAX_POLS; i++) {
		struct blkcg_policy *pol = blkcg_policy[i];

		if (pol)
			__clear_bit(pol->plid, q->blkcg_pols);
	}

	q->root_blkg = NULL;
	spin_unlock_irq(&q->queue_lock);
}
+0 −2
Original line number Diff line number Diff line
@@ -249,8 +249,6 @@ static inline struct blkcg_gq *blkg_lookup(struct blkcg *blkcg,
{
	struct blkcg_gq *blkg;

	WARN_ON_ONCE(!rcu_read_lock_held());

	if (blkcg == &blkcg_root)
		return q->root_blkg;

+5 −28
Original line number Diff line number Diff line
@@ -163,38 +163,15 @@ EXPORT_SYMBOL(blk_pre_runtime_resume);
 * @q: the queue of the device
 *
 * Description:
 *    For historical reasons, this routine merely calls blk_set_runtime_active()
 *    to do the real work of restarting the queue.  It does this regardless of
 *    whether the device's runtime-resume succeeded; even if it failed the
 *    Restart the queue of a runtime suspended device. It does this regardless
 *    of whether the device's runtime-resume succeeded; even if it failed the
 *    driver or error handler will need to communicate with the device.
 *
 *    This function should be called near the end of the device's
 *    runtime_resume callback.
 *    runtime_resume callback to correct queue runtime PM status and re-enable
 *    peeking requests from the queue.
 */
void blk_post_runtime_resume(struct request_queue *q)
{
	blk_set_runtime_active(q);
}
EXPORT_SYMBOL(blk_post_runtime_resume);

/**
 * blk_set_runtime_active - Force runtime status of the queue to be active
 * @q: the queue of the device
 *
 * If the device is left runtime suspended during system suspend the resume
 * hook typically resumes the device and corrects runtime status
 * accordingly. However, that does not affect the queue runtime PM status
 * which is still "suspended". This prevents processing requests from the
 * queue.
 *
 * This function can be used in driver's resume hook to correct queue
 * runtime PM status and re-enable peeking requests from the queue. It
 * should be called before first request is added to the queue.
 *
 * This function is also called by blk_post_runtime_resume() for
 * runtime resumes.  It does everything necessary to restart the queue.
 */
void blk_set_runtime_active(struct request_queue *q)
{
	int old_status;

@@ -211,4 +188,4 @@ void blk_set_runtime_active(struct request_queue *q)
	if (old_status != RPM_ACTIVE)
		blk_clear_pm_only(q);
}
EXPORT_SYMBOL(blk_set_runtime_active);
EXPORT_SYMBOL(blk_post_runtime_resume);
+2 −0
Original line number Diff line number Diff line
@@ -1320,6 +1320,7 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
		   tg_bps_limit(tg, READ), tg_bps_limit(tg, WRITE),
		   tg_iops_limit(tg, READ), tg_iops_limit(tg, WRITE));

	rcu_read_lock();
	/*
	 * Update has_rules[] flags for the updated tg's subtree.  A tg is
	 * considered to have rules if either the tg itself or any of its
@@ -1347,6 +1348,7 @@ static void tg_conf_updated(struct throtl_grp *tg, bool global)
		this_tg->latency_target = max(this_tg->latency_target,
				parent_tg->latency_target);
	}
	rcu_read_unlock();

	/*
	 * We're already holding queue_lock and know @tg is valid.  Let's
+75 −42
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ struct nbd_sock {
struct recv_thread_args {
	struct work_struct work;
	struct nbd_device *nbd;
	struct nbd_sock *nsock;
	int index;
};

@@ -395,6 +396,22 @@ static u32 req_to_nbd_cmd_type(struct request *req)
	}
}

static struct nbd_config *nbd_get_config_unlocked(struct nbd_device *nbd)
{
	if (refcount_inc_not_zero(&nbd->config_refs)) {
		/*
		 * Add smp_mb__after_atomic to ensure that reading nbd->config_refs
		 * and reading nbd->config is ordered. The pair is the barrier in
		 * nbd_alloc_and_init_config(), avoid nbd->config_refs is set
		 * before nbd->config.
		 */
		smp_mb__after_atomic();
		return nbd->config;
	}

	return NULL;
}

static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
{
	struct nbd_cmd *cmd = blk_mq_rq_to_pdu(req);
@@ -409,13 +426,13 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
		return BLK_EH_DONE;
	}

	if (!refcount_inc_not_zero(&nbd->config_refs)) {
	config = nbd_get_config_unlocked(nbd);
	if (!config) {
		cmd->status = BLK_STS_TIMEOUT;
		__clear_bit(NBD_CMD_INFLIGHT, &cmd->flags);
		mutex_unlock(&cmd->lock);
		goto done;
	}
	config = nbd->config;

	if (config->num_connections > 1 ||
	    (config->num_connections == 1 && nbd->tag_set.timeout)) {
@@ -489,15 +506,9 @@ static enum blk_eh_timer_return nbd_xmit_timeout(struct request *req)
	return BLK_EH_DONE;
}

/*
 *  Send or receive packet. Return a positive value on success and
 *  negtive value on failue, and never return 0.
 */
static int sock_xmit(struct nbd_device *nbd, int index, int send,
static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
		       struct iov_iter *iter, int msg_flags, int *sent)
{
	struct nbd_config *config = nbd->config;
	struct socket *sock = config->socks[index]->sock;
	int result;
	struct msghdr msg;
	unsigned int noreclaim_flag;
@@ -540,6 +551,19 @@ static int sock_xmit(struct nbd_device *nbd, int index, int send,
	return result;
}

/*
 *  Send or receive packet. Return a positive value on success and
 *  negtive value on failure, and never return 0.
 */
static int sock_xmit(struct nbd_device *nbd, int index, int send,
		     struct iov_iter *iter, int msg_flags, int *sent)
{
	struct nbd_config *config = nbd->config;
	struct socket *sock = config->socks[index]->sock;

	return __sock_xmit(nbd, sock, send, iter, msg_flags, sent);
}

/*
 * Different settings for sk->sk_sndtimeo can result in different return values
 * if there is a signal pending when we enter sendmsg, because reasons?
@@ -696,7 +720,7 @@ static int nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd, int index)
	return 0;
}

static int nbd_read_reply(struct nbd_device *nbd, int index,
static int nbd_read_reply(struct nbd_device *nbd, struct socket *sock,
			  struct nbd_reply *reply)
{
	struct kvec iov = {.iov_base = reply, .iov_len = sizeof(*reply)};
@@ -705,7 +729,7 @@ static int nbd_read_reply(struct nbd_device *nbd, int index,

	reply->magic = 0;
	iov_iter_kvec(&to, ITER_DEST, &iov, 1, sizeof(*reply));
	result = sock_xmit(nbd, index, 0, &to, MSG_WAITALL, NULL);
	result = __sock_xmit(nbd, sock, 0, &to, MSG_WAITALL, NULL);
	if (result < 0) {
		if (!nbd_disconnected(nbd->config))
			dev_err(disk_to_dev(nbd->disk),
@@ -829,14 +853,14 @@ static void recv_work(struct work_struct *work)
	struct nbd_device *nbd = args->nbd;
	struct nbd_config *config = nbd->config;
	struct request_queue *q = nbd->disk->queue;
	struct nbd_sock *nsock;
	struct nbd_sock *nsock = args->nsock;
	struct nbd_cmd *cmd;
	struct request *rq;

	while (1) {
		struct nbd_reply reply;

		if (nbd_read_reply(nbd, args->index, &reply))
		if (nbd_read_reply(nbd, nsock->sock, &reply))
			break;

		/*
@@ -871,7 +895,6 @@ static void recv_work(struct work_struct *work)
		percpu_ref_put(&q->q_usage_counter);
	}

	nsock = config->socks[args->index];
	mutex_lock(&nsock->tx_lock);
	nbd_mark_nsock_dead(nbd, nsock, 1);
	mutex_unlock(&nsock->tx_lock);
@@ -977,12 +1000,12 @@ static int nbd_handle_cmd(struct nbd_cmd *cmd, int index)
	struct nbd_sock *nsock;
	int ret;

	if (!refcount_inc_not_zero(&nbd->config_refs)) {
	config = nbd_get_config_unlocked(nbd);
	if (!config) {
		dev_err_ratelimited(disk_to_dev(nbd->disk),
				    "Socks array is empty\n");
		return -EINVAL;
	}
	config = nbd->config;

	if (index >= config->num_connections) {
		dev_err_ratelimited(disk_to_dev(nbd->disk),
@@ -1215,6 +1238,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
		INIT_WORK(&args->work, recv_work);
		args->index = i;
		args->nbd = nbd;
		args->nsock = nsock;
		nsock->cookie++;
		mutex_unlock(&nsock->tx_lock);
		sockfd_put(old);
@@ -1397,6 +1421,7 @@ static int nbd_start_device(struct nbd_device *nbd)
		refcount_inc(&nbd->config_refs);
		INIT_WORK(&args->work, recv_work);
		args->nbd = nbd;
		args->nsock = config->socks[i];
		args->index = i;
		queue_work(nbd->recv_workq, &args->work);
	}
@@ -1530,17 +1555,20 @@ static int nbd_ioctl(struct block_device *bdev, blk_mode_t mode,
	return error;
}

static struct nbd_config *nbd_alloc_config(void)
static int nbd_alloc_and_init_config(struct nbd_device *nbd)
{
	struct nbd_config *config;

	if (WARN_ON(nbd->config))
		return -EINVAL;

	if (!try_module_get(THIS_MODULE))
		return ERR_PTR(-ENODEV);
		return -ENODEV;

	config = kzalloc(sizeof(struct nbd_config), GFP_NOFS);
	if (!config) {
		module_put(THIS_MODULE);
		return ERR_PTR(-ENOMEM);
		return -ENOMEM;
	}

	atomic_set(&config->recv_threads, 0);
@@ -1548,12 +1576,24 @@ static struct nbd_config *nbd_alloc_config(void)
	init_waitqueue_head(&config->conn_wait);
	config->blksize_bits = NBD_DEF_BLKSIZE_BITS;
	atomic_set(&config->live_connections, 0);
	return config;

	nbd->config = config;
	/*
	 * Order refcount_set(&nbd->config_refs, 1) and nbd->config assignment,
	 * its pair is the barrier in nbd_get_config_unlocked().
	 * So nbd_get_config_unlocked() won't see nbd->config as null after
	 * refcount_inc_not_zero() succeed.
	 */
	smp_mb__before_atomic();
	refcount_set(&nbd->config_refs, 1);

	return 0;
}

static int nbd_open(struct gendisk *disk, blk_mode_t mode)
{
	struct nbd_device *nbd;
	struct nbd_config *config;
	int ret = 0;

	mutex_lock(&nbd_index_mutex);
@@ -1566,27 +1606,25 @@ static int nbd_open(struct gendisk *disk, blk_mode_t mode)
		ret = -ENXIO;
		goto out;
	}
	if (!refcount_inc_not_zero(&nbd->config_refs)) {
		struct nbd_config *config;

	config = nbd_get_config_unlocked(nbd);
	if (!config) {
		mutex_lock(&nbd->config_lock);
		if (refcount_inc_not_zero(&nbd->config_refs)) {
			mutex_unlock(&nbd->config_lock);
			goto out;
		}
		config = nbd_alloc_config();
		if (IS_ERR(config)) {
			ret = PTR_ERR(config);
		ret = nbd_alloc_and_init_config(nbd);
		if (ret) {
			mutex_unlock(&nbd->config_lock);
			goto out;
		}
		nbd->config = config;
		refcount_set(&nbd->config_refs, 1);

		refcount_inc(&nbd->refs);
		mutex_unlock(&nbd->config_lock);
		if (max_part)
			set_bit(GD_NEED_PART_SCAN, &disk->state);
	} else if (nbd_disconnected(nbd->config)) {
	} else if (nbd_disconnected(config)) {
		if (max_part)
			set_bit(GD_NEED_PART_SCAN, &disk->state);
	}
@@ -1990,22 +2028,17 @@ static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
		pr_err("nbd%d already in use\n", index);
		return -EBUSY;
	}
	if (WARN_ON(nbd->config)) {
		mutex_unlock(&nbd->config_lock);
		nbd_put(nbd);
		return -EINVAL;
	}
	config = nbd_alloc_config();
	if (IS_ERR(config)) {

	ret = nbd_alloc_and_init_config(nbd);
	if (ret) {
		mutex_unlock(&nbd->config_lock);
		nbd_put(nbd);
		pr_err("couldn't allocate config\n");
		return PTR_ERR(config);
		return ret;
	}
	nbd->config = config;
	refcount_set(&nbd->config_refs, 1);
	set_bit(NBD_RT_BOUND, &config->runtime_flags);

	config = nbd->config;
	set_bit(NBD_RT_BOUND, &config->runtime_flags);
	ret = nbd_genl_size_set(info, nbd);
	if (ret)
		goto out;
@@ -2208,7 +2241,8 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
	}
	mutex_unlock(&nbd_index_mutex);

	if (!refcount_inc_not_zero(&nbd->config_refs)) {
	config = nbd_get_config_unlocked(nbd);
	if (!config) {
		dev_err(nbd_to_dev(nbd),
			"not configured, cannot reconfigure\n");
		nbd_put(nbd);
@@ -2216,7 +2250,6 @@ static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
	}

	mutex_lock(&nbd->config_lock);
	config = nbd->config;
	if (!test_bit(NBD_RT_BOUND, &config->runtime_flags) ||
	    !nbd->pid) {
		dev_err(nbd_to_dev(nbd),
Loading