From patchwork Mon Feb 17 21:08:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11387593 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5B14138D for ; Mon, 17 Feb 2020 21:08:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 96D2620801 for ; Mon, 17 Feb 2020 21:08:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729468AbgBQVIs (ORCPT ); Mon, 17 Feb 2020 16:08:48 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:40993 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgBQVIs (ORCPT ); Mon, 17 Feb 2020 16:08:48 -0500 Received: by mail-pl1-f193.google.com with SMTP id t14so7202631plr.8 for ; Mon, 17 Feb 2020 13:08:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lzxine3G1GCtDYs+i7zBL+3PmcTRWigNPPzWowk8ylI=; b=CbK1E1DWl5d3OipljFSTGT7N9zWrEsgwnGgA6mRo4iA3dc6aEmvEe8R0lWGq4O5mPt OMqSGfDfA7rI7ZiajFaURWTCvgKMtjiBd8XNoJbLCkOQDn35YW7hI+3nfL3QMaAAiYEt MJQIdsKZnZjjAGGJzv2+VlKUFNpdxZiJtDMCg1KSO/3ucYetj3RndziFnyAt17Ws1KuJ Ww52v5CVvUWcID1O3QeHeBr6IK0n+tLGn4f7DVcnBbupi41HZOiDPIHRxB/Ew2uKn9ZX Lyj1CdqS0JWfu/dC3qRWh4E34W/dN/nI8SqoiMTl+FySPY/9fSo9rcVc1njvuiI/mcHM weRQ== X-Gm-Message-State: APjAAAVFfpH2Dja8b3KC37/WpgUdbRksCihdvDpi7ezC4olWgUZGpA9B KKjfYjntsVbfQMwTDMoWp7PyQTsDWtQ= X-Google-Smtp-Source: APXvYqz2uwh7HwnDwGQ2jQxdl4c8W6BEFFHne1Lw/k9RspUQPAFzjQzHF/jvNnlQocZf6uteMzxaOw== X-Received: by 2002:a17:90a:b10a:: with SMTP id z10mr1068662pjq.115.1581973727263; Mon, 17 Feb 2020 13:08:47 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:2474:e036:5bee:ca5b]) by smtp.gmail.com with ESMTPSA id h13sm362952pjc.9.2020.02.17.13.08.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:08:46 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , =?utf-8?q?Andr=C3=A9_Almeida?= Subject: [PATCH 1/5] blk-mq: Fix a comment in include/linux/blk-mq.h Date: Mon, 17 Feb 2020 13:08:35 -0800 Message-Id: <20200217210839.28535-2-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217210839.28535-1-bvanassche@acm.org> References: <20200217210839.28535-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org The 'hctx_list' member of struct blk_mq_hw_ctx is not a list head but instead an entry in q->unused_hctx_list. Fix the comment above this struct member. Cc: André Almeida Fixes: d386732bc142 ("blk-mq: fill header with kernel-doc") Signed-off-by: Bart Van Assche --- include/linux/blk-mq.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index 11cfd6470b1a..31344d5f83e2 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -162,7 +162,10 @@ struct blk_mq_hw_ctx { struct dentry *sched_debugfs_dir; #endif - /** @hctx_list: List of all hardware queues. */ + /** + * @hctx_list: if this hctx is not in use, this is an entry in + * q->unused_hctx_list. + */ struct list_head hctx_list; /** From patchwork Mon Feb 17 21:08:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11387595 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D433924 for ; Mon, 17 Feb 2020 21:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2299220725 for ; Mon, 17 Feb 2020 21:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729880AbgBQVIt (ORCPT ); Mon, 17 Feb 2020 16:08:49 -0500 Received: from mail-pg1-f193.google.com ([209.85.215.193]:42611 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgBQVIt (ORCPT ); Mon, 17 Feb 2020 16:08:49 -0500 Received: by mail-pg1-f193.google.com with SMTP id w21so9841566pgl.9 for ; Mon, 17 Feb 2020 13:08:49 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aK4Z7Mphg//NDzdiVLvRspVvZVPkLnrr8/rXfxsJ5jE=; b=tBLai4A6Hz6JaNTfyKxoS2inXzbyY6UHr9OrVFCE7I5O01gemVNwwyqymdj27RxzAt IEdZ46XcUo6O9Z5SLBAe3IlYDkwvHo2AVKxWxVcKlWHHMhoRuMYu2O5g0dbkfKmWJ9UP YTdiMWoK/1ULSWI4COCq6MwwaLjaav5tOy5QyMach3S2BlPQD0orcJe2361aC1NqZ1Ga x/Db7v42yegqluq3Gy2Hny1/T7T8n49t4S2QE4qntAZRzQ4isFEMMgqSIoIIToLQuId+ wK/lo4UsqlSTR4Yvxm/9KlEY3LLA5E7Ge/XkViXJz8nPE59iG3vBtbTktqL87+tIrK45 3ijQ== X-Gm-Message-State: APjAAAW4uBaysmY8qvukY0ASEDwm86HHLSuXmismgWvwly0vTMuV4IB9 aqcbnJupnjzb5cVah2ikaXI= X-Google-Smtp-Source: APXvYqz5+YhjVWzaE5NgL89NIMi5sANVlxfQH6j/JruIRPuq717GE+Qhnobdvni4iYQCPon2/LSJVQ== X-Received: by 2002:a63:7d59:: with SMTP id m25mr18751720pgn.356.1581973728770; Mon, 17 Feb 2020 13:08:48 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:2474:e036:5bee:ca5b]) by smtp.gmail.com with ESMTPSA id h13sm362952pjc.9.2020.02.17.13.08.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:08:47 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn , syzbot+d44e1b26ce5c3e77458d@syzkaller.appspotmail.com Subject: [PATCH 2/5] blk-mq: Keep set->nr_hw_queues and set->map[].nr_queues in sync Date: Mon, 17 Feb 2020 13:08:36 -0800 Message-Id: <20200217210839.28535-3-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217210839.28535-1-bvanassche@acm.org> References: <20200217210839.28535-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This patch fixes the following kernel warning: WARNING: CPU: 0 PID: 2501 at include/linux/cpumask.h:137 Call Trace: blk_mq_run_hw_queue+0x19d/0x350 block/blk-mq.c:1508 blk_mq_run_hw_queues+0x112/0x1a0 block/blk-mq.c:1525 blk_mq_requeue_work+0x502/0x780 block/blk-mq.c:775 process_one_work+0x9af/0x1740 kernel/workqueue.c:2269 worker_thread+0x98/0xe40 kernel/workqueue.c:2415 kthread+0x361/0x430 kernel/kthread.c:255 Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Reported-by: syzbot+d44e1b26ce5c3e77458d@syzkaller.appspotmail.com Fixes: ed76e329d74a ("blk-mq: abstract out queue map") # v5.0 Signed-off-by: Bart Van Assche --- block/blk-mq.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index f298500e6dda..2b9f490f5a64 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3050,6 +3050,16 @@ static int blk_mq_update_queue_map(struct blk_mq_tag_set *set) } } +static void blk_mq_set_nr_hw_queues(struct blk_mq_tag_set *set, + int new_nr_hw_queues) +{ + int i; + + set->nr_hw_queues = new_nr_hw_queues; + for (i = 0; i < set->nr_maps; i++) + set->map[i].nr_queues = new_nr_hw_queues; +} + static int blk_mq_realloc_tag_set_tags(struct blk_mq_tag_set *set, int cur_nr_hw_queues, int new_nr_hw_queues) { @@ -3068,7 +3078,7 @@ static int blk_mq_realloc_tag_set_tags(struct blk_mq_tag_set *set, sizeof(*set->tags)); kfree(set->tags); set->tags = new_tags; - set->nr_hw_queues = new_nr_hw_queues; + blk_mq_set_nr_hw_queues(set, new_nr_hw_queues); return 0; } @@ -3330,7 +3340,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, goto reregister; prev_nr_hw_queues = set->nr_hw_queues; - set->nr_hw_queues = nr_hw_queues; + blk_mq_set_nr_hw_queues(set, nr_hw_queues); blk_mq_update_queue_map(set); fallback: list_for_each_entry(q, &set->tag_list, tag_set_list) { @@ -3338,7 +3348,7 @@ static void __blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, if (q->nr_hw_queues != set->nr_hw_queues) { pr_warn("Increasing nr_hw_queues to %d fails, fallback to %d\n", nr_hw_queues, prev_nr_hw_queues); - set->nr_hw_queues = prev_nr_hw_queues; + blk_mq_set_nr_hw_queues(set, prev_nr_hw_queues); blk_mq_map_queues(&set->map[HCTX_TYPE_DEFAULT]); goto fallback; } From patchwork Mon Feb 17 21:08:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11387597 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B325D138D for ; Mon, 17 Feb 2020 21:08:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E636208C4 for ; Mon, 17 Feb 2020 21:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729881AbgBQVIv (ORCPT ); Mon, 17 Feb 2020 16:08:51 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33376 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgBQVIv (ORCPT ); Mon, 17 Feb 2020 16:08:51 -0500 Received: by mail-pf1-f193.google.com with SMTP id n7so9544970pfn.0 for ; Mon, 17 Feb 2020 13:08:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nm1uikhWNlAKb3TDjKxNmMKyI+HvYEOE+5FD96oknrE=; b=EGsqr1FHnNpUU4WdEQ72jCmKdcbpOtI5GtpTmxNaGIaT1JSEoDFsdTBQqBpxrHnYO2 2R4BODpAfa5yL2wx8Y+grm9u6RRYb2DHoYUvKnZVWzhdnUH2ZfyhINfqBRRTmU04vW29 9QUVhEinySPXfODuvzs8FYrL/jTHooEOeXHnhAhNmuVbDj+hybvE+6/YV10DBzdh4b/y eXuP4cO6yp4O9g7oWrsa8rieonsT7JUH6MqW+hdLbMPoa97T0UdoaBV8Kp43Fpj/GxxF +1b1Z/neqg8nBNV9J5IysDoZ4pcwpVxGcAQeyErCSYmqmcx/hMFeN9sxuMhC+1KGtk9Q uqgQ== X-Gm-Message-State: APjAAAV4E2lbv1IjaiHUqDXeksdvrYqxtttcE6anohlQ59YCeKphQDAe e2c+1f0uhYwev4fko2ERX34= X-Google-Smtp-Source: APXvYqwjCdFjvRhJFpTvSUTYPWmjQwZTAbke+p6ziOc7ZLHRTQ21I3FxeFzTFKgGI1wd4qIP24irKw== X-Received: by 2002:a62:18c9:: with SMTP id 192mr17956578pfy.117.1581973730295; Mon, 17 Feb 2020 13:08:50 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:2474:e036:5bee:ca5b]) by smtp.gmail.com with ESMTPSA id h13sm362952pjc.9.2020.02.17.13.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:08:49 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn , Keith Busch Subject: [PATCH 3/5] blk-mq: Fix a recently introduced regression in blk_mq_realloc_hw_ctxs() Date: Mon, 17 Feb 2020 13:08:37 -0800 Message-Id: <20200217210839.28535-4-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217210839.28535-1-bvanassche@acm.org> References: <20200217210839.28535-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org q->nr_hw_queues must only be updated once it is known that blk_mq_realloc_hw_ctxs() has succeeded. Otherwise it can happen that reallocation fails and that q->nr_hw_queues is larger than the number of allocated hardware queues. This patch fixes the following crash if increasing the number of hardware queues fails: BUG: KASAN: null-ptr-deref in blk_mq_map_swqueue+0x775/0x810 Write of size 8 at addr 0000000000000118 by task check/977 CPU: 3 PID: 977 Comm: check Not tainted 5.6.0-rc1-dbg+ #8 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 Call Trace: dump_stack+0xa5/0xe6 __kasan_report.cold+0x65/0x99 kasan_report+0x16/0x20 check_memory_region+0x140/0x1b0 memset+0x28/0x40 blk_mq_map_swqueue+0x775/0x810 blk_mq_update_nr_hw_queues+0x468/0x710 nullb_device_submit_queues_store+0xf7/0x1a0 [null_blk] configfs_write_file+0x1c4/0x250 [configfs] __vfs_write+0x4c/0x90 vfs_write+0x145/0x2c0 ksys_write+0xd7/0x180 __x64_sys_write+0x47/0x50 do_syscall_64+0x6f/0x2f0 entry_SYSCALL_64_after_hwframe+0x49/0xbe Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Cc: Keith Busch Fixes: ac0d6b926e74 ("block: Reduce the amount of memory required per request queue") Signed-off-by: Bart Van Assche Reviewed-by: Ming Lei --- block/blk-mq.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 2b9f490f5a64..5408098b58f2 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -2824,7 +2824,6 @@ static void blk_mq_realloc_hw_ctxs(struct blk_mq_tag_set *set, memcpy(new_hctxs, hctxs, q->nr_hw_queues * sizeof(*hctxs)); q->queue_hw_ctx = new_hctxs; - q->nr_hw_queues = set->nr_hw_queues; kfree(hctxs); hctxs = new_hctxs; } From patchwork Mon Feb 17 21:08:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11387599 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EEF17138D for ; Mon, 17 Feb 2020 21:08:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D8DB1207FD for ; Mon, 17 Feb 2020 21:08:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728935AbgBQVIx (ORCPT ); Mon, 17 Feb 2020 16:08:53 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:35512 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgBQVIx (ORCPT ); Mon, 17 Feb 2020 16:08:53 -0500 Received: by mail-pg1-f194.google.com with SMTP id v23so6455624pgk.2 for ; Mon, 17 Feb 2020 13:08:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bPzWNOjv3O7tUoM8pshITUVi9l0rQND6jwW8+Nd1kEc=; b=US1LP4tL/GkSBJsyyg/Pg5ekeJfrcYEtn1+RgndRgBOhiO4T9MHMQm1jUTBl+JQYDr lHFGhTJBAHM3HuRCl80undi8hIG+/Ljd+H9U30HqfyPbJp1rDMjAjmWiourx1ASZt+N/ KM8Clym0LJuez5Loz9XRmtqE7tG4EITz4X7tU36jto7OUskfBOJwYbePxk8qaa7V42Jt I1PfSrCoVf2693mF2Rd29DYJMI1ZXrqK3mKiMZeQwQ9QzwoBCOPgd87dAAaXnMog8RYb i894OGP2vZxKR/YT0d/JR9ee1caXtTtZuCS6KR2m1TFQODJQ39pTMEDobMeEBrdFchX1 knlw== X-Gm-Message-State: APjAAAXKUnXne74PfVmWAgyT0pY8/e7CPEF+bVr5eySyr+yJITZsVsWi GdrgRLRnfMygC960P1pjukARiWgJpzg= X-Google-Smtp-Source: APXvYqwWtGAZeqHaOzpc2iYCYFwKEQIsVCCf1+hiZevwYMbDE1w/IwowOP5OUGjgbDKNK1bSq0DbAg== X-Received: by 2002:a63:fb57:: with SMTP id w23mr19102585pgj.231.1581973731785; Mon, 17 Feb 2020 13:08:51 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:2474:e036:5bee:ca5b]) by smtp.gmail.com with ESMTPSA id h13sm362952pjc.9.2020.02.17.13.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:08:51 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 4/5] null_blk: Suppress an UBSAN complaint triggered when setting 'memory_backed' Date: Mon, 17 Feb 2020 13:08:38 -0800 Message-Id: <20200217210839.28535-5-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217210839.28535-1-bvanassche@acm.org> References: <20200217210839.28535-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Although it is not clear to me why UBSAN complains when 'memory_backed' is set, this patch suppresses the UBSAN complaint that is triggered when setting that configfs attribute. UBSAN: Undefined behaviour in drivers/block/null_blk_main.c:327:1 load of value 16 is not a valid value for type '_Bool' CPU: 2 PID: 8396 Comm: check Not tainted 5.6.0-rc1-dbg+ #14 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011 Call Trace: dump_stack+0xa5/0xe6 ubsan_epilogue+0x9/0x26 __ubsan_handle_load_invalid_value+0x6d/0x76 nullb_device_memory_backed_store.cold+0x2c/0x38 [null_blk] configfs_write_file+0x1c4/0x250 [configfs] __vfs_write+0x4c/0x90 vfs_write+0x145/0x2c0 ksys_write+0xd7/0x180 __x64_sys_write+0x47/0x50 do_syscall_64+0x6f/0x2f0 entry_SYSCALL_64_after_hwframe+0x49/0xbe Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Signed-off-by: Bart Van Assche --- drivers/block/null_blk_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 16510795e377..7cd31d4ef709 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -276,7 +276,7 @@ nullb_device_##NAME##_store(struct config_item *item, const char *page, \ { \ int (*apply_fn)(struct nullb_device *dev, TYPE new_value) = APPLY;\ struct nullb_device *dev = to_nullb_device(item); \ - TYPE uninitialized_var(new_value); \ + TYPE new_value = 0; \ int ret; \ \ ret = nullb_device_##TYPE##_attr_store(&new_value, page, count);\ From patchwork Mon Feb 17 21:08:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 11387601 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3969D924 for ; Mon, 17 Feb 2020 21:08:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1ACBA20801 for ; Mon, 17 Feb 2020 21:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729888AbgBQVIz (ORCPT ); Mon, 17 Feb 2020 16:08:55 -0500 Received: from mail-pj1-f66.google.com ([209.85.216.66]:40790 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728444AbgBQVIz (ORCPT ); Mon, 17 Feb 2020 16:08:55 -0500 Received: by mail-pj1-f66.google.com with SMTP id 12so53419pjb.5 for ; Mon, 17 Feb 2020 13:08:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nQz+s9/NC7dIiY7glYySFYWS0V805f2KdP7BLEhNNbM=; b=G8Q17RKF3HcO2jJ9v+Niqk550r42AjCLxFRhA0Mr+ZzCeGTO90zYfD3OlUVZ6+mcez Y8M3xBqEynWVEAzqzdce2+FzjrcuqkkXXb6tYfPGv4jgHGVVY0WoPKllp0c06NbF4c+j qUfME8PxFnYB3y7qR1jIhKZDlRUsx/XrThDxQH/FayHjBq7fqs9dF2syLKXiBDy+JcrN sN1Rd0PjE/lXRTbA4TTXjcWTIRVXoSyTSJcZmlz80o4JCjYELySXXsXAxu9IwLIV3JT8 hplaorRrjpRX7M/zbywvTQidBtk7CM2k1xpCHvsv2nVPB+bO2LHx/PUF1F4OF213+jVU 9u8w== X-Gm-Message-State: APjAAAUOJBqzpIav7yC7s3br8yamzdCmNwP9ZGJVPULlOKGZaOgkptFR MQLuOt51H0zJo0hk5f1Pqpg= X-Google-Smtp-Source: APXvYqxGtwLrAv+LExw8nYr28VwHN7EQ7Xv+yyQyQtjOzLTuv8hMwg4J/d+VRjV/5moM9kJqiAZPxQ== X-Received: by 2002:a17:902:8545:: with SMTP id d5mr16890033plo.116.1581973733097; Mon, 17 Feb 2020 13:08:53 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:2474:e036:5bee:ca5b]) by smtp.gmail.com with ESMTPSA id h13sm362952pjc.9.2020.02.17.13.08.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2020 13:08:52 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Christoph Hellwig , Ming Lei , Hannes Reinecke , Johannes Thumshirn Subject: [PATCH 5/5] null_blk: Fix changing the number of hardware queues Date: Mon, 17 Feb 2020 13:08:39 -0800 Message-Id: <20200217210839.28535-6-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200217210839.28535-1-bvanassche@acm.org> References: <20200217210839.28535-1-bvanassche@acm.org> MIME-Version: 1.0 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Instead of initializing null_blk hardware queues explicitly after the request queue has been created, provide .init_hctx() and .exit_hctx() callback functions. The latter functions are not only called during request queue allocation but also when the number of hardware queues changes. Allocate nr_cpu_ids queues during initialization to support increasing the number of hardware queues above the initial hardware queue count. This change fixes increasing the number of hardware queues above the initial number of hardware queues and also keeps nullb->nr_queues in sync with the number of hardware queues. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Fixes: 45919fbfe1c4 ("null_blk: Enable modifying 'submit_queues' after an instance has been configured") Signed-off-by: Bart Van Assche --- drivers/block/null_blk_main.c | 103 ++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 37 deletions(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 7cd31d4ef709..31678c9af43f 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -302,6 +302,12 @@ static int nullb_apply_submit_queues(struct nullb_device *dev, if (!nullb) return 0; + /* + * Make sure that null_init_hctx() does not access nullb->queues[] past + * the end of that array. + */ + if (submit_queues > nr_cpu_ids) + return -EINVAL; set = nullb->tag_set; blk_mq_update_nr_hw_queues(set, submit_queues); return set->nr_hw_queues == submit_queues ? 0 : -ENOMEM; @@ -1408,12 +1414,6 @@ static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx, return null_handle_cmd(cmd, sector, nr_sectors, req_op(bd->rq)); } -static const struct blk_mq_ops null_mq_ops = { - .queue_rq = null_queue_rq, - .complete = null_complete_rq, - .timeout = null_timeout_rq, -}; - static void cleanup_queue(struct nullb_queue *nq) { kfree(nq->tag_map); @@ -1430,6 +1430,43 @@ static void cleanup_queues(struct nullb *nullb) kfree(nullb->queues); } +static void null_exit_hctx(struct blk_mq_hw_ctx *hctx, unsigned int hctx_idx) +{ + struct nullb_queue *nq = hctx->driver_data; + struct nullb *nullb = nq->dev->nullb; + + nullb->nr_queues--; +} + +static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq) +{ + init_waitqueue_head(&nq->wait); + nq->queue_depth = nullb->queue_depth; + nq->dev = nullb->dev; +} + +static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *driver_data, + unsigned int hctx_idx) +{ + struct nullb *nullb = hctx->queue->queuedata; + struct nullb_queue *nq; + + nq = &nullb->queues[hctx_idx]; + hctx->driver_data = nq; + null_init_queue(nullb, nq); + nullb->nr_queues++; + + return 0; +} + +static const struct blk_mq_ops null_mq_ops = { + .queue_rq = null_queue_rq, + .complete = null_complete_rq, + .timeout = null_timeout_rq, + .init_hctx = null_init_hctx, + .exit_hctx = null_exit_hctx, +}; + static void null_del_dev(struct nullb *nullb) { struct nullb_device *dev = nullb->dev; @@ -1473,33 +1510,6 @@ static const struct block_device_operations null_ops = { .report_zones = null_report_zones, }; -static void null_init_queue(struct nullb *nullb, struct nullb_queue *nq) -{ - BUG_ON(!nullb); - BUG_ON(!nq); - - init_waitqueue_head(&nq->wait); - nq->queue_depth = nullb->queue_depth; - nq->dev = nullb->dev; -} - -static void null_init_queues(struct nullb *nullb) -{ - struct request_queue *q = nullb->q; - struct blk_mq_hw_ctx *hctx; - struct nullb_queue *nq; - int i; - - queue_for_each_hw_ctx(q, hctx, i) { - if (!hctx->nr_ctx || !hctx->tags) - continue; - nq = &nullb->queues[i]; - hctx->driver_data = nq; - null_init_queue(nullb, nq); - nullb->nr_queues++; - } -} - static int setup_commands(struct nullb_queue *nq) { struct nullb_cmd *cmd; @@ -1528,8 +1538,7 @@ static int setup_commands(struct nullb_queue *nq) static int setup_queues(struct nullb *nullb) { - nullb->queues = kcalloc(nullb->dev->submit_queues, - sizeof(struct nullb_queue), + nullb->queues = kcalloc(nr_cpu_ids, sizeof(struct nullb_queue), GFP_KERNEL); if (!nullb->queues) return -ENOMEM; @@ -1675,6 +1684,27 @@ static bool null_setup_fault(void) return true; } +/* + * This function is identical to blk_mq_init_queue() except that it sets + * queuedata before .init_hctx is called. + */ +static struct request_queue *nullb_alloc_queue(struct nullb *nullb) +{ + struct request_queue *uninit_q, *q; + struct blk_mq_tag_set *set = nullb->tag_set; + + uninit_q = blk_alloc_queue_node(GFP_KERNEL, set->numa_node); + if (!uninit_q) + return ERR_PTR(-ENOMEM); + + uninit_q->queuedata = nullb; + q = blk_mq_init_allocated_queue(set, uninit_q, false); + if (IS_ERR(q)) + blk_cleanup_queue(uninit_q); + + return q; +} + static int null_add_dev(struct nullb_device *dev) { struct nullb *nullb; @@ -1714,12 +1744,11 @@ static int null_add_dev(struct nullb_device *dev) goto out_cleanup_queues; nullb->tag_set->timeout = 5 * HZ; - nullb->q = blk_mq_init_queue(nullb->tag_set); + nullb->q = nullb_alloc_queue(nullb); if (IS_ERR(nullb->q)) { rv = -ENOMEM; goto out_cleanup_tags; } - null_init_queues(nullb); } else if (dev->queue_mode == NULL_Q_BIO) { nullb->q = blk_alloc_queue_node(GFP_KERNEL, dev->home_node); if (!nullb->q) {