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

Optimize to share upper half page table #509

Closed
wants to merge 1 commit into from

Conversation

zhuangel
Copy link
Contributor

@zhuangel zhuangel commented Jul 4, 2019

Sentry split memory address space into bottom half
and upper half, kernel address space will be mapped
into both ranges.
And sentry will setup kernel address space map at
upper half in every user task page table.
Optimize is done to share the kernel upper half
address space page table between sentry kernel and
user task, this will reduce the user task page table
memory consume and speed up user task initialize.

Sentry split memory address space into bottom half
and upper half, kernel address space will be mapped
into both ranges.
And sentry will setup kernel address space map at
upper half in every user task page table.
Optimize is done to share the kernel upper half
address space page table between sentry kernel and
user task, this will reduce the user task page table
memory consume and speed up user task initialize.
@googlebot googlebot added the cla: yes CLA has been signed label Jul 4, 2019
pr.physical)
return true // Keep iterating.
})
pageTables.MirrorKernelPageTable()
Copy link
Contributor

Choose a reason for hiding this comment

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

Per elsewhere, I think this would look something like:

pageTables.Mirror(m.kernel.PageTables, kernelStart, ....)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Per elsewhere, I think this would look something like:

pageTables.Mirror(m.kernel.PageTables, kernelStart, ....)

Thanks for advise on the patch, add new method Mirror, and take range as parameter, also using the walk API, I will try to update the patch later.

@@ -89,7 +89,7 @@ go_library(
"//pkg/sentry/platform/kvm:__subpackages__",
"//pkg/sentry/platform/ring0:__subpackages__",
],
deps = ["//pkg/sentry/usermem"],
deps = ["//pkg/sentry/usermem","//pkg/sentry/platform/safecopy"],
Copy link
Contributor

Choose a reason for hiding this comment

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

Not formatted correctly (see other lines). Also, I don’t think you actually need safecopy at all. It’s not user memory.


var kPageTable *PageTables

// MirrorInit set kernel page table as the mirror source.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is kind of a strange API. It’s an object method but used to set a singleton, and will panic if already set :)

I don’t think the pageTables package needs to have a reference to this at all and you could just drop this. I’ll elaborate below.

kPageTable = p
}

// Mirror the kernel upper address space page tables.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you really only need a single Mirror method, and can accept some pageTable argument. (I’ve shown this call above.) This let’s you get rid of the Singleton and weird API above, and the tweak to the walker API.

I don’t think you need to use safecopy to copy the PGDs, and would prefer if you accepted an explicit range to mirror (that would be the kernel range). It could just be called Mirror().

My other ask is that you document the Mirror() function really well. It would be really unsafe to use for any case where the lifetime of the other pageTables is not fixed and guaranteed, e.g. you can’t get creative and use it for fork. It’s a simple API but should only be used for kernel page tables.

@@ -83,7 +83,9 @@ func (w *Walker) iterateRange(start, end uintptr) {
panic("alloc spans non-canonical range")
}
w.iterateRangeCanonical(start, lowerTop)
w.iterateRangeCanonical(upperBottom, end)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don’t think you should do this, just document the API appropriately. Also, you already have w.pageTables, which is the same as the pageTables argument being passed here...

@amscanne
Copy link
Contributor

Just checking in. I'm happy to merge this once the API is tweaked.

@amscanne
Copy link
Contributor

amscanne commented Sep 6, 2019

Checking in again.

@prattmic prattmic added area: platform Issue related to platforms (kvm, ptrace) platform: kvm Issue related to the kvm platform area: performance Issue related to performance & benchmarks labels Jan 22, 2020
@amscanne
Copy link
Contributor

Note that per previous comments, if you have a change that addresses them then I don't think it has been pushed. I'd love to merge this with the fixes addressed, just let me know!

@amscanne
Copy link
Contributor

I believe that this change will be obsoleted by #2256, which will require only mapping the entry/exit stubs in the upper half as we will switch to the kernel page tables there. Closing under that assumption. Please reopen if this is not valid!

@amscanne amscanne closed this Mar 30, 2020
@laijs
Copy link
Contributor

laijs commented Mar 31, 2020

Oh, it is not obsoleted by #2256. I have a updated one for this pr(this #509), but I don't think it is so related to KPTI that I didn't include it.

@amscanne amscanne reopened this Mar 31, 2020
@github-actions
Copy link

This pull request is stale because it has been open 90 days with no activity. Remove the stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the stale The Issue or PR is stale. label Jun 30, 2020
@github-actions github-actions bot closed this Jul 30, 2020
@laijs laijs mentioned this pull request Aug 6, 2020
laijs added a commit to laijs/gvisor that referenced this pull request Nov 2, 2020
Fixes: google#509

Signed-off-by: Lai Jiangshan <jiangshan.ljs@antfin.com>
Signed-off-by: Lai Jiangshan <laijs@linux.alibaba.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: performance Issue related to performance & benchmarks area: platform Issue related to platforms (kvm, ptrace) cla: yes CLA has been signed platform: kvm Issue related to the kvm platform stale The Issue or PR is stale.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants