From patchwork Fri Feb 24 17:08:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13151561 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E11B1C6FA8E for ; Fri, 24 Feb 2023 17:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbjBXRIx (ORCPT ); Fri, 24 Feb 2023 12:08:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjBXRIw (ORCPT ); Fri, 24 Feb 2023 12:08:52 -0500 Received: from mail-il1-x12a.google.com (mail-il1-x12a.google.com [IPv6:2607:f8b0:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8852D26865 for ; Fri, 24 Feb 2023 09:08:50 -0800 (PST) Received: by mail-il1-x12a.google.com with SMTP id i12so93491ila.5 for ; Fri, 24 Feb 2023 09:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; t=1677258529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=evy5Nhcn/IK9a4WHn7+Nf7/BMe3ohJX14uH+qC58xX8=; b=5XTMOH/klFzt3FjJ0if1hdeJUIN4srqA4fFEyiq7QUfL3isiZnucAqhBFHjxE5+wDk rc/oHswCpyoggOxrBEePIMTA7Ti7mpg6+TXIDx4Rt+stmfOfPpMDZqxJ+ZA6nPooek8Z Yh5W9zkHiQtkkkpPya7PJzoLp/KBHwk2IzZ2FIpJSe405mgErgqxo/uMxfcT4cHytvZN QRhihcPIPlh8/rp+jXPiXqipQA0/HVRV9v6jca1ljwiwIXcNHjnDE8oHgFXh9D1xYr+N ayAPkFJT5GDy2GKnaXWrQzC5+1Svv/iyL7TaW/VbFlISyr7PHAwnBJfBuJQwWg+jZ8r+ y6Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677258529; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=evy5Nhcn/IK9a4WHn7+Nf7/BMe3ohJX14uH+qC58xX8=; b=HnmxgsLDktVfwrYFKVKpHdRJ2Qw793E8OiFzSyt77wbjhR3LUMwfD1K1ZNjlqQrE3r 2F8keJ89g/KGUtCCnB9u1lpExU2rItpBTh4qElTSLYnC04HNdjC/v+0JA31giJNNFqh1 LZxuc879S9LpbgLkj+5fXcm3rUPo6aYYPomnuRI5WfYcAOpXMUQH7FN4t+1Q0P05zO+v P3P3/Of4SOZvS9REVYsXt36I9HgoXCiTvZgNzo1R4WSl06RKOGhOhcvHgCUNuBk1n6rW yDQZJWNowDX+5EA+7/8imUC/XCtF1ICQwUdqkOs9bMBpB8wGxJQo6/OvODIHU9R+Qa5B o/Xw== X-Gm-Message-State: AO0yUKXViIsy9utjW7P/k6t87ev2F+2XsHnbNYeDV3jibJuF+JweTsGQ p61TqBoQh9wS7iXQT7UqEhSCKvzw/0c9kWbv X-Google-Smtp-Source: AK7set8z4Oi3tz5DjYLDXT6/eiJUyZvJ9FLbmpUSYMSF2IFo//6Mi7nXAZe7kEnwChgnd18FqbpibA== X-Received: by 2002:a05:6e02:1567:b0:317:16bc:dc97 with SMTP id k7-20020a056e02156700b0031716bcdc97mr1505626ilu.3.1677258529537; Fri, 24 Feb 2023 09:08:49 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id a1-20020a92d341000000b0031535ce9cc8sm4166018ilh.83.2023.02.24.09.08.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 09:08:48 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: kbusch@kernel.org, Jens Axboe , stable@vger.kernel.org Subject: [PATCH 1/2] block: clear bio->bi_bdev when putting a bio back in the cache Date: Fri, 24 Feb 2023 10:08:44 -0700 Message-Id: <20230224170845.175485-2-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230224170845.175485-1-axboe@kernel.dk> References: <20230224170845.175485-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org This isn't strictly needed in terms of correctness, but it does allow polling to know if the bio has been put already by a different task and hence avoid polling something that we don't need to. Cc: stable@vger.kernel.org Fixes: be4d234d7aeb ("bio: add allocation cache abstraction") Signed-off-by: Jens Axboe Reviewed-by: Keith Busch --- block/bio.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/bio.c b/block/bio.c index 2693f34afb7e..605c40025068 100644 --- a/block/bio.c +++ b/block/bio.c @@ -772,6 +772,7 @@ static inline void bio_put_percpu_cache(struct bio *bio) if ((bio->bi_opf & REQ_POLLED) && !WARN_ON_ONCE(in_interrupt())) { bio->bi_next = cache->free_list; + bio->bi_bdev = NULL; cache->free_list = bio; cache->nr++; } else { From patchwork Fri Feb 24 17:08:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13151562 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEDB2C7EE31 for ; Fri, 24 Feb 2023 17:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbjBXRIy (ORCPT ); Fri, 24 Feb 2023 12:08:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbjBXRIx (ORCPT ); Fri, 24 Feb 2023 12:08:53 -0500 Received: from mail-il1-x12f.google.com (mail-il1-x12f.google.com [IPv6:2607:f8b0:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC86C168A1 for ; Fri, 24 Feb 2023 09:08:51 -0800 (PST) Received: by mail-il1-x12f.google.com with SMTP id e10so98080ilu.4 for ; Fri, 24 Feb 2023 09:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D3rugt0kcqzEr09E9TYYrNcya1Yke+FnObjHejahto8=; b=cDUpGhxszykKXpp8/Iq26Xa/q3SrqpOO6Gd0mkCkeNVXj10d0nqNw6gMtcAoB4HK8r DZTomPSQrpxPpH0/lSNRHWTI4lnSIo+edgEf+ozof7hc7+Ch8l30mphxTDpdA6iX5RMX AAFC/376gJHY8FBvYuc6uRKEYWGR5DAPDQ7JcmbYzZP6fxH0If6+9fFzviIIv0BzBigM a5DHsgvtiRcgBLlEocpRkkVIRBR976VBnd4f9nY9Gl2nrle5yTnpVmdjmvz2OHUpuGj+ RwncXRMQ/fcc8rq5gOX/cwrgTGND5fHy2Bh91qzx0EBKzZGmtirpOPCZ1dXjYn195lhx O9Zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D3rugt0kcqzEr09E9TYYrNcya1Yke+FnObjHejahto8=; b=bb4Ps8wwO40Ts7Tc0tC7q2+IB/khqYg+nhMOcKYEnlSF9pVAP9e+0VnHiVsUIycGDQ +sJbmR1nNRrHRO5isTDuxK/sQFAA7F3qyMvx2beKmheEgd4JRo6IMvvI3QWKIsSijYth TCYqvyyuElJ31f9sRC5whGWKJPNynbOv6YZeL+L/MxzHBuf5rqZGO1ZnYL7GlNBCFOqf I+jnmrvbzIh5rmmQjEQKK+qZkTHk9LjwVQOKWIiktI96y1n1/cByjZrCRLXiB83og3ZX zpfZ1uNejWsWhfACCUi6DJFEZsP2xxE49M8ddyOXOgZkUQxpfo8fMoC+BL9ZEv0SDUtS 5RgQ== X-Gm-Message-State: AO0yUKXfb6rhmI6okKsCYCNqL1UBcgW/Bigj5+5UAU91XtnBnxKbCzKR 48dkhYkgRYdp+hhvMA7LWFYtbGq8Qhe1ysno X-Google-Smtp-Source: AK7set+kDzJRsqFGEY1uPTnRuTcoK+mCmFkBBoj/HVCCqqhA57MaesprK2TS1iN5fbFygF9bHu2V+w== X-Received: by 2002:a92:680f:0:b0:317:1ca3:f518 with SMTP id d15-20020a92680f000000b003171ca3f518mr831529ilc.0.1677258530686; Fri, 24 Feb 2023 09:08:50 -0800 (PST) Received: from localhost.localdomain ([96.43.243.2]) by smtp.gmail.com with ESMTPSA id a1-20020a92d341000000b0031535ce9cc8sm4166018ilh.83.2023.02.24.09.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Feb 2023 09:08:50 -0800 (PST) From: Jens Axboe To: linux-block@vger.kernel.org Cc: kbusch@kernel.org, Jens Axboe , Wei Zhang , stable@vger.kernel.org Subject: [PATCH 2/2] block: be a bit more careful in checking for NULL bdev while polling Date: Fri, 24 Feb 2023 10:08:45 -0700 Message-Id: <20230224170845.175485-3-axboe@kernel.dk> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230224170845.175485-1-axboe@kernel.dk> References: <20230224170845.175485-1-axboe@kernel.dk> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Wei reports a crash with an application using polled IO: PGD 14265e067 P4D 14265e067 PUD 47ec50067 PMD 0 Oops: 0000 [#1] SMP CPU: 0 PID: 21915 Comm: iocore_0 Kdump: loaded Tainted: G S 5.12.0-0_fbk12_clang_7346_g1bb6f2e7058f #1 Hardware name: Wiwynn Delta Lake MP T8/Delta Lake-Class2, BIOS Y3DLM08 04/10/2022 RIP: 0010:bio_poll+0x25/0x200 Code: 0f 1f 44 00 00 0f 1f 44 00 00 55 41 57 41 56 41 55 41 54 53 48 83 ec 28 65 48 8b 04 25 28 00 00 00 48 89 44 24 20 48 8b 47 08 <48> 8b 80 70 02 00 00 4c 8b 70 50 8b 6f 34 31 db 83 fd ff 75 25 65 RSP: 0018:ffffc90005fafdf8 EFLAGS: 00010292 RAX: 0000000000000000 RBX: 0000000000000000 RCX: 74b43cd65dd66600 RDX: 0000000000000003 RSI: ffffc90005fafe78 RDI: ffff8884b614e140 RBP: ffff88849964df78 R08: 0000000000000000 R09: 0000000000000008 R10: 0000000000000000 R11: 0000000000000000 R12: ffff88849964df00 R13: ffffc90005fafe78 R14: ffff888137d3c378 R15: 0000000000000001 FS: 00007fd195000640(0000) GS:ffff88903f400000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000270 CR3: 0000000466121001 CR4: 00000000007706f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: iocb_bio_iopoll+0x1d/0x30 io_do_iopoll+0xac/0x250 __se_sys_io_uring_enter+0x3c5/0x5a0 ? __x64_sys_write+0x89/0xd0 do_syscall_64+0x2d/0x40 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x94f225d Code: 24 cc 00 00 00 41 8b 84 24 d0 00 00 00 c1 e0 04 83 e0 10 41 09 c2 8b 33 8b 53 04 4c 8b 43 18 4c 63 4b 0c b8 aa 01 00 00 0f 05 <85> c0 0f 88 85 00 00 00 29 03 45 84 f6 0f 84 88 00 00 00 41 f6 c7 RSP: 002b:00007fd194ffcd88 EFLAGS: 00000202 ORIG_RAX: 00000000000001aa RAX: ffffffffffffffda RBX: 00007fd194ffcdc0 RCX: 00000000094f225d RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000000000007 RBP: 00007fd194ffcdb0 R08: 0000000000000000 R09: 0000000000000008 R10: 0000000000000001 R11: 0000000000000202 R12: 00007fd269d68030 R13: 0000000000000000 R14: 0000000000000001 R15: 0000000000000000 which is due to bio->bi_bdev being NULL. This can happen if we have two tasks doing polled IO, and task B ends up completing IO from task A if they are sharing a poll queue. If task B completes the IO and puts the bio into our cache, then it can allocate that bio again before task A is done polling for it. As that would necessitate a preempt between the two tasks, it's enough to just be a bit more careful in checking for whether or not bio->bi_bdev is NULL. Reported-and-tested-by: Wei Zhang Cc: stable@vger.kernel.org Fixes: be4d234d7aeb ("bio: add allocation cache abstraction") Signed-off-by: Jens Axboe Reviewed-by: Keith Busch --- block/blk-core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 5fb6856745b4..5d7e2ca75234 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -854,10 +854,16 @@ EXPORT_SYMBOL(submit_bio); */ int bio_poll(struct bio *bio, struct io_comp_batch *iob, unsigned int flags) { - struct request_queue *q = bdev_get_queue(bio->bi_bdev); blk_qc_t cookie = READ_ONCE(bio->bi_cookie); + struct block_device *bdev; + struct request_queue *q; int ret = 0; + bdev = READ_ONCE(bio->bi_bdev); + if (!bdev) + return 0; + + q = bdev_get_queue(bdev); if (cookie == BLK_QC_T_NONE || !test_bit(QUEUE_FLAG_POLL, &q->queue_flags)) return 0; @@ -926,7 +932,7 @@ int iocb_bio_iopoll(struct kiocb *kiocb, struct io_comp_batch *iob, */ rcu_read_lock(); bio = READ_ONCE(kiocb->private); - if (bio && bio->bi_bdev) + if (bio) ret = bio_poll(bio, iob, flags); rcu_read_unlock();