Skip to content

Commit 2d00e00

Browse files
committed
After-merge fixes for ASAN
The merge commit 0fd89a1 of commit b6ec1e8 was slightly incomplete. ReadView::mem_valid(): Use the correct primitive MEM_MAKE_ADDRESSABLE(), because MEM_UNDEFINED() now has no effect on ASAN. recv_sys_t::alloc(), recv_sys_t::add(): Use MEM_MAKE_ADDRESSABLE() instead of MEM_UNDEFINED(), to get the correct behaviour for ASAN. For Valgrind and MSAN, there is no change in behaviour. recv_sys_t::free(), recv_sys_t::clear(): Before freeing memory to buf_pool.free_list, invoke MEM_MAKE_ADDRESSABLE() on the entire buf_block_t::frame, to cancel the effect of MEM_NOACCESS() in recv_sys_t::alloc().
1 parent 4785916 commit 2d00e00

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

storage/innobase/include/read0types.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,20 @@ class ReadView: public ReadViewBase
279279

280280

281281
/**
282-
Unpoison the memory for innodb_monitor_set_option;
283-
It is operating also on the freed transaction objects.
284-
Declare the contents as initialized for Valgrind;
285-
We checked that it was initialized in trx_pools->mem_free(trx).
282+
Make the memory accessible by innodb_monitor_set_option;
283+
It is operating also on freed transaction objects.
286284
*/
287285
void mem_valid() const
288286
{
287+
/* Cancel the effect of MEM_NOACCESS(). */
289288
#ifdef __SANITIZE_ADDRESS__
290-
MEM_UNDEFINED(&m_mutex, sizeof m_mutex);
289+
MEM_MAKE_ADDRESSABLE(&m_mutex, sizeof m_mutex);
291290
#endif
292-
#ifdef HAVE_valgrind
291+
#if defined HAVE_valgrind && !__has_feature(memory_sanitizer)
292+
/* In Valgrind, we cannot cancel MEM_NOACCESS() without changing
293+
the state of the V bits (indicating which bits are initialized).
294+
We will declare the contents as initialized.
295+
We did invoke MEM_CHECK_DEFINED() in trx_pools->mem_free(). */
293296
MEM_MAKE_DEFINED(&m_mutex, sizeof m_mutex);
294297
#endif
295298
}

storage/innobase/include/ut0pool.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,14 @@ struct Pool {
9292
MEM_MAKE_ADDRESSABLE(&elem->m_type,
9393
sizeof elem->m_type);
9494
#endif
95-
/* Declare the contents initialized;
96-
we checked this in mem_free(). */
95+
#if defined HAVE_valgrind && !__has_feature(memory_sanitizer)
96+
/* In Valgrind, we cannot cancel MEM_NOACCESS() without
97+
changing the state of the V bits (which indicate
98+
which bits are initialized).
99+
We will declare the contents as initialized.
100+
We did invoke MEM_CHECK_DEFINED() in mem_free(). */
97101
MEM_MAKE_DEFINED(&elem->m_type, sizeof elem->m_type);
102+
#endif
98103
Factory::destroy(&elem->m_type);
99104
}
100105

@@ -136,11 +141,14 @@ struct Pool {
136141
MEM_MAKE_ADDRESSABLE(&elem->m_type,
137142
sizeof elem->m_type);
138143
# endif
139-
/* Declare the memory initialized.
140-
The trx_t that are released to the pool are
141-
actually initialized; we checked that by
142-
MEM_CHECK_DEFINED() in mem_free() below. */
144+
# if defined HAVE_valgrind && !__has_feature(memory_sanitizer)
145+
/* In Valgrind, we cannot cancel MEM_NOACCESS() without
146+
changing the state of the V bits (which indicate
147+
which bits are initialized).
148+
We will declare the contents as initialized.
149+
We did invoke MEM_CHECK_DEFINED() in mem_free(). */
143150
MEM_MAKE_DEFINED(&elem->m_type, sizeof elem->m_type);
151+
# endif
144152
}
145153
#endif
146154

