DAMON development mailing list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Enze Li" <lienze@kylinos.cn>
Cc: ojeda@kernel.org, damon@lists.linux.dev, gary@garyguo.net
Subject: Re: [RFC PATCH 3/4] samples/damon: add Rust sample for DAMON access-aware proactive reclamation
Date: Sun, 27 Sep 2026 07:37:10 +0000	[thread overview]
Message-ID: <20260927073710.928031F00893@smtp.kernel.org> (raw)
In-Reply-To: <20260927072812.2393456-4-lienze@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] damon/rust_prcl: concurrent writes to 'enabled' debugfs file leak threads
- [Low] damon/rust_prcl: custom boolean parsing rejects standard kernel bool strings
--

commit 195de0b55eeb64d2bfdbc4cb35a867a97366c03f
Author: Enze Li <lienze@kylinos.cn>

samples/damon: add Rust sample for DAMON access-aware proactive reclamation

This commit adds a Rust implementation of the DAMON-based proactive
reclamation sample module. It allows monitoring a target process's virtual
address space and proactively reclaiming cold memory via debugfs endpoints.

> diff --git a/samples/damon/rust_prcl.rs b/samples/damon/rust_prcl.rs
> new file mode 100644
> index 0000000000000..1e6c820311e23
> --- /dev/null
> +++ b/samples/damon/rust_prcl.rs
[ ... ]
> +fn damon_sample_rust_prcl_start(target_pid: i32) -> Result {
> +    let ctx = damon::DamonCtx::damon_new_ctx()?;
[ ... ]
> +    let ret = ctx.damon_start();
> +    match ret {
> +        Ok(_) => {
> +            CTX.store(ctx.into_raw(), Relaxed);
> +        }

[Severity: High]
Can this leak the original damon_ctx and its running thread if
damon_sample_rust_prcl_start() is called concurrently?

Concurrent callers to start() will overwrite the global CTX pointer here,
causing the first context to be permanently leaked along with its thread.

> +        Err(e) => {
> +            pr_err!("damon_start failed, error: {:?}\n", e);
> +            return Err(e);
> +        }
> +    }
> +    Ok(())
> +}
> +
> +fn damon_sample_rust_prcl_stop() {
> +    pr_info!("stop\n");
> +    let raw = CTX.xchg(null_mut(), Relaxed);

[Severity: High]
If stop() is called in a race with start(), could it read null_mut() here
before start() has recorded the context?

A rapid start/stop sequence could result in stop() incorrectly finding a
null pointer and failing to terminate the newly-starting thread.

[ ... ]
> +fn damon_sample_rust_parse_bool(s: &str) -> Result<bool> {
> +    let s = s.trim();
> +    if s.eq_ignore_ascii_case("y") {
> +        Ok(true)
> +    } else if s.eq_ignore_ascii_case("n") {
> +        Ok(false)
> +    } else {
> +        Err(EINVAL)
> +    }
> +}

[Severity: Low]
Does this custom parsing reject standard boolean representations that the
kernel conventionally accepts?

This function only accepts 'y', 'Y', 'n', and 'N'. Standard kernel boolean
parsing typically supports inputs like '1', '0', 'on', and 'off' via
mechanisms similar to kstrtobool(). This might provide a confusing example
for future Rust modules.

[ ... ]
> +fn enabled_write(data: &ModuleData, reader: &mut UserSliceReader) -> Result {
[ ... ]
> +    let enabled = damon_sample_rust_parse_bool(s)?;
> +
> +    let is_enabled = data.enabled.load(Relaxed);
> +    if enabled == is_enabled {
> +        return Ok(());
> +    }
> +
> +    if !damon::damon_initialized() {
> +        return Ok(());
> +    }
> +
> +    data.enabled.store(enabled, Relaxed);

[Severity: High]
Does this lockless read-and-update of the boolean flag allow multiple
concurrent writers to trigger complex state changes simultaneously?

Because the read-and-check of data.enabled lacks locking, a TOCTOU race
exists. Two processes writing 'y' concurrently will both bypass the
check and call damon_sample_rust_prcl_start(), which triggers the thread
and context leaks mentioned earlier.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260927072812.2393456-1-lienze@kylinos.cn?part=3

  reply	other threads:[~2026-09-27  7:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-27  7:28 [RFC PATCH 0/4] rust: damon: a first small step, plus a Rust prcl sample Enze Li
2026-09-27  7:28 ` [RFC PATCH 1/4] rust: add bindings for linux/damon.h Enze Li
2026-09-27  7:29   ` sashiko-bot
2026-09-27  7:28 ` [RFC PATCH 2/4] rust: damon: add basic DAMON abstractions Enze Li
2026-09-27  7:40   ` sashiko-bot
2026-09-27  7:28 ` [RFC PATCH 3/4] samples/damon: add Rust sample for DAMON access-aware proactive reclamation Enze Li
2026-09-27  7:37   ` sashiko-bot [this message]
2026-09-27  7:28 ` [RFC PATCH 4/4] MAINTAINERS: add entry for the DAMON Rust abstractions Enze Li
2026-09-27 10:07 ` [RFC PATCH 0/4] rust: damon: a first small step, plus a Rust prcl sample SJ Park
2026-09-28 12:59   ` Enze Li
2026-09-28 16:56     ` SJ Park

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=20260927073710.928031F00893@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=gary@garyguo.net \
    --cc=lienze@kylinos.cn \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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