From patchwork Wed Jan 15 13:10:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lizetao X-Patchwork-Id: 13940426 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8199B2459A3 for ; Wed, 15 Jan 2025 13:10:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736946615; cv=none; b=a8N7YqChJ4SoAUKfH7Ey1Y0oNlJdLa7F7Z/5fgrb/Oke33TlZfUYbiJ42AiH6SoxIXcKFs7Qo8mOJohc98YGzhUoFWFpG3GpLlPmyro0o7xl46fImWEf3y+BM+W00C6spRBn3L8mrCP45FUJ/mIOqrq35QZX1fdjWFYXsl0m4cM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736946615; c=relaxed/simple; bh=qp+FUUG0qWx5N5JB2aJeyNxnALeDYwotFojNI8zEUEc=; h=From:To:CC:Subject:Date:Message-ID:Content-Type:MIME-Version; b=BT4PbXlYbdHkz3MUXpWXQfAmVfFc0i6WwUimU0xTN41fsFxZ2js3SIA3Ci+7Luzzbx4RjRd59APNhZh5pAWMST/y/j9aveqKUq0zc0wMVpHpOhrGCQGW1K9OlDkTxJrS+Z4yKwh1AbYhUVE4MglNm4GaNfxqZ2LqL+AbB3u/9ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4YY5qr6p15z11SRM; Wed, 15 Jan 2025 21:07:04 +0800 (CST) Received: from kwepemd100011.china.huawei.com (unknown [7.221.188.204]) by mail.maildlp.com (Postfix) with ESMTPS id 6C1781402C7; Wed, 15 Jan 2025 21:10:07 +0800 (CST) Received: from kwepemd500012.china.huawei.com (7.221.188.25) by kwepemd100011.china.huawei.com (7.221.188.204) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.34; Wed, 15 Jan 2025 21:10:07 +0800 Received: from kwepemd500012.china.huawei.com ([7.221.188.25]) by kwepemd500012.china.huawei.com ([7.221.188.25]) with mapi id 15.02.1258.034; Wed, 15 Jan 2025 21:10:07 +0800 From: lizetao To: Jens Axboe , Pavel Begunkov CC: "io-uring@vger.kernel.org" Subject: [PATCH] test/defer: fix deadlock when io_uring_submit fail Thread-Topic: [PATCH] test/defer: fix deadlock when io_uring_submit fail Thread-Index: AdtnTle0AdCKvQv4QCG1RPRIudIQww== Date: Wed, 15 Jan 2025 13:10:06 +0000 Message-ID: <77ab74b3fdff491db2a5596b1edc86b6@huawei.com> Accept-Language: en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 While performing fault injection testing, a bug report was triggered: FAULT_INJECTION: forcing a failure. name fail_usercopy, interval 1, probability 0, space 0, times 0 CPU: 12 UID: 0 PID: 18795 Comm: defer.t Tainted: G O 6.13.0-rc6-gf2a0a37b174b #17 Tainted: [O]=OOT_MODULE Hardware name: linux,dummy-virt (DT) Call trace: show_stack+0x20/0x38 (C) dump_stack_lvl+0x78/0x90 dump_stack+0x1c/0x28 should_fail_ex+0x544/0x648 should_fail+0x14/0x20 should_fail_usercopy+0x1c/0x28 get_timespec64+0x7c/0x258 __io_timeout_prep+0x31c/0x798 io_link_timeout_prep+0x1c/0x30 io_submit_sqes+0x59c/0x1d50 __arm64_sys_io_uring_enter+0x8dc/0xfa0 invoke_syscall+0x74/0x270 el0_svc_common.constprop.0+0xb4/0x240 do_el0_svc+0x48/0x68 el0_svc+0x38/0x78 el0t_64_sync_handler+0xc8/0xd0 el0t_64_sync+0x198/0x1a0 The deadlock stack is as follows: io_cqring_wait+0xa64/0x1060 __arm64_sys_io_uring_enter+0x46c/0xfa0 invoke_syscall+0x74/0x270 el0_svc_common.constprop.0+0xb4/0x240 do_el0_svc+0x48/0x68 el0_svc+0x38/0x78 el0t_64_sync_handler+0xc8/0xd0 el0t_64_sync+0x198/0x1a0 This is because after the submission fails, the defer.t testcase is still waiting to submit the failed request, resulting in an eventual deadlock. Solve the problem by telling wait_cqes the number of requests to wait for. Fixes: 6f6de47d6126 ("test/defer: Test deferring with drain and links") Signed-off-by: Li Zetao --- test/defer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.33.0 diff --git a/test/defer.c b/test/defer.c index b0770ef..2447be0 100644 --- a/test/defer.c +++ b/test/defer.c @@ -69,12 +69,12 @@ err: return 1; } -static int wait_cqes(struct test_context *ctx) +static int wait_cqes(struct test_context *ctx, int num) { int ret, i; struct io_uring_cqe *cqe; - for (i = 0; i < ctx->nr; i++) { + for (i = 0; i < num; i++) { ret = io_uring_wait_cqe(ctx->ring, &cqe); if (ret < 0) { @@ -105,7 +105,7 @@ static int test_canceled_userdata(struct io_uring *ring) goto err; } - if (wait_cqes(&ctx)) + if (wait_cqes(&ctx, ret)) goto err; for (i = 0; i < nr; i++) { @@ -139,7 +139,7 @@ static int test_thread_link_cancel(struct io_uring *ring) goto err; } - if (wait_cqes(&ctx)) + if (wait_cqes(&ctx, ret)) goto err; for (i = 0; i < nr; i++) { @@ -185,7 +185,7 @@ static int test_drain_with_linked_timeout(struct io_uring *ring) goto err; } - if (wait_cqes(&ctx)) + if (wait_cqes(&ctx, ret)) goto err; free_context(&ctx); @@ -212,7 +212,7 @@ static int run_drained(struct io_uring *ring, int nr) goto err; } - if (wait_cqes(&ctx)) + if (wait_cqes(&ctx, ret)) goto err; free_context(&ctx);