qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Warner Losh <imp@bsdimp.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>
Cc: qemu-devel@nongnu.org, Riku Voipio <riku.voipio@iki.fi>,
	 Laurent Vivier <laurent@vivier.eu>,
	Kyle Evans <kevans@freebsd.org>
Subject: Re: [PATCH v4 2/3] bsd-user: Propagate alignment argument to mmap_find_vma()
Date: Sat, 8 Mar 2025 10:31:04 -0700	[thread overview]
Message-ID: <CANCZdfpwH=Y1JmK1Z2NCbo5YZOnzi9dQDPWntOO-wVu0i-C6mQ@mail.gmail.com> (raw)
In-Reply-To: <20250308122842.76377-3-philmd@linaro.org>

[-- Attachment #1: Type: text/plain, Size: 3867 bytes --]

On Sat, Mar 8, 2025 at 5:28 AM Philippe Mathieu-Daudé <philmd@linaro.org>
wrote:

> Propagate the alignment to mmap_find_vma(), effectively
> embedding mmap_find_vma_aligned() within mmap_find_vma().
>
> Add a comment in do_bsd_shmat() to clarify alignment above
> page size is not required.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  bsd-user/bsd-mem.h |  4 +++-
>  bsd-user/qemu.h    |  2 +-
>  bsd-user/mmap.c    | 10 ++--------
>  3 files changed, 6 insertions(+), 10 deletions(-)
>

Reviewed-by: Warner Losh <imp@bsdimp.com>


> diff --git a/bsd-user/bsd-mem.h b/bsd-user/bsd-mem.h
> index f5ec0de24ca..90ca0e33775 100644
> --- a/bsd-user/bsd-mem.h
> +++ b/bsd-user/bsd-mem.h
> @@ -370,9 +370,11 @@ static inline abi_long do_bsd_shmat(int shmid,
> abi_ulong shmaddr, int shmflg)
>          if (shmaddr) {
>              host_raddr = shmat(shmid, (void *)g2h_untagged(shmaddr),
> shmflg);
>          } else {
> +            abi_ulong alignment;
>              abi_ulong mmap_start;
>
> -            mmap_start = mmap_find_vma(0, shm_info.shm_segsz);
> +            alignment = 0; /* alignment above page size not required */
> +            mmap_start = mmap_find_vma(0, shm_info.shm_segsz, alignment);
>

Why create a write-only variable that you just pass to this function? Is
this
a pattern used elsewhere and if so when?

It's fine, imho, like this, but it is a little odd so I wonder why you did
it like this.
There may be something I can learn.

Warner


>              if (mmap_start == -1) {
>                  return -TARGET_ENOMEM;
> diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h
> index 4e97c796318..0b3bd65b180 100644
> --- a/bsd-user/qemu.h
> +++ b/bsd-user/qemu.h
> @@ -242,7 +242,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong
> old_size,
>                         abi_ulong new_addr);
>  int target_msync(abi_ulong start, abi_ulong len, int flags);
>  extern abi_ulong mmap_next_start;
> -abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size);
> +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong
> alignment);
>  void mmap_reserve(abi_ulong start, abi_ulong size);
>  void TSA_NO_TSA mmap_fork_start(void);
>  void TSA_NO_TSA mmap_fork_end(int child);
> diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c
> index dfa6e728ab5..3f0df79c375 100644
> --- a/bsd-user/mmap.c
> +++ b/bsd-user/mmap.c
> @@ -275,8 +275,7 @@ static abi_ulong mmap_find_vma_reserved(abi_ulong
> start, abi_ulong size,
>   * It must be called with mmap_lock() held.
>   * Return -1 if error.
>   */
> -static abi_ulong mmap_find_vma_aligned(abi_ulong start, abi_ulong size,
> -                                       abi_ulong alignment)
> +abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size, abi_ulong
> alignment)
>  {
>      void *ptr, *prev;
>      abi_ulong addr;
> @@ -395,11 +394,6 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong
> start, abi_ulong size,
>      }
>  }
>
> -abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size)
> -{
> -    return mmap_find_vma_aligned(start, size, 0);
> -}
> -
>  /* NOTE: all the constants are the HOST ones */
>  abi_long target_mmap(abi_ulong start, abi_ulong len, int prot,
>                       int flags, int fd, off_t offset)
> @@ -494,7 +488,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len,
> int prot,
>          host_len = len + offset - host_offset;
>          host_len = HOST_PAGE_ALIGN(host_len);
>          alignment = (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT;
> -        start = mmap_find_vma_aligned(real_start, host_len, alignment);
> +        start = mmap_find_vma(real_start, host_len, alignment);
>          if (start == (abi_ulong)-1) {
>              errno = ENOMEM;
>              goto fail;
> --
> 2.47.1
>
>

[-- Attachment #2: Type: text/html, Size: 5010 bytes --]

  reply	other threads:[~2025-03-08 17:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 12:28 [PATCH v4 0/3] user: Extract common MMAP API to 'user/mmap.h' Philippe Mathieu-Daudé
2025-03-08 12:28 ` [PATCH v4 1/3] bsd-user: Always use mmap_find_vma_aligned() in target_mmap() Philippe Mathieu-Daudé
2025-03-08 17:33   ` Warner Losh
2025-03-08 12:28 ` [PATCH v4 2/3] bsd-user: Propagate alignment argument to mmap_find_vma() Philippe Mathieu-Daudé
2025-03-08 17:31   ` Warner Losh [this message]
2025-03-08 12:28 ` [PATCH v4 3/3] user: Extract common MMAP API to 'user/mmap.h' Philippe Mathieu-Daudé
2025-03-09 12:10 ` [PATCH v4 0/3] " Philippe Mathieu-Daudé

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='CANCZdfpwH=Y1JmK1Z2NCbo5YZOnzi9dQDPWntOO-wVu0i-C6mQ@mail.gmail.com' \
    --to=imp@bsdimp.com \
    --cc=kevans@freebsd.org \
    --cc=laurent@vivier.eu \
    --cc=philmd@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).