All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Jan Beulich <JBeulich@suse.com>
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	206497@studenti.unimore.it,
	xen-devel <xen-devel@lists.xenproject.org>,
	nd@arm.com
Subject: Re: [PATCH] xen/arm: skip first page when RAM starts at 0x0
Date: Fri, 3 May 2019 13:16:47 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.10.1905031147490.3722@sstabellini-ThinkPad-X260> (raw)
In-Reply-To: <5CCBED14020000780022B7FE@prv1-mh.provo.novell.com>

On Fri, 3 May 2019, Jan Beulich wrote:
> >>> On 03.05.19 at 00:25, <sstabellini@kernel.org> wrote:
> > All right. Looking at the comment in pfn_pdx_hole_setup, it seems that
> > it is intending to skip the first MAX_ORDER bits, but actually it is
> > skipping the first MAX_ORDER-1 bits, if my calculations are correct.
> > 
> > MAX_ORDER is 18 on ARM which correspond to 1GB. With the current
> > implementation of pfn_pdx_hole_setup, if I pass a mask corresponding to
> > 512MB, I can see "PFN compression on bits 17...19". So the range
> > 512MB-1GB gets compressed.
> > 
> > Shouldn't it be:
> > 
> > diff --git a/xen/common/pdx.c b/xen/common/pdx.c
> > index 50c21b6..b334eb9 100644
> > --- a/xen/common/pdx.c
> > +++ b/xen/common/pdx.c
> > @@ -81,7 +81,7 @@ void __init pfn_pdx_hole_setup(unsigned long mask)
> >       * contiguous aligned ranges of 2^MAX_ORDER pages. Among others, our
> >       * buddy allocator relies on this assumption.
> >       */
> > -    for ( j = MAX_ORDER-1; ; )
> > +    for ( j = MAX_ORDER; ; )
> >      {
> >          i = find_next_zero_bit(&mask, BITS_PER_LONG, j);
> >          j = find_next_bit(&mask, BITS_PER_LONG, i); 
> 
> Yes, but. Originally we started from zero here. As a wild guess,
> I think Keir may have thought the cpumask_next() way when
> putting together bdb5439c3f, where an adjustment by 1 is
> needed in the call to find_next_bit(). Hence it probably was
> intuitive for him to have the index start at one less. I do think,
> however, that with the switch away from zero, things would
> better have become
> 
>     for ( j = MAX_ORDER - 1; ; )
>     {
>         i = find_next_zero_bit(&mask, BITS_PER_LONG, j + 1);
>         j = find_next_bit(&mask, BITS_PER_LONG, i + 1);
> 
> As you can see, using j + 1 when starting from zero wouldn't
> really have been correct (albeit we surely didn't expect to
> compress on bit zero, so this is merely a moot consideration).
> 
> Now there's a possible caveat here: While for symmetry also
> using i + 1 in the second call would seem desirable, I'm afraid
> it can't be used directly that way, as find_{,next_}zero_bit(),
> on x86 at least, assume their last argument to be less than
> their middle one. This, in turn, may already be violated in
> the general case (now that the function lives in common code):
> An architecture with all BITS_PER_LONG+PAGE_SIZE bits usable
> as physical address (x86-64 can use only up to 52, but x86-32
> can in principle - possibly with some extra conditions like running
> on top of a 64-bit hypervisor - use all 44 bits) the first call may
> already return BITS_PER_LONG, and hence the second call
> might already produce UB. As a result, to fix this other (latent
> only afaict) issue at the same time, the code imo ought to
> become
> 
>     for ( j = MAX_ORDER - 1; ; )
>     {
>         i = find_next_zero_bit(&mask, BITS_PER_LONG, j + 1);
>         if ( i >= BITS_PER_LONG )
>             break;
>         j = find_next_bit(&mask, BITS_PER_LONG, i + 1);
>         if ( j >= BITS_PER_LONG )
>             break;
> 

Makes sense. I tried it in my setup and it fixes the misbehavior I was
seeing. I am adding this patch to my short series of PDX fixes. I am
adding your signed-off-by to the patch, let me know if it is a problem.

_______________________________________________
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: Stefano Stabellini <sstabellini@kernel.org>
To: Jan Beulich <JBeulich@suse.com>
Cc: Stefano Stabellini <stefanos@xilinx.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	206497@studenti.unimore.it,
	xen-devel <xen-devel@lists.xenproject.org>,
	nd@arm.com
Subject: Re: [Xen-devel] [PATCH] xen/arm: skip first page when RAM starts at 0x0
Date: Fri, 3 May 2019 13:16:47 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.10.1905031147490.3722@sstabellini-ThinkPad-X260> (raw)
Message-ID: <20190503201647.5T2ChXK3L9Vr2DBxt9_oyvYbCN-6iLTUuMzBD09wgX0@z> (raw)
In-Reply-To: <5CCBED14020000780022B7FE@prv1-mh.provo.novell.com>

On Fri, 3 May 2019, Jan Beulich wrote:
> >>> On 03.05.19 at 00:25, <sstabellini@kernel.org> wrote:
> > All right. Looking at the comment in pfn_pdx_hole_setup, it seems that
> > it is intending to skip the first MAX_ORDER bits, but actually it is
> > skipping the first MAX_ORDER-1 bits, if my calculations are correct.
> > 
> > MAX_ORDER is 18 on ARM which correspond to 1GB. With the current
> > implementation of pfn_pdx_hole_setup, if I pass a mask corresponding to
> > 512MB, I can see "PFN compression on bits 17...19". So the range
> > 512MB-1GB gets compressed.
> > 
> > Shouldn't it be:
> > 
> > diff --git a/xen/common/pdx.c b/xen/common/pdx.c
> > index 50c21b6..b334eb9 100644
> > --- a/xen/common/pdx.c
> > +++ b/xen/common/pdx.c
> > @@ -81,7 +81,7 @@ void __init pfn_pdx_hole_setup(unsigned long mask)
> >       * contiguous aligned ranges of 2^MAX_ORDER pages. Among others, our
> >       * buddy allocator relies on this assumption.
> >       */
> > -    for ( j = MAX_ORDER-1; ; )
> > +    for ( j = MAX_ORDER; ; )
> >      {
> >          i = find_next_zero_bit(&mask, BITS_PER_LONG, j);
> >          j = find_next_bit(&mask, BITS_PER_LONG, i); 
> 
> Yes, but. Originally we started from zero here. As a wild guess,
> I think Keir may have thought the cpumask_next() way when
> putting together bdb5439c3f, where an adjustment by 1 is
> needed in the call to find_next_bit(). Hence it probably was
> intuitive for him to have the index start at one less. I do think,
> however, that with the switch away from zero, things would
> better have become
> 
>     for ( j = MAX_ORDER - 1; ; )
>     {
>         i = find_next_zero_bit(&mask, BITS_PER_LONG, j + 1);
>         j = find_next_bit(&mask, BITS_PER_LONG, i + 1);
> 
> As you can see, using j + 1 when starting from zero wouldn't
> really have been correct (albeit we surely didn't expect to
> compress on bit zero, so this is merely a moot consideration).
> 
> Now there's a possible caveat here: While for symmetry also
> using i + 1 in the second call would seem desirable, I'm afraid
> it can't be used directly that way, as find_{,next_}zero_bit(),
> on x86 at least, assume their last argument to be less than
> their middle one. This, in turn, may already be violated in
> the general case (now that the function lives in common code):
> An architecture with all BITS_PER_LONG+PAGE_SIZE bits usable
> as physical address (x86-64 can use only up to 52, but x86-32
> can in principle - possibly with some extra conditions like running
> on top of a 64-bit hypervisor - use all 44 bits) the first call may
> already return BITS_PER_LONG, and hence the second call
> might already produce UB. As a result, to fix this other (latent
> only afaict) issue at the same time, the code imo ought to
> become
> 
>     for ( j = MAX_ORDER - 1; ; )
>     {
>         i = find_next_zero_bit(&mask, BITS_PER_LONG, j + 1);
>         if ( i >= BITS_PER_LONG )
>             break;
>         j = find_next_bit(&mask, BITS_PER_LONG, i + 1);
>         if ( j >= BITS_PER_LONG )
>             break;
> 

Makes sense. I tried it in my setup and it fixes the misbehavior I was
seeing. I am adding this patch to my short series of PDX fixes. I am
adding your signed-off-by to the patch, let me know if it is a problem.

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

  reply	other threads:[~2019-05-03 20:16 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
2019-04-29 15:54                     ` [Xen-devel] " 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 [this message]
2019-05-03 20:16                                       ` 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=alpine.DEB.2.10.1905031147490.3722@sstabellini-ThinkPad-X260 \
    --to=sstabellini@kernel.org \
    --cc=206497@studenti.unimore.it \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=julien.grall@arm.com \
    --cc=nd@arm.com \
    --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.