All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] evl: fix the gdb accessing control buffer issue.
@ 2024-12-09  8:37 Qichen Qiu
  2024-12-09  9:25 ` Florian Bezdeka
  2024-12-09 15:01 ` Philippe Gerum
  0 siblings, 2 replies; 9+ messages in thread
From: Qichen Qiu @ 2024-12-09  8:37 UTC (permalink / raw)
  To: xenomai; +Cc: rpm, Qichen Qiu

Currently, EVL maps the control buffer using remap_pfn_range, tagging 
the memory with VM_IO. However, this prevents access by gdb.

This patch introduces the control_mmap_access function for the control 
VMA, enabling gdb access when CONFIG_HAVE_IOREMAP_PROT is supported on 
the target architecture.

Signed-off-by: Qichen Qiu <ruiqurm@gmail.com>
---
 kernel/evl/control.c | 53 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 52 insertions(+), 1 deletion(-)

diff --git a/kernel/evl/control.c b/kernel/evl/control.c
index 2d1b44f3b0dc..33ec47745740 100644
--- a/kernel/evl/control.c
+++ b/kernel/evl/control.c
@@ -8,6 +8,7 @@
 #include <linux/mm.h>
 #include <linux/sched/isolation.h>
 #include <linux/bitmap.h>
+#include <linux/highmem.h>
 #include <evl/memory.h>
 #include <evl/factory.h>
 #include <evl/tick.h>
@@ -335,8 +336,52 @@ static long control_ioctl(struct file *filp, unsigned int cmd,
 	return ret;
 }
 
+static int control_mmap_access(struct vm_area_struct *vma, unsigned long addr,
+			       void *buf, int len, int write)
+{
+	resource_size_t phys_addr;
+	pte_t *ptep, pte;
+	void *virt_addr;
+	spinlock_t *ptl;
+	struct page *page;
+	int offset = offset_in_page(addr);
+	int ret = -EINVAL;
+
+	if (follow_pte(vma, addr, &ptep, &ptl))
+		return -EINVAL;
+
+	pte = ptep_get(ptep);
+	pte_unmap_unlock(ptep, ptl);
+
+	phys_addr = (resource_size_t)pte_pfn(pte) << PAGE_SHIFT;
+	page = pfn_to_page(PFN_DOWN(phys_addr));
+
+	virt_addr = kmap(page) + offset;
+	if (!virt_addr) {
+		ret = -ENOMEM;
+		goto unmap;
+	}
+
+	if (write) {
+		memcpy(virt_addr, buf, len);
+	} else {
+		memcpy(buf, virt_addr, len);
+	}
+	ret = len;
+
+unmap:
+	kunmap(page);
+
+	return ret;
+}
+
+static const struct vm_operations_struct control_mmap_ops = {
+	.access = control_mmap_access
+};
+
 static int control_mmap(struct file *filp, struct vm_area_struct *vma)
 {
+	int err;
 	void *p = evl_get_heap_base(&evl_shared_heap);
 	unsigned long pfn = __pa(p) >> PAGE_SHIFT;
 	size_t len = vma->vm_end - vma->vm_start;
@@ -344,7 +389,13 @@ static int control_mmap(struct file *filp, struct vm_area_struct *vma)
 	if (len != evl_shm_size)
 		return -EINVAL;
 
-	return remap_pfn_range(vma, vma->vm_start, pfn, len, PAGE_SHARED);
+	err = remap_pfn_range(vma, vma->vm_start, pfn, len, PAGE_SHARED);
+	if (err < 0){
+		return err;
+	}
+
+	vma->vm_ops = &control_mmap_ops;
+	return 0;
 }
 
 static const struct file_operations control_fops = {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-12-17 14:26 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-09  8:37 [PATCH] evl: fix the gdb accessing control buffer issue Qichen Qiu
2024-12-09  9:25 ` Florian Bezdeka
2024-12-09 13:47   ` [PATCH v2] " Qichen Qiu
2024-12-09 15:11   ` [PATCH] " Philippe Gerum
2024-12-09 15:01 ` Philippe Gerum
2024-12-09 16:31   ` Qichen Qiu
2024-12-11 15:27   ` [PATCH] evl: replace `remap_pfn_range` with `vm_insert_page` in control_mmap Qichen Qiu
2024-12-16 14:22     ` Philippe Gerum
2024-12-17 14:26       ` Qichen Qiu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.