Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4940234ybv; Wed, 26 Feb 2020 05:42:18 -0800 (PST) X-Google-Smtp-Source: APXvYqw9qor/6gynyKvIeLeAfqUEbTOZFd4I9ZaUgdLVX6Bxn21TsBRu/hYXp4toVs3icbDrn+Sd X-Received: by 2002:aca:b9c2:: with SMTP id j185mr3019696oif.112.1582724537966; Wed, 26 Feb 2020 05:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582724537; cv=none; d=google.com; s=arc-20160816; b=ZWt6Gg0JcxuzD8i8dkJccllsC1Bxv8eE9Pv2i4RB9WWJ/2/5sV6z8Q9fW4+Q83Q2MF n4PQQlyY5oaMFty8YB0pTXNSJnoeyREifovsjBpQvUJD0w/GORVuhWi1QCHUN7YSJc3b CwQk8k8zw55nEt+9Y0j3zCUULgDYEBXfugQaqDfNrvBHAdZbQljqde0FPfFXWkYoQB9i 4pfGWKWmkF5TrJzOUPmulo7plgCIw93bpDoMDlqdOskgEDEB6wIeB4t8iLwpzREc5UqO TjGgxeBEqvSG8EH5EYXuXPobl6bRP6CdJ6PYvaV3tYC39CKvtLkCSwcaAx+vyxkm50RN mFIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:to:from:subject; bh=yXWtW+TLrSFZ6/b739M0UU9GWcw51419vSaeNpFbdys=; b=uXCINLm+DbwATpa1SxawnTeSgRAJqrt1s9x08nuhSMlY06mmJIth/ySa4hWvLP11FO rKUAemOLMOVs3Xv1NZUHTDmfYeG5GCMXNyE8E4G2j8hPxzXhxoym+OLi3NFg2WZ3xp8C BYa/JX9yosk2VwZ6YkVJdkrJnQ1G8Mn4nLtx/TFcWPY9wJ8Pgl/rtjEG0/tD+Kk/jeUy 94saFvamLW6ABauodPZ4XZNikTg9ZVB6Cxx+Jkq4v99wB1Gu3AjQ8224lkDM+ChU0m9h W1NCnaKc8m9MfSx2fUdGlW3ODEKyXfrgnl3P9J6xy7AiE0zpKd8WQ9fVaBN2l338Ygqt Q2EQ== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si1248199otp.25.2020.02.26.05.42.06; Wed, 26 Feb 2020 05:42:17 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727277AbgBZNlY (ORCPT + 99 others); Wed, 26 Feb 2020 08:41:24 -0500 Received: from relay.sw.ru ([185.231.240.75]:44730 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbgBZNlX (ORCPT ); Wed, 26 Feb 2020 08:41:23 -0500 Received: from dhcp-172-16-24-104.sw.ru ([172.16.24.104] helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.92.3) (envelope-from ) id 1j6wvx-0006rW-Gc; Wed, 26 Feb 2020 16:41:05 +0300 Subject: [PATCH RFC 3/5] fs: Add fallocate2() syscall From: Kirill Tkhai To: tytso@mit.edu, viro@zeniv.linux.org.uk, adilger.kernel@dilger.ca, snitzer@redhat.com, jack@suse.cz, ebiggers@google.com, riteshh@linux.ibm.com, krisman@collabora.com, surajjs@amazon.com, ktkhai@virtuozzo.com, dmonakhov@gmail.com, mbobrowski@mbobrowski.org, enwlinux@gmail.com, sblbir@amazon.com, khazhy@google.com, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Date: Wed, 26 Feb 2020 16:41:05 +0300 Message-ID: <158272446537.281342.16679772209236495407.stgit@localhost.localdomain> In-Reply-To: <158272427715.281342.10873281294835953645.stgit@localhost.localdomain> References: <158272427715.281342.10873281294835953645.stgit@localhost.localdomain> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This introduces a new syscall and propagates @physical there. Also, architecture-dependent definitions for x86 are added. Signed-off-by: Kirill Tkhai --- arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/x86/ia32/sys_ia32.c | 10 ++++++++++ fs/open.c | 16 +++++++++++++--- include/linux/syscalls.h | 8 +++++++- 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl index c17cb77eb150..62b3692df584 100644 --- a/arch/x86/entry/syscalls/syscall_32.tbl +++ b/arch/x86/entry/syscalls/syscall_32.tbl @@ -442,3 +442,4 @@ 435 i386 clone3 sys_clone3 __ia32_sys_clone3 437 i386 openat2 sys_openat2 __ia32_sys_openat2 438 i386 pidfd_getfd sys_pidfd_getfd __ia32_sys_pidfd_getfd +486 i386 fallocate2 sys_fallocate2 __ia32_compat_sys_x86_fallocate2 diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl index 44d510bc9b78..b106a39509ee 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 +486 common fallocate2 __x64_sys_fallocate2 # # x32-specific system call numbers start at 512 to avoid cache impact diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c index 21790307121e..1757bfe1a19c 100644 --- a/arch/x86/ia32/sys_ia32.c +++ b/arch/x86/ia32/sys_ia32.c @@ -230,6 +230,16 @@ COMPAT_SYSCALL_DEFINE6(x86_fallocate, int, fd, int, mode, ((u64)len_hi << 32) | len_lo); } +COMPAT_SYSCALL_DEFINE6(x86_fallocate2, int, fd, int, mode, + unsigned int, offset_lo, unsigned int, offset_hi, + unsigned int, len_lo, unsigned int, len_hi, + unsigned int physical_lo, unsigned int physical_hi) +{ + return ksys_fallocate2(fd, mode, ((u64)offset_hi << 32) | offset_lo, + ((u64)len_hi << 32) | len_lo, + ((u64)physical_hi << 32) | physical_lo); +} + /* * The 32-bit clone ABI is CONFIG_CLONE_BACKWARDS */ diff --git a/fs/open.c b/fs/open.c index 596fd3dc3988..1b964a37ecc2 100644 --- a/fs/open.c +++ b/fs/open.c @@ -290,6 +290,10 @@ int vfs_fallocate(struct file *file, int mode, if (ret) return ret; + if (physical != (u64)-1 && + !ns_capable(inode->i_sb->s_user_ns, CAP_FOWNER)) + return -EPERM; + if (S_ISFIFO(inode->i_mode)) return -ESPIPE; @@ -324,13 +328,13 @@ int vfs_fallocate(struct file *file, int mode, } EXPORT_SYMBOL_GPL(vfs_fallocate); -int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len) +int ksys_fallocate2(int fd, int mode, loff_t offset, loff_t len, u64 physical) { struct fd f = fdget(fd); int error = -EBADF; if (f.file) { - error = vfs_fallocate(f.file, mode, offset, len, (u64)-1); + error = vfs_fallocate(f.file, mode, offset, len, physical); fdput(f); } return error; @@ -338,7 +342,13 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len) SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len) { - return ksys_fallocate(fd, mode, offset, len); + return ksys_fallocate2(fd, mode, offset, len, (u64)-1); +} + +SYSCALL_DEFINE5(fallocate2, int, fd, int, mode, loff_t, offset, loff_t, len, + unsigned long long, physical) +{ + return ksys_fallocate2(fd, mode, offset, len, physical); } /* diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h index 1815065d52f3..1999493b03e9 100644 --- a/include/linux/syscalls.h +++ b/include/linux/syscalls.h @@ -427,6 +427,8 @@ asmlinkage long sys_truncate64(const char __user *path, loff_t length); asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length); #endif asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len); +asmlinkage long sys_fallocate2(int fd, int mode, loff_t offset, loff_t len, + unsigned long long physical); asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode); asmlinkage long sys_chdir(const char __user *filename); asmlinkage long sys_fchdir(unsigned int fd); @@ -1255,7 +1257,11 @@ ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count, loff_t pos); ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf, size_t count, loff_t pos); -int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len); +int ksys_fallocate2(int fd, int mode, loff_t offset, loff_t len, u64 physical); +static inline int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len) +{ + return ksys_fallocate2(fd, mode, offset, len, (u64)-1); +} #ifdef CONFIG_ADVISE_SYSCALLS int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice); #else