Date   

Re: [PATCH] dm: virtio-console: change STDIO BE attribute

Yu Wang
 

On Thu, Jun 30, 2022 at 11:11:13PM +0800, Conghui Chen wrote:
Fix the log format problem in devicemodel when using virtio-console with
'stdio' configuration.
In virtio-console, it will change the STDIO's attributes, and will case
the log message after that not align.
e.g:
for (i=0; i<3; i++)
printf('test\n');

The original output would be like this:

test
test
test

After add 'OPOST' to oflag of STDIO, the output would be like this:

test
test
test

(OPOST - Enable implementation-defined output processing)

Signed-off-by: Conghui <conghui.chen@...>
---
devicemodel/hw/pci/virtio/virtio_console.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c
index d3b0fb857..a55284f02 100644
--- a/devicemodel/hw/pci/virtio/virtio_console.c
+++ b/devicemodel/hw/pci/virtio/virtio_console.c
@@ -746,6 +746,7 @@ virtio_console_config_backend(struct virtio_console_backend *be)
saved_tio = tio;
cfmakeraw(&tio);
tio.c_cflag |= CLOCAL;
+ tio.c_oflag |= OPOST;
I just googled the OPOST. Looks like the CLOCAL is not performed if
OPOST is not set.

https://www.mkssoftware.com/docs/man5/struct_termios.5.asp

Can you please try to double confirm the behavior? Set OPOST but remove
the CLOCAL?

tcsetattr(fd, TCSANOW, &tio);

