xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@eu.citrix.com>
To: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Cc: Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Hanweidong <hanweidong@huawei.com>,
	xen-devel@lists.xen.org,
	Stefano Stabellini <stefano.stabellini@citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>
Subject: Re: [PATCH v3 8/8] libxl, hvmloader: Don't relocate memory for MMIO hole
Date: Fri, 21 Jun 2013 09:31:55 +0100	[thread overview]
Message-ID: <51C40F7B.8010803@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1306201825210.4548@kaball.uk.xensource.com>

On 20/06/13 18:38, Stefano Stabellini wrote:
> On Thu, 20 Jun 2013, George Dunlap wrote:
>> At the moment, qemu-xen can't handle memory being relocated by
>> hvmloader.  This may happen if a device with a large enough memory
>> region is passed through to the guest.  At the moment, if this
>> happens, then at some point in the future qemu will crash and the
>> domain will hang.  (qemu-traditional is fine.)
>>
>> It's too late in the release to do a proper fix, so we try to do
>> damage control.
>>
>> hvmloader already has mechanisms to relocate memory to 64-bit space
>> if it can't make a big enough MMIO hole.  By default this is 2GiB; if
>> we just refuse to make the hole bigger if it will overlap with guest
>> memory, then the relocation will happen by default.
>>
>> v3:
>>   - Fix polarity of comparison
>>   - Move diagnostic messages to another patch
>>   - Tested with xen platform pci device hacked to have different BAR sizes
>>     {256MiB, 1GiB} x {qemu-xen, qemu-traditional} x various memory
>>     configurations
>>   - Add comment explaining why we default to "allow"
>>   - Remove cast to bool
>> v2:
>>   - style fixes
>>   - fix and expand comment on the MMIO hole loop
>>   - use "%d" rather than "%s" -> (...)?"1":"0"
>>   - use bool instead of uint8_t
>>   - Move 64-bit bar relocate detection to another patch
>>   - Add more diagnostic messages
>>
>> Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
>> CC: Ian Campbell <ian.campbell@citrix.com>
>> CC: Ian Jackson <ian.jackson@citrix.com>
>> CC: Stefano Stabellini <stefano.stabellini@citrix.com>
>> CC: Hanweidong <hanweidong@huawei.com>
>> CC: Keir Fraser <keir@xen.org>
>> CC: Keir Fraser <keir@xen.org>
>> ---
>>   tools/firmware/hvmloader/pci.c          |   49 +++++++++++++++++++++++++++++--
>>   tools/libxl/libxl_dm.c                  |    6 ++++
>>   xen/include/public/hvm/hvm_xs_strings.h |    1 +
>>   3 files changed, 54 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/firmware/hvmloader/pci.c b/tools/firmware/hvmloader/pci.c
>> index 3108c8a..2364177 100644
>> --- a/tools/firmware/hvmloader/pci.c
>> +++ b/tools/firmware/hvmloader/pci.c
>> @@ -27,6 +27,8 @@
>>   
>>   #include <xen/memory.h>
>>   #include <xen/hvm/ioreq.h>
>> +#include <xen/hvm/hvm_xs_strings.h>
>> +#include <stdbool.h>
>>   
>>   unsigned long pci_mem_start = PCI_MEM_START;
>>   unsigned long pci_mem_end = PCI_MEM_END;
>> @@ -57,6 +59,32 @@ void pci_setup(void)
>>       } *bars = (struct bars *)scratch_start;
>>       unsigned int i, nr_bars = 0;
>>   
>> +    const char *s;
>> +    /*
>> +     * Do we allow hvmloader to relocate guest memory in order to
>> +     * increase the size of the lowmem MMIO hole?  Defaulting to 1
>> +     * here will mean that non-libxl toolstacks (including xend and
>> +     * home-grown ones) will experience this series as "no change".
>> +     * It does mean that those using qemu-xen will still experience
>> +     * the bug (described below); but it also means that those using
>> +     * qemu-traditional will *not* experience any change; and it also
>> +     * means that there is a work-around for those using qemu-xen,
>> +     * namely switching to qemu-traditional.
>> +     *
>> +     * If we defaulted to 0, and failing to resize the hole caused any
>> +     * problems with qemu-traditional, then there is no work-around.
>> +     *
>> +     * Since xend can't talk to qemu-traditional, I think this is the
>> +     * option that will have the least impact.
>> +     */
>> +    bool allow_memory_relocate = 1;
>> +
>> +    s = xenstore_read(HVM_XS_ALLOW_MEMORY_RELOCATE, NULL);
>> +    if ( s )
>> +        allow_memory_relocate = strtoll(s, NULL, 0);
> Considering that strtoll retuns a long long, are we sure that this
> allocation does what we want for all the possible long long values
> that can be returned?
>
> For example, if strtoll returns -1, do we want allow_memory_relocate to
> be set to true?

The only valid values here are "0" and "1"; everything else is undefined.

Look, the bike shed is already painted, the brushes have been washed and 
put away.  Leave it be. :-)

