Commit Graph

1258 Commits

Author SHA1 Message Date
Helmut Buchsbaum 78f702ef8c Use libdrm library for drm access
Use needed constants from libderm instead of directly using
kernel UAPI.

Tracked-On: #6688
Signed-off-by: Helmut Buchsbaum <helmut.buchsbaum@opensource.tttech-industrial.com>
2022-05-10 09:20:14 +08:00
Helmut Buchsbaum 7637e53963 dm: Remove dependency on libuuid
Since any uuid relevant action directly uses Linux kernel UAPI
(linux/uuid.h) the use of libuuid is not required.

Tracked-On: #6688
Signed-off-by: Helmut Buchsbaum <helmut.buchsbaum@opensource.tttech-industrial.com>
2022-05-10 09:20:14 +08:00
Zhao Yakui 3921812885 ACRN:DM:VGPU: Add more standard modes for EDID block
EDID uses the bytes of 38-53 to support up to 8 standard modes. And it is
based on the mechanism: Byte 0 defines the xres / 8 - 31 and byte 1 defines
the aspect_ratio/refresh_rate.
But now it uses the incorrect logic in course of adding standard mode, which
causes that no standard mode is added in EDID block.

Fix it and add another two standard modes so that the guest_vm can parse
more modes from EDID.

Tracked-On: #7376

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-05-07 10:08:46 +08:00
Zhao Yakui 4972d29c2d ACRN:DM:VGPU: Fix the incorrect offset for EDID detailed_timing_block
The EDID uses the bytes of 54-125 to define the four detailed_timing_blocks.
But the static offset is used to update the DTB. This will cause that
the incorrect offset is used for DTB if the edid_generate is called several
times.

Tracked-On: #7376

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-05-07 10:08:46 +08:00
Chenli Wei 513eafd6f0 dm: optimize the sub parameter of "-s" compatibility
This patch checks the change of "-s" sub parameters, which was
obsoleted or moved and the print some warnings msg or show the new
format.

The following obsoleted parameters are covered:

-s ,pci-gvt
-s ,virtio-hdcp
-s ,npk
-s ,virtio-coreu
--mac_seed

Reviewed-by: VanCutsem Geoffroy <geoffroy.vancutsem@intel.com>
Signed-off-by: Chenli Wei <chenli.wei@intel.com>
2022-05-05 15:03:34 +08:00
Fei Li 79442cbc96 dm: acpi: refine CPU Definition Blocks name
For all Definition Blocks in ACPI Namespace, their name are a fixed 32 bits.
This patch refine CPU Definition Blocks name to support more than 10 CPUs
for a guest.

Tracked-On: #7387
Signed-off-by: Fei Li <fei1.li@intel.com>
2022-04-29 16:53:16 +08:00
Zhao Yakui 373dac68ef ACRN:VGPU: Virtio_gpu_init calls the vdpy_init before vdpy_get_display_info
Now vdpy_get_display_info/get_edid is called before vdpy_init.
This is incorrect. They should be called after setting up the
connection with vdisplay.

Tracked-On: #7376
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-28 09:41:06 +08:00
Zhao Yakui e3b7f736d7 ACRN:VGPU: Add the missing initialization of vdisplay info
Now some fileds are not initialized, which causes that ACRN-DM doesn't
handle the request of VIRTIO_GPU_CMD_GET_DISPLAY_INFO and
VIRTIO_GPU_CMD_GET_EDID.

Tracked-On: #7376
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-28 09:41:06 +08:00
Zhao Yakui 402565f222 ACRN:VGPU: Fix the incorrect logic of fetching EDID
The virtio_gpu in guest_vm will try to fetch the EDID to query
the supported resolution. Guest vm will send the cmd of
VIRTIO_GPU_CMD_GET_EDID and receive the response of VIRTIO_GPU_RESP_OK_EDID.
Now acrn-dm has some issues in course of handlding EDID request: Incorrect
resp type, the incorrect response. This will cause that the guest_vm fails
to fetch the EDID.

Tracked-On: #7376
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-28 09:41:06 +08:00
Chenli Wei a0678c82bb dm: optimize the parameter compatibility
This patch checks the obsoleted parameters and print some warnings
instead of exiting the acrn-dm directly. The following obsoleted
parameters are covered:

