This is an archive of the discontinued LLVM Phabricator instance.

[RISCV][sanitizer] Set SANITIZER_MMAP_RANGE_SIZE for sv57
Needs ReviewPublic

Authored by hauhsu on Jun 14 2023, 10:01 PM.

Details

Summary

This patch enables sanitizers for sv57 virtual memory mode.
Alloctor checks whether SANITIZER_MMAP_RANGE_SIZE matches possible mmap regions:
sanitizer_allocator_primary32.h:292 "((res)) <((kNumPossibleRegions))"

Since SANITIZER_MMAP_RANGE_SIZE only controls "possible" mmap regions,
setting it to (1 << 57) also works for sv39 and sv48.

Depends on D139827

Diff Detail

Event Timeline

hauhsu created this revision.Jun 14 2023, 10:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 14 2023, 10:01 PM
hauhsu added a project: Restricted Project.Jun 14 2023, 10:15 PM
hauhsu published this revision for review.Jun 14 2023, 10:22 PM
Herald added subscribers: Restricted Project, pcwang-thead, eopXD. · View Herald TranscriptJun 14 2023, 10:22 PM

Since SANITIZER_MMAP_RANGE_SIZE only controls "possible" mmap regions, setting it to (1 << 57) also works for sv39 and sv48.

Why is (1 << 57) also supported by Sv48?

Since SANITIZER_MMAP_RANGE_SIZE only controls "possible" mmap regions, setting it to (1 << 57) also works for sv39 and sv48.

Why is (1 << 57) also supported by Sv48?

Without this patch, I encountered runtime error in SV57:

AddressSanitizer: CHECK failed: sanitizer_allocator_primary32.h:292 "((res)) < ((kNumPossibleRegions))" (0xffffffb72, 0x8000000)

I noted that the check comes from the AP32 header, even though we are using RV64.

So I dived a little bit deeper, there are 2 allocators in the sanitizer framework:

  1. internal allocator (sanitizer_allocator_internal.h): used by sanitizer framework internally (like dlsym or deadlock detector). Always AP32.
  2. xSAN allocator: dedicated for a specific sanitizer (asan_allocator.h for example)

And in Sv57, when the test program is initializing, it tries to access a memory larger then (1 << 48), which triggers the error.
In my memory the error occurs when the internal allocator is handling dlsym (https://reviews.llvm.org/D112588).

It seems to me that SANITIZER_MMAP_RANGE_SIZE only controls the largest mmap region.
In Sv48 we won't touch any memory region in Sv57, so setting it to a larger size (1 << 57) won't hurt.

vitalybuka resigned from this revision.Aug 27 2023, 10:23 PM