All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien@xen.org>
To: "Roger Pau Monné" <roger.pau@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>,
	Oleksandr Andrushchenko <andr2000@gmail.com>,
	Bertrand Marquis <Bertrand.Marquis@arm.com>,
	Oleksandr <olekstysh@gmail.com>,
	xen-devel <xen-devel@lists.xenproject.org>,
	Artem Mygaiev <joculator@gmail.com>
Subject: Re: Virtio in Xen on Arm (based on IOREQ concept)
Date: Wed, 22 Jul 2020 11:47:18 +0100	[thread overview]
Message-ID: <f3c54a7e-4352-7591-73c2-14215bd3ad34@xen.org> (raw)
In-Reply-To: <20200722082115.GR7191@Air-de-Roger>

Hi Roger,

On 22/07/2020 09:21, Roger Pau Monné wrote:
> On Tue, Jul 21, 2020 at 10:12:40PM +0100, Julien Grall wrote:
>> Hi Oleksandr,
>>
>> On 21/07/2020 19:16, Oleksandr wrote:
>>>
>>> On 21.07.20 17:27, Julien Grall wrote:
>>>> On a similar topic, I am a bit surprised you didn't encounter memory
>>>> exhaustion when trying to use virtio. Because on how Linux currently
>>>> works (see XSA-300), the backend domain as to have a least as much
>>>> RAM as the domain it serves. For instance, you have serve two
>>>> domains with 1GB of RAM each, then your backend would need at least
>>>> 2GB + some for its own purpose.
>>>>
>>>> This probably wants to be resolved by allowing foreign mapping to be
>>>> "paging" out as you would for memory assigned to a userspace.
>>>
>>> Didn't notice the last sentence initially. Could you please explain your
>>> idea in detail if possible. Does it mean if implemented it would be
>>> feasible to map all guest memory regardless of how much memory the guest
>>> has?
>>>
>>> Avoiding map/unmap memory each guest request would allow us to have
>>> better performance (of course with taking care of the fact that guest
>>> memory layout could be changed)...
>>
>> I will explain that below. Before let me comment on KVM first.
>>
>>> Actually what I understand looking at kvmtool is the fact it does not
>>> map/unmap memory dynamically, just calculate virt addresses according to
>>> the gfn provided.
>>
>> The memory management between KVM and Xen is quite different. In the case of
>> KVM, the guest RAM is effectively memory from the userspace (allocated via
>> mmap) and then shared with the guest.
>>
>>  From the userspace PoV, the guest memory will always be accessible from the
>> same virtual region. However, behind the scene, the pages may not always
>> reside in memory. They are basically managed the same way as "normal"
>> userspace memory.
>>
>> In the case of Xen, we are basically stealing a guest physical page
>> allocated via kmalloc() and provide no facilities for Linux to reclaim the
>> page if it needs to do it before the userspace decide to unmap the foreign
>> mapping.
>>
>> I think it would be good to handle the foreing mapping the same way as
>> userspace memory. By that I mean, that Linux could reclaim the physical page
>> used by the foreing mapping if it needs to.
>>
>> The process for reclaiming the page would look like:
>>      1) Unmap the foreign page
>>      2) Ballon in the backend domain physical address used by the foreing
>> mapping (allocate the page in the physmap)
>>
>> The next time the userspace is trying to access the foreign page, Linux will
>> receive a data abort that would result to:
>>      1) Allocate a backend domain physical page
>>      2) Balloon out the physical address (remove the page from the physmap)
>>      3) Map the foreing mapping at the new guest physical address
>>      4) Map the guest physical page in the userspace address space
> 
> This is going to shatter all the super pages in the stage-2
> translation.

Yes, but this is nothing really new as ballooning would result to 
(AFAICT) the same behavior on Linux.

> 
>> With this approach, we should be able to have backend domain that can handle
>> frontend domain without require a lot of memory.
> 
> Linux on x86 has the option to use empty hotplug memory ranges to map
> foreign memory: the balloon driver hotplugs an unpopulated physical
> memory range that's not made available to the OS free memory allocator
> and it's just used as scratch space to map foreign memory. Not sure
> whether Arm has something similar, or if it could be implemented.

