All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts
@ 2016-09-18  1:20 Felix Janda
  2016-09-22  6:22 ` Riku Voipio
  2016-09-28 23:30 ` Peter Maydell
  0 siblings, 2 replies; 5+ messages in thread
From: Felix Janda @ 2016-09-18  1:20 UTC (permalink / raw)
  To: qemu-devel; +Cc: Riku Voipio

Signed-off-by: Felix Janda <felix.janda@posteo.de>
---
 linux-user/mmap.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/linux-user/mmap.c b/linux-user/mmap.c
index c4371d9..4882816 100644
--- a/linux-user/mmap.c
+++ b/linux-user/mmap.c
@@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
 
     if (flags & MREMAP_FIXED) {
         host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                     old_size, new_size,
+                                     (size_t) old_size, (size_t) new_size,
                                      flags,
                                      g2h(new_addr));
 
@@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
             host_addr = MAP_FAILED;
         } else {
             host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
-                                         old_size, new_size,
+                                         (size_t) old_size, (size_t) new_size,
                                          flags | MREMAP_FIXED,
                                          g2h(mmap_start));
             if (reserved_va) {
-- 
2.7.3

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts
  2016-09-18  1:20 [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts Felix Janda
@ 2016-09-22  6:22 ` Riku Voipio
  2016-09-23  0:36   ` Felix Janda
  2016-09-28 23:30 ` Peter Maydell
  1 sibling, 1 reply; 5+ messages in thread
From: Riku Voipio @ 2016-09-22  6:22 UTC (permalink / raw)
  To: Felix Janda; +Cc: qemu-devel

Hi,

On Sat, Sep 17, 2016 at 09:20:14PM -0400, Felix Janda wrote:
> Signed-off-by: Felix Janda <felix.janda@posteo.de>

Have you run the mremap tests of ltp with this on your host/guest
combo? 

> ---
>  linux-user/mmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index c4371d9..4882816 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
>  
>      if (flags & MREMAP_FIXED) {
>          host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> -                                     old_size, new_size,
> +                                     (size_t) old_size, (size_t) new_size,
>                                       flags,
>                                       g2h(new_addr));
>  
> @@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
>              host_addr = MAP_FAILED;
>          } else {
>              host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> -                                         old_size, new_size,
> +                                         (size_t) old_size, (size_t) new_size,
>                                           flags | MREMAP_FIXED,
>                                           g2h(mmap_start));
>              if (reserved_va) {
> -- 
> 2.7.3
> 

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts
  2016-09-22  6:22 ` Riku Voipio
@ 2016-09-23  0:36   ` Felix Janda
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Janda @ 2016-09-23  0:36 UTC (permalink / raw)
  To: Riku Voipio; +Cc: qemu-devel

Riku Voipio wrote:
> Hi,
> 
> On Sat, Sep 17, 2016 at 09:20:14PM -0400, Felix Janda wrote:
> > Signed-off-by: Felix Janda <felix.janda@posteo.de>
> 
> Have you run the mremap tests of ltp with this on your host/guest
> combo? 

I have just run the tests. My host is arm and my guest is aarch64.
Without the patch all but mremap02 fail. With the patch all but
mremap04 pass. The mremap04 test indicates that shmat is broken.

> > ---
> >  linux-user/mmap.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> > index c4371d9..4882816 100644
> > --- a/linux-user/mmap.c
> > +++ b/linux-user/mmap.c
> > @@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
> >  
> >      if (flags & MREMAP_FIXED) {
> >          host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > -                                     old_size, new_size,
> > +                                     (size_t) old_size, (size_t) new_size,
> >                                       flags,
> >                                       g2h(new_addr));
> >  
> > @@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
> >              host_addr = MAP_FAILED;
> >          } else {
> >              host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > -                                         old_size, new_size,
> > +                                         (size_t) old_size, (size_t) new_size,
> >                                           flags | MREMAP_FIXED,
> >                                           g2h(mmap_start));
> >              if (reserved_va) {
> > -- 
> > 2.7.3
> > 

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts
  2016-09-18  1:20 [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts Felix Janda
  2016-09-22  6:22 ` Riku Voipio
@ 2016-09-28 23:30 ` Peter Maydell
  2016-09-29  2:46   ` Felix Janda
  1 sibling, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2016-09-28 23:30 UTC (permalink / raw)
  To: Felix Janda; +Cc: QEMU Developers, Riku Voipio

On 17 September 2016 at 18:20, Felix Janda <felix.janda@posteo.de> wrote:
> Signed-off-by: Felix Janda <felix.janda@posteo.de>
> ---
>  linux-user/mmap.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> index c4371d9..4882816 100644
> --- a/linux-user/mmap.c
> +++ b/linux-user/mmap.c
> @@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
>
>      if (flags & MREMAP_FIXED) {
>          host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> -                                     old_size, new_size,
> +                                     (size_t) old_size, (size_t) new_size,
>                                       flags,
>                                       g2h(new_addr));
>
> @@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
>              host_addr = MAP_FAILED;
>          } else {
>              host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> -                                         old_size, new_size,
> +                                         (size_t) old_size, (size_t) new_size,
>                                           flags | MREMAP_FIXED,
>                                           g2h(mmap_start));
>              if (reserved_va) {
> --
> 2.7.3

Rather than this, I think it would be better to switch to
using the mremap() library call rather than direct syscall
here, which then matches the other mremap()s later in the
function. (That will work right because mremap()'s prototype
says it takes size_t arguments, whereas syscall() is a
generic thing which doesn't, and so the C default promotions
do the wrong thing with the abi_ulongs.)

The use of syscall(__NR_mremap, ...) originally dates back to 2008:
https://lists.gnu.org/archive/html/qemu-devel/2008-12/msg01087.html
https://lists.gnu.org/archive/html/qemu-devel/2008-12/msg00480.html

and was to permit compilation with glibc 2.4 which didn't
support the 5-argument mremap() or define MREMAP_FIXED.

Since glibc 2.4 dates back to a decade ago now, we no longer
need to carry this ugly (and buggy) workaround for it.

thanks
-- PMM

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

* Re: [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts
  2016-09-28 23:30 ` Peter Maydell
@ 2016-09-29  2:46   ` Felix Janda
  0 siblings, 0 replies; 5+ messages in thread
From: Felix Janda @ 2016-09-29  2:46 UTC (permalink / raw)
  To: Peter Maydell; +Cc: QEMU Developers, Riku Voipio

Peter Maydell wrote:
> On 17 September 2016 at 18:20, Felix Janda <felix.janda@posteo.de> wrote:
> > Signed-off-by: Felix Janda <felix.janda@posteo.de>
> > ---
> >  linux-user/mmap.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/linux-user/mmap.c b/linux-user/mmap.c
> > index c4371d9..4882816 100644
> > --- a/linux-user/mmap.c
> > +++ b/linux-user/mmap.c
> > @@ -682,7 +682,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
> >
> >      if (flags & MREMAP_FIXED) {
> >          host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > -                                     old_size, new_size,
> > +                                     (size_t) old_size, (size_t) new_size,
> >                                       flags,
> >                                       g2h(new_addr));
> >
> > @@ -701,7 +701,7 @@ abi_long target_mremap(abi_ulong old_addr, abi_ulong old_size,
> >              host_addr = MAP_FAILED;
> >          } else {
> >              host_addr = (void *) syscall(__NR_mremap, g2h(old_addr),
> > -                                         old_size, new_size,
> > +                                         (size_t) old_size, (size_t) new_size,
> >                                           flags | MREMAP_FIXED,
> >                                           g2h(mmap_start));
> >              if (reserved_va) {
> > --
> > 2.7.3
> 
> Rather than this, I think it would be better to switch to
> using the mremap() library call rather than direct syscall
> here, which then matches the other mremap()s later in the
> function. (That will work right because mremap()'s prototype
> says it takes size_t arguments, whereas syscall() is a
> generic thing which doesn't, and so the C default promotions
> do the wrong thing with the abi_ulongs.)
> 
> The use of syscall(__NR_mremap, ...) originally dates back to 2008:
> https://lists.gnu.org/archive/html/qemu-devel/2008-12/msg01087.html
> https://lists.gnu.org/archive/html/qemu-devel/2008-12/msg00480.html
> 
> and was to permit compilation with glibc 2.4 which didn't
> support the 5-argument mremap() or define MREMAP_FIXED.
> 
> Since glibc 2.4 dates back to a decade ago now, we no longer
> need to carry this ugly (and buggy) workaround for it.

This sounds like a good idea. Thanks also for digging up the history.

I will prepare a new patch.

Thanks,
Felix

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

end of thread, other threads:[~2016-09-29  2:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-18  1:20 [Qemu-devel] [PATCH] linux-user: fix mremap for 64bit targets on 32bit hosts Felix Janda
2016-09-22  6:22 ` Riku Voipio
2016-09-23  0:36   ` Felix Janda
2016-09-28 23:30 ` Peter Maydell
2016-09-29  2:46   ` Felix Janda

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.