Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp630828pxb; Wed, 16 Feb 2022 00:22:19 -0800 (PST) X-Google-Smtp-Source: ABdhPJwR0WDf1LjKACm/53vROJHg1g4bYjEVNVO+qZYvunKbfTlb/l0GwT7nSZ5I6MTvK2EM74Bc X-Received: by 2002:a17:90a:8591:b0:1b9:da10:2127 with SMTP id m17-20020a17090a859100b001b9da102127mr454294pjn.13.1644999739456; Wed, 16 Feb 2022 00:22:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644999739; cv=none; d=google.com; s=arc-20160816; b=oFzLtprTB9gkUqnVJMgMcUJ6f2AnAx82ekhBpFSyWfDp1a763N3+gKv7VIlH76yVCT sPygTr0ARfvyHGUgljKz7XD9+WzCnSN614clL4obwWD4QaLAJ2dA8kjo9D2Urg/6ULU6 m5RwBes094FAFhJoU8TB6bctMsAwpnKdvvVMcTbzsRTedX4cA7Iagkr+GoBlT7dUKjow ZunGcBSM5rlslDsNLYClDNxpe8mXeh6b/X2SQRNcXWfcBBggQhpM3fmDiASE0paG/Vax 2pD5MbOr7A578fBoMb8xIPd8G6WPr8JDueaLT0Cal0KKF2KxEmXsaEXOuYSpUGLisMqM UCRQ== 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=sKNzKBb19Do3NGmL01/2ZoAEl367WiU5/pzUcTTd170=; b=aJc7nTqiajcHf7cgkcKjvIVtv1BiKhOld05O+QHnApuCnHFHDk0ox00AY9cbit88W4 MpjZB7bdNoT4SU0NSGfe5Ap/8Qfxgh3Q/2kAqB0Pvbpr3nEPfHfp/1E7DwLRmEHqZhHD oc4t6GHieUHvJe/T04TVqRQxZ16UVOp+JBIeWVLjUHJzqqSC7j3PrSfuHyJIfT8h6wGR l6NlqAIa5Yb7C0io377GlxBd50I8O3m7n4KKQ+DA2oBWVONSelFtF320FDxpb3DwF9cX z0OL7YdpHZknXHtm8QEQsz9t8RDqN03AyK+sdx8xdI0tdrPscXnOQtBRtU2ntlCrPyZC +1sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=Vs36gc3f; 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 m1si6542669pgu.609.2022.02.16.00.22.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Feb 2022 00:22:19 -0800 (PST) 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=Vs36gc3f; 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 312A2238900; Wed, 16 Feb 2022 00:05:50 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231279AbiBPIF6 (ORCPT + 99 others); Wed, 16 Feb 2022 03:05:58 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:54574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231417AbiBPIF5 (ORCPT ); Wed, 16 Feb 2022 03:05:57 -0500 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02951235857 for ; Wed, 16 Feb 2022 00:05:45 -0800 (PST) Received: by mail-yb1-xb30.google.com with SMTP id v186so3697541ybg.1 for ; Wed, 16 Feb 2022 00:05:44 -0800 (PST) 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=sKNzKBb19Do3NGmL01/2ZoAEl367WiU5/pzUcTTd170=; b=Vs36gc3ftF5yVkEl7PjXZQrnqiSL9oAPR1PmipoQVMOA0w+rD3oBNP6pQzK/rZADH3 Bk0A7vPTVpmr8Y4S9uEOpwGDZq232z+e9v18C7bAy3SCoHzi1r8E2pOBBowACqQN7WpN 0XMs0LATWPNEfJLFqeXftM4qgZuHS7FFtVMrmX2qh1QW8tiTUI44Xss5hoSv7Soh3Lwd /lLqcu/xYrF8Cibm41ZPRqiFjCTo+nTNjDBERw0A9pfK0q7tc0mIoqySOZY0fndicvvg mMWRM/YLGdaGuoNgpfmeYVdC1jDck29WGCmOcojgFIIda8arRXJlNWgBtki73KRdDHCU KkaQ== 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=sKNzKBb19Do3NGmL01/2ZoAEl367WiU5/pzUcTTd170=; b=XakLawoxlPx6vrAFB6mz14KDBqnsX368JDkxHxl48TgkF/KmjBBC6ObqBu6qJMrX3w eKKw506FlD5rvtL17mBzsoyKwtYb9+vn+faQETV5u6YpiO24FFQPJXCxa9BE5aW+nkwK yVLZHw7zIPKIVnl1xCCshQdxv3WK5Cf0G7I7zxD/j4WC4zBUtY/WqIG7YZjbIbUN/PWc alu073ohH3jSyQJ3O4qj16wxw39hKLrDF/NlNikKAXogpdB50ug6CxD9OSWlA8YJXdIn P4Ei9Q3FZZS5p5DkcpYZjoDsKAx+uLWjppneWgNNsVWJtcbP6PL5fLFEMkNMGFmQufzi i1Yw== X-Gm-Message-State: AOAM533rG3k0xi+Yie5WcaWWnlDAHYq790t22t6aj6vMpkUoxQlyinb4 HvISvjHS2VCwEjhawIjvUotf7QoGcHQ6zcMiHvCyPg== X-Received: by 2002:a25:e0d0:0:b0:613:e5b1:277e with SMTP id x199-20020a25e0d0000000b00613e5b1277emr1198675ybg.132.1644998744242; Wed, 16 Feb 2022 00:05:44 -0800 (PST) MIME-Version: 1.0 References: <20220208054632.66534-1-songmuchun@bytedance.com> <20220208054632.66534-2-songmuchun@bytedance.com> In-Reply-To: <20220208054632.66534-2-songmuchun@bytedance.com> From: Muchun Song Date: Wed, 16 Feb 2022 16:05:07 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] arm64: mm: hugetlb: add support for free vmemmap pages of HugeTLB To: mark.rutland@arm.com, catalin.marinas@arm.com, james.morse@arm.com Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com, David Hildenbrand , Mike Kravetz , David Rientjes , Oscar Salvador , "Bodeddula, Balasubramaniam" , Andrew Morton , Will Deacon 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 Tue, Feb 8, 2022 at 1:46 PM Muchun Song wrote: > > The feature of minimizing overhead of struct page associated with each > HugeTLB page aims to free its vmemmap pages (used as struct page) to > save memory, where is ~14GB/16GB per 1TB HugeTLB pages (2MB/1GB type). > In short, when a HugeTLB page is allocated or freed, the vmemmap array > representing the range associated with the page will need to be remapped. > When a page is allocated, vmemmap pages are freed after remapping. > When a page is freed, previously discarded vmemmap pages must be > allocated before remapping. More implementations and details can be > found here [1]. > > The preparation of freeing vmemmap pages associated with each HugeTLB > page is ready, so we can support this feature for arm64 now. The > flush_dcache_page() need to be adapted to operate on the head page's > flags since the tail vmemmap pages are mapped with read-only after > the feature is enabled (clear operation is not permitted). > > There was some discussions about this in the thread [2], but there was > no conclusion in the end. And I copied the concern proposed by Anshuman > to here. > > 1st concern: > ''' > But what happens when a hot remove section's vmemmap area (which is > being teared down) is nearby another vmemmap area which is either created > or being destroyed for HugeTLB alloc/free purpose. As you mentioned > HugeTLB pages inside the hot remove section might be safe. But what about > other HugeTLB areas whose vmemmap area shares page table entries with > vmemmap entries for a section being hot removed ? Massive HugeTLB alloc > /use/free test cycle using memory just adjacent to a memory hotplug area, > which is always added and removed periodically, should be able to expose > this problem. > ''' > > Answer: At the time memory is removed, all HugeTLB pages either have been > migrated away or dissolved. So there is no race between memory hot remove > and free_huge_page_vmemmap(). Therefore, HugeTLB pages inside the hot > remove section is safe. Let's talk your question "what about other > HugeTLB areas whose vmemmap area shares page table entries with vmemmap > entries for a section being hot removed ?", the question is not > established. The minimal granularity size of hotplug memory 128MB (on > arm64, 4k base page), any HugeTLB smaller than 128MB is within a section, > then, there is no share PTE page tables between HugeTLB in this section > and ones in other sections and a HugeTLB page could not cross two > sections. In this case, the section cannot be freed. Any HugeTLB bigger > than 128MB (section size) whose vmemmap pages is an integer multiple of > 2MB (PMD-mapped). As long as: > > 1) HugeTLBs are naturally aligned, power-of-two sizes > 2) The HugeTLB size >= the section size > 3) The HugeTLB size >= the vmemmap leaf mapping size > > Then a HugeTLB will not share any leaf page table entries with *anything > else*, but will share intermediate entries. In this case, at the time memory > is removed, all HugeTLB pages either have been migrated away or dissolved. > So there is also no race between memory hot remove and > free_huge_page_vmemmap(). > > 2nd concern: > ''' > differently, not sure if ptdump would require any synchronization. > > Dumping an wrong value is probably okay but crashing because a page table > entry is being freed after ptdump acquired the pointer is bad. On arm64, > ptdump() is protected against hotremove via [get|put]_online_mems(). > ''' > > Answer: The ptdump should be fine since vmemmap_remap_free() only exchanges > PTEs or split the PMD entry (which means allocating a PTE page table). Both > operations do not free any page tables (PTE), so ptdump cannot run into a > UAF on any page tables. The wrost case is just dumping an wrong value. > > [1] https://lore.kernel.org/all/20210510030027.56044-1-songmuchun@bytedance.com/ > [2] https://lore.kernel.org/all/20210518091826.36937-1-songmuchun@bytedance.com/ > > Signed-off-by: Muchun Song Hi Mark, I have updated the commit suggested from you in the previous version, do you (or other maintainers) have any comments on this? Thanks.