Date   

[PATCH] misc: refine slot issue of launch script

Chenli Wei
 

From: Chenli Wei <chenli.wei@...>

The current launch script allocate bdf for ivshmem by itself and have
not get bdf from scenario.

This patch refine the above logic and generate slot by user settings.

Signed-off-by: Chenli Wei <chenli.wei@...>
---
misc/config_tools/launch_config/launch_cfg_gen.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/misc/config_tools/launch_config/launch_cfg_gen.py b/misc/config_tools/launch_config/launch_cfg_gen.py
index 910b2e6df..b8950ce08 100755
--- a/misc/config_tools/launch_config/launch_cfg_gen.py
+++ b/misc/config_tools/launch_config/launch_cfg_gen.py
@@ -263,10 +263,20 @@ def generate_for_one_vm(board_etree, hv_scenario_etree, vm_scenario_etree, vm_id
#ivshmem and vuart own reserved slots which setting by user

for ivshmem in eval_xpath_all(vm_scenario_etree, f"//IVSHMEM_REGION[PROVIDED_BY = 'Device Model' and .//VM_NAME = '{vm_name}']"):
- script.add_virtual_device("ivshmem", options=f"dm:/{ivshmem.find('NAME').text},{ivshmem.find('IVSHMEM_SIZE').text}")
+ vbdf = eval_xpath(ivshmem, f".//VBDF/text()")
+ if vbdf is not None:
+ slot = int((vbdf.split(":")[1].split(".")[0]), 16)
+ else:
+ slot = None
+ script.add_virtual_device("ivshmem", slot, options=f"dm:/{ivshmem.find('NAME').text},{ivshmem.find('IVSHMEM_SIZE').text}")

for ivshmem in eval_xpath_all(vm_scenario_etree, f"//IVSHMEM_REGION[PROVIDED_BY = 'Hypervisor' and .//VM_NAME = '{vm_name}']"):
- script.add_virtual_device("ivshmem", options=f"hv:/{ivshmem.find('NAME').text},{ivshmem.find('IVSHMEM_SIZE').text}")
+ vbdf = eval_xpath(ivshmem, f".//VBDF/text()")
+ if vbdf is not None:
+ slot = int((vbdf.split(":")[1].split(".")[0]), 16)
+ else:
+ slot = None
+ script.add_virtual_device("ivshmem", slot, options=f"hv:/{ivshmem.find('NAME').text},{ivshmem.find('IVSHMEM_SIZE').text}")

if eval_xpath(vm_scenario_etree, ".//console_vuart/text()") == "PCI":
script.add_virtual_device("uart", options="vuart_idx:0")
--
2.25.1


Canceled: 2022 ACRN Project Technical Community Meeting: @ Monthly 3rd Wednesday 4PM (China-Shanghai), Wednesday 10AM (Europe-Munich), Tuesday 1AM (US-West Coast)

Zou, Terry
 

Cancel this month’s modularization topic, thanks.
WW25 ACRN Modularization Introduction Chen Jason 6/15/2021
 
Special Notes: If you have Zoom connection issue by using web browser, please install & launch Zoom application, manually input the meeting ID (320664063) to join the Zoom meeting.
 
Agenda & Archives:
WW Topic Presenter Status
Chinese New Year Break
WW12 Libvirt Enhancement Introduction to Replace acrnctl Wu Xiangyang 3/16/2021
WW17 ACRN DX: New config/para Design and Application Xie Nanlin 4/20/2021
WW21 ACRN Based X86 OPTEE Introduction Liu Yifan 5/18/2021
WW25 ACRN Modularization Introduction Chen Jason 6/15/2021
WW30 ACRN DX: Dynamic Parameter Configuration Liu, Hang 7/20/2021
 
Project ACRN: A flexible, light-weight, open source reference hypervisor for IoT devices
We invite you to attend a monthly "Technical Community" meeting where we'll meet community members and talk about the ACRN project and plans.
As we explore community interest and involvement opportunities, we'll (re)schedule these meetings at a time convenient to most attendees:
  • Meets every 3rd Wednesday, 4-5:00 PM (China-Shanghai), Wednesday 10-11:00 AM (Europe-Munich), Tuesday 1-2:00 AM (US-West Coast)
  • Chairperson: Terry ZOU, terry.zou@... (Intel)
  • Online conference link: https://zoom.com.cn/j/320664063
  • Zoom Meeting ID: 320 664 063
  • Special Notes: If you have Zoom connection issue by using web browser, please launch Zoom application, manually input the meeting ID (320664063) to join the Zoom meeting.
  • Online conference phone:
  • China: +86 010 87833177  or 400 669 9381 (Toll Free)
  • Germany: +49 (0) 30 3080 6188  or +49 800 724 3138 (Toll Free)
  • US: +1 669 900 6833  or +1 646 558 8656   or +1 877 369 0926 (Toll Free) or +1 855 880 1246 (Toll Free)
  • Additional international phone numbers
  • Meeting Notes:
 
 


Re: [V2 2/2] DM: Add endpoint index value check in doorbell write

Yu Wang
 

On Tue, Jun 14, 2022 at 10:14:26AM +0800, Liu Long wrote:
Add the endpint index value check in doorbell write function,
because the max index value is 32.
Title: dm: xhci: Add max ep index checking in doorbell write emulation

Check max ep index in doorbell write function to avoid overwriting
the pci_xhci_dev_emu->eps[XHCI_MAX_ENDPOINTS].


Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..eef4dee4a 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3419,6 +3419,10 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev,
UPRINTF(LWRN, "pci_xhci: controller halted\r\n");
return;
}
+ if (XHCI_DB_TARGET_GET(value) > XHCI_MAX_ENDPOINTS) {
+ UPRINTF(LWRN, "pci_xhci: endpoint index is not valid.\r\n");
UPRINTF(LWRN, "pci_xhci: invalid doorbell target %d!\n", XHCI_DB_TARGET_GET(value));

Acked-by: Wang, Yu1 <yu1.wang@...>

+ return;
+ }

if (offset == 0)
pci_xhci_complete_commands(xdev);
--
2.25.1


Re: [V2 1/2] ACRN: DM: Refine the vhost_vsock_deinit function

Yu Wang
 

On Tue, Jun 14, 2022 at 10:14:25AM +0800, Liu Long wrote:
In deinit function close the vhost_vsock fd and free the vhost_vsock
struct no matter the above logic.
Title: dm: vsock: fix the memory leakage bug

Fix the memory leakage issue caused by incomplete deinit flow.

Acked-by: Wang, Yu1 <yu1.wang@...>


Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..922258be4 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -208,25 +208,21 @@ fail:
return NULL;
}

-static int
+static void
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
int rc;

rc = vhost_vsock_stop(vhost_vsock);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_stop is failed.\n");
- return -1;
- }

rc = vhost_dev_deinit(&vhost_vsock->vdev);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
- }
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
}

static void
@@ -323,10 +319,9 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (dev->arg) {
vsock = (struct virtio_vsock *) dev->arg;

- if (vsock->vhost_vsock) {
+ if (vsock->vhost_vsock)
vhost_vsock_deinit(vsock->vhost_vsock);
- }
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


[V2 2/2] DM: Add endpoint index value check in doorbell write

Long Liu
 

Add the endpint index value check in doorbell write function,
because the max index value is 32.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..eef4dee4a 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3419,6 +3419,10 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev,
UPRINTF(LWRN, "pci_xhci: controller halted\r\n");
return;
}
+ if (XHCI_DB_TARGET_GET(value) > XHCI_MAX_ENDPOINTS) {
+ UPRINTF(LWRN, "pci_xhci: endpoint index is not valid.\r\n");
+ return;
+ }

if (offset == 0)
pci_xhci_complete_commands(xdev);
--
2.25.1


[V2 1/2] ACRN: DM: Refine the vhost_vsock_deinit function

Long Liu
 

In deinit function close the vhost_vsock fd and free the vhost_vsock
struct no matter the above logic.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..922258be4 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -208,25 +208,21 @@ fail:
return NULL;
}

-static int
+static void
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
int rc;

rc = vhost_vsock_stop(vhost_vsock);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_stop is failed.\n");
- return -1;
- }

rc = vhost_dev_deinit(&vhost_vsock->vdev);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
- }
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
}

static void
@@ -323,10 +319,9 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (dev->arg) {
vsock = (struct virtio_vsock *) dev->arg;

- if (vsock->vhost_vsock) {
+ if (vsock->vhost_vsock)
vhost_vsock_deinit(vsock->vhost_vsock);
- }
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


[V2 0/2] Fix vsock and usb memory leak

Long Liu
 

v1-->v2
1. Refine the vhost_vsock_devinit function return void
2. Add the endpoint index value check log.

Liu Long (2):
ACRN: DM: Refine the vhost_vsock_deinit function
ACRN: DM: Add endpoint index check in doorbell write

devicemodel/hw/pci/virtio/vhost_vsock.c | 11 ++++-------
devicemodel/hw/pci/xhci.c | 4 ++++
2 files changed, 8 insertions(+), 7 deletions(-)

--
2.25.1


Re: [PATCH 2/2] ACRN: DM: Add endpoint index check in xhci register write

Yonghua Huang
 

Hi Yu,

-----Original Message-----
From: Wang, Yu1 <yu1.wang@...>
Sent: Tuesday, June 14, 2022 09:15
To: Liu Long <long.liu@...>
Cc: Huang, Yonghua <yonghua.huang@...>; acrn-
dev@...
Subject: Re: [PATCH 2/2] ACRN: DM: Add endpoint index check in xhci register
write

On Tue, Jun 14, 2022 at 09:23:56AM +0800, Liu Long wrote:
Because the endpoint index max value is 32, add the index value check
in xhci register write function.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..83fbccc35 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3415,7 +3415,7 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev,
UPRINTF(LDBG, "doorbell write offset 0x%lx: 0x%lx\r\n",
offset, value);

- if (XHCI_HALTED(xdev)) {
+ if (XHCI_HALTED(xdev) || XHCI_DB_TARGET_GET(value) >
+XHCI_MAX_ENDPOINTS) {
UPRINTF(LWRN, "pci_xhci: controller halted\r\n");
Is there any capability register to indicate the max supported endpoint number? I
haven't find it.

And why FE driver ring the nonexisting ep?
This write request is from fuzzing guest, where any value that is compatible with hardware/software interface will be injected, ACRN backend driver should validate any inputs from guest, which is not trusted.


Another thing, this is not controller halted case, please do not re-use the same
log.

return;
}
--
2.25.1


Re: [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

Yu Wang
 

On Tue, Jun 14, 2022 at 01:28:33AM +0000, Long Liu wrote:


-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Yu Wang
Sent: Tuesday, June 14, 2022 9:04 AM
To: Liu Long <long.liu@...>
Cc: Huang, Yonghua <yonghua.huang@...>; acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
When deinit the vhost vsock release the vhost vsock struct to prevent
memory leak.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c
b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..544c392df 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -211,22 +211,21 @@ fail:
static int
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock) {
- int rc;
+ int rc = 0;

rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) {
pr_err("vhost_dev_stop is failed.\n");
- return -1;
}

rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) {
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
}
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
+ return rc;
}

