Linux Test Project
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Ricardo Branco <rbranco@suse.de>
Cc: "Claude Opus 5.5" <noreply@anthropic.com>, ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v4] userfaultfd: Add tests for UFFDIO_RWPROTECT and UFFDIO_SET_MODE
Date: Wed, 25 Nov 2026 13:22:06 +0100	[thread overview]
Message-ID: <awbS7qkrPNhm7Kfq@yuki.lan> (raw)
In-Reply-To: <20261124180149.614825-1-rbranco@suse.de>

Hi!
> +static void run(unsigned int n)
> +{
> +	pthread_t thr;
> +	struct uffdio_api uffdio_api = { .api = UFFD_API };
> +	struct uffdio_register uffdio_register;
> +	struct uffdio_set_mode uffdio_set_mode = {
> +		.disable = UFFD_FEATURE_RWP_ASYNC,
> +	};
> +	struct pollfd pollfd;
> +	unsigned char val;
> +
> +	uffdio_api.features = UFFD_FEATURE_RWP;
> +	if (n) {
> +		CHECK_UFFD_FEATURE(UFFD_FEATURE_RWP_ASYNC);
> +		uffdio_api.features |= UFFD_FEATURE_RWP_ASYNC;
> +	}
> +
> +	set_page();
> +	rwp_fault_seen = 0;
> +
> +	uffd = SAFE_USERFAULTFD(O_CLOEXEC | O_NONBLOCK, false);
> +
> +	SAFE_IOCTL(uffd, UFFDIO_API, &uffdio_api);
> +
> +	uffdio_register.range.start = (unsigned long)page;
> +	uffdio_register.range.len = page_size;
> +	uffdio_register.mode = UFFDIO_REGISTER_MODE_RWP;
> +
> +	SAFE_IOCTL(uffd, UFFDIO_REGISTER, &uffdio_register);
> +
> +	if (n) {
> +		/* Async mode is active, access must auto-resolve. */
> +		rwprotect((unsigned long)page, UFFDIO_RWPROTECT_MODE_RWP);
> +
> +		val = page[0];
> +
> +		if (val != PAGE_BYTE) {
> +			tst_res(TFAIL, "Async access corrupted content: got 0x%02x, expected 0x%02x",
> +				val, PAGE_BYTE);
> +			goto out;
> +		}
> +
> +		pollfd.fd = uffd;
> +		pollfd.events = POLLIN;
> +		if (SAFE_POLL(&pollfd, 1, 0) != 0) {
> +			tst_res(TFAIL, "Unexpected pagefault message in async mode");
> +			goto out;
> +		}
> +
> +		/* Switch to sync mode via UFFDIO_SET_MODE. */
> +		SAFE_IOCTL(uffd, UFFDIO_SET_MODE, &uffdio_set_mode);
> +	}
> +
> +	rwprotect((unsigned long)page, UFFDIO_RWPROTECT_MODE_RWP);
> +
> +	SAFE_PTHREAD_CREATE(&thr, NULL, handle_thread, NULL);
> +
> +	/* Try to read the RWP-protected page. */
> +	val = page[0];
> +
> +	SAFE_PTHREAD_JOIN(thr, NULL);
> +
> +	if (!rwp_fault_seen) {
> +		tst_res(TFAIL, "No RWPROTECT pagefault observed");
> +		goto out;
> +	}
> +
> +	if (val != PAGE_BYTE) {
> +		tst_res(TFAIL, "Page content corrupted: got 0x%02x, expected 0x%02x",
> +			val, PAGE_BYTE);
> +		goto out;
> +	}

Shouldn't this part be in else branch? Otherwise we run both tests for n
= 1.

I suppose that we would have to run the handle_thread in the first if
branch as well, but not as a thread, since it's asynchronous we can run
it as a normal function.

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2026-11-25 12:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 18:01 [LTP] [PATCH v4] userfaultfd: Add tests for UFFDIO_RWPROTECT and UFFDIO_SET_MODE Ricardo Branco
2026-11-25  1:10 ` [LTP] " linuxtestproject.agent
2026-11-25 12:22 ` Cyril Hrubis [this message]
2026-11-25 21:10   ` [LTP] [PATCH v4] " Ricardo Branco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awbS7qkrPNhm7Kfq@yuki.lan \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=noreply@anthropic.com \
    --cc=rbranco@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox