All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Gerum <rpm@xenomai.org>
To: Qichen Qiu <ruiqurm@gmail.com>
Cc: xenomai@lists.linux.dev
Subject: Re: [PATCH] evl: replace `remap_pfn_range` with `vm_insert_page` in control_mmap.
Date: Mon, 16 Dec 2024 15:22:02 +0100	[thread overview]
Message-ID: <87ed27emid.fsf@xenomai.org> (raw)
In-Reply-To: <20241211152730.864059-1-ruiqurm@gmail.com> (Qichen Qiu's message of "Wed, 11 Dec 2024 15:27:30 +0000")

Qichen Qiu <ruiqurm@gmail.com> writes:

> Hi, I used vm_insert_page to map the area to user space, and it 
> successfully resolved the issue.
>

Thanks for the patch. A few observations:

- for this to work, you definitely need to update the system heap
  allocation method accordingly in the same patch, i.e. using vzalloc
  instead of kzalloc. This patch is incomplete.

- Why eagerly clearing the VM_WRITE flag from the vma?

- the short log should refer to what is being fixed as perceived by
  $user, not how we do that. The latter should be part of the long log
  instead. In this case, that would be something like
  evl/memory: allow system heap inspection using GDB
  The long log could then give a few details about GDB, ptracing, the
  VM_IO issue, and the reasoning behind the change of interface from
  remap_pfn_range to vm_insert_page.

> Signed-off-by: Qichen Qiu <ruiqurm@gmail.com>
> ---
>  kernel/evl/control.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/evl/control.c b/kernel/evl/control.c
> index 2d1b44f3b0dc..eee4bcaad390 100644
> --- a/kernel/evl/control.c
> +++ b/kernel/evl/control.c
> @@ -338,13 +338,22 @@ static long control_ioctl(struct file *filp, unsigned int cmd,
>  static int control_mmap(struct file *filp, struct vm_area_struct *vma)
>  {
>  	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;
> +	unsigned long addr = vma->vm_start;
> +	int err;
>  
>  	if (len != evl_shm_size)
>  		return -EINVAL;
> +
> +	vm_flags_clear(vma, VM_WRITE);
> +
> +	while (addr < vma->vm_end) {
> +		err = vm_insert_page(vma, addr, virt_to_page(p));
> +		if (err < 0)
> +			return err;
> +		addr += PAGE_SIZE;
> +		p += PAGE_SIZE;
> +	}
>  
> -	return remap_pfn_range(vma, vma->vm_start, pfn, len, PAGE_SHARED);
> +	return 0;
>  }
>  
>  static const struct file_operations control_fops = {

-- 
Philippe.

  reply	other threads:[~2024-12-16 14:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2024-12-17 14:26       ` Qichen Qiu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ed27emid.fsf@xenomai.org \
    --to=rpm@xenomai.org \
    --cc=ruiqurm@gmail.com \
    --cc=xenomai@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.