Skip to contentSkip to conversation

host: Support macOS 12

PATCH In review Philippe Mathieu-Daudé 9 participants 48 messages Mar 6, 2022 – May 9, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v7 cover host: Support macOS 12

From: Philippe Mathieu-Daudé <[email protected]>

Few patches to be able to build QEMU on macOS 12 (Monterey).

Missing review:
0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0013-osdep-Avoid-using-Clang-specific-__builtin_available.patch 0014-meson-Resolve-the-entitlement.sh-script-once-for-goo.patch 0015-meson-Log-QEMU_CXXFLAGS-content-in-summary.patch 0016-configure-Pass-filtered-QEMU_OBJCFLAGS-to-meson.patch 0017-ui-cocoa-Constify-qkeycode-translation-arrays.patch 0020-ui-cocoa-capture-all-keys-and-combos-when-mouse-is-g.patch 0021-ui-cocoa-add-option-to-swap-Option-and-Command.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Since v6:
- Dropped merged patches
- Addressed Akihiko Odaki comments (squashed 2 patches, added R/T-b)
- Dropped 'configure: Disable out-of-line atomic operations on Aarch64'
- Add few macos patches on the list pending for 7.0 so tested by CI

Since v5:
- Fixed failed rebase between patches 10 and 16 (Akihiko)
- Include "ui/cocoa: Fix the leak of qemu_console_get_label"

Since v4:
- Use MAC_OS_X_VERSION_MIN_REQUIRED definition (Akihiko)
- Include patches from Akihiko

Since v3:
- Fix --enable-modules
- Ignore #pragma on softfloat3 tests
- Addressed Akihiko Odaki comments
- Include Cameron Esfahani patches

Since v2:
- Addressed Akihiko Odaki comments:
. use __is_identifier(),
. remove cocoa setAllowedFileTypes()
- Addressed Daniel Berrangé comment:
. rebased on testing/next, update libvirt-ci/lcitool

Akihiko Odaki (2):
audio: Log context for audio bug
coreaudio: Always return 0 in handle_voice_change

Cameron Esfahani (2):
hvf: Use standard CR0 and CR4 register definitions
hvf: Fix OOB write in RDTSCP instruction decode

Carwyn Ellis (2):
ui/cocoa: add option to disable left-command forwarding to guest ui/cocoa: release mouse when user switches away from QEMU window

Gustavo Noronha Silva (2):
ui/cocoa: capture all keys and combos when mouse is grabbed ui/cocoa: add option to swap Option and Command

Philippe Mathieu-Daudé (14):
configure: Allow passing extra Objective C compiler flags tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives
hvf: Make hvf_get_segments() / hvf_put_segments() local
hvf: Remove deprecated hv_vcpu_flush() calls block/file-posix: Remove a deprecation warning on macOS 12 audio/coreaudio: Remove a deprecation warning on macOS 12 audio/dbus: Fix building with modules on macOS
audio: Rename coreaudio extension to use Objective-C compiler
osdep: Avoid using Clang-specific __builtin_available()
meson: Resolve the entitlement.sh script once for good
meson: Log QEMU_CXXFLAGS content in summary
configure: Pass filtered QEMU_OBJCFLAGS to meson ui/cocoa: Constify qkeycode translation arrays
gitlab-ci: Support macOS 12 via cirrus-run

 .gitlab-ci.d/cirrus.yml            |  16 ++++
 .gitlab-ci.d/cirrus/macos-12.vars  |  16 ++++
 audio/audio.c                      |  25 +++---
 audio/audio_template.h             |  27 +++----
 audio/{coreaudio.c => coreaudio.m} |  23 +++---
 audio/meson.build                  |   4 +-
 block/file-posix.c                 |  14 +++-
 configure                          |  31 ++++++++
 include/qemu/osdep.h               |  10 +--
 meson.build                        |  17 +++-
 qapi/ui.json                       |  29 +++++++
 qemu-options.hx                    |  15 ++++
 target/i386/hvf/vmx.h              |  19 +++--
 target/i386/hvf/x86.c              |   6 +-
 target/i386/hvf/x86.h              |  34 --------
 target/i386/hvf/x86_decode.c       |  12 ++-
 target/i386/hvf/x86_mmu.c          |   2 +-
 target/i386/hvf/x86_task.c         |   4 +-
 target/i386/hvf/x86hvf.c           |  14 +++-
 target/i386/hvf/x86hvf.h           |   3 +-
 tests/fp/meson.build               |   5 ++
 tests/lcitool/refresh              |   1 +
 ui/cocoa.m                         | 122 ++++++++++++++++++++++++++---
 23 files changed, 327 insertions(+), 122 deletions(-)
 create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars
 rename audio/{coreaudio.c => coreaudio.m} (97%)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v7 1/22 configure: Allow passing extra Objective C compiler flags

From: Philippe Mathieu-Daudé <[email protected]>

We can pass C/CPP/LD flags via CFLAGS/CXXFLAGS/LDFLAGS environment variables, or via configure --extra-cflags / --extra-cxxflags / --extra-ldflags options. Provide similar behavior for Objective C:
use existing flags from $OBJCFLAGS, or passed via --extra-objcflags.

---
 configure   | 8 ++++++++
 meson.build | 5 +++++
 2 files changed, 13 insertions(+)
configure +8 -0
index 81618708e4..e60156f90f 100755
@@ -285,6 +285,7 @@ done
 
 EXTRA_CFLAGS=""
 EXTRA_CXXFLAGS=""
+EXTRA_OBJCFLAGS=""
 EXTRA_LDFLAGS=""
 
 xen_ctrl_version="$default_feature"
@@ -366,9 +367,12 @@ for opt do
   --extra-cflags=*)
     EXTRA_CFLAGS="$EXTRA_CFLAGS $optarg"
     EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
+    EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
     ;;
   --extra-cxxflags=*) EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $optarg"
   ;;
+  --extra-objcflags=*) EXTRA_OBJCFLAGS="$EXTRA_OBJCFLAGS $optarg"
+  ;;
   --extra-ldflags=*) EXTRA_LDFLAGS="$EXTRA_LDFLAGS $optarg"
   ;;
   --enable-debug-info) debug_info="yes"
@@ -748,6 +752,8 @@ for opt do
   ;;
   --extra-cxxflags=*)
   ;;
+  --extra-objcflags=*)
+  ;;
   --extra-ldflags=*)
   ;;
   --enable-debug-info)
@@ -1172,6 +1178,7 @@ Advanced options (experts only):
   --objcc=OBJCC            use Objective-C compiler OBJCC [$objcc]
   --extra-cflags=CFLAGS    append extra C compiler flags CFLAGS
   --extra-cxxflags=CXXFLAGS append extra C++ compiler flags CXXFLAGS
+  --extra-objcflags=OBJCFLAGS append extra Objective C compiler flags OBJCFLAGS
   --extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
   --cross-cc-ARCH=CC       use compiler when building ARCH guest test cases
   --cross-cc-cflags-ARCH=  use compiler flags when building ARCH guest tests
@@ -3137,6 +3144,7 @@ if test "$skip_meson" = no; then
   echo "[built-in options]" >> $cross
   echo "c_args = [$(meson_quote $CFLAGS $EXTRA_CFLAGS)]" >> $cross
   echo "cpp_args = [$(meson_quote $CXXFLAGS $EXTRA_CXXFLAGS)]" >> $cross
+  test -n "$objcc" && echo "objc_args = [$(meson_quote $OBJCFLAGS $EXTRA_OBJCFLAGS)]" >> $cross
   echo "c_link_args = [$(meson_quote $CFLAGS $LDFLAGS $EXTRA_CFLAGS $EXTRA_LDFLAGS)]" >> $cross
   echo "cpp_link_args = [$(meson_quote $CXXFLAGS $LDFLAGS $EXTRA_CXXFLAGS $EXTRA_LDFLAGS)]" >> $cross
   echo "[binaries]" >> $cross
meson.build +5 -0
index 038502714a..b6e30d7463 100644
@@ -3457,6 +3457,11 @@ if link_language == 'cpp'
                                                + ['-O' + get_option('optimization')]
                                                + (get_option('debug') ? ['-g'] : []))}
 endif
+if targetos == 'darwin'
+  summary_info += {'OBJCFLAGS':       ' '.join(get_option('objc_args')
+                                               + ['-O' + get_option('optimization')]
+                                               + (get_option('debug') ? ['-g'] : []))}
+endif
 link_args = get_option(link_language + '_link_args')
 if link_args.length() > 0
   summary_info += {'LDFLAGS':         ' '.join(link_args)}
Signature · 1 line
2.34.1
#2 lore raw

PATCH v7 2/22 tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Since we already use -Wno-unknown-pragmas, we can also use -Wno-ignored-pragmas. This silences hundred of warnings using clang 13 on macOS Monterey:

[409/771] Compiling C object tests/fp/libtestfloat.a.p/berkeley-testfloat-3_source_test_az_f128_rx.c.o ../tests/fp/berkeley-testfloat-3/source/test_az_f128_rx.c:49:14: warning: '#pragma FENV_ACCESS' is not supported on this target - ignored [-Wignored-pragmas] #pragma STDC FENV_ACCESS ON

               ^

1 warning generated.

Having:

  $ cc -v
  Apple clang version 13.0.0 (clang-1300.0.29.30)
---
 tests/fp/meson.build | 5 +++++
 1 file changed, 5 insertions(+)
tests/fp/meson.build +5 -0
index 59776a00a7..8bd0979f67 100644
@@ -37,6 +37,11 @@ tfcflags = [
   '-Wno-error',
 ]
 
