From patchwork Sat Jan 14 13:30:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Rapoport X-Patchwork-Id: 13101965 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 4FAFAC3DA78 for ; Sat, 14 Jan 2023 13:30:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8F918E0002; Sat, 14 Jan 2023 08:30:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A3F7C8E0001; Sat, 14 Jan 2023 08:30:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 907AF8E0002; Sat, 14 Jan 2023 08:30:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 81ACC8E0001 for ; Sat, 14 Jan 2023 08:30:27 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4DE24C063F for ; Sat, 14 Jan 2023 13:30:27 +0000 (UTC) X-FDA: 80353488894.17.6D1F171 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf15.hostedemail.com (Postfix) with ESMTP id 96F1FA0007 for ; Sat, 14 Jan 2023 13:30:25 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mrKXKdj+; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673703025; a=rsa-sha256; cv=none; b=gHbFxupdPQYEm1zGNy8chh5Tgs04QGsg1ySpeSC63WBVD7mrpdOy8Zu0HXPlZIx+smsuBC nFVe8VdQ4e+gHy/FPb8EKNvcVnqnn/zjnLJnGBqe+IB9HZ4StWn0WLbJcm3yg/8kUXkd6A A08czEn6DBRUVIGrum8A4es8FYcgKDc= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=mrKXKdj+; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673703025; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=4AIwVyWl+wCRPMRO7sAJHr4lzR+ieDHcsxhu8Tt+Aa0=; b=rp54t8bCDMBKRorgtZ+UIF8birDNKIHrB4PYxy5XvrQy/8nkPZcKO48xzHW5KIy0Dv/8xv s3+/fUuYHwQqRGKqc/sMyqswpG8jXzG+ddcOMWTm+Oo6N2zmIxCt6XvvjfSPMoyb+lU8BE HSQftkGJdCp76nqouJm0j9GGkkezVeM= 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 002E3B808CD; Sat, 14 Jan 2023 13:30:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02559C433EF; Sat, 14 Jan 2023 13:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1673703022; bh=cF7w2WUjmCAVcs3N4RrigyXBTZrsAH/r+Y+h/2zIfU4=; h=Date:From:To:Cc:Subject:From; b=mrKXKdj+3eVMbtpQIdnTLPEtzap8aSycMgtqXjM0xlGQqRzfOsh65Iz7b3JZLKvgM BfjtbumvOcatP1JoyrMkwNXItaL87LCJaIGlkdAWqTl6rYvdW9ysn7l25K/Mdhs1fg AuFZ5D7sogO+3BMM3A3/KZZsy5CBzyuMdVwY9bbAOOlfgh5LWYYfp7Wv1A0Njdp0xw gVDRq0Di2DIwV8vYYSOxZSaPe7kwerjVhlWlsNBsfvw0Ht8+PaykuetAVcxLXbYZIL Ue5AGIhB65FmDFLuxGw89jls2Dz4rO1It/zDQ6MyzzZQnDG9fOM0JR9me+SQUJ5uJx xV+kmElfJf5Dw== Date: Sat, 14 Jan 2023 15:30:11 +0200 From: Mike Rapoport To: Linus Torvalds Cc: Aaron Thompson , Mike Rapoport , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [GIT PULL] memblock: fix release of deferred pages in memblock_free_late() Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Rspam-User: X-Rspamd-Queue-Id: 96F1FA0007 X-Rspamd-Server: rspam01 X-Stat-Signature: 8eo8fx6gocmnrwsunpurcgkbyurtujqj X-HE-Tag: 1673703025-202054 X-HE-Meta: U2FsdGVkX1/twF1fuO6WjEEu8WVOBUu/PYqtzwsXHFHjGkm3KXehFLwyby7/aShSGGbfH2ZS2F7BVGmBz1t+mAUH0Pxia5f+NtUBAV2MdRcZ3xQAdPejJPbkcA1WzuKLWhhjDFBav1pkfWKZCdZnXqIB/j0q4rY4ihfmigm0Si/M3Ik5mjRE+OmwS7r0QdstIPZLnCUVV3rVg/BXKUwbeC9H4YNBi9f24sy+CQNVqDZDID79uDjaKMEsfudSfiG9pp/d6eqi29TV4LV8Eyjzi4LEiPSHjIVLgTpVKvQFcbFxabcKdiyAmxcYvClA0DDoyArba/76UQgZnLcG+akj+OivO28bKKLUcQhD4bRFMFWtM4k37YCbdRadvXNDtryPNvRhKlZAo4OtcSBHJ3bRAfRlpK60rnb6uGMpfPMaPzgsNh7wQwQaaCmXMu/9QncRbVQoq+H2GpFv/DVB6vvxn5ZASpE+K6gZE2Hr3pck44dnfBcBT7qi06NBzhCGXXFk8+41EkM02vdO/0ADfw+l9zoxFuXC+FEaO7Rzz+ayQD1piiVLAK8Dh/GpFoIO16JZ5aa+1HFNpY0rf4zW4DB/4RfKUnVlG5ru2bNmZexx/55wlUKquFGff1+4uupJXLfk+yi9nclrFgxQNT0eEIaATyFZWWzndhD1JV1wpNkeplmZViS+4vjM39RxX5y6X4DEy/RoEvhu7syT/YRpX62JoEsnmixmkOvCyFAN0MdLqXeg5ZJjrruN2EiJQ4DztREjC6X5yYxwmoZKuClOpYVaWmNbJiPYVPGVf9xatHVyU4040IMwnFXcu05nAicCS3yvonFcXjQLLuwd9fh7EsbHXng+cl0StauX2oUZzshgYRlh90J7ooVRXpsp/hMZbqUg86yFFIzyN+wJU2Vt8iBVaWXLysrBmliE66K0bJybxh1Fla/noKLZWknUm1cjNQrqhF1WqoktdnjXIJe55Ad FFyEUYSY aCI64SNWMvtF17XJ7BcF9rmlU9Xv3N85zlQjvnxEogSHy5DgSUm71i+3LWuBSvOo1r5F4r4xryXzIR+U= 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: Hi Linus, The following changes since commit fa81ab49bbe4e1ce756581c970486de0ddb14309: memblock: Fix doc for memblock_phys_free (2023-01-04 12:31:22 +0200) are available in the Git repository at: https://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock tags/fixes-2023-01-14 for you to fetch changes up to 115d9d77bb0f9152c60b6e8646369fa7f6167593: mm: Always release pages to the buddy allocator in memblock_free_late(). (2023-01-08 18:49:33 +0200) ---------------------------------------------------------------- memblock: always release pages to the buddy allocator in memblock_free_late() If CONFIG_DEFERRED_STRUCT_PAGE_INIT is enabled, memblock_free_pages() only releases pages to the buddy allocator if they are not in the deferred range. This is correct for free pages (as defined by for_each_free_mem_pfn_range_in_zone()) because free pages in the deferred range will be initialized and released as part of the deferred init process. memblock_free_pages() is called by memblock_free_late(), which is used to free reserved ranges after memblock_free_all() has run. All pages in reserved ranges have been initialized at that point, and accordingly, those pages are not touched by the deferred init process. This means that currently, if the pages that memblock_free_late() intends to release are in the deferred range, they will never be released to the buddy allocator. They will forever be reserved. In addition, memblock_free_pages() calls kmsan_memblock_free_pages(), which is also correct for free pages but is not correct for reserved pages. KMSAN metadata for reserved pages is initialized by kmsan_init_shadow(), which runs shortly before memblock_free_all(). For both of these reasons, memblock_free_pages() should only be called for free pages, and memblock_free_late() should call __free_pages_core() directly instead. One case where this issue can occur in the wild is EFI boot on x86_64. The x86 EFI code reserves all EFI boot services memory ranges via memblock_reserve() and frees them later via memblock_free_late() (efi_reserve_boot_services() and efi_free_boot_services(), respectively). If any of those ranges happens to fall within the deferred init range, the pages will not be released and that memory will be unavailable. For example, on an Amazon EC2 t3.micro VM (1 GB) booting via EFI: v6.2-rc2: Node 0, zone DMA spanned 4095 present 3999 managed 3840 Node 0, zone DMA32 spanned 246652 present 245868 managed 178867 v6.2-rc2 + patch: Node 0, zone DMA spanned 4095 present 3999 managed 3840 Node 0, zone DMA32 spanned 246652 present 245868 managed 222816 # +43,949 pages ---------------------------------------------------------------- Aaron Thompson (1): mm: Always release pages to the buddy allocator in memblock_free_late(). mm/memblock.c | 8 +++++++- tools/testing/memblock/internal.h | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-)