Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4112688rwl; Tue, 28 Mar 2023 02:49:02 -0700 (PDT) X-Google-Smtp-Source: AK7set/x4U+qrG47qY+I5jn3T/t461tklqoUNMdpUOoOhHZIv9BlRW8om/deCBhyZZXlfFIXbmIo X-Received: by 2002:a17:907:6e17:b0:902:874:9c31 with SMTP id sd23-20020a1709076e1700b0090208749c31mr24480759ejc.35.1679996942185; Tue, 28 Mar 2023 02:49:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679996942; cv=none; d=google.com; s=arc-20160816; b=OvbKbQLjUDaGk+15Efm3zxW3Xx7SmKiPGntDFRHqFh69FQQwWdAo2arH2c5wdjB5rX Y5d+NKMrgHJMOs5Rq1qMsrMhjkLDdjVGEy/3RPEdapk30lcw/ZghUB2ckj+ckjoCDG9n DgfCG1qnUBAMD0eRiqUF+e9+GTl2nz/dyq75u12TXkvehuFhMHjv+i51SwGpiBAvT+s+ 0HkE3jS0MW+xeO50/8cE/FmcZtJqGko3JAaK1/NRWydc42Apr/2LI1/pr8/oqL7h8hdK AQmnUKEtmnctIUjJPN1R4f4m8T4AQBG0jVpLb2ijEVRuHD10T/aDKPDDrTmrz6rJ9DHt a02w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=Stg5UHl32TtIntNpYHAfo04fHl2FpClHrAUpOSx9eUw=; b=glGN7Nq0jsVF19Q1Fga/zPNiuHa25nD1Vf7eXOgj2vp+KTPoS11BTHInwW0mJQXxM0 YFdDnU8CzRwQmAa5RFFK6ny2055b8MLDAAV0kKBYX1UXFkLUIhLDkQyBtUNc+cd8m1PC S3Gt+OFx3uV9Q4lu2vY50+Id4uYfyBItQgaEwSo0QF9N3JVGiGBVX8tT5FpFQld/HENO byx4LrMuslOJYf73nQKnnPiCYfl4SAh/xzybTihdWv0BvMeq+6yH2mf/md50Jdz8AcPk 037V+EHgNB9fEapcUQ6LK9Zx8g+bAbHb1a4RRtJCKHTtBDmt6AiGlyL0mKIJqy8s9MzV Wp7A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g16-20020a170906395000b00933106de4b0si26446211eje.845.2023.03.28.02.48.37; Tue, 28 Mar 2023 02:49:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232600AbjC1Jn1 (ORCPT + 99 others); Tue, 28 Mar 2023 05:43:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbjC1JnL (ORCPT ); Tue, 28 Mar 2023 05:43:11 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CEBE65AA; Tue, 28 Mar 2023 02:43:03 -0700 (PDT) Received: from dggpeml100012.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pm4Qn2S44zgZD1; Tue, 28 Mar 2023 17:39:45 +0800 (CST) Received: from localhost.localdomain (10.67.175.61) by dggpeml100012.china.huawei.com (7.185.36.121) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 28 Mar 2023 17:43:00 +0800 From: Zheng Yejian To: , , CC: , , , Subject: [PATCH] blktrace: Gracefully return if fail in blk_register_tracepoints() Date: Tue, 28 Mar 2023 17:46:05 +0800 Message-ID: <20230328094605.480557-1-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.175.61] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpeml100012.china.huawei.com (7.185.36.121) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently blk_register_tracepoints() WARN for every registration failure of block tracepoint, however, blk_trace can still be setup-ed. It seems better to cleanup registered tracepoints and return error when a certain registration failed, even if it's a small probability, and users can know the error and do blk_trace setup again. Signed-off-by: Zheng Yejian --- kernel/trace/blktrace.c | 113 +++++++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 26 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index d5d94510afd3..62ac72866f02 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -60,7 +60,7 @@ static struct tracer_flags blk_tracer_flags = { static DEFINE_MUTEX(blk_probe_mutex); static int blk_probes_ref; -static void blk_register_tracepoints(void); +static int blk_register_tracepoints(void); static void blk_unregister_tracepoints(void); /* @@ -330,12 +330,20 @@ static void blk_trace_free(struct request_queue *q, struct blk_trace *bt) kfree(bt); } -static void get_probe_ref(void) +static int get_probe_ref(void) { + int ret = 0; + mutex_lock(&blk_probe_mutex); - if (++blk_probes_ref == 1) - blk_register_tracepoints(); + if (++blk_probes_ref == 1) { + ret = blk_register_tracepoints(); + if (ret) { + pr_warn("Could not register block tracepoints\n"); + --blk_probes_ref; + } + } mutex_unlock(&blk_probe_mutex); + return ret; } static void put_probe_ref(void) @@ -608,13 +616,14 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, bt->pid = buts->pid; bt->trace_state = Blktrace_setup; + ret = get_probe_ref(); + if (ret) + goto err; rcu_assign_pointer(q->blk_trace, bt); - get_probe_ref(); + return 0; - ret = 0; err: - if (ret) - blk_trace_free(q, bt); + blk_trace_free(q, bt); return ret; } @@ -1088,42 +1097,92 @@ void blk_add_driver_data(struct request *rq, void *data, size_t len) } EXPORT_SYMBOL_GPL(blk_add_driver_data); -static void blk_register_tracepoints(void) +static int blk_register_tracepoints(void) { int ret; ret = register_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); - WARN_ON(ret); + if (ret) + return ret; ret = register_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); - WARN_ON(ret); + if (ret) + goto err_block_rq_issue; ret = register_trace_block_rq_merge(blk_add_trace_rq_merge, NULL); - WARN_ON(ret); + if (ret) + goto err_block_rq_merge; ret = register_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); - WARN_ON(ret); + if (ret) + goto err_block_rq_requeue; ret = register_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); - WARN_ON(ret); + if (ret) + goto err_block_rq_complete; ret = register_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_bounce; ret = register_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_complete; ret = register_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_backmerge; ret = register_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_frontmerge; ret = register_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_queue; ret = register_trace_block_getrq(blk_add_trace_getrq, NULL); - WARN_ON(ret); + if (ret) + goto err_block_getrq; ret = register_trace_block_plug(blk_add_trace_plug, NULL); - WARN_ON(ret); + if (ret) + goto err_block_plug; ret = register_trace_block_unplug(blk_add_trace_unplug, NULL); - WARN_ON(ret); + if (ret) + goto err_block_unplug; ret = register_trace_block_split(blk_add_trace_split, NULL); - WARN_ON(ret); + if (ret) + goto err_block_split; ret = register_trace_block_bio_remap(blk_add_trace_bio_remap, NULL); - WARN_ON(ret); + if (ret) + goto err_block_bio_remap; ret = register_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); - WARN_ON(ret); + if (ret) + goto err_block_rq_remap; + return 0; + +err_block_rq_remap: + unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL); +err_block_bio_remap: + unregister_trace_block_split(blk_add_trace_split, NULL); +err_block_split: + unregister_trace_block_unplug(blk_add_trace_unplug, NULL); +err_block_unplug: + unregister_trace_block_plug(blk_add_trace_plug, NULL); +err_block_plug: + unregister_trace_block_getrq(blk_add_trace_getrq, NULL); +err_block_getrq: + unregister_trace_block_bio_queue(blk_add_trace_bio_queue, NULL); +err_block_bio_queue: + unregister_trace_block_bio_frontmerge(blk_add_trace_bio_frontmerge, NULL); +err_block_bio_frontmerge: + unregister_trace_block_bio_backmerge(blk_add_trace_bio_backmerge, NULL); +err_block_bio_backmerge: + unregister_trace_block_bio_complete(blk_add_trace_bio_complete, NULL); +err_block_bio_complete: + unregister_trace_block_bio_bounce(blk_add_trace_bio_bounce, NULL); +err_block_bio_bounce: + unregister_trace_block_rq_complete(blk_add_trace_rq_complete, NULL); +err_block_rq_complete: + unregister_trace_block_rq_requeue(blk_add_trace_rq_requeue, NULL); +err_block_rq_requeue: + unregister_trace_block_rq_merge(blk_add_trace_rq_merge, NULL); +err_block_rq_merge: + unregister_trace_block_rq_issue(blk_add_trace_rq_issue, NULL); +err_block_rq_issue: + unregister_trace_block_rq_insert(blk_add_trace_rq_insert, NULL); + tracepoint_synchronize_unregister(); + return ret; } static void blk_unregister_tracepoints(void) @@ -1643,8 +1702,10 @@ static int blk_trace_setup_queue(struct request_queue *q, blk_trace_setup_lba(bt, bdev); + ret = get_probe_ref(); + if (ret) + goto free_bt; rcu_assign_pointer(q->blk_trace, bt); - get_probe_ref(); return 0; free_bt: -- 2.25.1