lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aQo1VjjQw1OZG8nY@kernel.org>
Date: Tue, 4 Nov 2025 19:18:14 +0200
From: Mike Rapoport <rppt@...nel.org>
To: Akinobu Mita <akinobu.mita@...il.com>,
	Dan Williams <dan.j.williams@...el.com>
Cc: linux-cxl@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-mm@...ck.org, akpm@...ux-foundation.org
Subject: Re: [PATCH] memblock: fix memblock_estimated_nr_free_pages() for
 soft-reserved memory

(added Dan Williams)

Hi,

On Tue, Nov 04, 2025 at 09:39:21AM +0900, Akinobu Mita wrote:
> memblock_estimated_nr_free_pages() returns the difference between the total
> size of the "memory" memblock type and the "reserved" memblock type.
> 
> The "soft-reserved" memory regions are added to the "reserved" memblock
> type, but not to the "memory" memblock type. Therefore,

@Dan, do we really need to memblock_reserve() the E820_TYPE_SOFT_RESERVED
ranges?
Quick scan didn't show anything that requires this, but I could easily miss
something.

> memblock_estimated_nr_free_pages() may return a smaller value than
> expected, or if it underflows, an extremely large value.
> 
> /proc/sys/kernel/threads-max is determined by the value of
> memblock_estimated_nr_free_pages().  This issue was discovered on machines
> with CXL memory because kernel.threads-max was either smaller than expected
> or extremely large for the installed DRAM size.
> 
> This fixes the issue by improving the accuracy of
> memblock_estimated_nr_free_pages() by subtracting only the overlapping size
> of regions with "memory" and "reserved" memblock types.
> 
> Signed-off-by: Akinobu Mita <akinobu.mita@...il.com>
> ---
>  mm/memblock.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/memblock.c b/mm/memblock.c
> index e23e16618e9b..af014fa10a44 100644
> --- a/mm/memblock.c
> +++ b/mm/memblock.c

...

> @@ -1826,7 +1842,22 @@ phys_addr_t __init_memblock memblock_reserved_kern_size(phys_addr_t limit, int n
>   */
>  unsigned long __init memblock_estimated_nr_free_pages(void)
>  {
> -	return PHYS_PFN(memblock_phys_mem_size() - memblock_reserved_size());

We have memblock_reserved_kern_size() that tells how much memory was
reserved from the actual RAM. Replacing memblock_reserved_size() with
memblock_reserved_kern_size() will omit "soft-reserved" ranges.

> +	int memory_idx, reserved_idx;
> +	struct memblock_type *memory_type = &memblock.memory;
> +	struct memblock_type *reserved_type = &memblock.reserved;
> +	struct memblock_region *memory_region, *reserved_region;
> +	phys_addr_t phys_mem_size = 0;
> +
> +	for_each_memblock_type(memory_idx, memory_type, memory_region) {
> +		phys_mem_size += memory_region->size;
> +		for_each_memblock_type(reserved_idx, reserved_type, reserved_region) {
> +			phys_mem_size -= memblock_addrs_overlap_size(memory_region->base,
> +					memory_region->size, reserved_region->base,
> +					reserved_region->size);
> +		}
> +	}
> +
> +	return PHYS_PFN(phys_mem_size);
>  }
>  
>  /* lowest address */
> -- 
> 2.43.0
> 

-- 
Sincerely yours,
Mike.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