-i, --ioc_node
-G, --gvtargs
-Y, --mptgen
--vsbl
--part_info
--pm_by_vuart
--pm_notify_channel

Tracked-On: #6690
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
Signed-off-by: Chenli Wei <chenli.wei@intel.com>
2022-04-24 10:25:09 +08:00
Zhao Yakui 599962fe71 ACRN:DM:VGPU: Rename thread_name for dedicated rendering thread
Otherwise it will use the "acrn_dm" as the thread_name, which is not
convenient to check the cpu_usage of rendering_thread.

Tracked-On: #7337
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-21 16:35:15 +08:00
Zhao Yakui 0873575a03 ACRN:DM:VGPU: Free the memory after creating udmabuf
In course of creating the udmabuf, udmabuf_create_list is allocated and
passed to kernel. After the dmabuf is returned, it is not used
any more. Need to free it otherwises it will cause the memory leak.

Tracked-On: #7337
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-21 16:35:15 +08:00
Zhao Yakui 8b7767e643 ACRN:DM:VGPU: Fix the incorrect use after free
It still tries to access the gpu->vdpy_handel after the gpu
is free. This is incorrect.

Tracked-On: #7337
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-21 16:35:15 +08:00
Zhao Yakui 2a7a269313 ACRN:DM:VDISPLAY:Fix the possible access after free
When virtio-gpu tries to submit the framebuffer based on
VIRTIO_GPU_CMD_2D, one pixman_image will be created. When the
sdl rendering_thread is terminated, the pixman_image will be 
released. But its pointer is set to NULL. In the next reboot,
its access in vdpy_surface_set is incorrect.  

Tracked-On: #7337
Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-21 16:35:15 +08:00
Zhao Yakui de3e0946bc ACRN:DM:VGPU: Add some checks to ignore multi-thread op
Now all the 3D ops are handled in one dedicated thread. As 3D ops are
not safe in multi-thread env, some checks are added so that it can indicate
that it is not in the expected code path.

Tracked-On: #7296
Acked-by: Wang Yu1 <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-19 18:30:06 +08:00
Zhao Yakui a555658484 ACRN:DM: Fix the memory_leak of vga_context in virtio_gpu_deinit
Otherwise the memory related with vga_context is leaked.

v1->v2: Use the pthread_join instead of usleep to wait for
the termination of vga_thread.

Tracked-On: #7296
Acked-by: Wang Yu1 <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-19 18:30:06 +08:00
Zhao Yakui 2e9773ed55 ACRN:DM: Avoid calling surface_set in course of virtio_gpu_reset
This is not needed as it is reconfigured in course of vga_thread_loop.
At the same time it is not thread-safe as the 3D api is involved
in vdpy_surface_set.

v2->v3: move the initialization of vga_surface width/height into
vga_thread.

Tracked-On: #7296
Acked-by: Wang Yu1 <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-19 18:30:06 +08:00
Zhao Yakui c73773c130 ACRN:DM: Avoid creating multi threads for vga_thread
In order to support the VGA op, one vga_thread is created. But
in course of virtio_gpu_reset, it will also create one vga_thread.
This is incorrect.

v1->v2: the thread_id of vga_thread is treated as read-only after
the thread is created.
        One thread_status based on atomic type indicates the life_cycle
of vga_thread.

v2->v3: Add the vga_thread_mtx in course of changing life_cycle of vga_thread

Tracked-On: #7296
Acked-by: Wang Yu1 <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-19 18:30:06 +08:00
Conghui 844c6e0bbc remove repetitive erasing for guest memory
The guest memory is allocated through hugetlb. Huge page fault is
triggered by writing a byte to the starting address for each huge page.
In hugetlb_fault(), The physical pages are allocated and *clear*.

So no need to erasing the memory again after hugetlb setup. This will
bring about 130ms (changes with platform) latency for each 1G memory.

Notice: this means we depends on kernel to erase the memory in huge page
fault!

