All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Leif Lindholm <leif.lindholm@linaro.org>
Cc: "Huangpeng (Peter)" <peter.huangpeng@huawei.com>,
	Hangaohuai <hangaohuai@huawei.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	andrew@fubar.geek.nz, xen-devel <xen-devel@lists.xen.org>,
	Julien Grall <julien.grall@citrix.com>,
	Stefano Stabellini <stefano.stabellini@citrix.com>,
	Shannon Zhao <shannon.zhao@linaro.org>,
	Jan Beulich <jbeulich@suse.com>,
	Shannon Zhao <zhaoshenglong@huawei.com>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Roger Pau Monne <roger.pau@citrix.com>,
	Parth Dixit <parth.dixit@linaro.org>,
	Christoffer Dall <christoffer.dall@linaro.org>,
	David Vrabel <david.vrabel@citrix.com>
Subject: Re: Design doc of adding ACPI support for arm64 on Xen - version 5
Date: Wed, 2 Sep 2015 17:37:09 +0200	[thread overview]
Message-ID: <CAKv+Gu_qLLWqiq3sWLMRkc2dq-48y0Em92RmwaLWYkQSpgq1Sg@mail.gmail.com> (raw)
In-Reply-To: <20150902152753.GB10728@bivouac.eciton.net>

On 2 September 2015 at 17:27, Leif Lindholm <leif.lindholm@linaro.org> wrote:
> On Wed, Sep 02, 2015 at 03:57:51PM +0200, Christoffer Dall wrote:
>> On Wed, Sep 2, 2015 at 3:54 PM, Ian Campbell <ian.campbell@citrix.com> wrote:
>> > On Wed, 2015-09-02 at 14:48 +0100, Julien Grall wrote:
>> >> On 02/09/15 14:26, Ian Campbell wrote:
>> >> > > > > I think the problem is how you reserved this region in the EFI
>> >> > > > > memory
>> >> > > > > table. From what I saw, you marked this new memory with
>> >> > > > > EFI_MEMORY_WB
>> >> > > > > (which means that the region can be usable by Linux).
>> >> > > > >
>> >> > > > Yes, I mark it with EFI_MEMORY_WB. Is this right?
>> >> > >
>> >> > > I would say no, but it's only because I looked at the kernel code
>> >> > > quickly.
>> >> > >
>> >> > > You have to looks how ACPI region/UEFI tables are described in the
>> >> > > host
>> >> > > EFI memory map and mimicking for the DOM0 EFI memory map.
>> >> >
>> >> > Surely it is the type (EfiACPIReclaimMemory, EfiACPIMemoryNVS etc) and
>> >> > not
>> >> > the mapping attributes which should control whether an OS considers a
>> >> > region usable? At least until the OS is done parsing tables neither of
>> >> > those are usable (which implies we want NVS as our type, unless the
>> >> > memory
>> >> > is intended to be reclaimed by dom0, implying it should own it).
>
> The mapping attributes are checked to see whether a page _could_ be
> used as generic RAM or not. is_reserve_region() determines whether it
> should.
>

Only the following regions are ever considered to be usable as normal memory:

EFI_LOADER_CODE:
EFI_LOADER_DATA:
EFI_BOOT_SERVICES_CODE:
EFI_BOOT_SERVICES_DATA:
EFI_CONVENTIONAL_MEMORY:
EFI_PERSISTENT_MEMORY:

The code in is_reserve_region() reads a bit backwards, but the only
reason for the is_normal_ram() in there is to prevent non-memory
regions (i.e., MMIO regions for the RTC or NOR flash the UEFI uses) to
be memblock_reserve()d.

>> >> It looks like that Linux on ARM64 is considering any region with
>> >> EFI_MEMORY_WB set as normal RAM and will try to add as System RAM (see
>> >> reserve_regions in arch/arm64/kernel/efi.c).
>
> The current state of things ends up being basically:
>     if (EFI_MEMORY_WB)
>        memblock_add()
>     if (EFI_MEMORY_WB && !reclaimable_region)
>        memblock_reserve()
>
> That is, apart from counterintuitive, a bug.
> It should be using memblock_remove() instead.
>

Indeed. It would be much better to never add reserved memory to the
linear mapping this way, but the problem is that we lose all
annotation of this region being backed by memory. I.e., pfn_valid()
will return false, and the ACPI code will map it as a device,
resulting in alignment faults when traversing ACPI tables it contains.

