Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2679598pxb; Thu, 11 Feb 2021 20:46:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmgYJS1nQIyHyIEs0OHmGewu+NzKCP8KeJ2oz7lWpN3RCGQnjGhIPdwxa0PallNWTSULR8 X-Received: by 2002:a17:907:770d:: with SMTP id kw13mr1195573ejc.219.1613105176817; Thu, 11 Feb 2021 20:46:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613105176; cv=none; d=google.com; s=arc-20160816; b=0skfQLLBK39c6VtCqpPzM9fo4vPAfVAbrom1lv7NMkBZsJuQgzMbqkAHltVfzdr+pu Rt8odxxX+i1+22KetAkSJ8Qx49qdSWhMFtWYyGGi9fWB2RWg2USNpmP4eOd/7QBSixKi p2m8sqgDGgXuSjG9UU3POD/tI3Gxv6nEkUKo9kts7c669dssIOcFUFcbEdrKyamDUYkj 9W3VgnuKGo119ELq4gekVcUukfFs6U5B+XNjUCAmXLctV2Hv1No59kUjEWoUluKcZ7W/ H/9mTUhr6TGazoTpwvNDP+vIHhpDJncCkXfvBm0HsmGvxJljFS62efDIR3Usl9geQ/yI ymDw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=meg9sC7YyyK/ccxHauwvbjLk6iFrdpEJaLlXNYNQrRw=; b=sQKILuiq2pE2pnIjwUFhr1MIq6IiGibbqux+8N+svhQ99FQYWINSLIjh2Z39NuTEhq +sf0ccN3Hv3H0VxFijSMmKLXALY5SIFNgDFS5tPPOBKiRSPfFRkjBWjmnZNdrttAIpQP 5gPABCapiq//9AcXi9oedlaZhcvbK7zR7mFHfVhOBqFVyMZb6VH59/04g5GImZwL6bVm aVfglWOcOzRB5KhHq4VURaQxlZUsr25sApjcbZ71u9s1WZg9eieh0zZJjd2Kv/nVpQLw rYkTAW6JxrwNorPe6Z5dFcfXooime2aRjXJ3cawJlSyzwkgYVp9xGgA4woClT/ZK6tc2 6r9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=j71D5TPJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dn20si5806004ejc.418.2021.02.11.20.45.53; Thu, 11 Feb 2021 20:46:16 -0800 (PST) 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=@chromium.org header.s=google header.b=j71D5TPJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229493AbhBLEp0 (ORCPT + 99 others); Thu, 11 Feb 2021 23:45:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbhBLEpX (ORCPT ); Thu, 11 Feb 2021 23:45:23 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8C6C061756 for ; Thu, 11 Feb 2021 20:44:43 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id m6so5098690pfk.1 for ; Thu, 11 Feb 2021 20:44:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=meg9sC7YyyK/ccxHauwvbjLk6iFrdpEJaLlXNYNQrRw=; b=j71D5TPJlB5a96J93TSXkpENx3ekgcrGWmn1JZtNQhnqd2Mge7An6OhBb5P8TnUMZQ 4OUadpA2+MJX9QKhG3n8gr0GKnHyeVCl4h2ODUFy+jbH8WgKbmv8HqUeXBekYqVqcTHV xS2DhrwxhEz9TIoS7Zn9TTVKi4LDipZ1HBq4s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=meg9sC7YyyK/ccxHauwvbjLk6iFrdpEJaLlXNYNQrRw=; b=blAJLoz9jdYLrEnScHYVXXLnY/85ggL/vjm6xVgB/cvcMVGahflVxgabkGeANMv2V0 T1kysT/qDmkaw64ctWZ4r/TZbcGzL8bD1jzZIwCiswGtUjWMLiwvdSxiWB09Zc2o3qDz n6kPT/vzzilHbq/qp/huQvdnNTrw+up9B/mQtBsefa9RurUbmz7OU8Qu1NVKdpeNf0GQ y7FF5TmrCc1LIgUIf9yK25Fqio3wmtqKLbXeUlN3BfWAXmFaF1bkA26S2fJA6KnkB7+W LqGUCKuIwI0wt/dr1o0qidYC4DLWDZobkWKU+xEcvINVYIHqQ4GkNS6u0cj8l73hA2mt bd6w== X-Gm-Message-State: AOAM531tAS6r2ZojxoPR1IO+SLf4hj4/K5T2VuaZVwx9xnV2Z03tM1Lf iGYEjZe5AI2GiCY20nqPQ/e3hw== X-Received: by 2002:a63:1845:: with SMTP id 5mr1499499pgy.244.1613105082790; Thu, 11 Feb 2021 20:44:42 -0800 (PST) Received: from drinkcat2.tpe.corp.google.com ([2401:fa00:1:b:a453:d6cd:41b9:5925]) by smtp.gmail.com with ESMTPSA id 25sm7298904pfh.199.2021.02.11.20.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 20:44:42 -0800 (PST) From: Nicolas Boichat To: "Darrick J . Wong" Cc: Alexander Viro , Ian Lance Taylor , Luis Lozano , Greg KH , Dave Chinner , Nicolas Boichat , Alexey Dobriyan , Alexey Gladkov , Christian Brauner , "Eric W. Biederman" , Ingo Molnar , Kees Cook , "Rafael J. Wysocki" , Steven Rostedt , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 0/6] Add generated flag to filesystem struct to block copy_file_range Date: Fri, 12 Feb 2021 12:43:59 +0800 Message-Id: <20210212044405.4120619-1-drinkcat@chromium.org> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We hit an issue when upgrading Go compiler from 1.13 to 1.15 [1], as we use Go's `io.Copy` to copy the content of `/sys/kernel/debug/tracing/trace` to a temporary file. Under the hood, Go 1.15 uses `copy_file_range` syscall to optimize the copy operation. However, that fails to copy any content when the input file is from tracefs, with an apparent size of 0 (but there is still content when you `cat` it, of course). From discussions in [2][3], it is clear that copy_file_range cannot be properly implemented on filesystems where the content is generated at runtime: the file size is incorrect (because it is unknown before the content is generated), and seeking in such files (as required by partial writes) is unlikely to work correctly. With this patch, Go's `io.Copy` gracefully falls back to a normal read/write file copy. I'm not 100% sure which stable tree this should go in, I'd say at least >=5.3 since this is what introduced support for cross-filesystem copy_file_range (and where most users are somewhat likely to hit this issue). But let's discuss the patch series first. [1] http://issuetracker.google.com/issues/178332739 [2] https://lkml.org/lkml/2021/1/25/64 [3] https://lkml.org/lkml/2021/1/26/1736 Nicolas Boichat (6): fs: Add flag to file_system_type to indicate content is generated proc: Add FS_GENERATED_CONTENT to filesystem flags sysfs: Add FS_GENERATED_CONTENT to filesystem flags debugfs: Add FS_GENERATED_CONTENT to filesystem flags tracefs: Add FS_GENERATED_CONTENT to filesystem flags vfs: Disallow copy_file_range on generated file systems fs/debugfs/inode.c | 1 + fs/proc/root.c | 2 +- fs/read_write.c | 3 +++ fs/sysfs/mount.c | 2 +- fs/tracefs/inode.c | 1 + include/linux/fs.h | 1 + 6 files changed, 8 insertions(+), 2 deletions(-) -- 2.30.0.478.g8a0d178c01-goog