All of lore.kernel.org
 help / color / mirror / Atom feed
From: Costin Lupu <costin.lupu@cs.pub.ro>
To: xen-devel@lists.xenproject.org
Cc: Tim Deegan <tim@xen.org>, Ian Jackson <iwj@xenproject.org>,
	Wei Liu <wl@xen.org>
Subject: [PATCH v3 1/5] tools/debugger: Fix PAGE_SIZE redefinition error
Date: Mon, 10 May 2021 11:35:15 +0300	[thread overview]
Message-ID: <88d4d2deeca3259450dc9af2b97f2fc1453a5d7d.1620633386.git.costin.lupu@cs.pub.ro> (raw)
In-Reply-To: <cover.1620633386.git.costin.lupu@cs.pub.ro>

If PAGE_SIZE is already defined in the system (e.g. in /usr/include/limits.h
header) then gcc will trigger a redefinition error because of -Werror. This
patch replaces usage of PAGE_* macros with KDD_PAGE_* macros in order to avoid
confusion between control domain page granularity (PAGE_* definitions) and
guest domain page granularity (which is what we are dealing with here).

We chose to define the KDD_PAGE_* macros instead of using XC_PAGE_* macros
because (1) the code in kdd.c should not include any Xen headers and (2) to add
consistency for code in both kdd.c and kdd-xen.c.

Signed-off-by: Costin Lupu <costin.lupu@cs.pub.ro>
---
 tools/debugger/kdd/kdd-xen.c | 15 ++++++---------
 tools/debugger/kdd/kdd.c     | 19 ++++++++-----------
 tools/debugger/kdd/kdd.h     |  7 +++++++
 3 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/tools/debugger/kdd/kdd-xen.c b/tools/debugger/kdd/kdd-xen.c
index f3f9529f9f..e78c9311c4 100644
--- a/tools/debugger/kdd/kdd-xen.c
+++ b/tools/debugger/kdd/kdd-xen.c
@@ -48,9 +48,6 @@
 
 #define MAPSIZE 4093 /* Prime */
 
-#define PAGE_SHIFT 12
-#define PAGE_SIZE (1U << PAGE_SHIFT)
-
 struct kdd_guest {
     struct xentoollog_logger xc_log; /* Must be first for xc log callbacks */
     xc_interface *xc_handle;
@@ -72,7 +69,7 @@ static void flush_maps(kdd_guest *g)
     int i;
     for (i = 0; i < MAPSIZE; i++) {
         if (g->maps[i] != NULL)
-            munmap(g->maps[i], PAGE_SIZE);
+            munmap(g->maps[i], KDD_PAGE_SIZE);
         g->maps[i] = NULL;
     }
 }
