Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7614745rwl; Thu, 23 Mar 2023 06:43:33 -0700 (PDT) X-Google-Smtp-Source: AK7set+0CvNukwzbwkHpfoagyL5/akUtvfyW9bpa9qVkPprheVkjyaQYJeuxi+1E7yIJsON/8bG2 X-Received: by 2002:a17:906:2f16:b0:931:7adf:547e with SMTP id v22-20020a1709062f1600b009317adf547emr10095130eji.70.1679579013263; Thu, 23 Mar 2023 06:43:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679579013; cv=none; d=google.com; s=arc-20160816; b=qOcnMMD9bfL04bmFyJCDRaQQDdhAnswkwXL43l2otrnqjYEkCtq8qTb3BUKlOS2qtY 7awKxic6nOH2E16N1DZewJm+8g3T9qivQ+EYsUHhZhBFDBUeIQNsxQll7jx2rnr1M5zC aCmgSwLo/n+2tTiugCz0qiLT6SAkhcotTxdItCCiLjC5i0tgsa6lmMRZY2zfJ7HHPlX0 Q2u+m8+qpLGFAbMu3pLbegg1Tm2YeUoAkrZB8oSTs+PYApVzgJyJvbTmgMYaddGmA0Pm oN3zSfq8eKRsbOi5VxOyWCSqmKYw1vB9IxLTlagwnw3jLu4htUbGp6FHPx2nUfM68GuJ Ye1g== 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:dkim-signature; bh=mXzYR6c2WCVTnZ/W9wW/e0omNfMuDAlzjXCmVrC/wTo=; b=dvl2zTImgfzGfDBhT8EnyYu/gmgt5y/lgIQDRaPJ069oZZXLGptAQfU+JyQsRmPUpD kI7hsM9UytwZI3tAuGH9+yPwJRFSdVxAKEAI3yemQ1auAVS18dNeXXIkMeJZU+Y0NrO0 PBkeXO5ZtN6vVwPqnLyK5jp5+hhKhx4R7QJBTTGvoYjfgMW7iVhN84eiYkRWo4NXq7uY AKtqAjk/fdoDN1B2tQMILBtftP3ab5JVSAqi+P8fBXDnMql1hm5ywtwcbrUvLsWqyzPB GAOxaYwIrtbguDWSK35W4ytvmCTblOl+CPEKP+Yr8qVaIZLNh3fbSVanPVk3fzFVZgMm aM6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WfjDxaPQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a1709062bd200b009318e114d7dsi15316584ejg.929.2023.03.23.06.43.08; Thu, 23 Mar 2023 06:43:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WfjDxaPQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231723AbjCWNch (ORCPT + 99 others); Thu, 23 Mar 2023 09:32:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231650AbjCWNcd (ORCPT ); Thu, 23 Mar 2023 09:32:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB5D25959 for ; Thu, 23 Mar 2023 06:31:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679578308; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=mXzYR6c2WCVTnZ/W9wW/e0omNfMuDAlzjXCmVrC/wTo=; b=WfjDxaPQ9FioChtd0Uc2b4MIYU+fadgXmATai95NqTPhtK4iCEpyPBN6Rjx2D2uiXhsoyO 5mAxCxBG5U//QBilgdLw2sE5T8oYMVaKVvdjz3aTmtB9NNRexnZZZrZBFoSX0HfV0VKHdS L8ISAPcZst7gIXJCO2Yp655a67Jfx6k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-yk90ah0pPruWBLBfLw4E4g-1; Thu, 23 Mar 2023 09:31:47 -0400 X-MC-Unique: yk90ah0pPruWBLBfLw4E4g-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EE80855304; Thu, 23 Mar 2023 13:31:46 +0000 (UTC) Received: from localhost (ovpn-12-97.pek2.redhat.com [10.72.12.97]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFDC8C15BA0; Thu, 23 Mar 2023 13:31:44 +0000 (UTC) Date: Thu, 23 Mar 2023 21:31:40 +0800 From: Baoquan He To: 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() Message-ID: References: <941f88bc5ab928e6656e1e2593b91bf0f8c81e1b.1679511146.git.lstoakes@gmail.com> <7aee68e9-6e31-925f-68bc-73557c032a42@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7aee68e9-6e31-925f-68bc-73557c032a42@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/23/23 at 11:38am, David Hildenbrand wrote: > On 23.03.23 11:36, Baoquan He wrote: > > On 03/23/23 at 06:44am, Lorenzo Stoakes wrote: > > > On Thu, Mar 23, 2023 at 10:52:09AM +0800, Baoquan He wrote: > > > > On 03/22/23 at 06:57pm, Lorenzo Stoakes wrote: > > > > > Having previously laid the foundation for converting vread() to an iterator > > > > > function, pull the trigger and do so. > > > > > > > > > > This patch attempts to provide minimal refactoring and to reflect the > > > > > existing logic as best we can, for example we continue to zero portions of > > > > > memory not read, as before. > > > > > > > > > > Overall, there should be no functional difference other than a performance > > > > > improvement in /proc/kcore access to vmalloc regions. > > > > > > > > > > Now we have eliminated the need for a bounce buffer in read_kcore_iter(), > > > > > we dispense with it, and try to write to user memory optimistically but > > > > > with faults disabled via copy_page_to_iter_nofault(). We already have > > > > > preemption disabled by holding a spin lock. We continue faulting in until > > > > > the operation is complete. > > > > > > > > I don't understand the sentences here. In vread_iter(), the actual > > > > content reading is done in aligned_vread_iter(), otherwise we zero > > > > filling the region. In aligned_vread_iter(), we will use > > > > vmalloc_to_page() to get the mapped page and read out, otherwise zero > > > > fill. While in this patch, fault_in_iov_iter_writeable() fault in memory > > > > of iter one time and will bail out if failed. I am wondering why we > > > > continue faulting in until the operation is complete, and how that is done. > > > > > > This is refererrring to what's happening in kcore.c, not vread_iter(), > > > i.e. the looped read/faultin. > > > > > > The reason we bail out if failt_in_iov_iter_writeable() is that would > > > indicate an error had occurred. > > > > > > The whole point is to _optimistically_ try to perform the operation > > > assuming the pages are faulted in. Ultimately we fault in via > > > copy_to_user_nofault() which will either copy data or fail if the pages are > > > not faulted in (will discuss this below a bit more in response to your > > > other point). > > > > > > If this fails, then we fault in, and try again. We loop because there could > > > be some extremely unfortunate timing with a race on e.g. swapping out or > > > migrating pages between faulting in and trying to write out again. > > > > > > This is extremely unlikely, but to avoid any chance of breaking userland 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() will > > pin the memory? I didn't find it from code and document. Seems it only > > 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." Thanks for the info. Then swapping out/migration could happen again, so that's why while(true) loop is meaningful.