From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4115AC352A2 for ; Thu, 6 Feb 2020 19:55:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 08819218AC for ; Thu, 6 Feb 2020 19:55:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20150623.gappssmtp.com header.i=@kernel-dk.20150623.gappssmtp.com header.b="o2TJ5na9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbgBFTzm (ORCPT ); Thu, 6 Feb 2020 14:55:42 -0500 Received: from mail-io1-f48.google.com ([209.85.166.48]:43048 "EHLO mail-io1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727479AbgBFTzl (ORCPT ); Thu, 6 Feb 2020 14:55:41 -0500 Received: by mail-io1-f48.google.com with SMTP id n21so7589659ioo.10 for ; Thu, 06 Feb 2020 11:55:40 -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=7EJDgXJItKSHtBqDlGpPXjVpKLFySBu/jYXtj6UBSqk=; b=o2TJ5na94rRJqPrzLey6UhOyaQeCV+fXbL9oXrunqYSqw1pwJlDwE0G22NET61LtcX 71Y43oiTYDi6ldv8WMbqqKkoHJuW46Sb6CMXM1sgTSxOnwduZanEhmT7m7J/SefDAARM WME4XkeUq+Tjzu58vXSPJcs1J/nt7mk8T/Aw8hZHo5geX6yvkdIN0k4KQ3kFAvgFfJXu Tb0rOVdECcmuDt8vO8Dt+F+UW7zAygiLBmZsp75DS4xfoM8xyfxlrWpA1UfRV2j7EFCG PV/p2CV73wg1i6YzpM2OfI0FqGMDtCvk2tfrTvK17Su/oj8ajn6MIeK5YacgEwzw9kD0 2btg== 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=7EJDgXJItKSHtBqDlGpPXjVpKLFySBu/jYXtj6UBSqk=; b=dMonPL8eW8+y7Xc63f/y8UHWzRMcKWOr+vGPlSnaOod1tphWtzQVF/7qYKFx/tsqSS A3l21q/yUY9oKO2oeLyzO8yaJvxXzbpaduGY+n/DX7JKRm7Q4qSAE1V5wz3RINQvlGuR 87DjqtejAlOLjT7qili46MXD9Du2jGprcCVKpDsYSirJgEcMKiodz1ucXkb3IDM0+nrC 5VhSRlRsh5XoqRjiqiLFJfdLIsSWNjyiFpTJHkSSno/CsXG4+z3n6pFzqTTIuqp0LZ4S Q8TqS6eyC9AEz2Nsm/13Fhwgq+nIqYpFCpTP97imw22upJU7ZQFiY0rqHmqUiHfXo+Ln di3A== X-Gm-Message-State: APjAAAUE+6l4jsx211Owt6MM6AB9W3fCUQD1cDjaRUF7TB688xsmzy8a LQZSHTsyb84XVi0H32o43t3oRw== X-Google-Smtp-Source: APXvYqwQ64mS6HQ41I/nwk6tzAjLMk/IwBf+dBUv+mgTa6HnkXBxFKkS7atl+hATRkpB/LmRUwAIyA== X-Received: by 2002:a5e:8b03:: with SMTP id g3mr34012728iok.279.1581018939563; Thu, 06 Feb 2020 11:55:39 -0800 (PST) Received: from [192.168.1.159] ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id u10sm282505ilq.1.2020.02.06.11.55.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 06 Feb 2020 11:55:39 -0800 (PST) Subject: Re: io_uring: io_grab_files() misses taking files->count? To: Kirill Tkhai , LKML , io-uring@vger.kernel.org References: From: Jens Axboe Message-ID: Date: Thu, 6 Feb 2020 12:55:38 -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 9:32 AM, Kirill Tkhai wrote: > Hi, Jens, > > in io_grab_files() we take pointer to current->files without taking > files->count. Later, this files become attached to worker in > io_worker_handle_work() also without any manipulation with counter. > > But files->count is used for different optimizations. Say, in > expand_fdtable() we avoid synchonize_rcu() in case of there is only > files user. In case of there are more users, missing of > synchronize_rcu() is not safe. > > Is this correct? Or maybe there is some hidden logic in io_uring, > which prevents this problem? Say, IORING_OP_OPENAT/CLOSE/ETC can't be > propagated to worker etc... We track requests that grab files on the side, since we can't safely grab a reference to the file table. We could have our own ring fd in the file table, and thus create a circular reference if we incremented files->count here. Looks like we might need a 2nd way to know if we need to use synchronize_rcu() or not, though I need to look into this particular case. -- Jens Axboe