From: Alexey Kardashevskiy <aik@amd.com>
To: Chenyi Qiang <chenyi.qiang@intel.com>,
Xiaoyao Li <xiaoyao.li@intel.com>, Peter Xu <peterx@redhat.com>
Cc: "David Hildenbrand" <david@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Michael Roth" <michael.roth@amd.com>,
qemu-devel@nongnu.org, kvm@vger.kernel.org,
"Williams Dan J" <dan.j.williams@intel.com>,
"Peng Chao P" <chao.p.peng@intel.com>,
"Gao Chao" <chao.gao@intel.com>, "Xu Yilun" <yilun.xu@intel.com>
Subject: Re: [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager
Date: Fri, 24 Jan 2025 16:56:50 +1100 [thread overview]
Message-ID: <2115c769-144c-4254-94b0-6b38b7afc6fc@amd.com> (raw)
In-Reply-To: <d54f6f53-3d11-477e-8849-cc3d28a201db@intel.com>
On 24/1/25 14:09, Chenyi Qiang wrote:
>
>
> On 1/24/2025 8:15 AM, Alexey Kardashevskiy wrote:
>>
>>
>> On 22/1/25 16:38, Xiaoyao Li wrote:
>>> On 1/22/2025 11:28 AM, Chenyi Qiang wrote:
>>>>
>>>>
>>>> On 1/22/2025 12:35 AM, Peter Xu wrote:
>>>>> On Tue, Jan 21, 2025 at 09:35:26AM +0800, Chenyi Qiang wrote:
>>>>>>
>>>>>>
>>>>>> On 1/21/2025 2:33 AM, Peter Xu wrote:
>>>>>>> On Mon, Jan 20, 2025 at 06:54:14PM +0100, David Hildenbrand wrote:
>>>>>>>> On 20.01.25 18:21, Peter Xu wrote:
>>>>>>>>> On Mon, Jan 20, 2025 at 11:48:39AM +0100, David Hildenbrand wrote:
>>>>>>>>>> Sorry, I was traveling end of last week. I wrote a mail on the
>>>>>>>>>> train and
>>>>>>>>>> apparently it was swallowed somehow ...
>>>>>>>>>>
>>>>>>>>>>>> Not sure that's the right place. Isn't it the (cc) machine
>>>>>>>>>>>> that controls
>>>>>>>>>>>> the state?
>>>>>>>>>>>
>>>>>>>>>>> KVM does, via MemoryRegion->RAMBlock->guest_memfd.
>>>>>>>>>>
>>>>>>>>>> Right; I consider KVM part of the machine.
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>> It's not really the memory backend, that's just the memory
>>>>>>>>>>>> provider.
>>>>>>>>>>>
>>>>>>>>>>> Sorry but is not "providing memory" the purpose of "memory
>>>>>>>>>>> backend"? :)
>>>>>>>>>>
>>>>>>>>>> Hehe, what I wanted to say is that a memory backend is just
>>>>>>>>>> something to
>>>>>>>>>> create a RAMBlock. There are different ways to create a
>>>>>>>>>> RAMBlock, even
>>>>>>>>>> guest_memfd ones.
>>>>>>>>>>
>>>>>>>>>> guest_memfd is stored per RAMBlock. I assume the state should
>>>>>>>>>> be stored per
>>>>>>>>>> RAMBlock as well, maybe as part of a "guest_memfd state" thing.
>>>>>>>>>>
>>>>>>>>>> Now, the question is, who is the manager?
>>>>>>>>>>
>>>>>>>>>> 1) The machine. KVM requests the machine to perform the
>>>>>>>>>> transition, and the
>>>>>>>>>> machine takes care of updating the guest_memfd state and
>>>>>>>>>> notifying any
>>>>>>>>>> listeners.
>>>>>>>>>>
>>>>>>>>>> 2) The RAMBlock. Then we need some other Object to trigger
>>>>>>>>>> that. Maybe
>>>>>>>>>> RAMBlock would have to become an object, or we allocate
>>>>>>>>>> separate objects.
>>>>>>>>>>
>>>>>>>>>> I'm leaning towards 1), but I might be missing something.
>>>>>>>>>
>>>>>>>>> A pure question: how do we process the bios gmemfds? I assume
>>>>>>>>> they're
>>>>>>>>> shared when VM starts if QEMU needs to load the bios into it,
>>>>>>>>> but are they
>>>>>>>>> always shared, or can they be converted to private later?
>>>>>>>>
>>>>>>>> You're probably looking for memory_region_init_ram_guest_memfd().
>>>>>>>
>>>>>>> Yes, but I didn't see whether such gmemfd needs conversions
>>>>>>> there. I saw
>>>>>>> an answer though from Chenyi in another email:
>>>>>>>
>>>>>>> https://lore.kernel.org/all/fc7194ee-ed21-4f6b-
>>>>>>> bf87-147a47f5f074@intel.com/
>>>>>>>
>>>>>>> So I suppose the BIOS region must support private / share
>>>>>>> conversions too,
>>>>>>> just like the rest part.
>>>>>>
>>>>>> Yes, the BIOS region can support conversion as well. I think
>>>>>> guest_memfd
>>>>>> backed memory regions all follow the same sequence during setup time:
>>>>>>
>>>>>> guest_memfd is shared when the guest_memfd fd is created by
>>>>>> kvm_create_guest_memfd() in ram_block_add(), But it will sooner be
>>>>>> converted to private just after kvm_set_user_memory_region() in
>>>>>> kvm_set_phys_mem(). So at the boot time of cc VM, the default
>>>>>> attribute
>>>>>> is private. During runtime, the vBIOS can also do the conversion if it
>>>>>> wants.
>>>>>
>>>>> I see.
>>>>>
>>>>>>
>>>>>>>
>>>>>>> Though in that case, I'm not 100% sure whether that could also be
>>>>>>> done by
>>>>>>> reusing the major guest memfd with some specific offset regions.
>>>>>>
>>>>>> Not sure if I understand you clearly. guest_memfd is per-Ramblock. It
>>>>>> will have its own slot. So the vBIOS can use its own guest_memfd to
>>>>>> get
>>>>>> the specific offset regions.
>>>>>
>>>>> Sorry to be confusing, please feel free to ignore my previous comment.
>>>>> That came from a very limited mindset that maybe one confidential VM
>>>>> should
>>>>> only have one gmemfd..
>>>>>
>>>>> Now I see it looks like it's by design open to multiple gmemfds for
>>>>> each
>>>>> VM, then it's definitely ok that bios has its own.
>>>>>
>>>>> Do you know why the bios needs to be convertable? I wonder whether
>>>>> the VM
>>>>> can copy it over to a private region and do whatever it wants, e.g.
>>>>> attest
>>>>> the bios being valid. However this is also more of a pure
>>>>> question.. and
>>>>> it can be offtopic to this series, so feel free to ignore.
>>>>
>>>> AFAIK, the vBIOS won't do conversion after it is set as private at the
>>>> beginning. But in theory, the VM can do the conversion at runtime with
>>>> current implementation. As for why make the vBIOS convertable, I'm also
>>>> uncertain about it. Maybe convenient for managing the private/shared
>>>> status by guest_memfd as it's also converted once at the beginning.
>>>
>>> The reason is just that we are too lazy to implement a variant of
>>> guest memfd for vBIOS that is disallowed to be converted from private
>>> to shared.
>>
>> What is the point in disallowing such conversion in QEMU? On AMD, a
>> malicious HV can try converting at any time and if the guest did not ask
>> for it, it will continue accessing those pages as private and trigger an
>> RMP fault. But if the guest asked for conversion, then it should be no
>> problem to convert to shared. What do I miss about TDX here? Thanks,
>
> Re-read Peter's question, maybe I misunderstood it a little bit.
>
> I thought Peter asked why the vBIOS need to do page conversion since it
> would keep private and no need to convert to shared at runtime. So it is
I suspect there is no need to convert vBIOS but also there is no need to
assume that some memory is never convertable.
> not necessary to manage the vBIOS with guest_memfd-backed memory region
> as it only converts to private once during setup stage. Xiaoyao
> mentioned no need to implement a variant of guest_memfd to convert from
> private to shared. As you said, allowing such conversion won't bring
> security issues.
>
> Now, I assume Peter's real question is, if we can copy the vBIOS to a
> private region and no need to create a specific guest_memfd-backed
> memory region for it?
I guess we can copy it but we have pc.bios and pc.rom in own memory
regions for some reason even for legacy non-secure VMs, for ages, so it
has little or nothing to do with whether vBIOS is in private or shared
memory. Thanks,
>
>>
>>
>>>
>>>>>
>>>>> Thanks,
>>>>>
>>>>
>>>
>>
>
--
Alexey
next prev parent reply other threads:[~2025-01-24 5:58 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 7:08 [PATCH 0/7] Enable shared device assignment Chenyi Qiang
2024-12-13 7:08 ` [PATCH 1/7] memory: Export a helper to get intersection of a MemoryRegionSection with a given range Chenyi Qiang
2024-12-18 12:33 ` David Hildenbrand
2025-01-08 4:47 ` Alexey Kardashevskiy
2025-01-08 6:41 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 2/7] guest_memfd: Introduce an object to manage the guest-memfd with RamDiscardManager Chenyi Qiang
2024-12-18 6:45 ` Chenyi Qiang
2025-01-08 4:48 ` Alexey Kardashevskiy
2025-01-08 10:56 ` Chenyi Qiang
2025-01-08 11:20 ` Alexey Kardashevskiy
2025-01-09 2:11 ` Chenyi Qiang
2025-01-09 2:55 ` Alexey Kardashevskiy
2025-01-09 4:29 ` Chenyi Qiang
2025-01-10 0:58 ` Alexey Kardashevskiy
2025-01-10 6:38 ` Chenyi Qiang
2025-01-09 21:00 ` Xu Yilun
2025-01-09 21:50 ` Xu Yilun
2025-01-13 3:34 ` Chenyi Qiang
2025-01-12 22:23 ` Xu Yilun
2025-01-14 1:14 ` Chenyi Qiang
2025-01-15 4:06 ` Alexey Kardashevskiy
2025-01-15 6:15 ` Chenyi Qiang
[not found] ` <2b2730f3-6e1a-4def-b126-078cf6249759@amd.com>
2025-01-20 20:46 ` Peter Xu
2024-06-24 16:31 ` Xu Yilun
2025-01-21 15:18 ` Peter Xu
2025-01-22 4:30 ` Alexey Kardashevskiy
2025-01-22 9:41 ` Xu Yilun
2025-01-22 16:43 ` Peter Xu
2025-01-23 9:33 ` Xu Yilun
2025-01-23 16:47 ` Peter Xu
2025-01-24 9:47 ` Xu Yilun
2025-01-24 15:55 ` Peter Xu
2025-01-24 18:17 ` David Hildenbrand
2025-01-26 3:34 ` Xu Yilun
2025-01-30 16:28 ` Peter Xu
2025-01-30 16:51 ` David Hildenbrand
2025-02-06 10:41 ` Xu Yilun
2025-02-06 20:03 ` Peter Xu
2025-01-14 6:45 ` Chenyi Qiang
2025-01-13 10:54 ` David Hildenbrand
2025-01-14 1:10 ` Chenyi Qiang
2025-01-15 4:05 ` Alexey Kardashevskiy
[not found] ` <f3aaffe7-7045-4288-8675-349115a867ce@redhat.com>
2025-01-20 17:21 ` Peter Xu
2025-01-20 17:54 ` David Hildenbrand
2025-01-20 18:33 ` Peter Xu
2025-01-20 18:47 ` David Hildenbrand
2025-01-20 20:19 ` Peter Xu
2025-01-20 20:25 ` David Hildenbrand
2025-01-20 20:43 ` Peter Xu
2025-01-21 1:35 ` Chenyi Qiang
2025-01-21 16:35 ` Peter Xu
2025-01-22 3:28 ` Chenyi Qiang
2025-01-22 5:38 ` Xiaoyao Li
2025-01-24 0:15 ` Alexey Kardashevskiy
2025-01-24 3:09 ` Chenyi Qiang
2025-01-24 5:56 ` Alexey Kardashevskiy [this message]
2025-01-24 16:12 ` Peter Xu
2025-01-20 18:09 ` Peter Xu
2025-01-21 9:00 ` Chenyi Qiang
2025-01-21 9:26 ` David Hildenbrand
2025-01-21 10:16 ` Chenyi Qiang
2025-01-21 10:26 ` David Hildenbrand
2025-01-22 6:43 ` Chenyi Qiang
2025-01-21 15:38 ` Peter Xu
2025-01-24 3:40 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 3/7] guest_memfd: Introduce a callback to notify the shared/private state change Chenyi Qiang
2024-12-13 7:08 ` [PATCH 4/7] KVM: Notify the state change event during shared/private conversion Chenyi Qiang
2024-12-13 7:08 ` [PATCH 5/7] memory: Register the RamDiscardManager instance upon guest_memfd creation Chenyi Qiang
2025-01-08 4:47 ` Alexey Kardashevskiy
2025-01-09 5:34 ` Chenyi Qiang
2025-01-09 9:32 ` Alexey Kardashevskiy
2025-01-10 5:13 ` Chenyi Qiang
[not found] ` <59bd0e82-f269-4567-8f75-a32c9c997ca9@redhat.com>
2025-01-24 3:27 ` Alexey Kardashevskiy
2025-01-24 5:36 ` Chenyi Qiang
2025-01-09 8:14 ` Zhao Liu
2025-01-09 8:17 ` Chenyi Qiang
2024-12-13 7:08 ` [PATCH 6/7] RAMBlock: make guest_memfd require coordinate discard Chenyi Qiang
2025-01-13 10:56 ` David Hildenbrand
2025-01-14 1:38 ` Chenyi Qiang
[not found] ` <e1141052-1dec-435b-8635-a41881fedd4c@redhat.com>
2025-01-21 6:26 ` Chenyi Qiang
2025-01-21 8:05 ` David Hildenbrand
2024-12-13 7:08 ` [RFC PATCH 7/7] memory: Add a new argument to indicate the request attribute in RamDismcardManager helpers Chenyi Qiang
2025-01-08 4:47 ` [PATCH 0/7] Enable shared device assignment Alexey Kardashevskiy
2025-01-08 6:28 ` Chenyi Qiang
2025-01-08 11:38 ` Alexey Kardashevskiy
2025-01-09 7:52 ` Chenyi Qiang
2025-01-09 8:18 ` Alexey Kardashevskiy
2025-01-09 8:49 ` Chenyi Qiang
2025-01-10 1:42 ` Alexey Kardashevskiy
2025-01-10 7:06 ` Chenyi Qiang
2025-01-10 8:26 ` David Hildenbrand
2025-01-10 13:20 ` Jason Gunthorpe
2025-01-10 13:45 ` David Hildenbrand
2025-01-10 14:14 ` Jason Gunthorpe
2025-01-10 14:50 ` David Hildenbrand
2025-01-15 3:39 ` Alexey Kardashevskiy
2025-01-15 12:49 ` Jason Gunthorpe
[not found] ` <cc3428b1-22b7-432a-9c74-12b7e36b6cc6@redhat.com>
2025-01-20 18:39 ` Jason Gunthorpe
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=2115c769-144c-4254-94b0-6b38b7afc6fc@amd.com \
--to=aik@amd.com \
--cc=chao.gao@intel.com \
--cc=chao.p.peng@intel.com \
--cc=chenyi.qiang@intel.com \
--cc=dan.j.williams@intel.com \
--cc=david@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=xiaoyao.li@intel.com \
--cc=yilun.xu@intel.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;
as well as URLs for NNTP newsgroup(s).