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

locking heap wrapper #1337

Merged
merged 4 commits into from
Nov 25, 2020
Merged

locking heap wrapper #1337

merged 4 commits into from
Nov 25, 2020

Conversation

wjhun
Copy link
Contributor

@wjhun wjhun commented Nov 23, 2020

As enumerated in #1302, there are many paths in the kernel where the kernel lock is not held and yet allocations or deallocations are being made from one of the kernel heaps. To address this issue, these changes introduce a "locked" kernel heap, using a wrapper heap which wraps heap methods with spinlock aquires, which helps to make such paths safe.

As the interface for the id heap is fairly complex and wouldn't be covered by a generic heap wrapper, a "locking" flag is specified on ID heap creation. The virtual huge and page heaps are now locking and thus safe to use from any context. The "backed" heap uses the locking wrapper, and a "locked" variant of general (using another mcache instance) is created for general-purpose allocations outside of the kernel lock. Allocations made under protection of the kernel lock should continue to use the general heap, as this will avoid unnecessary spinlock operations.

Note: SMP is enabled temporarily in this branch just to run through CI - it will be removed before merging (and until we agree it's safe to enable by default).

@wjhun wjhun requested a review from a team November 23, 2020 15:54
Copy link
Member

@francescolavra francescolavra left a comment

Choose a reason for hiding this comment

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

In init_pagecache(), pc->completions is initialized as an objcache, and is not locked. It should be locked instead (there is also an XXX comment that says this at pagecache.c:1320), because completions can be allocated and deallocated from that objcache without the kernel lock.

src/kernel/locking_heap.c Show resolved Hide resolved
platform/pc/service.c Outdated Show resolved Hide resolved
@francescolavra
Copy link
Member

In platform/pc/service.c, offset_block_io() calls allocate_merge() on the general kernel heap; since this can be called without the kernel lock (e.g. via pagecache_write_sg_finish -> filesystem_storage_write -> write_extent), it should use a locked heap instead.

@wjhun
Copy link
Contributor Author

wjhun commented Nov 24, 2020

I addressed the errors @francescolavra found and removed the unnecessary size parameter from locking_heap_wrapper.

…tions to locked heap locking_heap under src/kernel; use locking for sg_init, init_pagecache and virtio net; SMP_ENABLE by default for CI; host filesystems on locked heap; pagecache_write_sg_finish should not update write_count and apply completions on a read error; put xen grant_entry heap on locked
…ecessary size parameter from locking_heap_wrapper, fill meta field; use locking wrapper on pagecache completion objcache; offset_block_io: allocate merge off of locked heap; revert SMP_ENABLE for merge into master
@wjhun wjhun merged commit c719c3f into master Nov 25, 2020
@wjhun wjhun deleted the heap-locking branch December 2, 2020 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants