mbox series

[v2,00/29] tcg: Workaround macOS 11.2 mprotect bug

Message ID 20210314212724.1917075-1-richard.henderson@linaro.org
Headers show
Series tcg: Workaround macOS 11.2 mprotect bug | expand

Message

Richard Henderson March 14, 2021, 9:26 p.m. UTC
Changes for v2:
  * Move tcg_init_ctx someplace more private (patch 29)
  * Round result of tb_size based on qemu_get_host_physmem (patch 26)

Blurb for v1:
  It took a few more patches than imagined to unify the two
  places in which we manipulate the tcg code_gen buffer, but
  the result is surely cleaner.

  There's a lot more that could be done to clean up this part
  of tcg too.  I tried to not get too side-tracked, but didn't
  wholly succeed.


r~


Richard Henderson (29):
  meson: Split out tcg/meson.build
  meson: Split out fpu/meson.build
  tcg: Re-order tcg_region_init vs tcg_prologue_init
  tcg: Remove error return from tcg_region_initial_alloc__locked
  tcg: Split out tcg_region_initial_alloc
  tcg: Split out tcg_region_prologue_set
  tcg: Split out region.c
  accel/tcg: Inline cpu_gen_init
  accel/tcg: Move alloc_code_gen_buffer to tcg/region.c
  accel/tcg: Rename tcg_init to tcg_init_machine
  tcg: Create tcg_init
  accel/tcg: Merge tcg_exec_init into tcg_init_machine
  accel/tcg: Pass down max_cpus to tcg_init
  tcg: Introduce tcg_max_ctxs
  tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h
  tcg: Replace region.end with region.total_size
  tcg: Rename region.start to region.after_prologue
  tcg: Tidy tcg_n_regions
  tcg: Tidy split_cross_256mb
  tcg: Move in_code_gen_buffer and tests to region.c
  tcg: Allocate code_gen_buffer into struct tcg_region_state
  tcg: Return the map protection from alloc_code_gen_buffer
  tcg: Sink qemu_madvise call to common code
  tcg: Do not set guard pages in the rx buffer
  util/osdep: Add qemu_mprotect_rw
  tcg: Round the tb_size default from qemu_get_host_physmem
  tcg: Merge buffer protection and guard page protection
  tcg: When allocating for !splitwx, begin with PROT_NONE
  tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/

 meson.build               |  13 +-
 accel/tcg/internal.h      |   2 +
 include/qemu/osdep.h      |   1 +
 include/sysemu/tcg.h      |   2 -
 include/tcg/tcg.h         |  15 +-
 tcg/aarch64/tcg-target.h  |   1 +
 tcg/arm/tcg-target.h      |   1 +
 tcg/i386/tcg-target.h     |   2 +
 tcg/internal.h            |  40 ++
 tcg/mips/tcg-target.h     |   6 +
 tcg/ppc/tcg-target.h      |   2 +
 tcg/riscv/tcg-target.h    |   1 +
 tcg/s390/tcg-target.h     |   3 +
 tcg/sparc/tcg-target.h    |   1 +
 tcg/tci/tcg-target.h      |   1 +
 accel/tcg/tcg-all.c       |  33 +-
 accel/tcg/translate-all.c | 439 +----------------
 bsd-user/main.c           |   1 -
 linux-user/main.c         |   1 -
 tcg/region.c              | 991 ++++++++++++++++++++++++++++++++++++++
 tcg/tcg.c                 | 634 ++----------------------
 util/osdep.c              |   9 +
 fpu/meson.build           |   1 +
 tcg/meson.build           |  14 +
 24 files changed, 1139 insertions(+), 1075 deletions(-)
 create mode 100644 tcg/internal.h
 create mode 100644 tcg/region.c
 create mode 100644 fpu/meson.build
 create mode 100644 tcg/meson.build

-- 
2.25.1

Comments

no-reply@patchew.org March 14, 2021, 10:12 p.m. UTC | #1
Patchew URL: https://patchew.org/QEMU/20210314212724.1917075-1-richard.henderson@linaro.org/



Hi,

This series seems to have some coding style problems. See output below for
more information:

Type: series
Message-id: 20210314212724.1917075-1-richard.henderson@linaro.org
Subject: [PATCH v2 00/29] tcg: Workaround macOS 11.2 mprotect bug

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
 - [tag update]      patchew/20210314163927.1184-1-peter.maydell@linaro.org -> patchew/20210314163927.1184-1-peter.maydell@linaro.org
 * [new tag]         patchew/20210314212724.1917075-1-richard.henderson@linaro.org -> patchew/20210314212724.1917075-1-richard.henderson@linaro.org
