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

core/config.h: Bump the default WASM_STACK_GUARD_SIZE #3344

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

yamt
Copy link
Collaborator

@yamt yamt commented Apr 23, 2024

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases. But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls host snprintf. (2000 bytes)

Fixes: #3314

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: bytecodealliance#3314
@@ -486,7 +486,7 @@
/* UVWASI requires larger native stack */
#define WASM_STACK_GUARD_SIZE (4096 * 6)
#else
#define WASM_STACK_GUARD_SIZE (1024)
#define WASM_STACK_GUARD_SIZE (1024 * 5)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it better to increase the size only for linux/macos or posix like platforms? Seems that not all platforms need so much guard stack space, e.g. zephyr/esp-idf 32-bit, had better keep it unchanged for them now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe for 32-bit archs it can be a bit smaller. but are you sure 1KB is enough?

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, maybe we can also decrease the native stack usage by refining the code which calls snprintf? For example, in wasm_set_exception_local and set_exception_visitor, copy character one by one from source string until '\0' is found.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe for 32-bit archs it can be a bit smaller. but are you sure 1KB is enough?

I am not sure, my suggestion is to keep it unchanged temporarily, and change it after we do more test.

Copy link
Contributor

Choose a reason for hiding this comment

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

ps. keep it unchanged for non-posix like platforms until we do more test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

maybe for 32-bit archs it can be a bit smaller. but are you sure 1KB is enough?

I am not sure, my suggestion is to keep it unchanged temporarily, and change it after we do more test.

i can probably investigate the situation on xtensa/nuttx. do you think it's good enough to make it represent the "low end" side?

OK, thanks. Distinguish it into high end side and low end side is good to me, do yo think we should put the macro in each platform's platform_internal.h?

maybe. after all, it's very platform dependent.
otoh, i suspect that embedders for very small devices usually fine-tune WASM_STACK_GUARD_SIZE for their specific applications anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, maybe we can also decrease the native stack usage by refining the code which calls snprintf? For example, in wasm_set_exception_local and set_exception_visitor, copy character one by one from source string until '\0' is found.

i agree it's probably a good idea to reduce the stack usage of wasm_runtime_set_exception and friends.

but i'm not sure if we can reduce WASM_STACK_GUARD_SIZE with it unless we introduce a rather strong policy about where os_printf, LOG_DEBUG, etc can be used.

Yes, I think we can increase WASM_STACK_GUARD_SIZE to 5KB and also refine the code in some places to enhance the security. And decrease WASM_STACK_GUARD_SIZE only when we do a full test to make sure it is good.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe for 32-bit archs it can be a bit smaller. but are you sure 1KB is enough?

I am not sure, my suggestion is to keep it unchanged temporarily, and change it after we do more test.

i can probably investigate the situation on xtensa/nuttx. do you think it's good enough to make it represent the "low end" side?

OK, thanks. Distinguish it into high end side and low end side is good to me, do yo think we should put the macro in each platform's platform_internal.h?

maybe. after all, it's very platform dependent. otoh, i suspect that embedders for very small devices usually fine-tune WASM_STACK_GUARD_SIZE for their specific applications anyway.

OK, so had better keep putting the macro in core/config.h, and maybe we can add a document for detailed description about this macro and the native stack overflow check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

reverted for non-posix platforms for now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe. after all, it's very platform dependent. otoh, i suspect that embedders for very small devices usually fine-tune WASM_STACK_GUARD_SIZE for their specific applications anyway.

Agree.

Copy link
Contributor

@wenyongh wenyongh left a comment

Choose a reason for hiding this comment

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

LGTM

@wenyongh wenyongh merged commit 98ad36e into bytecodealliance:main Apr 23, 2024
386 checks passed
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 1, 2024
…ce#3344)

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: bytecodealliance#3314
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 2, 2024
…ce#3344)

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: bytecodealliance#3314
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ce#3344)

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: bytecodealliance#3314
victoryang00 pushed a commit to victoryang00/wamr-aot-gc-checkpoint-restore that referenced this pull request May 27, 2024
…ce#3344)

The old value (1KB) doesn't seem sufficient for many cases.

I suspect that the new value is still not sufficient for some cases.
But it's far safer than the old value.
Consider if the classic interpreter loop (2600 bytes) calls
host snprintf. (2000 bytes)

Fixes: bytecodealliance#3314
Signed-off-by: victoryang00 <victoryang00@ucsc.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

default WASM_STACK_GUARD_SIZE seems too small for linux
3 participants