Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3387092ybf; Tue, 3 Mar 2020 05:09:56 -0800 (PST) X-Google-Smtp-Source: ADFU+vv49jwAN9SeQmXiM3njwC0AQcMcv/zdLKwjNYV0zXunajkD8Hk3Yz2Gg1NY7+exIbO9eOVq X-Received: by 2002:aca:ed94:: with SMTP id l142mr2431646oih.58.1583240996820; Tue, 03 Mar 2020 05:09:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583240996; cv=none; d=google.com; s=arc-20160816; b=EhnNLPVFtXUgue423v/N6uDMYc7C/UwuvlvO3ofNIJZOVSKu0e1FBj8smHDkKoPjFq QJRlLW6xztmXfSspByK+5AZlORQHuFPCsspZcMSamWpWc9B3pzC0e/JQ1+7/zPUlFiTW AeWgb+XqpFAa00Mzf+fJV9FDMj1TZcELJEbCsHu3Dkyi3/bPV/vPlMmrecL6t09G9SwH fj2KcS3U+D/lH+of8J6puxvwP9e0GnKXM4K7Sf8TYLlm6T6uYXBRoOFgNueg7jR2R2q0 aD4Fu9GKtcw5MvTUa2uAz6Z/YBSGKFxh+wXRulRL6MBFZESyFbha9DJUGsIoihL5y8wU O4Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=YXFrIcqb5SuMTJIbFZM/SDCtnyxRtqn68RkQFM+tlus=; b=SiEuEhqXr/PZQVP147I5JN0ELlHZPEo/OogWa9vbYErfE/RQtCjFPUmkAybkVhEELT TUg9HwkFhuAnV5NVoS7PO9CrcT3FypBW0qx2RKbhuiim9WipgB+4df6FNPbZOyGt/7Eo xPMhRi8GixnO+8JSl109dbJw1KDHpi9uSicEQ7qOp7Ei/FfzBWq1iRQdDeHdBkq/f/XP 6JNsj0G2zuQhEAv6XFWkcrF3fZ1TG5x9iVYYU0dH9vWZRBttEsM6jqK0BmKTMtu9WEOe QW7zbdUQpJNlsQua06WNIl97SpRAcC3Qsy09BxCyeaLxBa4WFoOVxr0/gYP08cFV+0ti wV4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HGZKD28d; 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 f184si1763949oig.212.2020.03.03.05.09.42; Tue, 03 Mar 2020 05:09:56 -0800 (PST) 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=@kernel.org header.s=default header.b=HGZKD28d; 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 S1729264AbgCCNDv (ORCPT + 99 others); Tue, 3 Mar 2020 08:03:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:49700 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729249AbgCCNDu (ORCPT ); Tue, 3 Mar 2020 08:03:50 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 36E6D20866; Tue, 3 Mar 2020 13:03:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583240629; bh=f5TALLM7M04mw4MFMI6suvBwcBH6Hd4opudh07oYOZ4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HGZKD28dn34LE53PY7JnKdnnaep5PxSNdTqI9Rf14XPqJI6mRPHPh6qiVXbKKyccK Cs5GgBp32G+tzfpxv+05TCf4nQAoKK71wdKCP/p860chfn/v9IsbG7IAEwh+XTdJig iBvKRptwEaPe33EjTDzrITZpsidZvqdzKAdmvw2g= Date: Tue, 3 Mar 2020 14:03:47 +0100 From: Greg Kroah-Hartman To: Karel Zak Cc: Miklos Szeredi , David Howells , Ian Kent , Christian Brauner , James Bottomley , Steven Whitehouse , Miklos Szeredi , viro , Christian Brauner , Jann Horn , "Darrick J. Wong" , Linux API , linux-fsdevel , lkml Subject: Re: [PATCH 00/17] VFS: Filesystem information and notifications [ver #17] Message-ID: <20200303130347.GA2302029@kroah.com> References: <1582644535.3361.8.camel@HansenPartnership.com> <20200228155244.k4h4hz3dqhl7q7ks@wittgenstein> <107666.1582907766@warthog.procyon.org.uk> <0403cda7345e34c800eec8e2870a1917a8c07e5c.camel@themaw.net> <1509948.1583226773@warthog.procyon.org.uk> <20200303113814.rsqhljkch6tgorpu@ws.net.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200303113814.rsqhljkch6tgorpu@ws.net.home> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 03, 2020 at 12:38:14PM +0100, Karel Zak wrote: > On Tue, Mar 03, 2020 at 10:26:21AM +0100, Miklos Szeredi wrote: > > No, I don't think this is going to be a performance issue at all, but > > if anything we could introduce a syscall > > > > ssize_t readfile(int dfd, const char *path, char *buf, size_t > > bufsize, int flags); > > off-topic, but I'll buy you many many beers if you implement it ;-), > because open + read + close is pretty common for /sys and /proc in > many userspace tools; for example ps, top, lsblk, lsmem, lsns, udevd > etc. is all about it. Unlimited beers for a 21-line kernel patch? Sign me up! Totally untested, barely compiled patch below. Actually, I like this idea (the syscall, not just the unlimited beers). Maybe this could make a lot of sense, I'll write some actual tests for it now that syscalls are getting "heavy" again due to CPU vendors finally paying the price for their madness... thanks, greg k-h ------------------- diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index 44d510bc9b78..178cd45340e2 100644 --- a/arch/x86/entry/syscalls/syscall_64.tbl +++ b/arch/x86/entry/syscalls/syscall_64.tbl @@ -359,6 +359,7 @@ 435 common clone3 __x64_sys_clone3/ptregs 437 common openat2 __x64_sys_openat2 438 common pidfd_getfd __x64_sys_pidfd_getfd +439 common readfile __x86_sys_readfile # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/fs/open.c b/fs/open.c index 0788b3715731..1a830fada750 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1340,3 +1340,23 @@ int stream_open(struct inode *inode, struct file *filp) } EXPORT_SYMBOL(stream_open); + +SYSCALL_DEFINE5(readfile, int, dfd, const char __user *, filename, + char __user *, buffer, size_t, bufsize, int, flags) +{ + int retval; + int fd; + + if (force_o_largefile()) + flags |= O_LARGEFILE; + + fd = do_sys_open(dfd, filename, flags, O_RDONLY); + if (fd <= 0) + return fd; + + retval = ksys_read(fd, buffer, bufsize); + + __close_fd(current->files, fd); + + return retval; +}