All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julien Grall <julien.grall@arm.com>
To: Jan Beulich <JBeulich@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Stefano Stabellini <stefanos@xilinx.com>,
	nd@arm.com, 206497@studenti.unimore.it,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH] xen/arm: skip first page when RAM starts at 0x0
Date: Mon, 29 Apr 2019 16:54:35 +0100	[thread overview]
Message-ID: <10687f88-fb6b-721c-c6e8-a1ab06023616@arm.com> (raw)
In-Reply-To: <5CC6A47E0200007800229D67@prv1-mh.provo.novell.com>

Hi,

On 29/04/2019 08:15, Jan Beulich wrote:
>>>> On 27.04.19 at 01:47, <sstabellini@kernel.org> wrote:
>> The other change to nr_pdxs is less obvious. It is clear that nr_pdxs is
>> calculated wrongly in this case (memory 0-0x80000000,
>> 0x800000000-0x880000000, ps=0, pe=0x880000000): nr_pdxs=524288 which is
>> half the number we need (the correct number is 1048575).
>>
>> Taking a line from the x86 code xen/arch/x86/setup.c:setup_max_pdx
>> (Julien's suggestion):
>>
>>    max_pdx = pfn_to_pdx(top_page - 1) + 1;
>>
>> I changed nr_pdxs to
>>    
>>    nr_pdxs = pfn_to_pdx((pe >> PAGE_SHIFT) - 1) + 1;
>>
>> and it works. I think the change is correct because looking at the
>> implementation of pfn_to_pdx it is certainly meant to operate on a pfn
>> masking bits on it to compensate for the holes. It is not meant to work
>> on a size.
>>
>> Jan, does it look correct to you too?
> 
> Yes. pfn_to_pdx() and friends may only ever be passed actual
> PFNs / PDXes, not something that's one above or one below a
> valid range. I share Julien's question though: Was it really mere
> luck that things have been working to date?

TLDR; unexplained to not say mere luck

We define the size of the frametable using:

nr_pdxs = pfn_to_pdx(pe - ps);
frametable_size = nr_pdxs * sizeof (struct page_info);

mfn_to_page is implemented the following way:

frame_table + (mfn_to_pdx(mfn) - frametable_base_pdx)

Where frametable_base_pdx = pfn_to_pdx(ps >> PAGE_SHIFT)

On the two platforms (Juno-r2 + Foundation Model) I tested today, somehow

pfn_to_pdx(pe - ps) == (pfn_to_pdx((pe >> PAGE_SHIFT) - 1) + 1) - 
frametable_base_pdx)

So the frametable is correctly sized but I honestly I have no idea why it works.

Anyway, I also tested the change suggested by Stefano. This will substantially 
increase the size of the frametable on platform where the RAM does not start at 0.

For instance, on Foundation Model the RAM starts at 2GB. As we don't compress 
any of the first 31 bits, the frametable will now be 28MB bigger than we 
currently have (112MB up from 84MB).

So I think what we want is:

nr_pdxs = pfn_to_pdx(end - 1) - pfn_to_pdx(start) + 1;
frame_table_base_pdx = pfn_to_pdx(start);

On a side note, I noticed that the table is still much bigger than it should be. 
4GB of RAM should only require a frametable of 56MB, but it is 84MB. Anyway, 
that's probably a separate discussion.

Cheers,

-- 
Julien Grall

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

WARNING: multiple messages have this Message-ID (diff)
From: Julien Grall <julien.grall@arm.com>
To: Jan Beulich <JBeulich@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Stefano Stabellini <stefanos@xilinx.com>,
	nd@arm.com, 206497@studenti.unimore.it,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [Xen-devel] [PATCH] xen/arm: skip first page when RAM starts at 0x0
Date: Mon, 29 Apr 2019 16:54:35 +0100	[thread overview]
Message-ID: <10687f88-fb6b-721c-c6e8-a1ab06023616@arm.com> (raw)
Message-ID: <20190429155435.qp5R06EJYolUCDqagcbar7xM-BbluGzx1lFKKtAWtks@z> (raw)
In-Reply-To: <5CC6A47E0200007800229D67@prv1-mh.provo.novell.com>

Hi,