static void
@@ -324,9 +323,12 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vsock = (struct virtio_vsock *) dev->arg;

if (vsock->vhost_vsock) {
- vhost_vsock_deinit(vsock->vhost_vsock);
+ if (vhost_vsock_deinit(vsock->vhost_vsock)) {
return 0 for success or fail?
[Long:] return 0 is success, if this fail force close the vhost_vsock, because this is the deinit function.
In the vhost_vsock_deinit, it already close and free, why do it again?

+ close(vsock->vhost_vsock->vhost_fd);
+ free(vsock->vhost_vsock);
+ }
}
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1









Re: [PATCH 2/2] ACRN: DM: Add endpoint index check in xhci register write

Yu Wang
 

On Tue, Jun 14, 2022 at 09:23:56AM +0800, Liu Long wrote:
Because the endpoint index max value is 32, add the index value
check in xhci register write function.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..83fbccc35 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3415,7 +3415,7 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev,
UPRINTF(LDBG, "doorbell write offset 0x%lx: 0x%lx\r\n",
offset, value);

- if (XHCI_HALTED(xdev)) {
+ if (XHCI_HALTED(xdev) || XHCI_DB_TARGET_GET(value) > XHCI_MAX_ENDPOINTS) {
UPRINTF(LWRN, "pci_xhci: controller halted\r\n");
Is there any capability register to indicate the max supported endpoint
number? I haven't find it.

And why FE driver ring the nonexisting ep?

Another thing, this is not controller halted case, please do not re-use
the same log.

return;
}
--
2.25.1


Re: [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

Long Liu
 

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Yu Wang
Sent: Tuesday, June 14, 2022 9:04 AM
To: Liu Long <long.liu@...>
Cc: Huang, Yonghua <yonghua.huang@...>; acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
When deinit the vhost vsock release the vhost vsock struct to prevent
memory leak.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c
b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..544c392df 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -211,22 +211,21 @@ fail:
static int
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock) {
- int rc;
+ int rc = 0;

rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) {
pr_err("vhost_dev_stop is failed.\n");
- return -1;
}

rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) {
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
}
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
+ return rc;
}

static void
@@ -324,9 +323,12 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vsock = (struct virtio_vsock *) dev->arg;

if (vsock->vhost_vsock) {
- vhost_vsock_deinit(vsock->vhost_vsock);
+ if (vhost_vsock_deinit(vsock->vhost_vsock)) {
return 0 for success or fail?
[Long:] return 0 is success, if this fail force close the vhost_vsock, because this is the deinit function.

+ close(vsock->vhost_vsock->vhost_fd);
+ free(vsock->vhost_vsock);
+ }
}
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


Re: [PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

Yu Wang
 

On Tue, Jun 14, 2022 at 09:23:55AM +0800, Liu Long wrote:
When deinit the vhost vsock release the vhost vsock struct to prevent
memory leak.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..544c392df 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -211,22 +211,21 @@ fail:
static int
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
- int rc;
+ int rc = 0;

rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) {
pr_err("vhost_dev_stop is failed.\n");
- return -1;
}

rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) {
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
}
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
+ return rc;
}

static void
@@ -324,9 +323,12 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vsock = (struct virtio_vsock *) dev->arg;

if (vsock->vhost_vsock) {
- vhost_vsock_deinit(vsock->vhost_vsock);
+ if (vhost_vsock_deinit(vsock->vhost_vsock)) {
return 0 for success or fail?

+ close(vsock->vhost_vsock->vhost_fd);
+ free(vsock->vhost_vsock);
+ }
}
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


[PATCH 2/2] ACRN: DM: Add endpoint index check in xhci register write

Long Liu
 

