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=-14.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 1F446C433E0 for ; Fri, 12 Feb 2021 04:45:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EACEB64DCD for ; Fri, 12 Feb 2021 04:45:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbhBLEp3 (ORCPT ); Thu, 11 Feb 2021 23:45:29 -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-Google-Smtp-Source: ABdhPJzJ8v8dSTSVOML2sIt78PbLqD2VT6NK9LoWSGUmE8HEfFqP2J/kMV8nnkcPsdyrqXTVW649yQ== 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