We already discussed that last year :). This was attempted in the past 
(I was still at Citrix) and indefinitely paused for Arm.

/proc/iomem can be incomplete on Linux if we didn't load a driver for 
all the devices. This means that Linux doesn't have the full view of 
what is physical range is freed.

Additionally, in the case of Dom0, all the regions corresponding to the 
host RAM are unusable when using the SMMU. This is because we would do 
1:1 mapping for the foreign mapping as well.

It might be possible to take advantage of the direct mapping property if 
Linux do some bookeeping. Although, this wouldn't work for 32-bit Dom0 
using short page tables (e.g some version of Debian does) as it may not 
be able to access all the host RAM. Whether we still care about is a 
different situation :).

For all the other domains, I think we would want the toolstack to 
provide a region that can be safely used for foreign mapping (similar to 
what we already do for the grant-table).

> 
> You can still use the map-on-fault behaviour as above, but I would
> recommend that you try to limit the number of hypercalls issued.
> Having to issue a single hypercall for each page fault it's going to
> be slow, so I would instead use mmap batch to map the hole range in
> unpopulated physical memory and then the OS fault handler just needs to
> fill the page tables with the corresponding address.
IIUC your proposal, you are assuming that you will have enough free 
space in the physical address space to map the foreign mapping.

However that amount of free space is not unlimited and may be quite 
small (see above). It would be fairly easy to exhaust it given that a 
userspace application can map many times the same guest physical address.

So I still think we need to be able to allow Linux to swap a foreign 
page with another page.

Cheers,

-- 
Julien Grall


  reply	other threads:[~2020-07-22 10:47 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-17 14:11 Virtio in Xen on Arm (based on IOREQ concept) Oleksandr Tyshchenko
2020-07-17 15:00 ` Roger Pau Monné
2020-07-17 18:34   ` Oleksandr
2020-07-20  9:17     ` Roger Pau Monné
2020-07-20  9:40       ` Julien Grall
2020-07-20 10:20         ` Roger Pau Monné
2020-07-20 20:37           ` Stefano Stabellini
2020-07-21 12:31             ` Julien Grall
2020-07-21 13:25               ` Roger Pau Monné
2020-07-21 13:32                 ` Julien Grall
2020-07-21 13:40                   ` Roger Pau Monné
2020-07-21 14:09               ` Alex Bennée
2020-07-21 16:14                 ` Stefano Stabellini
2020-07-20 10:56       ` Oleksandr
2020-07-20 11:09         ` Roger Pau Monné
2020-07-20 20:40           ` Stefano Stabellini
2020-07-21 12:43             ` Oleksandr
2020-07-20 20:38     ` Stefano Stabellini
2020-07-21 12:26       ` Oleksandr
2020-07-21 13:43         ` Julien Grall
2020-07-21 14:32           ` André Przywara
2020-07-21 14:52             ` Oleksandr
2020-07-21 14:58               ` André Przywara
2020-07-21 16:09                 ` Oleksandr
2020-07-21 17:02                   ` André Przywara
2020-07-21 13:22       ` Julien Grall
2020-07-21 14:15         ` Alex Bennée
2020-07-21 14:40           ` Julien Grall
2020-07-21 16:42             ` Stefano Stabellini
2020-07-21 14:27     ` Julien Grall
2020-07-21 17:24       ` Oleksandr
2020-07-21 18:16       ` Oleksandr
2020-07-21 21:12         ` Julien Grall
2020-07-22  8:21           ` Roger Pau Monné
2020-07-22 10:47             ` Julien Grall [this message]
2020-07-22 11:10               ` Roger Pau Monné
2020-07-22 11:17                 ` Julien Grall
2020-07-22 11:37                   ` Roger Pau Monné

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=f3c54a7e-4352-7591-73c2-14215bd3ad34@xen.org \
    --to=julien@xen.org \
    --cc=Bertrand.Marquis@arm.com \
    --cc=andr2000@gmail.com \
    --cc=joculator@gmail.com \
    --cc=olekstysh@gmail.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.