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: <20250517162048.36347-1-sj@kernel.org>
Date: Sat, 17 May 2025 09:20:48 -0700
From: SeongJae Park <sj@...nel.org>
To: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Cc: SeongJae Park <sj@...nel.org>,
	David Hildenbrand <david@...hat.com>,
	Usama Arif <usamaarif642@...il.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	linux-mm@...ck.org,
	hannes@...xchg.org,
	shakeel.butt@...ux.dev,
	riel@...riel.com,
	ziy@...dia.com,
	laoar.shao@...il.com,
	baolin.wang@...ux.alibaba.com,
	Liam.Howlett@...cle.com,
	npache@...hat.com,
	ryan.roberts@....com,
	linux-kernel@...r.kernel.org,
	linux-doc@...r.kernel.org,
	kernel-team@...a.com
Subject: Is number of process_madvise()-able ranges limited to 8? (was Re: [PATCH 1/6] prctl: introduce PR_THP_POLICY_DEFAULT_HUGE for the process)

Hi Lorenzo,

On Fri, 16 May 2025 13:57:18 +0100 Lorenzo Stoakes <lorenzo.stoakes@...cle.com> wrote:
[...]
> Right now madvise() has limited utility because:
[...]
> - While you can perform multiple operations at once via process_madvise(),
>   even to the current process (after my changes to extend it), it's limited
>   to a single advice over 8 ranges.

I'm bit confused by the last part, since I'm understanding your point as 'vlen'
parameter of process_madvise() is limited to 8, but my test code below succeeds
with 'vlen' parameter value 512.  Could you please enlighten me?

Attaching my test code below.  You could simply run it as below.

    gcc test.c && ./a.out

==== Attachment 0 (test.c) ====
#define _GNU_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/uio.h>
#include <unistd.h>

#define SZ_PAGE (4096)
#define NR_PAGES (512)
#define MMAP_SZ	(SZ_PAGE * NR_PAGES)

int main(void)
{
	char *buf;
	unsigned int i;
	int ret;
	pid_t pid = getpid();
	int pidfd = syscall(SYS_pidfd_open, pid, 0);
	struct iovec *vec;

	buf = mmap(NULL, MMAP_SZ, PROT_READ | PROT_WRITE, MAP_PRIVATE |
			MAP_ANON, -1, 0);
	if (buf == MAP_FAILED) {
		printf("mmap fail\n");
		return -1;
	}

	for (i = 0; i < MMAP_SZ; i++)
		buf[i] = 123;

	vec = malloc(sizeof(*vec) * NR_PAGES);
	for (i = 0; i < NR_PAGES; i++) {
		vec[i].iov_base = &buf[i * SZ_PAGE];
		vec[i].iov_len = SZ_PAGE;
	}

	ret = syscall(SYS_process_madvise, pidfd, vec, NR_PAGES,
			MADV_DONTNEED, 0);
	if (ret != MMAP_SZ) {
		printf("process_madvise fail\n");
		return -1;
	}

	ret = munmap(buf, MMAP_SZ);
	if (ret) {
		printf("munmap failed\n");
		return -1;
	}

	close(pidfd);
	printf("good\n");
	return 0;
}

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