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=-2.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64, 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 4367FC2B9F4 for ; Tue, 22 Jun 2021 21:55:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D2A3260FDC for ; Tue, 22 Jun 2021 21:55:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D2A3260FDC Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A35396B0036; Tue, 22 Jun 2021 17:55:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A0BCB6B006C; Tue, 22 Jun 2021 17:55:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D41C6B006E; Tue, 22 Jun 2021 17:55:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0035.hostedemail.com [216.40.44.35]) by kanga.kvack.org (Postfix) with ESMTP id 49B0D6B0036 for ; Tue, 22 Jun 2021 17:55:18 -0400 (EDT) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6F19F181BDCA6 for ; Tue, 22 Jun 2021 21:55:18 +0000 (UTC) X-FDA: 78282716316.13.38BA9E6 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf14.hostedemail.com (Postfix) with ESMTP id CD796C01C088 for ; Tue, 22 Jun 2021 21:55:15 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-86-sl1tZ6CBMP-L3jncOw6psA-1; Tue, 22 Jun 2021 22:55:10 +0100 X-MC-Unique: sl1tZ6CBMP-L3jncOw6psA-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Tue, 22 Jun 2021 22:55:10 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.018; Tue, 22 Jun 2021 22:55:10 +0100 From: David Laight To: 'David Howells' , Al Viro CC: "torvalds@linux-foundation.org" , Ted Ts'o , Dave Hansen , Andrew Morton , "willy@infradead.org" , "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"? Thread-Topic: Do we need to unrevert "fs: do not prefault sys_write() user buffer pages"? Thread-Index: AQHXZ4N03eCp9KNCtEagRX54mD94w6sgkJXg Date: Tue, 22 Jun 2021 21:55:09 +0000 Message-ID: <7a6d8c55749d46d09f6f6e27a99fde36@AcuMS.aculab.com> References: <3221175.1624375240@warthog.procyon.org.uk> <3225322.1624379221@warthog.procyon.org.uk> In-Reply-To: <3225322.1624379221@warthog.procyon.org.uk> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com; dmarc=pass (policy=none) header.from=ACULAB.COM X-Stat-Signature: ons67xonp1hh5km644aofgrc6qdhrfcj X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: CD796C01C088 X-HE-Tag: 1624398915-925097 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: From: David Howells > Sent: 22 June 2021 17:27 >=20 > Al Viro wrote: >=20 > > On Tue, Jun 22, 2021 at 04:20:40PM +0100, David Howells wrote: > > > > > and wondering if the iov_iter_fault_in_readable() is actually effecti= ve. > > > Yes, it can make sure that the page we're intending to modify is drag= ged > > > into the pagecache and marked uptodate so that it can be read from, b= ut 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 potenti= ally > > > take a long time, say if it has to go and get a lock/lease from a ser= ver. > > > > Yes, it is. So what? We'll just retry. You *can't* take faults while > > holding some pages locked; not without shitloads of deadlocks. >=20 > In that case, can we amend the comment immediately above > iov_iter_fault_in_readable()? >=20 > =09/* > =09 * Bring in the user page that we will copy from _first_. > =09 * Otherwise there's a nasty deadlock on copying from the > =09 * same page as we're writing to, without it being marked > =09 * up-to-date. > =09 * > =09 * Not only is this an optimisation, but it is also required > =09 * to check that the address is actually valid, when atomic > =09 * usercopies are used, below. > =09 */ > =09if (unlikely(iov_iter_fault_in_readable(i, bytes))) { >=20 > The first part suggests this is for deadlock avoidance. If that's not tr= ue, > then this should perhaps be changed. I'd say something like: =09/* =09 * The actual copy_from_user() is done with a lock held =09 * so cannot fault in missing pages. =09 * So fault in the pages first. =09 * If they get paged out the inatomic usercopy will fail =09 * and the whole operation is retried. =09 * =09 * Hopefully there are enough memory pages available to =09 * stop this looping forever. =09 */ 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. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)