From: Borislav Petkov <bp@alien8.de>
To: Brendan Jackman <jackmanb@google.com>
Cc: akpm@linux-foundation.org, dave.hansen@linux.intel.com,
yosryahmed@google.com, kvm@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
peterz@infradead.org, seanjc@google.com, tglx@linutronix.de,
x86@kernel.org
Subject: Re: [PATCH RFC v2 03/29] mm: asi: Introduce ASI core API
Date: Fri, 14 Mar 2025 14:14:19 +0100 [thread overview]
Message-ID: <20250314131419.GJZ9Qrq8scAtDyBUcg@fat_crate.local> (raw)
In-Reply-To: <20250228084355.2061899-1-jackmanb@google.com>
On Fri, Feb 28, 2025 at 08:43:55AM +0000, Brendan Jackman wrote:
> Yeah I see what you mean. I think the issues are:
>
> 1. We're mixing up two different aspects in the API:
>
> a. Starting and finishing "critical sections" (i.e. the region
> between asi_enter() and asi_relax())
>
> b. Actually triggering address space transitions.
>
> 2. There is a fundamental asymmetry at play here: asi_enter() and
> asi_exit() can both be NOPs (when we're already in the relevant
> address space), and asi_enter() being a NOP is really the _whole
> point of ASI_.
I'm guessing you mean this thing in __asi_enter():
+ if (!target || target == this_cpu_read(curr_asi))
+ return;
The assumption being that curr_asi will be the target most of the time after
having done the expensive switch once...
> The ideal world is where asi_exit() is very very rare, so
> asi_enter() is almost always a NOP.
... asi_exit() being the actual switch to the unrestricted CR3.
And asi_relax() being the switch of current task's asi target ptr to NULL.
Comment says
"Domain to enter when returning to process context."
but I'm none-the-wiser.
So, why are we doing that relaxing thing?
I'm guessing the relaxing is marking the end of the region where we're running
untrusted code. After asi_relax() we are still in the restricted CR3 but we're
not running untrusted code.
> So we could disentangle part 1 by just rejigging things as you suggest,
> and I think the naming would be like:
>
> asi_enter
> asi_start_critical
> asi_end_critical
> asi_exit
Yap, that's what I was gonna suggest: asi_enter and asi_exit do the actual CR3
build and switch and start_critical and end_critical do the cheaper tracking
thing.
> But the issue with that is that asi_start_critical() _must_ imply
> asi_enter()
What does that mean exactly?
asi_start_critical() must never be called before asi_enter()?
If so, I'm sure there are ways to track and check that and warn if not, right?
> (otherwise if we get an NMI between asi_enter() and
> asi_start_critical(), and that causes a #PF, we will start the
> critical section in the wrong address space and ASI won't do its job).
> So, we are somewhat forced to mix up a. and b. from above.
I don't understand: asi_enter() can be interrupted by an NMI at any random
point. How is the current, imbalanced interface not vulnerable to this
scenario?
> BTW, there is another thing complicating this picture a little: ASI
> "clients" (really just meaning KVM code at this point) are not not
> really supposed to care at all about the actual address space, the fact
> that they currently have to call asi_exit() in part 4b is just a
> temporary thing to simplify the initial implementation. It has a
> performance cost (not enormous, serious KVM platforms try pretty hard
You mean the switch to the unrestricted_cr3? I can imagine...
> to avoid returning to user space, but it does still matter) so
> Google's internal version has already got rid of it and that's where I
> expect this thing to evolve too. But for now it just lets us keep
> things simple since e.g. we never have to think about context
> switching in the restricted address space.
>
> With that in mind, what if it looked like this:
>
> ioctl(KVM_RUN) {
> enter_from_user_mode()
> while !need_userspace_handling()
> // This implies asi_enter(), but this code "doesn't care"
> // about that.
> asi_start_critical();
> vmenter();
> asi_end_critical();
> }
> // TODO: This is temporary, it should not be needed.
> asi_exit();
> exit_to_user_mode()
> }
>
> Once the asi_exit() call disappears, it will be symmetrical from the
> "client API"'s point of view. And while we still mix up address space
> switching with critical section boundaries, the address space
> switching is "just an implementation detail" and not really visible as
> part of the API.
So I'm still unclear on that whole design here so I'm asking silly questions
but I know that:
1. you can do empty calls to keep the interface balanced and easy to use
2. once you can remove asi_exit(), you should be able to replace all in-tree
users in one atomic change so that they're all switched to the new,
simplified interface
But I still have the feeling that we could re-jig what asi_enter/relax/exit do
and thus have a balanced interface. We'll see...
> I have now setup Mutt.
I did that 20 years ago. Never looked back. I'd say you're on the right track
:-)
> But, for now I am replying with plan vim + git-send-email, because I also
> sent this RFC to a ridiculous CC list (I just blindly used the
> get_maintainers.pl output, I don't know why I thought that was a reasonable
> approach) and it turns out this is the easiest way to trim it in a reply!
> Hopefully I can get the headers right...
Yeah, works. On the next version, you could trim it to the couple relevant
lists and to whoever reviewed this. The others can always get the thread from
lore and there's really no need anymore to Cc the whole world :)
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2025-03-14 13:14 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-10 18:40 [PATCH RFC v2 00/29] Address Space Isolation (ASI) Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 01/29] mm: asi: Make some utility functions noinstr compatible Brendan Jackman
2025-01-16 0:18 ` Borislav Petkov
2025-01-16 10:27 ` Borislav Petkov
2025-01-16 13:22 ` Brendan Jackman
2025-01-16 14:02 ` Borislav Petkov
2025-01-10 18:40 ` [PATCH RFC v2 02/29] x86: Create CONFIG_MITIGATION_ADDRESS_SPACE_ISOLATION Brendan Jackman
2025-01-16 16:43 ` Borislav Petkov
2025-03-01 7:23 ` Mike Rapoport
2025-03-05 13:12 ` Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 03/29] mm: asi: Introduce ASI core API Brendan Jackman
2025-02-19 10:55 ` Borislav Petkov
2025-02-19 13:50 ` Brendan Jackman
2025-02-19 13:53 ` Brendan Jackman
2025-02-27 12:06 ` Borislav Petkov
2025-02-28 8:43 ` Brendan Jackman
2025-03-14 13:14 ` Borislav Petkov [this message]
2025-03-15 1:34 ` Junaid Shahid
2025-03-15 12:36 ` Borislav Petkov
2025-03-17 11:40 ` Brendan Jackman
2025-03-18 0:50 ` Junaid Shahid
2025-03-18 13:03 ` Brendan Jackman
2025-03-18 22:48 ` Junaid Shahid
2025-03-19 15:23 ` Borislav Petkov
2025-01-10 18:40 ` [PATCH RFC v2 04/29] mm: asi: Add infrastructure for boot-time enablement Brendan Jackman
2025-03-19 17:29 ` Borislav Petkov
2025-03-19 18:47 ` Yosry Ahmed
2025-03-20 10:44 ` Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 05/29] mm: asi: ASI support in interrupts/exceptions Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 06/29] mm: asi: Use separate PCIDs for restricted address spaces Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 07/29] mm: asi: Make __get_current_cr3_fast() ASI-aware Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 08/29] mm: asi: Avoid warning from NMI userspace accesses in ASI context Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 09/29] mm: asi: ASI page table allocation functions Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 10/29] mm: asi: asi_exit() on PF, skip handling if address is accessible Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 11/29] mm: asi: Functions to map/unmap a memory range into ASI page tables Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 12/29] mm: asi: Add basic infrastructure for global non-sensitive mappings Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 13/29] mm: Add __PAGEFLAG_FALSE Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 14/29] mm: asi: Map non-user buddy allocations as nonsensitive Brendan Jackman
2025-01-10 18:40 ` [PATCH TEMP WORKAROUND RFC v2 15/29] mm: asi: Workaround missing partial-unmap support Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 16/29] mm: asi: Map kernel text and static data as nonsensitive Brendan Jackman
2025-01-17 11:23 ` Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 17/29] mm: asi: Map vmalloc/vmap " Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 18/29] mm: asi: Map dynamic percpu memory " Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 19/29] mm: asi: Stabilize CR3 in switch_mm_irqs_off() Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 20/29] mm: asi: Make TLB flushing correct under ASI Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 21/29] KVM: x86: asi: Restricted address space for VM execution Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 22/29] mm: asi: exit ASI before accessing CR3 from C code where appropriate Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 23/29] mm: asi: exit ASI before suspend-like operations Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 24/29] mm: asi: Add infrastructure for mapping userspace addresses Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 25/29] mm: asi: Restricted execution fore bare-metal processes Brendan Jackman
2025-02-28 15:32 ` Yosry Ahmed
2025-03-20 15:55 ` Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 26/29] x86: Create library for flushing L1D for L1TF Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 27/29] mm: asi: Add some mitigations on address space transitions Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 28/29] x86/pti: Disable PTI when ASI is on Brendan Jackman
2025-01-10 18:40 ` [PATCH RFC v2 29/29] mm: asi: Stop ignoring asi=on cmdline flag Brendan Jackman
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=20250314131419.GJZ9Qrq8scAtDyBUcg@fat_crate.local \
--to=bp@alien8.de \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=jackmanb@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
--cc=yosryahmed@google.com \
/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