Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp32768pxb; Wed, 30 Mar 2022 22:07:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx04kcnyzUdqSNatI7RX+NHqwF9DtG+TJRuNr1Ci71FIJ4A/X3Fe4GWPtuyqnrJt+ARY4Co X-Received: by 2002:a17:902:c784:b0:156:15b:a739 with SMTP id w4-20020a170902c78400b00156015ba739mr3303507pla.146.1648703261678; Wed, 30 Mar 2022 22:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648703261; cv=none; d=google.com; s=arc-20160816; b=fCYLsLgt1b4OFPMy3ccPh9tlombU/zXcvUX1z88Qfv/VzydoofyfxPRKdvB46IMlJf 4RN7Abozae8aMgos+zvTtfP99fLDVxu2ZxxMO+yEjUf8SK0BfifSwPeBUR0hghYDkZlu ljEODSkeg64dq4BGV6svXAiL7vXlaj50UVBXTeM+trVr90BjajlG+qZvMZn3nY+g/gLg IHK3Q9FG3AxRLTg4VGOr9xdTLOn1vUBA/K2AoQLnkpHkThxzD9EVW0h+2TPPIAj2IBLx MzkCLXUcGCyDyhNvTACgnlSp97Wkd7LIRlOXIIZPzolWNu0CH19fkM9LQDrhAG+uCPQe ko3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=Ua8UaTFI67G0Cv07l0o/kWjxFQ2ehoUvU2qsvStlmPk=; b=xKdQtMndj3WLrniBeci5o1t43iFl3jqyXLUp+4WJBdIGBAnACQ2aANeSgT33RtGMzH Q3jB2OJekRd6kVESyhTjx111yLMtx/D1Hpe+Ead1mPes6GQVOEg+z+xrq9+cIQY/wV9W ZfkcvcgXL+yD2fhvavxWmX135ksIi8aSs2qrQMWc6DRt/zGpsxwXVDmqxvw1N4zNAZ8u vK4Qc+G0JBTkSRzJ1WybE0+QTAFxztztjV3GSkFxWhgdEEWsA9NhIcNM+Swndz3mcbZ/ iy4ZTDByOykHqYfyyZhqBTf4xTh5ENsrS7MXPMi+ErFtL39xzJZbmmfrXr7cahxoSGLQ LWcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EcssqheL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y9-20020a17090322c900b00153b2d164c2si25610794plg.202.2022.03.30.22.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 22:07:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=EcssqheL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F1901287A08; Wed, 30 Mar 2022 20:42:20 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229964AbiCaCaZ (ORCPT + 99 others); Wed, 30 Mar 2022 22:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbiCaCaX (ORCPT ); Wed, 30 Mar 2022 22:30:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9A6D13DFC; Wed, 30 Mar 2022 19:28:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 31C7BB81E87; Thu, 31 Mar 2022 02:28:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7637EC340F0; Thu, 31 Mar 2022 02:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1648693709; bh=+adBEntIzSSCVYqEhFC0POeZQwSN/e4WeFGSC39cYN0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EcssqheLZ56lijPSSHBApcxEaeL+Lmoj5IBhJoTd7QNYuZPZuSuA/3LYmjVFeQhb0 J1syqwcskBuQ0fhmx0C2KAj1OIE8NRR1bBLk599P3q83/j0nJjxapeSy7J2GGPgTPE dJUkmRKtvEOQS/V13ifwMGLP5tMhovnjLpD7laGY= Date: Wed, 30 Mar 2022 19:28:27 -0700 From: Andrew Morton To: Muchun Song Cc: corbet@lwn.net, mike.kravetz@oracle.com, mcgrof@kernel.org, keescook@chromium.org, yzaikin@google.com, osalvador@suse.de, david@redhat.com, masahiroy@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, smuchun@gmail.com Subject: Re: [PATCH v6 1/4] mm: hugetlb_vmemmap: introduce STRUCT_PAGE_SIZE_IS_POWER_OF_2 Message-Id: <20220330192827.4b95e3d7fb149ef9cc687ccb@linux-foundation.org> In-Reply-To: <20220330153745.20465-2-songmuchun@bytedance.com> References: <20220330153745.20465-1-songmuchun@bytedance.com> <20220330153745.20465-2-songmuchun@bytedance.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,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 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? > 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); ? > + return 0; > +} > -- > 2.11.0