From patchwork Thu Feb 20 02:44:35 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: 11393081 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 79D42138D for ; Thu, 20 Feb 2020 02:44:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6373B21D56 for ; Thu, 20 Feb 2020 02:44:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbgBTCou (ORCPT ); Wed, 19 Feb 2020 21:44:50 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:46466 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbgBTCou (ORCPT ); Wed, 19 Feb 2020 21:44:50 -0500 Received: by mail-pg1-f196.google.com with SMTP id y30so1129811pga.13 for ; Wed, 19 Feb 2020 18:44: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=5m6ZyW02AM7svaF7KIyDHbzAfYKA5zVKeqe99DoBEhc=; b=qn1clfdS4aWzbd0XAM5I5Is73jQYhg2EeY+V/xrKzpl6g36JECtjoLlMFcBK2vFcdK ALb31DcVcfzGkv7tNmBmvkdRu5XQv2v8Cph9RMge09QFtO4nUymRWKVZ+fjiz737H4v9 5GyLJH2rGZP3Hs/bI1OfCecZNvlhaGne9BaW/2BGCKEw3SpK+2dtQHERVg+rVV7I+GIO gMmnb7XjMtnPUh6Yg787oqopxr3oVOFGnhjawagWpX6Bv7qCbAIagYKpjN97aAvmfs3w Dloq9k1xMZmsw5xlxRYaX+ffxdUvOfdIzEVncudPhqEO4dEbdAyym1V9cZUo3obzkNPg M0cw== X-Gm-Message-State: APjAAAVaCJRrVrruNvJN1yw/8bJIzzPQsI9dVvmhyp5QJ6vJ475D1/ba I/AfIlGoBbQJhtd9cQD2l/4= X-Google-Smtp-Source: APXvYqxxBpZ4Q0wcS24E+iWz87NRPKfSYuAUld9+Met8+cK2s5G4RyyXRyuoMAlOdlOKYfrHi+WLJA== X-Received: by 2002:a63:7802:: with SMTP id t2mr29922490pgc.352.1582166689925; Wed, 19 Feb 2020 18:44:49 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44: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 , syzbot+d44e1b26ce5c3e77458d@syzkaller.appspotmail.com Subject: [PATCH v2 2/8] blk-mq: Keep set->nr_hw_queues and set->map[].nr_queues in sync Date: Wed, 19 Feb 2020 18:44:35 -0800 Message-Id: <20200220024441.11558-3-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 blk_mq_map_queues() and multiple .map_queues() implementations expect that set->map[HCTX_TYPE_DEFAULT].nr_queues is set to the number of hardware queues. Hence set .nr_queues before calling these functions. 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 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/blk-mq.c b/block/blk-mq.c index f298500e6dda..7f996e427733 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -3023,6 +3023,13 @@ static int blk_mq_alloc_rq_maps(struct blk_mq_tag_set *set) static int blk_mq_update_queue_map(struct blk_mq_tag_set *set) { + /* + * blk_mq_map_queues() and multiple .map_queues() implementations + * expect that set->map[HCTX_TYPE_DEFAULT].nr_queues is set to the + * number of hardware queues. + */ + set->map[HCTX_TYPE_DEFAULT].nr_queues = set->nr_hw_queues; + if (set->ops->map_queues && !is_kdump_kernel()) { int i; From patchwork Thu Feb 20 02:44: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: 11393085 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 71D2B1580 for ; Thu, 20 Feb 2020 02:44:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CD1324676 for ; Thu, 20 Feb 2020 02:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727921AbgBTCox (ORCPT ); Wed, 19 Feb 2020 21:44:53 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43094 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbgBTCox (ORCPT ); Wed, 19 Feb 2020 21:44:53 -0500 Received: by mail-pg1-f194.google.com with SMTP id u12so1133368pgb.10 for ; Wed, 19 Feb 2020 18:44:51 -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=VHzHniqW9FZF1qhMp65mKq0FyUT0hhSij2tHk+/E1cg=; b=Y66X6E6XEZI/0df9uutcNbZlHauE4KPTlF1h+L//uHonJC3TDwrsDMLUFJRz1r7VDC bL8qZD4hOFNg4aVgLFLefIzQR8cbN9n3QvlCMjuyEhSjteBnX46KoJ66J92F9rdYmQ6V sG5xPEJ6Iu73KxS4N0CUIE2f5ePqZNHRH4A1vIrNImoAWNsmQC+Iey9+fd7Gh4qg8Yy5 /JfVP0VCanFZ9Fe7P/LAn+gSjrRgzd5Bhf433SdWsO6BU0e4Zlae8MCLvalo7PWpARpk eYNNDedMSIdk5ez0WsvQY9fkzVvCjWRL+e0zWU70XEkZbJd+WjMcXGKyLNtN8/W5DKYA fIDA== X-Gm-Message-State: APjAAAWIUws8dDDooOhHG/JoQgxgnAwjuFB1PmX4l9ab6GC0LASoMpFz cRGiMu7AWAq8CQ8K8HuyPII= X-Google-Smtp-Source: APXvYqw5R5nzsc/wBnbG50HtmHcuvppit5Ke+Pua1QL7LncsUjQz87Ak3mMUBfv2e6c84UsgG6QoQA== X-Received: by 2002:a63:348b:: with SMTP id b133mr31194547pga.372.1582166691423; Wed, 19 Feb 2020 18:44:51 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44:50 -0800 (PST) From: Bart Van Assche To: Jens Axboe Cc: linux-block@vger.kernel.org, Christoph Hellwig , Bart Van Assche , Ming Lei , Christoph Hellwig , Hannes Reinecke , Johannes Thumshirn , Keith Busch Subject: [PATCH v2 3/8] blk-mq: Fix a recently introduced regression in blk_mq_realloc_hw_ctxs() Date: Wed, 19 Feb 2020 18:44:36 -0800 Message-Id: <20200220024441.11558-4-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 Reviewed-by: Ming Lei Cc: Christoph Hellwig 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 --- block/blk-mq.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/blk-mq.c b/block/blk-mq.c index 7f996e427733..948523fbfa7f 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 Thu Feb 20 02:44: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: 11393083 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 53D5D159A for ; Thu, 20 Feb 2020 02:44:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F97D24671 for ; Thu, 20 Feb 2020 02:44:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727922AbgBTCox (ORCPT ); Wed, 19 Feb 2020 21:44:53 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:42697 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727921AbgBTCox (ORCPT ); Wed, 19 Feb 2020 21:44:53 -0500 Received: by mail-pg1-f196.google.com with SMTP id w21so1138634pgl.9 for ; Wed, 19 Feb 2020 18:44:53 -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=QCmO/dabdljnCpB+OCiSYu+MW5VdzYD2K6v5mQTd1Ipa2QYdUsI1MjTPdzlU9YSCYE lbLpHlmp+4Cz3D/AQNGoL6p13o/isZToZjrI02m/7hdY0gV4yLEb4u8UXuhMn6vlgSH1 wztbaczL69EiB292/72LhZdfsL/cFtMPLqE72wsWliuMK2P3P71ymthjvN1iEiLjB8Wj +zszR4tLLdsjoAFof6vs77E/nsE0HYYu8bSjda22kJ0KVAHEUuf9sGaTjSV0e3EO1mEN 7VOd6Dhb5vafNOgICzgoDKckA6Lep1b3gEScHMijduKVR0BB9uEiEUoew23dNCzbM1cO S6lQ== X-Gm-Message-State: APjAAAUo4sicIg2avBrQwxF1Y/yPbNqxxEd2rMkYO97HO+xJ5lQ8Ij+M z8u5E6+xVxyxmLzV7ze7/t0= X-Google-Smtp-Source: APXvYqx3gXiJKTTJ8tAdYZTYjAPcWOyWncVoog7f0mfIYWBt/UtVRUc8EaLr17nIgUS3Eo3p7e9hdw== X-Received: by 2002:aa7:864b:: with SMTP id a11mr30039764pfo.175.1582166692882; Wed, 19 Feb 2020 18:44:52 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44: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 v2 4/8] null_blk: Suppress an UBSAN complaint triggered when setting 'memory_backed' Date: Wed, 19 Feb 2020 18:44:37 -0800 Message-Id: <20200220024441.11558-5-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 Thu Feb 20 02:44: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: 11393089 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 C65561580 for ; Thu, 20 Feb 2020 02:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A85BD24671 for ; Thu, 20 Feb 2020 02:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727926AbgBTCo5 (ORCPT ); Wed, 19 Feb 2020 21:44:57 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:43096 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbgBTCo4 (ORCPT ); Wed, 19 Feb 2020 21:44:56 -0500 Received: by mail-pg1-f194.google.com with SMTP id u12so1133424pgb.10 for ; Wed, 19 Feb 2020 18:44:54 -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=AgSGWlcoSqwz3XZkdQnWKlbEQk1zlvBAE+Xa8Iw2zO0T7kc3cW6bT8luO/2g1XOPI4 FFYdlw06UUIA3FG0El/xKPn4AJG61BhUgKyxPeQuunPU3nuCtfcHlpqD5wUQ9Ss8c+Px C2x+pDmYHtuiNkak2ZHGyQZfTyS5SiBOsYSQuv9qLnjVpMxBQRRSxZ3dobwDK6EkUzvf N+HrXsFv0b/0+c5ceQacQwgc24pZ1aJismWWQSyrEd3BAUTHhL8ctJvHeUOIFtggg1/w y7+18dk3T2iuNUFPvpD8o7cwSRj7ZWHhH8sTqnA0JsyUKlmX7tAjDtRSFGMC5XG73Kdn jHWw== X-Gm-Message-State: APjAAAU/yypOn1lan66mxBegWYIdZbjaeIRY/JSl2dMe/gfCNtBZR+9B 8CRWk2Ov0Bb3WLt/qODzCKI= X-Google-Smtp-Source: APXvYqxdvc+107JzEBXNaaDUtmlzfVaPJ7ZCzq11ClGQzp9Qem4TeFkLW1dS11HtLOMKGjK2z7giHg== X-Received: by 2002:a63:1d5f:: with SMTP id d31mr31418390pgm.159.1582166694454; Wed, 19 Feb 2020 18:44:54 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44:53 -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 v2 5/8] null_blk: Fix changing the number of hardware queues Date: Wed, 19 Feb 2020 18:44:38 -0800 Message-Id: <20200220024441.11558-6-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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) { From patchwork Thu Feb 20 02:44: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: 11393087 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 5BF07138D for ; Thu, 20 Feb 2020 02:44:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 474B824671 for ; Thu, 20 Feb 2020 02:44:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727928AbgBTCo4 (ORCPT ); Wed, 19 Feb 2020 21:44:56 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:39990 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727926AbgBTCo4 (ORCPT ); Wed, 19 Feb 2020 21:44:56 -0500 Received: by mail-pl1-f193.google.com with SMTP id y1so936313plp.7 for ; Wed, 19 Feb 2020 18:44:56 -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=DSZ9WoMz732W6+HJg8zmXiY2NNitNQdJi2okPnkNQ04=; b=MZj68CxKWsiuE4p9dK2A9UHzDhsdxsfajdixZIxyMaE88bot4uLEHL8BCWKGljmYBZ 0Umb5kDMm6Ot1XlYKtCNsqKyRh5zgQCJ70JLr0F9y70/Y6THpVDzlOyGmWDZwcKErUAn /ZX870iejSbPO8GdURexynQqoLvwyL85zAfO0BUNaUCYedEwoR8qWtrd8USFjscSWmQY ishDO0VRxF3a84ZEmo0fDfSX9enSMgMbYCa4+wEGRN6JTULdSTZMqQQl4slZPhb3yeHm vO8YmSUQpZzoPcsojN+eiBIvmtHMbDNXwV4AYVZeEnLkxjyI109hWvIECPzwk1gaa3e5 dz2A== X-Gm-Message-State: APjAAAXnRav8ITb3RJEhcpJCJRdZ0Kh+rpZfzNdHUbs9J0iSg3FWF9Sj BeFUncB2uXhyZ08YmoXRNmQ= X-Google-Smtp-Source: APXvYqxXmYNCDhnMncdWR4EBXZjvUtVfOZEvXC6d7XmQUyXrim+x7ly0dKbBTQw4lELmIAavhJM5BQ== X-Received: by 2002:a17:902:6508:: with SMTP id b8mr28964178plk.201.1582166695903; Wed, 19 Feb 2020 18:44:55 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44:55 -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 v2 6/8] null_blk: Fix the null_add_dev() error path Date: Wed, 19 Feb 2020 18:44:39 -0800 Message-Id: <20200220024441.11558-7-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 If null_add_dev() fails, clear dev->nullb. This patch fixes the following KASAN complaint: BUG: KASAN: use-after-free in nullb_device_submit_queues_store+0xcf/0x160 [null_blk] Read of size 8 at addr ffff88803280fc30 by task check/8409 Call Trace: dump_stack+0xa5/0xe6 print_address_description.constprop.0+0x26/0x260 __kasan_report.cold+0x7b/0x99 kasan_report+0x16/0x20 __asan_load8+0x58/0x90 nullb_device_submit_queues_store+0xcf/0x160 [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 RIP: 0033:0x7ff370926317 Code: 64 89 02 48 c7 c0 ff ff ff ff eb bb 0f 1f 80 00 00 00 00 f3 0f 1e fa 64 8b 04 25 18 00 00 00 85 c0 75 10 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 51 c3 48 83 ec 28 48 89 54 24 18 48 89 74 24 RSP: 002b:00007fff2dd2da48 EFLAGS: 00000246 ORIG_RAX: 0000000000000001 RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007ff370926317 RDX: 0000000000000002 RSI: 0000559437ef23f0 RDI: 0000000000000001 RBP: 0000559437ef23f0 R08: 000000000000000a R09: 0000000000000001 R10: 0000559436703471 R11: 0000000000000246 R12: 0000000000000002 R13: 00007ff370a006a0 R14: 00007ff370a014a0 R15: 00007ff370a008a0 Allocated by task 8409: save_stack+0x23/0x90 __kasan_kmalloc.constprop.0+0xcf/0xe0 kasan_kmalloc+0xd/0x10 kmem_cache_alloc_node_trace+0x129/0x4c0 null_add_dev+0x24a/0xe90 [null_blk] nullb_device_power_store+0x1b6/0x270 [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 Freed by task 8409: save_stack+0x23/0x90 __kasan_slab_free+0x112/0x160 kasan_slab_free+0x12/0x20 kfree+0xdf/0x250 null_add_dev+0xaf3/0xe90 [null_blk] nullb_device_power_store+0x1b6/0x270 [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 Fixes: 2984c8684f96 ("nullb: factor disk parameters") Signed-off-by: Bart Van Assche --- drivers/block/null_blk_main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 31678c9af43f..9846648780b6 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1819,6 +1819,7 @@ static int null_add_dev(struct nullb_device *dev) cleanup_queues(nullb); out_free_nullb: kfree(nullb); + dev->nullb = NULL; out: return rv; } From patchwork Thu Feb 20 02:44:40 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: 11393091 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 BF502138D for ; Thu, 20 Feb 2020 02:44:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AA47024671 for ; Thu, 20 Feb 2020 02:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbgBTCo6 (ORCPT ); Wed, 19 Feb 2020 21:44:58 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:41054 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbgBTCo5 (ORCPT ); Wed, 19 Feb 2020 21:44:57 -0500 Received: by mail-pg1-f196.google.com with SMTP id 70so1141116pgf.8 for ; Wed, 19 Feb 2020 18:44:57 -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=E4GY3Fkj3YylXp9zuUe95CfCuLdtSRGv1bENxS7eu8k=; b=V5TqXChfyC9nK5gEXkIxCvWreupEV1xmTrKflZJjd4nALqtgH6KOsGtlzmOLnnFMoQ sv3zzajaTCHrt8RfjDMd/BEU4gjW/eCHVYvzjOu6YH4nNni6mk7Z73t42PlalknUBpxS 4HvJ+B841k2EuZU8uJTzcoboLNx5m6uGqEVPTFXEEIdzi4QB7Wkux+7eRgWLfS4KbFHy q/h6bNbd0uD78X44c2C8NRuw6tJ7xlDDa31z5D7kmy4uvprRM9+G/ZxcFf2ClMcjiV4t u+lFC30Vfybrr5wxVVG2jlvGkLvhKGEp4420Hh08F/RzJKdOrDpTDMfd63z96KilO+EI 0nSg== X-Gm-Message-State: APjAAAUtXEGVVLu732ZnXN06qF1NFXKDMbAn8S689rav8FcmR310fN40 Iu7R/jE3bHMrYua8R4pu0IU= X-Google-Smtp-Source: APXvYqy0UK6n4q/N+hdCkRWxT+0TSKXluXhQScHU1PQ/f6yETP2Mj/R+d6ski8fjsmcoDkRe5yngsQ== X-Received: by 2002:aa7:96b7:: with SMTP id g23mr29031021pfk.108.1582166697191; Wed, 19 Feb 2020 18:44:57 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44:56 -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 v2 7/8] null_blk: Handle null_add_dev() failures properly Date: Wed, 19 Feb 2020 18:44:40 -0800 Message-Id: <20200220024441.11558-8-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 If null_add_dev() fails then null_del_dev() is called with a NULL argument. Make null_del_dev() handle this scenario correctly. This patch fixes the following KASAN complaint: null-ptr-deref in null_del_dev+0x28/0x280 [null_blk] Read of size 8 at addr 0000000000000000 by task find/1062 Call Trace: dump_stack+0xa5/0xe6 __kasan_report.cold+0x65/0x99 kasan_report+0x16/0x20 __asan_load8+0x58/0x90 null_del_dev+0x28/0x280 [null_blk] nullb_group_drop_item+0x7e/0xa0 [null_blk] client_drop_item+0x53/0x80 [configfs] configfs_rmdir+0x395/0x4e0 [configfs] vfs_rmdir+0xb6/0x220 do_rmdir+0x238/0x2c0 __x64_sys_unlinkat+0x75/0x90 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index 9846648780b6..ba83fd0537ce 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1469,7 +1469,12 @@ static const struct blk_mq_ops null_mq_ops = { static void null_del_dev(struct nullb *nullb) { - struct nullb_device *dev = nullb->dev; + struct nullb_device *dev; + + if (!nullb) + return; + + dev = nullb->dev; ida_simple_remove(&nullb_indexes, nullb->index); From patchwork Thu Feb 20 02:44:41 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: 11393093 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 7304B138D for ; Thu, 20 Feb 2020 02:45:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5CE8424671 for ; Thu, 20 Feb 2020 02:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727932AbgBTCpA (ORCPT ); Wed, 19 Feb 2020 21:45:00 -0500 Received: from mail-pj1-f68.google.com ([209.85.216.68]:51578 "EHLO mail-pj1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727515AbgBTCpA (ORCPT ); Wed, 19 Feb 2020 21:45:00 -0500 Received: by mail-pj1-f68.google.com with SMTP id fa20so240533pjb.1 for ; Wed, 19 Feb 2020 18:44:59 -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=qS4jYuSHffNekwNAsgtk/oo8N3cmEg+YtUoGOtRuAMU=; b=r2SaDeYJxbBCuWVWHedBHV24K1EwyOvOUd/8Lo494YGTi4POVogJUpX5Z3TyBJ/jzz YMRKhxUlxMAh8u2YRDrP6y1kR48B+UZ+IuIujUCvPm6+wtAb4tDh1UhfPvzU9OdiwGQk k+NmyAUJSWRMi3TWx4VU/Zc/CU09EnQHvnWsevSYFl3wpwX0aR3+WGWJ+jgmHpfuRebR YYN1iLFgBmDRrs6sGaPX80yBDsYkDvE3uMhnAjSJ38vmHXp8WlfNVg0areHdx0lX3h51 u5I4sNaTl/VpjkxJY8cEpxjQO6T1bCEFK5uan+5Ec8afFUjsD/0//SOK0/E6rTogyias qAzw== X-Gm-Message-State: APjAAAVju2gzWpZc+vklbGgIZlac+NxaDHlRkSOjitTklDhZnrOe4qEo WsUkCApzOA9hL+P0Z35M2vk= X-Google-Smtp-Source: APXvYqwlXt73jUDAsKHbmUqng97rWYe5XG5QdE5hUd5CLnd+PSm/6szUUBVn3rFrtnUF2mJ5WASxrw== X-Received: by 2002:a17:902:82c3:: with SMTP id u3mr27454974plz.73.1582166698682; Wed, 19 Feb 2020 18:44:58 -0800 (PST) Received: from asus.hsd1.ca.comcast.net ([2601:647:4000:d7:29a7:b1bb:5b40:3d61]) by smtp.gmail.com with ESMTPSA id t23sm1005466pfq.6.2020.02.19.18.44.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 18:44:58 -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 v2 8/8] null_blk: Add support for init_hctx() fault injection Date: Wed, 19 Feb 2020 18:44:41 -0800 Message-Id: <20200220024441.11558-9-bvanassche@acm.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200220024441.11558-1-bvanassche@acm.org> References: <20200220024441.11558-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 makes it possible to test the error path in blk_mq_realloc_hw_ctxs() and also several error paths in null_blk. Cc: Christoph Hellwig Cc: Ming Lei Cc: Hannes Reinecke Cc: Johannes Thumshirn Signed-off-by: Bart Van Assche --- drivers/block/null_blk_main.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index ba83fd0537ce..7fccf162b59b 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -23,6 +23,7 @@ #ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION static DECLARE_FAULT_ATTR(null_timeout_attr); static DECLARE_FAULT_ATTR(null_requeue_attr); +static DECLARE_FAULT_ATTR(null_init_hctx_attr); #endif static inline u64 mb_per_tick(int mbps) @@ -101,6 +102,9 @@ module_param_string(timeout, g_timeout_str, sizeof(g_timeout_str), 0444); static char g_requeue_str[80]; module_param_string(requeue, g_requeue_str, sizeof(g_requeue_str), 0444); + +static char g_init_hctx_str[80]; +module_param_string(init_hctx, g_init_hctx_str, sizeof(g_init_hctx_str), 0444); #endif static int g_queue_mode = NULL_Q_MQ; @@ -1451,6 +1455,11 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *driver_data, struct nullb *nullb = hctx->queue->queuedata; struct nullb_queue *nq; +#ifdef CONFIG_BLK_DEV_NULL_BLK_FAULT_INJECTION + if (g_init_hctx_str[0] && should_fail(&null_init_hctx_attr, 1)) + return -EFAULT; +#endif + nq = &nullb->queues[hctx_idx]; hctx->driver_data = nq; null_init_queue(nullb, nq); @@ -1685,6 +1694,8 @@ static bool null_setup_fault(void) return false; if (!__null_setup_fault(&null_requeue_attr, g_requeue_str)) return false; + if (!__null_setup_fault(&null_init_hctx_attr, g_init_hctx_str)) + return false; #endif return true; }