Thread (91 messages) 91 messages, 3 authors, 3d ago

Re: [PATCH v4 19/38] HSI: cmt_speech: convert mmap hook to mmap_prepare, refactor

flat view

From: Suren Baghdasaryan <surenb@google.com>
Date: 2026-10-04 18:09:54
Also in: bpf, fuse-devel, kvm, kvm-riscv, kvmarm, linux-arch, linux-doc, linux-fbdev, linux-fsdevel, linux-mm, linux-perf-users, linux-rdma, linux-riscv, linux-s390, linux-scsi, linux-sound, linux-usb, linuxppc-dev, lkml, selinux, sparclinux

On Sat, Oct 3, 2026 at 6:39 PM Lorenzo Stoakes (ARM) [off-list ref] wrote:
Use the mmap_prepare in favour of the deprecated mmap hook as part of the
work to convert one to another.

Since this is simply a refcounted kernel page that has been allocated, it
should not be marked VM_IO and should be inserted using the kernel page
insertion mechanism, so convert it to do this instead.

Use the VMA descriptor's private data field as a scratch buffer to store
the page in - this stays valid throughout the kernel page mapping
operation.

Signed-off-by: Lorenzo Stoakes (ARM) <ljs@kernel.org>
Reviewed-by: Suren Baghdasaryan <surenb@google.com>

quoted hunk ↗ jump to hunk
---
 drivers/hsi/clients/cmt_speech.c | 33 +++++++++------------------------
 1 file changed, 9 insertions(+), 24 deletions(-)
diff --git a/drivers/hsi/clients/cmt_speech.c b/drivers/hsi/clients/cmt_speech.c
index 7226677ebde7..801697b74d4f 100644
--- a/drivers/hsi/clients/cmt_speech.c
+++ b/drivers/hsi/clients/cmt_speech.c
@@ -1084,22 +1084,6 @@ static void cs_hsi_stop(struct cs_hsi_iface *hi)
        kfree(hi);
 }

-static vm_fault_t cs_char_vma_fault(struct vm_fault *vmf)
-{
-       struct cs_char *csdata = vmf->vma->vm_private_data;
-       struct page *page;
-
-       page = virt_to_page((void *)csdata->mmap_base);
-       get_page(page);
-       vmf->page = page;
-
-       return 0;
-}
-
-static const struct vm_operations_struct cs_char_vm_ops = {
-       .fault  = cs_char_vma_fault,
-};
-
 static int cs_char_fasync(int fd, struct file *file, int on)
 {
        struct cs_char *csdata = file->private_data;
@@ -1256,18 +1240,19 @@ static long cs_char_ioctl(struct file *file, unsigned int cmd,
        return r;
 }

-static int cs_char_mmap(struct file *file, struct vm_area_struct *vma)
+static int cs_char_mmap_prepare(struct vm_area_desc *desc)
 {
-       if (vma->vm_end < vma->vm_start)
-               return -EINVAL;
+       struct file *file = desc->file;
+       struct cs_char *csdata = file->private_data;
+       struct page **pages = (struct page **)&desc->private_data;

-       if (vma_pages(vma) != 1)
+       if (vma_desc_pages(desc) != 1)
                return -EINVAL;

-       vm_flags_set(vma, VM_IO | VM_DONTDUMP | VM_DONTEXPAND);
-       vma->vm_ops = &cs_char_vm_ops;
-       vma->vm_private_data = file->private_data;
+       vma_desc_set_flags(desc, VMA_DONTDUMP_BIT, VMA_DONTEXPAND_BIT);

+       *pages = virt_to_page((void *)csdata->mmap_base);
+       mmap_action_map_kernel_pages_full(desc, pages);
        return 0;
 }
@@ -1353,7 +1338,7 @@ static const struct file_operations cs_char_fops = {
        .write          = cs_char_write,
        .poll           = cs_char_poll,
        .unlocked_ioctl = cs_char_ioctl,
-       .mmap           = cs_char_mmap,
+       .mmap_prepare   = cs_char_mmap_prepare,
        .open           = cs_char_open,
        .release        = cs_char_release,
        .fasync         = cs_char_fasync,

--
2.55.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help