Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3296095pxb; Mon, 25 Jan 2021 11:57:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHTiGOed19qrrJx31RPB76DoZ7/7uf5wDULy3vrFkFU0MxVRZbzOb3cYHemcgidziqewUM X-Received: by 2002:a50:e0c1:: with SMTP id j1mr1816216edl.253.1611604668446; Mon, 25 Jan 2021 11:57:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611604668; cv=none; d=google.com; s=arc-20160816; b=CpkopTfvL2gQI8t+18+m6L9LMJki/6fJzpNg8PxY/2qkBmJAPiPHyBDEnaXoiSEck/ UdCh7MqCQNeBiywj/Vpe+bWpXcJntLeonEEDMGTu15AFrV5/TY69PdZ1CPMy54woQ6rL pKkGyCwVyxzcSN2Khxjuiuj0jaS5f52LTq4HWwxYXMiDltpfn6dpzvlwTBAAHEtwiG3e 7PxLEHOwCyoOgq037G5Do/uiqOoP38+vlr6e+yQ063FJQlX6xQ02mf7eDkDsTTEc4zqf /+/+Hvr2Lna67uNpJuQvogRc99CJHK9J+9shZDe6Op7HyjzKQRiUrFlsqeq2RPUBd5yd DnsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=3WM7O3cFXlBvf9L+JSljulU1VqAKIV6MOBvv4sGCgAo=; b=0bmO93yXh2XsYJCbFPyi0QrRsN0gnChX+JLsHS0KOCT7ll6pyMlAG8ugYA7iy+hGQc oxtg//s96HPwlOlk15n8ouwZwlrqdWxhqPTpZlMOR+PWgUFIXokMh3bdPaEgLRffJrUD y7J1NjXC9md1in+pWJvHOMmaaB9bVS8/sMJzpK+WoH55s7SbS7Amg/Zs7aXIzP69iU2C tcFvP/veyYXflIWMfPNszvfh+IJQT6v59+qdk9GWhKMigD18sjEIOEB3jDyqGdHTISD0 iU+2LStQFoYH01JaApUkmgDbVWXUnRFufj/xKpbEyN6dgVzVbmWz6Ay5CPXnrI22je8P 9L5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=bE4C3quK; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si6239940ejh.668.2021.01.25.11.57.22; Mon, 25 Jan 2021 11:57:48 -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=@google.com header.s=20161025 header.b=bE4C3quK; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726157AbhAYT4o (ORCPT + 99 others); Mon, 25 Jan 2021 14:56:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731978AbhAYTpg (ORCPT ); Mon, 25 Jan 2021 14:45:36 -0500 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7E9AC061756 for ; Mon, 25 Jan 2021 11:44:54 -0800 (PST) Received: by mail-lj1-x22d.google.com with SMTP id a25so15680131ljn.0 for ; Mon, 25 Jan 2021 11:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=3WM7O3cFXlBvf9L+JSljulU1VqAKIV6MOBvv4sGCgAo=; b=bE4C3quK2HDDkj26kdNPWzzjWPJqC6vm0bloEDWUNyPFOUw/Hd2xJAzElEcs8nGEg0 EjlC6Ers2ip8/6SQHU3BfPgXJM9zl4IGrcNx1WGwJze+7ej4FV4Lwr5QEsWkvkP0Ydpz 1gHgEYj3p4d1BRXNyDsqZIkpi2texxN2333flJWGLuH/ZPiYmgXthyLOVooPEUUAkV9t 3uMpIAsEfp6vEIj/zp0NgPom2Jfw2M36H8u0aNZ2jQStbcM6FMY2BdEFpuQOBw1TGqZS SB2KRxzk39vpuVtDPgtykyA7wthBxIlUvsP4/w6PDgG7PoD0Y+mqzDisdSv88bGGEL4h vFTg== 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=3WM7O3cFXlBvf9L+JSljulU1VqAKIV6MOBvv4sGCgAo=; b=HuoG2l4zUHf2JGkSQs1tg1UV+p0k5rV30IUsvzVA68hvhYB1/SjYTZZp0rLq1c9X8q jcSnXRAT3M97iCYvr6jk9NP88+dCTEOpQyHp+y+HxkxK6Hcq4WGMD3Gbpw/soY/X8+Uw i/wFn3xT85lZBCSTqknTF2WGhnBra4PBNFaMB+XejkMqcPq3aLUIirYx+P6Lk5pp+6vs nlk7RA2Ql/N+ZzNCkmlGdg9A0ahPYnV32uaqbqWTLvIDzf7P0yXiefMLpnl8xi/StnI5 BWROMbOFDgn2T+zuecHQw+l48ixDXx3rIjOuP21r6TGnDAxjSsZizHukist+Ka3WccWo KSoA== X-Gm-Message-State: AOAM532AsYEyipGuKe40fbivfmAoR6DFgQeSaMDtk8nCukRzg96qyzIG g10g5pUgnLvdU8WLY2Gu+BxbPTdf7vUalckpBAXcyg== X-Received: by 2002:a2e:8005:: with SMTP id j5mr979607ljg.34.1611603893145; Mon, 25 Jan 2021 11:44:53 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ian Lance Taylor Date: Mon, 25 Jan 2021 11:44:39 -0800 Message-ID: Subject: Re: [BUG] copy_file_range with sysfs file as input To: Nicolas Boichat Cc: "Darrick J. Wong" , linux-fsdevel@vger.kernel.org, lkml , Amir Goldstein , Dave Chinner , Luis Lozano Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thanks for the note. I'm not a kernel developer, but to me this sounds like a kernel bug. It seems particularly unfortunate that copy_file_range returns 0 in this case. From the perspective of the Go standard library, what we would need is some mechanism to detect when the copy_file_range system call will not or did not work correctly. As the biggest hammer, we currently only call copy_file_range on kernel versions 5.3 and newer. We can bump that requirement if necessary. Please feel free to open a bug about this at https://golang.org/issue, but we'll need guidance as to what we should do to avoid the problem. Thanks. Ian On Sun, Jan 24, 2021 at 11:54 PM Nicolas Boichat wrote: > > 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); > }