All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
@ 2021-02-10 10:55 Roman Bolshakov
  2021-03-08  6:47 ` Joelle van Dyne
  2021-03-09 14:03 ` Richard Henderson
  0 siblings, 2 replies; 5+ messages in thread
From: Roman Bolshakov @ 2021-02-10 10:55 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Maydell, Roman Bolshakov

There's a change in mprotect() behaviour [1] in the latest macOS on M1
and it's not yet clear if it's going to be fixed by Apple. For now we
can avoid unsupported mprotect() calls. QEMU and qtests work fine
without it.

1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
Apple-Feedback: FB8994773
Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
---
 util/osdep.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/util/osdep.c b/util/osdep.c
index 66d01b9160..1edd7b1caf 100644
--- a/util/osdep.c
+++ b/util/osdep.c
@@ -111,6 +111,12 @@ int qemu_mprotect_none(void *addr, size_t size)
 #ifdef _WIN32
     return qemu_mprotect__osdep(addr, size, PAGE_NOACCESS);
 #else
+# if defined(__APPLE__) && defined(__arm64__)
+    if (__builtin_available(macOS 11.2, *)) {
+        /* mprotect() in macOS 11.2 can't switch RWX to NONE */
+        return 0;
+    }
+# endif
     return qemu_mprotect__osdep(addr, size, PROT_NONE);
 #endif
 }
-- 
2.30.0



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

* Re: [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
  2021-02-10 10:55 [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2 Roman Bolshakov
@ 2021-03-08  6:47 ` Joelle van Dyne
  2021-03-09 13:31   ` Roman Bolshakov
  2021-03-09 14:03 ` Richard Henderson
  1 sibling, 1 reply; 5+ messages in thread
From: Joelle van Dyne @ 2021-03-08  6:47 UTC (permalink / raw)
  To: Roman Bolshakov; +Cc: Peter Maydell, QEMU Developers

On Wed, Feb 10, 2021 at 2:55 AM Roman Bolshakov <r.bolshakov@yadro.com> wrote:
>
> There's a change in mprotect() behaviour [1] in the latest macOS on M1
> and it's not yet clear if it's going to be fixed by Apple. For now we
> can avoid unsupported mprotect() calls. QEMU and qtests work fine
> without it.
>
> 1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f
>
> Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
> Apple-Feedback: FB8994773
> Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>

Reviewed-by: Joelle van Dyne <j@getutm.app>

FYI the "macOS 11.2, *" means it applies to all versions of iOS. I
think it only broke in iOS 14.2 but making it return on other versions
seems to be fine from my tests.

-j


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

* Re: [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
  2021-03-08  6:47 ` Joelle van Dyne
@ 2021-03-09 13:31   ` Roman Bolshakov
  2021-03-09 18:06     ` Joelle van Dyne
  0 siblings, 1 reply; 5+ messages in thread
From: Roman Bolshakov @ 2021-03-09 13:31 UTC (permalink / raw)
  To: Joelle van Dyne; +Cc: Peter Maydell, Richard Henderson, QEMU Developers

On Sun, Mar 07, 2021 at 10:47:06PM -0800, Joelle van Dyne wrote:
> On Wed, Feb 10, 2021 at 2:55 AM Roman Bolshakov <r.bolshakov@yadro.com> wrote:
> >
> > There's a change in mprotect() behaviour [1] in the latest macOS on M1
> > and it's not yet clear if it's going to be fixed by Apple. For now we
> > can avoid unsupported mprotect() calls. QEMU and qtests work fine
> > without it.
> >
> > 1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f
> >
> > Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
> > Apple-Feedback: FB8994773
> > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> 
> Reviewed-by: Joelle van Dyne <j@getutm.app>
> 

Thanks!

> FYI the "macOS 11.2, *" means it applies to all versions of iOS. I
> think it only broke in iOS 14.2 but making it return on other versions
> seems to be fine from my tests.
> 

Hm... do you know how to say "for macOS 11.2 and above only"?

Regards,
Roman


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

* Re: [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
  2021-02-10 10:55 [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2 Roman Bolshakov
  2021-03-08  6:47 ` Joelle van Dyne
@ 2021-03-09 14:03 ` Richard Henderson
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Henderson @ 2021-03-09 14:03 UTC (permalink / raw)
  To: Roman Bolshakov, qemu-devel; +Cc: Peter Maydell

On 2/10/21 2:55 AM, Roman Bolshakov wrote:
> There's a change in mprotect() behaviour [1] in the latest macOS on M1
> and it's not yet clear if it's going to be fixed by Apple. For now we
> can avoid unsupported mprotect() calls. QEMU and qtests work fine
> without it.
> 
> 1.https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

This is an unfortunate OS bug.

But I can use this as an opportunity to tidy up some memory management, and in 
the process go from NONE -> {RX,RW} instead.


r~


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

* Re: [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2
  2021-03-09 13:31   ` Roman Bolshakov
@ 2021-03-09 18:06     ` Joelle van Dyne
  0 siblings, 0 replies; 5+ messages in thread
From: Joelle van Dyne @ 2021-03-09 18:06 UTC (permalink / raw)
  To: Roman Bolshakov
  Cc: Peter Maydell, Richard Henderson, Joelle van Dyne, QEMU Developers

On Tue, Mar 9, 2021 at 5:31 AM Roman Bolshakov <r.bolshakov@yadro.com> wrote:
>
> On Sun, Mar 07, 2021 at 10:47:06PM -0800, Joelle van Dyne wrote:
> > On Wed, Feb 10, 2021 at 2:55 AM Roman Bolshakov <r.bolshakov@yadro.com> wrote:
> > >
> > > There's a change in mprotect() behaviour [1] in the latest macOS on M1
> > > and it's not yet clear if it's going to be fixed by Apple. For now we
> > > can avoid unsupported mprotect() calls. QEMU and qtests work fine
> > > without it.
> > >
> > > 1. https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f
> > >
> > > Buglink: https://bugs.launchpad.net/qemu/+bug/1914849
> > > Apple-Feedback: FB8994773
> > > Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
> >
> > Reviewed-by: Joelle van Dyne <j@getutm.app>
> >
>
> Thanks!
>
> > FYI the "macOS 11.2, *" means it applies to all versions of iOS. I
> > think it only broke in iOS 14.2 but making it return on other versions
> > seems to be fine from my tests.
> >
>
> Hm... do you know how to say "for macOS 11.2 and above only"?
>
> Regards,
> Roman

What you have is fine for "macOS 11.2 and above" but the "*" means "OR
any version of any platform not macOS". If you have
"__builtin_available(macOS 11.2, iOS 14.4, *)" would mean macOS 11.2
and above OR iOS 14.4 and above (which is the release aligned with
macOS 11.2, not iOS 14.2 as I originally mistyped) OR any version of
any platform not macOS. However, I think it's fine here as making this
change doesn't break anything on older versions of iOS (or macOS as
well). Btw, there's also tvOS and watchOS which I'm not sure if this
bug applies (I assume yes) but QEMU doesn't run on those platforms
(yet).

-j


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

end of thread, other threads:[~2021-03-09 19:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 10:55 [PATCH] util/osdep: Avoid mprotect() RWX->NONE on Big Sur 11.2 Roman Bolshakov
2021-03-08  6:47 ` Joelle van Dyne
2021-03-09 13:31   ` Roman Bolshakov
2021-03-09 18:06     ` Joelle van Dyne
2021-03-09 14:03 ` Richard Henderson

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.