Because the endpoint index max value is 32, add the index value
check in xhci register write function.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..83fbccc35 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3415,7 +3415,7 @@ pci_xhci_dbregs_write(struct pci_xhci_vdev *xdev,
UPRINTF(LDBG, "doorbell write offset 0x%lx: 0x%lx\r\n",
offset, value);

- if (XHCI_HALTED(xdev)) {
+ if (XHCI_HALTED(xdev) || XHCI_DB_TARGET_GET(value) > XHCI_MAX_ENDPOINTS) {
UPRINTF(LWRN, "pci_xhci: controller halted\r\n");
return;
}
--
2.25.1


[PATCH 1/2] ACRN: DM: Release vsock struct in case memory leak

Long Liu
 

When deinit the vhost vsock release the vhost vsock struct to prevent
memory leak.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..544c392df 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -211,22 +211,21 @@ fail:
static int
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
- int rc;
+ int rc = 0;

rc = vhost_vsock_stop(vhost_vsock);
if (rc < 0) {
pr_err("vhost_dev_stop is failed.\n");
- return -1;
}

rc = vhost_dev_deinit(&vhost_vsock->vdev);
if (rc < 0) {
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
}
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
+ return rc;
}

static void
@@ -324,9 +323,12 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
vsock = (struct virtio_vsock *) dev->arg;

if (vsock->vhost_vsock) {
- vhost_vsock_deinit(vsock->vhost_vsock);
+ if (vhost_vsock_deinit(vsock->vhost_vsock)) {
+ close(vsock->vhost_vsock->vhost_fd);
+ free(vsock->vhost_vsock);
+ }
}
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


[PATCH 0/2] Fix the Device USB and Vsock memory leak

Long Liu
 

1.Release the Vhost vsock when deinit the vsock.
2.Add endpoint index value check in xhci doorbell register write

Liu Long (2):
ACRN: DM: Release vsock struct in case memory leak
ACRN: DM: Add endpoint index check in xhci register write

devicemodel/hw/pci/virtio/vhost_vsock.c | 14 ++++++++------
devicemodel/hw/pci/xhci.c | 2 +-
2 files changed, 9 insertions(+), 7 deletions(-)

--
2.25.1


Re: [PATCH] ACRN: DM: USB-hot patch

Long Liu
 

Sorry ,ignore this patch, will send out the formal version later.

-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On Behalf Of Long Liu
Sent: Tuesday, June 14, 2022 9:15 AM
To: Wang, Yu1 <yu1.wang@...>; Huang, Yonghua <yonghua.huang@...>; acrn-dev@...
Subject: [acrn-dev] [PATCH] ACRN: DM: USB-hot patch

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 1 +
devicemodel/hw/platform/usb_mouse.c | 1 +
devicemodel/hw/platform/usb_pmapper.c | 27 ++++++++++++++++++++++-----
3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c index b5c1365ce..42dc8ef67 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3025,6 +3025,7 @@ pci_xhci_try_usb_xfer(struct pci_xhci_vdev *xdev,
err = dev->dev_ue->ue_data(dev->dev_instance, xfer, epid & 0x1 ?
USB_XFER_IN : USB_XFER_OUT, epid/2);
if (err == USB_ERR_CANCELLED) {
+ printf("%s err == USB_ERR_CANCELLED.\n", __func__);
if (USB_DATA_GET_ERRCODE(&xfer->data[xfer->head]) ==
USB_NAK)
err = XHCI_TRB_ERROR_SUCCESS;
diff --git a/devicemodel/hw/platform/usb_mouse.c b/devicemodel/hw/platform/usb_mouse.c
index 475e3515d..33b3dd257 100644
--- a/devicemodel/hw/platform/usb_mouse.c
+++ b/devicemodel/hw/platform/usb_mouse.c
@@ -740,6 +740,7 @@ umouse_data_handler(void *scarg, struct usb_xfer *xfer, int dir,
err = USB_ERR_CANCELLED;
USB_DATA_SET_ERRCODE(&xfer->data[xfer->head], USB_NAK);
pthread_mutex_unlock(&dev->mtx);
+ printf("XXXXXXXXXXXXXXXXXXXXXXX umouse USB_ERR_CANCELLED.\n");
goto done;
}

diff --git a/devicemodel/hw/platform/usb_pmapper.c b/devicemodel/hw/platform/usb_pmapper.c
index d7ff2f6b4..e0a30710d 100644
--- a/devicemodel/hw/platform/usb_pmapper.c
+++ b/devicemodel/hw/platform/usb_pmapper.c
@@ -20,6 +20,7 @@
static struct usb_dev_sys_ctx_info g_ctx; static uint16_t usb_dev_get_ep_maxp(struct usb_dev *udev, int pid, int epnum);

+int tracnf = 0;
static bool
usb_get_native_devinfo(struct libusb_device *ldev,
struct usb_native_devinfo *info,
@@ -324,6 +325,8 @@ cancel_out:
free(r);
free_transfer:
libusb_free_transfer(trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

static struct usb_dev_req *
@@ -359,8 +362,11 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_xfer *xfer, int in,
errout:
if (req && req->buffer)
free(req->buffer);
- if (req && req->trn)
+ if (req && req->trn) {
+ tracnf--;
libusb_free_transfer(req->trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
+ }
if (req)
free(req);
return NULL;
@@ -746,6 +752,7 @@ usb_dev_reset(void *pdata)
return rc;
}

+
int
usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx) { @@ -879,17 +886,22 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type);
if (r->buffer)
free(r->buffer);
- if (r->trn)
+ if (r->trn) {
libusb_free_transfer(r->trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d\n", __func__, tracnf);
+ }
free(r);
xfer->status = USB_ERR_INVAL;
}

rc = libusb_submit_transfer(r->trn);
+ tracnf++;
if (rc) {
xfer->status = USB_ERR_IOERROR;
- UPRINTF(LDBG, "libusb_submit_transfer fail: %d\n", rc);
- }
+ printf("libusb_submit_transfer fail: %d\n", rc);
+ } else
+ printf("XXXXXXXXXXXXXXXXX libusb_submit_transfer %d\n", tracnf);
done:
return xfer->status;
}
@@ -1124,7 +1136,9 @@ usb_dev_free_request(void *pdata)
struct libusb_transfer *trn;

trn = pdata;
+ tracnf--;
libusb_free_transfer(trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

void
@@ -1288,12 +1302,14 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
return -1;
}

+ printf("XXXXXXXXX before libusb_init!\n");
rc = libusb_init(&g_ctx.libusb_ctx);
if (rc < 0) {
UPRINTF(LFTL, "libusb_init fails, rc:%d\r\n", rc);
return -1;
}

+ printf("xxxxxxxxx After libusb_init!\n");
g_ctx.hci_data = hci_data;
g_ctx.conn_cb = conn_cb;
g_ctx.disconn_cb = disconn_cb;
@@ -1303,7 +1319,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
g_ctx.unlock_ep_cb = unlock_ep_cb;

num_devs = usb_dev_scan_dev(&g_ctx.devlist);
- UPRINTF(LINF, "found %d devices before Guest OS booted\r\n", num_devs);
+ printf("found %d devices before Guest OS booted\r\n", num_devs);

native_conn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
native_disconn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT; @@ -1330,6 +1346,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
goto errout;
}

+ printf("XXXXXXXXX After libusb_init!\n");
/* this is for guest rebooting purpose */
g_ctx.conn_handle = native_conn_handle;
g_ctx.disconn_handle = native_disconn_handle;
--
2.25.1


Re: [PATCH] ACRN: DM: USB-hot patch

Yu Wang
 

Where's your commit message? Is this a debug patch? Why there are
"XXXX" print?

On Tue, Jun 14, 2022 at 09:14:42AM +0800, Liu Long wrote:
Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 1 +
devicemodel/hw/platform/usb_mouse.c | 1 +
devicemodel/hw/platform/usb_pmapper.c | 27 ++++++++++++++++++++++-----
3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..42dc8ef67 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3025,6 +3025,7 @@ pci_xhci_try_usb_xfer(struct pci_xhci_vdev *xdev,
err = dev->dev_ue->ue_data(dev->dev_instance, xfer, epid & 0x1 ?
USB_XFER_IN : USB_XFER_OUT, epid/2);
if (err == USB_ERR_CANCELLED) {
+ printf("%s err == USB_ERR_CANCELLED.\n", __func__);
if (USB_DATA_GET_ERRCODE(&xfer->data[xfer->head]) ==
USB_NAK)
err = XHCI_TRB_ERROR_SUCCESS;
diff --git a/devicemodel/hw/platform/usb_mouse.c b/devicemodel/hw/platform/usb_mouse.c
index 475e3515d..33b3dd257 100644
--- a/devicemodel/hw/platform/usb_mouse.c
+++ b/devicemodel/hw/platform/usb_mouse.c
@@ -740,6 +740,7 @@ umouse_data_handler(void *scarg, struct usb_xfer *xfer, int dir,
err = USB_ERR_CANCELLED;
USB_DATA_SET_ERRCODE(&xfer->data[xfer->head], USB_NAK);
pthread_mutex_unlock(&dev->mtx);
+ printf("XXXXXXXXXXXXXXXXXXXXXXX umouse USB_ERR_CANCELLED.\n");
goto done;
}

diff --git a/devicemodel/hw/platform/usb_pmapper.c b/devicemodel/hw/platform/usb_pmapper.c
index d7ff2f6b4..e0a30710d 100644
--- a/devicemodel/hw/platform/usb_pmapper.c
+++ b/devicemodel/hw/platform/usb_pmapper.c
@@ -20,6 +20,7 @@
static struct usb_dev_sys_ctx_info g_ctx;
static uint16_t usb_dev_get_ep_maxp(struct usb_dev *udev, int pid, int epnum);

+int tracnf = 0;
static bool
usb_get_native_devinfo(struct libusb_device *ldev,
struct usb_native_devinfo *info,
@@ -324,6 +325,8 @@ cancel_out:
free(r);
free_transfer:
libusb_free_transfer(trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

static struct usb_dev_req *
@@ -359,8 +362,11 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_xfer *xfer, int in,
errout:
if (req && req->buffer)
free(req->buffer);
- if (req && req->trn)
+ if (req && req->trn) {
+ tracnf--;
libusb_free_transfer(req->trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
+ }
if (req)
free(req);
return NULL;
@@ -746,6 +752,7 @@ usb_dev_reset(void *pdata)
return rc;
}

+
int
usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
{
@@ -879,17 +886,22 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type);
if (r->buffer)
free(r->buffer);
- if (r->trn)
+ if (r->trn) {
libusb_free_transfer(r->trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d\n", __func__, tracnf);
+ }
free(r);
xfer->status = USB_ERR_INVAL;
}

rc = libusb_submit_transfer(r->trn);
+ tracnf++;
if (rc) {
xfer->status = USB_ERR_IOERROR;
- UPRINTF(LDBG, "libusb_submit_transfer fail: %d\n", rc);
- }
+ printf("libusb_submit_transfer fail: %d\n", rc);
+ } else
+ printf("XXXXXXXXXXXXXXXXX libusb_submit_transfer %d\n", tracnf);
done:
return xfer->status;
}
@@ -1124,7 +1136,9 @@ usb_dev_free_request(void *pdata)
struct libusb_transfer *trn;

trn = pdata;
+ tracnf--;
libusb_free_transfer(trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

void
@@ -1288,12 +1302,14 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
return -1;
}

+ printf("XXXXXXXXX before libusb_init!\n");
rc = libusb_init(&g_ctx.libusb_ctx);
if (rc < 0) {
UPRINTF(LFTL, "libusb_init fails, rc:%d\r\n", rc);
return -1;
}

+ printf("xxxxxxxxx After libusb_init!\n");
g_ctx.hci_data = hci_data;
g_ctx.conn_cb = conn_cb;
g_ctx.disconn_cb = disconn_cb;
@@ -1303,7 +1319,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
g_ctx.unlock_ep_cb = unlock_ep_cb;

num_devs = usb_dev_scan_dev(&g_ctx.devlist);
- UPRINTF(LINF, "found %d devices before Guest OS booted\r\n", num_devs);
+ printf("found %d devices before Guest OS booted\r\n", num_devs);

native_conn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
native_disconn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
@@ -1330,6 +1346,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
goto errout;
}

+ printf("XXXXXXXXX After libusb_init!\n");
/* this is for guest rebooting purpose */
g_ctx.conn_handle = native_conn_handle;
g_ctx.disconn_handle = native_disconn_handle;
--
2.25.1


[PATCH] ACRN: DM: USB-hot patch

Long Liu
 

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/xhci.c | 1 +
devicemodel/hw/platform/usb_mouse.c | 1 +
devicemodel/hw/platform/usb_pmapper.c | 27 ++++++++++++++++++++++-----
3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/devicemodel/hw/pci/xhci.c b/devicemodel/hw/pci/xhci.c
index b5c1365ce..42dc8ef67 100644
--- a/devicemodel/hw/pci/xhci.c
+++ b/devicemodel/hw/pci/xhci.c
@@ -3025,6 +3025,7 @@ pci_xhci_try_usb_xfer(struct pci_xhci_vdev *xdev,
err = dev->dev_ue->ue_data(dev->dev_instance, xfer, epid & 0x1 ?
USB_XFER_IN : USB_XFER_OUT, epid/2);
if (err == USB_ERR_CANCELLED) {
+ printf("%s err == USB_ERR_CANCELLED.\n", __func__);
if (USB_DATA_GET_ERRCODE(&xfer->data[xfer->head]) ==
USB_NAK)
err = XHCI_TRB_ERROR_SUCCESS;
diff --git a/devicemodel/hw/platform/usb_mouse.c b/devicemodel/hw/platform/usb_mouse.c
index 475e3515d..33b3dd257 100644
--- a/devicemodel/hw/platform/usb_mouse.c
+++ b/devicemodel/hw/platform/usb_mouse.c
@@ -740,6 +740,7 @@ umouse_data_handler(void *scarg, struct usb_xfer *xfer, int dir,
err = USB_ERR_CANCELLED;
USB_DATA_SET_ERRCODE(&xfer->data[xfer->head], USB_NAK);
pthread_mutex_unlock(&dev->mtx);
+ printf("XXXXXXXXXXXXXXXXXXXXXXX umouse USB_ERR_CANCELLED.\n");
goto done;
}

diff --git a/devicemodel/hw/platform/usb_pmapper.c b/devicemodel/hw/platform/usb_pmapper.c
index d7ff2f6b4..e0a30710d 100644
--- a/devicemodel/hw/platform/usb_pmapper.c
+++ b/devicemodel/hw/platform/usb_pmapper.c
@@ -20,6 +20,7 @@
static struct usb_dev_sys_ctx_info g_ctx;
static uint16_t usb_dev_get_ep_maxp(struct usb_dev *udev, int pid, int epnum);

+int tracnf = 0;
static bool
usb_get_native_devinfo(struct libusb_device *ldev,
struct usb_native_devinfo *info,
@@ -324,6 +325,8 @@ cancel_out:
free(r);
free_transfer:
libusb_free_transfer(trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

static struct usb_dev_req *
@@ -359,8 +362,11 @@ usb_dev_alloc_req(struct usb_dev *udev, struct usb_xfer *xfer, int in,
errout:
if (req && req->buffer)
free(req->buffer);
- if (req && req->trn)
+ if (req && req->trn) {
+ tracnf--;
libusb_free_transfer(req->trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
+ }
if (req)
free(req);
return NULL;
@@ -746,6 +752,7 @@ usb_dev_reset(void *pdata)
return rc;
}

+
int
usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
{
@@ -879,17 +886,22 @@ usb_dev_data(void *pdata, struct usb_xfer *xfer, int dir, int epctx)
UPRINTF(LFTL, "%s: wrong endpoint type %d\r\n", __func__, type);
if (r->buffer)
free(r->buffer);
- if (r->trn)
+ if (r->trn) {
libusb_free_transfer(r->trn);
+ tracnf--;
+ printf("%s libusb_free_transfer %d\n", __func__, tracnf);
+ }
free(r);
xfer->status = USB_ERR_INVAL;
}

rc = libusb_submit_transfer(r->trn);
+ tracnf++;
if (rc) {
xfer->status = USB_ERR_IOERROR;
- UPRINTF(LDBG, "libusb_submit_transfer fail: %d\n", rc);
- }
+ printf("libusb_submit_transfer fail: %d\n", rc);
+ } else
+ printf("XXXXXXXXXXXXXXXXX libusb_submit_transfer %d\n", tracnf);
done:
return xfer->status;
}
@@ -1124,7 +1136,9 @@ usb_dev_free_request(void *pdata)
struct libusb_transfer *trn;

trn = pdata;
+ tracnf--;
libusb_free_transfer(trn);
+ printf("%s libusb_free_transfer %d.\n", __func__, tracnf);
}

void
@@ -1288,12 +1302,14 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
return -1;
}

+ printf("XXXXXXXXX before libusb_init!\n");
rc = libusb_init(&g_ctx.libusb_ctx);
if (rc < 0) {
UPRINTF(LFTL, "libusb_init fails, rc:%d\r\n", rc);
return -1;
}

+ printf("xxxxxxxxx After libusb_init!\n");
g_ctx.hci_data = hci_data;
g_ctx.conn_cb = conn_cb;
g_ctx.disconn_cb = disconn_cb;
@@ -1303,7 +1319,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
g_ctx.unlock_ep_cb = unlock_ep_cb;

num_devs = usb_dev_scan_dev(&g_ctx.devlist);
- UPRINTF(LINF, "found %d devices before Guest OS booted\r\n", num_devs);
+ printf("found %d devices before Guest OS booted\r\n", num_devs);

native_conn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED;
native_disconn_evt = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT;
@@ -1330,6 +1346,7 @@ usb_dev_sys_init(usb_dev_sys_cb conn_cb, usb_dev_sys_cb disconn_cb,
goto errout;
}

+ printf("XXXXXXXXX After libusb_init!\n");
/* this is for guest rebooting purpose */
g_ctx.conn_handle = native_conn_handle;
g_ctx.disconn_handle = native_disconn_handle;
--
2.25.1


Re: [PATCH 1/2] dm: remove ASL_COMPILER macro

Yu Wang
 

On Mon, Jun 13, 2022 at 07:53:40AM +0000, Victor Sun wrote:


-----Original Message-----
From: acrn-dev@... <acrn-dev@...> On
Behalf Of Yu Wang
Sent: Monday, June 13, 2022 3:11 PM
To: acrn-dev@...
Subject: Re: [acrn-dev] [PATCH 1/2] dm: remove ASL_COMPILER macro

On Sun, Jun 12, 2022 at 01:42:02PM +0800, Victor Sun wrote:
Previously ASL_COMPILER macro that indicates iasl location was passed
from host build machine environment, this makes no sense on target
machine. If user has a specific iasl path on host, then devicemodel
will fail to run on target machine.

The patch uses popen() to create a child process to get the exact iasl
path on target machine. If no iasl is found, devicemodel will exit directly.

Signed-off-by: Victor Sun <victor.sun@...>
---
devicemodel/core/main.c | 5 ++++
devicemodel/hw/platform/acpi/acpi.c | 39 ++++++++++++++++++++++++---
--
devicemodel/include/acpi.h | 2 ++
3 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c index
0e3d77bfa..6e6e2608e 100644
--- a/devicemodel/core/main.c
+++ b/devicemodel/core/main.c
@@ -855,6 +855,11 @@ main(int argc, char *argv[])
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
fprintf(stderr, "cannot register handler for SIGPIPE\n");

+ if (get_iasl_compiler() != 0) {
+ pr_err("cannot find Intel ACPI ASL compiler tool \"iasl\"");
Cannot

+ exit(1);
+ }
+
if (parse_madt()) {
pr_err("Failed to parse the MADT table\n");
exit(1);
diff --git a/devicemodel/hw/platform/acpi/acpi.c
b/devicemodel/hw/platform/acpi/acpi.c
index 0ba25e879..6703b59d2 100644
--- a/devicemodel/hw/platform/acpi/acpi.c
+++ b/devicemodel/hw/platform/acpi/acpi.c
@@ -95,9 +95,8 @@

#define ASL_TEMPLATE "dm.XXXXXXX"
#define ASL_SUFFIX ".aml"
-#ifndef ASL_COMPILER
-#define ASL_COMPILER "/usr/sbin/iasl"
-#endif
+
+static char asl_compiler[MAXPATHLEN] = {0};

uint64_t audio_nhlt_len = 0;

@@ -972,7 +971,7 @@ basl_compile(struct vmctx *ctx,
uint64_t offset)
{
struct basl_fio io[2];
- static char iaslbuf[3*MAXPATHLEN + 10];
+ static char iaslbuf[4*MAXPATHLEN + 10];
int err;

err = basl_start(&io[0], &io[1]);
@@ -990,12 +989,12 @@ basl_compile(struct vmctx *ctx,
if (basl_verbose_iasl)
snprintf(iaslbuf, sizeof(iaslbuf),
"%s -p %s %s",
- ASL_COMPILER,
+ asl_compiler,
io[1].f_name, io[0].f_name);
else
snprintf(iaslbuf, sizeof(iaslbuf),
"/bin/sh -c \"%s -p %s %s\" 1>
/dev/null",
- ASL_COMPILER,
+ asl_compiler,
io[1].f_name, io[0].f_name);

err = system(iaslbuf);
@@ -1110,6 +1109,34 @@ get_acpi_table_length(void)
return ACPI_LENGTH;
}

+int
+get_iasl_compiler(void)
+{
+ int ret = -1;
+ char c;
+ int i = 0;
+ FILE *fd_iasl = popen("which iasl", "r");
+
+ if (fd_iasl != NULL)
+ {
+ while (i < (MAXPATHLEN - 1)) {
+
+ c = fgetc(fd_iasl);
+ if ((c == EOF) || (c == 0x0d) || (c == 0x0a) || (c == 0)) {
+ break;
+ }
What's mean of 0x0d, 0x0c?
Hi Yu:

Ascii 0x0d: '\r', 0x0a: '\n'.
How about change the code as below?
if ((c == EOF) || (c == '\n') || (c == '\r') || (c == 0)) {
Yes. That's better.

Please PR with the fix.
Acked-by: Wang, Yu1 <yu1.wang@...>



+
+ asl_compiler[i++] = c;
+ }
If it is 0x0d or 0x0c, should we add '\0' at the end?
The asl_compiler[] has been initialized as all zero already:
static char asl_compiler[MAXPATHLEN] = {0};

BR,
Victor


+ if (strlen(asl_compiler) > 0) {
+ pr_info("found iasl: %s\n", asl_compiler);
+ ret = 0;
+ }
+ pclose(fd_iasl);
+ }
+ return ret;
+}
+
int
acpi_build(struct vmctx *ctx, int ncpu) { diff --git
a/devicemodel/include/acpi.h b/devicemodel/include/acpi.h index
52130d220..e9941e677 100644
--- a/devicemodel/include/acpi.h
+++ b/devicemodel/include/acpi.h
@@ -121,4 +121,6 @@ int lapicid_from_pcpuid(int pcpu_id); int
lapic_to_pcpu(int lapic);

int parse_madt(void);
+int get_iasl_compiler(void);
+
#endif /* _ACPI_H_ */
--
2.25.1












[PATCH] config_tools: update the hugepage algorithm

Kunhui Li
 

update the hugepages algorithm as the following steps.
1. calculate the total hugepages of service vm using the formula.
"total memory*0.98 - the memory consumed by pre-launched VMs - 5G
-300M*num(number of virtio gpu instance)".
2. calculate hugepage 1G based post-launched vm memory setting.
3. check if the memory configured in post launch VMs is not larger than
the total hugepages.

Compared with the previous version, this patch removes the 2M hugepage
and the correction value, also update the formula of total hugepage.

Tracked-On: #7301
Signed-off-by: Kunhui-Li <kunhuix.li@...>
---
misc/config_tools/static_allocators/memory_allocator.py | 8 ++------
misc/config_tools/xforms/misc_cfg.h.xsl | 2 +-
2 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/misc/config_tools/static_allocators/memory_allocator.py b/misc/config_tools/static_allocators/memory_allocator.py
index fd8e0cf88..f47c8d1a0 100644
--- a/misc/config_tools/static_allocators/memory_allocator.py
+++ b/misc/config_tools/static_allocators/memory_allocator.py
@@ -157,9 +157,9 @@ def allocate_hugepages(board_etree, scenario_etree, allocation_etree):
hugepages_1gb = 0
hugepages_2mb = 0
ram_range_info = import_memory_info(board_etree)
- total_hugepages = sum(ram_range_info[i] for i in ram_range_info if i >= 0x100000000)/(1024*1024*1024) \
+ total_hugepages = int(sum(ram_range_info[i] for i in ram_range_info if i >= 0x100000000)*0.98/(1024*1024*1024) \
- sum(int(i) for i in scenario_etree.xpath("//vm[load_order = 'PRE_LAUNCHED_VM']/memory/hpa_region/size_hpa/text()"))/1024 \
- - 4 - 300/1024 * len(scenario_etree.xpath("//virtio_devices/gpu"))
+ - 5 - 300/1024 * len(scenario_etree.xpath("//virtio_devices/gpu")))

post_launch_vms = scenario_etree.xpath("//vm[load_order = 'POST_LAUNCHED_VM']")
if len(post_launch_vms) > 0:
@@ -171,14 +171,10 @@ def allocate_hugepages(board_etree, scenario_etree, allocation_etree):
hugepages_2mb = int(hugepages_2mb + math.ceil(mb * 1024 / 2))

post_vms_memory = sum(int(i) for i in scenario_etree.xpath("//vm[load_order = 'POST_LAUNCHED_VM']/memory/size/text()")) / 1024
- correction_mb, correction_gb = math.modf(total_hugepages - post_vms_memory)
if total_hugepages - post_vms_memory < 0:
logging.warning(f"The sum {post_vms_memory} of memory configured in post launch VMs should not be larger than " \
f"the calculated total hugepages {total_hugepages} of service VMs. Please update the configuration in post launch VMs")

- hugepages_1gb = hugepages_1gb + correction_gb
- hugepages_2mb = hugepages_2mb + math.ceil(correction_mb * 1024 / 2)
-
allocation_service_vm_node = common.get_node("/acrn-config/vm[load_order = 'SERVICE_VM']", allocation_etree)
if allocation_service_vm_node is not None:
common.append_node("./hugepages/gb", int(hugepages_1gb), allocation_service_vm_node)
diff --git a/misc/config_tools/xforms/misc_cfg.h.xsl b/misc/config_tools/xforms/misc_cfg.h.xsl
index f742a78ee..d5ffb3ea8 100644
--- a/misc/config_tools/xforms/misc_cfg.h.xsl
+++ b/misc/config_tools/xforms/misc_cfg.h.xsl
@@ -93,7 +93,7 @@
</xsl:variable>
<xsl:variable name="hugepage_kernelstring">
<xsl:if test="//board-data//processors//capability[@id='gbyte_pages']">
- <xsl:value-of select="concat('hugepagesz=1G hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/gb, ' hugepagesz=2M hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/mb)" />
+ <xsl:value-of select="concat('hugepagesz=1G hugepages=', //allocation-data//vm[acrn:is-service-vm(load_order)]/hugepages/gb)" />
</xsl:if>
</xsl:variable>
<xsl:value-of select="acrn:define('SERVICE_VM_ROOTFS', concat($quot, $sos_rootfs, ' ', $quot), '')" />
--
2.25.1

1 - 20 of 36191