Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp650358rwl; Thu, 5 Jan 2023 02:34:30 -0800 (PST) X-Google-Smtp-Source: AMrXdXuvM6QG6p4GtzT5utUYL+BzZrSolDUFQAV12w1B8PEA6jQVNJU9hpoakV4pPFf6AE5KLonz X-Received: by 2002:a05:6402:2488:b0:46b:34a:3945 with SMTP id q8-20020a056402248800b0046b034a3945mr52625277eda.31.1672914870706; Thu, 05 Jan 2023 02:34:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672914870; cv=none; d=google.com; s=arc-20160816; b=iFZ1Cd3Mhj/XidSWQCw2Uk7vLMp4SOc1S/C8xutbuUPJuwuqJv8Im4H4QNOjONynfF ndDwWrQq41NMg9K6Hw98kSJCB+vL/hTaEg9Vh35Wdv53RDtzKdQ3oiyB8L5xTkA28Wd9 B5y1pRcNW2mB2RG6UzycUsPaawxlC017WaEAl11VzsmgZhKDatlu/i+vRH0rTLQwZohM 41SVaOZZHcbhIJVEiadO6ffc5JZhMGwj0M9EZbpXcUb3GO7Jp7qn9xk6RKALf9NefPVK deB1tbbnV0ftyvQJv10DFB0Yi3qCsD7gDKszd269VNtaJ99jfe9B+vcJquGv0EJxGqRG 0gIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=hkM2VlDept7ckmc6yvItUWYTkRkdSHCYjtDUAvX91wOJfNuMu2RtPRI28pvHOwpGrg CmKlKjRnD/6J5mCjjnr86kCxuhEa8uDTmjQmsEUhtUBt9ZAfLG7H55dTey9LXETjzgk/ 5jEDpEwbmAi/I88GrFvKzMlHGHUD11hCebuipPqBKC3+4fz5Twh2QqwrLA0qqGpYyTuj 9utkDY1+ER/pVv5t34ENrcyvvvRVz/euhiSkZKxZHFVsygqHlcviyip0XXgMriMLiqIa fccZG+iiw8U/wWFB+DdZRCXWTFImd7dRlt++TMOOGBZE7NwcJxEZKqrL+bnlb277NQTH B04w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="mmJynU/T"; 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 r16-20020a50d690000000b0047ed1256ff6si32132429edi.443.2023.01.05.02.34.16; Thu, 05 Jan 2023 02:34:30 -0800 (PST) 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=20210112 header.b="mmJynU/T"; 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 S232488AbjAEKWF (ORCPT + 55 others); Thu, 5 Jan 2023 05:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231841AbjAEKUA (ORCPT ); Thu, 5 Jan 2023 05:20:00 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6956D559FA for ; Thu, 5 Jan 2023 02:19:31 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id t13-20020a056902018d00b0074747131938so36503973ybh.12 for ; Thu, 05 Jan 2023 02:19:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=mmJynU/TU9vgbAWdVBnooR6qbWy6e6Xt4HjkahKPBivEshc97MtogxTwIBRYXaYqJ0 fSpmPH7oyypf8QtZl1TBck6C8Qnc5vP3vXChtZzIua5/HPzB+uT2N0El75+vpSdXgb3I fXUucvYApqmIOdNMwmWBYNiybAbob8pq547IG5xhW67a2+7RxSBPQsKdkno0G9NfjnHR vThJc94sL2B5jTo0R162NfJZTasyE6NQSOqGcbgqMDv7BN8cJUhlAVO1ikA07733qw6v J0FL1bdTenfsSmm7z4ZB7CRnQWtuNtJNF7SWWWGOq6wzEvgYIHYppRVKiHaPtU8vk09q t6pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=9Yt8Zfl8fNE6CjUoa2m2ZbJ28GLtsXtxPk8weKgz6Sk=; b=cXo5JUEh4o8GWtFh0oryi0iMbw+nEYMwepqaRK37DFNyHS3xixrNsxy4GnAhhfESbO 9Cc+Cq3cT/mYzX2t9pxUg03ukXJ8lpJgCRRqcW2Yt0P4lj5u2wFhx+DvB46SKjN4/JVh wI5wlL7udYE7HTWNkeMVcA/r9zlqCdwAGo5W7XqMlM/7LJRDbRyMjzjVjM4Nv8flAxYe Tl8FDnvyy0Dw/NzR8+6iK+n9F9xdJq3gaIlBS9FxAayJ3WDmnmFrYcyJEg0BWHETQT5P npn259uRI1jWaOJ1o6NGg1SnMWgcMbWkFOiUPiF1hMA83mfX0URmJCGaQteSQUy7q9zz D0Jw== X-Gm-Message-State: AFqh2ko+AcwQSKmLOxIONL3y7Ua3XET/wdCAa6h/3QWWjeX7nRkD+wsj zK3FLGeOLD6lWvNihQTecY0ehcRN0CF9cWL0 X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:5056:0:b0:7b6:2b8f:f2c0 with SMTP id e83-20020a255056000000b007b62b8ff2c0mr25432ybb.46.1672913971225; Thu, 05 Jan 2023 02:19:31 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:23 +0000 In-Reply-To: <20230105101844.1893104-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230105101844.1893104-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20230105101844.1893104-26-jthoughton@google.com> Subject: [PATCH 25/46] hugetlb: update page_vma_mapped to do high-granularity walks From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu Cc: David Hildenbrand , David Rientjes , Axel Rasmussen , Mina Almasry , "Zach O'Keefe" , Manish Mishra , Naoya Horiguchi , "Dr . David Alan Gilbert" , "Matthew Wilcox (Oracle)" , Vlastimil Babka , Baolin Wang , Miaohe Lin , Yang Shi , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 Update the HugeTLB logic to look a lot more like the PTE-mapped THP logic. When a user calls us in a loop, we will update pvmw->address to walk to each page table entry that could possibly map the hugepage containing pvmw->pfn. Make use of the new pte_order so callers know what size PTE they're getting. The !pte failure case is changed to call not_found() instead of just returning false. This should be a no-op, but if somehow the hstate-level PTE were deallocated between iterations, not_found() should be called to drop locks. Signed-off-by: James Houghton --- mm/page_vma_mapped.c | 59 +++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/mm/page_vma_mapped.c b/mm/page_vma_mapped.c index 08295b122ad6..03e8a4987272 100644 --- a/mm/page_vma_mapped.c +++ b/mm/page_vma_mapped.c @@ -133,7 +133,8 @@ static void step_forward(struct page_vma_mapped_walk *pvmw, unsigned long size) * * Returns true if the page is mapped in the vma. @pvmw->pmd and @pvmw->pte point * to relevant page table entries. @pvmw->ptl is locked. @pvmw->address is - * adjusted if needed (for PTE-mapped THPs). + * adjusted if needed (for PTE-mapped THPs and high-granularity-mapped HugeTLB + * pages). * * If @pvmw->pmd is set but @pvmw->pte is not, you have found PMD-mapped page * (usually THP). For PTE-mapped THP, you should run page_vma_mapped_walk() in @@ -165,23 +166,47 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) if (unlikely(is_vm_hugetlb_page(vma))) { struct hstate *hstate = hstate_vma(vma); - unsigned long size = huge_page_size(hstate); - /* The only possible mapping was handled on last iteration */ - if (pvmw->pte) - return not_found(pvmw); - /* - * All callers that get here will already hold the - * i_mmap_rwsem. Therefore, no additional locks need to be - * taken before calling hugetlb_walk(). - */ - pvmw->pte = hugetlb_walk(vma, pvmw->address, size); - if (!pvmw->pte) - return false; + struct hugetlb_pte hpte; + pte_t pteval; + + end = (pvmw->address & huge_page_mask(hstate)) + + huge_page_size(hstate); + + do { + if (pvmw->pte) { + if (pvmw->ptl) + spin_unlock(pvmw->ptl); + pvmw->ptl = NULL; + pvmw->address += PAGE_SIZE << pvmw->pte_order; + if (pvmw->address >= end) + return not_found(pvmw); + } - pvmw->pte_order = huge_page_order(hstate); - pvmw->ptl = huge_pte_lock(hstate, mm, pvmw->pte); - if (!check_pte(pvmw)) - return not_found(pvmw); + /* + * All callers that get here will already hold the + * i_mmap_rwsem. Therefore, no additional locks need to + * be taken before calling hugetlb_walk(). + */ + if (hugetlb_full_walk(&hpte, vma, pvmw->address)) + return not_found(pvmw); + +retry: + pvmw->pte = hpte.ptep; + pvmw->pte_order = hpte.shift - PAGE_SHIFT; + pvmw->ptl = hugetlb_pte_lock(&hpte); + pteval = huge_ptep_get(hpte.ptep); + if (pte_present(pteval) && !hugetlb_pte_present_leaf( + &hpte, pteval)) { + /* + * Someone split from under us, so keep + * walking. + */ + spin_unlock(pvmw->ptl); + hugetlb_full_walk_continue(&hpte, vma, + pvmw->address); + goto retry; + } + } while (!check_pte(pvmw)); return true; } -- 2.39.0.314.g84b9a713c41-goog