Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1447453rwd; Thu, 8 Jun 2023 18:58:40 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6Pir2k3bUIGSC8j0WY+pKkbLRGusS+G8DVs/M4C0OjG04eTipG4X3uNt9DPoowbhLQlnHL X-Received: by 2002:a05:6358:f0a:b0:129:c6d1:2176 with SMTP id b10-20020a0563580f0a00b00129c6d12176mr80723rwj.15.1686275919823; Thu, 08 Jun 2023 18:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686275919; cv=none; d=google.com; s=arc-20160816; b=J18Z5f6MrFFiGY85EE/5juiZCbMJExqawVOsWn4HhCsjHaKAI4hL2xOH6pigwcWUL8 TlWX2DGFx1RJcErs7NOV5yHXkc/7QS0fVDJwNGP6UQ9atCMX4pylTyS+xTJ/kr7XvOQ1 RLhUz6jx9IQV5Mw6bRQziUQh/6bXu7nPqJ5FnooesQuDEPRv69deqmJpqPwaT38mFC5G DxAI0Q+6oCYji1YMwjhfw8RiznzD1jfCGCt2KdpAKyn3ZJOT2MOtTgzCGFlK69LUoXa1 rI5Fy8Flfrh12EXOLlD+zxKi77r3a0V4R79e7D3sNOnzfgKSO+VwBeDmrqyqq/mignKb bbkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=dk0QCHZ/ZrkXov8P0kyfxgscgrLXPV5n2YV5/OCWJso=; b=Qqs1bnxk2a5TTfEv21WPbnldx0P9Wi0HRwlfkiw1C9ocaONtPvG8rPQlJBlzvzXd03 SU0b5w+pQYcX12T3zjbBFkHTT6CG2em26pZ5M0yM/KecefNJIxTrp2uvedd6I+lQ/eCO JID1Mp+J6XvjlEgu7IXIaPK3RBHzzaV67wgwmfU0lnd2CdwXCDClYW6Koz6dWiheGEiP cd3eeyfJmReimtUyL+uJWHW6j23EPRtabtrBY+ZGqMwIPTNZGlS63WapCeGFlk6TBCXc ZlH0yjAF6cdWb/ZYIMBLxzNO349OqJAzPEi/DfyLi6PgoTAr9Jk2Gqq2zQCkmloDcBwz Ud3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=b0CpC9Xp; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p17-20020a637411000000b00543d1e8c889si1754969pgc.846.2023.06.08.18.58.26; Thu, 08 Jun 2023 18:58:39 -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=@google.com header.s=20221208 header.b=b0CpC9Xp; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236358AbjFIBOV (ORCPT + 99 others); Thu, 8 Jun 2023 21:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229684AbjFIBOT (ORCPT ); Thu, 8 Jun 2023 21:14:19 -0400 Received: from mail-yw1-x1129.google.com (mail-yw1-x1129.google.com [IPv6:2607:f8b0:4864:20::1129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 082BF184 for ; Thu, 8 Jun 2023 18:14:18 -0700 (PDT) Received: by mail-yw1-x1129.google.com with SMTP id 00721157ae682-568af2f6454so11288867b3.1 for ; Thu, 08 Jun 2023 18:14:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686273257; x=1688865257; 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=b0CpC9XpkwDMafp8znPdIUsufEoFF4TcEqSqtaBP/NRJK+TenjbuJzsvixBg7OeqD/ 2YfCQZOz9K140u4I0LV9p7i9HmUHhwPj5OjQEN4SArRt2Or8i+5jxZhLGecB/haRDICX vtLEyf8OOmoIO0wzxw5muMOyeWGS5tJSD8isNbt74/I3PyUiS3JXgFtf8p9995UjX66/ sVUXiIkxjAllgABbdRX2liHFwE/N9RUJ3gtPDEiB01DtZbdswHmgd6fCDnuNDxOd5cgB 2PYb4O3ns/eFa8oej3CUcEw8DbK3FH4hcK4a5VnPjgKE3o+d2ZfZbD5hqntDTaQ68DiO 87/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686273257; x=1688865257; 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=cZXaLpHOW5f8K39tCp7RAuFbU3hl5zL6ywwsqG+zO0l/3C13RfPSWbIVVJM+xipJXC 3PGWQmCmcL0yBLp9+Za5rNVMAQ9l1/lAKIKDDretRntFJbdYXBnh3qX6QADMAHgplGpa uRPffwTBtnYxx1IV1CQa1c9YEQKBiustagzNgUfmUmMrPDsPI+5TEYAEmA6pKkjNN8lG R21R3D0PuVLCMNABrZBohoCNHxKsA5y848nQmw1jLfotBCDrA0rhsEy6HyKml2KKpH5I WJfpaK5LGW67kVb4lw+Pml6dbd5DY+N3PuodXhhQL3Y+1ozwVL77+szLjpWOlWRxNC7v CCBA== X-Gm-Message-State: AC+VfDyZwd2f27vAbE5tA8HDrxaVfyydBA4JaASCGvged51YxnV/4OeL ci3PKe6kUqiT5XBm2dpowG5rrw== X-Received: by 2002:a0d:d6c8:0:b0:549:2623:6f65 with SMTP id y191-20020a0dd6c8000000b0054926236f65mr1346506ywd.33.1686273257036; Thu, 08 Jun 2023 18:14:17 -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 t66-20020a815f45000000b0054fba955474sm301207ywb.17.2023.06.08.18.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Jun 2023 18:14:16 -0700 (PDT) Date: Thu, 8 Jun 2023 18:14:12 -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 , Lorenzo Stoakes , Huang Ying , Naoya Horiguchi , Christophe Leroy , Zack Rusin , Jason Gunthorpe , Axel Rasmussen , Anshuman Khandual , Pasha Tatashin , Miaohe Lin , Minchan Kim , Christoph Hellwig , Song Liu , Thomas Hellstrom , Ryan Roberts , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH v2 07/32] mm/page_vma_mapped: reformat map_pte() with less indentation In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 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); -- 2.35.3