On Mon, Aug 24, 2026 at 8:28 PM Michal Koutný <[email protected]> wrote:
>
> On Mon, Jul 06, 2026 at 02:06:40PM +0200, Albert Esteve <[email protected]> 
> wrote:
> > Currently, dmem charging is driver-driven through direct
> > calls to dmem_cgroup_try_charge(), so cgroup selftests
> > do not have a generic way to trigger charge and uncharge
> > paths from userspace.
> >
> > This limits any selftest coverage to configuration/readout
> > checks unless a specific driver exposing charge hooks is
> > present in the test environment.
>
> What about that
> drivers/gpu/drm/ttm/tests/ttm_resource_test.c
> ?

But that test does not set up a dmem region (man->cg == NULL), so
ttm_resource_try_charge is a no-op. Even if we add a region there, it
would not exercise nested dmem.{max,min,low} from userspace as
intended here. But I can reword the message to avoid sounding like
there is no in-kernel coverage whatsoever.

>
> >
> > Add kernel/cgroup/dmem_selftest.c as a helper module
> > (CONFIG_DMEM_SELFTEST) that registers a synthetic dmem region
> > (dmem_selftest) and exposes debugfs control files:
> > /sys/kernel/debug/dmem_selftest/charge
> > /sys/kernel/debug/dmem_selftest/uncharge
>
> Nit: I'd think about alloc and free (to denote meaning not how it's
> implemented).

Works for me. I'll change the naming for the next version.

>
> >
> > Writing a size to charge triggers dmem_cgroup_try_charge() for
> > the calling task's cgroup (the module calls kstrtou64()).
> > Writing to uncharge releases the outstanding charge via
> > dmem_cgroup_uncharge(). Only a single outstanding charge
> > is supported.
> >
> > This provides a deterministic, driver-independent mechanism
> > for exercising dmem accounting paths in selftests.
> >
> > Signed-off-by: Albert Esteve <[email protected]>
> > ---
> >  init/Kconfig                  |  12 +++
> >  kernel/cgroup/Makefile        |   1 +
> >  kernel/cgroup/dmem_selftest.c | 198 
> > ++++++++++++++++++++++++++++++++++++++++++
> >  3 files changed, 211 insertions(+)
> >
> > diff --git a/init/Kconfig b/init/Kconfig
> > index 5230d4879b1c8..6fab65d6b44ea 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -1267,6 +1267,18 @@ config CGROUP_DMEM
> >         As an example, it allows you to restrict VRAM usage for applications
> >         in the DRM subsystem.
> >
> > +config DMEM_SELFTEST
> > +     tristate "dmem cgroup selftest helper module"
> > +     depends on CGROUP_DMEM && DEBUG_FS
> > +     default n
> > +     help
> > +       Builds a small loadable module that registers a dmem region named
> > +       "dmem_selftest" and exposes debugfs files under
> > +       /sys/kernel/debug/dmem_selftest/ so kselftests can trigger
> > +       dmem charge/uncharge operations from userspace.
> > +
> > +       Say N unless you run dmem selftests or develop the dmem controller.
>
> Could this be made w/out introduciton of a new Kconfig option? (E.g.
> what tools/testing/selftests/livepatch/test_modules/Makefile does)
>
> (Maybe reword to insmod if you choose building the test module as OOT.)

Ah, nice example. I'll drop the CONFIG_DMEM_SELFTEST and have the
helper module as OOT.

>
> > +static int __init dmem_selftest_register(void)
>
> Just an idea to reduce the amount debugfs of boilerplage -- the testing
> args could be handled by module_param_cb().

Ok, I'll switch to module parameters and drop the debugfs boilerplate
and DEBUG_FS dependency.

BR,
Albert

>
> > +static int __init dmem_selftest_init(void)
> ...
> > +     add_taint(TAINT_TEST, LOCKDEP_STILL_OK);
>
> Great!
>


Reply via email to