Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5973597yba; Thu, 11 Apr 2019 09:24:52 -0700 (PDT) X-Google-Smtp-Source: APXvYqxfle3D2CJQLw7X4V5tEBFFE4aSf6lYcN1ru/Xw8rpCFwFaI+Fgo4MLJtegS6NKZ6sI3gwV X-Received: by 2002:aa7:90ca:: with SMTP id k10mr50956130pfk.144.1554999891961; Thu, 11 Apr 2019 09:24:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554999891; cv=none; d=google.com; s=arc-20160816; b=Py5qHkJVHtLCW5N4AbUJ5J1PYX9jNPVhAT22G4ccXP3OCddoAEDF0QVM5ouP57lBti 9EPJKxNX0znELyJ/ZT5IUnUDOTi3kTu8E4UzZagZhtyR8mW+Yzwhq4CZRbYiYCqLlHBA jjTdmtZdtUB3BfN30foIJDfk/zJIelJZXfliFi0D4PP/vrR62/csNqkSgNLTQbmHruQS wBCQzhauemOz+7E+Fzh7Nay4G8TwK1miSJgefRrkvvjUigguHoebbSDv1H+IYO4D6iz+ vkQDtGe07seFFyGKx69cf+cwM5nB3gjj/CQleT1U2MCUSinVyZ4/MxQsCXm2n8yCebaD tdyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=SQG3fAkiUV20bO26Ld6sJCHOpwS1q4hdpfdFqRoHxoM=; b=AhkuizGEfT98afHQB2gnSKrD97snVVOgG26CTlQRxzvTSIkco+KIIA/Ig8/ebIuV58 mue+WtrSvy2Be2859ld7PPGQQRxghOrk0kx9abGeR5461N2UG6sbivi1NCTCYtC/pk+O D0vYmZJnsyjU6FVRl6txuBqaNSc+J1AowRc8TSKQI32S2QbEFFTRWq4bjzNEexcSLy/B N/xugjCJwMMzOBNjc3VegqRXa3ouOA3ASDAsdK6bfP8TXylPZ3AujDNzO2PJ3/M9EX0f /xCNcu0Nvmh2aWVdGCS1i9pIB87KfCpw8yujqxzcVSyqE+dP6RpP7B8XgAdPasGXDCov BuPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=Z0Q1fOHS; 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 b40si35244631pla.277.2019.04.11.09.24.36; Thu, 11 Apr 2019 09:24:51 -0700 (PDT) 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=@linux-foundation.org header.s=google header.b=Z0Q1fOHS; 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 S1726856AbfDKQXU (ORCPT + 99 others); Thu, 11 Apr 2019 12:23:20 -0400 Received: from mail-lf1-f67.google.com ([209.85.167.67]:35539 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726773AbfDKQXU (ORCPT ); Thu, 11 Apr 2019 12:23:20 -0400 Received: by mail-lf1-f67.google.com with SMTP id u21so5197577lfu.2 for ; Thu, 11 Apr 2019 09:23:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=SQG3fAkiUV20bO26Ld6sJCHOpwS1q4hdpfdFqRoHxoM=; b=Z0Q1fOHSPCHOhBg1JKd5iEmmQ0/jsnNt7NEQOMpZAIi6DdydVfjj6QnQaEXX8Gz+7s YA+8bHIkuUumGy6mZX/ZcdzE9pt3vuwrZDx20oUfvX5bVG0wUueotFvbNY6WU+TbLZyz Wi3ZJegqCN6RjJ9Nr2IbBVaSy0zQ/mtMc35l4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SQG3fAkiUV20bO26Ld6sJCHOpwS1q4hdpfdFqRoHxoM=; b=lafeijIsMCaZo1LaSR3p5FJnoB7Z4teiFKy1wyiyLxx6WCeYyZd/yDlv211/vvwAYb ukqM+17+HyQ5BuPuF6S9x54x9gERvJhB6e7Dg28qKLHm45qgM9NmytNpzzGjEOiWRPix c0Ck6vyzFCrTiX7vvccAzXEDmnQ41obeEv6YWcGneI7cJPOq8Wzuk7i3AQCEjU+IyYKX xMRCUvBJTvFv3DZU9Jj4CBMVER5RmJ87g7pDVGS65fb5tPLnZSCadXOLyGqXvlwfrolq c2LxmkhBVWycdslgrhDvPuO0NbSdsxttLhgcpFCDa1Y41BNnes04JgxEu0XKSdUX+8Yc iZmA== X-Gm-Message-State: APjAAAWH+wQrdGS9M1uszJqKR4YTY5nXyEM37vXxkXH5hNgNkFMfOysc 52tQxckTBHAKJBkCv9GdHhxJSkPD6II= X-Received: by 2002:a19:2d57:: with SMTP id t23mr6437198lft.99.1554999797881; Thu, 11 Apr 2019 09:23:17 -0700 (PDT) Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com. [209.85.167.46]) by smtp.gmail.com with ESMTPSA id g24sm7683159lfb.49.2019.04.11.09.23.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Apr 2019 09:23:13 -0700 (PDT) Received: by mail-lf1-f46.google.com with SMTP id o19so838372lfl.4 for ; Thu, 11 Apr 2019 09:23:13 -0700 (PDT) X-Received: by 2002:a19:a40b:: with SMTP id q11mr27540073lfc.33.1554999793169; Thu, 11 Apr 2019 09:23:13 -0700 (PDT) MIME-Version: 1.0 References: <4c4651e2-167e-bfcc-7b3e-cda118f98a69@rasmusvillemoes.dk> <20190409203807.GA13855@deco.navytux.spb.ru> <20190411123816.GA18309@deco.navytux.spb.ru> In-Reply-To: <20190411123816.GA18309@deco.navytux.spb.ru> From: Linus Torvalds Date: Thu, 11 Apr 2019 09:22:56 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/3] fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock To: Kirill Smelkov Cc: Rasmus Villemoes , Al Viro , Arnd Bergmann , Christoph Hellwig , Greg Kroah-Hartman , linux-fsdevel , Linux List Kernel Mailing Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 11, 2019 at 5:38 AM Kirill Smelkov wrote: > > However file->f_pos writing is still there and it will bug under race > detector, e.g. under KTSAN because read and write can be running > simultaneously. Maybe it is not only race bug, but also a bit of > slowdown as read and write code paths write to the same memory thus > needing inter-cpu synchronization if read and write handlers are on > different cpus. However for this I'm not sure. I doubt it's noticeable, but it would probably be good to simply not do the write for streams. That *could* be done somewhat similarly, with just changing th address to be updated, or course. In fact, we *used* to (long ago) pass in the address of "file->f_pos" itself to the low-level read/write routines. We then changed it to do that indirection through a local copy of pos (and file_pos_read/file_pos_write) because we didn't do the proper locking, so different read/write versions could mess with each other (and with lseek). But one of the things that commit 9c225f2655e36 ("vfs: atomic f_pos accesses as per POSIX") did was to add the proper locking at least for the cases that we care about deeply, so we *could* say that we have three cases: - FMODE_ATOMIC_POS: properly locked, - FMODE_STREAM: no pos at all - otherwise a "mostly don't care - don't mix!" and so we could go back to not copying the pos at all, and instead do something like loff_t *ppos = f.file->f_mode & FMODE_STREAM ? NULL : &file->f_pos; ret = vfs_write(f.file, buf, count, ppos); and perhaps have a long-term plan to try to get rid of the "don't mix" case entirely (ie "if you use f_pos, then we'll do the proper locking") (The above is obviously surrounded by the fdget_pos()/fdput_pos() that implements the locking decision). Linus