storage/innobase/log/log0recv.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,7 @@ inline void recv_sys_t::clear()
10501050
buf_block_t *prev_block= UT_LIST_GET_PREV(unzip_LRU, block);
10511051
ut_ad(block->page.state() == BUF_BLOCK_MEMORY);
10521052
UT_LIST_REMOVE(blocks, block);
1053+
MEM_MAKE_ADDRESSABLE(block->frame, srv_page_size);
10531054
buf_block_free(block);
10541055
block= prev_block;
10551056
}
@@ -1093,7 +1094,7 @@ inline void *recv_sys_t::alloc(size_t len)
10931094
ut_calc_align<uint16_t>(static_cast<uint16_t>(len), ALIGNMENT);
10941095
static_assert(ut_is_2pow(ALIGNMENT), "ALIGNMENT must be a power of 2");
10951096
UT_LIST_ADD_FIRST(blocks, block);
1096-
MEM_UNDEFINED(block->frame, len);
1097+
MEM_MAKE_ADDRESSABLE(block->frame, len);
10971098
MEM_NOACCESS(block->frame + len, srv_page_size - len);
10981099
return my_assume_aligned<ALIGNMENT>(block->frame);
10991100
}
@@ -1113,7 +1114,7 @@ inline void *recv_sys_t::alloc(size_t len)
11131114

11141115
block->page.access_time= ((block->page.access_time >> 16) + 1) << 16 |
11151116
ut_calc_align<uint16_t>(static_cast<uint16_t>(free_offset), ALIGNMENT);
1116-
MEM_UNDEFINED(block->frame + free_offset - len, len);
1117+
MEM_MAKE_ADDRESSABLE(block->frame + free_offset - len, len);
11171118
return my_assume_aligned<ALIGNMENT>(block->frame + free_offset - len);
11181119
}
11191120

@@ -1148,6 +1149,7 @@ inline void recv_sys_t::free(const void *data)
11481149
if (!((block->page.access_time -= 1U << 16) >> 16))
11491150
{
11501151
UT_LIST_REMOVE(blocks, block);
1152+
MEM_MAKE_ADDRESSABLE(block->frame, srv_page_size);
11511153
buf_block_free(block);
11521154
}
11531155
return;
@@ -1758,7 +1760,7 @@ inline void recv_sys_t::add(const page_id_t page_id,
17581760
{
17591761
/* Use already allocated 'padding' bytes */
17601762
append:
1761-
MEM_UNDEFINED(end + 1, len);
1763+
MEM_MAKE_ADDRESSABLE(end + 1, len);
17621764
/* Append to the preceding record for the page */
17631765
tail->append(l, len);
17641766
return;

storage/innobase/trx/trx0trx.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,26 @@ void trx_free(trx_t*& trx)
455455
/* Unpoison the memory for innodb_monitor_set_option;
456456
it is operating also on the freed transaction objects. */
457457
MEM_MAKE_ADDRESSABLE(&trx->mutex, sizeof trx->mutex);
458+
# ifdef WITH_WSREP
459+
MEM_MAKE_ADDRESSABLE(&trx->wsrep, sizeof trx->wsrep);
460+
# endif
458461
/* For innobase_kill_connection() */
459462
MEM_MAKE_ADDRESSABLE(&trx->state, sizeof trx->state);
460463
MEM_MAKE_ADDRESSABLE(&trx->mysql_thd, sizeof trx->mysql_thd);
461464
#endif
462-
/* Unpoison the memory for innodb_monitor_set_option;
463-
it is operating also on the freed transaction objects.
464-
We checked that these were initialized in
465-
trx_pools->mem_free(trx). */
465+
#if defined HAVE_valgrind && !__has_feature(memory_sanitizer)
466+
/* In Valgrind, we cannot cancel the effect of MEM_NOACCESS()
467+
without changing the state of the V bits (indicating which
468+
bits are initialized). We did invoke MEM_CHECK_DEFINED() in
469+
trx_pools->mem_free(). */
466470
MEM_MAKE_DEFINED(&trx->mutex, sizeof trx->mutex);
467471
/* For innobase_kill_connection() */
468472
# ifdef WITH_WSREP
469473
MEM_MAKE_DEFINED(&trx->wsrep, sizeof trx->wsrep);
470474
# endif
471475
MEM_MAKE_DEFINED(&trx->state, sizeof trx->state);
472476
MEM_MAKE_DEFINED(&trx->mysql_thd, sizeof trx->mysql_thd);
477+
#endif
473478

474479
trx = NULL;
475480
}

0 commit comments

Comments
 (0)