Tracked-On: #7298
Signed-off-by: Conghui <conghui.chen@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-04-18 14:07:54 +08:00
Liu Long e347320787 ACRN:DM: Add pci msi per-vector masking capable
Add msi per-vector masking capable and emulate msi mask
pending mechanism in DM.

Tracked-On: #7265
Signed-off-by: Liu Long <long.liu@linux.intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-04-11 13:50:21 +08:00
Sun Peng c61d41da27 dm: Update license info of types.h
Add license info to devicemodel/include/types.h

Tracked-On: #7248
Signed-off-by: Sun Peng <peng.p.sun@linux.intel.com>
2022-04-08 13:54:47 +08:00
Sun Peng bfde6182d2 dm: virtio-gpu: update copyright and license
Add license information to virtio_gpu.c
Fix some grammar issues.

Tracked-On: #7241
Signed-off-by: Sun Peng <peng.p.sun@linux.intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-04-08 13:54:47 +08:00
Geoffroy Van Cutsem 8b16be9185 Remove "All rights reserved" string headers
Many of the license and Intel copyright headers include the "All rights
reserved" string. It is not relevant in the context of the BSD-3-Clause
license that the code is released under. This patch removes those strings
throughout the code (hypervisor, devicemodel and misc).

Tracked-On: #7254
Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
2022-04-06 13:21:02 +08:00
Zhao Yakui 34bfaa71f6 ACRN:DM: Export BLOB feature to guest
The DMABuf sharing is based on the BLOB feature. This will
check the attribute of system memory for guest_vm and udmabuf.list_limit
parameter. If it meets with the requirement, export the BLOB feature
so that the FE driver in guest_vm can send the blob cmd.
VIRTIO_GPU_CMD_CREATE_BLOB:
VIRTIO_GPU_CMD_SET_SCANOUT_BLOB:
VIRTIO_GPU_CMD_SET_FLUSH(BLOB)

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Zhao Yakui c19b2bed18 ACRN:DM: Add the support of blob_buffer from guest_vm
Now Virtio-gpu FE is using the below cmds to submit the framebuffer that
needs to be displayed.
   VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D
   VIRTIO_GPU_CMD_SET_SCANOUT
   VIRTIO_GPU_CMD_FLUSH

This will introduce twice copy. In order to optimize the twice copy, the below
cmds are added and the virtio-gpu BE can use the dma-buf sharing.
   VIRTIO_GPU_CMD_CREATE_BLOB
   VIRTIO_GPU_CMD_SET_SCANOUT_BLOB
   VIRTIO_GPU_CMD_FLUSH

V2->V3: Remove the inlined header file of devicemodel/include/public/udmabuf.h
to avoid the license issue

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Zhao Yakui f9aa6f754a ACRN:DM: Add Texture based on DMAbuf to support dmabuf_sharing rendering
Now the Opengl rendering is used implicitly in SDL backend. But sometimes
it needs to create the texture explicitly based on DMABuf so that it can
render the framebuffer submitted from virtio-gpu.

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Zhao Yakui 3645a9557d ACRN:DM: Add one API to query the memfd/offset for the given GPA
After using the memfd to allocate memory for guest vm, it needs to
query the offset in memfd for the given GPA. In order to search the
memfd/offset, the added memory_region from memfd needs to be kept in
one arrary.

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Zhao Yakui a46b0058d8 ACRN:DM: Use the memfd to allocate anonymous hugetlb file
The ACRN-DM uses the explicit hugetlb file to allocate the memory
for guest and the 2M/1G hugetlb can be used. This is based on mounting
hugetlb filesystem.
Now the Linux provides one flexbile memfd mechanism to allocate the memory
and this can make it possible to create the udmabuf for sharing. And the
memfd still can be based on Hugetlb 1G/2M policy. This can bring the below
benefits besides the 1G/2M hugetlb support.
a. memfd is based on anonymous file
b. possible dmabuf mechanism

v2->v3: After completing the mmap for memfd, it will call the ftruncate to
set the desired size and then add the F_SEAL_SEAL flag.

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Zhao Yakui 3bf11d9285 ACRN:DM: Check the alignment of mem_size
Now the memory region is aligned down to 2M if 2M hugetlb is supported.
Maybe some contents are dropped if it is not aligned. 

Tracked-On: #7210

