]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
staging: comedi: support vm_access_process for mmap'd buffer
authorIan Abbott <abbotti@mev.co.uk>
Thu, 20 Apr 2017 18:05:14 +0000 (19:05 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 25 Apr 2017 18:43:42 +0000 (20:43 +0200)
If a process that has mmap'd a COMEDI buffer is being run under a
debugger such as GDB, the buffer contents are inaccessible from the
debugger.  Support the `access()` VM operation to allow the buffer
contents to be accessed by another process.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/comedi/comedi_buf.c
drivers/staging/comedi/comedi_fops.c
drivers/staging/comedi/comedi_internal.h

index 1e1df89b50181e97a6df0fbed0d6ba54c01439a2..8e9b30b26810bd127fcde5baab4734dd6a21c57a 100644 (file)
@@ -161,6 +161,30 @@ int comedi_buf_map_put(struct comedi_buf_map *bm)
        return 1;
 }
 
+/* helper for "access" vm operation */
+int comedi_buf_map_access(struct comedi_buf_map *bm, unsigned long offset,
+                         void *buf, int len, int write)
+{
+       unsigned int pgoff = offset & ~PAGE_MASK;
+       unsigned long pg = offset >> PAGE_SHIFT;
+       int done = 0;
+
+       while (done < len && pg < bm->n_pages) {
+               int l = min_t(int, len - done, PAGE_SIZE - pgoff);
+               void *b = bm->page_list[pg].virt_addr + pgoff;
+
+               if (write)
+                       memcpy(b, buf, l);
+               else
+                       memcpy(buf, b, l);
+               buf += l;
+               done += l;
+               pg++;
+               pgoff = 0;
+       }
+       return done;
+}
+
 /* returns s->async->buf_map and increments its kref refcount */
 struct comedi_buf_map *
 comedi_buf_map_from_subdev_get(struct comedi_subdevice *s)
index 92d864fc08acec25f894c996256427abbb9a47b8..f191c2a7573226c647521b6a454d4face790a3d1 100644 (file)
@@ -2165,9 +2165,24 @@ static void comedi_vm_close(struct vm_area_struct *area)
        comedi_buf_map_put(bm);
 }
 
+static int comedi_vm_access(struct vm_area_struct *vma, unsigned long addr,
+                           void *buf, int len, int write)
+{
+       struct comedi_buf_map *bm = vma->vm_private_data;
+       unsigned long offset =
+           addr - vma->vm_start + (vma->vm_pgoff << PAGE_SHIFT);
+
+       if (len < 0)
+               return -EINVAL;
+       if (len > vma->vm_end - addr)
+               len = vma->vm_end - addr;
+       return comedi_buf_map_access(bm, offset, buf, len, write);
+}
+
 static const struct vm_operations_struct comedi_vm_ops = {
        .open = comedi_vm_open,
        .close = comedi_vm_close,
+       .access = comedi_vm_access,
 };
 
 static int comedi_mmap(struct file *file, struct vm_area_struct *vma)
index 534415e331b663aeea52ecd4357b6124df3acffa..6246f4a78ca6c6ea81b8efaa4779485669f4f498 100644 (file)
@@ -29,6 +29,8 @@ void comedi_buf_reset(struct comedi_subdevice *s);
 bool comedi_buf_is_mmapped(struct comedi_subdevice *s);
 void comedi_buf_map_get(struct comedi_buf_map *bm);
 int comedi_buf_map_put(struct comedi_buf_map *bm);
+int comedi_buf_map_access(struct comedi_buf_map *bm, unsigned long offset,
+                         void *buf, int len, int write);
 struct comedi_buf_map *comedi_buf_map_from_subdev_get(
                struct comedi_subdevice *s);
 unsigned int comedi_buf_write_n_available(struct comedi_subdevice *s);