On Fri, Nov 13, 2026 at 03:06:13PM +0800, Mengmeng Zhao wrote:
> From: Mengmeng Zhao <zhaomengmeng(a)kylinos.cn>
>
> This series adds dma-buf read/write support for ext4. The dma-buf direct
> I/O infrastructure allows dma-buf to be handed to file I/O as an iov_iter,
> but currently it only supports raw block devices. To better serve the
> GPU-NVMe direct access through normal filesystems, prior work for XFS has
> been discussed at [1]. We are also interested in this field and working on
> it [2].
Can you an Anuj please work together and merge this into a single
series covering both XFS and ext4?
On Mon, Nov 16, 2026 at 03:21:01PM +0100, Andreas Hindborg wrote:
For the fs and pid_namespace bits:
Acked-by: Christian Brauner <brauner(a)kernel.org>
On Fri, Nov 13, 2026 at 03:06:19PM +0800, Mengmeng Zhao wrote:
> From: Mengmeng Zhao <zhaomengmeng(a)kylinos.cn>
>
> Add a file mode bit for files that can be the target of dma-buf I/O and
> require it when a buffer is registered. Block device files set it when
> the backing disk supports dma-buf I/O, and filesystems can set it for
> inodes whose data can be reached without the page cache. The bit is
> coarse: a driver that installs ->init_dma_buf_io_ctx for every
> namespace, like nvme, still decides per device at registration.
>
> dma_buf_io_ctx_create() is the only caller of ->init_dma_buf_io_ctx, so
> the capability and the O_DIRECT requirement are checked there for every
> file type rather than in each helper; O_DIRECT belongs at registration
> because F_SETFL can change it afterwards. Add bdev_can_dmabuf_io() so
> the open-time and registration checks share one predicate.
>
> Signed-off-by: Mengmeng Zhao <zhaomengmeng(a)kylinos.cn>
> Signed-off-by: Li Wang <liwang(a)kylinos.cn>
> ---
> block/bdev.c | 8 ++++----
> block/fops.c | 2 +-
> drivers/dma-buf/dma-buf-io.c | 13 +++++++++----
> include/linux/blkdev.h | 7 ++++++-
> include/linux/fs.h | 8 +++++++-
> 5 files changed, 27 insertions(+), 11 deletions(-)
>
> diff --git a/block/bdev.c b/block/bdev.c
> index 88e3f552f5d4..4e7a7f7e1e8b 100644
> --- a/block/bdev.c
> +++ b/block/bdev.c
> @@ -61,14 +61,12 @@ struct block_device *file_bdev(struct file *bdev_file)
> }
> EXPORT_SYMBOL(file_bdev);
>
> -int bdev_init_dma_buf_io_ctx(struct file *file, struct block_device *bdev,
> +int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
> struct dma_buf_io_ctx *ctx)
> {
> - if (!(file->f_flags & O_DIRECT))
> - return -EINVAL;
> if (ctx->dmabuf->size > UINT_MAX)
> return -EINVAL;
> - if (!bdev->bd_disk->fops->init_dma_buf_io_ctx)
> + if (!bdev_can_dmabuf_io(bdev))
> return -EOPNOTSUPP;
> return bdev->bd_disk->fops->init_dma_buf_io_ctx(bdev, ctx);
> }
> @@ -1041,6 +1039,8 @@ int bdev_open(struct block_device *bdev, blk_mode_t mode, void *holder,
>
> bdev_file->f_flags |= O_LARGEFILE;
> bdev_file->f_mode |= FMODE_CAN_ODIRECT;
> + if (bdev_can_dmabuf_io(bdev))
> + bdev_file->f_mode |= FMODE_CAN_DMABUF_IO;
> if (bdev_nowait(bdev))
> bdev_file->f_mode |= FMODE_NOWAIT;
> if (mode & BLK_OPEN_RESTRICT_WRITES)
> diff --git a/block/fops.c b/block/fops.c
> index 86bf1f298b79..7e5702e047a2 100644
> --- a/block/fops.c
> +++ b/block/fops.c
> @@ -1008,7 +1008,7 @@ static int blkdev_mmap_prepare(struct vm_area_desc *desc)
> static int blkdev_init_dma_buf_io_ctx(struct file *file,
> struct dma_buf_io_ctx *ctx)
> {
> - return bdev_init_dma_buf_io_ctx(file, file_bdev(file), ctx);
> + return bdev_init_dma_buf_io_ctx(file_bdev(file), ctx);
> }
>
> const struct file_operations def_blk_fops = {
> diff --git a/drivers/dma-buf/dma-buf-io.c b/drivers/dma-buf/dma-buf-io.c
> index 8440151de860..9575b7d65ec5 100644
> --- a/drivers/dma-buf/dma-buf-io.c
> +++ b/drivers/dma-buf/dma-buf-io.c
> @@ -152,9 +152,11 @@ static void dma_buf_io_ctx_shutdown(struct dma_buf_io_ctx *ctx)
> * @out_ctx: [out] resulting ctx
> *
> * Create a new I/O context from the given DMA buffer for the given file.
> - * It only works with files implementing ->init_dma_buf_io_ctx and fails
> - * with -EOPNOTSUPP otherwise. Once created, the user can create a map
> - * and use it to issue I/O, such as read/write requests, to @file.
> + * It only works with files implementing ->init_dma_buf_io_ctx,
> + * advertising FMODE_CAN_DMABUF_IO and currently opened for direct I/O,
> + * and fails with -EOPNOTSUPP or -EINVAL otherwise. Once created, the
> + * user can create a map and use it to issue I/O, such as read/write
> + * requests, to @file.
> */
> int dma_buf_io_ctx_create(struct file *file,
> struct dma_buf *dmabuf,
> @@ -164,8 +166,11 @@ int dma_buf_io_ctx_create(struct file *file,
> struct dma_buf_io_ctx *ctx;
> int ret;
>
> - if (!file->f_op->init_dma_buf_io_ctx)
> + if (!file->f_op->init_dma_buf_io_ctx ||
> + !(file->f_mode & FMODE_CAN_DMABUF_IO))
> return -EOPNOTSUPP;
> + if (!(file->f_flags & O_DIRECT))
> + return -EINVAL;
>
> ctx = kzalloc_obj(*ctx);
> if (!ctx)
> diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
> index b98f43478cc0..0cfb6fb6b4e2 100644
> --- a/include/linux/blkdev.h
> +++ b/include/linux/blkdev.h
> @@ -1610,9 +1610,14 @@ struct block_device_operations {
> int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector);
> };
>
> -int bdev_init_dma_buf_io_ctx(struct file *file, struct block_device *bdev,
> +int bdev_init_dma_buf_io_ctx(struct block_device *bdev,
> struct dma_buf_io_ctx *ctx);
>
> +static inline bool bdev_can_dmabuf_io(struct block_device *bdev)
> +{
> + return !!bdev->bd_disk->fops->init_dma_buf_io_ctx;
> +}
> +
> #ifdef CONFIG_COMPAT
> extern int blkdev_compat_ptr_ioctl(struct block_device *, blk_mode_t,
> unsigned int, unsigned long);
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 99caef43ff3c..f5524fc770d4 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -121,7 +121,13 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
> /* File supports atomic writes */
> #define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)(1 << 7))
>
> -/* FMODE_* bit 8 */
> +/*
> + * File can be the target of dma-buf I/O. Set it for files whose data can be
> + * reached with direct I/O without the page cache: a dma-buf iterator has no
> + * pages to copy, so a buffered path cannot serve it. The bit is coarse; both
> + * the device behind it and O_DIRECT are checked when a buffer is registered.
> + */
> +#define FMODE_CAN_DMABUF_IO ((__force fmode_t)(1 << 8))
This is stealing yet another FMODE_* bit for special-purpose stuff.
We're really really short of them. Did Christoph suggest this?
On Wed, Nov 18, 2026 at 04:17:45PM +0100, Olivier Moysan wrote:
> This series adds support for the STM32 Multi-function Digital Filter
> (MDF) found on STM32MP2 SoCs. MDF converts bitstreams from external
> sigma-delta modulators and PDM microphones into samples for IIO and
> ASoC consumers.
>
> The drivers support direct IIO conversions, cyclic DMA acquisition,
> CIC configuration and scaling, synchronized and interleaved filters,
> and external timer triggers. An ASoC DAI provides PDM microphone capture.
>
> This revision addresses the v1 review comments listed below and splits
> the driver patch into smaller functional patches for readability.
> It retains the existing IIO backend interface for external sigma-delta
> modulators, pending agreement on the preferred abstraction.
>
> These changes do not resolve all v1 review comments. In particular, the
> frontend/backend architecture, DT child-node model and complete clock
> topology remain open discussion points.
>
> * Open questions: MDF topology (backend/frontend)
>
> In Analog Devices use of the IIO backend framework, the AXI ADC is a
> hardware backend, while the AD9467 is a hardware frontend. The external
> sigma-delta modulator is actually a hardware frontend in the MDF signal
> chain. The difference from the AD9467 use case is which driver owns the
> aggregate IIO device.
My red line here, that I probably made pretty clear on v1, is that what
is done needs to make sense when the ADC is feeding the MDF, it cannot
only work for the data coming in from sd modulators or w/e you connect
to the SITFx inputs.
> Option 1:
> One option would be to generalize the existing backend abstraction to
> represent components contributing to an aggregate IIO device,
> independently of their position in the signal chain.
>
> The existing framework appears to provide the required mechanisms. None
> of these mechanisms inherently requires the provider to be a hardware backend.
> A generic component/provider model would support both topologies without
> duplicating interfaces or requiring reciprocal dependencies. The key
> point here is to preserve the compatibility of APIs and DT bindings.
>
> Option 2:
> Alternatively, if the backend abstraction should retain its hardware
> meaning, we could introduce an explicit frontend-provider abstraction
> sharing the existing infrastructure. Frontend operations would cover
> analog-side control and conversion parameters.
>
> Would generalizing the existing abstraction be acceptable, or would a
> separate frontend interface built on shared infrastructure be preferred?
For either of these options, do you envisage the data being retrieved
from the mdf sysfs files rather than from the modulator?
>
> Option 3:
> An aggregate IIO device based on the component framework, as discussed
> in previous threads, could also be considered. I currently regard this
> as a fallback solution:
> https://lore.kernel.org/all/ec411432-4b77-4410-b0aa-b29f73b82c84@foss.st.co…
You option 2 in the earlier thread had:
| 2 - DFSDM managed as a "hardware accelerator"
|
|
| +-------------+
| | Sysfs |
| | - Scale | +---------------+
| | - Raw data | | IIO char dev |
| +-------------+ +---------------+
| ^ /\
| | ||
| | || Userland
| -----------------------------------------------------------
| | || IIO fw
| | ||
| | ||
| -----------------------------------------------------------
| | ||
| +--|-------------||--+ +----------------+
| | | || | | | Drivers
| | | ======================= |
| | | | | || |
| | +-----------------+-----+--+ || |
| | +---------+-----+--+ || |
| +----------|---------+ +-----------||---+
| | ||
| -----------------------------------------------------------
| | ||
| +----------|---------+ +-----------||---+
| | | | || | Hardware
| | sd modulator | | DFSDM || |
| ============================================= |
| | | | |
| +----------+---------+ +----------------+
| |
| |
| Vref
|
| The DFSDM is a consumer of the SD modulator.
|
| In addition to its complexity, the main drawback of this approach is
| that it is unsuitable for interleaved mode.
Two mails prior I had theorised a way to deal with the interleaved mode
https://lore.kernel.org/all/20261015-attentive-conflict-1a1f538de77d@spud/
but I never saw a response from you as to why something like that cannot
work. That's twice in that thread you said it was unsuitable without
providing the actual explanation for why?
Cheers,
Conor.
>
> * Driver implementation
>
> Serial interfaces (SITF) are shared resources managed directly by the
> MDF core and no longer have separate platform devices. This revision
> retains their DT nodes to describe configuration and clock connections,
> and to allow filters to reference their input bitstreams without
> duplicating shared settings.
>
> This revision also retains a platform device for each MDF filter, as
> each filter manages its own registers, interrupt, DMA channel and IIO
> acquisition state, with a separate suspend/resume lifecycle.
>
> * Clock management
>
> Several clock-management review comments are addressed in this revision:
> - The provider-side clock-frequency property has been removed. Consumers
> request CCK rates through assigned-clocks and assigned-clock-rates.
> - The clock-names property has been removed. The core acquires its single
> input clock by index, and CCK gating uses regmap-based clock operations.
> - Remove the unused clock-ranges property, as the core now explicitly
> shares the kernel clock with the serial interfaces and filters instead
> of relying on parent clock lookup.
>
> Clock topology point remains open, awaiting clarification of the MDF topology.
>
> Changes since v1:
> - Split the large IIO driver patch into smaller functional patches.
> - Replace provider-side clock-frequency with consumer-assigned CCK rates
> through the common clock framework.
> - Remove the platform devices for serial interfaces.
> - Replace the interleave phandle list with a filter count, covering
> consecutive filters starting at filter 0.
> - Simplify clock-output-names, remove clock-names, reset-names and
> filter-level clock properties, and move mdf-dai into an explicit
> property outside the conditional schema.
> - Rename the binding to match the STM32MP25 compatible, sort compatible
> entries, and simplify the binding patch subject.
> - Use unsigned long for match data, improve probe error reporting and
> wrapping, remove a probe-success debug message, and add kernel-doc for
> exported core functions.
> - Use scoped spinlock guards.
> - Remove empty serial-interface runtime-PM callbacks.
> - Remove the redundant ASoC platform module alias.
>
> Additional fixes since v1 (following Sashiko review):
> - Compute the settling-time discard count with 64-bit arithmetic.
> - Size cyclic DMA periods in complete scans and validate buffer and
> period alignment before starting DMA.
> - Fix backend-enable rollback so backend zero is disabled as well.
> - Use managed allocation for the conversion buffer and managed IIO
> triggered-buffer setup.
> - Release temporary synchronization and serial-interface firmware-node
> references. Replacing interleave phandles also removes the associated
> stored node references.
> - Avoid unregistering secondary interleaved filters that were never
> registered as IIO devices.
> - Use managed acquisition of the optional serial clock.
> - Replace the GCD-based CCK divider selection with a search for the
> largest valid divisor, allowing non-power-of-two divider values.
> - Remove the selection of the undefined COMMON_CLK_REGMAP symbol.
>
> Previous discussion:
> https://lore.kernel.org/all/20261001145702.2628429-1-olivier.moysan@foss.st…
>
> Signed-off-by: Olivier Moysan <olivier.moysan(a)foss.st.com>
> ---
> Olivier Moysan (11):
> dt-bindings: iio: adc: add stm32mp2 mdf filter
> iio: adc: stm32-mdf: add core registration
> iio: adc: stm32-mdf: add cck clocks provider
> iio: adc: stm32-mdf: add serial interfaces support
> iio: adc: stm32-mdf: add digital filter device support
> iio: adc: stm32-mdf: configure cic filters and sample rates
> iio: adc: stm32-mdf: add direct iio conversion support
> iio: adc: stm32-mdf: add dma buffered acquisition support
> iio: adc: stm32-mdf: add external timer trigger support
> iio: adc: stm32-mdf: add dmic audio filter support
> ASoC: stm32: add mdf dai support
>
> .../bindings/iio/adc/st,stm32mp25-mdf.yaml | 341 ++++
> drivers/iio/adc/Kconfig | 29 +
> drivers/iio/adc/Makefile | 3 +
> drivers/iio/adc/stm32-mdf-adc.c | 2080 ++++++++++++++++++++
> drivers/iio/adc/stm32-mdf-core.c | 899 +++++++++
> drivers/iio/adc/stm32-mdf-serial.c | 223 +++
> drivers/iio/adc/stm32-mdf.h | 275 +++
> include/linux/iio/adc/stm32-mdf-adc.h | 19 +
> sound/soc/stm/Kconfig | 15 +
> sound/soc/stm/Makefile | 3 +
> sound/soc/stm/stm32_amdf.c | 375 ++++
> 11 files changed, 4262 insertions(+)
> ---
> base-commit: d922ed738439e1d5b4701df7f4cdd49a09925624
> change-id: 20261112-upstream_mdf_v2-76040d99138e
>
> Best regards,
> --
> Olivier Moysan <olivier.moysan(a)foss.st.com>
>
On Tue, Nov 17, 2026 at 11:54 PM Paul Moore <paul(a)paul-moore.com> wrote:
>
> On Nov 17, 2026 Albert Esteve <aesteve(a)redhat.com> wrote:
> >
> > Both DMA_HEAP_IOCTL_ALLOC and the new DMA_BUF_IOCTL_XFER_CHARGE ioctl
> > accept a charge_fd field that, when set, causes the allocation to be
> > charged to an arbitrary process's cgroup rather than the caller's.
> >
> > Charging is currently limited to the caller's own memcg subtree unless
> > the caller holds CAP_SYS_RESOURCE. But the capability is all-or-nothing.
> > A process holding it, along with a dma-heap device node or a dma-buf
> > fd can charge unlimited memory to any other process's cgroup, potentially
> > exhausting that cgroup's limit and triggering OOM kills independent of
> > the victim's own activity or privileges.
> >
> > Add security_memcg_charge_task(), called in get_obj_cgroup_from_fd()
> > when charge_fd refers to another process. The hook receives
> > the credentials of the allocating process (from) and the credentials
> > of the process whose cgroup will be charged (to), giving security
> > modules a controlled enforcement point for cross-cgroup objcg
> > attribution policy.
> >
> > When CONFIG_SECURITY is not set the hook compiles to an inline
> > returning 0, adding no overhead to the fast path.
> >
> > Signed-off-by: Albert Esteve <aesteve(a)redhat.com>
> > ---
> > include/linux/lsm_hook_defs.h | 1 +
> > include/linux/security.h | 7 +++++++
> > mm/memcontrol.c | 11 +++++++++++
> > security/security.c | 15 +++++++++++++++
> > 4 files changed, 34 insertions(+)
>
> ...
>
> > diff --git a/mm/memcontrol.c b/mm/memcontrol.c
> > index 03cd90d5e623..2e6fcbe14d43 100644
> > --- a/mm/memcontrol.c
> > +++ b/mm/memcontrol.c
> > @@ -60,6 +60,7 @@
> > #include <linux/lockdep.h>
> > #include <linux/resume_user_mode.h>
> > #include <linux/psi.h>
> > +#include <linux/security.h>
> > #include <linux/seq_buf.h>
> > #include <linux/sched/isolation.h>
> > #include <linux/kmemleak.h>
> > @@ -3198,10 +3199,12 @@ static bool mem_cgroup_may_charge(struct mem_cgroup *memcg)
> > struct obj_cgroup *get_obj_cgroup_from_fd(int fd)
> > {
> > struct cgroup_subsys_state *css;
> > + const struct cred *tcred;
> > struct obj_cgroup *objcg;
> > struct mem_cgroup *memcg;
> > struct task_struct *task;
> > unsigned int pidfd_flags;
> > + int ret;
> >
> > if (mem_cgroup_disabled())
> > return ERR_PTR(-EOPNOTSUPP);
> > @@ -3226,6 +3229,14 @@ struct obj_cgroup *get_obj_cgroup_from_fd(int fd)
> > if (IS_ERR(task))
> > return ERR_CAST(task);
> >
> > + tcred = get_task_cred(task);
> > + ret = security_memcg_charge_task(current_cred(), tcred);
>
> Do you ever envision this "from" cred being something other than
> current_cred()?
Good point. No, I do not.
> If the answer is "no", we might want to consider changing
> the LSM hook slightly to help prevent misuse in the future:
>
> int security_current_memcg_charge_task(const struct cred *tcred);
Agreed. I'll apply the same to the cgroupfd variant for symmetry (its
"from" is also always current_cred()).
BR,
Albert.
>
> > + put_cred(tcred);
> > + if (ret) {
> > + put_task_struct(task);
> > + return ERR_PTR(ret);
> > + }
> > +
> > rcu_read_lock();
> > css = task_css(task, memory_cgrp_id);
> > put_task_struct(task);
>
> --
> paul-moore.com
>
On Tue, Nov 17, 2026 at 03:54:31PM +0000, Ying Xiao wrote:
> system_heap_allocate() allocates pages via order_flags[] with __GFP_ZERO
> while the direct map still has the memory encryption bit set. For the
> system_cc_shared heap, set_memory_decrypted() subsequently clears the
> encryption bit without re-zeroing, leaving ciphertext in DRAM on
> confidential computing (CoCo) guests instead of plaintext zeros.
>
> Skip __GFP_ZERO during alloc_pages() for cc_shared allocations, and zero
> the pages once in system_heap_set_page_decrypted() after
> set_memory_decrypted() succeeds.
>
> Fixes: 78b30c50a7ac ("dma-buf: heaps: system: add system_cc_shared heap for explicitly shared memory")
> Reviewed-by: Jacob Moroni <jmoroni(a)google.com>
> Signed-off-by: Ying Xiao <eagleshaw(a)google.com>
> ---
> drivers/dma-buf/heaps/system_heap.c | 24 ++++++++++++++++++++----
> 1 file changed, 20 insertions(+), 4 deletions(-)
This seems fine, but Aneesh is fixing this in a more complete way with
this other series.
Reviewed-by: Jason Gunthorpe <jgg(a)nvidia.com>
Jason
On Tue, Nov 17, 2026 at 11:54 PM Paul Moore <paul(a)paul-moore.com> wrote:
>
> On Nov 17, 2026 Albert Esteve <aesteve(a)redhat.com> wrote:
> >
> > Shared-memory allocator services (e.g., Android's gralloc)
> > allocate dma-bufs on behalf of client processes in different
> > cgroups. Today those allocations are charged to the allocator's
> > own cgroup, leaving client cgroups with no visibility into their
> > actual memory consumption and defeating resource limits.
> >
> > This series adds memory cgroup accounting for dma-buf allocations,
> > building on T.J. Mercier's earlier series [1] and incorporating
> > feedback from previous versions and LPC discussions [2].
> >
> > Patch 1 introduces the MEMCG_DMABUF stat and the
> > obj_cgroup_reserve_dmabuf()/obj_cgroup_cancel_dmabuf() and
> > mem_cgroup_commit_dmabuf()/mem_cgroup_uncharge_dmabuf() helpers
> > in mm/memcontrol.c
> >
> > Patch 2 wires up the charging policy: dma_buf_export() stores
> > exp_info.objcg and updates the stat, a new charge_fd field in
> > DMA_HEAP_IOCTL_ALLOC accepts a pidfd or cgroupfd to identify
> > the target cgroup, and __GFP_ACCOUNT is removed from system-heap
> > allocations to avoid double counting.
> >
> > Patch 3 adds DMA_BUF_IOCTL_XFER_CHARGE, a general ioctl on any
> > dma-buf fd to transfer charges post-allocation. This covers the
> > double-hop allocator case (SurfaceFlinger -> gralloc -> kernel)
> > and works for buffers from any exporter that opts in. Charging
> > is gated by dmabuf->objcg being set at export time, ensuring that
> > transfer is only applied for buffers backed by system memory where
> > size reflects actual bytes. If the receiving cgroup lacks capacity
> > for the charge, the ioctl returns -ENOMEM and the original charge
> > is preserved.
> >
> > Patches 4-7 add access control for cross-cgroup charging. Letting
> > userspace decide who to charge needs to be a privileged operation
> > because it has material impact on OOM decision and resource limits.
> > Charging outside the caller's own memcg subtree requires
> > CAP_SYS_RESOURCE. On top of that, LSM hooks gate the two charge_fd
> > flavours: security_memcg_charge_task() gates the pidfd path (target
> > identified by task credentials) and security_memcg_charge_cgroup()
> > gates the cgroupfd path (target identified by cgroup directory label),
> > with SELinux implementations using process2:charge_to and
> > cgroup:charge_to permissions.
>
> I'm probably misunderstanding the description here, but in both cases
> (the pidfd or cgroupfd case), ultimately the cgroup is charged, yes? In
> the cgroupfd case it is more direct, but in the pidfd case it is still
> the cgroup associated with the process identified by pidfd, yes?
Your understanding is correct here.
>
> If that's the case - and it very well may not be (!) - it probably makes
> more sense to combine the two SELinux access controls into one. Yes, the
> LSM hooks and callbacks would likely need to be different due to the
> mechanics of it, but the permission check "cgroup/charge" could be the
> same.
Combining SELinux access controls makes sense to me. I kept them split
because I wanted to preserve granularity between the two flavours, and
process2 seemed like a natural fit for the pidfd path, but I guess it
can still be achieved with a single permission through the target
types.
I'll rework for v6. So, in the pidfd case the check target would
remain the process's domain:
allow allocator_t client_t:cgroup charge_to;
where allocator_t is the domain requesting the charge (i.e., the
central allocator), and client_t is the domain of the process the
pidfd refers to. The groupfd path would check the cgroup directory
label like so:
allow allocator_t cgroup_t:cgroup charge_to;
Would that be ok?
>
> > Patch 8 adds selftests. The tests and vmtest script were mostly
> > written by an LLM, closely following the style of the surrounding
> > tests and the virtme-ng setup. All code has been reviewed and tested.
>
> I think we need to have selinux-testsuite tests to go along with
> this, especially as this would be the first patchset to add cgroup
> controls. Historically I've pushed back on piecemeal cgroup additions,
> pushing for some basic design of how to manage access controls for
> resource management first, but since evidently no one wants to do that,
> we really do need tests.
>
> https://github.com/SELinuxProject/selinux-testsuite
Agreed! I was already playing with it between the last version and
this one. I have some tests drafted, more or less. I was unfamiliar
with the testsuite, so instead of offloading the work to an LLM, I
tried to follow along and proceeded too slowly.
I will link a PR when sending the next version.
>
> > Known limitations:
> >
> > - Single-owner model: a dma-buf carries one memcg charge regardless
> > of how many processes share it.
>
> Once again, I'm sure I'm misunderstanding things, but are you saying
> that multiple cgroups can end up sharing the same dma-buf despite
> only one of the cgroups taking the accounting hit?
Yes, you are correct. A dma-buf (its fd) can be shared by multiple
processes from multiple cgroups, but only one holds the charge. With
this series it can be transferred, but never shared.
Sharing could be a follow-up series. Perhaps splitting the charge
equally? But sharing is a big problem on its own, so I preferred to
keep it out of this series.
>
> Hopefully the charged cgroup is deterministic?
Yes, the charged cgroup is deterministic: it is set at allocation, and
only moves via an explicit ioctl.
>
> > - Only memcg accounting. CMA heaps would additionally need dmem
> > controller integration.
>
> Do you have a rough idea of how that would work? I ask only because I'm
> interested in seeing if that would require an additional LSM hook or if
> there is some way we could leverage the same hook(s) used here.
Rough idea, yes. Today, no dma-buf allocation charges dmem at all, and
of course no target charging either. The first goal for CMA is simply
getting those heaps accounted. In that regard, Eric Chanudet has a
series making CMA allocations memcg-accountable with per-area counter
[1], and is working on extending that approach to dmem. It's a bit on
hold waiting for the feedback on this series.
But afaik the cross-cgroup charging and central allocator problem is
mainly a system-memory one. Whether dmem ever needs the same
cross-cgroup attribution (e.g., DRM central allocator wanting to
charge clients' dmem budgets) is not clear to me.
Nonetheless, if it does, the internals should be mostly the same;
everything, including the permission checks is controller-agnostic.
Only the controller performing the charge changes. I expect no
additional hook is required.
[1] https://lore.kernel.org/all/20260821-cma-memcg-regions-v1-0-d21b165b8440@re…
>
> > - If a transfer of an uncharged buffer fails, the buffer remains
> > charged to the original cgroup. The allocator (userspace) is
> > expected to handle this (retry, free, ...).
> > - The LSM hooks are intentionally narrow. Broader cgroup access controls
> > (e.g. for the memfd/kexec handover case [2]) could be a separate effort
> > reusing the same pattern.
> > - Only system heap sets exp_info.objcg today. Other exporters
> > (DRM, V4L2, etc.) can opt in by setting it, but are not
> > covered by this series.
> > - Related to the above: lazy backing-store allocation is not supported.
> > This can be extended later, e.g., by adding a flag on the dma-buf
> > struct for explicitly marking when memory is committed.
>
> Similar to the CMA case, any rough ideas on what this would look like?
Yes, again I have a rough idea. We already separate reserve and commit
operations, so the idea is to delay when a charge is committed. For
that we can use a flag in the dma-buf struct to mark when the memory
is committed. The limit is still enforced up front (so a lazy exporter
cannot overcommit), and the stat reflects the actual allocation.
The permission model is also unchanged for this case. The flag only
affects when the stat will reflect the charge.
Thanks!
Albert.
>
> > Note on TTM/GPU accounting [3]: that effort charges system memory
> > allocated for GPU buffers per page, with its own stats (gpu_active
> > and gpu_reclaim). This series charges at the dma-buf level, for
> > memory with no memory.stat category of its own; exporters whose
> > memory is already charged by their allocator must not opt in, so
> > the two do not overlap.
> >
> > [1] https://lore.kernel.org/cgroups/20230109213809.418135-1-tjmercier@google.co…
> > [2] https://lpc.events/event/20/contributions/2416/
> > [3] https://lore.kernel.org/all/20260706052330.1110909-1-airlied@gmail.com/
> >
> > Signed-off-by: Albert Esteve <aesteve(a)redhat.com>
>
> --
> paul-moore.com
>