Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp666081rwl; Thu, 5 Jan 2023 02:52:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXvjth5FKMsUxxONrWvZqTuoKmfB2y6fE9kO/cBRlSv9U630QX9WdrgTzByZy1sy1M9mhBYf X-Received: by 2002:a05:6a20:3d18:b0:aa:5fed:8d6 with SMTP id y24-20020a056a203d1800b000aa5fed08d6mr78146931pzi.15.1672915948533; Thu, 05 Jan 2023 02:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672915948; cv=none; d=google.com; s=arc-20160816; b=yxsIvycxqdoAwJuR6hFstrEybBs/lRT4L6xbEU9pqp/4N8zaB8/mNZv5Dd7ozCMjUR laEiEcz4j31Xb/hcdwE/rFw4a5qyDCHWNFED7bES52Da881Gf8RFrB8JYEk0HyxE1gnb /EjK56E5CK8HKsGD1qtC/m8+71out7Eekr4mQKge10Rd7jU3gkIqoYp09jh/U2o1+C4e BwwJi3IMbzKJ5flRGlEeeni8z31P1i607FhlOKVoqamyaClqEraBKOBGqEuj8PUhIdgI 1HuH0plmv3TYUbVH1RIANxuPUy/hp/2i09cv5IjzkArlll0VQI79Zn/ogmkyyiaAoxUh m+Vg== 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=1YiV8/mi4PL7n0t7wUxWEcBb+colJN0WHKmqKjso6aI=; b=WJfkAzpO4eVNn3kTscuwBs7RvwlmO4/9YAoT0xxInLqTROfn19KCd2/NhnYACeegwF R8IuzTdhA+kfoPXc8fy88zBv/QGnUd1r9sjYjjoOjcGTRNlsaqycbBkvpis6cGrkKRSh 7X2JCGqyYDbRKvdgWaa9fFeKLb0iSK49UNJjj8JYCJWFkuRW81vv9AaYv/ygeVSCIURX GGBRYB0AEhfmSxc9Zwy0lol1CtC2+hU+EDJ5UB4laWPORepOwvTBEEDz47TBHhfx9bgT E/gQ7su8MVmy7XHdO8VOkbQiuze+OQCHzKUeMCjVjfXj8gzyLwuPnVJ+kQ4vZ9JcptLz T//g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=LLH1FHQm; 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 t71-20020a63814a000000b0049ceae025b7si22413126pgd.334.2023.01.05.02.52.21; Thu, 05 Jan 2023 02:52:28 -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=LLH1FHQm; 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 S232938AbjAEKVX (ORCPT + 55 others); Thu, 5 Jan 2023 05:21:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232642AbjAEKT5 (ORCPT ); Thu, 5 Jan 2023 05:19:57 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64687559CD for ; Thu, 5 Jan 2023 02:19:25 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-4b34cf67fb6so64981647b3.6 for ; Thu, 05 Jan 2023 02:19:25 -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=1YiV8/mi4PL7n0t7wUxWEcBb+colJN0WHKmqKjso6aI=; b=LLH1FHQmSuPREM9no8Xr1mrJ+WX7c7pQin9EAc1TvbLcGl/RkRXVwm8E1KdBkYBfGV YIbOE4N1o74dyaPeOKZcf4lLMNNXkB6ntMAbzLwmbHJOP6v9E5qeX1N0aPIuGJxFBbMc DAYDRj/A2/l8+0SDjtsFQpbfETrwBoJUzB2rpy+l5tAr/dFGII17vpR5Red3X2ZytOJ7 oWSpFA1Ze6s9PZS3/XShmJem6/Ne0GdcNEZibyC+1G61SR9BHwKMzCLxkcexZKOZqBmj o+/TsTl7bfdyibV9AZKmqM5CVurcLoGPu4otDexr+01trkvt9Pgocw+EzAHZiG5i0KHf sA1w== 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=1YiV8/mi4PL7n0t7wUxWEcBb+colJN0WHKmqKjso6aI=; b=Kk8s3VtO8SJCYObezdiIa4NF4+tIosP4TcPNkGR/VguwI/IQt4OzzhOVUvVl93uG8J uLwWh9h7vtvXGchXteRiMJZOkcSgGKBEdnQ8pezImzlExYS0M65NJ6I2B/V4Hz8jg+lA FQCqEcUpu9RBfgEyRL+AFTJ6wM1EkTnj/w0RXOv0miRz4oFZjkvfBF2VvrGOJ7h9L9z6 ovNp5qupq38Szq3mkuTwP3nIU9m9LJr89GNPOAkF1ml+tOeFIoeeWhmAH3/sS9ABeWLO Y9iE5c7pP7V+HiyGGPFJuTPqJm6FwrHo850ZwNzzjjCttzDSvo58VO9PsOQwVWdzRual wi3w== X-Gm-Message-State: AFqh2kphvfHqGNIDoqyCiSiZxDR+xcM2sjnddGLHv+pPoW2b6kCbob7r L9SRAH7TT0Lb7U/uSHznQL5l2BOO/ocNkZ1Y X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a25:d06:0:b0:731:7af4:cc3e with SMTP id 6-20020a250d06000000b007317af4cc3emr3400989ybn.368.1672913964504; Thu, 05 Jan 2023 02:19:24 -0800 (PST) Date: Thu, 5 Jan 2023 10:18:18 +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-21-jthoughton@google.com> Subject: [PATCH 20/46] hugetlb: add HGM support for hugetlb_follow_page_mask 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 The change here is very simple: do a high-granularity walk. Signed-off-by: James Houghton --- mm/hugetlb.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 30fea414d9ee..718572444a73 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6553,11 +6553,10 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, unsigned long address, unsigned int flags) { struct hstate *h = hstate_vma(vma); - struct mm_struct *mm = vma->vm_mm; - unsigned long haddr = address & huge_page_mask(h); struct page *page = NULL; spinlock_t *ptl; - pte_t *pte, entry; + pte_t entry; + struct hugetlb_pte hpte; /* * FOLL_PIN is not supported for follow_page(). Ordinary GUP goes via @@ -6567,13 +6566,24 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, return NULL; hugetlb_vma_lock_read(vma); - pte = hugetlb_walk(vma, haddr, huge_page_size(h)); - if (!pte) + + if (hugetlb_full_walk(&hpte, vma, address)) goto out_unlock; - ptl = huge_pte_lock(h, mm, pte); - entry = huge_ptep_get(pte); +retry: + ptl = hugetlb_pte_lock(&hpte); + entry = huge_ptep_get(hpte.ptep); if (pte_present(entry)) { + if (unlikely(!hugetlb_pte_present_leaf(&hpte, entry))) { + /* + * We raced with someone splitting from under us. + * Keep walking to get to the real leaf. + */ + spin_unlock(ptl); + hugetlb_full_walk_continue(&hpte, vma, address); + goto retry; + } + page = pte_page(entry) + ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); /* -- 2.39.0.314.g84b9a713c41-goog