Skip to contentSkip to conversation

Some fixes for the existing dynamic dtbo code

PATCH Superseded Henry Wang 1 participant 3 messages May 7, 2024

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Henry Wang

author
#0 lore raw

v2 cover Some fixes for the existing dynamic dtbo code

During the review process for the v1 of the dynamic dtbo series, some issues of the existing code were identified. Discussions of them can be found in [1] (for the first patch) and [2] (for the second patch).

Since the main part of the remaining dynamic dtbo series requires more rework, just send these fixes for now.

[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/eaea1986-a27e-4d6c-932f-1d0a9918861f@perard/

Henry Wang (2):
xen/common/dt-overlay: Fix missing lock when remove the device tools/xl: Correct the help information and exit code of the dt-overlay
command

 tools/xl/xl_vmcontrol.c | 6 +++---
 xen/common/dt-overlay.c | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH v2 1/2 xen/common/dt-overlay: Fix missing lock when remove the device

If CONFIG_DEBUG=y, below assertion will be triggered:
(XEN) Assertion 'rw_is_locked(&dt_host_lock)' failed at drivers/passthrough/device_tree.c:146 (XEN) ----[ Xen-4.19-unstable arm64 debug=y Not tainted ]----

(XEN) CPU:    0
(XEN) PC:     00000a0000257418 iommu_remove_dt_device+0x8c/0xd4
(XEN) LR:     00000a00002573a0
(XEN) SP:     00008000fff7fb30
(XEN) CPSR:   0000000000000249 MODE:64-bit EL2h (Hypervisor, handler)

[...]

(XEN) Xen call trace:

(XEN)    [<00000a0000257418>] iommu_remove_dt_device+0x8c/0xd4 (PC)
(XEN)    [<00000a00002573a0>] iommu_remove_dt_device+0x14/0xd4 (LR)
(XEN)    [<00000a000020797c>] dt-overlay.c#remove_node_resources+0x8c/0x90
(XEN)    [<00000a0000207f14>] dt-overlay.c#remove_nodes+0x524/0x648
(XEN)    [<00000a0000208460>] dt_overlay_sysctl+0x428/0xc68
(XEN)    [<00000a00002707f8>] arch_do_sysctl+0x1c/0x2c
(XEN)    [<00000a0000230b40>] do_sysctl+0x96c/0x9ec
(XEN)    [<00000a0000271e08>] traps.c#do_trap_hypercall+0x1e8/0x288
(XEN)    [<00000a0000273490>] do_trap_guest_sync+0x448/0x63c
(XEN)    [<00000a000025c480>] entry.o#guest_sync_slowpath+0xa8/0xd8

(XEN)
(XEN)
(XEN) ****************************************
(XEN) Panic on CPU 0:
(XEN) Assertion 'rw_is_locked(&dt_host_lock)' failed at drivers/passthrough/device_tree.c:146 (XEN) ****************************************

This is because iommu_remove_dt_device() is called without taking the dt_host_lock. dt_host_lock is meant to ensure that the DT node will not disappear behind back. So fix the issue by taking the lock as soon as getting hold of overlay_node.

Fixes 7e5c4a8b86f1 ("xen/arm: Implement device tree node removal functionalities")

---
v2:
- Take the lock as soon as getting hold of overlay_node. v1.1:
- Move the unlock position before the check of rc.

---
 xen/common/dt-overlay.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/dt-overlay.c +2 -2
index 1b197381f6..25d15cbcb1 100644
@@ -429,6 +429,8 @@ static int remove_nodes(const struct overlay_track *tracker)
         if ( overlay_node == NULL )
             return -EINVAL;
 
+        write_lock(&dt_host_lock);
+
         rc = remove_descendant_nodes_resources(overlay_node);
         if ( rc )
             return rc;
@@ -439,8 +441,6 @@ static int remove_nodes(const struct overlay_track *tracker)
 
         dt_dprintk("Removing node: %s\n", overlay_node->full_name);
 
-        write_lock(&dt_host_lock);
-
         rc = dt_overlay_remove_node(overlay_node);
         if ( rc )
         {
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH v2 2/2 tools/xl: Correct the help information and exit code of the dt-overlay command

In reply to Henry Wang

Fix the name mismatch in the xl dt-overlay command, the command name should be "dt-overlay" instead of "dt_overlay".

Fix the exit code of the dt-overlay command, use EXIT_FAILURE instead of ERROR_FAIL.

Fixes 61765a07e3d8 ("tools/xl: Add new xl command overlay for device tree overlay support")

---
v2:
- New patch

---
 tools/xl/xl_vmcontrol.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
tools/xl/xl_vmcontrol.c +3 -3
index 98f6bd2e76..02575d5d36 100644
@@ -1278,7 +1278,7 @@ int main_dt_overlay(int argc, char **argv)
     const int overlay_remove_op = 2;
 
     if (argc < 2) {
-        help("dt_overlay");
+        help("dt-overlay");
         return EXIT_FAILURE;
     }
 
@@ -1302,11 +1302,11 @@ int main_dt_overlay(int argc, char **argv)
             fprintf(stderr, "failed to read the overlay device tree file %s\n",
                     overlay_config_file);
             free(overlay_dtb);
-            return ERROR_FAIL;
+            return EXIT_FAILURE;
         }
     } else {
         fprintf(stderr, "overlay dtbo file not provided\n");
-        return ERROR_FAIL;
+        return EXIT_FAILURE;
     }
 
     rc = libxl_dt_overlay(ctx, overlay_dtb, overlay_dtb_size, op);
Signature · 1 line
2.34.1