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=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 59703C433DB for ; Mon, 25 Jan 2021 08:02:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F303522C9F for ; Mon, 25 Jan 2021 08:02:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727324AbhAYIAp (ORCPT ); Mon, 25 Jan 2021 03:00:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727236AbhAYH4l (ORCPT ); Mon, 25 Jan 2021 02:56:41 -0500 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1134C0613ED for ; Sun, 24 Jan 2021 23:54:43 -0800 (PST) Received: by mail-vs1-xe2e.google.com with SMTP id 186so6676243vsz.13 for ; Sun, 24 Jan 2021 23:54:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:from:date:message-id:subject:to:cc; bh=shLCHFFMB4DAp0A0ILgc+eh2S2wXCYfyelqnf4KL6us=; b=Px9KUJsGwJ+VtNulQrpo/gNubEPUdjzL9axWZwpaxfB/oLoVrtc0t1GYJCMzKHcXDV 9l6qQIgZcF4L1+IAccLk1ZVIAxm/s0IaiWoE+lC4RDtEB8AVaSimH+KNn/RfinTLPu3C fQeytqMsM3ShLU1d/TSI7rWDnJmmkSacvXy3k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=shLCHFFMB4DAp0A0ILgc+eh2S2wXCYfyelqnf4KL6us=; b=Eg0ER09SVsyB8RhpAdvDO1gjoNIBlyGGq6rU3BWZcYUZrpVFlykZkksLKWr9nHDhHI G8r7h1XyPRBBzd2O5KYIH6fnS0D44MO1PyMI1/69WD4YWFsm0dH8USKOqNc4loJqHENt 0P9ZZhJ4bJdX7dR1hgxpCSAzxr4Mo2hlVOogB756YN/sdeINmo3lKE/Urke6HkhSB+d1 yQpJMeIl3B10KRLV4mCcZcOba2zwwYXETMuWFQqNWPxUDqCwWxxYh1YqcEv8CufYM40D 2RVUp0g5OKniVMtkYtDSfZqA7pLiNZo+lR3R0DYXsmho86VFRY/tSlPSILD3oLcLD0oK ohBw== X-Gm-Message-State: AOAM530iqP1cNtnH7RW+verG4RHWs7PzIl7we7XWwMcIjREAEZnXtqQn 5geV1QyW0ozrefn2fIyioxkLBUKhFS9ugExW20r+XA== X-Google-Smtp-Source: ABdhPJxq6uXHnDY4RVG3ffjbpATtyupiGISReVdidQGDUJdMst+TXrrJKK/Vy7bMu/1qDhBMrWXBpYi1MsH/3SjYMfE= X-Received: by 2002:a67:6b46:: with SMTP id g67mr4296vsc.60.1611561282606; Sun, 24 Jan 2021 23:54:42 -0800 (PST) MIME-Version: 1.0 From: Nicolas Boichat Date: Mon, 25 Jan 2021 15:54:31 +0800 Message-ID: Subject: [BUG] copy_file_range with sysfs file as input To: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, lkml , Amir Goldstein , Dave Chinner Cc: Luis Lozano , iant@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi copy_file_range experts, We hit this interesting issue when upgrading Go compiler from 1.13 to 1.15 [1]. Basically we use Go's `io.Copy` to copy the content of `/sys/kernel/debug/tracing/trace` to a temporary file. Under the hood, Go now uses `copy_file_range` syscall to optimize the copy operation. However, that fails to copy any content when the input file is from sysfs/tracefs, with an apparent size of 0 (but there is still content when you `cat` it, of course). A repro case is available in comment7 (adapted from the man page), also copied below [2]. Output looks like this (on kernels 5.4.89 (chromeos), 5.7.17 and 5.10.3 (chromeos)) $ ./copyfrom /sys/kernel/debug/tracing/trace x 0 bytes copied $ cat x $ cat /sys/kernel/debug/tracing/trace # tracer: nop # # entries-in-buffer/entries-written: 0/0 #P:8 # # _-----=> irqs-off # / _----=> need-resched # | / _---=> hardirq/softirq # || / _--=> preempt-depth # ||| / delay # TASK-PID CPU# |||| TIMESTAMP FUNCTION # | | | |||| | | I can try to dig further, but thought you'd like to get a bug report as soon as possible. Thanks, Nicolas [1] http://issuetracker.google.com/issues/178332739 [2] #define _GNU_SOURCE #include #include #include #include #include #include int main(int argc, char **argv) { int fd_in, fd_out; loff_t ret; if (argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(EXIT_FAILURE); } fd_in = open(argv[1], O_RDONLY); if (fd_in == -1) { perror("open (argv[1])"); exit(EXIT_FAILURE); } fd_out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644); if (fd_out == -1) { perror("open (argv[2])"); exit(EXIT_FAILURE); } ret = copy_file_range(fd_in, NULL, fd_out, NULL, 1024, 0); if (ret == -1) { perror("copy_file_range"); exit(EXIT_FAILURE); } printf("%d bytes copied\n", (int)ret); close(fd_in); close(fd_out); exit(EXIT_SUCCESS); }