From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D8F6C2B9F4 for ; Tue, 22 Jun 2021 22:05:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1163C60249 for ; Tue, 22 Jun 2021 22:05:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1163C60249 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D839C6B0071; Tue, 22 Jun 2021 18:05:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D0B2F6B0072; Tue, 22 Jun 2021 18:05:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B12046B0073; Tue, 22 Jun 2021 18:05:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0036.hostedemail.com [216.40.44.36]) by kanga.kvack.org (Postfix) with ESMTP id 58AEE6B0071 for ; Tue, 22 Jun 2021 18:05:08 -0400 (EDT) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 778A1202F9 for ; Tue, 22 Jun 2021 22:05:08 +0000 (UTC) X-FDA: 78282741096.26.8A229EA Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id E17A160019CC for ; Tue, 22 Jun 2021 22:05:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=2m7GLG5w20KHHhlTaOprqLvS/Hx9yXDVOmadVvXFND8=; b=u3lQwtebrfuytes2L8nzZ8N6YB aJhsNvMMqMSpPGNJH8kmiR7ZH5GZ8SaF6yU7/DOCPamQgOmhypPXOtCUwm2z1Uuq6NQAJOrjXIRU9 n/ezdix3gyl8PG/XzrrMkgvYY6M/RFMFSGzbaMi06n0HKx4MbgT6PLCgR0eTxZgD19e3PU7iZkul2 y4z1w0+QVKMDlEUubiBrPxYl21fwfxo+q5NE67cHub2Jm1uTmGVXZfWHsHzz8kFgw6LdE3F6YDdAe mOmOdSvwj8/y4BLxz3wuRRtYpq7Pw3J2c2GCZZGWaWpZ0fTG17fhLLlpwU1wnkA84w5mZPT9JKDZf IAbFQkXA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1lvoVD-00EnTi-HC; Tue, 22 Jun 2021 22:04:25 +0000 Date: Tue, 22 Jun 2021 23:04:15 +0100 From: Matthew Wilcox To: David Laight Cc: 'David Howells' , Al Viro , "torvalds@linux-foundation.org" , Ted Ts'o , Dave Hansen , Andrew Morton , "linux-mm@kvack.org" , "linux-ext4@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: Do we need to unrevert "fs: do not prefault sys_write() user buffer pages"? Message-ID: References: <3221175.1624375240@warthog.procyon.org.uk> <3225322.1624379221@warthog.procyon.org.uk> <7a6d8c55749d46d09f6f6e27a99fde36@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7a6d8c55749d46d09f6f6e27a99fde36@AcuMS.aculab.com> Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=u3lQwteb; dmarc=none; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-Stat-Signature: rwi5sy6ra6j59j5nw4itknowk7xhp3oy X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: E17A160019CC X-HE-Tag: 1624399507-949776 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: On Tue, Jun 22, 2021 at 09:55:09PM +0000, David Laight wrote: > From: David Howells > > Sent: 22 June 2021 17:27 > > > > Al Viro wrote: > > > > > On Tue, Jun 22, 2021 at 04:20:40PM +0100, David Howells wrote: > > > > > > > and wondering if the iov_iter_fault_in_readable() is actually effective. > > > > Yes, it can make sure that the page we're intending to modify is dragged > > > > into the pagecache and marked uptodate so that it can be read from, but is > > > > it possible for the page to then get reclaimed before we get to > > > > iov_iter_copy_from_user_atomic()? a_ops->write_begin() could potentially > > > > take a long time, say if it has to go and get a lock/lease from a server. > > > > > > Yes, it is. So what? We'll just retry. You *can't* take faults while > > > holding some pages locked; not without shitloads of deadlocks. > > > > In that case, can we amend the comment immediately above > > iov_iter_fault_in_readable()? > > > > /* > > * Bring in the user page that we will copy from _first_. > > * Otherwise there's a nasty deadlock on copying from the > > * same page as we're writing to, without it being marked > > * up-to-date. > > * > > * Not only is this an optimisation, but it is also required > > * to check that the address is actually valid, when atomic > > * usercopies are used, below. > > */ > > if (unlikely(iov_iter_fault_in_readable(i, bytes))) { > > > > The first part suggests this is for deadlock avoidance. If that's not true, > > then this should perhaps be changed. > > I'd say something like: > /* > * The actual copy_from_user() is done with a lock held > * so cannot fault in missing pages. > * So fault in the pages first. > * If they get paged out the inatomic usercopy will fail > * and the whole operation is retried. > * > * Hopefully there are enough memory pages available to > * stop this looping forever. > */ > > It is perfectly possible for another application thread to > invalidate one of the buffer fragments after iov_iter_fault_in_readable() > return success - so it will then fail on the second pass. > > The maximum number of pages required is twice the maximum number > of iov fragments. > If the system is crawling along with no available memory pages > the same physical page could get used for two user pages. I would suggest reading the function before you suggest modifications to it. offset = (pos & (PAGE_SIZE - 1)); bytes = min_t(unsigned long, PAGE_SIZE - offset, iov_iter_count(i));