Skip to content

Commit d4210ce

Browse files
Dominik InführV8 LUCI CQ
authored andcommitted
[heap] Add shared trusted spaces
This CL adds shared variants for the trusted spaces (both for regular- sized and large objects). These spaces will be needed when we eventually want to share Wasm types between multiple isolates. Bug: 338342768 Change-Id: Ia6a080f6acb22f895dc8ef4f81c2f639d0ba637a Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5501038 Reviewed-by: Michael Lippautz <[email protected]> Commit-Queue: Dominik Inführ <[email protected]> Cr-Commit-Position: refs/heads/main@{#93682}
1 parent 0f647b4 commit d4210ce

15 files changed

Lines changed: 248 additions & 27 deletions

src/common/globals.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,11 +1150,13 @@ enum AllocationSpace {
11501150
TRUSTED_SPACE, // Space for trusted objects. When the sandbox is enabled,
11511151
// this space will be located outside of it so that objects in
11521152
// it cannot directly be corrupted by an attacker.
1153-
NEW_LO_SPACE, // Young generation large object space.
1154-
LO_SPACE, // Old generation large object space.
1155-
CODE_LO_SPACE, // Old generation large code object space.
1156-
SHARED_LO_SPACE, // Space shared between multiple isolates. Optional.
1157-
TRUSTED_LO_SPACE, // Like TRUSTED_SPACE but for large objects.
1153+
SHARED_TRUSTED_SPACE, // Trusted space but for shared objects. Optional.
1154+
NEW_LO_SPACE, // Young generation large object space.
1155+
LO_SPACE, // Old generation large object space.
1156+
CODE_LO_SPACE, // Old generation large code object space.
1157+
SHARED_LO_SPACE, // Space shared between multiple isolates. Optional.
1158+
SHARED_TRUSTED_LO_SPACE, // Like TRUSTED_SPACE but for shared large objects.
1159+
TRUSTED_LO_SPACE, // Like TRUSTED_SPACE but for large objects.
11581160

11591161
FIRST_SPACE = RO_SPACE,
11601162
LAST_SPACE = TRUSTED_LO_SPACE,
@@ -1189,6 +1191,8 @@ constexpr const char* ToString(AllocationSpace space) {
11891191
return "shared_space";
11901192
case AllocationSpace::TRUSTED_SPACE:
11911193
return "trusted_space";
1194+
case AllocationSpace::SHARED_TRUSTED_SPACE:
1195+
return "shared_trusted_space";
11921196
case AllocationSpace::NEW_LO_SPACE:
11931197
return "new_large_object_space";
11941198
case AllocationSpace::LO_SPACE:
@@ -1197,6 +1201,8 @@ constexpr const char* ToString(AllocationSpace space) {
11971201
return "code_large_object_space";
11981202
case AllocationSpace::SHARED_LO_SPACE:
11991203
return "shared_large_object_space";
1204+
case AllocationSpace::SHARED_TRUSTED_LO_SPACE:
1205+
return "shared_trusted_large_object_space";
12001206
case AllocationSpace::TRUSTED_LO_SPACE:
12011207
return "trusted_large_object_space";
12021208
}
@@ -1211,10 +1217,11 @@ enum class AllocationType : uint8_t {
12111217
kOld, // Regular object allocated in OLD_SPACE or LO_SPACE.
12121218
kCode, // InstructionStream object allocated in CODE_SPACE or CODE_LO_SPACE.
12131219
kMap, // Map object allocated in OLD_SPACE.
1214-
kReadOnly, // Object allocated in RO_SPACE.
1215-
kSharedOld, // Regular object allocated in OLD_SPACE in the shared heap.
1216-
kSharedMap, // Map object in OLD_SPACE in the shared heap.
1217-
kTrusted, // Object allocated in TRUSTED_SPACE or TRUSTED_LO_SPACE.
1220+
kReadOnly, // Object allocated in RO_SPACE.
1221+
kSharedOld, // Regular object allocated in OLD_SPACE in the shared heap.
1222+
kSharedMap, // Map object in OLD_SPACE in the shared heap.
1223+
kSharedTrusted, // Trusted objects in TRUSTED_SPACE in the shared heap.
1224+
kTrusted, // Object allocated in TRUSTED_SPACE or TRUSTED_LO_SPACE.
12181225
};
12191226

12201227
constexpr const char* ToString(AllocationType kind) {
@@ -1235,6 +1242,8 @@ constexpr const char* ToString(AllocationType kind) {
12351242
return "SharedMap";
12361243
case AllocationType::kTrusted:
12371244
return "Trusted";
1245+
case AllocationType::kSharedTrusted:
1246+
return "SharedTrusted";
12381247
}
12391248
}
12401249

src/heap/heap-allocator-inl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ OldLargeObjectSpace* HeapAllocator::trusted_lo_space() const {
6060
return static_cast<OldLargeObjectSpace*>(spaces_[TRUSTED_LO_SPACE]);
6161
}
6262

63+
OldLargeObjectSpace* HeapAllocator::shared_trusted_lo_space() const {
64+
return shared_trusted_lo_space_;
65+
}
66+
6367
bool HeapAllocator::CanAllocateInReadOnlySpace() const {
6468
return read_only_space()->writable();
6569
}
@@ -143,6 +147,10 @@ V8_WARN_UNUSED_RESULT V8_INLINE AllocationResult HeapAllocator::AllocateRaw(
143147
allocation = trusted_space_allocator_->AllocateRaw(size_in_bytes,
144148
alignment, origin);
145149
break;
150+
case AllocationType::kSharedTrusted:
151+
allocation = shared_trusted_space_allocator_->AllocateRaw(
152+
size_in_bytes, alignment, origin);
153+
break;
146154
}
147155
}
148156
}
@@ -192,6 +200,9 @@ AllocationResult HeapAllocator::AllocateRaw(int size_in_bytes,
192200
case AllocationType::kTrusted:
193201
return AllocateRaw<AllocationType::kTrusted>(size_in_bytes, origin,
194202
alignment);
203+
case AllocationType::kSharedTrusted:
204+
return AllocateRaw<AllocationType::kSharedTrusted>(size_in_bytes, origin,
205+
alignment);
195206
}
196207
UNREACHABLE();
197208
}
@@ -213,6 +224,7 @@ AllocationResult HeapAllocator::AllocateRawData(int size_in_bytes,
213224
case AllocationType::kSharedMap:
214225
case AllocationType::kSharedOld:
215226
case AllocationType::kTrusted:
227+
case AllocationType::kSharedTrusted:
216228
UNREACHABLE();
217229
}
218230
UNREACHABLE();