+if cc.get_id() == 'clang'
+  # Clang does not support '#pragma STDC FENV_ACCESS'
+  tfcflags += [ '-Wno-ignored-pragmas' ]
+endif
+
 tfgencases = [
   tfdir / 'genCases_ui32.c',
   tfdir / 'genCases_ui64.c',
Signature · 1 line
2.34.1
#4 lore raw

PATCH v7 3/22 hvf: Use standard CR0 and CR4 register definitions

In reply to Philippe Mathieu-Daudé

From: Cameron Esfahani <[email protected]>

No need to have our own definitions of these registers.

---
 target/i386/hvf/vmx.h      | 17 +++++++++--------
 target/i386/hvf/x86.c      |  6 +++---
 target/i386/hvf/x86.h      | 34 ----------------------------------
 target/i386/hvf/x86_mmu.c  |  2 +-
 target/i386/hvf/x86_task.c |  3 ++-
 5 files changed, 15 insertions(+), 47 deletions(-)
target/i386/hvf/vmx.h +9 -8
index 6df87116f6..29b7deed3c 100644
@@ -124,10 +124,11 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     uint64_t efer = rvmcs(vcpu, VMCS_GUEST_IA32_EFER);
     uint64_t old_cr0 = rvmcs(vcpu, VMCS_GUEST_CR0);
     uint64_t changed_cr0 = old_cr0 ^ cr0;
-    uint64_t mask = CR0_PG | CR0_CD | CR0_NW | CR0_NE | CR0_ET;
+    uint64_t mask = CR0_PG_MASK | CR0_CD_MASK | CR0_NW_MASK |
+                    CR0_NE_MASK | CR0_ET_MASK;
     uint64_t entry_ctls;
 
-    if ((cr0 & CR0_PG) && (rvmcs(vcpu, VMCS_GUEST_CR4) & CR4_PAE) &&
+    if ((cr0 & CR0_PG_MASK) && (rvmcs(vcpu, VMCS_GUEST_CR4) & CR4_PAE_MASK) &&
         !(efer & MSR_EFER_LME)) {
         address_space_read(&address_space_memory,
                            rvmcs(vcpu, VMCS_GUEST_CR3) & ~0x1f,
@@ -142,8 +143,8 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     wvmcs(vcpu, VMCS_CR0_SHADOW, cr0);
 
     if (efer & MSR_EFER_LME) {
-        if (changed_cr0 & CR0_PG) {
-            if (cr0 & CR0_PG) {
+        if (changed_cr0 & CR0_PG_MASK) {
+            if (cr0 & CR0_PG_MASK) {
                 enter_long_mode(vcpu, cr0, efer);
             } else {
                 exit_long_mode(vcpu, cr0, efer);
@@ -155,8 +156,8 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     }
 
     /* Filter new CR0 after we are finished examining it above. */
-    cr0 = (cr0 & ~(mask & ~CR0_PG));
-    wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE | CR0_ET);
+    cr0 = (cr0 & ~(mask & ~CR0_PG_MASK));
+    wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE_MASK | CR0_ET_MASK);
 
     hv_vcpu_invalidate_tlb(vcpu);
     hv_vcpu_flush(vcpu);
@@ -164,11 +165,11 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
 
 static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)
 {
-    uint64_t guest_cr4 = cr4 | CR4_VMXE;
+    uint64_t guest_cr4 = cr4 | CR4_VMXE_MASK;
 
     wvmcs(vcpu, VMCS_GUEST_CR4, guest_cr4);
     wvmcs(vcpu, VMCS_CR4_SHADOW, cr4);
-    wvmcs(vcpu, VMCS_CR4_MASK, CR4_VMXE);
+    wvmcs(vcpu, VMCS_CR4_MASK, CR4_VMXE_MASK);
 
     hv_vcpu_invalidate_tlb(vcpu);
     hv_vcpu_flush(vcpu);
target/i386/hvf/x86.c +3 -3
index 2898bb70a8..91a3fe002c 100644
@@ -119,7 +119,7 @@ bool x86_read_call_gate(struct CPUState *cpu, struct x86_call_gate *idt_desc,
 bool x86_is_protected(struct CPUState *cpu)
 {
     uint64_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
-    return cr0 & CR0_PE;
+    return cr0 & CR0_PE_MASK;
 }
 
 bool x86_is_real(struct CPUState *cpu)
@@ -150,13 +150,13 @@ bool x86_is_long64_mode(struct CPUState *cpu)
 bool x86_is_paging_mode(struct CPUState *cpu)
 {
     uint64_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
-    return cr0 & CR0_PG;
+    return cr0 & CR0_PG_MASK;
 }
 
 bool x86_is_pae_enabled(struct CPUState *cpu)
 {
     uint64_t cr4 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR4);
-    return cr4 & CR4_PAE;
+    return cr4 & CR4_PAE_MASK;
 }
 
 target_ulong linear_addr(struct CPUState *cpu, target_ulong addr, X86Seg seg)
target/i386/hvf/x86.h +0 -34
index 782664c2ea..947b98da41 100644
@@ -42,40 +42,6 @@ typedef struct x86_register {
     };
 } __attribute__ ((__packed__)) x86_register;
 
-typedef enum x86_reg_cr0 {
-    CR0_PE =            (1L << 0),
-    CR0_MP =            (1L << 1),
-    CR0_EM =            (1L << 2),
-    CR0_TS =            (1L << 3),
-    CR0_ET =            (1L << 4),
-    CR0_NE =            (1L << 5),
-    CR0_WP =            (1L << 16),
-    CR0_AM =            (1L << 18),
-    CR0_NW =            (1L << 29),
-    CR0_CD =            (1L << 30),
-    CR0_PG =            (1L << 31),
-} x86_reg_cr0;
-
-typedef enum x86_reg_cr4 {
-    CR4_VME =            (1L << 0),
-    CR4_PVI =            (1L << 1),
-    CR4_TSD =            (1L << 2),
-    CR4_DE  =            (1L << 3),
-    CR4_PSE =            (1L << 4),
-    CR4_PAE =            (1L << 5),
-    CR4_MSE =            (1L << 6),
-    CR4_PGE =            (1L << 7),
-    CR4_PCE =            (1L << 8),
-    CR4_OSFXSR =         (1L << 9),
-    CR4_OSXMMEXCPT =     (1L << 10),
-    CR4_VMXE =           (1L << 13),
-    CR4_SMXE =           (1L << 14),
-    CR4_FSGSBASE =       (1L << 16),
-    CR4_PCIDE =          (1L << 17),
-    CR4_OSXSAVE =        (1L << 18),
-    CR4_SMEP =           (1L << 20),
-} x86_reg_cr4;
-
 /* 16 bit Task State Segment */
 typedef struct x86_tss_segment16 {
     uint16_t link;
target/i386/hvf/x86_mmu.c +1 -1
index e9ed0f5aa1..df0b91cd42 100644
@@ -129,7 +129,7 @@ static bool test_pt_entry(struct CPUState *cpu, struct gpt_translation *pt,
 
     uint32_t cr0 = rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0);
     /* check protection */
-    if (cr0 & CR0_WP) {
+    if (cr0 & CR0_WP_MASK) {
         if (pt->write_access && !pte_write_access(pte)) {
             return false;
         }
target/i386/hvf/x86_task.c +2 -1
index 422156128b..e1301599e9 100644
@@ -174,7 +174,8 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea
         //ret = task_switch_16(cpu, tss_sel, old_tss_sel, old_tss_base, &next_tss_desc);
         VM_PANIC("task_switch_16");
 
-    macvm_set_cr0(cpu->hvf->fd, rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0) | CR0_TS);
+    macvm_set_cr0(cpu->hvf->fd, rvmcs(cpu->hvf->fd, VMCS_GUEST_CR0) |
+                                CR0_TS_MASK);
     x86_segment_descriptor_to_vmx(cpu, tss_sel, &next_tss_desc, &vmx_seg);
     vmx_write_segment_descriptor(cpu, &vmx_seg, R_TR);
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH v7 4/22 hvf: Make hvf_get_segments() / hvf_put_segments() local

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Both hvf_get_segments/hvf_put_segments() functions are only used within x86hvf.c: do not declare them as public API.

---
 target/i386/hvf/x86hvf.c | 4 ++--
 target/i386/hvf/x86hvf.h | 2 --
 2 files changed, 2 insertions(+), 4 deletions(-)
target/i386/hvf/x86hvf.c +2 -2
index 05ec1bddc4..907f09f1b4 100644
@@ -83,7 +83,7 @@ void hvf_put_xsave(CPUState *cpu_state)
     }
 }
 
-void hvf_put_segments(CPUState *cpu_state)
+static void hvf_put_segments(CPUState *cpu_state)
 {
     CPUX86State *env = &X86_CPU(cpu_state)->env;
     struct vmx_segment seg;
@@ -166,7 +166,7 @@ void hvf_get_xsave(CPUState *cpu_state)
     x86_cpu_xrstor_all_areas(X86_CPU(cpu_state), xsave, xsave_len);
 }
 
-void hvf_get_segments(CPUState *cpu_state)
+static void hvf_get_segments(CPUState *cpu_state)
 {
     CPUX86State *env = &X86_CPU(cpu_state)->env;
 
target/i386/hvf/x86hvf.h +0 -2
index 99ed8d608d..db6003d6bd 100644
@@ -26,11 +26,9 @@ void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
                      SegmentCache *qseg, bool is_tr);
 void hvf_get_segment(SegmentCache *qseg, struct vmx_segment *vmx_seg);
 void hvf_put_xsave(CPUState *cpu_state);
-void hvf_put_segments(CPUState *cpu_state);
 void hvf_put_msrs(CPUState *cpu_state);
 void hvf_get_xsave(CPUState *cpu_state);
 void hvf_get_msrs(CPUState *cpu_state);
 void vmx_clear_int_window_exiting(CPUState *cpu);
-void hvf_get_segments(CPUState *cpu_state);
 void vmx_update_tpr(CPUState *cpu);
 #endif
Signature · 1 line
2.34.1
#6 lore raw

PATCH v7 5/22 hvf: Remove deprecated hv_vcpu_flush() calls

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

When building on macOS 11 [*], we get:

In file included from ../target/i386/hvf/hvf.c:59:
../target/i386/hvf/vmx.h:174:5: error: 'hv_vcpu_flush' is deprecated: first deprecated in macOS 11.0 - This API has no effect and always returns HV_UNSUPPORTED [-Werror,-Wdeprecated-declarations]

      hv_vcpu_flush(vcpu);
      ^
  /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Hypervisor.framework/Headers/hv.h:364:20: note: 'hv_vcpu_flush' has been explicitly marked deprecated here
  extern hv_return_t hv_vcpu_flush(hv_vcpuid_t vcpu)
                     ^

Since this call "has no effect", simply remove it ¯\_(ツ)_/¯

Not very useful deprecation doc:
https://developer.apple.com/documentation/hypervisor/1441386-hv_vcpu_flush

[*] Also 10.15 (Catalina):
https://lore.kernel.org/qemu-devel/[email protected]/

---
 target/i386/hvf/vmx.h      | 2 --
 target/i386/hvf/x86_task.c | 1 -
 target/i386/hvf/x86hvf.c   | 2 --
 3 files changed, 5 deletions(-)
target/i386/hvf/vmx.h +0 -2
index 29b7deed3c..573ddc33c0 100644
@@ -160,7 +160,6 @@ static inline void macvm_set_cr0(hv_vcpuid_t vcpu, uint64_t cr0)
     wvmcs(vcpu, VMCS_GUEST_CR0, cr0 | CR0_NE_MASK | CR0_ET_MASK);
 
     hv_vcpu_invalidate_tlb(vcpu);
-    hv_vcpu_flush(vcpu);
 }
 
 static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)
@@ -172,7 +171,6 @@ static inline void macvm_set_cr4(hv_vcpuid_t vcpu, uint64_t cr4)
     wvmcs(vcpu, VMCS_CR4_MASK, CR4_VMXE_MASK);
 
     hv_vcpu_invalidate_tlb(vcpu);
-    hv_vcpu_flush(vcpu);
 }
 
 static inline void macvm_set_rip(CPUState *cpu, uint64_t rip)
target/i386/hvf/x86_task.c +0 -1
index e1301599e9..d24daf6a41 100644
@@ -182,5 +182,4 @@ void vmx_handle_task_switch(CPUState *cpu, x68_segment_selector tss_sel, int rea
     store_regs(cpu);
 
     hv_vcpu_invalidate_tlb(cpu->hvf->fd);
-    hv_vcpu_flush(cpu->hvf->fd);
 }
target/i386/hvf/x86hvf.c +0 -2
index 907f09f1b4..bec9fc5814 100644
@@ -125,8 +125,6 @@ static void hvf_put_segments(CPUState *cpu_state)
 
     hvf_set_segment(cpu_state, &seg, &env->ldt, false);
     vmx_write_segment_descriptor(cpu_state, &seg, R_LDTR);
-    
-    hv_vcpu_flush(cpu_state->hvf->fd);
 }
     
 void hvf_put_msrs(CPUState *cpu_state)
Signature · 1 line
2.34.1
#7 lore raw

PATCH v7 6/22 hvf: Fix OOB write in RDTSCP instruction decode

In reply to Philippe Mathieu-Daudé

From: Cameron Esfahani <[email protected]>

A guest could craft a specific stream of instructions that will have QEMU write 0xF9 to inappropriate locations in memory. Add additional asserts to check for this. Generate a #UD if there are more than 14 prefix bytes.

Found by Julian Stecklina <[email protected]>

Message-Id: <[email protected]>

---
 target/i386/hvf/x86_decode.c | 12 ++++++++++--
 target/i386/hvf/x86hvf.c     |  8 ++++++++
 target/i386/hvf/x86hvf.h     |  1 +
 3 files changed, 19 insertions(+), 2 deletions(-)
target/i386/hvf/x86_decode.c +10 -2
index 062713b1a4..5d051252b4 100644
@@ -24,8 +24,10 @@
 #include "vmx.h"
 #include "x86_mmu.h"
 #include "x86_descr.h"
+#include "x86hvf.h"
 
 #define OPCODE_ESCAPE   0xf
+#define X86_MAX_INSN_PREFIX_LENGTH (14)
 
 static void decode_invalid(CPUX86State *env, struct x86_decode *decode)
 {
@@ -541,7 +543,8 @@ static void decode_lidtgroup(CPUX86State *env, struct x86_decode *decode)
     };
     decode->cmd = group[decode->modrm.reg];
     if (0xf9 == decode->modrm.modrm) {
-        decode->opcode[decode->len++] = decode->modrm.modrm;
+        VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
+        decode->opcode[decode->opcode_len++] = decode->modrm.modrm;
         decode->cmd = X86_DECODE_CMD_RDTSCP;
     }
 }
@@ -1847,7 +1850,8 @@ void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode,
 
 static void decode_prefix(CPUX86State *env, struct x86_decode *decode)
 {
-    while (1) {
+    /* At most X86_MAX_INSN_PREFIX_LENGTH prefix bytes. */
+    for (int i = 0; i < X86_MAX_INSN_PREFIX_LENGTH; i++) {
         /*
          * REX prefix must come after legacy prefixes.
          * REX before legacy is ignored.
@@ -1892,6 +1896,8 @@ static void decode_prefix(CPUX86State *env, struct x86_decode *decode)
             return;
         }
     }
+    /* Too many prefixes!  Generate #UD. */
+    hvf_inject_ud(env);
 }
 
 void set_addressing_size(CPUX86State *env, struct x86_decode *decode)
@@ -2090,11 +2096,13 @@ static void decode_opcodes(CPUX86State *env, struct x86_decode *decode)
     uint8_t opcode;
 
     opcode = decode_byte(env, decode);
+    VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
     decode->opcode[decode->opcode_len++] = opcode;
     if (opcode != OPCODE_ESCAPE) {
         decode_opcode_1(env, decode, opcode);
     } else {
         opcode = decode_byte(env, decode);
+        VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
         decode->opcode[decode->opcode_len++] = opcode;
         decode_opcode_2(env, decode, opcode);
     }
target/i386/hvf/x86hvf.c +8 -0
index bec9fc5814..a338c207b7 100644
@@ -423,6 +423,14 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
             & (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR));
 }
 
+void hvf_inject_ud(CPUX86State *env)
+{
+    env->exception_nr = EXCP06_ILLOP;
+    env->exception_injected = 1;
+    env->has_error_code = false;
+    env->error_code = 0;
+}
+
 int hvf_process_events(CPUState *cpu_state)
 {
     X86CPU *cpu = X86_CPU(cpu_state);
target/i386/hvf/x86hvf.h +1 -0
index db6003d6bd..427cdc1c13 100644
@@ -22,6 +22,7 @@
 
 int hvf_process_events(CPUState *);
 bool hvf_inject_interrupts(CPUState *);
+void hvf_inject_ud(CPUX86State *);
 void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
                      SegmentCache *qseg, bool is_tr);
 void hvf_get_segment(SegmentCache *qseg, struct vmx_segment *vmx_seg);
Signature · 1 line
2.34.1
#27 lore raw

PATCH v7 18/22 ui/cocoa: add option to disable left-command forwarding to guest

In reply to Philippe Mathieu-Daudé

From: Carwyn Ellis <[email protected]>

When switching between guest and host on a Mac using command-tab the command key is sent to the guest which can trigger functionality in the guest OS. Specifying left-command-key=off disables forwarding this key to the guest. Defaults to enabled.

Also updated the cocoa display documentation to reference the new left-command-key option along with the existing show-cursor option.

[PMD: Set QAPI structure @since tag to 7.0]
---
 qapi/ui.json    | 18 ++++++++++++++++++
 qemu-options.hx | 12 ++++++++++++
 ui/cocoa.m      |  8 +++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)
qapi/ui.json +18 -0
index 4a13f883a3..4dea35a819 100644
@@ -1260,6 +1260,23 @@
 { 'struct'  : 'DisplayCurses',
   'data'    : { '*charset'       : 'str' } }
 
+##
+# @DisplayCocoa:
+#
+# Cocoa display options.
+#
+# @left-command-key: Enable/disable forwarding of left command key to
+#                    guest. Allows command-tab window switching on the
+#                    host without sending this key to the guest when
+#                    "off". Defaults to "on"
+#
+# Since: 7.0
+##
+{ 'struct': 'DisplayCocoa',
+  'data': {
+      '*left-command-key': 'bool'
+  } }
+
 ##
 # @DisplayType:
 #
@@ -1338,6 +1355,7 @@
   'discriminator' : 'type',
   'data'    : {
       'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' },
+      'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' },
       'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' },
       'egl-headless': { 'type': 'DisplayEGLHeadless',
                         'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } },
qemu-options.hx +12 -0
index 094a6c1d7c..ffaeab61ed 100644
@@ -1922,6 +1922,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_DBUS_DISPLAY)
     "-display dbus[,addr=<dbusaddr>]\n"
     "             [,gl=on|core|es|off][,rendernode=<file>]\n"
+#endif
+#if defined(CONFIG_COCOA)
+    "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n"
 #endif
     "-display none\n"
     "                select display backend type\n"
@@ -2009,6 +2012,15 @@ SRST
         ``charset=CP850`` for IBM CP850 encoding. The default is
         ``CP437``.
 
+    ``cocoa``
+        Display video output in a Cocoa window. Mac only. This interface
+        provides drop-down menus and other UI elements to configure and
+        control the VM during runtime. Valid parameters are:
+
+        ``show-cursor=on|off`` :  Force showing the mouse cursor
+
+        ``left-command-key=on|off`` : Disable forwarding left command key to host
+
     ``egl-headless[,rendernode=<file>]``
         Offload all OpenGL operations to a local DRI device. For any
         graphical display, this display needs to be paired with either
