Hi Ryan, Jean-Philippe, On Thu, Oct 15, 2026 at 4:27 PM Ryan Roberts <[email protected]> wrote:
> Expose CLA devices through a character device so userspace can enumerate > the available hardware and map accelerator register frames. > > Provide ioctl interface to report device topology, CPU affinity, domain > membership, mmap offsets, architecture version and attached accelerator > masks, together with the IIDR, DEVARCH and REVIDR of each accelerator. > > CLA registers can only be read from the CPU local to the device, while > enumeration may occur on any CPU. Validate the supported CLA > architecture version during device setup and cache the CLA and > accelerator identification registers for later ioctl queries. > > Support shared read-write mmap of one or more CLA register pages. Create > a context for every domain covered by the mapping and resolve faults > only while that context owns the domain. Queue unassigned contexts with > the domain scheduler, drop mmap_lock while waiting for assignment and > retry the fault after the context is woken. > > Co-developed-by: Jean-Philippe Brucker <[email protected]> > Signed-off-by: Jean-Philippe Brucker <[email protected]> > Signed-off-by: Ryan Roberts <[email protected]> This uapi is very simplistic and IIUC only provides a mmap:ed view of the accelerator memory area, without any details on how it is actually used. Since we don't know much about the usage it is hard to say whether this is a good approach compared to using e.g. an arm64-specific syscall. Whether to choose one or the other depends much on the error modus of this thing, how a CPU or a context should recover etc. > + /* > + * Cache some standard accelerator registers that user space may query > + * via ioctl from a remote CPU. > + */ If you're caching these registers for efficiency, a vDSO syscall could be more efficient as it could return the cached information without a roundtrip to kernelspace. OK kludgy, I know, but efficient. > +#define cla_for_each_mapped_domain(_vma, _domain) \ > + for (unsigned long __pg = (_vma)->vm_pgoff; \ > + __pg < (_vma)->vm_pgoff + vma_pages(_vma) && \ > + ((_domain) = cla_lut_pg[dev_nospec(__pg)]->domain); \ > + __pg = (_domain)->pg_offset + (_domain)->nr_devs) I like this macro. Very helpful. > +static long cla_ioctl_validate_param(struct file *file, > + struct arm_cla_param *param) (...) > +static long cla_ioctl_get_param(struct file *file, unsigned long arg) Looks good. > +static int cla_file_open(struct inode *inode, struct file *file) > +{ > + unsigned int index = iminor(inode) - MINOR(cla_devt); > + > + if (index >= cla_nr_classes) > + return -ENODEV; > + > + file->private_data = cla_accel_classes[index]; > + > + return 0; > +} As you mention that this absolutely will not work unless the process (task) is tied to the current CPU, this should be verified and enforced. Obviously the task is running on the CPU it is running on when it gets here. What we need to ascertain is that it absolutely cannot migrate. Essentially it needs to execute as a userspace version of a CPU-local workqueue or other CPU-bound kernel daemon that uses kthread_bind(). You *can* of course pin a process/task to a CPU with sched_setaffinity() in userspace and at a minimum this chardev should not be allowed to be opened unless the process has already done this and the affinity is set to the current CPU and the current CPU only. You want this to be enforced, but userspace does not provide a way to irrevocably bind a task to a certain CPU. Interestingly the kernel does, PF_NO_SETAFFINITY which is used in kthread.c. The only thing (I think) that can affect a task with PF_NO_SETAFFINITY is CPU hotplug. So I suggest that you might want to pursue some syscall extention to sched_setaffinity() such that PF_NO_SETAFFINITY is set on the process inside the kernel after creation, and then cla_file_open() should verify that the affinity is set to the current CPU only, and that PF_NO_SETAFFINITY is set. (You could of course hack-set the flag here in open() but I don't think that would be appreciated.) Yours, Linus Walleij
