Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp21605pxb; Wed, 30 Mar 2022 21:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyfz5gflsa6owlTv9TtRGFEOA/qnzHuLFdTOUxYL7Rbq9Ev4nH+diP5Mzeo8OC31V7f2G64 X-Received: by 2002:a17:90a:4e87:b0:1c7:49c:2e3f with SMTP id o7-20020a17090a4e8700b001c7049c2e3fmr3892147pjh.191.1648701908180; Wed, 30 Mar 2022 21:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648701908; cv=none; d=google.com; s=arc-20160816; b=rh9bwkjmVqf57uIYHGAeyXmQPSCQPNhSXsdpSilKn6bX3jmhZuVYguZ7+7PlIh9mRE KrfYuxj1ni7ANCFH68/HTUPLjsoQFkfoE68OYQ0fDlidIQd4LzoyhieN6jd2NvkhUjNJ Eog/Em46VjClOXgdNmVl4cSJrBBvFTS506griB0pUwrgXLb5MCA/jshu0EGhuRW5mww6 J4LPgxLwmewGilDbTlBWxQW+Xjuv/PrPKz9oVsJo0tZnE+JZKsI5ucczrnQ9wgegEhDw Wt2FIpbvncq+dK+Kaz0m2HVHOYybN263GpAOsI66s8hrZT00GRaJsV9BL2rgdAot1G2P G9Vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=LDGcIKDDCWfntxIrDwg9NeEeCU9Lt3ZtVZJtgLcXbjo=; b=Iz9DId1c+kylcHSaGO3ZyQCdK+uUFXzorWwJb1V3LCZtJO7nitn88G6v0LxgrPuDWh y89n9cRSTKMlX169kIg1mbStR4SKjptcsPSQSQOk1XXM5XfMLtpbp+pZVgY5PmsXHeQ0 yeqkMr1sPsx6QDfALJHEMpQvKsGnVWV0jn6KkSDOVKEtlI+j+btx9kL1UVx5zWsQIB4L h5ovAOv9AhGSLhMTK7jNQg3fG6C7y61/DjcwjwUGoOfdGqtpnIEsZaM1lyCn4lQNb67J 1CalwXH9apqyNaddDXTkaup4Bf5tKnbeZi3KvtqKl0WWz3BmO7PTE0Tqnh3XliKlbWUM Bdag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ehvnGf0k; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id i17-20020a170902c95100b00153b2d1641asi25853561pla.34.2022.03.30.21.45.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 21:45:08 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=ehvnGf0k; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 42CF6139AC2; Wed, 30 Mar 2022 20:42:03 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229810AbiCaC6A (ORCPT + 99 others); Wed, 30 Mar 2022 22:58:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbiCaC5x (ORCPT ); Wed, 30 Mar 2022 22:57:53 -0400 Received: from mail-yb1-xb35.google.com (mail-yb1-xb35.google.com [IPv6:2607:f8b0:4864:20::b35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 071EFD7627 for ; Wed, 30 Mar 2022 19:56:00 -0700 (PDT) Received: by mail-yb1-xb35.google.com with SMTP id x20so39908485ybi.5 for ; Wed, 30 Mar 2022 19:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LDGcIKDDCWfntxIrDwg9NeEeCU9Lt3ZtVZJtgLcXbjo=; b=ehvnGf0k3aAoq9MC2JYKyRY0i4dKaTVRiQuSZTvJKKIQkMCypskYgzN4Xm/JZ52RC/ vK4R4fZ/MtrdkHepjo7BcnI12BnCd+kS2eiqIJB2uoKfcoKGfxcSryGLZzFQXRB/SSqA WxQDRxBwkq47q9kYArRurS3/a/bs9pEhxJ4HWxa/v1mvrJrPsrZgUm21pX5NOE+NCmYP NTDa4hYvbaVQvfUj7MoHdxT+X99VAM/tHihgKAzlBkVVtDaqc9MOOPAHACpZtT83gCk9 cRehK8HZzQ+ywONbDwHF9mFr7g1MEi3Q4cFY7IJOnk+VwX8lXE1NdbVVHaR6WIZUAUdT nC0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LDGcIKDDCWfntxIrDwg9NeEeCU9Lt3ZtVZJtgLcXbjo=; b=EQKvnsx0ArgtGm9rgmVkaeBqPLunNeVijZN83vSqW6XYfLDJ6jDWqBs2aijKRYIhPJ bBKt0n1RCNFYxNXF/XYGdG2Dpv34Mou55UFEyrMWIIB3M5qn4/Ey3RXDQszdwRubyiK0 CCpkbeQA/6muoE/bq03/DnW0oatvGhqdy9cLCVnkkcG79Hc9O7Rt+XZAedGvwhcHSuVY xW8naBiypk21W0AVn8G3fRgjkjdKUyzhRLh56S3sMm24nUGeioeyomBEXQZsSOekmXK9 TvjQKSftxeL+IlEk7DJynod06q9R4n9OrJuKeQXADn6w5oWTvhVnlfBKbc/85JkVgts3 r73A== X-Gm-Message-State: AOAM533Dqy3A/Nx4RvdBCQAyVziJyV1JJ7SVVnxFbnefXzKuuFlBjpr6 XKyY5brzx55CepvRUvT3L1Pl3lHyJpZ0cOI7O5RMYQ== X-Received: by 2002:a25:e70e:0:b0:634:1a47:4ff2 with SMTP id e14-20020a25e70e000000b006341a474ff2mr2484276ybh.89.1648695213764; Wed, 30 Mar 2022 19:53:33 -0700 (PDT) MIME-Version: 1.0 References: <20220330153745.20465-1-songmuchun@bytedance.com> <20220330153745.20465-2-songmuchun@bytedance.com> <20220330192827.4b95e3d7fb149ef9cc687ccb@linux-foundation.org> In-Reply-To: <20220330192827.4b95e3d7fb149ef9cc687ccb@linux-foundation.org> From: Muchun Song Date: Thu, 31 Mar 2022 10:52:58 +0800 Message-ID: Subject: Re: [PATCH v6 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 To: Andrew Morton Cc: Jonathan Corbet , Mike Kravetz , Luis Chamberlain , Kees Cook , Iurii Zaikin , Oscar Salvador , David Hildenbrand , Masahiro Yamada , Linux Doc Mailing List , LKML , Linux Memory Management List , Xiongchun duan , Muchun Song Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Thu, Mar 31, 2022 at 10:28 AM Andrew Morton wrote: > > On Wed, 30 Mar 2022 23:37:42 +0800 Muchun Song wrote: > > > If the size of "struct page" is not the power of two and this > > feature is enabled, > > What is "this feature"? Let's spell it out? Will do. > > > then the vmemmap pages of HugeTLB will be > > corrupted after remapping (panic is about to happen in theory). > > But this only exists when !CONFIG_MEMCG && !CONFIG_SLUB on > > x86_64. However, it is not a conventional configuration nowadays. > > So it is not a real word issue, just the result of a code review. > > But we have to prevent anyone from configuring that combined > > configuration. In order to avoid many checks like "is_power_of_2 > > (sizeof(struct page))" through mm/hugetlb_vmemmap.c. Introduce > > STRUCT_PAGE_SIZE_IS_POWER_OF_2 to detect if the size of struct > > page is power of 2 and make this feature depends on this new > > macro. Then we could prevent anyone do any unexpected > > configuration. > > > > ... > > > > --- /dev/null > > +++ b/mm/struct_page_size.c > > @@ -0,0 +1,20 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Generate definitions needed by the preprocessor. > > + * This code generates raw asm output which is post-processed > > + * to extract and format the required data. > > + */ > > + > > +#define __GENERATING_STRUCT_PAGE_SIZE_IS_POWER_OF_2_H > > +/* Include headers that define the enum constants of interest */ > > +#include > > +#include > > +#include > > + > > +int main(void) > > +{ > > + if (is_power_of_2(sizeof(struct page))) > > + DEFINE(STRUCT_PAGE_SIZE_IS_POWER_OF_2, is_power_of_2(sizeof(struct page))); > > Why not > > DEFINE(STRUCT_PAGE_SIZE_IS_POWER_OF_2, 1); > Yep, this is more simple. But the 2nd parameter of DEFINE() will go into the comments. I want to make it more clear when someone reads the code of this macro. The two different sentences will generate the following two different comments. Which one do you think is better? #define STRUCT_PAGE_SIZE_IS_POWER_OF_2 1 /* is_power_of_2(sizeof(struct page)) */ #define STRUCT_PAGE_SIZE_IS_POWER_OF_2 1 /* 1 */ Thanks.