Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <linux/blk-mq.h>
#include <linux/spinlock.h>
#include <uapi/linux/loop.h>
#include <linux/stacktrace.h>

/* Possible states of device */
enum {
Expand Down Expand Up @@ -86,6 +87,12 @@ struct loop_cmd {
struct bio_vec *bvec;
struct cgroup_subsys_state *blkcg_css;
struct cgroup_subsys_state *memcg_css;
#if defined(CONFIG_KCOV) && defined(CONFIG_STACKTRACE)
unsigned long stack_entries[30];
int stack_nr;
pid_t pid;
char comm[TASK_COMM_LEN];
#endif
};

#define LOOP_IDLE_WORKER_TIMEOUT (60 * HZ)
Expand Down Expand Up @@ -1808,6 +1815,13 @@ static blk_status_t loop_queue_rq(struct blk_mq_hw_ctx *hctx,
#endif
}
#endif

#if defined(CONFIG_KCOV) && defined(CONFIG_STACKTRACE)
cmd->stack_nr = stack_trace_save(cmd->stack_entries, ARRAY_SIZE(cmd->stack_entries), 0);
cmd->pid = current->pid;
get_task_comm(cmd->comm, current);
#endif

loop_queue_work(lo, cmd);

return BLK_STS_OK;
Expand All @@ -1823,6 +1837,21 @@ static void loop_handle_cmd(struct loop_cmd *cmd)
int ret = 0;
struct mem_cgroup *old_memcg = NULL;

#if defined(CONFIG_KCOV) && defined(CONFIG_STACKTRACE)
/*
* This request was queued after checking lo->lo_state == Lo_bound
* in loop_queue_rq(). The state should remain unchanged unless
* __loop_clr_fd() by error starts before blk_mq_complete_request()
* is called.
*/
if (unlikely(data_race(READ_ONCE(lo->lo_state)) != Lo_bound &&
disk_openers(lo->lo_disk) == 0)) {
pr_err("BUG: found I/O issued by %s/%u but loop%d is no longer bound.\n",
cmd->comm, cmd->pid, lo->lo_number);
printk("Call Trace:\n");
stack_trace_print(cmd->stack_entries, cmd->stack_nr, 4);
}
#endif
if (write && (lo->lo_flags & LO_FLAGS_READ_ONLY)) {
ret = -EIO;
goto failed;
Expand Down
Loading