From patchwork Sat Feb 18 00:28:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Houghton X-Patchwork-Id: 13145395 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 0049DC636D6 for ; Sat, 18 Feb 2023 00:29:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4F6F7280019; Fri, 17 Feb 2023 19:29:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 45991280002; Fri, 17 Feb 2023 19:29:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2AF5A280019; Fri, 17 Feb 2023 19:29:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 1CA13280002 for ; Fri, 17 Feb 2023 19:29:15 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id F35F21A050F for ; Sat, 18 Feb 2023 00:29:14 +0000 (UTC) X-FDA: 80478528228.02.1C6F9DC Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf02.hostedemail.com (Postfix) with ESMTP id 459798000C for ; Sat, 18 Feb 2023 00:29:13 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Zm6/7/Qa"; spf=pass (imf02.hostedemail.com: domain of 32BvwYwoKCPUgqelrdeqlkdlldib.Zljifkru-jjhsXZh.lod@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=32BvwYwoKCPUgqelrdeqlkdlldib.Zljifkru-jjhsXZh.lod@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1676680153; 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=mRwFktkeJYIdKMusf4qC81y0TR6AbHEOFSy4VjO6bDw=; b=1WXoPWDhLGW64u5dDE9nG2Q5Q6dZcByJLaEjGq5sBynt3gjMVec3IZf4+Wg3bNwcw54U7k Wkec1fVdmW3b5yWBhAt/HxPaWWqaBgUjLOLepkX4b487B6tp/5X+PVcMQNVu5OYxTg5oBi kGdb8fsbs3ZJ2PWWkkuhxCQ4noIofH0= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="Zm6/7/Qa"; spf=pass (imf02.hostedemail.com: domain of 32BvwYwoKCPUgqelrdeqlkdlldib.Zljifkru-jjhsXZh.lod@flex--jthoughton.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=32BvwYwoKCPUgqelrdeqlkdlldib.Zljifkru-jjhsXZh.lod@flex--jthoughton.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676680153; a=rsa-sha256; cv=none; b=anheXFn5dwI9UN4sByB+cpTM7Ja+ooRrWGcni4+wmAXrCLgTLyiGOlFZHIfkmyynF7/8fN AUKr30V/fRJ0W2cO0diopyl3IrQTsYynx1YXCo2I6w+qlsNhaljJsD9Zq/JqYsv/ybh5q8 gqgv4NgaiGCV6Cf4ifLIQ86KZDSt8Wg= Received: by mail-yb1-f202.google.com with SMTP id b15-20020a252e4f000000b008ee1c76c25dso2086503ybn.11 for ; Fri, 17 Feb 2023 16:29:12 -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=mRwFktkeJYIdKMusf4qC81y0TR6AbHEOFSy4VjO6bDw=; b=Zm6/7/QaEOKxvrDuMfeB7vwmF4lLu6UTGBUmswTJcUAlfDSMlIReG5bhg0wTj24gmC pyzKX/4iSeu0TJCnoaa5IeZeAwpPJP4t7J15FYcDft0GCDUyIekB7QiiA5d6VpYF6r1H nOxlRQfswvR4QTg+iFofMR17/iZTfwCKWd+Emo/OWhpb51k0Epcgf3/x2g21X+2fJvir E6KpK03FxgLoBdBKPFmKqjWGZ7c7Mw5BSnv8qT+zAW5LhNVyj/X7uCXj4k6ZrqZKQzWs jRtMwhX56IYmGhi9pxW4bL/oSI6T41SeQ+p8o0DKCkHwnC/wa7X1kwvdzUJ3ryjcOdKA 7yIw== 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=mRwFktkeJYIdKMusf4qC81y0TR6AbHEOFSy4VjO6bDw=; b=6uXENifqCagfFy7irmNVRMWyCh2yg4fLhgqef1v3+DBJ4zfMny3sYRuvTB5DhtAIcv ehHl8H3uCocTYz6Lz54jJdqi8sjVOEbjFqn8b5dfN5xQsqjZ6QkqTRrrrDUZWBUTq9Ls NLhl/+7NLrwobKLwfbda29GbmueVy5B0PZZop96w5tis4HaAQAGLsj92rEo2lxlVEaG5 G9RkzXE0CRS1wfKJ7PezC13BDxtfLC8bgwR9XZp4vxGs2Fy1HvHrMXtoqdmqKmZZSvr7 B+HyC0MEnMnOfHhrwHKUFPBOTKQgiB0wY4HvBloKHq/iOFO6rI3kTguv22HMmFVLcCuM 75Xg== X-Gm-Message-State: AO0yUKWxZJFBYn1H9F7lLAYTHWwA400c1kuxrskSUewL7ee9uKribCih 0A6Qb/MCYj0ONFNBTYqrLhxefuH68BdxiEnS X-Google-Smtp-Source: AK7set8dwJ3KQ5pRHgFDkybx18bdI4wSFLevnVCzXA1Or4MzQVqGPdFvHJZtBGks9A5Y7+5HxTvdx/c0MRnYUx9S X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:1103:b0:8ed:3426:8a69 with SMTP id o3-20020a056902110300b008ed34268a69mr91121ybu.1.1676680152644; Fri, 17 Feb 2023 16:29:12 -0800 (PST) Date: Sat, 18 Feb 2023 00:28:02 +0000 In-Reply-To: <20230218002819.1486479-1-jthoughton@google.com> Mime-Version: 1.0 References: <20230218002819.1486479-1-jthoughton@google.com> X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230218002819.1486479-30-jthoughton@google.com> Subject: [PATCH v2 29/46] hugetlb: update page_vma_mapped to do high-granularity walks From: James Houghton To: Mike Kravetz , Muchun Song , Peter Xu , Andrew Morton 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 , Frank van der Linden , Jiaqi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org, James Houghton X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: pogkfapcycjnd64z8n6ysf65bdrzyc5k X-Rspamd-Queue-Id: 459798000C X-HE-Tag: 1676680153-540137 X-HE-Meta: U2FsdGVkX1+Q2Y2LqqsFDkH6UwTHZ4VKnuScf6D32B6Bog0PpuTPV+7w27c0Ok4fuNaXsbKjIkMQF3yrgg/y9DKR1YuDyJYsX2r/Fo7VCGHX7UJzatZNv3pbzLz7yJB/iVXVFNH6bqnD0DTTqU/OHDiGHrFJtIVHHzGUYJ8dgV6s07OjIeUY0pH0qL44OxQ6eSyB3tgFcrNwqIOUoZD4kN44w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8kGvGBbL6tKdO0devrsKLRmVR9DTihlDVtIjACoOuUFA9YaxE2iGOQJtVujoh0AsuTzd9CKjtvVhihnp9bpNWHX28/r069PE+ZB5tfKI/f74Zi5fFf0TpQsA5fy0OWj0TN2QUpMWs0K4iaci15MRx4M9mdp6gtD4+kxI9jkjFY8WN/+knBL9D3y/82iFLHD3JCYeEw+JUFDI7NGnO4n8N34zjw/mLSutwVCyHu2BPNnvcy9rQ2pyfFwsdcdibAUuU8uU1ymdryJ1m9Ak4lOFQmmgEggq4bTzoguIwhV4sedewosh9fNYSkjinVQ= 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: 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 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; }