Acked-by: Wang Yu <yu1.wang@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-04-01 11:40:43 +08:00
Peter Fang 4fc4b84304 OVMF release v3.0
- VGA interface of virtio-gpu adapter support
- Ovmf:ACRN: Fix the building error
- acrn: fix how to get memory below 4G

Tracked-On: #7231
Signed-off-by: Peter Fang <peter.fang@intel.com>
2022-03-31 09:06:34 +08:00
Zhao Yakui 473c5819ea ACRN:DM: Add extra path header definition to support cross-compiler building
The virtio-gpu needs to include some system header files.
In order to support the cross-compiler building, the header
path is added.

Tracked-On: #7210

Reported-by: Naveen Kumar Saine <naveen.kumar.saini@intel.com>
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
2022-03-29 11:16:40 +08:00
Sun, Peng 1ed96bfbf8 dm: virtio-gpu: VGA compability support
Legacy VGA & VBE interface as a common interface is supported by
many legacy and modern OS. Many installer of OS distribution use
this interface to display the GUI of installer when setup a refresh
new installation on bare-metal. Besides, Windows OS always use this
interface to display it's BSOD, recovery mode & safe mode GUI. It
is need because Windows don't include virtio-gpu driver as their
in-box driver, VGA interface will be used before the virtio-gpu
driver been installed.
To be compatiable with the PCI bar layout of legacy VGA, the layout
is refined to meet with the requirement of legacy VGA and modern
virtio-gpu.

BAR0: VGA Framebuffer memory, 16 MB in size.
BAR2: MMIO Space
  [0x0000~0x03ff] EDID data blob
  [0x0400~0x041f] VGA ioports registers
  [0x0500~0x0516] bochs display interface registers
  [0x1000~0x17ff] Virtio common configuration registers
  [0x1800~0x1fff] Virtio ISR state registers
  [0x2000~0x2fff] Virtio device configuration registers
  [0x3000~0x3fff] Virtio notification registers
BAR4: MSI/MSI-X
BAR5: Virtio port io

Tracked-On: #7210
Signed-off-by: Sun Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Sun, Peng f2cfa761ae dm: virtio-gpu: cursor surpport
Hardware cursor emulation of virtio-gpu video adapter. Guest vm can
show its own cursor in virtual display, not share the cursor with
service vm. It also accelerated by SDL(OpenGL ES 2.0 backend) API
with hardware acceleration based on the GPU hardware own by service
vm.

Tracked-On: #7210
Signed-off-by: Sun, Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Sun, Peng fae4286cb3 dm: virtio-gpu: 2D mode support
Implement 2D mode of virtio-gpu adapter which can transfer outputs
from guest vm framebuffer and store them to host 2D scanout buffers.
These 2D scanout buffer can be shown by calling vdpy_surface_set/update
API provided device/include/vdisplay.h.

Virtio-gpu 2D commands calling sequence:
  1) VIRTIO_GPU_CMD_GET_EDID
  2) VIRTIO_GPU_CMD_GET_DISPLAY_INFO
  3) VIRTIO_GPU_CMD_RESOURCE_CREATE_2D
  4) VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING
  5) VIRTIO_GPU_CMD_SET_SCANOUT
  6) VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D
  7) VIRTIO_GPU_CMD_RESOURCE_FLUSH

Tracked-On: #7210
Signed-off-by: Sun, Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Sun, Peng eba0820bc7 dm: virtio-gpu: EDID emulation of virtual monitor
Extended display identification data(EDID) is a data to store
display timings which are supported by ACRN virtual monitor.
Virtio-gpu FE driver will request it to config crtc for display
resolutions.

Tracked-On: #7210
Signed-off-by: Sun, Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Sun, Peng bca6464e9f dm: virtio-gpu: virtual display support
ACRN virtual monitor shown as a GUI system window of service vm.
It can display graphic outputs of guest vm which is stored in
service vm's buffers by virtio-gpu. Display operation is accelerated
by Intel GPU PF(SRIOV) device with SDL(OpenGL ES 2.0 backend) API.
This provides one generic display solution. When the virtio-gpu is
added, it will firstly try to setup the connection to graphics system
and then display the framebuffer from the guest vm in the created
window region.

