From patchwork Tue Oct 16 03:19:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10642937 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CEC117D2 for ; Tue, 16 Oct 2018 03:20:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76F9929AA8 for ; Tue, 16 Oct 2018 03:20:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A4A029B48; Tue, 16 Oct 2018 03:20:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 512DF29AA8 for ; Tue, 16 Oct 2018 03:20:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 021CE6B0280; Mon, 15 Oct 2018 23:20:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F125F6B0282; Mon, 15 Oct 2018 23:20:01 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E034D6B0283; Mon, 15 Oct 2018 23:20:01 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by kanga.kvack.org (Postfix) with ESMTP id 9D36C6B0280 for ; Mon, 15 Oct 2018 23:20:01 -0400 (EDT) Received: by mail-pg1-f197.google.com with SMTP id e6-v6so16117803pge.5 for ; Mon, 15 Oct 2018 20:20:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:subject:from:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-transfer-encoding; bh=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=dreV39YE5htxEkaQ6C+BYgX60ClipVuj1LZL6c1LgiI5BkuAqut60UgaC2ZY9OXuOD HS/oEMlEkahbgrMSEHYXY5woqGV1VvEcs2a5NlA8whXnkaNbmre/R9pT6IHiJaRpUKLM RwI9KZOPTFqwcEWxsADUgu/BtOdvEcJ31NeKF5iv/JCZX3qqEaJiuAyQgfpwY19xtsRO 54xPA87zr/6+LF1h9vgCfeF6Vpq3WdvibW56EJ1xcusO6Vw0vmPUoTAqj1qIZtkxhaH0 TTQXT1QzX02aVcR5NEatMxtSVkXkJPBKq1pWmxYrCrdAhBfovNd2F1pgQTBWh17e74qJ V4lg== X-Gm-Message-State: ABuFfohZcJFgx89qIkEWBK7K2ZoVFaPuOz1cczjzbSkVfAwfnrtmxgIh 39HehXW2NzViLiodQG3YNcrT54aOh8IC3n8BgN4vYDTjNluFPHHJ+P9npW5IwFeXLd5BFiQEQeW UYTOmYNZ59FbjSIGnLqX4U4IZwdvr1B1z3ZSBbNHIVy16fSezfgjA++mLJphpF6sGdw== X-Received: by 2002:a63:2e47:: with SMTP id u68-v6mr18778965pgu.294.1539660001305; Mon, 15 Oct 2018 20:20:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV60pAmJEQ8AmJvc3lOg99v8alRBlvoghQg6FZk6VZYisJBdgH5Z43sYqRK5FeanQICDKnIU2 X-Received: by 2002:a63:2e47:: with SMTP id u68-v6mr18778926pgu.294.1539660000418; Mon, 15 Oct 2018 20:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539660000; cv=none; d=google.com; s=arc-20160816; b=CHnEn2b4wVCdhSampHF7JHZlV9twE71NyCqaf45uN7qPdH760mKLNCDyMTSDGT2BB/ l9RI+GiPiIha2JaPFEuI4uucecUkHQ0luNIsPXTpqPShSviFfB/EwC3UCtIPSDfO1/Tg 32Uh7rENbExfa9eL8wkrSz5ei/TlAsTQVq/v4uoJ4hkL3xMmTfec6XeUJGpXy1JHCq3O hceMs61Qt9aVZA9Iugnghp3PdK/dD9O0cpz0g09YaCnr8OjAnwXTafH3rWaLDZ1vaNgs dRbBR2JP1bufa/MY/K4VFZ3jxcPPdo4mYReY/790btjCbO1cCaaWeYIhkUSKSJItFm3D KLrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:message-id:date:cc:to:from:subject:dkim-signature; bh=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=fyvgi544prG0ZuyNtk1cgzGBJya+WQ2PbFpQNkGDR8o+RsBk41EY5CfkWCh5JM6u7K mNaCHxPY/Ies9cnpqwaM/3gvaxAhxpbLcEd50B76h5TYmnC+ybDnfdNjW3gdSsxl5pDM +G2UWsVe3jgapd/XGWZJa8eN8MgkP9jxeKFGcsYYgu1m4iWRD4/vggLsif54smIK+r3X lJQ+PRNR0NxqQgaA2OkXsZ5cE+3+z7qtCT3fldAJbvEV6KB8Ygd+bVbiI1hN0VFTIPKS 5TKXv70V0YR29lh24VFig+SZSvdBVNni/H08c6myz9cOlhbOPqwGLRNsHRiqyVxMhCnC 0mxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=u0a1psOV; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from userp2130.oracle.com (userp2130.oracle.com. [156.151.31.86]) by mx.google.com with ESMTPS id m63-v6si11832523pld.379.2018.10.15.20.20.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Oct 2018 20:20:00 -0700 (PDT) Received-SPF: pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) client-ip=156.151.31.86; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=u0a1psOV; spf=pass (google.com: domain of darrick.wong@oracle.com designates 156.151.31.86 as permitted sender) smtp.mailfrom=darrick.wong@oracle.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w9G3J8UF051365; Tue, 16 Oct 2018 03:19:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=SxxelvM9Mhs/thMFIyphjK7HMbNrvjZhnvUfpeQTw9o=; b=u0a1psOVYfQuU0VE0ParteRBbVJ7OAR5sMDVRQqSrnJRlbXb6uvwDgEkBDTzVuDgRDm9 K/oeZoJaQCo7UYIOm9r3jvNo+mPpvsR4jkstV+qmxFaDcOWRWcKliOStKkizL1KDuetE C4vcETfUGYzYUtHR0yf+TID24atjgBz38Nzx7oUWBfD6ZwHN3rg6ah/rpt/d3YUABLfy y07BBEUMuZM8JHpeqZhgdJYxtAlU1Bpgi5xlpE3tYytAKWlKLq8pYBREOuufi2vlnZNv +whmoAFXpGb3lw5AHYqv/hgPNn8KVR3EEhcEqsIBvQT+a+lQSMXv3/w20QDnx4XzRYEA WA== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2n384tx287-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:57 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w9G3JuxD027717 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 16 Oct 2018 03:19:56 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w9G3Juvi006963; Tue, 16 Oct 2018 03:19:56 GMT Received: from localhost (/10.159.227.150) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 15 Oct 2018 20:19:55 -0700 Subject: [PATCH 17/26] vfs: enable remap callers that can handle short operations From: "Darrick J. Wong" To: david@fromorbit.com, darrick.wong@oracle.com Cc: sandeen@redhat.com, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, Amir Goldstein , linux-unionfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-mm@kvack.org, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, ocfs2-devel@oss.oracle.com Date: Mon, 15 Oct 2018 20:19:54 -0700 Message-ID: <153965999426.3607.3221368918901209000.stgit@magnolia> In-Reply-To: <153965939489.1256.7400115244528045860.stgit@magnolia> References: <153965939489.1256.7400115244528045860.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9047 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=985 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810160028 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Plumb in a remap flag that enables the filesystem remap handler to shorten remapping requests for callers that can handle it. Now copy_file_range can report partial success (in case we run up against alignment problems, resource limits, etc.). We also enable CAN_SHORTEN for fideduperange to maintain existing userspace-visible behavior where xfs/btrfs shorten the dedupe range to avoid stale post-eof data exposure. Signed-off-by: Darrick J. Wong Reviewed-by: Amir Goldstein --- fs/read_write.c | 28 ++++++++++++++++++++-------- include/linux/fs.h | 7 +++++-- mm/filemap.c | 16 ++++++++++++---- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/fs/read_write.c b/fs/read_write.c index f6ab5beb935a..ee9314b7bfc3 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1593,7 +1593,8 @@ ssize_t vfs_copy_file_range(struct file *file_in, loff_t pos_in, cloned = file_in->f_op->remap_file_range(file_in, pos_in, file_out, pos_out, - min_t(loff_t, MAX_RW_COUNT, len), 0); + min_t(loff_t, MAX_RW_COUNT, len), + REMAP_FILE_CAN_SHORTEN); if (cloned > 0) { ret = cloned; goto done; @@ -1721,6 +1722,8 @@ static int remap_verify_area(struct file *file, loff_t pos, loff_t len, * can't meaningfully compare post-EOF contents. * * For clone we only link a partial EOF block above the destination file's EOF. + * + * Shorten the request if possible. */ static int generic_remap_check_len(struct inode *inode_in, struct inode *inode_out, @@ -1729,16 +1732,24 @@ static int generic_remap_check_len(struct inode *inode_in, unsigned int remap_flags) { u64 blkmask = i_blocksize(inode_in) - 1; + loff_t new_len = *len; if ((*len & blkmask) == 0) return 0; - if (remap_flags & REMAP_FILE_DEDUP) - *len &= ~blkmask; - else if (pos_out + *len < i_size_read(inode_out)) - return -EINVAL; + if ((remap_flags & REMAP_FILE_DEDUP) || + pos_out + *len < i_size_read(inode_out)) + new_len &= ~blkmask; - return 0; + if (new_len == *len) + return 0; + + if (remap_flags & REMAP_FILE_CAN_SHORTEN) { + *len = new_len; + return 0; + } + + return (remap_flags & REMAP_FILE_DEDUP) ? -EBADE : -EINVAL; } /* Update inode timestamps and remove security privileges when remapping. */ @@ -2023,7 +2034,8 @@ loff_t vfs_dedupe_file_range_one(struct file *src_file, loff_t src_pos, { loff_t ret; - WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP)); + WARN_ON_ONCE(remap_flags & ~(REMAP_FILE_DEDUP | + REMAP_FILE_CAN_SHORTEN)); ret = mnt_want_write_file(dst_file); if (ret) @@ -2124,7 +2136,7 @@ int vfs_dedupe_file_range(struct file *file, struct file_dedupe_range *same) deduped = vfs_dedupe_file_range_one(file, off, dst_file, info->dest_offset, len, - 0); + REMAP_FILE_CAN_SHORTEN); if (deduped == -EBADE) info->status = FILE_DEDUPE_RANGE_DIFFERS; else if (deduped < 0) diff --git a/include/linux/fs.h b/include/linux/fs.h index c0ae85a7bd9d..594fe4ba0b15 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1726,14 +1726,17 @@ struct block_device_operations; * If it is called with len == 0 that means "remap to end of source file". * * REMAP_FILE_DEDUP: only remap if contents identical (i.e. deduplicate) + * REMAP_FILE_CAN_SHORTEN: caller can handle a shortened request */ #define REMAP_FILE_DEDUP (1 << 0) +#define REMAP_FILE_CAN_SHORTEN (1 << 1) /* All valid REMAP_FILE flags */ -#define REMAP_FILE_VALID_FLAGS (REMAP_FILE_DEDUP) +#define REMAP_FILE_VALID_FLAGS (REMAP_FILE_DEDUP | \ + REMAP_FILE_CAN_SHORTEN) /* REMAP_FILE flags taken care of by the vfs. */ -#define REMAP_FILE_ADVISORY (0) +#define REMAP_FILE_ADVISORY (REMAP_FILE_CAN_SHORTEN) struct iov_iter; diff --git a/mm/filemap.c b/mm/filemap.c index 1e93269efafe..898eb358f7d2 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3051,8 +3051,12 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, if (pos_in + count == size_in) { bcount = ALIGN(size_in, bs) - pos_in; } else { - if (!IS_ALIGNED(count, bs)) - return -EINVAL; + if (!IS_ALIGNED(count, bs)) { + if (remap_flags & REMAP_FILE_CAN_SHORTEN) + count = ALIGN_DOWN(count, bs); + else + return -EINVAL; + } bcount = count; } @@ -3063,10 +3067,14 @@ int generic_remap_checks(struct file *file_in, loff_t pos_in, pos_out < pos_in + bcount) return -EINVAL; - /* For now we don't support changing the length. */ - if (*req_count != count) + /* + * We shortened the request but the caller can't deal with that, so + * bounce the request back to userspace. + */ + if (*req_count != count && !(remap_flags & REMAP_FILE_CAN_SHORTEN)) return -EINVAL; + *req_count = count; return 0; }