src/heap/heap-allocator.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ void HeapAllocator::Setup(LinearAllocationArea* new_allocation_info,
4949
heap_->shared_allocation_space(),
5050
MainAllocator::IsNewGeneration::kNo);
5151
shared_lo_space_ = heap_->shared_lo_allocation_space();
52+
53+
shared_trusted_space_allocator_.emplace(
54+
local_heap_, heap_->shared_trusted_allocation_space(),
55+
MainAllocator::IsNewGeneration::kNo);
56+
shared_trusted_lo_space_ = heap_->shared_trusted_lo_allocation_space();
5257
}
5358
}
5459

@@ -71,6 +76,8 @@ AllocationResult HeapAllocator::AllocateRawLargeInternal(
7176
return shared_lo_space()->AllocateRaw(local_heap_, size_in_bytes);
7277
case AllocationType::kTrusted:
7378
return trusted_lo_space()->AllocateRaw(local_heap_, size_in_bytes);
79+
case AllocationType::kSharedTrusted:
80+
return shared_trusted_lo_space()->AllocateRaw(local_heap_, size_in_bytes);
7481
case AllocationType::kMap:
7582
case AllocationType::kReadOnly:
7683
case AllocationType::kSharedMap:
@@ -93,6 +100,7 @@ constexpr AllocationSpace AllocationTypeToGCSpace(AllocationType type) {
93100
case AllocationType::kReadOnly:
94101
case AllocationType::kSharedMap:
95102
case AllocationType::kSharedOld:
103+
case AllocationType::kSharedTrusted:
96104
UNREACHABLE();
97105
}
98106
}
@@ -168,6 +176,10 @@ void HeapAllocator::MakeLinearAllocationAreasIterable() {
168176
if (shared_space_allocator_) {
169177
shared_space_allocator_->MakeLinearAllocationAreaIterable();
170178
}
179+
180+
if (shared_trusted_space_allocator_) {
181+
shared_trusted_space_allocator_->MakeLinearAllocationAreaIterable();
182+
}
171183
}
172184

173185
#if DEBUG
@@ -182,6 +194,10 @@ void HeapAllocator::VerifyLinearAllocationAreas() const {
182194
if (shared_space_allocator_) {
183195
shared_space_allocator_->Verify();
184196
}
197+
198+
if (shared_trusted_space_allocator_) {
199+
shared_trusted_space_allocator_->Verify();
200+
}
185201
}
186202
#endif // DEBUG
187203