ui/cocoa.m +7 -1
index a6db8ebfb6..319af5045b 100644
@@ -95,6 +95,7 @@ static DisplayChangeListener dcl = {
 };
 static int last_buttons;
 static int cursor_hide = 1;
+static int left_command_key_enabled = 1;
 
 static int gArgc;
 static char **gArgv;
@@ -853,7 +854,8 @@ QemuCocoaView *cocoaView;
                 /* Don't pass command key changes to guest unless mouse is grabbed */
                 case kVK_Command:
                     if (isMouseGrabbed &&
-                        !!(modifiers & NSEventModifierFlagCommand)) {
+                        !!(modifiers & NSEventModifierFlagCommand) &&
+                        left_command_key_enabled) {
                         [self toggleKey:Q_KEY_CODE_META_L];
                     }
                     break;
@@ -2068,6 +2070,10 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
         cursor_hide = 0;
     }
 
+    if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) {
+        left_command_key_enabled = 0;
+    }
+
     // register vga output callbacks
     register_displaychangelistener(&dcl);
 
Signature · 1 line
2.34.1
#11 lore raw

PATCH v7 7/22 block/file-posix: Remove a deprecation warning on macOS 12

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

When building on macOS 12 we get:

block/file-posix.c:3335:18: warning: 'IOMasterPort' is deprecated: first deprecated in macOS 12.0 [-Wdeprecated-declarations]

      kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort );
                   ^~~~~~~~~~~~
                   IOMainPort

Replace by IOMainPort, redefining it to IOMasterPort if not available.

Reviewed by: Cameron Esfahani <[email protected]>

---
 block/file-posix.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
block/file-posix.c +10 -4
index 1f1756e192..13393ad296 100644
@@ -3319,17 +3319,23 @@ BlockDriver bdrv_file = {
 #if defined(__APPLE__) && defined(__MACH__)
 static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
                                 CFIndex maxPathSize, int flags);
+
+#if !defined(MAC_OS_VERSION_12_0) \
+    || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_12_0)
+#define IOMainPort IOMasterPort
+#endif
+
 static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator)
 {
     kern_return_t kernResult = KERN_FAILURE;
-    mach_port_t     masterPort;
+    mach_port_t mainPort;
     CFMutableDictionaryRef  classesToMatch;
     const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass};
     char *mediaType = NULL;
 
-    kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort );
+    kernResult = IOMainPort(MACH_PORT_NULL, &mainPort);
     if ( KERN_SUCCESS != kernResult ) {
-        printf( "IOMasterPort returned %d\n", kernResult );
+        printf("IOMainPort returned %d\n", kernResult);
     }
 
     int index;
@@ -3342,7 +3348,7 @@ static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator)
         }
         CFDictionarySetValue(classesToMatch, CFSTR(kIOMediaEjectableKey),
                              kCFBooleanTrue);
-        kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch,
+        kernResult = IOServiceGetMatchingServices(mainPort, classesToMatch,
                                                   mediaIterator);
         if (kernResult != KERN_SUCCESS) {
             error_report("Note: IOServiceGetMatchingServices returned %d",
Signature · 1 line
2.34.1
#15 lore raw

PATCH v7 11/22 coreaudio: Always return 0 in handle_voice_change

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

handle_voice_change() is a CoreAudio callback function as of CoreAudio type AudioObjectPropertyListenerProc, and for the latter MacOSX.sdk/System/ Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h says "The return value is currently unused and should always be 0.".

Message-Id: <[email protected]>

---
 audio/coreaudio.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
audio/coreaudio.c +2 -4
index 23d7593eb9..3186b68474 100644
@@ -545,7 +545,6 @@ static OSStatus handle_voice_change(
     const AudioObjectPropertyAddress *in_addresses,
     void *in_client_data)
 {
-    OSStatus status;
     coreaudioVoiceOut *core = in_client_data;
 
     qemu_mutex_lock_iothread();
@@ -554,13 +553,12 @@ static OSStatus handle_voice_change(
         fini_out_device(core);
     }
 
-    status = init_out_device(core);
-    if (!status) {
+    if (!init_out_device(core)) {
         update_device_playback_state(core);
     }
 
     qemu_mutex_unlock_iothread();
-    return status;
+    return 0;
 }
 
 static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
Signature · 1 line
2.34.1
#12 lore raw

PATCH v7 8/22 audio/coreaudio: Remove a deprecation warning on macOS 12

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

When building on macOS 12 we get:

audio/coreaudio.c:50:5: error: 'kAudioObjectPropertyElementMaster' is deprecated: first deprecated in macOS 12.0 [-Werror,-Wdeprecated-declarations]

      kAudioObjectPropertyElementMaster
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      kAudioObjectPropertyElementMain
  /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardwareBase.h:208:5: note: 'kAudioObjectPropertyElementMaster' has been explicitly marked deprecated here
      kAudioObjectPropertyElementMaster API_DEPRECATED_WITH_REPLACEMENT("kAudioObjectPropertyElementMain", macos(10.0, 12.0), ios(2.0, 15.0), watchos(1.0, 8.0), tvos(9.0, 15.0)) = kAudioObjectPropertyElementMain
      ^

Replace by kAudioObjectPropertyElementMain, redefining it to kAudioObjectPropertyElementMaster if not available.

---
 audio/coreaudio.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
audio/coreaudio.c +11 -6
index 0f19d0ce01..23d7593eb9 100644
@@ -44,10 +44,15 @@ typedef struct coreaudioVoiceOut {
     bool enabled;
 } coreaudioVoiceOut;
 
+#if !defined(MAC_OS_VERSION_12_0) \
+    || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_12_0)
+#define kAudioObjectPropertyElementMain kAudioObjectPropertyElementMaster
+#endif
+
 static const AudioObjectPropertyAddress voice_addr = {
     kAudioHardwarePropertyDefaultOutputDevice,
     kAudioObjectPropertyScopeGlobal,
-    kAudioObjectPropertyElementMaster
+    kAudioObjectPropertyElementMain
 };
 
 static OSStatus coreaudio_get_voice(AudioDeviceID *id)
@@ -69,7 +74,7 @@ static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
     AudioObjectPropertyAddress addr = {
         kAudioDevicePropertyBufferFrameSizeRange,
         kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
+        kAudioObjectPropertyElementMain
     };
 
     return AudioObjectGetPropertyData(id,
@@ -86,7 +91,7 @@ static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize)
     AudioObjectPropertyAddress addr = {
         kAudioDevicePropertyBufferFrameSize,
         kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
+        kAudioObjectPropertyElementMain
     };
 
     return AudioObjectGetPropertyData(id,
@@ -103,7 +108,7 @@ static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
     AudioObjectPropertyAddress addr = {
         kAudioDevicePropertyBufferFrameSize,
         kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
+        kAudioObjectPropertyElementMain
     };
 
     return AudioObjectSetPropertyData(id,
@@ -121,7 +126,7 @@ static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
     AudioObjectPropertyAddress addr = {
         kAudioDevicePropertyStreamFormat,
         kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
+        kAudioObjectPropertyElementMain
     };
 
     return AudioObjectSetPropertyData(id,
@@ -138,7 +143,7 @@ static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result)
     AudioObjectPropertyAddress addr = {
         kAudioDevicePropertyDeviceIsRunning,
         kAudioDevicePropertyScopeOutput,
-        kAudioObjectPropertyElementMaster
+        kAudioObjectPropertyElementMain
     };
 
     return AudioObjectGetPropertyData(id,
Signature · 1 line
2.34.1
#28 lore raw

PATCH v7 19/22 ui/cocoa: release mouse when user switches away from QEMU window

In reply to Philippe Mathieu-Daudé

From: Carwyn Ellis <[email protected]>

This resolves an issue where using command-tab to switch between QEMU and other windows on the host can leave the mouse pointer visible.

By releasing the mouse when the user switches away, the user must left click on the QEMU window when switching back in order to hide the pointer and return control to the guest.

This appraoch ensures that the calls to NSCursor hide and unhide are always balanced and thus work correctly when invoked.

---
 ui/cocoa.m | 2 ++
 1 file changed, 2 insertions(+)
ui/cocoa.m +2 -0
index 319af5045b..31f0846c30 100644
@@ -1264,6 +1264,7 @@ QemuCocoaView *cocoaView;
 - (void) applicationWillResignActive: (NSNotification *)aNotification
 {
     COCOA_DEBUG("QemuCocoaAppController: applicationWillResignActive\n");
+    [cocoaView ungrabMouse];
     [cocoaView raiseAllKeys];
 }
 
@@ -2066,6 +2067,7 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
             [(QemuCocoaAppController *)[[NSApplication sharedApplication] delegate] toggleFullScreen: nil];
         });
     }
+
     if (opts->has_show_cursor && opts->show_cursor) {
         cursor_hide = 0;
     }
Signature · 1 line
2.34.1
#13 lore raw

PATCH v7 9/22 audio/dbus: Fix building with modules on macOS

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

When configuring QEMU with --enable-modules we get on macOS:

--- stderr ---
Dependency ui-dbus cannot be satisfied

ui-dbus depends on pixman and opengl, so add these dependencies to audio-dbus.

Fixes 739362d420 ("audio: add "dbus" audio backend")
---
 audio/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
audio/meson.build +1 -1
index 0ac3791d0b..d9b295514f 100644
@@ -28,7 +28,7 @@ endforeach
 
 if dbus_display
     module_ss = ss.source_set()
-    module_ss.add(when: gio, if_true: files('dbusaudio.c'))
+    module_ss.add(when: [gio, pixman, opengl, 'CONFIG_GIO'], if_true: files('dbusaudio.c'))
     audio_modules += {'dbus': module_ss}
 endif
 
Signature · 1 line
2.34.1
#14 lore raw

PATCH v7 10/22 audio: Log context for audio bug

In reply to Philippe Mathieu-Daudé

From: Akihiko Odaki <[email protected]>

Without this change audio_bug aborts when the bug condition is met, which discards following useful logs. Call abort after such logs.

Message-Id: <[email protected]>

---
 audio/audio.c          | 25 ++++++++++++-------------
 audio/audio_template.h | 27 ++++++++++++---------------
 2 files changed, 24 insertions(+), 28 deletions(-)
audio/audio.c +12 -13
index a88572e713..6bc313d9f5 100644
@@ -117,7 +117,6 @@ int audio_bug (const char *funcname, int cond)
             AUD_log (NULL, "I am sorry\n");
         }
         AUD_log (NULL, "Context:\n");
-        abort();
     }
 
     return cond;
@@ -138,7 +137,7 @@ static inline int audio_bits_to_index (int bits)
     default:
         audio_bug ("bits_to_index", 1);
         AUD_log (NULL, "invalid bits %d\n", bits);
-        return 0;
+        abort();
     }
 }
 
@@ -156,7 +155,7 @@ void *audio_calloc (const char *funcname, int nmemb, size_t size)
         AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n",
                  funcname);
         AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len);
-        return NULL;
+        abort();
     }
 
     return g_malloc0 (len);
@@ -543,7 +542,7 @@ static size_t audio_pcm_hw_get_live_in(HWVoiceIn *hw)
     size_t live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
     if (audio_bug(__func__, live > hw->conv_buf->size)) {
         dolog("live=%zu hw->conv_buf->size=%zu\n", live, hw->conv_buf->size);
-        return 0;
+        abort();
     }
     return live;
 }
@@ -581,7 +580,7 @@ static size_t audio_pcm_sw_read(SWVoiceIn *sw, void *buf, size_t size)
     }
     if (audio_bug(__func__, live > hw->conv_buf->size)) {
         dolog("live_in=%zu hw->conv_buf->size=%zu\n", live, hw->conv_buf->size);
-        return 0;
+        abort();
     }
 
     rpos = audio_ring_posb(hw->conv_buf->pos, live, hw->conv_buf->size);
@@ -656,7 +655,7 @@ static size_t audio_pcm_hw_get_live_out (HWVoiceOut *hw, int *nb_live)
 
         if (audio_bug(__func__, live > hw->mix_buf->size)) {
             dolog("live=%zu hw->mix_buf->size=%zu\n", live, hw->mix_buf->size);
-            return 0;
+            abort();
         }
         return live;
     }
