Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2247124rwl; Thu, 30 Mar 2023 07:55:40 -0700 (PDT) X-Google-Smtp-Source: AKy350bKcdyjwfqYUCxlRscVRhq8HMKU2ZpsW6vfl1OtCS1wRTdPTEjZF6l9q3Ljtljid0Y9lBDK X-Received: by 2002:a17:906:dd:b0:93e:22e6:e7d1 with SMTP id 29-20020a17090600dd00b0093e22e6e7d1mr2383788eji.3.1680188139888; Thu, 30 Mar 2023 07:55:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680188139; cv=none; d=google.com; s=arc-20160816; b=zpYM035g+GxDoTygs3w6xe1XQ9Dg/gd0JAySk7+O/AErqXnRWUGmaGmHtwPElqn1B9 aqdOBMGgbuBxtTsLw0eSWfG6444q7vEeOihxD3d7M/ccYipyWdSAv5TbKvv4KpEi4Fxj TZXpYyulfmPOQ3D1pb6fH42pbXZdSIndcXSwFmUSmqYjRdhCeZD3Sa5gd7hIvIJF5AKw NvUBgPIaaUgSrhwsfRF2tKQPXMtd5ULwV5TnjUHmtuGbUh1GiLnOdvTL8N8EIK5uy3hl jX9TZtSIn9VdcYVr2nQVPu9oQJ+KhBv1NMWLKh7jNqP0Yi1fmfS7VkSeHhEGjjzNpGWt HHRQ== 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=eKfMO97Puxbxg9b5V2zEzriSKSgWDMsPXMYWqPT9qnU=; b=prQKd/pdFg1ygMFDKIr5wtpYjeQ50blNOmmiU7RpOJS8es+igK/VUPacYiQOTp1Mhq UQxmz+a7EOG6PR2Vatc3AjOhT2qJNE3iTq2Ycfq8HJv07RNDMxePVJrZjLZEBCYl214+ HckQLRNnkJB1DVo6DCn5s+JCWc8/6K4eDGfAKAr0auvwceNOA4FJ1WjahiJXv7/sWnkJ onmUc74mV0XiQPt7yPK8p5ZRciEbn5ih7TfqO94wUliyTnuB2q8jJATabDL5TuMsiznw G87LzegV95IyoVFwBIV+Km65aZmWD6ZPBr3KeqdlQr8QZUe+N3Kfuvp1Ofc8iD/WFRt8 N+NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=NY7Rm6tR; 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 ht14-20020a170907608e00b0093f87005ba7si14618291ejc.95.2023.03.30.07.55.14; Thu, 30 Mar 2023 07:55:39 -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=NY7Rm6tR; 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 S232603AbjC3Oyv (ORCPT + 99 others); Thu, 30 Mar 2023 10:54:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232517AbjC3Oyl (ORCPT ); Thu, 30 Mar 2023 10:54:41 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43F5E469E; Thu, 30 Mar 2023 07:54:39 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id l12so19362276wrm.10; Thu, 30 Mar 2023 07:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680188077; 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=eKfMO97Puxbxg9b5V2zEzriSKSgWDMsPXMYWqPT9qnU=; b=NY7Rm6tRHFZ76SKQjHQdrDnj9n2jWzPmsbsXRr5sKH2eH3gRHQlQaR4Xoy5egkkK3c EGB/hzWp1i/3AzduUWZ0JfogkFiG/lN3KpUiFOWNOj0HuAABld2CwxHAYYR91+cifYln lLkPPpPcxJcB/9hItQ8keDXeLXji7HIwIybnBFNggrZtCIS5IwaZYLyw+ykua7UJmNwc jumPip94qNG8lZOkxUUzU8YTEBlEIkRpRgMXlhTiDkvZUBuZ4Vy/AsMWi4vfnLGJn7+Y of2tdDBRpfALUs8LZOZoKBAM22ckJDR5ThRkc3GrCWEjvxS0GdqOQzIw72A6U6d2B1cS xdQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680188077; 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=eKfMO97Puxbxg9b5V2zEzriSKSgWDMsPXMYWqPT9qnU=; b=rnOztK7g0qXOxoferby0TlKXPJE0sR8f3Vf9pWOMbMgoaM7GAZOt+m5j2vRU+ImoeH Rgl0wKkBN7/HHitMojaD1+MbZ9QXNaDvRBaaEsTYETz0vmpynM3glevcuFRAWAqFxB4a NaesG+542U+xeRDtIYY3pBSttkQNW+WegNEL2kfloxkzkBiP533cPTtMdKN9DGE9+dck QQ0mPuUHRiV7vDU3gIhDqSKQ+G87Lm5FPyLIDNVQht36M15bb9PEFKSo2HpO64x7Y0j4 5qSwOMBsl25mTIEbscG9MEEYJZGqT5hI37a6y+fvo3Ty0PwzZCyMPNAzRV8XENJRk4Uq bYjA== X-Gm-Message-State: AAQBX9ecNOoehB6Rh6UIDnDjU+HRWCUqGXI8TyLDIF/0sy51yFCz4qib tmFSvpk0OrpqLIFEn5ztbxevWUxComM= X-Received: by 2002:a5d:500a:0:b0:2cb:29eb:a35e with SMTP id e10-20020a5d500a000000b002cb29eba35emr5127532wrt.11.1680188077486; Thu, 30 Mar 2023 07:54:37 -0700 (PDT) Received: from 127.0.0.1localhost (82-132-231-234.dab.02.net. [82.132.231.234]) by smtp.gmail.com with ESMTPSA id d7-20020adffbc7000000b002d5a8d8442asm28727962wrs.37.2023.03.30.07.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Mar 2023 07:54:37 -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 04/11] io_uring: io_free_req() via tw Date: Thu, 30 Mar 2023 15:53:22 +0100 Message-Id: <6b0c640860a6250abf883840b160ccd50fd5f311.1680187408.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 c944833099a6..52a88da65f57 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) +__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