@@ -201,12 +217,18 @@ void HeapAllocator::MarkSharedLinearAllocationAreasBlack() {
201217
if (shared_space_allocator_) {
202218
shared_space_allocator_->MarkLinearAllocationAreaBlack();
203219
}
220+
if (shared_trusted_space_allocator_) {
221+
shared_trusted_space_allocator_->MarkLinearAllocationAreaBlack();
222+
}
204223
}
205224

206225
void HeapAllocator::UnmarkSharedLinearAllocationAreas() {
207226
if (shared_space_allocator_) {
208227
shared_space_allocator_->UnmarkLinearAllocationArea();
209228
}
229+
if (shared_trusted_space_allocator_) {
230+
shared_trusted_space_allocator_->UnmarkLinearAllocationArea();
231+
}
210232
}
211233

212234
void HeapAllocator::FreeLinearAllocationAreas() {
@@ -220,6 +242,10 @@ void HeapAllocator::FreeLinearAllocationAreas() {
220242
if (shared_space_allocator_) {
221243
shared_space_allocator_->FreeLinearAllocationArea();
222244
}
245+
246+
if (shared_trusted_space_allocator_) {
247+
shared_trusted_space_allocator_->FreeLinearAllocationArea();
248+
}
223249
}
224250

225251
void HeapAllocator::PublishPendingAllocations() {

src/heap/heap-allocator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class NewLargeObjectSpace;
2525
class OldLargeObjectSpace;
2626
class PagedSpace;
2727
class ReadOnlySpace;
28+
class SharedTrustedLargeObjectSpace;
2829
class Space;
2930

3031
// Allocator for the main thread. All exposed functions internally call the
@@ -134,6 +135,7 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
134135
V8_INLINE NewLargeObjectSpace* new_lo_space() const;
135136
V8_INLINE OldLargeObjectSpace* lo_space() const;
136137
V8_INLINE OldLargeObjectSpace* shared_lo_space() const;
138+
V8_INLINE OldLargeObjectSpace* shared_trusted_lo_space() const;
137139
V8_INLINE PagedSpace* old_space() const;
138140
V8_INLINE ReadOnlySpace* read_only_space() const;
139141
V8_INLINE PagedSpace* trusted_space() const;
@@ -167,7 +169,9 @@ class V8_EXPORT_PRIVATE HeapAllocator final {
167169

168170
// Allocators for the shared spaces.
169171
base::Optional<MainAllocator> shared_space_allocator_;
172+
base::Optional<MainAllocator> shared_trusted_space_allocator_;
170173
OldLargeObjectSpace* shared_lo_space_;
174+
SharedTrustedLargeObjectSpace* shared_trusted_lo_space_;
171175

172176
#ifdef V8_ENABLE_ALLOCATION_TIMEOUT
173177
// Specifies how many allocations should be performed until returning

src/heap/heap-inl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ bool Heap::IsPendingAllocationInternal(Tagged<HeapObject> object) {
419419

420420
case SHARED_SPACE:
421421
case SHARED_LO_SPACE:
422+
case SHARED_TRUSTED_SPACE:
423+
case SHARED_TRUSTED_LO_SPACE:
422424
// TODO(v8:13267): Ensure that all shared space objects have a memory
423425
// barrier after initialization.
424426
return false;

src/heap/heap.cc

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4612,6 +4612,8 @@ bool Heap::SharedHeapContains(Tagged<HeapObject> value) const {
46124612
if (shared_allocation_space_) {
46134613
if (shared_allocation_space_->Contains(value)) return true;
46144614
if (shared_lo_allocation_space_->Contains(value)) return true;
4615+
if (shared_trusted_allocation_space_->Contains(value)) return true;
4616+
if (shared_trusted_lo_allocation_space_->Contains(value)) return true;
46154617
}
46164618

46174619
return false;
@@ -4647,6 +4649,8 @@ bool Heap::InSpace(Tagged<HeapObject> value, AllocationSpace space) const {
46474649
return shared_space_->Contains(value);
46484650
case TRUSTED_SPACE:
46494651
return trusted_space_->Contains(value);
4652+
case SHARED_TRUSTED_SPACE:
4653+
return shared_trusted_space_->Contains(value);
46504654
case LO_SPACE:
46514655
return lo_space_->Contains(value);
46524656
case CODE_LO_SPACE:
@@ -4655,6 +4659,8 @@ bool Heap::InSpace(Tagged<HeapObject> value, AllocationSpace space) const {
46554659
return new_lo_space_->Contains(value);
46564660
case SHARED_LO_SPACE:
46574661
return shared_lo_space_->Contains(value);
4662+
case SHARED_TRUSTED_LO_SPACE:
4663+
return shared_trusted_lo_space_->Contains(value);
46584664
case TRUSTED_LO_SPACE:
46594665
return trusted_lo_space_->Contains(value);
46604666
case RO_SPACE:
@@ -4681,6 +4687,8 @@ bool Heap::InSpaceSlow(Address addr, AllocationSpace space) const {
46814687
return shared_space_->ContainsSlow(addr);
46824688
case TRUSTED_SPACE:
46834689
return trusted_space_->ContainsSlow(addr);
4690+
case SHARED_TRUSTED_SPACE:
4691+
return shared_trusted_space_->ContainsSlow(addr);
46844692
case LO_SPACE:
46854693
return lo_space_->ContainsSlow(addr);
46864694
case CODE_LO_SPACE:
@@ -4689,6 +4697,8 @@ bool Heap::InSpaceSlow(Address addr, AllocationSpace space) const {
46894697
return new_lo_space_->ContainsSlow(addr);
46904698
case SHARED_LO_SPACE:
46914699
return shared_lo_space_->ContainsSlow(addr);
4700+
case SHARED_TRUSTED_LO_SPACE:
4701+
return shared_trusted_lo_space_->ContainsSlow(addr);
46924702
case TRUSTED_LO_SPACE:
46934703
return trusted_lo_space_->ContainsSlow(addr);
46944704
case RO_SPACE:
@@ -4708,7 +4718,9 @@ bool Heap::IsValidAllocationSpace(AllocationSpace space) {
47084718
case CODE_LO_SPACE:
47094719
case SHARED_LO_SPACE:
47104720
case TRUSTED_SPACE:
4721+
case SHARED_TRUSTED_SPACE:
47114722
case TRUSTED_LO_SPACE:
4723+
case SHARED_TRUSTED_LO_SPACE:
47124724
case RO_SPACE:
47134725
return true;
47144726
default:
@@ -5981,24 +5993,36 @@ void Heap::SetUpSpaces(LinearAllocationArea& new_allocation_info,
59815993
code_lo_space_ =
59825994
static_cast<CodeLargeObjectSpace*>(space_[CODE_LO_SPACE].get());
59835995

5996+
space_[TRUSTED_SPACE] = std::make_unique<TrustedSpace>(this);
5997+
trusted_space_ = static_cast<TrustedSpace*>(space_[TRUSTED_SPACE].get());
5998+
5999+
space_[TRUSTED_LO_SPACE] = std::make_unique<TrustedLargeObjectSpace>(this);
6000+
trusted_lo_space_ =
6001+
static_cast<TrustedLargeObjectSpace*>(space_[TRUSTED_LO_SPACE].get());
6002+
59846003
if (isolate()->is_shared_space_isolate()) {
59856004
space_[SHARED_LO_SPACE] = std::make_unique<SharedLargeObjectSpace>(this);
59866005
shared_lo_space_ =
59876006
static_cast<SharedLargeObjectSpace*>(space_[SHARED_LO_SPACE].get());
6007+
6008+
space_[SHARED_TRUSTED_SPACE] = std::make_unique<SharedTrustedSpace>(this);
6009+
shared_trusted_space_ =
6010+
static_cast<SharedTrustedSpace*>(space_[SHARED_TRUSTED_SPACE].get());
6011+
6012+
space_[SHARED_TRUSTED_LO_SPACE] =
6013+
std::make_unique<SharedTrustedLargeObjectSpace>(this);
6014+
shared_trusted_lo_space_ = static_cast<SharedTrustedLargeObjectSpace*>(
6015+
space_[SHARED_TRUSTED_LO_SPACE].get());
59886016
}
59896017

59906018
if (isolate()->has_shared_space()) {
59916019
Heap* heap = isolate()->shared_space_isolate()->heap();
59926020
shared_allocation_space_ = heap->shared_space_;
59936021
shared_lo_allocation_space_ = heap->shared_lo_space_;
5994-
}
5995-
5996-
space_[TRUSTED_SPACE] = std::make_unique<TrustedSpace>(this);
5997-
trusted_space_ = static_cast<TrustedSpace*>(space_[TRUSTED_SPACE].get());
59986022

5999-
space_[TRUSTED_LO_SPACE] = std::make_unique<TrustedLargeObjectSpace>(this);
6000-
trusted_lo_space_ =
6001-
static_cast<TrustedLargeObjectSpace*>(space_[TRUSTED_LO_SPACE].get());
6023+
shared_trusted_allocation_space_ = heap->shared_trusted_space_;
6024+
shared_trusted_lo_allocation_space_ = heap->shared_trusted_lo_space_;
6025+
}
60026026

60036027
main_thread_local_heap()->SetUpMainThread(new_allocation_info,
60046028
old_allocation_info);
@@ -7214,11 +7238,14 @@ bool Heap::AllowedToBeMigrated(Tagged<Map> map, Tagged<HeapObject> obj,
72147238
return dst == SHARED_SPACE;
72157239
case TRUSTED_SPACE:
72167240
return dst == TRUSTED_SPACE;
7241+
case SHARED_TRUSTED_SPACE:
7242+
return dst == SHARED_TRUSTED_SPACE;
72177243
case LO_SPACE:
72187244
case CODE_LO_SPACE:
72197245
case NEW_LO_SPACE:
72207246
case SHARED_LO_SPACE:
72217247
case TRUSTED_LO_SPACE:
7248+
case SHARED_TRUSTED_LO_SPACE:
72227249
case RO_SPACE:
72237250
return false;
72247251
}

src/heap/heap.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class SemiSpaceNewSpace;
126126
class SharedLargeObjectSpace;
127127
class SharedReadOnlySpace;
128128
class SharedSpace;
129+
class SharedTrustedLargeObjectSpace;
130+
class SharedTrustedSpace;
129131
class Space;
130132
class StickySpace;
131133
class StressScavengeObserver;
@@ -782,6 +784,12 @@ class Heap final {
782784
OldLargeObjectSpace* shared_lo_allocation_space() const {
783785
return shared_lo_allocation_space_;
784786
}
787+
SharedTrustedSpace* shared_trusted_allocation_space() const {
788+
return shared_trusted_allocation_space_;
789+
}
790+
SharedTrustedLargeObjectSpace* shared_trusted_lo_allocation_space() const {
791+
return shared_trusted_lo_allocation_space_;
792+
}
785793

786794
inline PagedSpace* paged_space(int idx) const;
787795
inline Space* space(int idx) const;
@@ -2150,12 +2158,16 @@ class Heap final {
21502158
SharedLargeObjectSpace* shared_lo_space_ = nullptr;
21512159
ReadOnlySpace* read_only_space_ = nullptr;
21522160
TrustedSpace* trusted_space_ = nullptr;
2161+
SharedTrustedSpace* shared_trusted_space_ = nullptr;
21532162
TrustedLargeObjectSpace* trusted_lo_space_ = nullptr;
2163+
SharedTrustedLargeObjectSpace* shared_trusted_lo_space_ = nullptr;
21542164

21552165
// Either pointer to owned shared spaces or pointer to unowned shared spaces
21562166
// in another isolate.
21572167
PagedSpace* shared_allocation_space_ = nullptr;
21582168
OldLargeObjectSpace* shared_lo_allocation_space_ = nullptr;
2169+
SharedTrustedSpace* shared_trusted_allocation_space_ = nullptr;
2170+
SharedTrustedLargeObjectSpace* shared_trusted_lo_allocation_space_ = nullptr;
21592171

21602172
// Map from the space id to the space.
21612173
std::unique_ptr<Space> space_[LAST_SPACE + 1];

src/heap/large-spaces.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ void CodeLargeObjectSpace::RemovePage(LargePageMetadata* page) {
457457
SharedLargeObjectSpace::SharedLargeObjectSpace(Heap* heap)
458458
: OldLargeObjectSpace(heap, SHARED_LO_SPACE) {}
459459

460+
SharedTrustedLargeObjectSpace::SharedTrustedLargeObjectSpace(Heap* heap)
461+
: OldLargeObjectSpace(heap, SHARED_TRUSTED_LO_SPACE) {}
460462

461463
TrustedLargeObjectSpace::TrustedLargeObjectSpace(Heap* heap)
462464
: OldLargeObjectSpace(heap, TRUSTED_LO_SPACE) {}

src/heap/large-spaces.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ class TrustedLargeObjectSpace : public OldLargeObjectSpace {
168168
explicit TrustedLargeObjectSpace(Heap* heap);
169169
};
170170

171+
// Similar to the TrustedLargeObjectSpace, but for shared objects.
172+
class SharedTrustedLargeObjectSpace : public OldLargeObjectSpace {
173+
public:
174+
explicit SharedTrustedLargeObjectSpace(Heap* heap);
175+
};
176+
171177
class NewLargeObjectSpace : public LargeObjectSpace {
172178
public:
173179
NewLargeObjectSpace(Heap* heap, size_t capacity);

0 commit comments

Comments
 (0)