Skip to contentSkip to conversation

arm/vuart: move vpl011-related code to vpl011 emulator

PATCH Superseded [email protected] 2 participants 2 messages Feb 11, 2025 – Feb 12, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm/vuart: move vpl011-related code to vpl011 emulator

From: Denis Mukhin <[email protected]>

Xen console driver has vpl011-related logic which shall belong vpl011 emulator code (Arm port). Move vpl011-related code from arch-independent console driver to Arm's vpl011.c.

---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/

---
 xen/arch/arm/include/asm/vpl011.h |  2 +-
 xen/arch/arm/vpl011.c             | 15 +++++++++++----
 xen/drivers/char/console.c        | 21 +++++++--------------
 3 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/arm/include/asm/vpl011.h +1 -1
index c09abcd7a9..cc83868281 100644
@@ -69,7 +69,7 @@ struct vpl011_init_info {
 int domain_vpl011_init(struct domain *d,
                        struct vpl011_init_info *info);
 void domain_vpl011_deinit(struct domain *d);
-void vpl011_rx_char_xen(struct domain *d, char c);
+int vpl011_rx_char_xen(struct domain *d, char c);
 #else
 static inline int domain_vpl011_init(struct domain *d,
                                      struct vpl011_init_info *info)
xen/arch/arm/vpl011.c +11 -4
index 1fc3114cce..c72f3778bf 100644
@@ -567,16 +567,21 @@ static void vpl011_data_avail(struct domain *d,
 
 /*
  * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer.
- * It is only used when the vpl011 backend is in Xen.
  */
-void vpl011_rx_char_xen(struct domain *d, char c)
+int vpl011_rx_char_xen(struct domain *d, char c)
 {
     unsigned long flags;
     struct vpl011 *vpl011 = &d->arch.vpl011;
     struct vpl011_xen_backend *intf = vpl011->backend.xen;
     XENCONS_RING_IDX in_cons, in_prod, in_fifo_level;
 
-    ASSERT(!vpl011->backend_in_domain);
+    /* Forward input iff the vpl011 backend is in Xen. */
+    if ( vpl011->backend_in_domain )
+        return -ENODEV;
+
+    if ( intf == NULL )
+        return -ENODEV;
+
     VPL011_LOCK(d, flags);
 
     in_cons = intf->in_cons;
@@ -584,7 +589,7 @@ void vpl011_rx_char_xen(struct domain *d, char c)
     if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == sizeof(intf->in) )
     {
         VPL011_UNLOCK(d, flags);
-        return;
+        return -ENOSPC;
     }
 
     intf->in[xencons_mask(in_prod, sizeof(intf->in))] = c;
@@ -596,6 +601,8 @@ void vpl011_rx_char_xen(struct domain *d, char c)
 
     vpl011_data_avail(d, in_fifo_level, sizeof(intf->in), 0, SBSA_UART_FIFO_SIZE);
     VPL011_UNLOCK(d, flags);
+
+    return 0;
 }
 
 static void vpl011_notification(struct vcpu *v, unsigned int port)
xen/drivers/char/console.c +7 -14
index b4cec77247..5e6f0fb062 100644
@@ -553,21 +553,14 @@ static void __serial_rx(char c)
     {
         struct domain *d = rcu_lock_domain_by_id(console_rx - 1);
 
-        /*
-         * If we have a properly initialized vpl011 console for the
-         * domain, without a full PV ring to Dom0 (in that case input
-         * comes from the PV ring), then send the character to it.
-         */
-        if ( d != NULL &&
-             !d->arch.vpl011.backend_in_domain &&
-             d->arch.vpl011.backend.xen != NULL )
-            vpl011_rx_char_xen(d, c);
-        else
-            printk("Cannot send chars to Dom%d: no UART available\n",
-                   console_rx - 1);
-
-        if ( d != NULL )
+        if ( d )
+        {
+            int rc = vpl011_rx_char_xen(d, c);
+            if ( rc )
+                printk(KERN_WARNING "%pd: failed to process console input: %d\n",
+                       d, rc);
             rcu_unlock_domain(d);
+        }
 
         break;
     }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 59 lines · On Tue, 11 Feb 2025, [email protected] wrote:

From: Denis Mukhin <[email protected]>

Xen console driver has vpl011-related logic which shall belong vpl011 emulator code (Arm port). Move vpl011-related code from arch-independent console driver to Arm's vpl011.c.

---
Link to the original patch:
https://lore.kernel.org/xen-devel/[email protected]/

---
 xen/arch/arm/include/asm/vpl011.h |  2 +-
 xen/arch/arm/vpl011.c             | 15 +++++++++++----
 xen/drivers/char/console.c        | 21 +++++++--------------
 3 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/arm/include/asm/vpl011.h +1 -1
index c09abcd7a9..cc83868281 100644
@@ -69,7 +69,7 @@ struct vpl011_init_info {
 int domain_vpl011_init(struct domain *d,
                        struct vpl011_init_info *info);
 void domain_vpl011_deinit(struct domain *d);
-void vpl011_rx_char_xen(struct domain *d, char c);
+int vpl011_rx_char_xen(struct domain *d, char c);
 #else
 static inline int domain_vpl011_init(struct domain *d,
                                      struct vpl011_init_info *info)
xen/arch/arm/vpl011.c +8 -3
index 1fc3114cce..c72f3778bf 100644
@@ -567,16 +567,21 @@ static void vpl011_data_avail(struct domain *d,
 
 /*
  * vpl011_rx_char_xen adds a char to a domain's vpl011 receive buffer.
- * It is only used when the vpl011 backend is in Xen.
  */
-void vpl011_rx_char_xen(struct domain *d, char c)
+int vpl011_rx_char_xen(struct domain *d, char c)
 {
     unsigned long flags;
     struct vpl011 *vpl011 = &d->arch.vpl011;
     struct vpl011_xen_backend *intf = vpl011->backend.xen;
     XENCONS_RING_IDX in_cons, in_prod, in_fifo_level;
 
-    ASSERT(!vpl011->backend_in_domain);
+    /* Forward input iff the vpl011 backend is in Xen. */
+    if ( vpl011->backend_in_domain )
+        return -ENODEV;
+
+    if ( intf == NULL )
+        return -ENODEV;
+
     VPL011_LOCK(d, flags);
 
     in_cons = intf->in_cons;

xen/arch/arm/vpl011.c void vpl011_rx_char_xen(struct domain *d, char c) · line 592

Quoted 5 lines
xen/arch/arm/vpl011.c +1 -1
@@ -584,7 +589,7 @@ void vpl011_rx_char_xen(struct domain *d, char c)
     if ( xencons_queued(in_prod, in_cons, sizeof(intf->in)) == sizeof(intf->in) )
     {
         VPL011_UNLOCK(d, flags);
-        return;
+        return -ENOSPC;

Everything else looks fine. I am a bit unsure about this -ENOSPC return because...

Quoted 30 lines
xen/arch/arm/vpl011.c +2 -0
     }
 
     intf->in[xencons_mask(in_prod, sizeof(intf->in))] = c;
@@ -596,6 +601,8 @@ void vpl011_rx_char_xen(struct domain *d, char c)
 
     vpl011_data_avail(d, in_fifo_level, sizeof(intf->in), 0, SBSA_UART_FIFO_SIZE);
     VPL011_UNLOCK(d, flags);
+
+    return 0;
 }
 
 static void vpl011_notification(struct vcpu *v, unsigned int port)
xen/drivers/char/console.c +0 -10
index b4cec77247..5e6f0fb062 100644
@@ -553,21 +553,14 @@ static void __serial_rx(char c)
     {
         struct domain *d = rcu_lock_domain_by_id(console_rx - 1);
 
-        /*
-         * If we have a properly initialized vpl011 console for the
-         * domain, without a full PV ring to Dom0 (in that case input
-         * comes from the PV ring), then send the character to it.
-         */
-        if ( d != NULL &&
-             !d->arch.vpl011.backend_in_domain &&
-             d->arch.vpl011.backend.xen != NULL )
-            vpl011_rx_char_xen(d, c);
-        else

xen/drivers/char/console.c static void __serial_rx(char c) · line 561

Quoted 10 lines
xen/drivers/char/console.c +6 -4
-            printk("Cannot send chars to Dom%d: no UART available\n",
-                   console_rx - 1);
-
-        if ( d != NULL )
+        if ( d )
+        {
+            int rc = vpl011_rx_char_xen(d, c);
+            if ( rc )
+                printk(KERN_WARNING "%pd: failed to process console input: %d\n",
+                       d, rc);

... it could trigger a warning here. And any prink triggerable by the guest should be rate limited. We already have a function for that which is guest_printk. So I think we should probably change this warning to be guest_printk. Or change return -ENODEV into return 0.

Quoted 9 lines
xen/drivers/char/console.c +1 -0
             rcu_unlock_domain(d);
+        }
 
         break;
     }
Signature · 1 line
2.34.1