From patchwork Mon May 22 04:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hugh Dickins X-Patchwork-Id: 13249757 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 5C322C77B73 for ; Mon, 22 May 2023 04:57:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F07D3900009; Mon, 22 May 2023 00:57:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB873900002; Mon, 22 May 2023 00:57:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA71A900009; Mon, 22 May 2023 00:57:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CA496900002 for ; Mon, 22 May 2023 00:57:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A39F81C757B for ; Mon, 22 May 2023 04:57:32 +0000 (UTC) X-FDA: 80816682744.07.304B19F Received: from mail-yw1-f173.google.com (mail-yw1-f173.google.com [209.85.128.173]) by imf21.hostedemail.com (Postfix) with ESMTP id D50261C000A for ; Mon, 22 May 2023 04:57:30 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CynFLjQo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684731450; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=dk0QCHZ/ZrkXov8P0kyfxgscgrLXPV5n2YV5/OCWJso=; b=MDw1dVaJ86hoRNJlc6rpn+AHFFqsgpxW5FHtgCH5ZZolWljX1xSfAc6ka8NawAR+DmrrVi WrHcL8XdUXoMK/JmbdLS5sdFqyznCpiUz/nuA8DW87rJeL2WbPeu17+PUgwCGRKc42M1CC CEft+fVqnHzdduC5vuQaWcIHCwcDSxU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=CynFLjQo; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of hughd@google.com designates 209.85.128.173 as permitted sender) smtp.mailfrom=hughd@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684731450; a=rsa-sha256; cv=none; b=d9z/gnTxXR17HcwnBNDOKQVKXcKQN/cQxqlwvH7HNBKZsntJ4iay5qhcThszbBU4Npgexh KVKLKQvXysIwHK6NuCGsaKzHsPZWHQk4PiCXIt6dbT1tQmki1hDaGdmuFVeY33Ca8algHc 2o2HKEIjtQ4uTtlQJzCNvksNqr5ZI58= Received: by mail-yw1-f173.google.com with SMTP id 00721157ae682-561a33b6d63so74535137b3.1 for ; Sun, 21 May 2023 21:57:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684731450; x=1687323450; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=dk0QCHZ/ZrkXov8P0kyfxgscgrLXPV5n2YV5/OCWJso=; b=CynFLjQo0B1iyGJQ1Hhn7p6Dwng2pZKqC1sA23EZv3JCM+ZbaT1ahTTm4sUvOZtzCZ BowaOQG29xMNLY0nY/iY+TITfx8rXjfCpXFh5g/iSfQ5lmiD0WCo6dz+EbU/qzow4T48 gIYfejZ6h5BXNTbcNV7JSAg8ejqfun0/YIkYFIX2j/yjnUq7/K2x26jXo8nJSL+Ur/DZ +SUB1nDtFHo1Zu1hnHccttoMBnxyawb0XgPXLVByf6aDR7smWV6B07cuec2Ws0N9yLdQ 8jqD+ttVDEwqJC0ct/mh9eZgT02XjAOsBx+WhPs+42uDF1lV5/G1Bt1qT41SuPS3wH4j Fx7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684731450; x=1687323450; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dk0QCHZ/ZrkXov8P0kyfxgscgrLXPV5n2YV5/OCWJso=; b=KUZUDig6BbaKUJnciZLqzRZW+5Cl9Y/1ZvwZiMcBm4BerFcOMVtFFVJgEdCplcUssl Ey2f0exE45JCL/DtqCVGD8TWSJ82zBdjT06hGIK81ZbztQi6+wyyz+BFRwrWCZ82oXWf Tx/CEMnst4YFH4Rsp+VQfs/uLr0WtC/Qi+z5c0wxt9uJGQTuKzT8W6jQq1rlT6YsMm9J cOVBG/gZiL8f+jATrds5OaaShXqdw84Xj6osqAua4EfbDCYRS39uHibXBiDyGS8Rqv2J kpVev7QhnZVzQqypwweoTdN5taiZyduhqQPzbMgwKHnh7hB7waco8uCqyVuLUdU5LMD9 5b8A== X-Gm-Message-State: AC+VfDxEVvjkcEAJC2sP5NvD5UkJGra+TnSQ8uH2bTNLjclYZWMbUQla qm56OJG08AOeUAmELe4n9e8eNQ== X-Google-Smtp-Source: ACHHUZ6bURP043biciXrsTo4ID2f5FUMVgcYdQ4w5Fut/Rhs5NuMHxd9s5+H+9KhMfle9QGb5MKZdA== X-Received: by 2002:a81:9206:0:b0:55a:2ce1:2353 with SMTP id j6-20020a819206000000b0055a2ce12353mr9508264ywg.2.1684731449358; Sun, 21 May 2023 21:57:29 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id c130-20020a814e88000000b0056183cdb2d9sm1794222ywb.60.2023.05.21.21.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 21 May 2023 21:57:29 -0700 (PDT) Date: Sun, 21 May 2023 21:57:25 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton cc: Mike Kravetz , Mike Rapoport , "Kirill A. Shutemov" , Matthew Wilcox , David Hildenbrand , Suren Baghdasaryan , Qi Zheng , Yang Shi , Mel Gorman , Peter Xu , Peter Zijlstra , Will Deacon , Yu Zhao , Alistair Popple , Ralph Campbell , Ira Weiny , Steven Price , SeongJae Park , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 07/31] mm/page_vma_mapped: reformat map_pte() with less indentation In-Reply-To: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> Message-ID: <4d93bd9-346c-938f-45d0-e073372323f6@google.com> References: <68a97fbe-5c1e-7ac6-72c-7b9c6290b370@google.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: D50261C000A X-Stat-Signature: dd18kjupa61n4fnfdhit5k758ym4r8km X-HE-Tag: 1684731450-593313 X-HE-Meta: U2FsdGVkX1+VA7cbUwb76ttSBu/6+23D/IAOAsh5MPTJfj3cIGVQArlQjeXLGTOwNrY/ZGVNBpzVX3KSQ+n34Zs4tcpo0GzSNzy9GE19WQVWfnNwn3VgCBabIJwb2B5lS2qsuFkdN3jU8x6XaYbpQvWuVl/gRtYT64ULx2HqRJXWGbtQiyQBC3rsG+WYsQvvkm1PK+hM7PSuAVj/g8aeV1xiyD9CL5zf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kLRQWmUBv0aIhOeYoo/OI8LDn38yFOrGkeomCUayhlBN5y+i9HBztzKDGCR9Sc1hFRYrFcz5Q7lmPtyEhgalRaMnV4J9uGOeGo4kezXJW+T9F4wBqfoCi1VzQSwpygokBp5A== 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: No functional change here, but adjust the format of map_pte() so that the following commit will be easier to read: separate out the PVMW_SYNC case first, and remove two levels of indentation from the ZONE_DEVICE case. Signed-off-by: Hugh Dickins --- mm/page_vma_mapped.c | 65 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 007dc7456f0e..947dc7491815 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -15,38 +15,41 @@ static inline bool not_found(struct page_vma_mapped_walk *pvmw) static bool map_pte(struct page_vma_mapped_walk *pvmw) { - pvmw->pte = pte_offset_map(pvmw->pmd, pvmw->address); - if (!(pvmw->flags & PVMW_SYNC)) { - if (pvmw->flags & PVMW_MIGRATION) { - if (!is_swap_pte(*pvmw->pte)) - return false; - } else { - /* - * We get here when we are trying to unmap a private - * device page from the process address space. Such - * page is not CPU accessible and thus is mapped as - * a special swap entry, nonetheless it still does - * count as a valid regular mapping for the page (and - * is accounted as such in page maps count). - * - * So handle this special case as if it was a normal - * page mapping ie lock CPU page table and returns - * true. - * - * For more details on device private memory see HMM - * (include/linux/hmm.h or mm/hmm.c). - */ - if (is_swap_pte(*pvmw->pte)) { - swp_entry_t entry; + if (pvmw->flags & PVMW_SYNC) { + /* Use the stricter lookup */ + pvmw->pte = pte_offset_map_lock(pvmw->vma->vm_mm, pvmw->pmd, + pvmw->address, &pvmw->ptl); + return true; + } - /* Handle un-addressable ZONE_DEVICE memory */ - entry = pte_to_swp_entry(*pvmw->pte); - if (!is_device_private_entry(entry) && - !is_device_exclusive_entry(entry)) - return false; - } else if (!pte_present(*pvmw->pte)) - return false; - } + pvmw->pte = pte_offset_map(pvmw->pmd, pvmw->address); + if (pvmw->flags & PVMW_MIGRATION) { + if (!is_swap_pte(*pvmw->pte)) + return false; + } else if (is_swap_pte(*pvmw->pte)) { + swp_entry_t entry; + /* + * Handle un-addressable ZONE_DEVICE memory. + * + * We get here when we are trying to unmap a private + * device page from the process address space. Such + * page is not CPU accessible and thus is mapped as + * a special swap entry, nonetheless it still does + * count as a valid regular mapping for the page + * (and is accounted as such in page maps count). + * + * So handle this special case as if it was a normal + * page mapping ie lock CPU page table and return true. + * + * For more details on device private memory see HMM + * (include/linux/hmm.h or mm/hmm.c). + */ + entry = pte_to_swp_entry(*pvmw->pte); + if (!is_device_private_entry(entry) && + !is_device_exclusive_entry(entry)) + return false; + } else if (!pte_present(*pvmw->pte)) { + return false; } pvmw->ptl = pte_lockptr(pvmw->vma->vm_mm, pvmw->pmd); spin_lock(pvmw->ptl);