So in the series Leif refers to below, I use the physmem memblock
table to record all regions, use the memory memblock table to only
record the regions available to the OS. That way, we can keep track of
which regions are backed by RAM but not covered by the linear mapping.

>> > It's hard to believe this isn't a bug... It's probably worth asking the
>> > Linux maintainers about this.
>>
>> wasn't this that whole workaround to make sure Linux maps the data as
>> regular RAM, because otherwise architecture generic code would map it
>> as IO memory,
>
> I hope not.
>

Indeed.

>> and generic routines such as memcpy would fault on
>> unaligned accesses, or am I confusing ACPI with EFI here?
>
> Even ACPI tables should need to be in Normal memory in order to work
> as expected.
>
>> Leif (added to the to-field) had some insight on this earlier on.
>
> (Adding Ard as well.)
> Ard wrote a series end of last year to clean much of this up, but it's
> not been merged:
> http://thread.gmane.org/gmane.linux.kernel.efi/5133
>
> We should probably push for this to go in as a bugfix, and those
> interested in seeing this can weigh in in public.
>

I will brush up the series and repost.

-- 
Ard.

  reply	other threads:[~2015-09-02 15:37 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28  9:45 Design doc of adding ACPI support for arm64 on Xen - version 5 Shannon Zhao
2015-08-28 12:55 ` Julien Grall
2015-08-29  1:00   ` Shannon Zhao
2015-08-31  7:33     ` Jan Beulich
2015-08-31 11:44     ` Julien Grall
2015-08-31 12:03       ` Shannon Zhao
2015-08-31 12:34         ` Julien Grall
2015-09-01  4:12           ` Shannon Zhao
2015-09-01 11:28             ` Julien Grall
2015-09-01 12:35               ` Shannon Zhao
2015-09-01 13:40                 ` Julien Grall
2015-09-01 14:03                   ` Jan Beulich
2015-09-01 14:20                     ` Julien Grall
2015-09-02  6:02                   ` Shannon Zhao
2015-09-02  8:41                     ` Jan Beulich
2015-09-02  9:18                       ` Christoffer Dall
2015-09-02 11:15                         ` Julien Grall
2015-09-02  9:25                       ` Shannon Zhao
2015-09-02 12:30                         ` Jan Beulich
2015-09-02 11:09                     ` Julien Grall
2015-09-02 12:02                       ` Shannon Zhao
2015-09-02 12:52                         ` Julien Grall
2015-09-02 13:26                           ` Ian Campbell
2015-09-02 13:48                             ` Julien Grall
2015-09-02 13:54                               ` Ian Campbell
2015-09-02 13:57                                 ` Christoffer Dall
2015-09-02 15:27                                   ` Leif Lindholm
2015-09-02 15:37                                     ` Ard Biesheuvel [this message]
2015-09-02 14:00                               ` Jan Beulich
2015-09-02 12:58           ` Ian Campbell
2015-08-28 15:06 ` Jan Beulich
2015-08-29  1:29   ` Shannon Zhao
2015-08-31  7:39     ` Jan Beulich
2015-08-31  8:51       ` Shannon Zhao
2015-08-31  9:40         ` Jan Beulich
2015-08-31 11:31           ` Shannon Zhao
2015-08-31 11:46             ` Jan Beulich
2015-09-02 12:54           ` Ian Campbell
2015-09-02 13:59             ` Shannon Zhao
2015-09-02 14:24               ` Ian Campbell
2015-09-02 12:18 ` Ian Campbell
2015-09-07  3:37   ` Shannon Zhao
2015-09-07 10:47     ` Stefano Stabellini

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=CAKv+Gu_qLLWqiq3sWLMRkc2dq-48y0Em92RmwaLWYkQSpgq1Sg@mail.gmail.com \
    --to=ard.biesheuvel@linaro.org \
    --cc=andrew@fubar.geek.nz \
    --cc=boris.ostrovsky@oracle.com \
    --cc=christoffer.dall@linaro.org \
    --cc=david.vrabel@citrix.com \
    --cc=hangaohuai@huawei.com \
    --cc=ian.campbell@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@citrix.com \
    --cc=leif.lindholm@linaro.org \
    --cc=parth.dixit@linaro.org \
    --cc=peter.huangpeng@huawei.com \
    --cc=roger.pau@citrix.com \
    --cc=shannon.zhao@linaro.org \
    --cc=stefano.stabellini@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xen.org \
    --cc=zhaoshenglong@huawei.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 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.