[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3 3/6] xen/x86: Use ASSERT instead of VIRTUAL_BUG_ON for phys_to_nid


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Wei Chen <wei.chen@xxxxxxx>
  • Date: Mon, 22 Aug 2022 10:58:07 +0800
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=2; 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=aO0eR2JiviKwTq0b191QwsRxcYqLc/8IFPWe53IzyX4=; b=UACoZ4YclbKw6YEqf747WGVDGawlPLZMh5LbBpFa+4CrCo0+KZ+CXmMnjjQxtihBf5VhuZIbqVEoz6t5rp0J3dn95tshBnfsyRjAGalY3ltChOZmBuxBBVsMyju3ZHRg5Sb+Fvv3SSr88GDD5sbZog+v2/yz0LKkDjLlLFygQgcLgSe6Q1M0S7+F5CWlB4TEAiIwlEIc3NmWsjF3Q+DKzcxqTI3JU+H8HvP+OC1ZbfDmu4eKXDAQ9vpQSy7NMYfpNf6OijojoRay1UqQKv9wSRSo6zJy5GPcBKTQ16mugav8qtDGmjHcD6iiRiHWQsVbtOBYSBZjxjFiWLJQyaIDjg==
  • 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=aO0eR2JiviKwTq0b191QwsRxcYqLc/8IFPWe53IzyX4=; b=QbhXcmlYeehALAyPnZ+G8puqWPbeRKBA95e9xw1Vd/H9fFDHTB2lgXI6JqSeQp8SSo5HsyYeBR6RTgQQDJHSFELEleL1MrmNeM/Eh5ndtXuGdYwcm8XT8IWVG0UwOBZdrSGaPF3S39FubGoacYikxgeprpQ6ers7lpDa6ja2YHSr9Fy2F5cwue7m8ZyHcU9vzcCmVlAeyt0vJNOeQtxWKcsUaZ5mQidzcqoT+Ye5dFpt2NGzt3hKQPfaATyVs+zfZ+QIOmyrvD6Mbm54Nvb2fUyjyX20d1zEjDGIHKbyLkqpQD4Qaj0unFmEJE7/UOfYupX5AKSnQ4aAsGzTt8Fs1w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=dyS0Xc3cmuyYKaud0hRFjrq5mJI+9DUY65/RFVYq/tDAWMkEAkBiEea4x1tjF9hF6SDaxyT4vXxbzd/5sYQ1cRekX3Ky/rP48z5MDtQth+Oj7Zri57zDY5/YrMEVGiMeSpAFqL7QM4rVBrI9GMOuL9enWUTMGoGazuJMmEKafEJobxe53jjqu70TvDImD/GN2a8dCUCSY35jB3NBRT0w1tylRzy9GdtZcmHIfIGXig269YhAc0ZwsPWas7AdEh7ulaGGib0ivsEBMomeCJ1SD15mi1FuN6OjRVxkS8a8q3zrwq36bnDdczYoK0uZPpe2eDCVp8Uct7Gc6sLwKH2Pyg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FZVaRQo0kiwoi6qPpDpFTBFCxKo1W1vRhktTpxK1P5NlwqS2fJbMiKqzUULO6qpt40HqoHNQNMwpJJSncD7jIeLkTAKWzi/T4I/tyaIUNRXqMy4cFicjVchW//wlFhzOYBQmnIEiJkCHaFZREjXTkk9jxaPKFV79PIiq+D2B7GgJ4esPXY70iMtOeX7ZiK7xBVpmn2Jc4RmdrxyfWqL5BkoYLMOnW7EmNRWUAyngnTD7rZGI6zGDfGo6l/OmxA3PmXXorNX/lDdZ4EfrJtFI9C7N7D3xPT9xa0VElA9GCwAQ2ImlTm5YXpoblrN2LwrkW2nhuTOJbLFUWfF6pONSiw==
  • Cc: <nd@xxxxxxx>, Wei Chen <wei.chen@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, "Jan Beulich" <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Jiamei Xie <jiamei.xie@xxxxxxx>
  • Delivery-date: Mon, 22 Aug 2022 02:59:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

VIRTUAL_BUG_ON is an empty macro used in phys_to_nid. This
results in two lines of error-checking code in phys_to_nid
that is not actually working and causing two compilation
errors:
1. error: "MAX_NUMNODES" undeclared (first use in this function).
   This is because in the common header file, "MAX_NUMNODES" is
   defined after the common header file includes the ARCH header
   file, where phys_to_nid has attempted to use "MAX_NUMNODES".
   This error was resolved after we moved the phys_to_nid from
   x86 ARCH header file to common header file.
2. error: wrong type argument to unary exclamation mark.
   This is because, the error-checking code contains !node_data[nid].
   But node_data is a data structure variable, it's not a pointer.

So, in this patch, we use ASSERT instead of VIRTUAL_BUG_ON to
enable the two lines of error-checking code. And fix the left
compilation errors by replacing !node_data[nid] to
!node_data[nid].node_spanned_pages. Although NUMA allows one node
can only have CPUs but without any memory. And node with 0 bytes
of memory might have an entry in memnodemap[] theoretically. But
that doesn't mean phys_to_nid can find any valid address from a
node with 0 bytes memory.

Signed-off-by: Wei Chen <wei.chen@xxxxxxx>
Tested-by: Jiamei Xie <jiamei.xie@xxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2 -> v3:
1. Remove unnecessary change items in history.
2. Add Acked-by.
v1 -> v2:
1. Use ASSERT to replace VIRTUAL_BUG_ON in phys_to_nid.
2. Adjust the conditional express for ASSERT.
3. Refine the justification of using !node_data[nid].node_spanned_pages.
---
 xen/include/xen/numa.h | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/xen/include/xen/numa.h b/xen/include/xen/numa.h
index bae534bb04..b779e68787 100644
--- a/xen/include/xen/numa.h
+++ b/xen/include/xen/numa.h
@@ -36,8 +36,6 @@ struct node {
 extern unsigned int compute_hash_shift(const struct node *nodes,
                                        nodeid_t numnodes, nodeid_t *nodeids);
 
-#define VIRTUAL_BUG_ON(x)
-
 extern bool numa_off;
 extern void numa_add_cpu(unsigned int cpu);
 extern void numa_init_array(void);
@@ -69,9 +67,9 @@ extern struct node_data node_data[];
 static inline __attribute_pure__ nodeid_t phys_to_nid(paddr_t addr)
 {
     nodeid_t nid;
-    VIRTUAL_BUG_ON((paddr_to_pdx(addr) >> memnode_shift) >= memnodemapsize);
+    ASSERT((paddr_to_pdx(addr) >> memnode_shift) < memnodemapsize);
     nid = memnodemap[paddr_to_pdx(addr) >> memnode_shift];
-    VIRTUAL_BUG_ON(nid >= MAX_NUMNODES || !node_data[nid]);
+    ASSERT(nid < MAX_NUMNODES && node_data[nid].node_spanned_pages);
     return nid;
 }
 
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.