On 29/04/2019 08:15, Jan Beulich wrote:
>>>> On 27.04.19 at 01:47, <sstabellini@kernel.org> wrote:
>> The other change to nr_pdxs is less obvious. It is clear that nr_pdxs is
>> calculated wrongly in this case (memory 0-0x80000000,
>> 0x800000000-0x880000000, ps=0, pe=0x880000000): nr_pdxs=524288 which is
>> half the number we need (the correct number is 1048575).
>>
>> Taking a line from the x86 code xen/arch/x86/setup.c:setup_max_pdx
>> (Julien's suggestion):
>>
>>    max_pdx = pfn_to_pdx(top_page - 1) + 1;
>>
>> I changed nr_pdxs to
>>    
>>    nr_pdxs = pfn_to_pdx((pe >> PAGE_SHIFT) - 1) + 1;
>>
>> and it works. I think the change is correct because looking at the
>> implementation of pfn_to_pdx it is certainly meant to operate on a pfn
>> masking bits on it to compensate for the holes. It is not meant to work
>> on a size.
>>
>> Jan, does it look correct to you too?
> 
> Yes. pfn_to_pdx() and friends may only ever be passed actual
> PFNs / PDXes, not something that's one above or one below a
> valid range. I share Julien's question though: Was it really mere
> luck that things have been working to date?

TLDR; unexplained to not say mere luck

We define the size of the frametable using:

nr_pdxs = pfn_to_pdx(pe - ps);
frametable_size = nr_pdxs * sizeof (struct page_info);

mfn_to_page is implemented the following way:

frame_table + (mfn_to_pdx(mfn) - frametable_base_pdx)

Where frametable_base_pdx = pfn_to_pdx(ps >> PAGE_SHIFT)

On the two platforms (Juno-r2 + Foundation Model) I tested today, somehow

pfn_to_pdx(pe - ps) == (pfn_to_pdx((pe >> PAGE_SHIFT) - 1) + 1) - 
frametable_base_pdx)

So the frametable is correctly sized but I honestly I have no idea why it works.

Anyway, I also tested the change suggested by Stefano. This will substantially 
increase the size of the frametable on platform where the RAM does not start at 0.

For instance, on Foundation Model the RAM starts at 2GB. As we don't compress 
any of the first 31 bits, the frametable will now be 28MB bigger than we 
currently have (112MB up from 84MB).

So I think what we want is:

nr_pdxs = pfn_to_pdx(end - 1) - pfn_to_pdx(start) + 1;
frame_table_base_pdx = pfn_to_pdx(start);

On a side note, I noticed that the table is still much bigger than it should be. 
4GB of RAM should only require a frametable of 56MB, but it is 84MB. Anyway, 
that's probably a separate discussion.

Cheers,

-- 
Julien Grall

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

  reply	other threads:[~2019-04-29 15:54 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-25 17:51 [PATCH] xen/arm: skip first page when RAM starts at 0x0 Stefano Stabellini
2019-04-25 17:51 ` [Xen-devel] " Stefano Stabellini
2019-04-25 21:27 ` Julien Grall
2019-04-25 21:27   ` [Xen-devel] " Julien Grall
2019-04-26  9:12   ` Jan Beulich
2019-04-26  9:12     ` [Xen-devel] " Jan Beulich
2019-04-26  9:19     ` Julien Grall
2019-04-26  9:19       ` [Xen-devel] " Julien Grall
2019-04-26  9:42       ` Jan Beulich
2019-04-26  9:42         ` [Xen-devel] " Jan Beulich
2019-04-26 15:38         ` Julien Grall
2019-04-26 15:38           ` [Xen-devel] " Julien Grall
2019-04-26 15:48           ` Jan Beulich
2019-04-26 15:48             ` [Xen-devel] " Jan Beulich
2019-04-26 21:31             ` Julien Grall
2019-04-26 21:31               ` [Xen-devel] " Julien Grall
2019-04-26 23:47               ` Stefano Stabellini
2019-04-26 23:47                 ` [Xen-devel] " Stefano Stabellini
2019-04-27 19:43                 ` Julien Grall
2019-04-27 19:43                   ` [Xen-devel] " Julien Grall
2019-04-29  7:15                 ` Jan Beulich
2019-04-29  7:15                   ` [Xen-devel] " Jan Beulich
2019-04-29 15:54                   ` Julien Grall [this message]
2019-04-29 15:54                     ` Julien Grall
2019-04-29 16:07                     ` Jan Beulich
2019-04-29 16:07                       ` [Xen-devel] " Jan Beulich
2019-04-29 17:51                       ` Stefano Stabellini
2019-04-29 17:51                         ` [Xen-devel] " Stefano Stabellini
2019-05-01 22:44                         ` Stefano Stabellini
2019-05-01 22:44                           ` [Xen-devel] " Stefano Stabellini
2019-05-02  7:30                           ` Jan Beulich
2019-05-02  7:30                             ` [Xen-devel] " Jan Beulich
2019-05-02  9:02                             ` Julien Grall
2019-05-02  9:02                               ` [Xen-devel] " Julien Grall
2019-05-02  9:20                               ` Jan Beulich
2019-05-02  9:20                                 ` [Xen-devel] " Jan Beulich
2019-05-02 22:25                                 ` Stefano Stabellini
2019-05-02 22:25                                   ` [Xen-devel] " Stefano Stabellini
2019-05-03  7:26                                   ` Jan Beulich
2019-05-03  7:26                                     ` [Xen-devel] " Jan Beulich
2019-05-03 20:16                                     ` Stefano Stabellini
2019-05-03 20:16                                       ` [Xen-devel] " Stefano Stabellini
2019-04-29  7:07               ` Jan Beulich
2019-04-29  7:07                 ` [Xen-devel] " 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=10687f88-fb6b-721c-c6e8-a1ab06023616@arm.com \
    --to=julien.grall@arm.com \
    --cc=206497@studenti.unimore.it \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=nd@arm.com \
    --cc=sstabellini@kernel.org \
    --cc=stefanos@xilinx.com \
    --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.