[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v6 1/4] tools/init-xenstore-domain: Replace variable MB() usage
- To: Anthony PERARD <anthony.perard@xxxxxxxxx>
- From: Jason Andryuk <jason.andryuk@xxxxxxx>
- Date: Wed, 3 Apr 2024 08:51:02 -0400
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=cloud.com smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=OMyIZ6BpMbAlZ4idaFKVciVEJZm2R12PLhnjEgAwobM=; b=MM5M9hIAIUTz9pJGq2tjR0VP0ZJ/7M2IHFfp1NQsGBUuFfXmUl90m+oBDWgjL9hoM+0XpYqi38fc/Xh/DJiMRG/5CMeN6Bo+pA7gYtGda2CCBq/lqswtnVIU03xBF7HsOBJfgQyBY/jnMAbZnVgMC8Li6xD4fHQhqYum3DLHRTQ1hdbDMG7LZ8/uQ0GKKPGe0b2q3i04AEHSawF2JLMSFEcGH3dF0dJMKsJ7mHnODS/yjTi8I3HoOXkYKtuSwTTlsLiJImUvx7xmDPA5J5Qz4se1n+tCmxRyqQ/JEKXPmpGWYvzoh6vVC7tISQgtD7yuMD2m+addlL95EmBCUOzXew==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OYVMmDwPp79OXmBYRsFPUQ6hwYtwr2/tK/6IUiJWTGVfWXVAhgFpbz5D33Qwyjp9ap5LXFqFpdyrK2+7X/9vEn+IByEOYJNKRKlfAu0mabCP1BVD9OjBE24rbUyXuj+U6bniJmnyD96rMsZso7yPaK0kf4cuClQstint9i+BLZJQ/onVI3M6jlsC/MHkbEG6gQ+N/ooG4YeBVrtZ13MW8PMy3ilW7c1LsxbrwFvW1ovAUjzyBaFfguo9C1wVjJqkmB2gNvvgqJC34pcRh0poXjGpyUoiiiX9EEmGnTz5ixQd3mpV31qFjrYnL4xzUJlNBLHTxXSBX8mV1z1PMFxPNQ==
- Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, "Julien Grall" <julien@xxxxxxx>
- Delivery-date: Wed, 03 Apr 2024 12:51:16 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
On 2024-04-03 08:41, Anthony PERARD wrote:
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) ;-).
Well, I think I wrote the wrong word for the description. The old Macro
might have been okay, but the new one as (_AC(_mb, ULL) << 20) fails for
MB(memory):
init-xenstore-domain.c: In function ‘build’:
init-xenstore-domain.c:82:28: error: ‘memoryULL’ undeclared (first use
in this function); did you mean ‘memory’?
82 | uint64_t mem_size = MB(memory);
| ^~~~~~
I should have written "only work for numeric values."
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")
Nice catch!
Anyway, this patch on it's own looks fine:
Reviewed-by: Anthony PERARD <anthony.perard@xxxxxxxxxx>
Thank you.
Regards,
Jason
|