Tracked-On: #7210
Signed-off-by: Sun, Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Sun, Peng 37a4cdc2e0 dm: virtio-gpu: basic framework
Virtio-gpu is a virtio based graphic adapter. It supports 2D mode
which can transfer the guest vm's framebuffer into service vm's
buffers for displaying. It can co-work with Intel GPU VF(SRIOV)
device and provide thransport for the accelerated contents. With
this, guest vm can benefit Intel GPU hardware to accelerate media
coding, 3D rendering and compute.

Tracked-On: #7210
Signed-off-by: Sun, Peng <peng.p.sun@linux.intel.com>
Reviewed-by: Zhao, yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-28 15:26:20 +08:00
Minggui Cao 1bc2921c27 Revert "Revert "dm: set PMU_PT flag for CPU ...""
This reverts commit 6750d5a277.

the bug is root caused and fixed, so recovery the original patch.

Tracked-On: #6966
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
2022-03-28 12:00:01 +08:00
Yonghua Huang d8c0d5eebb dm: update virtio-i2c bus counter when device is deinit
i2c bus counter 'acpi_i2c_adapter_num' shall be updated
 when virtio-i2c device is de-initialized, else in user VM
 reboot case, this global counter will not be reset and
 keep the value last user VM boot, which is not expected
 and cause iasl(building ACPI data) program crash finally
 because the i2c device name space overflow.

Tracked-On: #7208
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2022-03-23 10:37:52 +08:00
Chenli Wei b9431b8da4 dm: remove the assume of virtio-net device name
Now, the DM assumes the device name entered by user is dependent on
the type.

For example, the device of tap type is named tap_TAAG, this patch
remove the above assumption.

User could set any name, no matter the code of DM or actually created,
it is represented by user input.

Tracked-On: #6690
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
Signed-off-by: Chenli Wei<chenli.wei@linux.intel.com>
2022-03-22 11:33:09 +08:00
Yuanyuan Zhao 8f9a47c30f dm: add warning for `-A` param
DM dynamic param '-A' has been removed.
For compability, add a warning for `-A` instead of terminate the launch
process.

Tracked-On:#6690
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
Signed-off-by: Yuanyuan Zhao <yuanyuan.zhao@linux.intel.com>
2022-03-21 14:06:02 +08:00
Minggui Cao 6750d5a277 Revert "dm: set PMU_PT flag for CPU core partition VM"
This reverts commit 811992ee2b.

There could be some conflict with current configure tool. will fix it
later.

Tracked-On: #6966
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
2022-03-14 20:18:08 +08:00
Minggui Cao 811992ee2b dm: set PMU_PT flag for CPU core partition VM
for CPU core partition VM, like RTVM, set PMU passthrough
flag for vtune/perf to run in guest VM.

Tracked-On: #6966
Acked-by: Anthony Xu <anthony.xu@intel.com>
Signed-off-by: Minggui Cao <minggui.cao@intel.com>
2022-03-10 14:34:33 +08:00
Tw d1e3e8d633 dm/tools: compatible with openssl3.0
HMAC_*, MD5_* and SHA256_* are deprecated since openssl3.0, replace them with the corresponding equivalents.

Tracked-On: #6743
Signed-off-by: Tw <wei.tan@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-03-08 17:39:47 +08:00
dongshen ce7b38ee04 dm: fixed a bug where mptable failed to wake up CPU1# when adding acpi=off into User VM cmdline
Previous commit introduced the "use physical APIC IDs as vLAPIC IDs for VMs" change,
but it didn't update the apic_id in mptable. Changed the mptable code to also
set apic_id to physical APIC ID to fix the bug

Tracked-On: #7146
Signed-off-by: dongshen <dongsheng.x.zhang@intel.com>
2022-03-02 11:22:31 +08:00
Zhao Yakui eb9a58c70e ACRN:DM: Set the desired state to inject PCI legacy intx
When the virtio-XXX pci devices fall back to legacy PCI intx,
the pci_irq_assert is called to inject the interrupt and then
the pci_irq_deassert is used to mark the completion of PCI interrupt.
Currently the HV vIOAPIC uses the pin_state for the interrupt injection
of legacy PCI intx. In such case it will fail to inject the PCI legacy
intx and the guest system fails to be booted when adding the boot option
of "pci=nomsi".

