xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Daniel Kiper <daniel.kiper@oracle.com>
Cc: Jan Beulich <JBeulich@suse.com>, Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 2/2] efi/boot: Don't free ebmalloc area at all
Date: Tue, 28 Feb 2017 19:09:14 +0000	[thread overview]
Message-ID: <33a04856-4885-cc0d-08fa-e6b44a6d90d7@citrix.com> (raw)
In-Reply-To: <20170228190121.GK26294@olila.local.net-space.pl>

On 28/02/17 19:01, Daniel Kiper wrote:
> On Tue, Feb 28, 2017 at 05:58:26PM +0000, Andrew Cooper wrote:
>> On 28/02/17 17:41, Daniel Kiper wrote:
>>> On Tue, Feb 28, 2017 at 04:08:35PM +0000, Andrew Cooper wrote:
>>>> On 28/02/17 16:03, Jan Beulich wrote:
>>>>>>>> On 28.02.17 at 16:20, <andrew.cooper3@citrix.com> wrote:
>>>>>> Freeing part of the BSS back for general use proves to be problematic.  It is
>>>>>> not accounted for in xen_in_range(), causing errors when constructing the
>>>>>> IOMMU tables, resulting in a failure to boot.
>>>>>>
>>>>>> Other smaller issues are that tboot treats the entire BSS as hypervisor data,
>>>>>> creating and checking a MAC of it on S3, and that, by being 1MB in size,
>>>>>> freeing it guarentees to shatter the hypervisor superpage mappings.
>>>>>>
>>>>>> Judging by the content stored in it, 1MB is overkill on size.  Drop it to a
>>>>>> more-reasonable 32kB and keep the entire buffer around after boot.
>>>>> Well, that's just because right now there's only a single user. The
>>>>> reason I refused Daniel making it smaller than its predecessor is
>>>>> that we can't really give a good estimate of how much data may
>>>>> need storing there: The memory map can have hundreds of entries
>>>>> and command lines for modules may also be almost arbitrarily long.
>>>>>
>>>>> What I don't recall, Daniel: Why was it that we can't use EFI boot
>>>>> services allocations here?
>>>> From the original commit message,
>>>>
>>>>     1) We could use native EFI allocation functions (e.g. AllocatePool()
>>>>        or AllocatePages()) to get memory chunk. However, later (somewhere
>>>>        in __start_xen()) we must copy its contents to safe place or reserve
>>>>        it in e820 memory map and map it in Xen virtual address space. This
>>>>        means that the code referring to Xen command line, loaded modules and
>>>>        EFI memory map, mostly in __start_xen(), will be further complicated
>>>>        and diverge from legacy BIOS cases. Additionally, both former things
>>>>        have to be placed below 4 GiB because their addresses are stored in
>>>>        multiboot_info_t structure which has 32-bit relevant members.
>>>>
>>>>
>>>> One way or another, if we don't want to shatter superpages, we either
>>>> must keep the entire allocation, or copy the content out later into a
>>>> smaller location once other heap facilities are available.
>>> Hmmm... Why BSS free "shatter superpages" and .init.* sections free does not?
>> Xen is purposefully laid out like this:
>>
>> .text, 2M aligned, R/X
>> .rodata, 2M aligned, R/NX
>> .init.*, 2M aligned, R/W/X (reclaimed)
>> .data + .bss, 2M aligned, R/W/NX
> AIUI, the purpose is to have properly mapped (in terms of R/W/X/NX)
> sections. Right?

When I did the original work, it was both to get proper pagetable
permissions, and to get all of the compiled bits of Xen living in 2M
superpages (which allows the entire hypervisor to operate in 5 TLB entries!)

>
>> (In reality there is a syslinux bug which caused me to revert the 2M
>> alignment in non-EFI builds, so we are still using 4k alignment, but I
>> need to find a way to work around this and move back to enforcing the 2M
>> alignment.)
>>
>> When .init gets reclaimed, this leaves a (deliberate) hole which is all
>> 2M aligned, which has no impact on the adjacent 2M superpages.
>>
>> When ebmalloc gets reclaimed, it must shatter one or two superpages
>> mapping the .data/.bss section.
> Looking at this I do not have a better idea for fix off the top of my head.
> So, I have a feeling that we should drop free_ebmalloc_unused_mem() and leave
> comment around ebmalloc() why we do not reclaim unused ebmalloc_mem region.
> Should I post a patch or whether you would like to do it?

The patch at the root of this thread is basically that.

As a stopgap solution to unblock staging, I think I should drop the
adjustment of MB(1) to KB(32) and submit the patch.

This satisfies Jan's request to not make the current buffer smaller than
it currently is, and will give us more time to discuss alternative
solutions, at the cost of wasting 1MB of RAM.  (Not exactly breaking the
bank these days, but definitely something which should be fixed before
4.9 ships.)

>
>>> In regards to tboot I think that we should just take into account during
>>> calculation ebmalloc_mem allocated part only. Maybe move of ebmalloc_mem
>>> region to the end of BSS would help somehow here.
>> At the moment, all the ranges of Xen VA space are bounded by linker symbols.
>>
>> It is certainly possible to could account for the ebmalloc object in the
>> middle of the BSS, but it is turning into a layering violation.
> I am not sure what do you mean by "layering violation".

It feels hacky, and the wrong way to solve the problem.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-02-28 19:09 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 15:20 [PATCH 1/2] x86/layout: Correct Xen's idea of its own memory layout Andrew Cooper
2017-02-28 15:20 ` [PATCH 2/2] efi/boot: Don't free ebmalloc area at all Andrew Cooper
2017-02-28 16:03   ` Jan Beulich
2017-02-28 16:08     ` Andrew Cooper
2017-02-28 16:14       ` Jan Beulich
2017-02-28 17:09         ` Daniel Kiper
2017-02-28 17:24           ` Jan Beulich
2017-02-28 18:45             ` Daniel Kiper
2017-03-01  7:48               ` Jan Beulich
2017-03-01  8:20                 ` Daniel Kiper
2017-03-01  8:47                   ` Jan Beulich
2017-03-01  9:21                     ` Daniel Kiper
2017-02-28 17:41       ` Daniel Kiper
2017-02-28 17:58         ` Andrew Cooper
2017-02-28 19:01           ` Daniel Kiper
2017-02-28 19:09             ` Andrew Cooper [this message]
2017-02-28 19:21               ` Daniel Kiper
2017-03-01  8:02               ` Jan Beulich
2017-03-01  9:00                 ` Daniel Kiper
2017-03-01  9:08                   ` Jan Beulich
2017-03-01  9:44                     ` Daniel Kiper
2017-02-28 15:54 ` [PATCH 1/2] x86/layout: Correct Xen's idea of its own memory layout Jan Beulich

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=33a04856-4885-cc0d-08fa-e6b44a6d90d7@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=daniel.kiper@oracle.com \
    --cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).