@@ -490,13 +487,13 @@ static uint32_t kdd_access_physical_page(kdd_guest *g, uint64_t addr,
     uint32_t map_pfn, map_offset;
     uint8_t *map;
 
-    map_pfn = (addr >> PAGE_SHIFT);
-    map_offset = addr & (PAGE_SIZE - 1);
+    map_pfn = (addr >> KDD_PAGE_SHIFT);
+    map_offset = addr & (KDD_PAGE_SIZE - 1);
 
     /* Evict any mapping of the wrong frame from our slot */ 
     if (g->pfns[map_pfn % MAPSIZE] != map_pfn
         && g->maps[map_pfn % MAPSIZE] != NULL) {
-        munmap(g->maps[map_pfn % MAPSIZE], PAGE_SIZE);
+        munmap(g->maps[map_pfn % MAPSIZE], KDD_PAGE_SIZE);
         g->maps[map_pfn % MAPSIZE] = NULL;
     }
     g->pfns[map_pfn % MAPSIZE] = map_pfn;
@@ -507,7 +504,7 @@ static uint32_t kdd_access_physical_page(kdd_guest *g, uint64_t addr,
     else {
         map = xc_map_foreign_range(g->xc_handle,
                                    g->domid,
-                                   PAGE_SIZE,
+                                   KDD_PAGE_SIZE,
                                    PROT_READ|PROT_WRITE,
                                    map_pfn);
 
@@ -533,7 +530,7 @@ uint32_t kdd_access_physical(kdd_guest *g, uint64_t addr,
 {
     uint32_t chunk, rv, done = 0;
     while (len > 0) {
-        chunk = PAGE_SIZE - (addr & (PAGE_SIZE - 1));
+        chunk = KDD_PAGE_SIZE - (addr & (KDD_PAGE_SIZE - 1));
         if (chunk > len) 
             chunk = len;
         rv = kdd_access_physical_page(g, addr, chunk, buf, write);
diff --git a/tools/debugger/kdd/kdd.c b/tools/debugger/kdd/kdd.c
index 17513c2650..320c623eda 100644
--- a/tools/debugger/kdd/kdd.c
+++ b/tools/debugger/kdd/kdd.c
@@ -288,9 +288,6 @@ static void kdd_log_pkt(kdd_state *s, const char *name, kdd_pkt *p)
  *  Memory access: virtual addresses and syntactic sugar.
  */
 
-#define PAGE_SHIFT (12)
-#define PAGE_SIZE (1ULL << PAGE_SHIFT) 
-
 static uint32_t kdd_read_physical(kdd_state *s, uint64_t addr, 
                                   uint32_t len, void *buf)
 {
@@ -352,7 +349,7 @@ static uint64_t v2p(kdd_state *s, int cpuid, uint64_t va)
 
     /* Walk the appropriate number of levels */
     for (i = levels; i > 0; i--) {
-        shift = PAGE_SHIFT + bits * (i-1);
+        shift = KDD_PAGE_SHIFT + bits * (i-1);
         mask = ((1ULL << bits) - 1) << shift;
         offset = ((va & mask) >> shift) * width;
         KDD_DEBUG(s, "level %i: mask 0x%16.16"PRIx64" pa 0x%16.16"PRIx64
@@ -364,12 +361,12 @@ static uint64_t v2p(kdd_state *s, int cpuid, uint64_t va)
             return -1ULL; // Not present
         pa = entry & 0x000ffffffffff000ULL;
         if (pse && (i == 2) && (entry & 0x80)) { // Superpage
-            mask = ((1ULL << (PAGE_SHIFT + bits)) - 1);
+            mask = ((1ULL << (KDD_PAGE_SHIFT + bits)) - 1);
             return (pa & ~mask) + (va & mask);
         }
     }
 
-    return pa + (va & (PAGE_SIZE - 1));
+    return pa + (va & (KDD_PAGE_SIZE - 1));
 }
 
 static uint32_t kdd_access_virtual(kdd_state *s, int cpuid, uint64_t addr,
@@ -380,7 +377,7 @@ static uint32_t kdd_access_virtual(kdd_state *s, int cpuid, uint64_t addr,
     
     /* Process one page at a time */
     while (len > 0) {
-        chunk = PAGE_SIZE - (addr & (PAGE_SIZE - 1));
+        chunk = KDD_PAGE_SIZE - (addr & (KDD_PAGE_SIZE - 1));
         if (chunk > len) 
             chunk = len;
         pa = v2p(s, cpuid, addr);
@@ -591,7 +588,7 @@ static void get_os_info_64(kdd_state *s)
     uint64_t dbgkd_addr;
     DBGKD_GET_VERSION64 dbgkd_get_version64;
     /* Maybe 1GB is too big for the limit to search? */
-    uint32_t search_limit = (1024 * 1024 * 1024) / PAGE_SIZE; /*1GB/PageSize*/
+    uint32_t search_limit = (1024 * 1024 * 1024) / KDD_PAGE_SIZE; /*1GB/PageSize*/
     uint64_t efer;
 
     /* if we are not in 64-bit mode, fail */
@@ -620,7 +617,7 @@ static void get_os_info_64(kdd_state *s)
      * in 1GB range above the current page base address
      */
 
-    base = idt0_addr & ~(PAGE_SIZE - 1);
+    base = idt0_addr & ~(KDD_PAGE_SIZE - 1);
 
     while (search_limit) {
         uint16_t val;
@@ -633,7 +630,7 @@ static void get_os_info_64(kdd_state *s)
         if (val == MZ_HEADER) // MZ
             break;
 
-        base -= PAGE_SIZE;
+        base -= KDD_PAGE_SIZE;
         search_limit -= 1;
     }
 
@@ -720,7 +717,7 @@ static void find_os(kdd_state *s)
         /* Try each page in the potential range of kernel load addresses */
         for (limit = s->os.base + s->os.range;
              s->os.base <= limit;
-             s->os.base += PAGE_SIZE)
+             s->os.base += KDD_PAGE_SIZE)
             if (check_os(s))
                 return;
     }
diff --git a/tools/debugger/kdd/kdd.h b/tools/debugger/kdd/kdd.h
index b9a17440df..b476a76d93 100644
--- a/tools/debugger/kdd/kdd.h
+++ b/tools/debugger/kdd/kdd.h
@@ -39,6 +39,13 @@
 
 #define PACKED __attribute__((packed))
 
+/* We define our page related constants here in order to specifically
+ * avoid using the Xen page macros (this is a restriction for the code
+ * in kdd.c which should not include any Xen headers) and to add
+ * consistency for code in both kdd.c and kdd-xen.c. */
+#define KDD_PAGE_SHIFT 12
+#define KDD_PAGE_SIZE (1U << KDD_PAGE_SHIFT)
+
 /*****************************************************************************
  * Serial line protocol: Sender sends a 16-byte header with an optional
  * payload following it.  Receiver responds to each packet with an
-- 
2.20.1



  reply	other threads:[~2021-05-10  8:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-10  8:35 [PATCH v3 0/5] Fix redefinition errors for toolstack libs Costin Lupu
2021-05-10  8:35 ` Costin Lupu [this message]
2021-05-11  6:35   ` [PATCH v3 1/5] tools/debugger: Fix PAGE_SIZE redefinition error Tim Deegan
2021-05-10  8:35 ` [PATCH v3 2/5] tools/libfsimage: Fix PATH_MAX " Costin Lupu
2021-05-10  8:35 ` [PATCH v3 3/5] tools/libs/foreignmemory: Fix PAGE_SIZE " Costin Lupu
2021-05-17 18:12   ` Julien Grall
2021-06-08 12:37     ` Costin Lupu
2021-05-10  8:35 ` [PATCH v3 4/5] tools/libs/gnttab: " Costin Lupu
2021-05-17 18:16   ` Julien Grall
2021-06-08 12:37     ` Costin Lupu
2021-05-10  8:35 ` [PATCH v3 5/5] tools/ocaml: Fix redefinition errors Costin Lupu
2021-05-17 18:16   ` Julien Grall
2021-05-19 14:03     ` Dario Faggioli

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=88d4d2deeca3259450dc9af2b97f2fc1453a5d7d.1620633386.git.costin.lupu@cs.pub.ro \
    --to=costin.lupu@cs.pub.ro \
    --cc=iwj@xenproject.org \
    --cc=tim@xen.org \
    --cc=wl@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.