From patchwork Tue Jan 11 13:16:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muchun Song X-Patchwork-Id: 12709864 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EE390C433F5 for ; Tue, 11 Jan 2022 13:17:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D666C6B0072; Tue, 11 Jan 2022 08:17:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEF076B0073; Tue, 11 Jan 2022 08:17:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B8F926B0074; Tue, 11 Jan 2022 08:17:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0136.hostedemail.com [216.40.44.136]) by kanga.kvack.org (Postfix) with ESMTP id A83D16B0072 for ; Tue, 11 Jan 2022 08:17:19 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 57720181DF760 for ; Tue, 11 Jan 2022 13:17:19 +0000 (UTC) X-FDA: 79018057398.21.F5FA22B Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf31.hostedemail.com (Postfix) with ESMTP id 3E7AE20011 for ; Tue, 11 Jan 2022 13:17:18 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id l15so17060392pls.7 for ; Tue, 11 Jan 2022 05:17:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=51hfnZMrjVMwncBAfuPjR9jE1rmCVx4hXfZuwfJArk8=; b=LljzaIex9oaWpQpDIkneXLdfCcqNXilOgXqkk4D/kR7cYhdCa23RDZGJuoq6DBFGtO TTWUAFmaCLHz05QRmZdtZvkYMzdEtuxqpD4CDixUwHnGyp4T73EkQKomQVCKhnxLJTJ2 bbtj+7nyl6t95Uc231qFZLxXJfavpeElcBVgpxNE3+0jW78xxdxhGy8doKfjcdXqAw5T HvyP/EQyittIW0StHo18qvuDv2PFZMijQyc78uvJxxzfkvHq6wB/wg85RRM7Lnvo2Pdo u29iAq85glUaEykP2fObR7yddVtFz399OM4p3NsF3ZSC1rzPatOTKrqG8Nul2Xmr6e61 RUWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=51hfnZMrjVMwncBAfuPjR9jE1rmCVx4hXfZuwfJArk8=; b=0ookfRhFNOftD//2f7T0Jq+E7JVX//bPGH14CefP+NDseJmedJn+5l2Aymbv48bcdA 7FUT0/60U4NHa5ckz5JM4AwkE1n5TqGkWhn6NZp47ffEVtmeV97ZhU4obWYr0iRug8Pa b/MJ3fuwTQqFHn/4XIECJ9IA8A/daSShr+FICji7nlx8Jz9FngZpsmVtv2MaaxIu84V2 0pgg0YRMUBg1FHYhPcfACqfQaK7o8APN0zZa/Oae3qdGl9SVaX11dALcFZZvwdX5KJ2F uYipUdFmTQMclyYSnRQHHVwSHz/bA2qIvpDZMe89XfYYCGgoAf79EIEJaO7XLKS+73I9 o2SQ== X-Gm-Message-State: AOAM533MTNsD5RLzDK/bX5IRGsp6VgIRvGSK1xrkM+LOKEwDUrrQs+Ta QsPYwbWlH6RIjI1sThEAx9N1Gg== X-Google-Smtp-Source: ABdhPJzTrKFps+GeCoX3uZCxSVOWXOuaPD/0YuD2oXFzH+R10vAlnkfSlcZEwlQMzychksQJaXWtZw== X-Received: by 2002:a63:485a:: with SMTP id x26mr4019728pgk.580.1641907036736; Tue, 11 Jan 2022 05:17:16 -0800 (PST) Received: from C02FF4E5ML7H.tiktokd.org ([139.177.225.248]) by smtp.gmail.com with ESMTPSA id c124sm10080450pfb.139.2022.01.11.05.17.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Jan 2022 05:17:16 -0800 (PST) From: Muchun Song To: will@kernel.org, akpm@linux-foundation.org, david@redhat.com, bodeddub@amazon.com, osalvador@suse.de, mike.kravetz@oracle.com, rientjes@google.com, 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, Muchun Song Subject: [PATCH] arm64: mm: hugetlb: add support for free vmemmap pages of HugeTLB Date: Tue, 11 Jan 2022 21:16:52 +0800 Message-Id: <20220111131652.61947-1-songmuchun@bytedance.com> X-Mailer: git-send-email 2.32.0 (Apple Git-132) MIME-Version: 1.0 X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 3E7AE20011 X-Stat-Signature: 48o48ijzxn49geirifa958dhncnwkd5x Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=LljzaIex; spf=pass (imf31.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com; dmarc=pass (policy=none) header.from=bytedance.com X-HE-Tag: 1641907038-957629 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The preparation of supporting freeing vmemmap associated with each HugeTLB page is ready, so we can support this feature for arm64. Signed-off-by: Muchun Song --- There is already some discussions about this in [1], but there was no conclusion in the end. 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. " My Answer: As you already know 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. Why? The minimal granularity size of hotplug memory 128MB (on arm64, 4k base page), so 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 could not cross two sections. Any HugeTLB bigger than 128MB (e.g. 1GB) whose size is an integer multible of a section and vmemmap area is also an integer multiple of 2MB. At the time memory is removed, all huge pages either have been migrated away or dissolved. The vmemmap is stable. So there is no problem in this case as well. 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(). " My 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, 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/linux-mm/b8cdc9c8-853c-8392-a2fa-4f1a8f02057a@arm.com/T/ fs/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/Kconfig b/fs/Kconfig index 7a2b11c0b803..04cfd5bf5ec9 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -247,7 +247,7 @@ config HUGETLB_PAGE config HUGETLB_PAGE_FREE_VMEMMAP def_bool HUGETLB_PAGE - depends on X86_64 + depends on X86_64 || ARM64 depends on SPARSEMEM_VMEMMAP config HUGETLB_PAGE_FREE_VMEMMAP_DEFAULT_ON