Switched to a new branch 'test'
9906c07 tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/
ef1e2c0 tcg: When allocating for !splitwx, begin with PROT_NONE
76e12ad tcg: Merge buffer protection and guard page protection
1e9c899 tcg: Round the tb_size default from qemu_get_host_physmem
4bdfded util/osdep: Add qemu_mprotect_rw
a1751c5 tcg: Do not set guard pages in the rx buffer
40483ad tcg: Sink qemu_madvise call to common code
856c724 tcg: Return the map protection from alloc_code_gen_buffer
7622097 tcg: Allocate code_gen_buffer into struct tcg_region_state
251d71e tcg: Move in_code_gen_buffer and tests to region.c
a6a064d tcg: Tidy split_cross_256mb
af03a0d tcg: Tidy tcg_n_regions
218436d tcg: Rename region.start to region.after_prologue
9f3981e tcg: Replace region.end with region.total_size
276ecb9 tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h
683f5af tcg: Introduce tcg_max_ctxs
d7bf2f6 accel/tcg: Pass down max_cpus to tcg_init
a1cd412 accel/tcg: Merge tcg_exec_init into tcg_init_machine
4940162 tcg: Create tcg_init
4ab59ad accel/tcg: Rename tcg_init to tcg_init_machine
e27bd38 accel/tcg: Move alloc_code_gen_buffer to tcg/region.c
d4c3608 accel/tcg: Inline cpu_gen_init
2245d5c tcg: Split out region.c
a284234 tcg: Split out tcg_region_prologue_set
d116828 tcg: Split out tcg_region_initial_alloc
c75ce79 tcg: Remove error return from tcg_region_initial_alloc__locked
0df4d6c tcg: Re-order tcg_region_init vs tcg_prologue_init
cc0f7f7 meson: Split out fpu/meson.build
b0a2113 meson: Split out tcg/meson.build

=== OUTPUT BEGIN ===
1/29 Checking commit b0a211318ba3 (meson: Split out tcg/meson.build)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#44: 
new file mode 100644

total: 0 errors, 1 warnings, 35 lines checked

Patch 1/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
2/29 Checking commit cc0f7f7fdc1a (meson: Split out fpu/meson.build)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#16: 
new file mode 100644

total: 0 errors, 1 warnings, 17 lines checked

Patch 2/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
3/29 Checking commit 0df4d6c7ee67 (tcg: Re-order tcg_region_init vs tcg_prologue_init)
4/29 Checking commit c75ce79d8926 (tcg: Remove error return from tcg_region_initial_alloc__locked)
5/29 Checking commit d116828491cc (tcg: Split out tcg_region_initial_alloc)
6/29 Checking commit a284234d3909 (tcg: Split out tcg_region_prologue_set)
7/29 Checking commit 2245d5c83ec4 (tcg: Split out region.c)
Use of uninitialized value $acpi_testexpected in string eq at ./scripts/checkpatch.pl line 1529.
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?
#17: 
new file mode 100644

total: 0 errors, 1 warnings, 1189 lines checked

Patch 7/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
8/29 Checking commit d4c36080e021 (accel/tcg: Inline cpu_gen_init)
9/29 Checking commit e27bd38f652c (accel/tcg: Move alloc_code_gen_buffer to tcg/region.c)
WARNING: Block comments use a leading /* on a separate line
#499: FILE: tcg/region.c:411:
+/* Minimum size of the code gen buffer.  This number is randomly chosen,

WARNING: Block comments use * on subsequent lines
#500: FILE: tcg/region.c:412:
+/* Minimum size of the code gen buffer.  This number is randomly chosen,
+   but not so small that we can't have a fair number of TB's live.  */

WARNING: Block comments use a trailing */ on a separate line
#500: FILE: tcg/region.c:412:
+   but not so small that we can't have a fair number of TB's live.  */

WARNING: Block comments use a leading /* on a separate line
#503: FILE: tcg/region.c:415:
+/* Maximum size of the code gen buffer we'd like to use.  Unless otherwise

WARNING: Block comments use * on subsequent lines
#504: FILE: tcg/region.c:416:
+/* Maximum size of the code gen buffer we'd like to use.  Unless otherwise
+   indicated, this is constrained by the range of direct branches on the

WARNING: Block comments use a trailing */ on a separate line
#505: FILE: tcg/region.c:417:
+   host cpu, as used by the TCG implementation of goto_tb.  */

WARNING: architecture specific defines should be avoided
#506: FILE: tcg/region.c:418:
+#if defined(__x86_64__)

WARNING: Block comments use a leading /* on a separate line
#520: FILE: tcg/region.c:432:
+  /* We have a 256MB branch region, but leave room to make sure the

WARNING: Block comments use * on subsequent lines
#521: FILE: tcg/region.c:433:
+  /* We have a 256MB branch region, but leave room to make sure the
+     main executable is also within that region.  */