PCI legacy INTx usually use active low level trigger mode as it is Open-Drain
state and allows multitple interrupt signals to share a single line.
https://wiki.osdev.org/PCI_Local_Bus_Signals
In such case DM needs to set the correct state for the PCI device so that the
HV vIOAPIC can help to inject the PCI legacy intx.

BTW: When the MSI/MSIX is used for PCI device, it uses another mechanism
to inject the interrupt. It is harmless to configure the initial state.

Tracked-On: #7124
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-02-21 15:34:01 +08:00
Yonghua Huang b4386566ef dm: fix mevent mutex deadlock issue
'mevent_lmutex' is initialized as default type,
 while attempting to recursively lock on this
 kind of mutext results in undefined behaviour.

 Recursively lock on 'mevent_lmutex' can be detected
 in mevent thread when user tries to trigger system
 reset from user VM, in this case, user VM reboot hang.

 The backtrace for this issue:
  #1 in mevent_qlock () at core/mevent.c:93
  #2 in mevent_delete_even at core/mevent.c:357
    ===>Recursively LOCK
  #3 in mevent_delete_close at core/mevent.c:387
  #4 in acrn_timer_deinit at core/timer.c:106
  #5 in virtio_reset_dev at hw/pci/virtio/virtio.c:171
  #6 in virtio_console_reset at
     hw/pci/virtio/virtio_console.c:196
  #7 in virtio_console_destroy at
    hw/pci/virtio/virtio_console.c:1015
  #8 in virtio_console_teardown_backend at
    hw/pci/virtio/virtio_console.c:1042
  #9 in mevent_drain_del_list () at
    core/mevent.c:348 ===> 1st LOCK
  #10 in mevent_dispatch () at core/mevent.c:472
  #11 in main at core/main.c:1110

  So the root cause is:
  mevent_mutex lock is recursively locked by mevent thread
  itself (#9 for this first lock and #2 for recursively lock),
  which is not allowed for mutex with default attribute.

  This patch changes the mutex type of 'mevent_lmutex'
  from default to "PTHREAD_MUTEX_RECURSIVE", because
  recrusively lock shall be allowed as user of mevent
  may call mevent functions (where mutex lock maybe required)
  in teardown callbacks.

Tracked-On: #7133
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2022-02-21 14:23:03 +08:00
Wen Qian a5a005f129 dm: add checks of ioctl return value for ACRN userspace
The current code does not always check the return value of function
ioctl called in ACRN userspace, and lack of error message printing
to help debug.

This code fixes it by checking the return value of ioctl, and adding
function errormsg to return a string describing of the error code.

Tracked-On: #7029
Signed-off-by: Wen Qian <qian.wen@intel.com>
Signed-off-by: Li Fei <fei1.li@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-02-21 09:25:50 +08:00
Xiangyang Wu cc2efdc049 DM: add DM parameter for command monitor
Libvirt or kata container needs to send some commands
(such as VM destory command) to the DM instance of User VM
through command monitor socket, they will specify the socket
path and pass this path name to DM instance through DM parameter.

In this patch, add new DM parameter (cmd_monitor) to get socket
path from libvirt or kata container. If cmd_monitor is specified,
it initialize and deinitialize command monitor in DM main loop.

v2-->v3:
	Include command monitor initialization and deinitialization.

Tracked-On: #5921

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-02-18 18:33:52 +08:00
Xiangyang Wu 02e94b1537 DM: add new monitor module
This monitor module is to initialize socket intance, register
handlers to handle command from socket message, close socket,
free socket instance:
init_cmd_monitor: initialize socket intance and register handlers
to handle command.
deinit_cmd_monitor: close socket and free socket instance.

In this patch DM makefile is updated to build command monitor.

v1--v2:
	Update socket path and update log message format.
	Parse JSON format command message using libcjson lib APIs.
v2-->v3:
	Use socket path length MACRO.
	Update JSON format command message to {"command": "xxx"}.

Tracked-On: #5921

Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2022-02-18 18:33:52 +08:00