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

[XEN v3] Xen: Ensure "xenheap_bits - PAGE_SHIFT" can be used as a rhs operand of shift operator


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Date: Fri, 2 Dec 2022 12:35:59 +0000
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org 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
  • 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=EgHT1+lbjR4JTCrqNY8MheImjOa7MHsLTBAZGqdrZJM=; b=J6+EHcHWmLTDjHCaA3m6RlM0uztS9AR+7R8Pf3e1LUXS0VNkFeGgPfTsSsb1R7BZrK8aw27BumjvxSMGtLEeUa7ewiGwRIRFTDTF6g7u5vHgJcl7GdvUfUbmX/hDdX8ZXVgo8rtNQTznjlCQcU85s/9dLbTzSBtA6tI47bsfXIDhxmF6LKPzgJruqzOgUJq8XHIuS0QqM+7mT1lYExbSqhXGOtvJoijf/h4Fvhs+QbNBqx4Lrv2GxwedrE/1+AqlMvENU0csszZ9EYeLRId7zpja70iigpswf1iKodJTqHc3+s8fpDLQ/7UPS8zambwK+/pbbaFirOuf7kn+JUlwkw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mn6JTb43WcLoLon/rgn9B7W9vG23WUB08COZsB7nRiFHKb/c3tUFfqdmLHz9YglISF/4b7W4zRiftS4S6mP3n7HQITh39p9Cd8nfF5spmF4/lQGe1EX8RgsHdsjQl7/Fh9BES+Nyw1PspvUDTuyY+hPktT4RcklGJ0OvqCX+MuYK6p33xEHbW6gRhmBWjkiqZTj3I2+Upb8LcBUFCSSwZnyUpW6SzqMxlJSLi90WiXpAhQgeSD9gIp2P4fr8BNnRcllczjCsL1ZtzoZOzfdq7AxV4Es6iwqnGXA/a1CM0i+AbO+Uc02T7HlASIuKtkODA9i/A8xYhrFxuBYHGj14Xw==
  • Cc: <sstabellini@xxxxxxxxxx>, <stefanos@xxxxxxxxxx>, <julien@xxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <george.dunlap@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, <bobbyeshleman@xxxxxxxxx>, <alistair.francis@xxxxxxx>, <connojdavis@xxxxxxxxx>, <wl@xxxxxxx>, Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
  • Delivery-date: Fri, 02 Dec 2022 12:36:24 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

We want to ensure that "xenheap_bits - PAGE_SHIFT" is strictly less than
the number of bits to represent unsigned long as it is used a rhs operand
to shift mfn.
It is also important to note that the "xenheap_bits - PAGE_SHIFT" is never
used to shift an address (rather than a frame number), and going forward
then also shouldn't be (perhaps unless further precautions are taken).

Signed-off-by: Ayan Kumar Halder <ayan.kumar.halder@xxxxxxx>
---

Currently this change will not have any impact on the existing architectures.
The following table illustrates PADDR_BITS vs BITS_PER_LONG of different archs

------------------------------------------------
| Arch      |   PADDR_BITS    |   BITS_PER_LONG |
------------------------------------------------
| Arm_64    |   48            |   64            |
| Arm_32    |   40            |   32            |
| RISCV_64  |   Don't know    |   64            |
| x86       |   52            |   64            |
-------------------------------------------------

However, this will change when we introduce a platform (For eg Cortex-R52) which
supports 32 bit physical address and BITS_PER_LONG. This platform does not 
follow
the same code path as Arm_32.
Thus, I have introduced this change as I don't see it causing a regression on
any of the supported platforms.

Changes from v1:-
1. Changed the check from "(PADDR_BITS > BITS_PER_LONG)" to "((PADDR_BITS - 
PAGE_SHIFT) >= BITS_PER_LONG)"
2. Updated the commit message to explain the reason for this.

v2 :-
1. Updated the commit message.

 xen/common/page_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c
index 62afb07bc6..c5b8c7444f 100644
--- a/xen/common/page_alloc.c
+++ b/xen/common/page_alloc.c
@@ -2245,7 +2245,7 @@ void __init xenheap_max_mfn(unsigned long mfn)
 {
     ASSERT(!first_node_initialised);
     ASSERT(!xenheap_bits);
-    BUILD_BUG_ON(PADDR_BITS >= BITS_PER_LONG);
+    BUILD_BUG_ON((PADDR_BITS - PAGE_SHIFT) >= BITS_PER_LONG);
     xenheap_bits = min(flsl(mfn + 1) - 1 + PAGE_SHIFT, PADDR_BITS);
     printk(XENLOG_INFO "Xen heap: %u bits\n", xenheap_bits);
 }
-- 
2.17.1




 


Rackspace

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