public inbox for linux-mm@kvack.org
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>
Cc: damon@lists.linux.dev, linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: (sashiko review) [RFC PATCH v3 03/10] mm/damon/sysfs-schemes: implement fail_charge_{num,denom} files
Date: Tue,  7 Apr 2026 08:55:04 -0700	[thread overview]
Message-ID: <20260407155504.51888-1-sj@kernel.org> (raw)
In-Reply-To: <20260407010536.83603-4-sj@kernel.org>

TL; DR: sashiko argues two issues that I think ok to ignore, so I will do so.

Forwarding full sashiko review in a reply format with my 
inline comments below, for sharing details of my view and
doing followup discussions via mails if needed.

> # review url: https://sashiko.dev/#/patchset/20260407010536.83603-4-sj@kernel.org
> # start of sashiko.dev inline review
> commit 233e1cffd501d91418c4d1f0badd7f5b509664c0
> Author: SeongJae Park <sj@kernel.org>
> 
> mm/damon/sysfs-schemes: implement fail_charge_{num,denom} files
> 
> Implement the user-space ABI for the DAMOS action failed region
> quota-charge ratio setup.  For this, add two new sysfs files under the
> DAMON sysfs interface for DAMOS quotas.
> 
> > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> > index 5186966dafb35..d5bfba79f105f 100644
> > --- a/mm/damon/sysfs-schemes.c
> > +++ b/mm/damon/sysfs-schemes.c
> [ ... ]
> > @@ -1663,6 +1665,48 @@ static ssize_t goal_tuner_store(struct kobject *kobj,
> >  	return -EINVAL;
> >  }
> >  
> > +static ssize_t fail_charge_num_show(struct kobject *kobj,
> > +		struct kobj_attribute *attr, char *buf)
> > +{
> > +	struct damon_sysfs_quotas *quotas = container_of(kobj,
> > +			struct damon_sysfs_quotas, kobj);
> > +
> > +	return sysfs_emit(buf, "%u\n", quotas->fail_charge_num);
> > +}
> > +
> > +static ssize_t fail_charge_num_store(struct kobject *kobj,
> > +		struct kobj_attribute *attr, const char *buf, size_t count)
> > +{
> > +	struct damon_sysfs_quotas *quotas = container_of(kobj,
> > +			struct damon_sysfs_quotas, kobj);
> > +	int err = kstrtouint(buf, 0, &quotas->fail_charge_num);
> 
> Is it possible for large values of fail_charge_num to cause integer
> overflows in the quota calculation?
> 
> Because kstrtouint allows values up to UINT_MAX without bounds checking,
> the multiplication in mult_frac(sz_region - sz_applied,
> quota->fail_charge_num, quota->fail_charge_denom) during
> damos_charge_quota() might silently overflow the unsigned long capacity.
> 
> Upon overflow, the calculated charge wraps around to a significantly
> smaller value.
> 
> Could this artificially suppress the accumulated quota->charged_sz,
> causing damos_quota_is_full() to incorrectly return false and completely
> bypass the user-configured quota limits?

As I mentioned on the second patch thread, I will just let this overflows if
the user really wants to set such large number, since it will make DAMON
behavior bit weird but not breaking something serious, unless other humans have
different opinions.

> 
> > +
> > +	if (err)
> > +		return -EINVAL;
> > +	return count;
> > +}
> > +
> > +static ssize_t fail_charge_denom_show(struct kobject *kobj,
> > +		struct kobj_attribute *attr, char *buf)
> > +{
> > +	struct damon_sysfs_quotas *quotas = container_of(kobj,
> > +			struct damon_sysfs_quotas, kobj);
> > +
> > +	return sysfs_emit(buf, "%u\n", quotas->fail_charge_denom);
> > +}
> > +
> > +static ssize_t fail_charge_denom_store(struct kobject *kobj,
> > +		struct kobj_attribute *attr, const char *buf, size_t count)
> > +{
> > +	struct damon_sysfs_quotas *quotas = container_of(kobj,
> > +			struct damon_sysfs_quotas, kobj);
> > +	int err = kstrtouint(buf, 0, &quotas->fail_charge_denom);
> 
> Can the lack of bounds checking on fail_charge_denom also contribute to
> unexpected behaviors or overflows in the same mult_frac() calculation?

Ditto.

> 
> > +
> > +	if (err)
> > +		return -EINVAL;
> > +	return count;
> > +}
> 
> 
> # end of sashiko.dev inline review
> # review url: https://sashiko.dev/#/patchset/20260407010536.83603-4-sj@kernel.org


Thanks,
SJ

# hkml [1] generated a draft of this mail.  You can regenerate
# this using below command:
#
#     hkml patch sashiko_dev --for_forwarding \
#             20260407010536.83603-4-sj@kernel.org
#
# [1] https://github.com/sjp38/hackermail


  reply	other threads:[~2026-04-07 15:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07  1:05 [RFC PATCH v3 00/10] mm/damon: introduce DAMOS failed region quota charge ratio SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 01/10] mm/damon/core: handle <min_region_sz remaining quota as empty SeongJae Park
2026-04-07 14:12   ` (sashiko review) " SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 02/10] mm/damon/core: introduce failed region quota charge ratio SeongJae Park
2026-04-07 15:51   ` (sashiko review) " SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 03/10] mm/damon/sysfs-schemes: implement fail_charge_{num,denom} files SeongJae Park
2026-04-07 15:55   ` SeongJae Park [this message]
2026-04-07  1:05 ` [RFC PATCH v3 04/10] Docs/mm/damon/design: document fail_charge_{num,denom} SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 05/10] Docs/admin-guide/mm/damon/usage: document fail_charge_{num,denom} files SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 06/10] Docs/ABI/damon: document fail_charge_{num,denom} SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 07/10] mm/damon/tests/core-kunit: test fail_charge_{num,denom} committing SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 08/10] selftests/damon/_damon_sysfs: support failed region quota charge ratio SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 09/10] selftests/damon/drgn_dump_damon_status: " SeongJae Park
2026-04-07  1:05 ` [RFC PATCH v3 10/10] selftests/damon/sysfs.py: test " SeongJae 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=20260407155504.51888-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /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