>
>
>
>> +    printf("Relocating guest memory for lowmem MMIO space %s\n",
>> +           allow_memory_relocate?"enabled":"disabled");
>> +
>>       /* Program PCI-ISA bridge with appropriate link routes. */
>>       isa_irq = 0;
>>       for ( link = 0; link < 4; link++ )
>> @@ -208,8 +236,25 @@ void pci_setup(void)
>>           pci_writew(devfn, PCI_COMMAND, cmd);
>>       }
>>   
>> -    while ( (mmio_total > (pci_mem_end - pci_mem_start)) &&
>> -            ((pci_mem_start << 1) != 0) )
>> +    /*
>> +     * At the moment qemu-xen can't deal with relocated memory regions.
>> +     * It's too close to the release to make a proper fix; for now,
>> +     * only allow the MMIO hole to grow large enough to move guest memory
>> +     * if we're running qemu-traditional.  Items that don't fit will be
>> +     * relocated into the 64-bit address space.
>> +     *
>> +     * This loop now does the following:
>> +     * - If allow_memory_relocate, increase the MMIO hole until it's
>> +     *   big enough, or until it's 2GiB
>> +     * - If !allow_memory_relocate, increase the MMIO hole until it's
>> +     *   big enough, or until it's 2GiB, or until it overlaps guest
>> +     *   memory
>> +     */
>> +    while ( (mmio_total > (pci_mem_end - pci_mem_start))
>> +            && ((pci_mem_start << 1) != 0)
>> +            && (allow_memory_relocate
>> +                || (((pci_mem_start << 1) >> PAGE_SHIFT)
>> +                    >= hvm_info->low_mem_pgend)) )
>>           pci_mem_start <<= 1;
>>   
>>       if ( mmio_total > (pci_mem_end - pci_mem_start) ) {
>> diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
>> index ac1f90e..342d2ce 100644
>> --- a/tools/libxl/libxl_dm.c
>> +++ b/tools/libxl/libxl_dm.c
>> @@ -1154,6 +1154,12 @@ void libxl__spawn_local_dm(libxl__egc *egc, libxl__dm_spawn_state *dmss)
>>           libxl__xs_write(gc, XBT_NULL,
>>                           libxl__sprintf(gc, "%s/hvmloader/bios", path),
>>                           "%s", libxl_bios_type_to_string(b_info->u.hvm.bios));
>> +        /* Disable relocating memory to make the MMIO hole larger
>> +         * unless we're running qemu-traditional */
>> +        libxl__xs_write(gc, XBT_NULL,
>> +                        libxl__sprintf(gc, "%s/hvmloader/allow-memory-relocate", path),
>> +                        "%d",
>> +                        b_info->device_model_version==LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN_TRADITIONAL);
> line length

Blame the person who made a *47-character* identifier.

Seriously, would you rather have the "==" on a separate line or 
something? That seems really ridiculous.

I'll break the sprintf though.

  -George

  reply	other threads:[~2013-06-21  8:31 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 16:33 [PATCH 0/8] Relocate devices rather than memory for qemu-xen George Dunlap
2013-06-20 16:33 ` [PATCH v3 1/8] hvmloader: Remove all 64-bit print arguments George Dunlap
2013-06-20 17:06   ` Stefano Stabellini
2013-06-20 17:09     ` Ian Jackson
2013-06-21  8:37       ` George Dunlap
2013-06-21  8:34     ` George Dunlap
2013-06-21  9:22       ` George Dunlap
2013-06-21 10:22   ` [PATCH v3 1/8] hvmloader: Remove all 64-bit print arguments [and 1 more messages] Ian Jackson
2013-06-21 10:23   ` [PATCH v3 1/8] hvmloader: Remove all 64-bit print arguments Ian Jackson
2013-06-20 16:33 ` [PATCH v3 2/8] hvmloader: Make the printfs more informative George Dunlap
2013-06-20 17:12   ` Stefano Stabellini
2013-06-21  9:35     ` George Dunlap
2013-06-21  9:50       ` George Dunlap
2013-06-21 10:53         ` Stefano Stabellini
2013-06-21 10:53       ` Stefano Stabellini
2013-06-21 10:35   ` Ian Jackson
2013-06-20 16:33 ` [PATCH v3 3/8] hvmloader: Set up highmem resouce appropriately if there is no RAM above 4G George Dunlap
2013-06-20 17:16   ` Stefano Stabellini
2013-06-21  7:01   ` Jan Beulich
2013-06-21  9:06     ` George Dunlap
2013-06-21 10:38   ` Ian Jackson
2013-06-20 16:33 ` [PATCH v3 4/8] hvmloader: Fix check for needing a 64-bit bar George Dunlap
2013-06-20 16:33 ` [PATCH v3 5/8] hvmloader: Correct bug in low mmio region accounting George Dunlap
2013-06-20 17:20   ` Stefano Stabellini
2013-06-21  7:09   ` Jan Beulich
2013-06-20 16:33 ` [PATCH v3 6/8] hvmloader: Load large devices into high MMIO space as needed George Dunlap
2013-06-20 17:23   ` Stefano Stabellini
2013-06-21  7:12   ` Jan Beulich
2013-06-20 16:33 ` [PATCH v3 7/8] hvmloader: Remove minimum size for BARs to relocate to 64-bit space George Dunlap
2013-06-20 16:33 ` [PATCH v3 8/8] libxl, hvmloader: Don't relocate memory for MMIO hole George Dunlap
2013-06-20 17:38   ` Stefano Stabellini
2013-06-21  8:31     ` George Dunlap [this message]
2013-06-21 11:21       ` Stefano Stabellini
2013-06-21 11:31         ` Ian Jackson
2013-06-21  7:17   ` Jan Beulich
2013-06-21  8:32     ` George Dunlap

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=51C40F7B.8010803@eu.citrix.com \
    --to=george.dunlap@eu.citrix.com \
    --cc=hanweidong@huawei.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@citrix.com \
    --cc=stefano.stabellini@eu.citrix.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).