All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@cloud.com>
To: Jason Andryuk <jason.andryuk@amd.com>
Cc: xen-devel@lists.xenproject.org, Juergen Gross <jgross@suse.com>,
	Julien Grall <julien@xen.org>
Subject: Re: [PATCH v6 1/4] tools/init-xenstore-domain: Replace variable MB() usage
Date: Wed, 3 Apr 2024 13:41:01 +0100	[thread overview]
Message-ID: <3bcdb957-717e-4505-951e-711c87744f6c@perard> (raw)
In-Reply-To: <20240327215102.136001-2-jason.andryuk@amd.com>

On Wed, Mar 27, 2024 at 05:50:59PM -0400, Jason Andryuk wrote:
> The local MB() & GB() macros will be replaced with a common
> implementation, but those only work with constant values.  Introduce a

By the way, this is not true, the macro introduce in the following patch
("tools: Move MB/GB() to common-macros.h") works (compiler doesn't
complain) if you do something like MB(maxmem+0) ;-).

> static inline mb_to_bytes() in place of the MB() macro to convert the
> variable values.
> 
> diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xenstore-domain.c
> index 1683438c5c..5405842dfe 100644
> --- a/tools/helpers/init-xenstore-domain.c
> +++ b/tools/helpers/init-xenstore-domain.c
> @@ -20,7 +20,6 @@
>  #include "init-dom-json.h"
>  
>  #define LAPIC_BASE_ADDRESS  0xfee00000UL
> -#define MB(x)               ((uint64_t)x << 20)
>  #define GB(x)               ((uint64_t)x << 30)
>  
>  static uint32_t domid = ~0;
> @@ -36,6 +35,11 @@ static xc_evtchn_port_or_error_t console_evtchn;
>  static xentoollog_level minmsglevel = XTL_PROGRESS;
>  static void *logger;
>  
> +static inline uint64_t mb_to_bytes(int mem)
> +{
> +	return (uint64_t)mem << 20;
> +}
> +
>  static struct option options[] = {
>      { "kernel", 1, NULL, 'k' },
>      { "memory", 1, NULL, 'm' },
> @@ -76,8 +80,8 @@ static int build(xc_interface *xch)
>      int rv, xs_fd;
>      struct xc_dom_image *dom = NULL;
>      int limit_kb = (maxmem ? : memory) * 1024 + X86_HVM_NR_SPECIAL_PAGES * 4;
> -    uint64_t mem_size = MB(memory);
> -    uint64_t max_size = MB(maxmem ? : memory);
> +    uint64_t mem_size = mb_to_bytes(memory);
> +    uint64_t max_size = mb_to_bytes(maxmem ? : memory);
>      struct e820entry e820[3];
>      struct xen_domctl_createdomain config = {
>          .ssidref = SECINITSID_DOMU,
 
Sorry, just notice they were more versions of the series, so repeating
here:

Looks like this change actually fix a bug. When `maxmem` is set, we
would have "max_size = maxmem", otherwise, it would be
"max_size = memory << 20"

The macro should have been written as
 #define MB(x)               ((uint64_t)(x) << 20)

This patch could be backported to 4.17 and later, with:
    Fixes: 134d53f57707 ("tools/init-xenstore-domain: fix memory map for PVH stubdom")

Anyway, this patch on it's own looks fine:
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>



-- 
Anthony PERARD


  reply	other threads:[~2024-04-03 12:41 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-27 21:50 [PATCH v6 0/4] x86/pvh: Support relocating dom0 kernel Jason Andryuk
2024-03-27 21:50 ` [PATCH v6 1/4] tools/init-xenstore-domain: Replace variable MB() usage Jason Andryuk
2024-04-03 12:41   ` Anthony PERARD [this message]
2024-04-03 12:51     ` Jason Andryuk
2024-04-04 10:09   ` Jan Beulich
2024-04-04 13:55     ` Jason Andryuk
2024-03-27 21:51 ` [PATCH v6 2/4] tools: Move MB/GB() to common-macros.h Jason Andryuk
2024-04-03 12:57   ` Anthony PERARD
2024-03-27 21:51 ` [PATCH v6 3/4] libelf: Store maximum PHDR p_align Jason Andryuk
2024-03-28 16:47   ` Jan Beulich
2024-03-29 14:41     ` Jason Andryuk
2024-04-02  6:44       ` Jan Beulich
2024-04-04 14:00         ` Jason Andryuk
2024-03-27 21:51 ` [PATCH v6 4/4] x86/PVH: Support relocatable dom0 kernels Jason Andryuk
2024-04-02 14:34   ` Jan Beulich
2024-04-04 14:01     ` Jason Andryuk
2024-03-27 21:55 ` [PATCH v6] RFC: x86/pvh: Make Xen PVH entrypoint PIC for x86-64 Jason Andryuk

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=3bcdb957-717e-4505-951e-711c87744f6c@perard \
    --to=anthony.perard@cloud.com \
    --cc=jason.andryuk@amd.com \
    --cc=jgross@suse.com \
    --cc=julien@xen.org \
    --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.