if (be->be_type == VIRTIO_CONSOLE_BE_STDIO) {
--
2.25.1






[Announce] ACRN Open Source Ver3.0 Release Notes

Zou, Terry
 

Hi all, We are very pleased to announce Version 3.0 release of ACRN. You can see the release blog from https://projectacrn.org/blog/ and detailed Release Notes in website https://projectacrn.github.io/latest/release_notes/release_notes_3.0.html

What’s New in v3.0:

·        Redesigned ACRN Configuration

We heard your feedback: ACRN configuration is difficult, confusing, and had too many parameters that were not easy to understand. Release v3.0 features a new ACRN Configurator UI tool with a more intuitive design and workflow that simplifies getting the setup for the ACRN hypervisor right. You’ll also see changes for configuring individual VMs. We’ve greatly reduced the number of parameters needing your attention, organized them into basic and advanced categories, provided practical defaults, and added error checking so you can be much more confident in your configuration before building ACRN. We’ve also integrated the previously separated scenario and launch options into a merged scenario XML configuration file managed by the new Configurator. Read more in the ACRN Configurator Tool page.

This is our first major step of continued ACRN user experience improvements. If you have feedback on this, or other aspects of ACRN, please share them on the ACRN users mailing list.

We’ve also simplified installation of the Configurator by providing a Debian package that you can download from the ACRN v3.0 tag assets and install. See the Getting Started Guide for more information.

·        Improved Board Inspector Collection and Reporting

You run the ACRN Board Inspector tool to collect information about your target system’s processors, memory, devices, and more. The generated board XML file is used by the ACRN Configurator to determine which ACRN configuration options are possible, as well as possible values for target system resources. The v3.0 Board Inspector has improved scanning and provides more messages about potential issues or limitations of your target system that could impact ACRN configuration options. Read more in Board Inspector Tool.

·        Commercial off-the-shelf Tiger Lake machine support

The Vecow SPC-7100 system is validated and supported by ACRN. This is a commercially available 11th Generation Intel® Core™ Processor (codenamed Tiger Lake) from Vecow. Read more in the Supported Hardware documentation.

·        Refined shutdown & reset sequence

A Windows User VM can now shut down or reset the system gracefully. This supports a user model where a Windows-based VM provides a system management interface. This shutdown capability is achieved by lifecycle managers in each VM that talk to each other via a virtual UART channel.

·        Hypervisor Real Time Clock (RTC)

Each VM now has its own PC/AT-compatible RTC/CMOS device emulated by the hypervisor. With this, we can avoid any sudden jump in a VM’s system clock that may confuse certain applications.

·        ACRN Debianization

We appreciate a big contribution from the ACRN community! Helmut Buchsbaum from TTTech Industrial submitted a “debianization” feature that lets developers build and package ACRN into several Debian packages, install them on the target Ubuntu or Debian OS, and reboot the machine with ACRN running. Read more in debian/README.rst.

Document Updates:

With the introduction of the improved Configurator, we could improve our Getting Started Guide documentation and let you quickly build a simple ACRN hypervisor and User VM configuration from scratch instead of using a contrived pre-defined scenario configuration. That also let us reorganize and change configuration option documentation to use the newly defined developer-friendly names for configuration options.

Check out our improved Getting Started and Configuration documents:

² What Is ACRN

² Getting Started Guide

² Configuration and Development Overview

² Scenario Configuration Options

² Introduction to ACRN Configuration

² Board Inspector Tool

² ACRN Configurator Tool

² Upgrading ACRN Configurations to Recent Releases

² User VM Guide

² Device Model Parameters and Launch Script

Here are some of the high-level design documents that were updated since the v2.7 release:

² ACRN High-Level Design Overview

² AT Keyboard Controller Emulation

² Device Model High-Level Design

² Emulated Devices High-Level Design

² Power Management High-Level Design

² Security High-Level Design

² Virtio Devices High-Level Design

² Host Bridge Emulation

² CPU Virtualization

² Device Passthrough

² Hypercall / HSM Upcall

² Physical Interrupt High-Level Design

² I/O Emulation High-Level Design

² IOC Virtualization High-Level Design

² Virtual Interrupt

² ACRN Shared Memory Based Inter-VM Communication

² System Timer Virtualization

² UART Virtualization

² Virtio-BLK

² Virtio-Console

² Virtio-Input

² Virtio-Net

² vUART Virtualization

² L1 Terminal Fault Mitigation

² Trusty TEE

We’ve also made edits throughout the documentation to improve clarity, formatting, and presentation. We started updating feature enabling tutorials based on the new Configurator, and will continue updating them after the v3.0 release (in the latest documentation).  See the v3.0 full release notes and documentation for more information about this release including fixed and known issues.

Upgrading to v3.0 From Previous Releases

With the introduction of the Configurator UI tool, the need for manually editing XML files is gone. While working on this improved Configurator, we’ve also made many adjustments to available options in the underlying XML files, including merging the previous scenario and launch XML files into a combined scenario XML file. The board XML file generated by the v3.0 Board Inspector tool includes more information about the target system that is needed by the v3.0 Configurator.

We recommend you generate a new board XML for your target system with the v3.0 Board Inspector. You should also use the v3.0 Configurator to generate a new scenario XML file and launch scripts. Scenario XML files and launch scripts created by previous ACRN versions will not work with the v3.0 ACRN hypervisor build process and could produce unexpected errors during the build.

Given the scope of changes for the v3.0 release, we have recommendations for how to upgrade from prior ACRN versions:

1.       Start fresh from our Getting Started Guide. This is the best way to ensure you have a v3.0-ready board XML file from your target system and generate a new scenario XML and launch scripts from the new ACRN Configurator that are consistent and will work for the v3.0 build system.
2.       Use the upgrade tool to attempt upgrading configuration files that worked with a release before v3.0. You’ll need the matched pair of scenario XML and launch XML files from a prior configuration, and use them to create a new merged scenario XML file. See Upgrading ACRN Configurations to Recent Releases for details.
3.       Manually edit your prior scenario XML and launch XML files to make them compatible with v3.0. This is not our recommended approach.

 

Best & Regards

Terry


[PATCH] dm: virtio-console: change STDIO BE attribute

Conghui Chen
 

Fix the log format problem in devicemodel when using virtio-console with
'stdio' configuration.
In virtio-console, it will change the STDIO's attributes, and will case
the log message after that not align.
e.g:
for (i=0; i<3; i++)
printf('test\n');

The original output would be like this:

test
test
test

After add 'OPOST' to oflag of STDIO, the output would be like this:

test
test
test

(OPOST - Enable implementation-defined output processing)

Signed-off-by: Conghui <conghui.chen@...>
---
devicemodel/hw/pci/virtio/virtio_console.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/devicemodel/hw/pci/virtio/virtio_console.c b/devicemodel/hw/pci/virtio/virtio_console.c
index d3b0fb857..a55284f02 100644
--- a/devicemodel/hw/pci/virtio/virtio_console.c
+++ b/devicemodel/hw/pci/virtio/virtio_console.c
@@ -746,6 +746,7 @@ virtio_console_config_backend(struct virtio_console_backend *be)
saved_tio = tio;
cfmakeraw(&tio);
tio.c_cflag |= CLOCAL;
+ tio.c_oflag |= OPOST;
tcsetattr(fd, TCSANOW, &tio);

if (be->be_type == VIRTIO_CONSOLE_BE_STDIO) {
--
2.25.1


[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

901 - 920 of 37094