Received: by 2002:ac8:156:0:b0:3e0:cd10:60c8 with SMTP id f22csp2652908qtg; Tue, 4 Apr 2023 05:42:51 -0700 (PDT) X-Google-Smtp-Source: AKy350a7GYAUm8iK/3OSguzj65i0PyJFsqcfcHv4IcZvu8y7nVUKrEwHeb/+fo0Pou9lpQ+RIOj+ X-Received: by 2002:a05:6a20:914e:b0:e6:88c6:ab16 with SMTP id x14-20020a056a20914e00b000e688c6ab16mr4327506pzc.21.1680612170984; Tue, 04 Apr 2023 05:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680612170; cv=none; d=google.com; s=arc-20160816; b=GFEES1Rgh6x33NnzQhOfVCkgCDPftU4IxpN0TyD5N3ISdOgSC5ytrrYR/42zH7rbot sy9+yArLi9FGnby6zvHZWj/DBgyR4Ds4a5+QJu+WwuLGpWLF06+tkhDjI01SVZgE9T4D cIc1hhLDjLuz1ouilQNX+YzbaXGf8BawKCiOAwN1bqdA2sqi2FJdOKh3LSI0xTprH7Jm bd+RRuAAEq845NiDUhhys11Fw827VZwcG0g5IDqSF9b1DkIgQCDhxozSlk7IOsM5O+E4 HA5FWn9n1rx4CiOCy0AQlbRCgQAnYBEfp5Hha7MN3i/8ubYcpcFQNu4Ib4I/FWeLnSbt 9BgQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F32O348mTkggRcCcK2wkzqvHv1nRgFctuPngecPv3KY=; b=A46feWxTVcP71R80IJGPA6qmYJdh5MiyGf0GH9CLE9jd7aVSaihugX0hGEppxTJ9xN hW4GFrvAoEfaJ1rauXbJ2Mzaj3PQF4Yb8iIkZsTLh6UZswjDJ0geZ/EOcBvs8uU+xZ8V nOCYzSGC7VQI+3bazNGOifcWGqemEYffGuwYrIaSrYLgMDNf5o7gqIEswzr4Zz4P0bzH mF2VQDCkETqNcCOC7hkrLvpWD5EPlPBToKsYp3JPSgYUqlUkNSUDTTiLNr6iN5b3hN6i r2yYSsK87hNkHLDrjG4ulOlMDBraIWR2ve+zmUUQZo/HivoKLaDyPcaQLRjV4NPhCERy WdEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dTK7+Kye; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e125-20020a636983000000b005134ad7aeccsi10716103pgc.812.2023.04.04.05.42.37; Tue, 04 Apr 2023 05:42:50 -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; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dTK7+Kye; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234657AbjDDMlJ (ORCPT + 99 others); Tue, 4 Apr 2023 08:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234000AbjDDMk6 (ORCPT ); Tue, 4 Apr 2023 08:40:58 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76E1AD8; Tue, 4 Apr 2023 05:40:54 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id cn12so130059676edb.4; Tue, 04 Apr 2023 05:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680612053; 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=F32O348mTkggRcCcK2wkzqvHv1nRgFctuPngecPv3KY=; b=dTK7+Kye78JXOJfhcNt8QivolTT8rVP53t8GXXvuGVNhpH8N24pc2EoeSFwmyWZEWs AGbEG0jOIjwCTd04Zps0w3m1P+vKhsMcbIpQaYx/Zrk2ki5Hj/jKinjGlb1UgxyYawvr p3AWcONqwd/fk4GXL7mvTxJe6ReZNXMoLzDO3C83my3sO4oe2HmM7929WWWspr6KYt1e bD4mCFWZHL3XeeRns0BB4yADWqE0M/2s/FfGVoVwH1LoiyW3zyETnRwzGfaBvkXcViLr 1Ek01KizZI53MjFIa1c0kS/6VfHXob/40V0x06HjYltnfmo1ZN9nfcGBtNkB8oT8HY6x 58WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680612053; 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=F32O348mTkggRcCcK2wkzqvHv1nRgFctuPngecPv3KY=; b=xclh7kU/hzPIeiounBe9iiuXTAFCrDhOE10PH1YsKrriqfq0uSqv/nX6eO2fQaEokW Mi+MyRaxE+VHFyMsYVddUPHO38VwZZeqTOeEd0EkowxbBIOgDQialkKYbAMMQYFlw6wU k0zJISF92lpAnl5SGTn9jaBAdQYEoV0Ley5k7dHQPcMju5t7O3prWA7EbD51qbXpL3p7 PxPsuJ2tR06WZBaaMZWKrcDteY+b+GagwhZZYLqU95972zIssm8+dwu6mlX5uJQQbGtG hN27Q6UzXx487bAzJIe/uMNkkuA8+32QKA5j9iG0gQNRjl2Xh1DW31ZO7swFjOXivaSQ rsPQ== X-Gm-Message-State: AAQBX9fS03bpcRVXYBuuMpO2Y+vkw1vuQCIrrzqsFhgRHIiBLphsT3po rlLCU0KPpV184ZVAUxA70HxM0T44sv8= X-Received: by 2002:a17:906:ee1:b0:862:c1d5:ea1b with SMTP id x1-20020a1709060ee100b00862c1d5ea1bmr2064833eji.8.1680612052843; Tue, 04 Apr 2023 05:40:52 -0700 (PDT) Received: from 127.com ([2620:10d:c092:600::2:2b22]) by smtp.gmail.com with ESMTPSA id g8-20020a170906394800b008cafeec917dsm5978851eje.101.2023.04.04.05.40.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 05:40:52 -0700 (PDT) From: Pavel Begunkov To: io-uring@vger.kernel.org Cc: Jens Axboe , asml.silence@gmail.com, linux-kernel@vger.kernel.org Subject: [PATCH v2 04/13] io_uring: io_free_req() via tw Date: Tue, 4 Apr 2023 13:39:48 +0100 Message-Id: <3a92fe80bb068757e51aaa0b105cfbe8f5dfee9e.1680576071.git.asml.silence@gmail.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, 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 io_free_req() is not often used but nevertheless problematic as there is no way to know the current context, it may be used from the submission path or even by an irq handler. Push it to a fresh context using task_work. Signed-off-by: Pavel Begunkov --- io_uring/io_uring.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 596af20cddb4..98320f4b0bca 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1116,7 +1116,7 @@ static inline void io_dismantle_req(struct io_kiocb *req) io_put_file(req->file); } -__cold void io_free_req(struct io_kiocb *req) +static __cold void io_free_req_tw(struct io_kiocb *req, struct io_tw_state *ts) { struct io_ring_ctx *ctx = req->ctx; @@ -1130,6 +1130,12 @@ __cold void io_free_req(struct io_kiocb *req) spin_unlock(&ctx->completion_lock); } +__cold void io_free_req(struct io_kiocb *req) +{ + req->io_task_work.func = io_free_req_tw; + io_req_task_work_add(req); +} + static void __io_req_find_next_prep(struct io_kiocb *req) { struct io_ring_ctx *ctx = req->ctx; -- 2.39.1