Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: Enable wasm and allow to load .wasm on Apple silicon #23257

Merged
merged 4 commits into from
Sep 29, 2022

Conversation

dio
Copy link
Member

@dio dio commented Sep 27, 2022

Commit Message: This applies changes from https://chromium-review.googlesource.com/c/v8/v8/+/3700352 as a fix for MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages.

This mainly affects macOS > 11.2 due to mprotect() behavior changes (#23243, https://chromium-review.googlesource.com/c/v8/v8/+/3610445/comment/6294ada3_a3cab643/) on Apple silicon.

This also flips the Wasm feature to be enabled by default on macOS.

The future patch removal task is tracked in #23258.

Signed-off-by: Dhi Aurrahman [email protected]

Additional description:
By applying this patch on my local (macOS, 12.6 (21G115), M1), I can run envoy to load a .wasm from the examples/wasm-cc. Before this patch, it was caught by: EACCESS error. See #23243 for more details.

$ uname -a
Darwin Dhis-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
$ pwd
/Users/dio/src/envoy/examples/wasm-cc
$ ~/src/envoy/bazel-bin/source/exe/envoy-static -c envoy.yaml

Also, I think we need to backport this to release/1.23 (which has the same v8 version), hence the Homebrew build for Apple silicon will have this Wasm feature enabled.

Risk Level: Low, since the current behavior is preserved, and the patch is included on upstream (v8, 10.5-lkgr has it)
Testing: existing, and manual testing on macOS M1
Docs Changes: N/A
Release Notes: N/A (should we add an announcement since we enable wasm by default again?)
Platform Specific Features: enable wasm (v8 runtime) on macOS by default
Fixes #23243

This applies https://chromium-review.googlesource.com/c/v8/v8/+/3700352 as a fix for
MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages.

This mainly affects macOS > 11.2 due to mprotect behavior changes (envoyproxy#23243)
on Apple silicon.

Signed-off-by: Dhi Aurrahman <[email protected]>
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Sep 27, 2022
@repokitteh-read-only
Copy link

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @RyanTheOptimist

🐱

Caused by: #23257 was opened by dio.

see: more, trace.

bazel/v8.patch Outdated
@@ -7,13 +7,15 @@
# 7. Fix build errors in SIMD IndexOf/includes (https://crrev.com/c/3749192).
# 8. Fix build on arm64.
# 9. Fix build on older versions of Linux.
# 10. Fix MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages,
# mainly affecting macOS on Apple silicon (https://chromium-review.googlesource.com/c/v8/v8/+/3700352).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you file an issue to track when this is released?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked here: #23258.

Signed-off-by: Dhi Aurrahman <[email protected]>
lizan
lizan previously approved these changes Sep 27, 2022
@dio
Copy link
Member Author

dio commented Sep 27, 2022

Thanks, @lizan! 🙇🏾

@RyanTheOptimist
Copy link
Contributor

/lgtm deps

@repokitteh-read-only repokitteh-read-only bot removed the deps Approval required for changes to Envoy's external dependencies label Sep 27, 2022
PiotrSikora
PiotrSikora previously approved these changes Sep 28, 2022
Copy link
Contributor

@PiotrSikora PiotrSikora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but quite frankly I'd first try upgrading to v10.6 (or even v10.7, really).

bazel/v8.patch Outdated
const int target_align = 32;
// Scalar loop to reach desired alignment
@@ -256,21 +266,21 @@ TARGET_AVX2 inline uintptr_t fast_search_avx(T* array, uintptr_t array_len,
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This PR contains a dozen of unnecessary (whitespace) changes that make this much less readable, consider unstaging them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry, my editor seems too eager to remove "trailing" whitespaces.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better now, thanks!

Signed-off-by: Dhi Aurrahman <[email protected]>
Signed-off-by: Dhi Aurrahman <[email protected]>
@dio dio dismissed stale reviews from PiotrSikora and lizan via b40a61d September 28, 2022 03:01
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Sep 28, 2022
@dio
Copy link
Member Author

dio commented Sep 28, 2022

@PiotrSikora sure. I'll try. However, since release/1.23 is on this 10.4.132.18 I think we can backport this for release/1.23 first, and not sure if updating deps (with minor release version) can be done in stable branches.

@dio dio requested review from PiotrSikora and lizan and removed request for PiotrSikora and lizan September 28, 2022 03:06
@dio
Copy link
Member Author

dio commented Sep 28, 2022

(sorry for the spammy request for re-reviewing this, seems like there was a glitch on GitHub on my side)

@PiotrSikora
Copy link
Contributor

@PiotrSikora sure. I'll try. However, since release/1.23 is on this 10.4.132.18 I think we can backport this for release/1.23 first, and not sure if updating deps (with minor release version) can be done in stable branches.

Good point. I guess we could merge this (since it's already approved) and then update V8 in a follow-up PR.

@dio
Copy link
Member Author

dio commented Sep 28, 2022

@RyanTheOptimist seems like we need another stamp (for deps).

@RyanTheOptimist
Copy link
Contributor

/lgtm deps

@repokitteh-read-only repokitteh-read-only bot removed the deps Approval required for changes to Envoy's external dependencies label Sep 28, 2022
@dio
Copy link
Member Author

dio commented Sep 28, 2022

@lizan could you help to approve and merge this? 🙇🏾

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks.

@wbpcode wbpcode merged commit 63f27a6 into envoyproxy:main Sep 29, 2022
dio added a commit to dio/envoy that referenced this pull request Sep 29, 2022
…xy#23257)

* macOS: Allow to load .wasm on Apple silicon

This applies https://chromium-review.googlesource.com/c/v8/v8/+/3700352 as a fix for
MemoryAllocator::PartialFreeMemory() which shouldn't try to change permissions of RWX pages.

This mainly affects macOS > 11.2 due to mprotect behavior changes (envoyproxy#23243)
on Apple silicon.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to load .wasm on macOS running on Apple silicon
5 participants