From: "Huang, Kai" <kai.huang@intel.com>
To: Jarkko Sakkinen <jarkko.sakkinen@iki.fi>,
Jarkko Sakkinen <jarkko@kernel.org>,
"linux-sgx@vger.kernel.org" <linux-sgx@vger.kernel.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: Re: VMA merging updateds?
Date: Thu, 26 Sep 2024 12:53:45 +1200 [thread overview]
Message-ID: <f25ad4ab-9843-411f-befb-d7d20ca99bc9@intel.com> (raw)
In-Reply-To: <D4FSOFDIBTSU.395W5ZC73BU4N@iki.fi>
>>>>>>> I started to look into this old issue with mm subsystem and SGX, i.e.
>>>>>>> can we make SGX VMA's to merge together?
>>>>>>>
>>>>>>> This demonstrates the problem pretty well:
>>>>>>>
>>>>>>> https://lore.kernel.org/linux-sgx/884c7ea454cf2eb0ba2e95f7c25bd42018824f97.camel@kernel.org/
>>>>>>>
>>>>>>> It was result of brk() syscall being applied a few times.
>>>>>
>>>>> Briging some context here. This can be fixed in the run-time by book
>>>>> keeping the ranges and doing unmapping/mapping. I guess this goes
>>>>> beyond what mm should support?
>>>>>
>>>>> I thought to plain check this as it has been two years since my last
>>>>> query on topic (if we could improve either the driver or mm somehow).
>>>>
>>>> In the past I've substituted kernel's mm merge code with user space
>>>> replacement:
>>>>
>>>> https://github.com/enarx/mmledger/blob/main/src/lib.rs
>>>>
>>>> It's essentially a reimplementation of al stuff that goes into
>>>> mm/mmap.c's vma_merge(). I cannot recall anymore whether merges
>>>> which map over existing ranges were working correctly, i.e. was
>>>> the issue only concerning adjacent VMA's.
>>>>
>>>> What I'm looking here is that can we make some cosntraints that
>>>> if satisfied by the pfnmap code, it could leverage the code from
>>>> vma_merge(). Perhaps by making explicit call to vma_merge()?
>>>> I get that implicit use moves too much responsibility to the mm
>>>> subsystem.
>>>>
>>>
>>> Hi Jarkko,
>>>
>>> Just want to understand more on the background:
>>>
>>> Are you seeing any real problem due to needing a lot of mmap()s to the
>>> same enclave, or it is just a problem that doesn't look nice and you
>>> want to resolve?
>>>
>>> I mean, this problem doesn't seem to be SGX-specific but a common one
>>> for VMAs with VM_PFNMAP (any bit in VM_SPECIAL), e.g., from random
>>> device drivers with mmap() support. We will need a good justification
>>> if we want to make any core-mm change, if any, for this.
>>
>> It requires essentially replicating core mm in user space.
>>
>> It's a manageable problem but feels silly since logic in merging
>> is mostly 1:1. It's not a problem for me personally as I'm not
>> making any money from SGX (more so to Intel).
>
> I.e. in the case when you want do a syscall shim. You fix it up by
> maintaining reflected version of the VMA database in the user space
> and remapping everything based on that for every possible mm-call.
>
> I've implemented such feature in the past for Enarx so it is entirely
> possible.
>
Just want to understand the problem/use case better:
I _think_ I got what the "syscall shim" is. But can you elaborate why
is this "syscall shim" related to the "kernel unable to merge contiguous
VMAs for the same enclave"? Assuming the kernel can actually merge
enclave VMAs, how does it help on the "syscall shim"?
next prev parent reply other threads:[~2024-09-26 0:54 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-22 16:27 Jarkko Sakkinen
2024-09-22 16:35 ` Jarkko Sakkinen
2024-09-22 16:57 ` Jarkko Sakkinen
2024-09-23 7:48 ` Jarkko Sakkinen
2024-09-26 0:07 ` Huang, Kai
2024-09-26 0:33 ` Jarkko Sakkinen
2024-09-26 0:38 ` Jarkko Sakkinen
2024-09-26 0:53 ` Huang, Kai [this message]
2024-09-26 0:38 ` Huang, Kai
2024-09-26 1:47 ` Jarkko Sakkinen
2024-09-26 1:48 ` Jarkko Sakkinen
2024-09-26 10:02 ` Jarkko Sakkinen
2024-09-27 17:39 ` Lorenzo Stoakes
2024-09-29 22:36 ` Jarkko Sakkinen
2024-09-30 8:05 ` Lorenzo Stoakes
2024-10-09 14:03 ` Jarkko Sakkinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f25ad4ab-9843-411f-befb-d7d20ca99bc9@intel.com \
--to=kai.huang@intel.com \
--cc=jarkko.sakkinen@iki.fi \
--cc=jarkko@kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-sgx@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox