Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2973488rwi; Fri, 21 Oct 2022 09:56:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZmiFt2MQU254Lu58GAcBJZVbedZU0p6TufcFLrhiIo34FQ6h1QagbBBw7JyL6vYdo2nEJ X-Received: by 2002:a17:907:7203:b0:792:56d7:2851 with SMTP id dr3-20020a170907720300b0079256d72851mr12062117ejc.268.1666371417497; Fri, 21 Oct 2022 09:56:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666371417; cv=none; d=google.com; s=arc-20160816; b=YLGB6jwgsGu5FGL2YvIJptu8DxVEaAj7IliT2RitmW3TnBaIy1oOuYgq69BmHnK0uv z4Kz9L3hBp2XAEkvIqy9ta3AECGEkKDHCqBOOT+Vd6xTjdO7FdcMkUOEkwACYjp+SUHP DzY71OuKVkSJfi4FpWNB8fDaojMReJIqk5NJH1GE1COHK+h64J9kdCI90y52q9sPLbXn Y5zBgqi9r91rdQ/lHMugA8oVDrHqnrtyo/bJG5+wXu21qG98LESOeKKdJKP27plHqaBa rSLA5Q5VpokpVM7mjMMFyOfJWn8GF14os4MLSVf/YFT/x69IsdJPjE6nqLoI76N9w1+R tGBg== 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=CRJ6pkRKArtLmZe7XMBJjGLJyFbSk0rbbeye9q84C9k=; b=OTzr9noAMNXsBr2MRuLojqacOllw0GHcvx1uFCM/Qs2uW09MTD4+26K74v9FA4Hj0w WLySGXPGDR5Ms8xsn55W0TJ5dtP25Rv1f9ftmJGSTWmazdUVlVcMZYYLdu/udA8tQ+Fl VdoOYsH3c/dhhAvdEZZfr4Cr3X05PbIAAc7FgHCW/4mtmMXLVsm03lVE9emBTo7rYF6n pNS4BJYhU0cxNmPHhlCc1TGflZLryq3snS3E4bsX3hZYhZamx7vUrD6HLkUcV/djU8xP U8iPcX0niFOnjObG3xgSuuWqoeuCw22tuX3ZJWoeAH5QKEhE/NCLMFAS/ruBLh1OSVsz ij5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ZQtGwmeX; 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 p7-20020a170906498700b0073d8659db5csi18152718eju.966.2022.10.21.09.56.32; Fri, 21 Oct 2022 09:56:57 -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=20210112 header.b=ZQtGwmeX; 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 S230460AbiJUQjF (ORCPT + 99 others); Fri, 21 Oct 2022 12:39:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbiJUQiJ (ORCPT ); Fri, 21 Oct 2022 12:38:09 -0400 Received: from mail-vs1-xe4a.google.com (mail-vs1-xe4a.google.com [IPv6:2607:f8b0:4864:20::e4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 886E7285996 for ; Fri, 21 Oct 2022 09:37:35 -0700 (PDT) Received: by mail-vs1-xe4a.google.com with SMTP id i4-20020a05610220c400b003a7718929ecso1043612vsr.10 for ; Fri, 21 Oct 2022 09:37:35 -0700 (PDT) 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=CRJ6pkRKArtLmZe7XMBJjGLJyFbSk0rbbeye9q84C9k=; b=ZQtGwmeXsLEasfxlAVd+Ky+KcZ4u0ied8Nvno8abVpS+XKmDnGeaG7sbDC8DX8DjvM 74vP8xl/C/D6frwkZjH0NjGEaALQrxYOl4qyIHM6NFQ6TqBYFbfRh99+goV7aMS+wqHZ EWOers7WW52iKsOYpfLe1iauG6eIptFtQYmFfmKiotPdEPO4sKbu65xEzDbR/5RG82C/ y77vYpTF7YV+Whm4oAUX1QUUOJtL0b1RKIBN4O1mH8xMYkKU5aZVNAgTr4TGtpelYVZI e9gU8PeJNzs1B5TCPPy55btaAR0P5+I/VVVQLdPgY9hG0sq1HT32TKdmh24otsMY096+ x/yw== 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=CRJ6pkRKArtLmZe7XMBJjGLJyFbSk0rbbeye9q84C9k=; b=QXrSZID3DZb2tjqMQ3iz4ddmhYtkKm5Xk55sArygLEkLaKi0F/Fq/5gb2h45ehMUjS uGgBBXVjE9U2ZgrsMea35WJ02Cx7sw6eMBbVBDVbwRLcEI2GxHMR8n2DGR01tfFKAY7e EHI0ZHfm18/P6FHwbyDEi76BcGl7NolszPrH3ounF2eQSnjnv9dZAalw0FveFJe+M8Yh pRaYfKVq9nrbDI2UtnKpDUxFG+wK/qc63sCxGD4ElzLizgk72mOCCl8Mkvm3fknHl/4/ zW7yZaS+/BBRxMvcbaWfMZMxDmEXyOOhOIU//ny1R0vm+YHuPBrx2f2u1OUKNSBg3aQn kCrw== X-Gm-Message-State: ACrzQf2dgtVGS4ZhR1wwh4oAmVjMbmKfrQsYhv4rUW+NprYLHBJneyqX Lj9BS3RDel0Lr22Sbo/yPeYTIefKQREX3Pxo X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6102:3678:b0:3a7:6056:9e7a with SMTP id bg24-20020a056102367800b003a760569e7amr12639659vsb.62.1666370254111; Fri, 21 Oct 2022 09:37:34 -0700 (PDT) Date: Fri, 21 Oct 2022 16:36:35 +0000 In-Reply-To: <20221021163703.3218176-1-jthoughton@google.com> Mime-Version: 1.0 References: <20221021163703.3218176-1-jthoughton@google.com> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog Message-ID: <20221021163703.3218176-20-jthoughton@google.com> Subject: [RFC PATCH v2 19/47] hugetlb: make hugetlb_follow_page_mask HGM-enabled 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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d76ab32fb6d3..5783a8307a77 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -6408,6 +6408,7 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, struct page *page = NULL; spinlock_t *ptl; pte_t *pte, entry; + struct hugetlb_pte hpte; /* * FOLL_PIN is not supported for follow_page(). Ordinary GUP goes via @@ -6429,9 +6430,22 @@ struct page *hugetlb_follow_page_mask(struct vm_area_struct *vma, return NULL; } - ptl = huge_pte_lock(h, mm, pte); +retry_walk: + hugetlb_pte_populate(&hpte, pte, huge_page_shift(h), + hpage_size_to_level(huge_page_size(h))); + hugetlb_hgm_walk(mm, vma, &hpte, address, + PAGE_SIZE, + /*stop_at_none=*/true); + + ptl = hugetlb_pte_lock(mm, &hpte); entry = huge_ptep_get(pte); if (pte_present(entry)) { + if (unlikely(!hugetlb_pte_present_leaf(&hpte, entry))) { + /* We raced with someone splitting from under us. */ + spin_unlock(ptl); + goto retry_walk; + } + page = pte_page(entry) + ((address & ~huge_page_mask(h)) >> PAGE_SHIFT); /* -- 2.38.0.135.g90850a2211-goog