Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2971552rwi; Fri, 21 Oct 2022 09:55:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7DPzJytlS9G+YWERIRQt7h1AgSBjNeN46oXjcgOi7DYx1Qzdlp8vQwp/7EsR1dorITgLrA X-Received: by 2002:a17:906:2bc7:b0:72f:dc70:a3c6 with SMTP id n7-20020a1709062bc700b0072fdc70a3c6mr16458664ejg.645.1666371312267; Fri, 21 Oct 2022 09:55:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666371312; cv=none; d=google.com; s=arc-20160816; b=TBPP05tzrNmIImjNnbIzRCuAA/NwKHAS++tKzkSbOMqaSiWmoMT9ifPlU4sZ5yBGLV 3+FqOc1ia3y1ZpD60CL3QRc8C2ReGuSxXBXN9On6yR8RSma7AQ84LhlTGdeWIl2bozUX tIPISo6J8MRHjp5wwecQ9y5m9zPlYQQsnzvS6Frjje5awXy7VVhALKwYTcEUTF8/zyoB Whvx6jrkPQ0qZbp1PUFzyBBl2OrOtW4lgBZzbnErLUBk0ypV+Gc3fhFdkiTGqQ4/6fFp xUtvSNjvG3ZajJ39u5IO+6jXd/VefmujS8SWrUMORCeJ7k1MYK6doNIlOaJZWZz4cXov Pkcw== 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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=og6SqWUkec4a1KUJgqsHDbqEU1iTNsvdc1Bd+D4zlEABIcGZOc2AIfOKy1rDSO5KCL LnlKzKHGWXKzgqwMLecBj1pizQ12e381IBO1PQggJxBvTK26HibLUM2T6JpnKTA+1qSi X+wYu5dW0NHss5D0qnW1qqvLnjE6NvnPeKb+wxv3vSxiEHORZkmjm/aJmXxoSNsGCqY8 0o9DB31ePt+tpV7N6fiZ3RU92reoeuhiew1e5cGSV0pZu/2VjJqcqtJDEqyj3JGaOrL3 6zRZJotOddFfnjXcKOY+8/Aue7Xolel/RqmVG94gAyabQwsb8FHvvDxXoJy/vtTsNkZI fq2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nd84xfoS; 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 di13-20020a170906730d00b0078d1e08f1e5si19705372ejc.919.2022.10.21.09.54.47; Fri, 21 Oct 2022 09:55:12 -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=nd84xfoS; 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 S231400AbiJUQlT (ORCPT + 99 others); Fri, 21 Oct 2022 12:41:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231290AbiJUQjd (ORCPT ); Fri, 21 Oct 2022 12:39:33 -0400 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 A183F2892E3 for ; Fri, 21 Oct 2022 09:37:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id o4-20020a258d84000000b006bcfc1aafbdso3722554ybl.14 for ; Fri, 21 Oct 2022 09:37:47 -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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=nd84xfoSk805dVcAVyuoNqGohV7P5cWuxEwnitdbs1rkx0N7wPZbXDeJ4RvhkuBQuI 1v5ieZAWL4fzYytJgsDwUG418qnEFB1/qmZtj48lT3wl5WE9DVb2V1XTv+zdOICQ5pda 5diZHurVjQaoJ7Iv2PjP8DCGO1/4fukcBNdxrI/uAXh+hc99Z5wn2kayMv2lFTeOX5T6 kP7/z1HmhxO1WbkpEmUOZN3ey0YjwgIFaCUcG52wZtr3jBV58ShZQQ9oLg2hp/N1Ghjm Ji/V0BtPfvSDPqTGOkZQH+0TcxQ7lca6EKfHqsThwhdtFcp6XI9rp8phcpX8i0ybjokl Tk3Q== 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=WxKGqQ6TZ4IrlRpo46PGVbYr6hPIEsEGe3hsSCnb6qg=; b=4dLlbuKN1GjeYFVaTXVd+pXYSwmLJtxH5AGeziP8I2DOEds1H8LgrYVQT+Vvl5HVrm 1NNqjoiN7cCqNxR5DvTZ9ZO+JA2YI2gKKn87D0U+qMBNw8Ww35hReEcjGeIXwi+6fbXh Linz5DUSuMASKGTTwdx1Rx/rJ1+LTYVRq51ZlBMmLWJK1aryDht4hMPb/iyu2q/OFJt0 dA4rJKwx9zWxqhrJBxzyLDTQeguJEQFyDhUbAZJ4dcwaiTZqxZ1hoyjY0yPygRflTTlz IkMG1NiDvZEJJFAopJzd3QjRDD83XfHPi2EwpSNXiCr9hFTvNGvqN0p443JmpVJU9UEc 0Z3w== X-Gm-Message-State: ACrzQf1/PzzSaZh+ktpR5zGTAafpSOzXCsIPlzRs9KSbEr+3/erj2DFJ UNA4wdQpSQvn8DHGnabWL+Cg/gKmm7W1R4tX X-Received: from jthoughton.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2a4f]) (user=jthoughton job=sendgmr) by 2002:a05:6902:1027:b0:6ca:71ca:e68b with SMTP id x7-20020a056902102700b006ca71cae68bmr2934076ybt.2.1666370266458; Fri, 21 Oct 2022 09:37:46 -0700 (PDT) Date: Fri, 21 Oct 2022 16:36:48 +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-33-jthoughton@google.com> Subject: [RFC PATCH v2 32/47] hugetlb: add for_each_hgm_shift 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 This is a helper macro to loop through all the usable page sizes for a high-granularity-enabled HugeTLB VMA. Given the VMA's hstate, it will loop, in descending order, through the page sizes that HugeTLB supports for this architecture. It always includes PAGE_SIZE. This is done by looping through the hstates; however, there is no hstate for PAGE_SIZE. To handle this case, the loop intentionally goes out of bounds, and the out-of-bounds pointer is mapped to PAGE_SIZE. Signed-off-by: James Houghton --- mm/hugetlb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index d6f07968156c..6eaec40d66ad 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7856,6 +7856,25 @@ int enable_hugetlb_hgm(struct vm_area_struct *vma) hugetlb_unshare_all_pmds(vma); return 0; } + +/* Should only be used by the for_each_hgm_shift macro. */ +static unsigned int __shift_for_hstate(struct hstate *h) +{ + /* If h is out of bounds, we have reached the end, so give PAGE_SIZE */ + if (h >= &hstates[hugetlb_max_hstate]) + return PAGE_SHIFT; + return huge_page_shift(h); +} + +/* + * Intentionally go out of bounds. An out-of-bounds hstate will be converted to + * PAGE_SIZE. + */ +#define for_each_hgm_shift(hstate, tmp_h, shift) \ + for ((tmp_h) = hstate; (shift) = __shift_for_hstate(tmp_h), \ + (tmp_h) <= &hstates[hugetlb_max_hstate]; \ + (tmp_h)++) + #endif /* CONFIG_HUGETLB_HIGH_GRANULARITY_MAPPING */ /* -- 2.38.0.135.g90850a2211-goog