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

Re: [PATCH 09/15] tools/libs/light: Modify dtbo to domU linux dtbo format


  • To: Anthony PERARD <anthony.perard@xxxxxxxxx>
  • From: Henry Wang <xin.wang2@xxxxxxx>
  • Date: Mon, 6 May 2024 13:40:29 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=cloud.com 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=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=Cuqj2S6r6M1ACM+fj5csnjKIRemFWACC7B5ROJ6ZRqs=; b=kDMQlwB58+buozohYfN+BzBiolBNs2f7r9+rucTHi+6JW8DBxpV0yk68320Rqy63c55UarZgdVTbg9LMAHB6PAwd4+DZQ4lQofxQ+9qH+vwQXQjyVdynh6fM1brLJU+Yum7cJnoeQwCr9Kwvw/OFHlyOCmcezVb2+GhogrNA/J4udh53j8xR/BFjOQ/eMHflxGrpipoQXua7CUJlvkMLBnbNIYkxx8LN0Wm/4/5vuxPo5VjunGWvu2ThTor+rAPMm0bcH7vL84G10FGvcQvBuoUCOWSOYIB+42dPRg9C42wfI3FggvWYlwProlEh10n0bpWqdiVeNWxd02BPfJRrxA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gsnzpv6mISkJsjG+3p1PfzE9rZJZ7bcbVlEhIu86IR/4KmnECRMWyLIRxBH9pli9b3H2Wz/Wpe8jcGCLHNfjJXpr2oWj91MJLMqlD9TwZbXsARRfIlqI1KYcAToetZxT0mDYPSJ8MAy6XM57I7TSNFTN3l6nkPVo1tFice33nrhoXdnmSz3dLAt8VrJTxoLsxRwNHMXAxR5tqL1coKECbkuILGZkCLXXFIYYt8i/zycZjKUJfAmGIBHlPNxa10/ghvweN3c+Y3qVwdJW9vVA6HKfVCrYcD21PNd8BvlNJWWpEcMWVXcCRY+To53mpnD+pYAmariogvs0yTvfuo1FdQ==
  • Cc: <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxx>
  • Delivery-date: Mon, 06 May 2024 05:40:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Anthony,

On 5/1/2024 11:09 PM, Anthony PERARD wrote:
On Wed, Apr 24, 2024 at 11:34:43AM +0800, Henry Wang wrote:
diff --git a/tools/libs/light/libxl_dt_overlay.c 
b/tools/libs/light/libxl_dt_overlay.c
index cdb62b28cf..eaf11a0f9c 100644
--- a/tools/libs/light/libxl_dt_overlay.c
+++ b/tools/libs/light/libxl_dt_overlay.c
@@ -41,6 +42,69 @@ static int check_overlay_fdt(libxl__gc *gc, void *fdt, 
size_t size)
      return 0;
  }
+static int modify_overlay_for_domU(libxl__gc *gc, void *overlay_dt_domU,
+                                   size_t size)
+{
+    int rc = 0;
+    int virtual_interrupt_parent = GUEST_PHANDLE_GIC;
+    const struct fdt_property *fdt_prop_node = NULL;
+    int overlay;
+    int prop_len = 0;
+    int subnode = 0;
+    int fragment;
+    const char *prop_name;
+    const char *target_path = "/";
+
+    fdt_for_each_subnode(fragment, overlay_dt_domU, 0) {
+        prop_name = fdt_getprop(overlay_dt_domU, fragment, "target-path",
+                                &prop_len);
+        if (prop_name == NULL) {
+            LOG(ERROR, "target-path property not found\n");
LOG* macros already takes care of adding \n, no need to add an extra
one.

Sure, I will remove the "\n".


+            rc = ERROR_FAIL;
+            goto err;
+        }
+
+        /* Change target path for domU dtb. */
+        rc = fdt_setprop_string(overlay_dt_domU, fragment, "target-path",
fdt_setprop_string() isn't a libxl function, store the return value in a
variable named `r` instead.'

Thanks for spotting this. Will change it to `r`.

+                                target_path);
+        if (rc) {
+            LOG(ERROR, "Setting interrupt parent property failed for %s\n",
+                prop_name);
+            goto err;
+        }
+
+        overlay = fdt_subnode_offset(overlay_dt_domU, fragment, "__overlay__");
+
+        fdt_for_each_subnode(subnode, overlay_dt_domU, overlay)
+        {
+            const char *node_name = fdt_get_name(overlay_dt_domU, subnode,
+                                                 NULL);
+
+            fdt_prop_node = fdt_getprop(overlay_dt_domU, subnode,
+                                        "interrupt-parent", &prop_len);
+            if (fdt_prop_node == NULL) {
+                LOG(DETAIL, "%s property not found for %s. Skip to next 
node\n",
+                    "interrupt-parent", node_name);
Why do you have "interrupt-parent" in a separate argument? Do you meant
to do something like
     const char *some_name = "interrupt-parent";
and use that in the 4 different places that this string is used? (Using
a variable mean that we (or the compiler) can make sure that they are
all spelled correctly.

Great suggestion! I will do this way.

+                continue;
+            }
+
+            rc = fdt_setprop_inplace_u32(overlay_dt_domU, subnode,
+                                         "interrupt-parent",
+                                         virtual_interrupt_parent);
+            if (rc) {
+                LOG(ERROR, "Setting interrupt parent property failed for %s\n",
+                    "interrupt-parent");
+                goto err;
+            }
+        }
+    }
+
+return 0;
Missed indentation.

Will correct it.

+
+err:
+    return rc;
A few things, looks like `rc` is always going to be ERROR_FAIL here,
unless you find an libxl_error code that better describe the error, so
you could forgo the `rc` variable.

Also, if you don't need to clean up anything in the function or have a
generic error message, you could simply "return " instead of using the
"goto" style.

Sure, I will simply use return because I don't really think there is anything to be cleaned up.

+}
+
  int libxl_dt_overlay(libxl_ctx *ctx, uint32_t domid, void *overlay_dt,
                       uint32_t overlay_dt_size, uint8_t overlay_op,
                       bool auto_mode, bool domain_mapping)
@@ -73,6 +137,15 @@ int libxl_dt_overlay(libxl_ctx *ctx, uint32_t domid, void 
*overlay_dt,
          rc = ERROR_FAIL;
      }
+ /*
+     * auto_mode doesn't apply to dom0 as dom0 can get the physical
+     * description of the hardware.
+     */
+    if (domid && auto_mode) {
+        if (overlay_op == LIBXL_DT_OVERLAY_ADD)
Shouldn't libxl complain if the operation is different?

I will add corresponding error handling code here. Thanks!

Kind regards,
Henry

+            rc = modify_overlay_for_domU(gc, overlay_dt, overlay_dt_size);
+    }
+
  out:
      GC_FREE;
      return rc;
Thanks,





 


Rackspace

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