From patchwork Thu Jul 7 14:13:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12909720 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 161CFC43334 for ; Thu, 7 Jul 2022 14:14:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235267AbiGGOOV (ORCPT ); Thu, 7 Jul 2022 10:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232153AbiGGOOT (ORCPT ); Thu, 7 Jul 2022 10:14:19 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C002F38C for ; Thu, 7 Jul 2022 07:14:18 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id dn9so27385348ejc.7 for ; Thu, 07 Jul 2022 07:14:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/iwdvLNwdILLGbbj5+PGHQP7PZ0tgLha+x+EmB31DpU=; b=Sh4d83p6h+XYNKnCQrd6wkn5WXI/d9OKVc53p/VBAC7KCYyfdpZeDLTlaIxln0pZgO ++gk1tCJLqCVEgbv5hGUDMCDQS7jMLtqkC59LYRxx5YzEYQj7Y3dB/FZSMX0xDN96Ii2 Ym2smh2z3AAJ7soItNbMp0jMqZko69zdViUvBFzfocIAKabg3r6ZG7wS6ucksKLbosrB fpqW8U97xfr0GQ3zz0L6aPQ/jE8MK6b+gXCaWiTbmKT65HyteHaAxytrfVgq5MJ9Fg1G 4xZMDN55a0Binl5/G+b1UHUy1SZi1ZMw5ZcgWhWPljqnKyd+SxJRo2lajofhNgHLxDlw Wb4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/iwdvLNwdILLGbbj5+PGHQP7PZ0tgLha+x+EmB31DpU=; b=Kx0fZNZ3TaZVhI1yYShQIKdbMIvg9scwP5/KeOo209HxjKh8qoh8epnv23puGaySXZ DCec+99jZ6IFm9lGk807kk0QEcakPstLI5/UOrC/UI/TgpPBp3P5rTWIQ00brpkhrGRo E4LF+5iMTecnd8yKWUsS853o418tDJ3RN8r0XS1yYdiE5I0E+w1iacYynNgo8iJllwao l2yZ5jYO7FCIae7uwiCr+roinNTRCyytGnEQQnut2UvqR6UBVYY+b9GIb41NukytvQDc dkN+76ZWYWKw1JrLKAdkGTY2tqU3PL6TTo8VMrzOqrZ358bRAqZmMIzPcqw62mJOtuJA kKVg== X-Gm-Message-State: AJIora9nNGB+3v3OZP8LJrhfsG1rGvatV0LOlPVvi1gMFfsXWih2TFr1 WWlpVzyZl18R0XXlZ+dTkqOuoY+CPvxOQtTp X-Google-Smtp-Source: AGRyM1uc6rE6QU9qD1aSIPntslyFm98FGe/7Q99ypNOfh5spJCb5peBIKfrLajM6STsgPjjFRxTPeg== X-Received: by 2002:a17:907:9816:b0:726:2b90:4bab with SMTP id ji22-20020a170907981600b007262b904babmr45585951ejc.544.1657203257267; Thu, 07 Jul 2022 07:14:17 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c093:600::1:3fc3]) by smtp.gmail.com with ESMTPSA id bq15-20020a056402214f00b00435a742e350sm28254125edb.75.2022.07.07.07.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 07:14:16 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, syzbot+49950ba66096b1f0209b@syzkaller.appspotmail.com Subject: [PATCH for-next 1/4] io_uring: don't miss setting REQ_F_DOUBLE_POLL Date: Thu, 7 Jul 2022 15:13:14 +0100 Message-Id: <8b680d83ded07424db83e8745585e7a6d72826ef.1657203020.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org When adding a second poll entry we should set REQ_F_DOUBLE_POLL unconditionally. We might race with the first entry removal but that doesn't change the rule. Fixes: a18427bb2d9b ("io_uring: optimise submission side poll_refs") Reported-and-tested-by: syzbot+49950ba66096b1f0209b@syzkaller.appspotmail.com Signed-off-by: Pavel Begunkov --- io_uring/poll.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 57747d92bba4..3710a0a46a87 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -401,16 +401,18 @@ static void io_poll_double_prepare(struct io_kiocb *req) /* head is RCU protected, see io_poll_remove_entries() comments */ rcu_read_lock(); head = smp_load_acquire(&poll->head); - if (head) { - /* - * poll arm may not hold ownership and so race with - * io_poll_wake() by modifying req->flags. There is only one - * poll entry queued, serialise with it by taking its head lock. - */ + /* + * poll arm may not hold ownership and so race with + * io_poll_wake() by modifying req->flags. There is only one + * poll entry queued, serialise with it by taking its head lock. + */ + if (head) spin_lock_irq(&head->lock); - req->flags |= REQ_F_DOUBLE_POLL; + + req->flags |= REQ_F_DOUBLE_POLL; + + if (head) spin_unlock_irq(&head->lock); - } rcu_read_unlock(); } From patchwork Thu Jul 7 14:13:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12909721 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 A2150CCA479 for ; Thu, 7 Jul 2022 14:14:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235259AbiGGOOV (ORCPT ); Thu, 7 Jul 2022 10:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235059AbiGGOOU (ORCPT ); Thu, 7 Jul 2022 10:14:20 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACC2C2F39A for ; Thu, 7 Jul 2022 07:14:19 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id o25so32690093ejm.3 for ; Thu, 07 Jul 2022 07:14:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FoaoLGayVR9g1LFSguZ7ChvtAEKoJH/jleNZLvLR1+A=; b=BOHYKCXCvG0ixGvUIhD265l0Fdv8ON05wJjzTgzVAaqCv/RO0CZkR8fpM15sQAAOAm IPEmS/v0pIss3Ou38Dv6R+qeUXWKN8EuLfIb8guzjYAjsV5mbmRR28uXrSinnHrN4Ifg 8MCbkQaHATNHK/MtwV36busUIEmUW6rOfCfmzn/co3pZsusgd3Hei5Lq04P5iofDRAxz to71ljoKbpEuWDlIJN25CMRPDiqHB/hGojGqVFXQKN5r2l8KmyH9HblVc6byoj5Z52zy pNfioXGlBWIgRfe4bhDyF0f7v91m1MBlRLpdxrnXU04kKtEMIt6Jmo+8PWIu2qrzJV7c oE8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FoaoLGayVR9g1LFSguZ7ChvtAEKoJH/jleNZLvLR1+A=; b=6KsC4FLh/R6te1GxU7X9TEh1Xt2UX+TaO+RZxs8tvTbmCSM0dOpbLJG+Rm5MNRL0QA IRYyzh9I2wbtY2kBvQRJT/pxodH6nldZ1QNN7ddiJ+j3xGvv5wP/kU+6mtI8qBaV7BsR 8MBc7aG0pFdERAry9zCYI7x1Qf7dUEAFtYHHzPAT2kIz72QUpP7C3AqbiCi2o1cFWbsl xK+Q9wZkaMGg7EMTtoUSHSWmBx6wCHoFE5qKmghSpniXfgReNbFAVHnI6fksSOJQN4Wh Um1oSmLyft8vPxwaS1vFHLXv6C2UuNGNszkdcdLxiYFg6CHb+yJbXIDnUI+p+YyeTr2j /dDA== X-Gm-Message-State: AJIora/gGrrA81vKTNQXQuuq6bei91GXi+VUIZkbWMJerkHXpt9y71JU HSNYxHujNZLS2LSgIuU8dB/PQnNduiaeHdGF X-Google-Smtp-Source: AGRyM1vzLNpzJaE/hHDIMcuELbEauevRRdSRR89Vd8EYZRQA8fnZ4mifuBXXz84IR3D9KvmvWZxYDg== X-Received: by 2002:a17:907:72cf:b0:72a:e56a:3157 with SMTP id du15-20020a17090772cf00b0072ae56a3157mr14330079ejc.465.1657203258008; Thu, 07 Jul 2022 07:14:18 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c093:600::1:3fc3]) by smtp.gmail.com with ESMTPSA id bq15-20020a056402214f00b00435a742e350sm28254125edb.75.2022.07.07.07.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 07:14:17 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 2/4] io_uring: don't race double poll setting REQ_F_ASYNC_DATA Date: Thu, 7 Jul 2022 15:13:15 +0100 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Just as with io_poll_double_prepare() setting REQ_F_DOUBLE_POLL, we can race with the first poll entry when setting REQ_F_ASYNC_DATA. Move it under io_poll_double_prepare(). Fixes: a18427bb2d9b ("io_uring: optimise submission side poll_refs") Signed-off-by: Pavel Begunkov --- io_uring/poll.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 3710a0a46a87..c1359d45a396 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -410,6 +410,8 @@ static void io_poll_double_prepare(struct io_kiocb *req) spin_lock_irq(&head->lock); req->flags |= REQ_F_DOUBLE_POLL; + if (req->opcode == IORING_OP_POLL_ADD) + req->flags |= REQ_F_ASYNC_DATA; if (head) spin_unlock_irq(&head->lock); @@ -448,13 +450,11 @@ static void __io_queue_proc(struct io_poll *poll, struct io_poll_table *pt, return; } - io_poll_double_prepare(req); /* mark as double wq entry */ wqe_private |= IO_WQE_F_DOUBLE; io_init_poll_iocb(poll, first->events, first->wait.func); + io_poll_double_prepare(req); *poll_ptr = poll; - if (req->opcode == IORING_OP_POLL_ADD) - req->flags |= REQ_F_ASYNC_DATA; } else { /* fine to modify, there is no poll queued to race with us */ req->flags |= REQ_F_SINGLE_POLL; From patchwork Thu Jul 7 14:13:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12909722 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 A9B60C433EF for ; Thu, 7 Jul 2022 14:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235059AbiGGOOW (ORCPT ); Thu, 7 Jul 2022 10:14:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232153AbiGGOOV (ORCPT ); Thu, 7 Jul 2022 10:14:21 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9FF72F39C for ; Thu, 7 Jul 2022 07:14:20 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id os14so2430579ejb.4 for ; Thu, 07 Jul 2022 07:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xykTgCQ9MK6li84TM+cB65FPijGtvT2IntKDqB/chPM=; b=NNfi/RUJLb6kqFrWk9iw0r6c4axZAo5X602z2LPkLS9fvQT39JH3Zmsv9TOalMcu1N UqLpGd5kmexKZBw8GZ57QFtLkLgTj7ICDNwPeEGomKJPcAQGKVy260wBtxGWOAIQGU4x wV8g4XHGSx9NG0XbCWUYfCp45xy1TRtai21IuXFjYfNrMYxQBwAO8nsaQcHeGlb6eE4v Gn3+HrYjwKYTaoDfteZyyidVvpLx3vpCrVobRc1ZsNvofjBSVds5BO6IyKueAql3Y2SA Pu6wYul1LNiuLm9SKenoJKucwKg/qZ7aUpHZw3hvMvk4atBbTEy0AExoa+UwN/BBvEw0 W9zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xykTgCQ9MK6li84TM+cB65FPijGtvT2IntKDqB/chPM=; b=n2NpHGnpL1nCJGfqxE9u0nZNz3AHDSbuW0Yacc/pV0t/I0CBl4MG17tEECv3Cq288S tl0NdZISQHx4pnkFWvRlMw/UkPSRut/WO0+Hh746lk6IrG9pEGi+xQiLkN9fmiduD/3U VdyLrfyh2XPrC2qx4QYnKDxdOQ10FkJ6sYuHWQdbpuwvgk0iivsqLw3E0lugdYde0eY4 0KYHxBo347Po1Al1yXDrC7h9eXnyX8Ufnnt9mxBPZs22+t2GiZqLdhd3fJAyA5ANK9ht LYPFh0Wgy1V2JHLZcEJdUEgYpehOQHBSiqiMq7ha7mU9KpH3TqvKJF1j09GxAQvVqoeQ OIoA== X-Gm-Message-State: AJIora9toX4J+u1yy+opoY4Kqbwvwh9EGB2osYXd/8jFfSYpkLipeoiN ypvgKaVyO8Lrl5WCS1s2vZOanngw20453r0y X-Google-Smtp-Source: AGRyM1tkgoQUjqldcT/SAU9DPYy7C2dwPROcgOsTy7XrOh9U/oLPohR4065oYYjFSbY6kxtHD0pLcA== X-Received: by 2002:a17:907:3e9a:b0:726:d079:d868 with SMTP id hs26-20020a1709073e9a00b00726d079d868mr46023154ejc.620.1657203258987; Thu, 07 Jul 2022 07:14:18 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c093:600::1:3fc3]) by smtp.gmail.com with ESMTPSA id bq15-20020a056402214f00b00435a742e350sm28254125edb.75.2022.07.07.07.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 07:14:18 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 3/4] io_uring: clear REQ_F_HASH_LOCKED on hash removal Date: Thu, 7 Jul 2022 15:13:16 +0100 Message-Id: <02e48bb88d6f1480c94ac2924c43ad1fbd48e92a.1657203020.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Instead of clearing REQ_F_HASH_LOCKED while arming a poll, unset the bit when we're removing the entry from the table in io_poll_tw_hash_eject(). Signed-off-by: Pavel Begunkov --- io_uring/poll.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index c1359d45a396..77b669b06046 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -132,6 +132,7 @@ static void io_poll_tw_hash_eject(struct io_kiocb *req, bool *locked) */ io_tw_lock(ctx, locked); hash_del(&req->hash_node); + req->flags &= ~REQ_F_HASH_LOCKED; } else { io_poll_req_delete(req, ctx); } @@ -617,9 +618,7 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) * apoll requests already grab the mutex to complete in the tw handler, * so removal from the mutex-backed hash is free, use it by default. */ - if (issue_flags & IO_URING_F_UNLOCKED) - req->flags &= ~REQ_F_HASH_LOCKED; - else + if (!(issue_flags & IO_URING_F_UNLOCKED)) req->flags |= REQ_F_HASH_LOCKED; if (!def->pollin && !def->pollout) @@ -880,8 +879,6 @@ int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) if (!(issue_flags & IO_URING_F_UNLOCKED) && (req->ctx->flags & (IORING_SETUP_SQPOLL | IORING_SETUP_SINGLE_ISSUER))) req->flags |= REQ_F_HASH_LOCKED; - else - req->flags &= ~REQ_F_HASH_LOCKED; ret = __io_arm_poll_handler(req, poll, &ipt, poll->events, issue_flags); if (ret > 0) { From patchwork Thu Jul 7 14:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Begunkov X-Patchwork-Id: 12909723 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 C81C1C43334 for ; Thu, 7 Jul 2022 14:14:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231579AbiGGOOY (ORCPT ); Thu, 7 Jul 2022 10:14:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235182AbiGGOOX (ORCPT ); Thu, 7 Jul 2022 10:14:23 -0400 Received: from mail-ed1-x52b.google.com (mail-ed1-x52b.google.com [IPv6:2a00:1450:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DB892F3A0 for ; Thu, 7 Jul 2022 07:14:22 -0700 (PDT) Received: by mail-ed1-x52b.google.com with SMTP id z41so23360301ede.1 for ; Thu, 07 Jul 2022 07:14:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6BtvDKTuBY2Sh4BYJQe6+DnANlvOqVlrRS4OpC6qmGA=; b=RkQZfvIniOzxxWntRZZIFvB6zauSh0kc00Uru5IYlYHdrlh7ZPEGLASEhengF0uHcm vYPGDYmg7XEXyIzaSqp7GBLIAz10xFl1HookPqnw4lJBnFJtewjjJRqfB5TwlO7VMsyM tcx47ZOtHwAHg+DljqOB1EHVCw/BC0y/D/nvJznTwX5y8V97eljuQwjOlHlYd1SpJqZt iYyICowevEXaYqVh5CYqoQFfDfq4WWjZO/ne2ILuHAs+cIfQ4S9wrqtadxmHm29L7gS/ wAHNkr4yICVQHtUXtX0wnLlph+dMow++RdBUGB5XbUJpgVUw0lA0cO0ZRzPivBpOcXrX vW0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6BtvDKTuBY2Sh4BYJQe6+DnANlvOqVlrRS4OpC6qmGA=; b=yXlQ7Ycstbly5uwS7i06FMVEikr/oIOnZnDuhxKE2f7st4GFDDsbYhrdT1/Xhm3YLE vc5g3NJ/VahqiMiJsJnoQ1GU1i7VqT7IYEjt++EfHd6oYqao44CCqoz0u9kUs+0zGSnl oOYUv0MSZDoy5sNDphV9/uOSImTE2UQlUpEV512tys4r8v+5KAxyENlfvSOX2yRwNJOl OAvzpBNCSpqKT4nd4pvNoOhLuvRAhsUL8FDBVs6pDf/49r7R4qEIcldvLhc3KL3ccBIH SE1nCZYRpcsVZjVRlebtGFI2M5yX/8uN/eyDjf3Ftt9Q55rm01u+UoX/F2qGB6turgii GEXA== X-Gm-Message-State: AJIora8FYmb4OaZDx87KktdnfzWRgvRkle71l1X0/uTwlvhPr3j3eNPd Iztipkoqz0zYsfLSlwpyxjxDKkZBOOwxoLr1 X-Google-Smtp-Source: AGRyM1uj9PyAPAmfQfCu36o2c3Taw8qejLfpNHezWHHpsXD0SiBgjShaKZWu7z52OpXvA0hVAfjH8w== X-Received: by 2002:a50:eb89:0:b0:43a:1212:db8c with SMTP id y9-20020a50eb89000000b0043a1212db8cmr36013663edr.391.1657203259923; Thu, 07 Jul 2022 07:14:19 -0700 (PDT) Received: from 127.0.0.1localhost.com ([2620:10d:c093:600::1:3fc3]) by smtp.gmail.com with ESMTPSA id bq15-20020a056402214f00b00435a742e350sm28254125edb.75.2022.07.07.07.14.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 07:14:19 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com Subject: [PATCH for-next 4/4] io_uring: consolidate hash_locked io-wq handling Date: Thu, 7 Jul 2022 15:13:17 +0100 Message-Id: <0ff0ffdfaa65b3d536131535c3dad3c63d9b7bb0.1657203020.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org Don't duplicate code disabling REQ_F_HASH_LOCKED for IO_URING_F_UNLOCKED (i.e. io-wq), move the handling into __io_arm_poll_handler(). Signed-off-by: Pavel Begunkov --- io_uring/poll.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/io_uring/poll.c b/io_uring/poll.c index 77b669b06046..76592063abe7 100644 --- a/io_uring/poll.c +++ b/io_uring/poll.c @@ -523,8 +523,12 @@ static int __io_arm_poll_handler(struct io_kiocb *req, * io_poll_can_finish_inline() tries to deal with that. */ ipt->owning = issue_flags & IO_URING_F_UNLOCKED; - atomic_set(&req->poll_refs, (int)ipt->owning); + + /* io-wq doesn't hold uring_lock */ + if (issue_flags & IO_URING_F_UNLOCKED) + req->flags &= ~REQ_F_HASH_LOCKED; + mask = vfs_poll(req->file, &ipt->pt) & poll->events; if (unlikely(ipt->error || !ipt->nr_entries)) { @@ -618,8 +622,7 @@ int io_arm_poll_handler(struct io_kiocb *req, unsigned issue_flags) * apoll requests already grab the mutex to complete in the tw handler, * so removal from the mutex-backed hash is free, use it by default. */ - if (!(issue_flags & IO_URING_F_UNLOCKED)) - req->flags |= REQ_F_HASH_LOCKED; + req->flags |= REQ_F_HASH_LOCKED; if (!def->pollin && !def->pollout) return IO_APOLL_ABORTED; @@ -876,8 +879,7 @@ int io_poll_add(struct io_kiocb *req, unsigned int issue_flags) * If sqpoll or single issuer, there is no contention for ->uring_lock * and we'll end up holding it in tw handlers anyway. */ - if (!(issue_flags & IO_URING_F_UNLOCKED) && - (req->ctx->flags & (IORING_SETUP_SQPOLL | IORING_SETUP_SINGLE_ISSUER))) + if (req->ctx->flags & (IORING_SETUP_SQPOLL|IORING_SETUP_SINGLE_ISSUER)) req->flags |= REQ_F_HASH_LOCKED; ret = __io_arm_poll_handler(req, poll, &ipt, poll->events, issue_flags);