Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1957721pxb; Thu, 4 Nov 2021 11:25:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDajz5lXbSKSwOxOktmGXG3WtVtnHoF2ulk+lIIXU74xh2h8PNUYZLcMaqy9BLDmAUkval X-Received: by 2002:a17:907:6e0b:: with SMTP id sd11mr6025650ejc.134.1636050354184; Thu, 04 Nov 2021 11:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636050354; cv=none; d=google.com; s=arc-20160816; b=OeibISVWJcNz+5IB8OpWRgtw86JpjMXxAS1xFdX5xrYej2113rxQR04To7h22lIRvR ETjdh1m7tHC056nH/Udw3PREreJdJACtnEJFKASoakALexk/XnjLGu9tTJcugaVtFlN2 F5PVrq/mtD51EXwhQgLgbTBrPPEaN36SzxlAJsBEYgK2o3dT6W3Y9Cq1/sFuP4JO2h/6 HahI9BOzNG2tSeEEl6Mxlt9zsAiy+sGG0piqAWMjo6vJj2EwaZVq7o/XWHpLPgDqJul9 3j+NrBMw/zM2JXHFal83E5AlH8WdRpnPVXw8x40vYM+6d9KYIlLr+eHZNEpyeI5W6P7f lLQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=1bsHpEymyup3SU5m+8dqBppbL3ymnnvKIpLWrDtUd6w=; b=ctq6Fs0g1STw4wG4PlD0c1Xh5bvZ8B9IFrkWVngnk4WQj5bvx7GtK0VviryTaTtTet Xt7azR0cSLFlqcptwmrIwBQ8eue26lZCZ8J0iBOjMgIk5LBlxjtu3R+PPj3vifWYxBnj 9F1IbsxirGuw9H8fPFjxICGmgeR2lr9fWn3PtLZZKKyhXUh2TNb11r34rAdPo4yt468T iywEH0b2kVWn7uC2/hdUl4VLxYWYjppdNsn8ti21RPYTFm21KeXeDkXZy0wdLxi/Jsd5 gNpOT4ITwd829voeY2OclmQGN1Wcw1luMNgadEke99A9HzK0WAjgCczYQi6dyfPqMw+3 ea2A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id et2si4882635ejc.740.2021.11.04.11.25.30; Thu, 04 Nov 2021 11:25:54 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234177AbhKDSZc (ORCPT + 99 others); Thu, 4 Nov 2021 14:25:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:58592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234135AbhKDSZ2 (ORCPT ); Thu, 4 Nov 2021 14:25:28 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8A5C161212; Thu, 4 Nov 2021 18:22:47 +0000 (UTC) Date: Thu, 4 Nov 2021 18:22:44 +0000 From: Catalin Marinas To: Andreas Gruenbacher Cc: cluster-devel@redhat.com, Linus Torvalds , Alexander Viro , Christoph Hellwig , "Darrick J. Wong" , Paul Mackerras , Jan Kara , Matthew Wilcox , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, ocfs2-devel@oss.oracle.com, kvm-ppc@vger.kernel.org, linux-btrfs@vger.kernel.org, joey.gouly@arm.com Subject: Re: [PATCH v9 04/17] iov_iter: Turn iov_iter_fault_in_readable into fault_in_iov_iter_readable Message-ID: References: <20211102122945.117744-1-agruenba@redhat.com> <20211102122945.117744-5-agruenba@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211102122945.117744-5-agruenba@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 02, 2021 at 01:29:32PM +0100, Andreas Gruenbacher wrote: > Turn iov_iter_fault_in_readable into a function that returns the number > of bytes not faulted in, similar to copy_to_user, instead of returning a > non-zero value when any of the requested pages couldn't be faulted in. > This supports the existing users that require all pages to be faulted in > as well as new users that are happy if any pages can be faulted in. > > Rename iov_iter_fault_in_readable to fault_in_iov_iter_readable to make > sure this change doesn't silently break things. > > Signed-off-by: Andreas Gruenbacher [...] > diff --git a/mm/filemap.c b/mm/filemap.c > index ff34f4087f87..4dd5edcd39fd 100644 > --- a/mm/filemap.c > +++ b/mm/filemap.c > @@ -3757,7 +3757,7 @@ ssize_t generic_perform_write(struct file *file, > * same page as we're writing to, without it being marked > * up-to-date. > */ > - if (unlikely(iov_iter_fault_in_readable(i, bytes))) { > + if (unlikely(fault_in_iov_iter_readable(i, bytes))) { > status = -EFAULT; > break; > } Now that fault_in_iov_iter_readable() returns the number of bytes, we could change the above test to: if (unlikely(fault_in_iov_iter_readable(i, bytes) == bytes)) { Assuming we have a pointer 'a', accessible, and 'a + PAGE_SIZE' unmapped: write(fd, a + PAGE_SIZE - 1, 2); can still copy one byte but it returns -EFAULT instead since the second page is not accessible. While writing some test-cases for MTE (sub-page faults, 16-byte granularity), we noticed that reading 2 bytes from 'a + 15' with 'a + 16' tagged for faulting: write(fd, a + 15, 2); succeeds as long as 'a + 16' is not at a page boundary. Checking against 'bytes' above makes this consistent. The downside is that it's an ABI change though not sure anyone is relying on it. -- Catalin