WARNING: Block comments use a trailing */ on a separate line
#521: FILE: tcg/region.c:433:
+     main executable is also within that region.  */

WARNING: architecture specific defines should be avoided
#579: FILE: tcg/region.c:491:
+#ifdef __mips__

WARNING: Block comments use a leading /* on a separate line
#580: FILE: tcg/region.c:492:
+/* In order to use J and JAL within the code_gen_buffer, we require

WARNING: Block comments use * on subsequent lines
#581: FILE: tcg/region.c:493:
+/* In order to use J and JAL within the code_gen_buffer, we require
+   that the buffer not cross a 256MB boundary.  */

WARNING: Block comments use a trailing */ on a separate line
#581: FILE: tcg/region.c:493:
+   that the buffer not cross a 256MB boundary.  */

WARNING: Block comments use a leading /* on a separate line
#587: FILE: tcg/region.c:499:
+/* We weren't able to allocate a buffer without crossing that boundary,

WARNING: Block comments use * on subsequent lines
#588: FILE: tcg/region.c:500:
+/* We weren't able to allocate a buffer without crossing that boundary,
+   so make do with the larger portion of the buffer that doesn't cross.

WARNING: Block comments use a trailing */ on a separate line
#589: FILE: tcg/region.c:501:
+   Returns the new base of the buffer, and adjusts code_gen_buffer_size.  */

WARNING: architecture specific defines should be avoided
#634: FILE: tcg/region.c:546:
+#ifdef __mips__

WARNING: architecture specific defines should be avoided
#686: FILE: tcg/region.c:598:
+#ifdef __mips__

WARNING: architecture specific defines should be avoided
#736: FILE: tcg/region.c:648:
+#ifdef __mips__

WARNING: architecture specific defines should be avoided
#753: FILE: tcg/region.c:665:
+#ifdef __mips__