@@ -706,7 +705,7 @@ static size_t audio_pcm_sw_write(SWVoiceOut *sw, void *buf, size_t size)
     live = sw->total_hw_samples_mixed;
     if (audio_bug(__func__, live > hwsamples)) {
         dolog("live=%zu hw->mix_buf->size=%zu\n", live, hwsamples);
-        return 0;
+        abort();
     }
 
     if (live == hwsamples) {
@@ -998,7 +997,7 @@ static size_t audio_get_avail (SWVoiceIn *sw)
     if (audio_bug(__func__, live > sw->hw->conv_buf->size)) {
         dolog("live=%zu sw->hw->conv_buf->size=%zu\n", live,
               sw->hw->conv_buf->size);
-        return 0;
+        abort();
     }
 
     ldebug (
@@ -1028,7 +1027,7 @@ static size_t audio_get_free(SWVoiceOut *sw)
     if (audio_bug(__func__, live > sw->hw->mix_buf->size)) {
         dolog("live=%zu sw->hw->mix_buf->size=%zu\n", live,
               sw->hw->mix_buf->size);
-        return 0;
+        abort();
     }
 
     dead = sw->hw->mix_buf->size - live;
@@ -1170,7 +1169,7 @@ static void audio_run_out (AudioState *s)
 
         if (audio_bug(__func__, live > hw->mix_buf->size)) {
             dolog("live=%zu hw->mix_buf->size=%zu\n", live, hw->mix_buf->size);
-            continue;
+            abort();
         }
 
         if (hw->pending_disable && !nb_live) {
@@ -1203,7 +1202,7 @@ static void audio_run_out (AudioState *s)
         if (audio_bug(__func__, hw->mix_buf->pos >= hw->mix_buf->size)) {
             dolog("hw->mix_buf->pos=%zu hw->mix_buf->size=%zu played=%zu\n",
                   hw->mix_buf->pos, hw->mix_buf->size, played);
-            hw->mix_buf->pos = 0;
+            abort();
         }
 
 #ifdef DEBUG_OUT
@@ -1223,7 +1222,7 @@ static void audio_run_out (AudioState *s)
             if (audio_bug(__func__, played > sw->total_hw_samples_mixed)) {
                 dolog("played=%zu sw->total_hw_samples_mixed=%zu\n",
                       played, sw->total_hw_samples_mixed);
-                played = sw->total_hw_samples_mixed;
+                abort();
             }
 
             sw->total_hw_samples_mixed -= played;
@@ -1346,7 +1345,7 @@ static void audio_run_capture (AudioState *s)
             if (audio_bug(__func__, captured > sw->total_hw_samples_mixed)) {
                 dolog("captured=%zu sw->total_hw_samples_mixed=%zu\n",
                       captured, sw->total_hw_samples_mixed);
-                captured = sw->total_hw_samples_mixed;
+                abort();
             }
 
             sw->total_hw_samples_mixed -= captured;
audio/audio_template.h +12 -15
index d2d348638b..7192b19e73 100644
@@ -59,12 +59,13 @@ static void glue(audio_init_nb_voices_, TYPE)(AudioState *s,
     if (audio_bug(__func__, !voice_size && max_voices)) {
         dolog ("drv=`%s' voice_size=0 max_voices=%d\n",
                drv->name, max_voices);
-        glue (s->nb_hw_voices_, TYPE) = 0;
+        abort();
     }
 
     if (audio_bug(__func__, voice_size && !max_voices)) {
         dolog ("drv=`%s' voice_size=%d max_voices=0\n",
                drv->name, voice_size);
+        abort();
     }
 }
 
@@ -81,6 +82,7 @@ static void glue(audio_pcm_hw_alloc_resources_, TYPE)(HW *hw)
         size_t samples = hw->samples;
         if (audio_bug(__func__, samples == 0)) {
             dolog("Attempted to allocate empty buffer\n");
+            abort();
         }
 
         HWBUF = g_malloc0(sizeof(STSampleBuffer) + sizeof(st_sample) * samples);
@@ -252,12 +254,12 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
 
     if (audio_bug(__func__, !drv)) {
         dolog ("No host audio driver\n");
-        return NULL;
+        abort();
     }
 
     if (audio_bug(__func__, !drv->pcm_ops)) {
         dolog ("Host audio driver without pcm_ops\n");
-        return NULL;
+        abort();
     }
 
     hw = audio_calloc(__func__, 1, glue(drv->voice_size_, TYPE));
@@ -275,12 +277,13 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
     QLIST_INIT (&hw->cap_head);
 #endif
     if (glue (hw->pcm_ops->init_, TYPE) (hw, as, s->drv_opaque)) {
-        goto err0;
+        g_free(hw);
+        return NULL;
     }
 
     if (audio_bug(__func__, hw->samples <= 0)) {
         dolog("hw->samples=%zd\n", hw->samples);
-        goto err1;
+        abort();
     }
 
     if (hw->info.is_float) {
@@ -309,12 +312,6 @@ static HW *glue(audio_pcm_hw_add_new_, TYPE)(AudioState *s,
     audio_attach_capture (hw);
 #endif
     return hw;
-
- err1:
-    glue (hw->pcm_ops->fini_, TYPE) (hw);
- err0:
-    g_free (hw);
-    return NULL;
 }
 
 AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
@@ -435,7 +432,7 @@ void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
     if (sw) {
         if (audio_bug(__func__, !card)) {
             dolog ("card=%p\n", card);
-            return;
+            abort();
         }
 
         glue (audio_close_, TYPE) (sw);
@@ -457,7 +454,7 @@ SW *glue (AUD_open_, TYPE) (
     if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
         dolog ("card=%p name=%p callback_fn=%p as=%p\n",
                card, name, callback_fn, as);
-        goto fail;
+        abort();
     }
 
     s = card->state;
@@ -468,12 +465,12 @@ SW *glue (AUD_open_, TYPE) (
 
     if (audio_bug(__func__, audio_validate_settings(as))) {
         audio_print_settings (as);
-        goto fail;
+        abort();
     }
 
     if (audio_bug(__func__, !s->drv)) {
         dolog ("Can not open `%s' (no host audio driver)\n", name);
-        goto fail;
+        abort();
     }
 
     if (sw && audio_pcm_info_eq (&sw->info, as)) {
Signature · 1 line
2.34.1
#16 lore raw

PATCH v7 12/22 audio: Rename coreaudio extension to use Objective-C compiler

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

The coreaudio library includes Objective-C declarations (using the caret '^' symbol to declare block references [*]). When building with a C compiler we get:

[175/839] Compiling C object libcommon.fa.p/audio_coreaudio.c.o
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/CoreAudio.h:18,
from ../../audio/coreaudio.c:26:
/Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk/System/Library/Frameworks/CoreAudio.framework/Headers/AudioHardware.h:162:2: error: expected identifier or '(' before '^' token
162 | (^AudioObjectPropertyListenerBlock)( UInt32 inNumberAddresses,
| ^
FAILED: libcommon.fa.p/audio_coreaudio.c.o

Rename the file to use the Objective-C default extension (.m) so meson calls the correct compiler.

[*] https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html

---
 audio/{coreaudio.c => coreaudio.m} | 0
 audio/meson.build                  | 2 +-
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename audio/{coreaudio.c => coreaudio.m} (100%)
audio/coreaudio.m renamed from audio/coreaudio.c +0 -0
similarity index 100%
rename from audio/coreaudio.c
rename to audio/coreaudio.m
audio/meson.build +1 -1
index d9b295514f..94dab16891 100644
@@ -7,7 +7,7 @@ softmmu_ss.add(files(
   'wavcapture.c',
 ))
 
-softmmu_ss.add(when: coreaudio, if_true: files('coreaudio.c'))
+softmmu_ss.add(when: coreaudio, if_true: files('coreaudio.m'))
 softmmu_ss.add(when: dsound, if_true: files('dsoundaudio.c', 'audio_win_int.c'))
 
 audio_modules = {}
Signature · 1 line
2.34.1
#29 lore raw

PATCH v7 20/22 ui/cocoa: capture all keys and combos when mouse is grabbed

In reply to Philippe Mathieu-Daudé

From: Gustavo Noronha Silva <[email protected]>

Applications such as Gnome may use Alt-Tab and Super-Tab for different purposes, some use Ctrl-arrows so we want to allow qemu to handle everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Message-Id: <[email protected]>

Message-Id: <[email protected]>

---
 qapi/ui.json    |  8 +++++-
 qemu-options.hx |  3 +++
 ui/cocoa.m      | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 2 deletions(-)
qapi/ui.json +7 -1
index 4dea35a819..1d60d5fc78 100644
@@ -1270,11 +1270,17 @@
 #                    host without sending this key to the guest when
 #                    "off". Defaults to "on"
 #
+# @full-grab: Capture all key presses, including system combos. This
+#             requires accessibility permissions, since it performs
+#             a global grab on key events. (default: off)
+#             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
+#
 # Since: 7.0
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
-      '*left-command-key': 'bool'
+      '*left-command-key': 'bool',
+      '*full-grab': 'bool'
   } }
 
 ##
qemu-options.hx +3 -0
index ffaeab61ed..2e6d54db4f 100644
@@ -1916,6 +1916,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_CURSES)
     "-display curses[,charset=<encoding>]\n"
 #endif
+#if defined(CONFIG_COCOA)
+    "-display cocoa[,full_grab=on|off]\n"
+#endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
 #endif
ui/cocoa.m +64 -1

110 lines not on this page · raw message

Signature · 1 line
2.34.1
#17 lore raw

PATCH v7 13/22 osdep: Avoid using Clang-specific __builtin_available()

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Remove the Clang specific __builtin_available() to allow building with GCC, otherwise we get:

include/qemu/osdep.h: In function 'qemu_thread_jit_write':
include/qemu/osdep.h:787:9: warning: implicit declaration of function '__builtin_available'; did you mean '__builtin_scalbl'? [-Wimplicit-function-declaration]

    787 |     if (__builtin_available(macOS 11.0, *)) {
        |         ^~~~~~~~~~~~~~~~~~~
        |         __builtin_scalbl
  include/qemu/osdep.h:787:9: warning: nested extern declaration of '__builtin_available' [-Wnested-externs]
  include/qemu/osdep.h:787:29: error: 'macOS' undeclared (first use in this function)
    787 |     if (__builtin_available(macOS 11.0, *)) {
        |                             ^~~~~
  include/qemu/osdep.h:787:29: note: each undeclared identifier is reported only once for each function it appears in
  include/qemu/osdep.h:787:34: error: expected ')' before numeric constant
    787 |     if (__builtin_available(macOS 11.0, *)) {
        |                            ~     ^~~~~
        |                                  )

Beside, on macOS Catalina we get 2254 times:

include/qemu/osdep.h:780:5: warning: 'pthread_jit_write_protect_np' is only available on macOS 11.0 or newer [-Wunguarded-availability-new]

      pthread_jit_write_protect_np(true);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix by using a stricker toolchain version low range, replacing MAC_OS_X_VERSION_MAX_ALLOWED by MAC_OS_X_VERSION_MIN_REQUIRED.

---
 include/qemu/osdep.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
include/qemu/osdep.h +3 -7
index 7bcce3bceb..488a286300 100644
@@ -642,19 +642,15 @@ size_t qemu_get_host_physmem(void);
  * for the current thread.
  */
 #if defined(MAC_OS_VERSION_11_0) && \
-    MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+    MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
 static inline void qemu_thread_jit_execute(void)
 {
-    if (__builtin_available(macOS 11.0, *)) {
-        pthread_jit_write_protect_np(true);
-    }
+    pthread_jit_write_protect_np(true);
 }
 
 static inline void qemu_thread_jit_write(void)
 {
-    if (__builtin_available(macOS 11.0, *)) {
-        pthread_jit_write_protect_np(false);
-    }
+    pthread_jit_write_protect_np(false);
 }
 #else
 static inline void qemu_thread_jit_write(void) {}
Signature · 1 line
2.34.1
#21 lore raw

PATCH v7 15/22 meson: Log QEMU_CXXFLAGS content in summary

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

---
 meson.build | 1 +
 1 file changed, 1 insertion(+)
meson.build +1 -0
index 8ca2b7c8c2..0d38b2e72a 100644
@@ -3470,6 +3470,7 @@ if link_args.length() > 0
   summary_info += {'LDFLAGS':         ' '.join(link_args)}
 endif
 summary_info += {'QEMU_CFLAGS':       config_host['QEMU_CFLAGS']}
+summary_info += {'QEMU_CXXFLAGS':     config_host['QEMU_CXXFLAGS']}
 summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
 summary_info += {'profiler':          get_option('profiler')}
 summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
Signature · 1 line
2.34.1
#33 lore raw

PATCH v7 22/22 gitlab-ci: Support macOS 12 via cirrus-run

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Add support for macOS 12 build on Cirrus-CI, similarly to commit 0e103a65ba1 ("gitlab: support for ... macOS 11 via cirrus-run"), but with the following differences:
- Enable modules (configure --enable-modules)
- Do not run softfloat3 tests (make check-softfloat)
- Run Aarch64 qtests instead of x86_64 ones

Generate the vars file by calling 'make lcitool-refresh'.

---
 .gitlab-ci.d/cirrus.yml           | 16 ++++++++++++++++
 .gitlab-ci.d/cirrus/macos-12.vars | 16 ++++++++++++++++
 tests/lcitool/refresh             |  1 +
 3 files changed, 33 insertions(+)
 create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars
.gitlab-ci.d/cirrus.yml +16 -0
index b96b22e269..be1dce5d4e 100644
@@ -87,6 +87,22 @@ x64-macos-11-base-build:
     PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/ncurses/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig
     TEST_TARGETS: check-unit check-block check-qapi-schema check-softfloat check-qtest-x86_64
 
+x64-macos-12-base-build:
+  extends: .cirrus_build_job
+  variables:
+    NAME: macos-12
+    CIRRUS_VM_INSTANCE_TYPE: osx_instance
+    CIRRUS_VM_IMAGE_SELECTOR: image
+    CIRRUS_VM_IMAGE_NAME: monterey-base
+    CIRRUS_VM_CPUS: 12
+    CIRRUS_VM_RAM: 24G
+    UPDATE_COMMAND: brew update
+    INSTALL_COMMAND: brew install
+    PATH_EXTRA: /usr/local/opt/ccache/libexec:/usr/local/opt/gettext/bin
+    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/ncurses/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig
+    CONFIGURE_ARGS: --enable-modules
+    TEST_TARGETS: check-unit check-block check-qapi-schema check-qtest-aarch64
+
 
 # The following jobs run VM-based tests via KVM on a Linux-based Cirrus-CI job
 .cirrus_kvm_job:
.gitlab-ci.d/cirrus/macos-12.vars new file +16 -0
new file mode 100644
index 0000000000..a793258c64
@@ -0,0 +1,16 @@
+# THIS FILE WAS AUTO-GENERATED
+#
+#  $ lcitool variables macos-12 qemu
+#
+# https://gitlab.com/libvirt/libvirt-ci
+
+CCACHE='/usr/local/bin/ccache'
+CPAN_PKGS='Test::Harness'
+CROSS_PKGS=''
+MAKE='/usr/local/bin/gmake'
+NINJA='/usr/local/bin/ninja'
+PACKAGING_COMMAND='brew'
+PIP3='/usr/local/bin/pip3'
+PKGS='bash bc bzip2 capstone ccache cpanminus ctags curl dbus diffutils dtc gcovr gettext git glib gnu-sed gnutls gtk+3 jemalloc jpeg-turbo libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson ncurses nettle ninja perl pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy sparse spice-protocol tesseract texinfo usbredir vde vte3 zlib zstd'
+PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme virtualenv'
+PYTHON='/usr/local/bin/python3'
tests/lcitool/refresh +1 -0
index 1f00281b44..e2f0bbd1b1 100755
@@ -105,6 +105,7 @@ try:
    generate_cirrus("freebsd-12")
    generate_cirrus("freebsd-13")
    generate_cirrus("macos-11")
+   generate_cirrus("macos-12")
 
    sys.exit(0)
 except Exception as ex:
Signature · 1 line
2.34.1
#19 lore raw

PATCH v7 14/22 meson: Resolve the entitlement.sh script once for good

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Commit 235b523dba ("meson: Use find_program() to resolve the entitlement.sh script") didn't correctly fixed the issue, as the script is still resolved for each target. Move the check earlier, before processing each target.

---
 meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meson.build +4 -1
index b6e30d7463..8ca2b7c8c2 100644
@@ -3063,6 +3063,10 @@ common_all = static_library('common',
 
 feature_to_c = find_program('scripts/feature_to_c.sh')
 
+if targetos == 'darwin'
+  entitlement = find_program('scripts/entitlement.sh')
+endif
+
 emulators = {}
 foreach target : target_dirs
   config_target = config_target_mak[target]
@@ -3220,7 +3224,6 @@ foreach target : target_dirs
         install_input += meson.current_source_dir() / entitlements
       endif
 
-      entitlement = find_program('scripts/entitlement.sh')
       emulators += {exe['name'] : custom_target(exe['name'],
                    input: build_input,
                    output: exe['name'],
Signature · 1 line
2.34.1
#31 lore raw

PATCH v7 21/22 ui/cocoa: add option to swap Option and Command

In reply to Philippe Mathieu-Daudé

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change swaps them around so that Alt is the key closer to the space bar and Meta/Super is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/cocoa.m      | 49 +++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 46 insertions(+), 12 deletions(-)
qapi/ui.json +6 -1
index 1d60d5fc78..664da9e462 100644
@@ -1275,12 +1275,17 @@
 #             a global grab on key events. (default: off)
 #             See https://support.apple.com/en-in/guide/mac-help/mh32356/mac
 #
+# @swap-opt-cmd: Swap the Option and Command keys so that their key codes match
+#                their position on non-Mac keyboards and you can use Meta/Super
+#                and Alt where you expect them. (default: off)
+#
 # Since: 7.0
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
       '*left-command-key': 'bool',
-      '*full-grab': 'bool'
+      '*full-grab': 'bool',
+      '*swap-opt-cmd': 'bool'
   } }
 
 ##
qemu-options.hx +1 -1
index 2e6d54db4f..f443b0f33a 100644
@@ -1917,7 +1917,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
     "-display curses[,charset=<encoding>]\n"
 #endif
 #if defined(CONFIG_COCOA)
-    "-display cocoa[,full_grab=on|off]\n"
+    "-display cocoa[,full-grab=on|off][,swap-opt-cmd=on|off]\n"
 #endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
ui/cocoa.m +39 -10

92 lines not on this page · raw message

Signature · 1 line
2.34.1
#25 lore raw

PATCH v7 17/22 ui/cocoa: Constify qkeycode translation arrays

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

---
 ui/cocoa.m | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ui/cocoa.m +2 -2
index 8ab9ab5e84..a6db8ebfb6 100644
@@ -671,7 +671,7 @@ QemuCocoaView *cocoaView;
 
     /* translates Macintosh keycodes to QEMU's keysym */
 
-    int without_control_translation[] = {
+    static const int without_control_translation[] = {
         [0 ... 0xff] = 0,   // invalid key
 
         [kVK_UpArrow]       = QEMU_KEY_UP,
@@ -686,7 +686,7 @@ QemuCocoaView *cocoaView;
         [kVK_Delete]        = QEMU_KEY_BACKSPACE,
     };
 
-    int with_control_translation[] = {
+    static const int with_control_translation[] = {
         [0 ... 0xff] = 0,   // invalid key
 
         [kVK_UpArrow]       = QEMU_KEY_CTRL_UP,
Signature · 1 line
2.34.1
#23 lore raw

PATCH v7 16/22 configure: Pass filtered QEMU_OBJCFLAGS to meson

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Filter unsupported Objective-C options, to avoid 'unknown-warning-option' warnings when using Clang:

[34/373] Compiling Objective-C object libcommon.fa.p/audio_coreaudio.m.o
warning: unknown warning option '-Wold-style-declaration'; did you mean '-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean '-Wimplicit-fallthrough'? [-Wunknown-warning-option] 2 warnings generated.

---
 configure   | 23 +++++++++++++++++++++++
 meson.build |  6 +++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
configure +23 -0
index e60156f90f..7d1f35603b 100755
@@ -77,6 +77,7 @@ TMPB="qemu-conf"
 TMPC="${TMPDIR1}/${TMPB}.c"
 TMPO="${TMPDIR1}/${TMPB}.o"
 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
+TMPM="${TMPDIR1}/${TMPB}.m"
 TMPE="${TMPDIR1}/${TMPB}.exe"
 
 rm -f config.log
@@ -148,6 +149,10 @@ do_cxx() {
     do_compiler "$cxx" $CPU_CFLAGS "$@"
 }
 
+do_objc() {
+    do_compiler "$objcc" $CPU_CFLAGS "$@"
+}
+
 # Append $2 to the variable named $1, with space separation
 add_to() {
     eval $1=\${$1:+\"\$$1 \"}\$2
@@ -1445,10 +1450,27 @@ cc_has_warning_flag() {
     compile_prog "-Werror $optflag" ""
 }
 
+objcc_has_warning_flag() {
+    cat > $TMPM <<EOF
+int main(void) { return 0; }
+EOF
+
+    # Use the positive sense of the flag when testing for -Wno-wombat
+    # support (gcc will happily accept the -Wno- form of unknown
+    # warning options).
+    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
+    do_objc -Werror $optflag \
+      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
+      -o $TMPE $TMPM $QEMU_LDFLAGS
+}
+
 for flag in $gcc_flags; do
     if cc_has_warning_flag $flag ; then
         QEMU_CFLAGS="$QEMU_CFLAGS $flag"
     fi
+    if objcc_has_warning_flag $flag ; then
+        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
+    fi
 done
 
 if test "$stack_protector" != "no"; then
@@ -2990,6 +3012,7 @@ echo "LD=$ld" >> $config_host_mak
 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
+echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
 echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
meson.build +5 -1
index 0d38b2e72a..a770e80a32 100644
@@ -173,11 +173,13 @@ endif
 
 qemu_cflags = config_host['QEMU_CFLAGS'].split()
 qemu_cxxflags = config_host['QEMU_CXXFLAGS'].split()
+qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split()
 qemu_ldflags = config_host['QEMU_LDFLAGS'].split()
 
 if get_option('gprof')
   qemu_cflags += ['-p']
   qemu_cxxflags += ['-p']
+  qemu_objcflags += ['-p']
   qemu_ldflags += ['-p']
 endif
 
@@ -216,8 +218,9 @@ if get_option('fuzzing')
   endif
 endif
 
-add_global_arguments(qemu_cflags, native: false, language: ['c', 'objc'])
+add_global_arguments(qemu_cflags, native: false, language: ['c'])
 add_global_arguments(qemu_cxxflags, native: false, language: ['cpp'])
+add_global_arguments(qemu_objcflags, native: false, language: ['objc'])
 add_global_link_arguments(qemu_ldflags, native: false, language: ['c', 'cpp', 'objc'])
 
 if targetos == 'linux'
@@ -3471,6 +3474,7 @@ if link_args.length() > 0
 endif
 summary_info += {'QEMU_CFLAGS':       config_host['QEMU_CFLAGS']}
 summary_info += {'QEMU_CXXFLAGS':     config_host['QEMU_CXXFLAGS']}
+summary_info += {'QEMU_OBJCFLAGS':    config_host['QEMU_OBJCFLAGS']}
 summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
 summary_info += {'profiler':          get_option('profiler')}
 summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
Signature · 1 line
2.34.1
Reviewed-by Tested-by on v7 13/22
#18 lore raw

Re: [PATCH v7 13/22] osdep: Avoid using Clang-specific __builtin_available()

In reply to Philippe Mathieu-Daudé
Quoted 65 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Remove the Clang specific __builtin_available() to allow building with GCC, otherwise we get:

include/qemu/osdep.h: In function 'qemu_thread_jit_write':
include/qemu/osdep.h:787:9: warning: implicit declaration of function '__builtin_available'; did you mean '__builtin_scalbl'? [-Wimplicit-function-declaration]

    787 |     if (__builtin_available(macOS 11.0, *)) {
        |         ^~~~~~~~~~~~~~~~~~~
        |         __builtin_scalbl
  include/qemu/osdep.h:787:9: warning: nested extern declaration of '__builtin_available' [-Wnested-externs]
  include/qemu/osdep.h:787:29: error: 'macOS' undeclared (first use in this function)
    787 |     if (__builtin_available(macOS 11.0, *)) {
        |                             ^~~~~
  include/qemu/osdep.h:787:29: note: each undeclared identifier is reported only once for each function it appears in
  include/qemu/osdep.h:787:34: error: expected ')' before numeric constant
    787 |     if (__builtin_available(macOS 11.0, *)) {
        |                            ~     ^~~~~
        |                                  )

Beside, on macOS Catalina we get 2254 times:

include/qemu/osdep.h:780:5: warning: 'pthread_jit_write_protect_np' is only available on macOS 11.0 or newer [-Wunguarded-availability-new]

      pthread_jit_write_protect_np(true);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix by using a stricker toolchain version low range, replacing MAC_OS_X_VERSION_MAX_ALLOWED by MAC_OS_X_VERSION_MIN_REQUIRED.

---
 include/qemu/osdep.h | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)
include/qemu/osdep.h +3 -8
index 7bcce3bceb..488a286300 100644
@@ -642,19 +642,15 @@ size_t qemu_get_host_physmem(void);
  * for the current thread.
  */
 #if defined(MAC_OS_VERSION_11_0) && \
-    MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0
+    MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_VERSION_11_0
 static inline void qemu_thread_jit_execute(void)
 {
-    if (__builtin_available(macOS 11.0, *)) {
-        pthread_jit_write_protect_np(true);
-    }
+    pthread_jit_write_protect_np(true);
 }
 
 static inline void qemu_thread_jit_write(void)
 {
-    if (__builtin_available(macOS 11.0, *)) {
-        pthread_jit_write_protect_np(false);
-    }
+    pthread_jit_write_protect_np(false);
 }
 #else
 static inline void qemu_thread_jit_write(void) {}
--

2.34.1

Reviewed-by Tested-by on v7 14/22
#20 lore raw

Re: [PATCH v7 14/22] meson: Resolve the entitlement.sh script once for good

In reply to Philippe Mathieu-Daudé
Quoted 39 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Commit 235b523dba ("meson: Use find_program() to resolve the entitlement.sh script") didn't correctly fixed the issue, as the script is still resolved for each target. Move the check earlier, before processing each target.

---
 meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
meson.build +4 -2
index b6e30d7463..8ca2b7c8c2 100644
@@ -3063,6 +3063,10 @@ common_all = static_library('common',
 
 feature_to_c = find_program('scripts/feature_to_c.sh')
 
+if targetos == 'darwin'
+  entitlement = find_program('scripts/entitlement.sh')
+endif
+
 emulators = {}
 foreach target : target_dirs
   config_target = config_target_mak[target]
@@ -3220,7 +3224,6 @@ foreach target : target_dirs
         install_input += meson.current_source_dir() / entitlements
       endif
 
-      entitlement = find_program('scripts/entitlement.sh')
       emulators += {exe['name'] : custom_target(exe['name'],
                    input: build_input,
                    output: exe['name'],
--

2.34.1

Reviewed-by Tested-by on v7 15/22
#22 lore raw

Re: [PATCH v7 15/22] meson: Log QEMU_CXXFLAGS content in summary

In reply to Philippe Mathieu-Daudé
Quoted 23 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

---
 meson.build | 1 +
 1 file changed, 1 insertion(+)
meson.build +1 -1
index 8ca2b7c8c2..0d38b2e72a 100644
@@ -3470,6 +3470,7 @@ if link_args.length() > 0
   summary_info += {'LDFLAGS':         ' '.join(link_args)}
 endif
 summary_info += {'QEMU_CFLAGS':       config_host['QEMU_CFLAGS']}
+summary_info += {'QEMU_CXXFLAGS':     config_host['QEMU_CXXFLAGS']}
 summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
 summary_info += {'profiler':          get_option('profiler')}
 summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
--

2.34.1

Reviewed-by Tested-by on v7 16/22
#24 lore raw

Re: [PATCH v7 16/22] configure: Pass filtered QEMU_OBJCFLAGS to meson

In reply to Philippe Mathieu-Daudé
Quoted 117 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Filter unsupported Objective-C options, to avoid 'unknown-warning-option' warnings when using Clang:

[34/373] Compiling Objective-C object libcommon.fa.p/audio_coreaudio.m.o
warning: unknown warning option '-Wold-style-declaration'; did you mean '-Wout-of-line-declaration'? [-Wunknown-warning-option]
warning: unknown warning option '-Wimplicit-fallthrough=2'; did you mean '-Wimplicit-fallthrough'? [-Wunknown-warning-option] 2 warnings generated.

---
 configure   | 23 +++++++++++++++++++++++
 meson.build |  6 +++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
configure +23 -0
index e60156f90f..7d1f35603b 100755
@@ -77,6 +77,7 @@ TMPB="qemu-conf"
 TMPC="${TMPDIR1}/${TMPB}.c"
 TMPO="${TMPDIR1}/${TMPB}.o"
 TMPCXX="${TMPDIR1}/${TMPB}.cxx"
+TMPM="${TMPDIR1}/${TMPB}.m"
 TMPE="${TMPDIR1}/${TMPB}.exe"
 
 rm -f config.log
@@ -148,6 +149,10 @@ do_cxx() {
     do_compiler "$cxx" $CPU_CFLAGS "$@"
 }
 
+do_objc() {
+    do_compiler "$objcc" $CPU_CFLAGS "$@"
+}
+
 # Append $2 to the variable named $1, with space separation
 add_to() {
     eval $1=\${$1:+\"\$$1 \"}\$2
@@ -1445,10 +1450,27 @@ cc_has_warning_flag() {
     compile_prog "-Werror $optflag" ""
 }
 
+objcc_has_warning_flag() {
+    cat > $TMPM <<EOF
+int main(void) { return 0; }
+EOF
+
+    # Use the positive sense of the flag when testing for -Wno-wombat
+    # support (gcc will happily accept the -Wno- form of unknown
+    # warning options).
+    optflag="$(echo $1 | sed -e 's/^-Wno-/-W/')"
+    do_objc -Werror $optflag \
+      $OBJCFLAGS $EXTRA_OBJCFLAGS $CONFIGURE_OBJCFLAGS $QEMU_OBJCFLAGS \
+      -o $TMPE $TMPM $QEMU_LDFLAGS
+}
+
 for flag in $gcc_flags; do
     if cc_has_warning_flag $flag ; then
         QEMU_CFLAGS="$QEMU_CFLAGS $flag"
     fi
+    if objcc_has_warning_flag $flag ; then
+        QEMU_OBJCFLAGS="$QEMU_OBJCFLAGS $flag"
+    fi
 done
 
 if test "$stack_protector" != "no"; then
@@ -2990,6 +3012,7 @@ echo "LD=$ld" >> $config_host_mak
 echo "CFLAGS_NOPIE=$CFLAGS_NOPIE" >> $config_host_mak
 echo "QEMU_CFLAGS=$QEMU_CFLAGS" >> $config_host_mak
 echo "QEMU_CXXFLAGS=$QEMU_CXXFLAGS" >> $config_host_mak
+echo "QEMU_OBJCFLAGS=$QEMU_OBJCFLAGS" >> $config_host_mak
 echo "GLIB_CFLAGS=$glib_cflags" >> $config_host_mak
 echo "GLIB_LIBS=$glib_libs" >> $config_host_mak
 echo "GLIB_VERSION=$(pkg-config --modversion glib-2.0)" >> $config_host_mak
meson.build +5 -2
index 0d38b2e72a..a770e80a32 100644
@@ -173,11 +173,13 @@ endif
 
 qemu_cflags = config_host['QEMU_CFLAGS'].split()
 qemu_cxxflags = config_host['QEMU_CXXFLAGS'].split()
+qemu_objcflags = config_host['QEMU_OBJCFLAGS'].split()
 qemu_ldflags = config_host['QEMU_LDFLAGS'].split()
 
 if get_option('gprof')
   qemu_cflags += ['-p']
   qemu_cxxflags += ['-p']
+  qemu_objcflags += ['-p']
   qemu_ldflags += ['-p']
 endif
 
@@ -216,8 +218,9 @@ if get_option('fuzzing')
   endif
 endif
 
-add_global_arguments(qemu_cflags, native: false, language: ['c', 'objc'])
+add_global_arguments(qemu_cflags, native: false, language: ['c'])
 add_global_arguments(qemu_cxxflags, native: false, language: ['cpp'])
+add_global_arguments(qemu_objcflags, native: false, language: ['objc'])
 add_global_link_arguments(qemu_ldflags, native: false, language: ['c', 'cpp', 'objc'])
 
 if targetos == 'linux'
@@ -3471,6 +3474,7 @@ if link_args.length() > 0
 endif
 summary_info += {'QEMU_CFLAGS':       config_host['QEMU_CFLAGS']}
 summary_info += {'QEMU_CXXFLAGS':     config_host['QEMU_CXXFLAGS']}
+summary_info += {'QEMU_OBJCFLAGS':    config_host['QEMU_OBJCFLAGS']}
 summary_info += {'QEMU_LDFLAGS':      config_host['QEMU_LDFLAGS']}
 summary_info += {'profiler':          get_option('profiler')}
 summary_info += {'link-time optimization (LTO)': get_option('b_lto')}
--

2.34.1

Reviewed-by Tested-by on v7 17/22
#26 lore raw

Re: [PATCH v7 17/22] ui/cocoa: Constify qkeycode translation arrays

In reply to Philippe Mathieu-Daudé
Quoted 34 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

---
 ui/cocoa.m | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
ui/cocoa.m +2 -3
index 8ab9ab5e84..a6db8ebfb6 100644
@@ -671,7 +671,7 @@ QemuCocoaView *cocoaView;
 
     /* translates Macintosh keycodes to QEMU's keysym */
 
-    int without_control_translation[] = {
+    static const int without_control_translation[] = {
         [0 ... 0xff] = 0,   // invalid key
 
         [kVK_UpArrow]       = QEMU_KEY_UP,
@@ -686,7 +686,7 @@ QemuCocoaView *cocoaView;
         [kVK_Delete]        = QEMU_KEY_BACKSPACE,
     };
 
-    int with_control_translation[] = {
+    static const int with_control_translation[] = {
         [0 ... 0xff] = 0,   // invalid key
 
         [kVK_UpArrow]       = QEMU_KEY_CTRL_UP,
--

2.34.1

#32 lore raw

Re: [PATCH v7 21/22] ui/cocoa: add option to swap Option and Command

In reply to Philippe Mathieu-Daudé
Quoted 170 lines · Philippe Mathieu-Daudé

From: Gustavo Noronha Silva <[email protected]>

On Mac OS X the Option key maps to Alt and Command to Super/Meta. This change
swaps them around so that Alt is the key closer to the space bar and Meta/Super
is between Control and Alt, like on non-Mac keyboards.

It is a cocoa display option, disabled by default.

Message-Id: <[email protected]>

Message-Id: <[email protected]>

---
 qapi/ui.json    |  7 ++++++-
 qemu-options.hx |  2 +-
 ui/cocoa.m      | 49 +++++++++++++++++++++++++++++++++++++++----------
 3 files changed, 46 insertions(+), 12 deletions(-)
qapi/ui.json +0 -0
index 1d60d5fc78..664da9e462 100644
@@ -1275,12 +1275,17 @@
 #             a global grab on key events. (default: off)
 #             See

https://support.apple.com/en-in/guide/mac-help/mh32356/mac
#
+# @swap-opt-cmd: Swap the Option and Command keys so that their key codes match
+# their position on non-Mac keyboards and you can use
Meta/Super

qapi/ui.json +4 -1
+#                and Alt where you expect them. (default: off)
+#
 # Since: 7.0
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
       '*left-command-key': 'bool',
-      '*full-grab': 'bool'
+      '*full-grab': 'bool',
+      '*swap-opt-cmd': 'bool'
   } }
 
 ##
qemu-options.hx +1 -1
index 2e6d54db4f..f443b0f33a 100644
@@ -1917,7 +1917,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
     "-display curses[,charset=<encoding>]\n"
 #endif
 #if defined(CONFIG_COCOA)
-    "-display cocoa[,full_grab=on|off]\n"
+    "-display cocoa[,full-grab=on|off][,swap-opt-cmd=on|off]\n"
 #endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
ui/cocoa.m +1 -0
index ca1cab1ae6..c0a948201d 100644
@@ -96,6 +96,7 @@ static DisplayChangeListener dcl = {
 static int last_buttons;
 static int cursor_hide = 1;
 static int left_command_key_enabled = 1;
+static bool swap_opt_cmd;
 
 static int gArgc;
 static char **gArgv;
@@ -854,12 +855,22 @@ static CGEventRef handleTapEvent(CGEventTapProxy

proxy, CGEventType type, CGEven

         qkbd_state_key_event(kbd, Q_KEY_CODE_CTRL_R, false);
     }
     if (!(modifiers & NSEventModifierFlagOption)) {
ui/cocoa.m +14 -4
-        qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
-        qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        if (swap_opt_cmd) {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        } else {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        }
     }
     if (!(modifiers & NSEventModifierFlagCommand)) {
-        qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
-        qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        if (swap_opt_cmd) {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_ALT_R, false);
+        } else {
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_L, false);
+            qkbd_state_key_event(kbd, Q_KEY_CODE_META_R, false);
+        }
     }
 
     switch ([event type]) {
@@ -891,29 +902,44 @@ static CGEventRef handleTapEvent(CGEventTapProxy

proxy, CGEventType type, CGEven

                 case kVK_Option:
                     if (!!(modifiers & NSEventModifierFlagOption)) {
ui/cocoa.m +10 -2
-                        [self toggleKey:Q_KEY_CODE_ALT];
+                        if (swap_opt_cmd) {
+                            [self toggleKey:Q_KEY_CODE_META_L];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_ALT];
+                        }
                     }
                     break;
 
                 case kVK_RightOption:
                     if (!!(modifiers & NSEventModifierFlagOption)) {
-                        [self toggleKey:Q_KEY_CODE_ALT_R];
+                        if (swap_opt_cmd) {
+                            [self toggleKey:Q_KEY_CODE_META_R];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_ALT_R];
+                        }
                     }
                     break;
 
                 /* Don't pass command key changes to guest unless mouse

is grabbed */

                 case kVK_Command:
                     if (isMouseGrabbed &&
ui/cocoa.m +14 -4
-                        !!(modifiers & NSEventModifierFlagCommand) &&
-                        left_command_key_enabled) {
-                        [self toggleKey:Q_KEY_CODE_META_L];
+                        !!(modifiers & NSEventModifierFlagCommand)) {
+                        if (swap_opt_cmd) {
+                            [self toggleKey:Q_KEY_CODE_ALT];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_META_L];
+                        }
                     }
                     break;
 
                 case kVK_RightCommand:
                     if (isMouseGrabbed &&
                         !!(modifiers & NSEventModifierFlagCommand)) {
-                        [self toggleKey:Q_KEY_CODE_META_R];
+                        if (swap_opt_cmd) {
+                            [self toggleKey:Q_KEY_CODE_ALT_R];
+                        } else {
+                            [self toggleKey:Q_KEY_CODE_META_R];
+                        }
                     }
                     break;
             }
@@ -2134,6 +2160,9 @@ static void cocoa_display_init(DisplayState *ds,
 DisplayOptions *opts)
     if (opts->has_show_cursor && opts->show_cursor) {
         cursor_hide = 0;
     }
+    if (opts->u.cocoa.has_swap_opt_cmd) {
+        swap_opt_cmd = opts->u.cocoa.swap_opt_cmd;
+    }
 
     if (opts->u.cocoa.has_left_command_key &&
!opts->u.cocoa.left_command_key) {
         left_command_key_enabled = 0;

--
2.34.1

#30 lore raw

Re: [PATCH v7 20/22] ui/cocoa: capture all keys and combos when mouse is grabbed

In reply to Philippe Mathieu-Daudé
Quoted 205 lines · Philippe Mathieu-Daudé

From: Gustavo Noronha Silva <[email protected]>

Applications such as Gnome may use Alt-Tab and Super-Tab for different purposes, some use Ctrl-arrows so we want to allow qemu to handle everything when it captures the mouse/keyboard.

However, Mac OS handles some combos like Command-Tab and Ctrl-arrows at an earlier part of the event handling chain, not letting qemu see it.

We add a global Event Tap that allows qemu to see all events when the mouse is grabbed. Note that this requires additional permissions.

See:

https://developer.apple.com/documentation/coregraphics/1454426-cgeventtapcreate?language=objc#discussion
https://support.apple.com/en-in/guide/mac-help/mh32356/mac

Message-Id: <[email protected]>

Message-Id: <[email protected]>

---
 qapi/ui.json    |  8 +++++-
 qemu-options.hx |  3 +++
 ui/cocoa.m      | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 74 insertions(+), 2 deletions(-)
qapi/ui.json +4 -0
index 4dea35a819..1d60d5fc78 100644
@@ -1270,11 +1270,17 @@
 #                    host without sending this key to the guest when
 #                    "off". Defaults to "on"
 #
+# @full-grab: Capture all key presses, including system combos. This
+#             requires accessibility permissions, since it performs
+#             a global grab on key events. (default: off)
+#             See

https://support.apple.com/en-in/guide/mac-help/mh32356/mac

qapi/ui.json +3 -1
+#
 # Since: 7.0
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
-      '*left-command-key': 'bool'
+      '*left-command-key': 'bool',
+      '*full-grab': 'bool'
   } }
 
 ##
qemu-options.hx +3 -0
index ffaeab61ed..2e6d54db4f 100644
@@ -1916,6 +1916,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
 #if defined(CONFIG_CURSES)
     "-display curses[,charset=<encoding>]\n"
 #endif
+#if defined(CONFIG_COCOA)
+    "-display cocoa[,full_grab=on|off]\n"
+#endif
 #if defined(CONFIG_OPENGL)
     "-display egl-headless[,rendernode=<file>]\n"
 #endif
ui/cocoa.m +15 -0
index 31f0846c30..ca1cab1ae6 100644
@@ -309,11 +309,13 @@ static void handleAnyDeviceErrors(Error * err)
     BOOL isMouseGrabbed;
     BOOL isFullscreen;
     BOOL isAbsoluteEnabled;
+    CFMachPortRef eventsTap;
 }
 - (void) switchSurface:(pixman_image_t *)image;
 - (void) grabMouse;
 - (void) ungrabMouse;
 - (void) toggleFullScreen:(id)sender;
+- (void) setFullGrab:(id)sender;
 - (void) handleMonitorInput:(NSEvent *)event;
 - (bool) handleEvent:(NSEvent *)event;
 - (bool) handleEventLocked:(NSEvent *)event;
@@ -336,6 +338,19 @@ static void handleAnyDeviceErrors(Error * err)
 
 QemuCocoaView *cocoaView;
 
+static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type,
 CGEventRef cgEvent, void *userInfo)
+{
+    QemuCocoaView *cocoaView = userInfo;
+    NSEvent *event = [NSEvent eventWithCGEvent:cgEvent];
+    if ([cocoaView isMouseGrabbed] && [cocoaView handleEvent:event]) {
+        COCOA_DEBUG("Global events tap: qemu handled the event,
 capturing!\n");
+        return NULL;
+    }
+    COCOA_DEBUG("Global events tap: qemu did not handle the event,
 letting it through...\n");
+
+    return cgEvent;
+}
+

@implementation QemuCocoaView
- (id)initWithFrame:(NSRect)frameRect
{

ui/cocoa.m +17 -0
@@ -361,6 +376,11 @@ QemuCocoaView *cocoaView;
     }
 
     qkbd_state_free(kbd);
+
+    if (eventsTap) {
+        CFRelease(eventsTap);
+    }
+
     [super dealloc];
 }
 
@@ -655,6 +675,36 @@ QemuCocoaView *cocoaView;
     }
 }
 
+- (void) setFullGrab:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaView: setFullGrab\n");
+
+    CGEventMask mask = CGEventMaskBit(kCGEventKeyDown) |
 CGEventMaskBit(kCGEventKeyUp) | CGEventMaskBit(kCGEventFlagsChanged);
+    eventsTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap,
 kCGEventTapOptionDefault,
+                                 mask, handleTapEvent, self);
+    if (!eventsTap) {
+        warn_report("Could not create event tap, system key combos will
 not be captured.\n");
+        return;
+    } else {
+        COCOA_DEBUG("Global events tap created! Will capture system key

combos.\n");

ui/cocoa.m +5 -0
+    }
+
+    CFRunLoopRef runLoop = CFRunLoopGetCurrent();
+    if (!runLoop) {
+        warn_report("Could not obtain current CF RunLoop, system key

combos will not be captured.\n");

ui/cocoa.m +4 -0
+        return;
+    }
+
+    CFRunLoopSourceRef tapEventsSrc =

CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventsTap, 0);

ui/cocoa.m +2 -0
+    if (!tapEventsSrc ) {
+        warn_report("Could not obtain current CF RunLoop, system key

combos will not be captured.\n");

ui/cocoa.m +21 -1
+        return;
+    }
+
+    CFRunLoopAddSource(runLoop, tapEventsSrc, kCFRunLoopDefaultMode);
+    CFRelease(tapEventsSrc);
+}
+
 - (void) toggleKey: (int)keycode {
     qkbd_state_key_event(kbd, keycode, !qkbd_state_key_get(kbd, keycode));
 }
@@ -1284,6 +1334,13 @@ QemuCocoaView *cocoaView;
     [cocoaView toggleFullScreen:sender];
 }
 
+- (void) setFullGrab:(id)sender
+{
+    COCOA_DEBUG("QemuCocoaAppController: setFullGrab\n");
+
+    [cocoaView setFullGrab:sender];
+}
+
 /* Tries to find then open the specified filename */
 - (void) openDocumentation: (NSString *) filename
 {
@@ -2060,11 +2117,17 @@ static void cocoa_display_init(DisplayState *ds,
 DisplayOptions *opts)
     qemu_sem_wait(&app_started_sem);
     COCOA_DEBUG("cocoa_display_init: app start completed\n");
 
+    QemuCocoaAppController *controller = (QemuCocoaAppController
 *)[[NSApplication sharedApplication] delegate];
     /* if fullscreen mode is to be used */
     if (opts->has_full_screen && opts->full_screen) {
         dispatch_async(dispatch_get_main_queue(), ^{
             [NSApp activateIgnoringOtherApps: YES];
-            [(QemuCocoaAppController *)[[NSApplication sharedApplication]
 delegate] toggleFullScreen: nil];
+            [controller toggleFullScreen: nil];
+        });
+    }
+    if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) {
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [controller setFullGrab: nil];
         });
     }

--
2.34.1

#8 lore raw

Re: [PATCH v7 06/22] hvf: Fix OOB write in RDTSCP instruction decode

In reply to Philippe Mathieu-Daudé

Hi Paolo,

I forgot to Cc you. Could you Ack this patch?

Quoted 106 lines · Philippe Mathieu-Daudé

From: Cameron Esfahani <[email protected]>

A guest could craft a specific stream of instructions that will have QEMU write 0xF9 to inappropriate locations in memory. Add additional asserts to check for this. Generate a #UD if there are more than 14 prefix bytes.

Found by Julian Stecklina <[email protected]>

Message-Id: <[email protected]>

---
  target/i386/hvf/x86_decode.c | 12 ++++++++++--
  target/i386/hvf/x86hvf.c     |  8 ++++++++
  target/i386/hvf/x86hvf.h     |  1 +
  3 files changed, 19 insertions(+), 2 deletions(-)
target/i386/hvf/x86_decode.c +10 -2
index 062713b1a4..5d051252b4 100644
@@ -24,8 +24,10 @@
  #include "vmx.h"
  #include "x86_mmu.h"
  #include "x86_descr.h"
+#include "x86hvf.h"
 
  #define OPCODE_ESCAPE   0xf
+#define X86_MAX_INSN_PREFIX_LENGTH (14)
 
  static void decode_invalid(CPUX86State *env, struct x86_decode *decode)
  {
@@ -541,7 +543,8 @@ static void decode_lidtgroup(CPUX86State *env, struct x86_decode *decode)
      };
      decode->cmd = group[decode->modrm.reg];
      if (0xf9 == decode->modrm.modrm) {
-        decode->opcode[decode->len++] = decode->modrm.modrm;
+        VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
+        decode->opcode[decode->opcode_len++] = decode->modrm.modrm;
          decode->cmd = X86_DECODE_CMD_RDTSCP;
      }
  }
@@ -1847,7 +1850,8 @@ void calc_modrm_operand(CPUX86State *env, struct x86_decode *decode,
 
  static void decode_prefix(CPUX86State *env, struct x86_decode *decode)
  {
-    while (1) {
+    /* At most X86_MAX_INSN_PREFIX_LENGTH prefix bytes. */
+    for (int i = 0; i < X86_MAX_INSN_PREFIX_LENGTH; i++) {
          /*
           * REX prefix must come after legacy prefixes.
           * REX before legacy is ignored.
@@ -1892,6 +1896,8 @@ static void decode_prefix(CPUX86State *env, struct x86_decode *decode)
              return;
          }
      }
+    /* Too many prefixes!  Generate #UD. */
+    hvf_inject_ud(env);
  }
 
  void set_addressing_size(CPUX86State *env, struct x86_decode *decode)
@@ -2090,11 +2096,13 @@ static void decode_opcodes(CPUX86State *env, struct x86_decode *decode)
      uint8_t opcode;
 
      opcode = decode_byte(env, decode);
+    VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
      decode->opcode[decode->opcode_len++] = opcode;
      if (opcode != OPCODE_ESCAPE) {
          decode_opcode_1(env, decode, opcode);
      } else {
          opcode = decode_byte(env, decode);
+        VM_PANIC_ON(decode->opcode_len >= sizeof(decode->opcode));
          decode->opcode[decode->opcode_len++] = opcode;
          decode_opcode_2(env, decode, opcode);
      }
target/i386/hvf/x86hvf.c +8 -0
index bec9fc5814..a338c207b7 100644
@@ -423,6 +423,14 @@ bool hvf_inject_interrupts(CPUState *cpu_state)
              & (CPU_INTERRUPT_INIT | CPU_INTERRUPT_TPR));
  }
 
+void hvf_inject_ud(CPUX86State *env)
+{
+    env->exception_nr = EXCP06_ILLOP;
+    env->exception_injected = 1;
+    env->has_error_code = false;
+    env->error_code = 0;
+}
+
  int hvf_process_events(CPUState *cpu_state)
  {
      X86CPU *cpu = X86_CPU(cpu_state);
target/i386/hvf/x86hvf.h +1 -0
index db6003d6bd..427cdc1c13 100644
@@ -22,6 +22,7 @@
 
  int hvf_process_events(CPUState *);
  bool hvf_inject_interrupts(CPUState *);
+void hvf_inject_ud(CPUX86State *);
  void hvf_set_segment(struct CPUState *cpu, struct vmx_segment *vmx_seg,
                       SegmentCache *qseg, bool is_tr);
  void hvf_get_segment(SegmentCache *qseg, struct vmx_segment *vmx_seg);
#34 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

In reply to Philippe Mathieu-Daudé

Hi Alex, Thomas, Daniel,

Could you ack this patch?

Quoted 80 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Add support for macOS 12 build on Cirrus-CI, similarly to commit 0e103a65ba1 ("gitlab: support for ... macOS 11 via cirrus-run"), but with the following differences:
- Enable modules (configure --enable-modules)
- Do not run softfloat3 tests (make check-softfloat)
- Run Aarch64 qtests instead of x86_64 ones

Generate the vars file by calling 'make lcitool-refresh'.

---
  .gitlab-ci.d/cirrus.yml           | 16 ++++++++++++++++
  .gitlab-ci.d/cirrus/macos-12.vars | 16 ++++++++++++++++
  tests/lcitool/refresh             |  1 +
  3 files changed, 33 insertions(+)

create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars

.gitlab-ci.d/cirrus.yml +16 -0
index b96b22e269..be1dce5d4e 100644
@@ -87,6 +87,22 @@ x64-macos-11-base-build:
      PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/ncurses/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig
      TEST_TARGETS: check-unit check-block check-qapi-schema check-softfloat check-qtest-x86_64
 
+x64-macos-12-base-build:
+  extends: .cirrus_build_job
+  variables:
+    NAME: macos-12
+    CIRRUS_VM_INSTANCE_TYPE: osx_instance
+    CIRRUS_VM_IMAGE_SELECTOR: image
+    CIRRUS_VM_IMAGE_NAME: monterey-base
+    CIRRUS_VM_CPUS: 12
+    CIRRUS_VM_RAM: 24G
+    UPDATE_COMMAND: brew update
+    INSTALL_COMMAND: brew install
+    PATH_EXTRA: /usr/local/opt/ccache/libexec:/usr/local/opt/gettext/bin
+    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/ncurses/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig
+    CONFIGURE_ARGS: --enable-modules
+    TEST_TARGETS: check-unit check-block check-qapi-schema check-qtest-aarch64
+
 
  # The following jobs run VM-based tests via KVM on a Linux-based Cirrus-CI job
  .cirrus_kvm_job:
.gitlab-ci.d/cirrus/macos-12.vars new file +16 -0
new file mode 100644
index 0000000000..a793258c64
@@ -0,0 +1,16 @@
+# THIS FILE WAS AUTO-GENERATED
+#
+#  $ lcitool variables macos-12 qemu
+#
+# https://gitlab.com/libvirt/libvirt-ci
+
+CCACHE='/usr/local/bin/ccache'
+CPAN_PKGS='Test::Harness'
+CROSS_PKGS=''
+MAKE='/usr/local/bin/gmake'
+NINJA='/usr/local/bin/ninja'
+PACKAGING_COMMAND='brew'
+PIP3='/usr/local/bin/pip3'
+PKGS='bash bc bzip2 capstone ccache cpanminus ctags curl dbus diffutils dtc gcovr gettext git glib gnu-sed gnutls gtk+3 jemalloc jpeg-turbo libepoxy libffi libgcrypt libiscsi libnfs libpng libslirp libssh libtasn1 libusb llvm lzo make meson ncurses nettle ninja perl pixman pkg-config python3 rpm2cpio sdl2 sdl2_image snappy sparse spice-protocol tesseract texinfo usbredir vde vte3 zlib zstd'
+PYPI_PKGS='PyYAML numpy pillow sphinx sphinx-rtd-theme virtualenv'
+PYTHON='/usr/local/bin/python3'
tests/lcitool/refresh +1 -0
index 1f00281b44..e2f0bbd1b1 100755
@@ -105,6 +105,7 @@ try:
     generate_cirrus("freebsd-12")
     generate_cirrus("freebsd-13")
     generate_cirrus("macos-11")
+   generate_cirrus("macos-12")
 
     sys.exit(0)
  except Exception as ex:
Reviewed-by on v7 22/22
#43 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Add support for macOS 12 build on Cirrus-CI, similarly to commit 0e103a65ba1 ("gitlab: support for ... macOS 11 via cirrus-run"), but with the following differences:
- Enable modules (configure --enable-modules)
- Do not run softfloat3 tests (make check-softfloat)
- Run Aarch64 qtests instead of x86_64 ones

Generate the vars file by calling 'make lcitool-refresh'.

Quoted 7 lines
---
 .gitlab-ci.d/cirrus.yml           | 16 ++++++++++++++++
 .gitlab-ci.d/cirrus/macos-12.vars | 16 ++++++++++++++++
 tests/lcitool/refresh             |  1 +
 3 files changed, 33 insertions(+)
 create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Acked-by on v7 2/22
#3 lore raw

Re: [PATCH v7 02/22] tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives

In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Since we already use -Wno-unknown-pragmas, we can also use -Wno-ignored-pragmas. This silences hundred of warnings using clang 13 on macOS Monterey:

[409/771] Compiling C object tests/fp/libtestfloat.a.p/berkeley-testfloat-3_source_test_az_f128_rx.c.o ../tests/fp/berkeley-testfloat-3/source/test_az_f128_rx.c:49:14: warning: '#pragma FENV_ACCESS' is not supported on this target - ignored [-Wignored-pragmas] #pragma STDC FENV_ACCESS ON

               ^

1 warning generated.

Having:

Quoted 7 lines
  $ cc -v
  Apple clang version 13.0.0 (clang-1300.0.29.30)
Signature · 1 line
Alex Bennée
#35 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

In reply to Philippe Mathieu-Daudé
Quoted 3 lines · Philippe Mathieu-Daudé

Hi Alex, Thomas, Daniel,

Could you ack this patch?

Basically fine for me, but can we really run additional cirrus-ci jobs by default? IIRC the parallel execution of those were quite limited for the free tier, so did you look close that we don't run into additional timeouts yet, due to delayed cirrus-ci jobs?

Thomas

Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 18 lines

From: Philippe Mathieu-Daudé <[email protected]>

Add support for macOS 12 build on Cirrus-CI, similarly to commit 0e103a65ba1 ("gitlab: support for ... macOS 11 via cirrus-run"), but with the following differences:
  - Enable modules (configure --enable-modules)
  - Do not run softfloat3 tests (make check-softfloat)
  - Run Aarch64 qtests instead of x86_64 ones

Generate the vars file by calling 'make lcitool-refresh'.

---
  .gitlab-ci.d/cirrus.yml           | 16 ++++++++++++++++ .gitlab-ci.d/cirrus/macos-12.vars | 16 ++++++++++++++++ tests/lcitool/refresh             |  1 +

  3 files changed, 33 insertions(+)

  create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars

#36 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 9 lines · Thomas Huth
Quoted 3 lines · Philippe Mathieu-Daudé

Hi Alex, Thomas, Daniel,

Could you ack this patch?

Basically fine for me, but can we really run additional cirrus-ci jobs by default? IIRC the parallel execution of those were quite limited for the free tier, so did you look close that we don't run into additional timeouts yet, due to delayed cirrus-ci jobs?

You can run 2 jobs in parallel in Cirrus. Beyond that they get queued/serialized

We have a 1 hour job timeout.

We have to expect jobs will sometimes run slower than normal.

IOW if we have a job on Cirrus taking 30 minutes normally, we expect it will sometimes take 45 minutes.

All this means that if we want Cirrus to be reliable and not time out, we can really only have 2 jobs by default, unless we can get the job execution time down to around 20 minutes to allow for serialization.

We used to have terrible problems with cirrus timeouts when we were running 4 jobs concurrently (2 on staging and 2 on master). We addressed that in 9968de0a4a5470bd7b98dcd2fae5d5269908f16b by disabling the jobs on master.

IOW, we really need to choose 1 macOS job and 1 FreeBSD job and others need to be marked manual.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#37 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 22 lines · Daniel P. Berrangé
Quoted 4 lines · Thomas Huth

Basically fine for me, but can we really run additional cirrus-ci jobs by default? IIRC the parallel execution of those were quite limited for the free tier, so did you look close that we don't run into additional timeouts yet, due to delayed cirrus-ci jobs?

You can run 2 jobs in parallel in Cirrus. Beyond that they get queued/serialized

We have a 1 hour job timeout.

We have to expect jobs will sometimes run slower than normal.

IOW if we have a job on Cirrus taking 30 minutes normally, we expect it will sometimes take 45 minutes.

All this means that if we want Cirrus to be reliable and not time out, we can really only have 2 jobs by default, unless we can get the job execution time down to around 20 minutes to allow for serialization.

Quoted 7 lines

We used to have terrible problems with cirrus timeouts when we were running 4 jobs concurrently (2 on staging and 2 on master). We addressed that in 9968de0a4a5470bd7b98dcd2fae5d5269908f16b by disabling the jobs on master.

IOW, we really need to choose 1 macOS job and 1 FreeBSD job and others need to be marked manual.

Not sure which job to choose yet. Per the first google hits we still want to cover Catalina first:
https://www.statista.com/statistics/944559/worldwide-macos-version-market-share/

Would it be beneficial to have a 1 per OS job during PR, and other jobs run nightly (once a day, not per PR)?

#38 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 2 lines · Philippe Mathieu-Daudé

Would it be beneficial to have a 1 per OS job during PR, and other jobs run nightly (once a day, not per PR)?

Is there a way to trigger nightly runs in gitlab?

Thomas

#39 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 6 lines · Thomas Huth
Quoted 2 lines · Philippe Mathieu-Daudé

Would it be beneficial to have a 1 per OS job during PR, and other jobs run nightly (once a day, not per PR)?

Is there a way to trigger nightly runs in gitlab?

Yes, in the repo CI settings create a scheduled job, using cron syntax. Relies on the job "rules" in the config file not excluding scheduled execution of course.

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#40 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

In reply to Philippe Mathieu-Daudé
Quoted 28 lines · Philippe Mathieu-Daudé
Quoted 27 lines · Daniel P. Berrangé
Quoted 4 lines · Thomas Huth

Basically fine for me, but can we really run additional cirrus-ci jobs by default? IIRC the parallel execution of those were quite limited for the free tier, so did you look close that we don't run into additional timeouts yet, due to delayed cirrus-ci jobs?

You can run 2 jobs in parallel in Cirrus. Beyond that they get queued/serialized

We have a 1 hour job timeout.

We have to expect jobs will sometimes run slower than normal.

IOW if we have a job on Cirrus taking 30 minutes normally, we expect it will sometimes take 45 minutes.

All this means that if we want Cirrus to be reliable and not time out, we can really only have 2 jobs by default, unless we can get the job execution time down to around 20 minutes to allow for serialization.

We used to have terrible problems with cirrus timeouts when we were running 4 jobs concurrently (2 on staging and 2 on master). We addressed that in 9968de0a4a5470bd7b98dcd2fae5d5269908f16b by disabling the jobs on master.

Quoted 6 lines
Quoted 2 lines

IOW, we really need to choose 1 macOS job and 1 FreeBSD job and others need to be marked manual.

Not sure which job to choose yet. Per the first google hits we still want to cover Catalina first:
https://www.statista.com/statistics/944559/worldwide-macos-version-market-share/

My general gut feeling is usually to prioritize testing older versions as they tend to be more widely used, and we want to avoid regresions on stuff that has been around the longest. Compatibility problems with new releases tend to get reported by users/maintainers and would not be regressions, but rather enhancements to support the new platform.

But it is not really an easy decision, as clearly we would prefer to test both old and new if we had the ability.

Having one as a nightly job is a reasonable compromise.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#41 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 5 lines · Daniel P. Berrangé
Quoted 3 lines · Philippe Mathieu-Daudé

Not sure which job to choose yet. Per the first google hits we still want to cover Catalina first:
https://www.statista.com/statistics/944559/worldwide-macos-version-market-share/

...that page says that the figures for Catalina are "incorrectly high", so not a very useful set of data for these purposes I think.

Quoted 5 lines

My general gut feeling is usually to prioritize testing older versions as they tend to be more widely used, and we want to avoid regresions on stuff that has been around the longest. Compatibility problems with new releases tend to get reported by users/maintainers and would not be regressions, but rather enhancements to support the new platform.

Note that technically speaking Catalina (10.15) has already fallen off the end of our support policy (which currently requires Big Sur (11) and Monterey (12) support, as the two most recent versions). My personal macos x86 laptop is still running Catalina, though, because Big Sur dropped support for that hardware :-/
That suggests that maybe Big Sur would be what we should go for now if we have to pick just one for the CI.

thanks
-- PMM

#42 lore raw

Re: [PATCH v7 22/22] gitlab-ci: Support macOS 12 via cirrus-run

Quoted 16 lines · Peter Maydell
Quoted 5 lines · Daniel P. Berrangé
Quoted 3 lines · Philippe Mathieu-Daudé

Not sure which job to choose yet. Per the first google hits we still want to cover Catalina first:
https://www.statista.com/statistics/944559/worldwide-macos-version-market-share/

...that page says that the figures for Catalina are "incorrectly high", so not a very useful set of data for these purposes I think.

Quoted 5 lines

My general gut feeling is usually to prioritize testing older versions as they tend to be more widely used, and we want to avoid regresions on stuff that has been around the longest. Compatibility problems with new releases tend to get reported by users/maintainers and would not be regressions, but rather enhancements to support the new platform.

Quoted 7 lines

Note that technically speaking Catalina (10.15) has already fallen off the end of our support policy (which currently requires Big Sur (11) and Monterey (12) support, as the two most recent versions). My personal macos x86 laptop is still running Catalina, though, because Big Sur dropped support for that hardware :-/
That suggests that maybe Big Sur would be what we should go for now if we have to pick just one for the CI.

OK. Since I'm running Monterey (12) on my workstation, I'll make this job manual / nightly, and keep the Big Sur (11) on CI.

I'll let Daniel / Thomas / Alex decide which FreeBSD job to demote to manual.

Regards,

Phil.

#44 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Few patches to be able to build QEMU on macOS 12 (Monterey).

Quoted 10 lines

Missing review:
0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0013-osdep-Avoid-using-Clang-specific-__builtin_available.patch 0014-meson-Resolve-the-entitlement.sh-script-once-for-goo.patch 0015-meson-Log-QEMU_CXXFLAGS-content-in-summary.patch 0016-configure-Pass-filtered-QEMU_OBJCFLAGS-to-meson.patch 0017-ui-cocoa-Constify-qkeycode-translation-arrays.patch 0020-ui-cocoa-capture-all-keys-and-combos-when-mouse-is-g.patch 0021-ui-cocoa-add-option-to-swap-Option-and-Command.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Queuing reviewed patches; IOW all except:

0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Thanks,

Phil.

#10 lore raw

Re: [PATCH v7 06/22] hvf: Fix OOB write in RDTSCP instruction decode

In reply to Peter Maydell
Quoted 11 lines · Peter Maydell
Quoted 4 lines · Philippe Mathieu-Daudé

Hi Paolo,

I forgot to Cc you. Could you Ack this patch?

I had review comments on the version of this patch in v5 which still need to be addressed:

https://lore.kernel.org/qemu-devel/CAFEAcA8yaBOD3KXc-DY94oqzC5wkCENPkePgVCybqR=9NmdQFQ@mail.gmail.com/

Thanks for pointing at your comments, I totally missed them.

I'll let Cameron address them.

Regards,

Phil.

#45 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 15 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Few patches to be able to build QEMU on macOS 12 (Monterey).

Missing review:
0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0013-osdep-Avoid-using-Clang-specific-__builtin_available.patch 0014-meson-Resolve-the-entitlement.sh-script-once-for-goo.patch 0015-meson-Log-QEMU_CXXFLAGS-content-in-summary.patch 0016-configure-Pass-filtered-QEMU_OBJCFLAGS-to-meson.patch 0017-ui-cocoa-Constify-qkeycode-translation-arrays.patch 0020-ui-cocoa-capture-all-keys-and-combos-when-mouse-is-g.patch 0021-ui-cocoa-add-option-to-swap-Option-and-Command.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Quoted 5 lines

Since v6:
- Dropped merged patches
- Addressed Akihiko Odaki comments (squashed 2 patches, added R/T-b)
- Dropped 'configure: Disable out-of-line atomic operations on Aarch64'
- Add few macos patches on the list pending for 7.0 so tested by CI

Hi Philippe, I did not find v6 somehow,

and I was looking for patch:

"[PATCH v5 06/16] hvf: Enable RDTSCP support"

was it dropped / merged with something else? I do not see it in latest git, nor in this respin, maybe it is in your tree somewhere?

Thanks,

Claudio

Quoted 81 lines

Since v5:
- Fixed failed rebase between patches 10 and 16 (Akihiko)
- Include "ui/cocoa: Fix the leak of qemu_console_get_label"

Since v4:
- Use MAC_OS_X_VERSION_MIN_REQUIRED definition (Akihiko)
- Include patches from Akihiko

Since v3:
- Fix --enable-modules
- Ignore #pragma on softfloat3 tests
- Addressed Akihiko Odaki comments
- Include Cameron Esfahani patches

Since v2:
- Addressed Akihiko Odaki comments:
. use __is_identifier(),
. remove cocoa setAllowedFileTypes()
- Addressed Daniel Berrangé comment:
. rebased on testing/next, update libvirt-ci/lcitool

Akihiko Odaki (2):
audio: Log context for audio bug
coreaudio: Always return 0 in handle_voice_change

Cameron Esfahani (2):
hvf: Use standard CR0 and CR4 register definitions
hvf: Fix OOB write in RDTSCP instruction decode

Carwyn Ellis (2):
ui/cocoa: add option to disable left-command forwarding to guest ui/cocoa: release mouse when user switches away from QEMU window

Gustavo Noronha Silva (2):
ui/cocoa: capture all keys and combos when mouse is grabbed ui/cocoa: add option to swap Option and Command

Philippe Mathieu-Daudé (14):
configure: Allow passing extra Objective C compiler flags tests/fp/berkeley-testfloat-3: Ignore ignored #pragma directives
hvf: Make hvf_get_segments() / hvf_put_segments() local
hvf: Remove deprecated hv_vcpu_flush() calls block/file-posix: Remove a deprecation warning on macOS 12 audio/coreaudio: Remove a deprecation warning on macOS 12 audio/dbus: Fix building with modules on macOS
audio: Rename coreaudio extension to use Objective-C compiler
osdep: Avoid using Clang-specific __builtin_available()
meson: Resolve the entitlement.sh script once for good
meson: Log QEMU_CXXFLAGS content in summary
configure: Pass filtered QEMU_OBJCFLAGS to meson ui/cocoa: Constify qkeycode translation arrays
gitlab-ci: Support macOS 12 via cirrus-run

 .gitlab-ci.d/cirrus.yml            |  16 ++++
 .gitlab-ci.d/cirrus/macos-12.vars  |  16 ++++
 audio/audio.c                      |  25 +++---
 audio/audio_template.h             |  27 +++----
 audio/{coreaudio.c => coreaudio.m} |  23 +++---
 audio/meson.build                  |   4 +-
 block/file-posix.c                 |  14 +++-
 configure                          |  31 ++++++++
 include/qemu/osdep.h               |  10 +--
 meson.build                        |  17 +++-
 qapi/ui.json                       |  29 +++++++
 qemu-options.hx                    |  15 ++++
 target/i386/hvf/vmx.h              |  19 +++--
 target/i386/hvf/x86.c              |   6 +-
 target/i386/hvf/x86.h              |  34 --------
 target/i386/hvf/x86_decode.c       |  12 ++-
 target/i386/hvf/x86_mmu.c          |   2 +-
 target/i386/hvf/x86_task.c         |   4 +-
 target/i386/hvf/x86hvf.c           |  14 +++-
 target/i386/hvf/x86hvf.h           |   3 +-
 tests/fp/meson.build               |   5 ++
 tests/lcitool/refresh              |   1 +
 ui/cocoa.m                         | 122 ++++++++++++++++++++++++++---
 23 files changed, 327 insertions(+), 122 deletions(-)
 create mode 100644 .gitlab-ci.d/cirrus/macos-12.vars
 rename audio/{coreaudio.c => coreaudio.m} (97%)
#46 lore raw
Quoted 23 lines · Claudio Fontana
Quoted 15 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Few patches to be able to build QEMU on macOS 12 (Monterey).

Missing review:
0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0013-osdep-Avoid-using-Clang-specific-__builtin_available.patch 0014-meson-Resolve-the-entitlement.sh-script-once-for-goo.patch 0015-meson-Log-QEMU_CXXFLAGS-content-in-summary.patch 0016-configure-Pass-filtered-QEMU_OBJCFLAGS-to-meson.patch 0017-ui-cocoa-Constify-qkeycode-translation-arrays.patch 0020-ui-cocoa-capture-all-keys-and-combos-when-mouse-is-g.patch 0021-ui-cocoa-add-option-to-swap-Option-and-Command.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Quoted 5 lines

Since v6:
- Dropped merged patches
- Addressed Akihiko Odaki comments (squashed 2 patches, added R/T-b)
- Dropped 'configure: Disable out-of-line atomic operations on Aarch64'
- Add few macos patches on the list pending for 7.0 so tested by CI

Quoted 8 lines

Hi Philippe, I did not find v6 somehow,

and I was looking for patch:

"[PATCH v5 06/16] hvf: Enable RDTSCP support"

was it dropped / merged with something else? I do not see it in latest git, nor in this respin, maybe it is in your tree somewhere?

The patch stayed unreviewed during 2 months, so I dropped it.

Now it got at least a Tested-by tag from Silvio, I'll include it in the next PR.

Regards,

Phil.

#47 lore raw
Quoted 33 lines · Philippe Mathieu-Daudé
Quoted 23 lines · Claudio Fontana
Quoted 15 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Few patches to be able to build QEMU on macOS 12 (Monterey).

Missing review:
0006-hvf-Fix-OOB-write-in-RDTSCP-instruction-decode.patch 0013-osdep-Avoid-using-Clang-specific-__builtin_available.patch 0014-meson-Resolve-the-entitlement.sh-script-once-for-goo.patch 0015-meson-Log-QEMU_CXXFLAGS-content-in-summary.patch 0016-configure-Pass-filtered-QEMU_OBJCFLAGS-to-meson.patch 0017-ui-cocoa-Constify-qkeycode-translation-arrays.patch 0020-ui-cocoa-capture-all-keys-and-combos-when-mouse-is-g.patch 0021-ui-cocoa-add-option-to-swap-Option-and-Command.patch 0022-gitlab-ci-Support-macOS-12-via-cirrus-run.patch

Quoted 5 lines

Since v6:
- Dropped merged patches
- Addressed Akihiko Odaki comments (squashed 2 patches, added R/T-b)
- Dropped 'configure: Disable out-of-line atomic operations on Aarch64'
- Add few macos patches on the list pending for 7.0 so tested by CI

Quoted 8 lines

Hi Philippe, I did not find v6 somehow,

and I was looking for patch:

"[PATCH v5 06/16] hvf: Enable RDTSCP support"

was it dropped / merged with something else? I do not see it in latest git, nor in this respin, maybe it is in your tree somewhere?

Quoted 9 lines

The patch stayed unreviewed during 2 months, so I dropped it.

Now it got at least a Tested-by tag from Silvio, I'll include it in the next PR.

Regards,

Phil.

Awesome, thanks for the update!

Claudio