From patchwork Tue Mar 30 08:08:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yanan Wang X-Patchwork-Id: 12171979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD0F3C433E1 for ; Tue, 30 Mar 2021 08:10:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7A15D619A6 for ; Tue, 30 Mar 2021 08:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231546AbhC3IJt (ORCPT ); Tue, 30 Mar 2021 04:09:49 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15103 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231336AbhC3IJM (ORCPT ); Tue, 30 Mar 2021 04:09:12 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F8hqs4k0gz19Jq6; Tue, 30 Mar 2021 16:07:05 +0800 (CST) Received: from DESKTOP-TMVL5KK.china.huawei.com (10.174.187.128) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.498.0; Tue, 30 Mar 2021 16:09:01 +0800 From: Yanan Wang To: Paolo Bonzini , Andrew Jones , , , CC: Ben Gardon , Sean Christopherson , Vitaly Kuznetsov , Peter Xu , "Ingo Molnar" , Adrian Hunter , Jiri Olsa , Arnaldo Carvalho de Melo , Arnd Bergmann , Michael Kerrisk , Thomas Gleixner , , , Yanan Wang Subject: [PATCH v6 02/10] mm/hugetlb: Add a macro to get HUGETLB page sizes for mmap Date: Tue, 30 Mar 2021 16:08:48 +0800 Message-ID: <20210330080856.14940-3-wangyanan55@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210330080856.14940-1-wangyanan55@huawei.com> References: <20210330080856.14940-1-wangyanan55@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.174.187.128] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We know that if a system supports multiple hugetlb page sizes, the desired hugetlb page size can be specified in bits [26:31] of the mmap() flag arguments. The value in these 6 bits will be the shift of each hugetlb page size. So add a macro to get the page size shift and then calculate the corresponding hugetlb page size, using flag x. Cc: Ben Gardon Cc: Ingo Molnar Cc: Adrian Hunter Cc: Jiri Olsa Cc: Arnaldo Carvalho de Melo Cc: Arnd Bergmann Cc: Michael Kerrisk Cc: Thomas Gleixner Suggested-by: Ben Gardon Signed-off-by: Yanan Wang Reviewed-by: Ben Gardon --- include/uapi/linux/mman.h | 2 ++ tools/include/uapi/linux/mman.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/include/uapi/linux/mman.h b/include/uapi/linux/mman.h index f55bc680b5b0..d72df73b182d 100644 --- a/include/uapi/linux/mman.h +++ b/include/uapi/linux/mman.h @@ -41,4 +41,6 @@ #define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB #define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB +#define MAP_HUGE_PAGE_SIZE(x) (1ULL << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK)) + #endif /* _UAPI_LINUX_MMAN_H */ diff --git a/tools/include/uapi/linux/mman.h b/tools/include/uapi/linux/mman.h index f55bc680b5b0..d72df73b182d 100644 --- a/tools/include/uapi/linux/mman.h +++ b/tools/include/uapi/linux/mman.h @@ -41,4 +41,6 @@ #define MAP_HUGE_2GB HUGETLB_FLAG_ENCODE_2GB #define MAP_HUGE_16GB HUGETLB_FLAG_ENCODE_16GB +#define MAP_HUGE_PAGE_SIZE(x) (1ULL << ((x >> MAP_HUGE_SHIFT) & MAP_HUGE_MASK)) + #endif /* _UAPI_LINUX_MMAN_H */