ERROR: externs should be avoided in .c files
#795: FILE: tcg/region.c:707:
+extern kern_return_t mach_vm_remap(vm_map_t target_task,

total: 1 errors, 21 warnings, 895 lines checked

Patch 9/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.

10/29 Checking commit 4ab59ad7fbac (accel/tcg: Rename tcg_init to tcg_init_machine)
11/29 Checking commit 49401622f6bd (tcg: Create tcg_init)
12/29 Checking commit a1cd412ff253 (accel/tcg: Merge tcg_exec_init into tcg_init_machine)
WARNING: Block comments use a leading /* on a separate line
#56: FILE: accel/tcg/tcg-all.c:121:
+    /* There's no guest base to take into account, so go ahead and

WARNING: Block comments use * on subsequent lines
#57: FILE: accel/tcg/tcg-all.c:122:
+    /* There's no guest base to take into account, so go ahead and
+       initialize the prologue now.  */

WARNING: Block comments use a trailing */ on a separate line
#57: FILE: accel/tcg/tcg-all.c:122:
+       initialize the prologue now.  */

total: 0 errors, 3 warnings, 81 lines checked

Patch 12/29 has style problems, please review.  If any of these errors
are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
13/29 Checking commit d7bf2f6c5b84 (accel/tcg: Pass down max_cpus to tcg_init)
14/29 Checking commit 683f5af79dd7 (tcg: Introduce tcg_max_ctxs)
15/29 Checking commit 276ecb9d18cb (tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h)
16/29 Checking commit 9f3981e89b60 (tcg: Replace region.end with region.total_size)
17/29 Checking commit 218436d137c1 (tcg: Rename region.start to region.after_prologue)
18/29 Checking commit af03a0d81294 (tcg: Tidy tcg_n_regions)
19/29 Checking commit a6a064d88d21 (tcg: Tidy split_cross_256mb)
20/29 Checking commit 251d71e63d7f (tcg: Move in_code_gen_buffer and tests to region.c)
21/29 Checking commit 76220971b8cc (tcg: Allocate code_gen_buffer into struct tcg_region_state)
22/29 Checking commit 856c72493829 (tcg: Return the map protection from alloc_code_gen_buffer)
23/29 Checking commit 40483adb7b2e (tcg: Sink qemu_madvise call to common code)
24/29 Checking commit a1751c559ba8 (tcg: Do not set guard pages in the rx buffer)
25/29 Checking commit 4bdfded6d21a (util/osdep: Add qemu_mprotect_rw)
26/29 Checking commit 1e9c89999f44 (tcg: Round the tb_size default from qemu_get_host_physmem)
27/29 Checking commit 76e12ad880b1 (tcg: Merge buffer protection and guard page protection)
28/29 Checking commit ef1e2c0e7aed (tcg: When allocating for !splitwx, begin with PROT_NONE)
29/29 Checking commit 9906c07d1a1e (tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/)
=== OUTPUT END ===

Test command exited with code: 1


The full log is available at
http://patchew.org/logs/20210314212724.1917075-1-richard.henderson@linaro.org/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to patchew-devel@redhat.com
Roman Bolshakov March 15, 2021, 11:08 p.m. UTC | #2
On Sun, Mar 14, 2021 at 03:26:55PM -0600, Richard Henderson wrote:
> Changes for v2:

>   * Move tcg_init_ctx someplace more private (patch 29)

>   * Round result of tb_size based on qemu_get_host_physmem (patch 26)

> 

> Blurb for v1:

>   It took a few more patches than imagined to unify the two

>   places in which we manipulate the tcg code_gen buffer, but

>   the result is surely cleaner.

> 

>   There's a lot more that could be done to clean up this part

>   of tcg too.  I tried to not get too side-tracked, but didn't

>   wholly succeed.

> 

> 


Hi Richard,

Thanks for doing the changes!
I'm not sure if I'll find enough time for thorough review but the series
helps qemu on Big Sur 11.2.3, so:

Tested-by: Roman Bolshakov <r.bolshakov@yadro.com>


Regards,
Roman

> r~

> 

> 

> Richard Henderson (29):

>   meson: Split out tcg/meson.build

>   meson: Split out fpu/meson.build

>   tcg: Re-order tcg_region_init vs tcg_prologue_init

>   tcg: Remove error return from tcg_region_initial_alloc__locked

>   tcg: Split out tcg_region_initial_alloc

>   tcg: Split out tcg_region_prologue_set

>   tcg: Split out region.c

>   accel/tcg: Inline cpu_gen_init

>   accel/tcg: Move alloc_code_gen_buffer to tcg/region.c

>   accel/tcg: Rename tcg_init to tcg_init_machine

>   tcg: Create tcg_init

>   accel/tcg: Merge tcg_exec_init into tcg_init_machine

>   accel/tcg: Pass down max_cpus to tcg_init

>   tcg: Introduce tcg_max_ctxs

>   tcg: Move MAX_CODE_GEN_BUFFER_SIZE to tcg-target.h

>   tcg: Replace region.end with region.total_size

>   tcg: Rename region.start to region.after_prologue

>   tcg: Tidy tcg_n_regions

>   tcg: Tidy split_cross_256mb

>   tcg: Move in_code_gen_buffer and tests to region.c

>   tcg: Allocate code_gen_buffer into struct tcg_region_state

>   tcg: Return the map protection from alloc_code_gen_buffer

>   tcg: Sink qemu_madvise call to common code

>   tcg: Do not set guard pages in the rx buffer

>   util/osdep: Add qemu_mprotect_rw

>   tcg: Round the tb_size default from qemu_get_host_physmem

>   tcg: Merge buffer protection and guard page protection

>   tcg: When allocating for !splitwx, begin with PROT_NONE

>   tcg: Move tcg_init_ctx and tcg_ctx from accel/tcg/

> 

>  meson.build               |  13 +-

>  accel/tcg/internal.h      |   2 +

>  include/qemu/osdep.h      |   1 +

>  include/sysemu/tcg.h      |   2 -

>  include/tcg/tcg.h         |  15 +-

>  tcg/aarch64/tcg-target.h  |   1 +

>  tcg/arm/tcg-target.h      |   1 +

>  tcg/i386/tcg-target.h     |   2 +

>  tcg/internal.h            |  40 ++

>  tcg/mips/tcg-target.h     |   6 +

>  tcg/ppc/tcg-target.h      |   2 +

>  tcg/riscv/tcg-target.h    |   1 +

>  tcg/s390/tcg-target.h     |   3 +

>  tcg/sparc/tcg-target.h    |   1 +

>  tcg/tci/tcg-target.h      |   1 +

>  accel/tcg/tcg-all.c       |  33 +-

>  accel/tcg/translate-all.c | 439 +----------------

>  bsd-user/main.c           |   1 -

>  linux-user/main.c         |   1 -

>  tcg/region.c              | 991 ++++++++++++++++++++++++++++++++++++++

>  tcg/tcg.c                 | 634 ++----------------------

>  util/osdep.c              |   9 +

>  fpu/meson.build           |   1 +

>  tcg/meson.build           |  14 +

>  24 files changed, 1139 insertions(+), 1075 deletions(-)

>  create mode 100644 tcg/internal.h

>  create mode 100644 tcg/region.c

>  create mode 100644 fpu/meson.build

>  create mode 100644 tcg/meson.build

> 

> -- 

> 2.25.1

>