8327971: Multiple ASAN errors reported for metaspace

8327988: When running ASAN, disable dangerous NMT test

Reviewed-by: jsjolen, rkennke
This commit is contained in:
Thomas Stuefe 2024-03-27 08:36:40 +00:00
parent 8fc9097b37
commit 9e566d76d1
9 changed files with 50 additions and 2 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@ -34,6 +34,7 @@
#include "utilities/align.hpp"
#include "utilities/copy.hpp"
#include "utilities/debug.hpp"
#include "utilities/macros.hpp"
#include "utilities/ostream.hpp"
namespace metaspace {
@ -285,7 +286,9 @@ void Metachunk::verify() const {
const size_t required_alignment = word_size() * sizeof(MetaWord);
assert_is_aligned(base(), required_alignment);
// Test accessing the committed area.
// Test accessing the committed area. But not for ASAN. We don't know which portions
// of the chunk are still poisoned.
#if !INCLUDE_ASAN
SOMETIMES(
if (_committed_words > 0) {
for (const MetaWord* p = _base; p < _base + _committed_words; p += os::vm_page_size()) {
@ -294,6 +297,7 @@ void Metachunk::verify() const {
dummy = *(_base + _committed_words - 1);
}
)
#endif // !INCLUDE_ASAN
}
#endif // ASSERT

View File

@ -48,6 +48,7 @@
#include "utilities/align.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
#include "utilities/ostream.hpp"
namespace metaspace {
@ -433,6 +434,9 @@ void VirtualSpaceNode::verify_locked() const {
_commit_mask.verify();
// Verify memory against commit mask.
// Down here, from ASAN's view, this memory may be poisoned, since we only unpoison
// way up at the ChunkManager level.
#if !INCLUDE_ASAN
SOMETIMES(
for (MetaWord* p = base(); p < base() + used_words(); p += os::vm_page_size()) {
if (_commit_mask.is_committed_address(p)) {
@ -440,6 +444,7 @@ void VirtualSpaceNode::verify_locked() const {
}
}
)
#endif // !INCLUDE_ASAN
assert(committed_words() <= word_size(), "Sanity");
assert_is_aligned(committed_words(), Settings::commit_granule_words());

View File

@ -40,6 +40,7 @@
#include "runtime/safefetch.hpp"
#include "services/mallocLimit.hpp"
#include "utilities/debug.hpp"
#include "utilities/macros.hpp"
#include "utilities/ostream.hpp"
#include "utilities/vmError.hpp"
#include "utilities/globalDefinitions.hpp"
@ -226,6 +227,8 @@ void MallocTracker::deaccount(MallocHeader::FreeInfo free_info) {
bool MallocTracker::print_pointer_information(const void* p, outputStream* st) {
assert(MemTracker::enabled(), "NMT not enabled");
#if !INCLUDE_ASAN
address addr = (address)p;
// Carefully feel your way upwards and try to find a malloc header. Then check if
@ -303,5 +306,8 @@ bool MallocTracker::print_pointer_information(const void* p, outputStream* st) {
}
return true;
}
#endif // !INCLUDE_ASAN
return false;
}

View File

@ -75,6 +75,7 @@
#include "utilities/defaultStream.hpp"
#include "utilities/events.hpp"
#include "utilities/fastrand.hpp"
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"
#ifndef _WINDOWS
@ -1199,6 +1200,8 @@ void os::print_location(outputStream* st, intptr_t x, bool verbose) {
return;
}
#if !INCLUDE_ASAN
bool accessible = is_readable_pointer(addr);
// Check if addr is a JNI handle.
@ -1285,7 +1288,10 @@ void os::print_location(outputStream* st, intptr_t x, bool verbose) {
return;
}
#endif // !INCLUDE_ASAN
st->print_cr(INTPTR_FORMAT " is an unknown value", p2i(addr));
}
static bool is_pointer_bad(intptr_t* ptr) {

View File

@ -635,4 +635,10 @@
#define NOT_CDS_JAVA_HEAP_RETURN_(code) { return code; }
#endif
#ifdef ADDRESS_SANITIZER
#define INCLUDE_ASAN 1
#else
#define INCLUDE_ASAN 0
#endif
#endif // SHARE_UTILITIES_MACROS_HPP

View File

@ -34,6 +34,7 @@
#include "memory/metaspace/virtualSpaceNode.hpp"
#include "runtime/mutexLocker.hpp"
#include "sanitizers/address.hpp"
#include "utilities/macros.hpp"
#include "utilities/debug.hpp"
//#define LOG_PLEASE
#include "metaspaceGtestCommon.hpp"
@ -156,6 +157,11 @@ class VirtualSpaceNodeTest {
// The chunk should be as far committed as was requested
EXPECT_GE(c->committed_words(), request_commit_words);
// At the VirtualSpaceNode level, all memory is still poisoned.
// Since we bypass the normal way of allocating chunks (ChunkManager::get_chunk), we
// need to unpoison this chunk.
ASAN_UNPOISON_MEMORY_REGION(c->base(), c->committed_words() * BytesPerWord);
// Zap committed portion.
DEBUG_ONLY(zap_range(c->base(), c->committed_words());)

View File

@ -26,11 +26,14 @@
#include "memory/allocation.hpp"
#include "nmt/memTracker.hpp"
#include "runtime/os.hpp"
#include "sanitizers/address.hpp"
#include "utilities/debug.hpp"
#include "utilities/ostream.hpp"
#include "unittest.hpp"
#include "testutils.hpp"
#if !INCLUDE_ASAN
// This prefix shows up on any c heap corruption NMT detects. If unsure which assert will
// come, just use this one.
#define COMMON_NMT_HEAP_CORRUPTION_MESSAGE_PREFIX "NMT corruption"
@ -161,3 +164,5 @@ TEST_VM(NMT, test_realloc) {
}
}
}
#endif // !INCLUDE_ASAN

View File

@ -28,6 +28,7 @@
#include "nmt/mallocTracker.hpp"
#include "nmt/memTracker.hpp"
#include "runtime/os.hpp"
#include "sanitizers/address.hpp"
#include "testutils.hpp"
#include "unittest.hpp"
@ -38,6 +39,9 @@ static void check_expected_malloc_header(const void* payload, MEMFLAGS type, siz
EXPECT_EQ(hdr->flags(), type);
}
// ASAN complains about allocating very large sizes
#if !INCLUDE_ASAN
// Check that a malloc with an overflowing size is rejected.
TEST_VM(NMT, malloc_failure1) {
void* p = os::malloc(SIZE_MAX, mtTest);
@ -85,6 +89,7 @@ TEST_VM(NMT, realloc_failure_overflowing_size) {
TEST_VM(NMT, realloc_failure_gigantic_size) {
check_failing_realloc(SIZE_MAX - M);
}
#endif // !INCLUDE_ASAN
static void* do_realloc(void* p, size_t old_size, size_t new_size, uint8_t old_content, bool check_nmt_header) {

View File

@ -27,12 +27,15 @@
#include "nmt/mallocHeader.inline.hpp"
#include "nmt/memTracker.hpp"
#include "runtime/os.hpp"
#include "sanitizers/address.hpp"
#include "unittest.hpp"
// Uncomment to get test output
//#define LOG_PLEASE
#include "testutils.hpp"
#if !INCLUDE_ASAN
using ::testing::HasSubstr;
static void test_pointer(const void* p, bool expected_return_code, const char* expected_message) {
@ -123,3 +126,5 @@ static void test_for_mmap(size_t sz, ssize_t offset) {
TEST_VM(NMT, location_printing_mmap_1) { test_for_mmap(os::vm_page_size(), 0); }
TEST_VM(NMT, location_printing_mmap_2) { test_for_mmap(os::vm_page_size(), os::vm_page_size() - 1); }
#endif // !INCLUDE_ASAN