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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4122EC77B61 for ; Sun, 26 Mar 2023 13:27:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4788B6B0072; Sun, 26 Mar 2023 09:27:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 427A26B0074; Sun, 26 Mar 2023 09:27:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3174F6B0075; Sun, 26 Mar 2023 09:27:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2418D6B0072 for ; Sun, 26 Mar 2023 09:27:07 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id EA467120463 for ; Sun, 26 Mar 2023 13:27:06 +0000 (UTC) X-FDA: 80611125252.03.DF12A55 Received: from eu-smtp-inbound-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf07.hostedemail.com (Postfix) with ESMTP id 942644000B for ; Sun, 26 Mar 2023 13:27:04 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf07.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679837224; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MVIdf+jByEKJ2W3CDiYCJoEKGX5GQOmWAJbTTZuJw8c=; b=yri3lg1iNDNy0zoyF4aJpI8bdXirDapKxdPHa3CPw1puZPvoZqOZwAd3++hnayWxjC3JXJ BBC3Avah2HENM1ghNxx39462Xk2CjVi8NO6jnY6W899oOdmgZQ2BimNQfpbgY9E7MKbdw2 ugaP+yrS4pbE1/hgtIb+NMvZMjhjiRQ= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=aculab.com; spf=pass (imf07.hostedemail.com: domain of david.laight@aculab.com designates 185.58.85.151 as permitted sender) smtp.mailfrom=david.laight@aculab.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679837224; a=rsa-sha256; cv=none; b=lXifcaK/uUsI136t5uiQm0Yjy3l+/9Na90pqoGAGPe3pMwUmz3C2SOOH2QCLORd7D0n9rg FJxbo2U2iBO2XOZyLyQqK5qqknozmDcv6ltWj66J4tO1timyX0ffegj5LAs7PKstiw7tGQ JWx4yT7WQgpELrCz6B39OrhYVhLP6OQ= Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with both STARTTLS and AUTH (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-34-QskMV83HPiqItOif3_5aJA-1; Sun, 26 Mar 2023 14:26:59 +0100 X-MC-Unique: QskMV83HPiqItOif3_5aJA-1 Received: from AcuMS.Aculab.com (10.202.163.6) by AcuMS.aculab.com (10.202.163.6) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 26 Mar 2023 14:26:57 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.048; Sun, 26 Mar 2023 14:26:57 +0100 From: David Laight To: 'Baoquan He' , David Hildenbrand CC: Lorenzo Stoakes , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , Andrew Morton , Uladzislau Rezki , Matthew Wilcox , Liu Shixin , Jiri Olsa , Jens Axboe , Alexander Viro Subject: RE: [PATCH v7 4/4] mm: vmalloc: convert vread() to vread_iter() Thread-Topic: [PATCH v7 4/4] mm: vmalloc: convert vread() to vread_iter() Thread-Index: AQHZXYvy5HgRBBUkm0qsuDBYF9y6k68ND8zA Date: Sun, 26 Mar 2023 13:26:57 +0000 Message-ID: <0cff573c3a344504b1b1b77486b4d853@AcuMS.aculab.com> References: <941f88bc5ab928e6656e1e2593b91bf0f8c81e1b.1679511146.git.lstoakes@gmail.com> <7aee68e9-6e31-925f-68bc-73557c032a42@redhat.com> In-Reply-To: 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 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 942644000B X-Stat-Signature: gjxijq3bs3pap1kzhb7zoxjwkdwgymos X-HE-Tag: 1679837224-157375 X-HE-Meta: U2FsdGVkX19HyxrQ9F96L+94fHJ0MRDFlOaLQHXTn5D2nHyA6LRLWmcUPbvnHIJCyWes9GTTjN7jNlE8Th0RzFpzXhhDaaOexws83iAL4IMUqUUbs+8yVLUSGaME/2CyNdtphjQSeGre8pbmGaLjA0z2Ut5B0EvOKfdJh6yDgZXEORuIvWSMUAplyFMX9ni8xinL9L9/jyhtT92IWgh06yZJgg6l/INpkwNZ3AyWHkW7EZdC5hEsTFDRuArMrX8lo5ocyc/nd526PaUnqUrCPgqdOZreQ4rzmUqtL6MgzW2rdGQdmFMQ4JxTdfms7//z5vAKYNhGjuzZHB3dbFW3EAeFstjWj/fDd04wKGtCwKP7jTulpA0UiVV6RMCStJFrAj46Zmmtdn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A6lAw== 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: Baoquan He > Sent: 23 March 2023 13:32 ... > > > > If this fails, then we fault in, and try again. We loop because the= re could > > > > be some extremely unfortunate timing with a race on e.g. swapping o= ut or > > > > migrating pages between faulting in and trying to write out again. > > > > > > > > This is extremely unlikely, but to avoid any chance of breaking use= rland we > > > > repeat the operation until it completes. In nearly all real-world > > > > situations it'll either work immediately or loop once. > > > > > > Thanks a lot for these helpful details with patience. I got it now. I= was > > > mainly confused by the while(true) loop in KCORE_VMALLOC case of read= _kcore_iter. > > > > > > Now is there any chance that the faulted in memory is swapped out or > > > migrated again before vread_iter()? fault_in_iov_iter_writeable() wil= l > > > pin the memory? I didn't find it from code and document. Seems it onl= y > > > falults in memory. If yes, there's window between faluting in and > > > copy_to_user_nofault(). > > > > > > > See the documentation of fault_in_safe_writeable(): > > > > "Note that we don't pin or otherwise hold the pages referenced that we = fault > > in. There's no guarantee that they'll stay in memory for any duration = of > > time." >=20 > Thanks for the info. Then swapping out/migration could happen again, so > that's why while(true) loop is meaningful. One of the problems is that is the system is under severe memory pressure and you try to fault in (say) 20 pages, the first page might get unmapped in order to map the last one in. So it is quite likely better to retry 'one page at a time'. There have also been cases where the instruction to copy data has faulted for reasons other than 'page fault'. ISTR an infinite loop being caused by misaligned accesses failing due to 'bad instruction choice' in the copy code. While this is rally a bug, an infinite retry in a file read/write didn't make it easy to spot. So maybe there are cases where a dropping back to a 'bounce buffer' may be necessary. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)