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

[PATCH v10 1/5] xen/console: use ACCESS_ONCE for console_rx


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Date: Wed, 4 Feb 2026 15:37:08 -0800
  • 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 (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=z+m+wfbaQfqsO+srFswTlFpdkOkHztR+/HdKJrjtAEE=; b=oZu6urX+QGXoQzrPduGk/GB1YpW0Hub/re+Zpzz/XavS8kYDpkFmnw7JSZyRnKDZMIWRuTaw7GG/+SgH+x4lKviXqNeHrCI6si0JaeKa6kglqBlODWTA/FeOIRNXJuCIc9BVWTOExlLHibeuZUkQq4s5odnCJMn8jUEnqdV/5htKhqn+7IHSxwQ0gCKIfxEkWFXwP2Nj3zHGE/FlWDeDyrxZtS9uOJOhi5FY0kb/FEQhP+f37sHnf3FIDyuj1UawBZxdtf11asdLnQlHYlxrwt9z7THkMGRTYL9jZ8gCMtig3hzgori6KeoS31DRI92rh2vW1C/Wgy2N/O3wkRp5GQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vjpu7FHY3GbsqJ8C+iiNw+C7Ci+IqUwNbvJhUQGkrjtip+u1LeH3LRvbxOUVfaHtagXmpFAKBDpb/JKvJ6UzPfL8dhfZbKN16lMfVNz05txJWqgnhSFYiJaC8pX/V/N5TLaTPvH9qnhyBpEk3b1MbLZJtmxJrPmjNB47wDW/CpwgcVGpSWgsl5KjTEFY2F8p6osP7bzz7UDgpMSM1AWlYzb1qhvnjt5ygc3cucbhEJD7Lp1RGFB90VZQfxgtUXmRaEXPTz7qR8v5Eo0iz9+JFkawccu/0O/XvQ5KejQbV5osk8iNf5jgSVoXy1mjbUb5INYSO0U55DI65sLEVDJsoQ==
  • Cc: <grygorii_strashko@xxxxxxxx>, <anthony.perard@xxxxxxxxxx>, <michal.orzel@xxxxxxx>, <julien@xxxxxxx>, <roger.pau@xxxxxxxxxx>, <jason.andryuk@xxxxxxx>, <victorm.lira@xxxxxxx>, <andrew.cooper3@xxxxxxxxxx>, <jbeulich@xxxxxxxx>, <sstabellini@xxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxx>
  • Delivery-date: Wed, 04 Feb 2026 23:37:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

There can be concurrent reads and writes to the console_rx variable so
it is prudent to use ACCESS_ONCE.

Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxx>
Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 xen/drivers/char/console.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 2bdb4d5fb4..35f541ca8e 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -518,11 +518,12 @@ static unsigned int __read_mostly console_rx = 0;
 struct domain *console_get_domain(void)
 {
     struct domain *d;
+    unsigned int rx = ACCESS_ONCE(console_rx);
 
-    if ( console_rx == 0 )
-            return NULL;
+    if ( rx == 0 )
+        return NULL;
 
-    d = rcu_lock_domain_by_id(console_rx - 1);
+    d = rcu_lock_domain_by_id(rx - 1);
     if ( !d )
         return NULL;
 
@@ -542,7 +543,7 @@ void console_put_domain(struct domain *d)
 
 static void console_switch_input(void)
 {
-    unsigned int next_rx = console_rx;
+    unsigned int next_rx = ACCESS_ONCE(console_rx);
 
     /*
      * Rotate among Xen, dom0 and boot-time created domUs while skipping
@@ -555,7 +556,7 @@ static void console_switch_input(void)
 
         if ( next_rx++ >= max_console_rx )
         {
-            console_rx = 0;
+            ACCESS_ONCE(console_rx) = 0;
             printk("*** Serial input to Xen");
             break;
         }
@@ -575,7 +576,7 @@ static void console_switch_input(void)
 
             rcu_unlock_domain(d);
 
-            console_rx = next_rx;
+            ACCESS_ONCE(console_rx) = next_rx;
             printk("*** Serial input to DOM%u", domid);
             break;
         }
@@ -592,7 +593,7 @@ static void __serial_rx(char c)
     struct domain *d;
     int rc = 0;
 
-    if ( console_rx == 0 )
+    if ( ACCESS_ONCE(console_rx) == 0 )
         return handle_keypress(c, false);
 
     d = console_get_domain();
@@ -1193,7 +1194,7 @@ void __init console_endboot(void)
      * a useful 'how to switch' message.
      */
     if ( opt_conswitch[1] == 'x' )
-        console_rx = max_console_rx;
+        ACCESS_ONCE(console_rx) = max_console_rx;
 
     register_keyhandler('w', conring_dump_keyhandler,
                         "synchronously dump console ring buffer (dmesg)", 0);
-- 
2.25.1




 


Rackspace

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