Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp52338pxk; Tue, 15 Sep 2020 17:32:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMYAZc0M6p6aNJvML7nut3/HXQg3ZDeMe6iUEAtmuj5DVOaJ7E8I3s6pg82GJikIPL15I7 X-Received: by 2002:a05:6402:a46:: with SMTP id bt6mr25059921edb.269.1600216328228; Tue, 15 Sep 2020 17:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600216328; cv=none; d=google.com; s=arc-20160816; b=uxcquzwPZ420/zeXgduVOnlRdJ3A+4TM7nXIodaozsRYct6PvHmbJtG0JaeQYxXk3U MOnhWbiJIA6yfgHpc8CxS3Frdf+XfF8pvRDx9mxcFfn7XQfXXhefKfXosHb+YvR8n5rq h+RCtKhKG/bM+7/JtYh6rvsqrciO0TOErCtp1q76wKveb/097mQNBcYygEGl4pJD1bDB 5+Dn8sM224QljkqlftCBy3NSXjDQ+DbWMRwbPIfUMmrMH8LEFua09M3mLOwl+bC6nQkI Aw77GLvYYIcNYtTPKlRi5qLUyWfgc/OVPaLHR7mkL7OYBqjB/vXoJcIhA5PfVVMyU+HI RIvw== 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:references:cc:to:from:subject:dkim-signature; bh=5nixci3CSSlm0JVJHjLv8kSY8PhichT9C9IRwcdycYA=; b=Kj7CTbSPGG8KL7ehPwI5Hro4mVzfVRxXpg+kNpi4h35YunilHbk4AmkkikI7/3CrBi mhX2o/o6rzjYN74zYSwvj8IE8gm+TFjit6NQfZ7UkNGvpaGeKvOO/hX25TdzoNxdG8C2 cOCrzcdezksaynmGpV/p+exNi94uXLfM2o6utN1Q3FTdDwbmfiATvnphv5QDfg4umWKU W4Mqjop3mvEfeyTL/Ha1KnZZYbCxUSwRL/SsWKF6+4GntL8BJsVSNLZMgGKwHUmMTbCY ckowzv0ImKd+uqPSJCFoPQSyP5eSmqKAq2yVhLTOMZ5ir6wCKMODtJbV6PwVFvQL6jSv LnyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=frM1guUP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h27si11392763edj.263.2020.09.15.17.31.46; Tue, 15 Sep 2020 17:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=frM1guUP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726750AbgIPA3T (ORCPT + 99 others); Tue, 15 Sep 2020 20:29:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbgIONti (ORCPT ); Tue, 15 Sep 2020 09:49:38 -0400 Received: from mail-ot1-x344.google.com (mail-ot1-x344.google.com [IPv6:2607:f8b0:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B9E1C061A28 for ; Tue, 15 Sep 2020 06:36:57 -0700 (PDT) Received: by mail-ot1-x344.google.com with SMTP id g96so3191978otb.12 for ; Tue, 15 Sep 2020 06:36:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=5nixci3CSSlm0JVJHjLv8kSY8PhichT9C9IRwcdycYA=; b=frM1guUPtYEMHzBHOmBXc1LJN0o/Mhxc876Up3RbNvLAopbQ51jsxn66hMudOWe+7D qb0q6byNtnMAi7YZ/5QVMXXBGRO8H+YZre3Z0q+2wt1a/4W5UmqMAoPDfsHXvx/gaacZ f9VKtNiD/2RmhiywtqC6DD11yNsMPRZHlVGu+H8XXcT7nMXl0TKxbHdXwp2msnugNfda 5FMcbZ5ppng5F+r02LNIJJvEOmSKmXygmLJuVT1IevEOJqkJpB2Z9xq0q0A5nRd25IjN FsYcvSBU0Fre2hTvb7hD+Dc7Ro39e+TKVPUsoQrkRDiwf2ncucLBcd23rPxa1gqOO8pG g65w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=5nixci3CSSlm0JVJHjLv8kSY8PhichT9C9IRwcdycYA=; b=aA5RyOx+oztYs1tW7nAqt7Zer4zHvAs6WHkX/TuQczvhQVE4rvGkB2qE+4MXQxkevH n1Iyx/PmwHPR7Rc8XlWCIVCEnVv0ugzuKtJzyqusR09SNo12srdIpoBzeV0OxG2ouz4A kWhPZQ84PRmgYfw8yKh3Xw8nX+mdAEdAd3/mY1Fr0JKzw2Hn4Il5aWZ4ENNCZpQsTJU9 aYTBPy172yVZ+yNn8suwMQi0iBlSkBLwkdL0+jJnt22obc6NlhEydrmmtPsHmQFyearK oOV9YHQ1ahnvGASPQpnxFLi7D47EecjmQZ9k4qWcrXpgc4sx0pI6rx5eKomzR4vdXYK4 NxhQ== X-Gm-Message-State: AOAM530+hkgOwyx8DOAbUpiTt3w5f52+xmi49BsOAfv4ALTgSwg1G9qf j9klChVVIUOcpz62MbMBfag9UVOjvBM6QqRZ X-Received: by 2002:a9d:315:: with SMTP id 21mr13659132otv.278.1600177016337; Tue, 15 Sep 2020 06:36:56 -0700 (PDT) Received: from [192.168.1.10] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id o13sm5597673otj.2.2020.09.15.06.36.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Sep 2020 06:36:55 -0700 (PDT) Subject: Re: [PATCH] io_uring: fix the bug of child process can't do io task From: Jens Axboe To: Yinyin Zhu , viro@zeniv.linux.org.uk Cc: linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org References: <20200915130245.89585-1-zhuyinyin@bytedance.com> Message-ID: <0d66eabc-3b8b-2f84-05b7-981c2b6fe5dd@kernel.dk> Date: Tue, 15 Sep 2020 07:36:54 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 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 9/15/20 7:25 AM, Jens Axboe wrote: > On 9/15/20 7:02 AM, Yinyin Zhu wrote: >> when parent process setup a io_uring_instance, the ctx->sqo_mm was >> assigned of parent process'mm. Then it fork a child >> process. So the child process inherits the io_uring_instance fd from >> parent process. Then the child process submit a io task to the io_uring >> instance. The kworker will do the io task actually, and use >> the ctx->sqo_mm as its mm, but this ctx->sqo_mm is parent process's mm, >> not the child process's mm. so child do the io task unsuccessfully. To >> fix this bug, when a process submit a io task to the kworker, assign the >> ctx->sqo_mm with this process's mm. > > Hmm, what's the test case for this? There's a 5.9 regression where we > don't always grab the right context for certain linked cases, below > is the fix. Does that fix your case? Ah hang on, you're on the 5.4 code base... I think this is a better approach. Any chance you can test it? The problem with yours is that you can have multiple pending async ones, and you can't just re-assign ctx->sqo_mm. That one should only be used by the SQPOLL thread. diff --git a/fs/io_uring.c b/fs/io_uring.c index 2a539b794f3b..e8a4b4ae7006 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -514,7 +514,7 @@ static inline void io_queue_async_work(struct io_ring_ctx *ctx, } } - req->task = current; + req->task = get_task_struct(current); spin_lock_irqsave(&ctx->task_lock, flags); list_add(&req->task_list, &ctx->task_list); @@ -1832,6 +1832,7 @@ static void io_poll_complete_work(struct work_struct *work) spin_unlock_irq(&ctx->completion_lock); io_cqring_ev_posted(ctx); + put_task_struct(req->task); io_put_req(req); out: revert_creds(old_cred); @@ -2234,11 +2235,11 @@ static void io_sq_wq_submit_work(struct work_struct *work) ret = 0; if (io_req_needs_user(req) && !cur_mm) { - if (!mmget_not_zero(ctx->sqo_mm)) { + if (!mmget_not_zero(req->task->mm)) { ret = -EFAULT; goto end_req; } else { - cur_mm = ctx->sqo_mm; + cur_mm = req->task->mm; use_mm(cur_mm); old_fs = get_fs(); set_fs(USER_DS); @@ -2275,6 +2276,7 @@ static void io_sq_wq_submit_work(struct work_struct *work) } /* drop submission reference */ + put_task_struct(req->task); io_put_req(req); if (ret) { -- Jens Axboe