Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1903023ybv; Thu, 6 Feb 2020 11:59:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxlWjgfbNyqEvJucGoh9ERbdNOTyTRUYpKwX7FhjDY9PbhdhXxJ3u/F2P2ja3CRnqtR5gPr X-Received: by 2002:a05:6830:2102:: with SMTP id i2mr31196051otc.123.1581019147562; Thu, 06 Feb 2020 11:59:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581019147; cv=none; d=google.com; s=arc-20160816; b=Mzk4/mYbpxvIfPtL9JTLz9cUQdT+ZtbB3pL3vZpGWa21L7rm/DH0zLGwj4HkE4/YAw sr5FPL2TYTcNgIB8ExU6DuBCobgngO4Dkpw9w/QkuXpX29k/nWkx8o/uAZ7RWUDdRKNj EukbEnhCJctmRyV+kQ9l9c/HmK82O4p5/yVllaTvwpMi+nFV2qv/hVJ3/pB1MxQ4tC9V fWgpDmc90aFslFRLRe1ugl6oVver6DKG/h3dS9XrPw0pmGCyGTRnBpeoPcL9A5+61Ru5 DUcfCwWj/I/vIrTxiFpdTudAYLOahkYPsfMPyd8qOcsAj4D8Id8ZDBtFK2oLbA+nsz/K +VLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature; bh=Q1s66fc5wEyyCtqAZ1fxyuIa4B0bjzdDWKhuT8omqjw=; b=AOVvOSF6L7osJRssIg8TMfIcwgHicnwUfTZJJDhLbJnQ9FApsqdCOQ5bpfSH2j0/jX JCYoXZT6znupV70DP8yyBNGS2B9qNoRDI1cem2K7t2/4Rv7Xluvvc9YJCfMI3Bwmlyy3 pBa7WGEouqpTTrwuRQgeaqhWVLGVQWuOMDS41JUBvi4a/vh5g9ElLeQZ82HFVNXABfSJ QlPb7NapfNUztSLkIyBLGHEvsGJxqXMHYvPrjQXLE7rLt25XxEOMnB1KszZw7v7TzF/E phRWhtmZIa0vz8Dz/OPcy4ACBwrhk0Tl9fm+THebtE/sm04/cgeGt5hva1rb60gvGi1k m/SA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YYJZJvMg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d20si367023otq.157.2020.02.06.11.58.55; Thu, 06 Feb 2020 11:59:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YYJZJvMg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727835AbgBFT5B (ORCPT + 99 others); Thu, 6 Feb 2020 14:57:01 -0500 Received: from mail-io1-f66.google.com ([209.85.166.66]:43467 "EHLO mail-io1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727479AbgBFT5B (ORCPT ); Thu, 6 Feb 2020 14:57:01 -0500 Received: by mail-io1-f66.google.com with SMTP id n21so7594146ioo.10 for ; Thu, 06 Feb 2020 11:56:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=Q1s66fc5wEyyCtqAZ1fxyuIa4B0bjzdDWKhuT8omqjw=; b=YYJZJvMgL+oKB4Kf9hFzm3HKoaJu4d8ykkFQ54Qte3tsBTUxwnRX9PA8npvcW4R9JY q3LrSwfGvqC1MZVMiPx2jzWpkrmI45mvpBJqG1TIqBlepEoNV1jCbazWZ2k9YzKAHWU/ mz+YiPwzqojbBKLyr2B6babbXal5qxQ849vDtTPPSSc7LNkgyPHZIr6J97sA9lrBeqQ/ bWo6rkPlM795YTm1cLiKWR2AKWCqHJGZxpPJp+3Xm0rlJ25V5pDr/iBP3HeS67VEmdJ5 jPHG7XsWJ69BLrtvkHg+Q6gyCE1F0nBFysQG9DC4DlMqBTjfMRjGakcrcWQlLdahOJ2f Mq8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Q1s66fc5wEyyCtqAZ1fxyuIa4B0bjzdDWKhuT8omqjw=; b=mTKznBRfkuf5i1fDYpK5yihiM6aZfU34YQC36wrETXuNuYrGc7e5VKApF/6fzp060z VdTl99gRCHwI0h3V8sSb42oYxwpjjJunAYaDwiNIBJwN6mWEKXehrC2cvrJIP91x9X9N 1MIvvQRUHhx33LaleiB09IDpSN5gGW/7oaTOZfCUsS1DsVayxqzh0Ur2XPI5sbt1KKPT ymzg+Ur1KsAaMvhP1pD3L2neETJf0ei0gcl03b5oqbXmeJGBFu45jWAbQQqFppOfKQ57 amOq5w5XtjcWVM3bEeL2KzHbKR20/DJgdtHsOHUF4JAeR6fW+t9d2bB/wat/iLGJkrVc UQ1g== X-Gm-Message-State: APjAAAX6uzXD81IhkjFesXeWUZxGXHP+l8K315Frhi0FWI3lJX59NLOa vagz1b/K/Oc3T/+lHgLaJB3qHzuJBuU= X-Received: by 2002:a6b:5902:: with SMTP id n2mr24866691iob.298.1581019018760; Thu, 06 Feb 2020 11:56:58 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id o1sm156128ioo.56.2020.02.06.11.56.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Feb 2020 11:56:58 -0800 (PST) Subject: Re: [PATCH] io_uring: fix deferred req iovec leak To: Pavel Begunkov , io-uring@vger.kernel.org, linux-kernel@vger.kernel.org References: From: Jens Axboe Message-ID: <6e7207b6-95c4-4287-5872-fb05abf60e88@kernel.dk> Date: Thu, 6 Feb 2020 12:56:57 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/6/20 10:16 AM, Pavel Begunkov wrote: > On 06/02/2020 20:04, Pavel Begunkov wrote: >> On 06/02/2020 19:51, Pavel Begunkov wrote: >>> After defer, a request will be prepared, that includes allocating iovec >>> if needed, and then submitted through io_wq_submit_work() but not custom >>> handler (e.g. io_rw_async()/io_sendrecv_async()). However, it'll leak >>> iovec, as it's in io-wq and the code goes as follows: >>> >>> io_read() { >>> if (!io_wq_current_is_worker()) >>> kfree(iovec); >>> } >>> >>> Put all deallocation logic in io_{read,write,send,recv}(), which will >>> leave the memory, if going async with -EAGAIN. >>> >> Interestingly, this will fail badly if it returns -EAGAIN from io-wq context. >> Apparently, I need to do v2. >> > Or not... > Jens, can you please explain what's with the -EAGAIN handling in > io_wq_submit_work()? Checking the code, it seems neither of > read/write/recv/send can return -EAGAIN from async context (i.e. > force_nonblock=false). Are there other ops that can do it? Nobody should return -EAGAIN with force_nonblock=false, they should end the io_kiocb inline for that. -- Jens Axboe