Date   

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


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

Victor Sun
 

-----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\"");
+ 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)) {


+
+ 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








Re: [PATCH v1] dm: vdisplay: fix comment typos.

Yu Wang
 

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

On Mon, Jun 13, 2022 at 01:27:13PM +0800, peng.p.sun@... wrote:
From: Sun Peng <peng.p.sun@...>

Fix some typos in output logs.

Tracked-on: #7747
Signed-off-by: Sun Peng <peng.p.sun@...>
---
devicemodel/hw/vdisplay_sdl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicemodel/hw/vdisplay_sdl.c b/devicemodel/hw/vdisplay_sdl.c
index 1c3eb1efa..077d73189 100644
--- a/devicemodel/hw/vdisplay_sdl.c
+++ b/devicemodel/hw/vdisplay_sdl.c
@@ -1140,7 +1140,7 @@ gfx_ui_init()
setenv("SDL_RENDER_SCALE_QUALITY", "linear", 1);

if (SDL_Init(SDL_INIT_VIDEO)) {
- pr_err("Failed to Init SDL2 system");
+ pr_err("Failed to Init SDL2 system\n");
Init -> init

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

return -1;
}

--
2.25.1


Re: [PATCH 2/2] Makefile: remove ASL_COMPILER dependency

Yu Wang
 

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

On Sun, Jun 12, 2022 at 01:42:03PM +0800, Victor Sun wrote:
Given ASL_COMPILER macro is removed from devicemodel, remove this dependency
in devicemodel Makefile.

Signed-off-by: Victor Sun <victor.sun@...>
---
Makefile | 3 +--
devicemodel/Makefile | 4 ----
2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 3872b2ce6..fa2b6d3c5 100644
--- a/Makefile
+++ b/Makefile
@@ -82,7 +82,6 @@ BUILD_VERSION ?=
BUILD_TAG ?=
HV_CFG_LOG = $(HV_OUT)/cfg.log
VM_CONFIGS_DIR = $(T)/misc/config_tools
-ASL_COMPILER ?= $(shell which iasl)
DPKG_BIN ?= $(shell which dpkg)
YARN_BIN ?= $(shell which yarn)
CARGO_BIN ?= $(shell which cargo)
@@ -132,7 +131,7 @@ hvapplydiffconfig:
@$(MAKE) applydiffconfig $(HV_MAKEOPTS) PATCH=$(abspath $(PATCH))

devicemodel: tools
- $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) DM_ASL_COMPILER=$(ASL_COMPILER) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)
+ $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)

tools:
mkdir -p $(TOOLS_OUT)
diff --git a/devicemodel/Makefile b/devicemodel/Makefile
index 3fcd1dd55..d4b87876a 100644
--- a/devicemodel/Makefile
+++ b/devicemodel/Makefile
@@ -45,10 +45,6 @@ CFLAGS += -I$(SYSROOT)/usr/include/SDL2
CFLAGS += -I$(SYSROOT)/usr/include/EGL
CFLAGS += -I$(SYSROOT)/usr/include/GLES2

-ifneq (, $(DM_ASL_COMPILER))
-CFLAGS += -DASL_COMPILER=\"$(DM_ASL_COMPILER)\"
-endif
-
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)

--
2.25.1






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

Yu Wang
 

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\"");
+ 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?

+
+ asl_compiler[i++] = c;
+ }
If it is 0x0d or 0x0c, should we add '\0' at the end?

+ 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 v1] dm: vdisplay: fix comment typos.

Sun, Peng
 

From: Sun Peng <peng.p.sun@...>

Fix some typos in output logs.

Tracked-on: #7747
Signed-off-by: Sun Peng <peng.p.sun@...>
---
devicemodel/hw/vdisplay_sdl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/devicemodel/hw/vdisplay_sdl.c b/devicemodel/hw/vdisplay_sdl.c
index 1c3eb1efa..077d73189 100644
--- a/devicemodel/hw/vdisplay_sdl.c
+++ b/devicemodel/hw/vdisplay_sdl.c
@@ -1140,7 +1140,7 @@ gfx_ui_init()
setenv("SDL_RENDER_SCALE_QUALITY", "linear", 1);

if (SDL_Init(SDL_INIT_VIDEO)) {
- pr_err("Failed to Init SDL2 system");
+ pr_err("Failed to Init SDL2 system\n");
return -1;
}

--
2.25.1


[PATCH 2/2] Makefile: remove ASL_COMPILER dependency

Victor Sun
 

Given ASL_COMPILER macro is removed from devicemodel, remove this dependency
in devicemodel Makefile.

Signed-off-by: Victor Sun <victor.sun@...>
---
Makefile | 3 +--
devicemodel/Makefile | 4 ----
2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 3872b2ce6..fa2b6d3c5 100644
--- a/Makefile
+++ b/Makefile
@@ -82,7 +82,6 @@ BUILD_VERSION ?=
BUILD_TAG ?=
HV_CFG_LOG = $(HV_OUT)/cfg.log
VM_CONFIGS_DIR = $(T)/misc/config_tools
-ASL_COMPILER ?= $(shell which iasl)
DPKG_BIN ?= $(shell which dpkg)
YARN_BIN ?= $(shell which yarn)
CARGO_BIN ?= $(shell which cargo)
@@ -132,7 +131,7 @@ hvapplydiffconfig:
@$(MAKE) applydiffconfig $(HV_MAKEOPTS) PATCH=$(abspath $(PATCH))

devicemodel: tools
- $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) DM_ASL_COMPILER=$(ASL_COMPILER) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)
+ $(MAKE) -C $(T)/devicemodel DM_OBJDIR=$(DM_OUT) DM_BUILD_VERSION=$(BUILD_VERSION) DM_BUILD_TAG=$(BUILD_TAG) TOOLS_OUT=$(TOOLS_OUT) RELEASE=$(RELEASE)

tools:
mkdir -p $(TOOLS_OUT)
diff --git a/devicemodel/Makefile b/devicemodel/Makefile
index 3fcd1dd55..d4b87876a 100644
--- a/devicemodel/Makefile
+++ b/devicemodel/Makefile
@@ -45,10 +45,6 @@ CFLAGS += -I$(SYSROOT)/usr/include/SDL2
CFLAGS += -I$(SYSROOT)/usr/include/EGL
CFLAGS += -I$(SYSROOT)/usr/include/GLES2

-ifneq (, $(DM_ASL_COMPILER))
-CFLAGS += -DASL_COMPILER=\"$(DM_ASL_COMPILER)\"
-endif
-
GCC_MAJOR=$(shell echo __GNUC__ | $(CC) -E -x c - | tail -n 1)
GCC_MINOR=$(shell echo __GNUC_MINOR__ | $(CC) -E -x c - | tail -n 1)

--
2.25.1


[PATCH 1/2] dm: remove ASL_COMPILER macro

Victor Sun
 

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\"");
+ 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;
+ }
+
+ asl_compiler[i++] = c;
+ }
+ 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

1161 - 1180 of 37344