Commit Graph

12 Commits

Author SHA1 Message Date
Mingqiang Chi 5375a1613b dm:use acrn-dm logger function instread of printf
Use acrn-dm logger function instread of printf,
this helps the stability testing log capture.

Tracked-On: #4098
Signed-off-by: Mingqiang Chi <mingqiang.chi@intel.com>
Reviewed-by: Cao Minggui <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
2019-11-14 15:34:04 +08:00
Yonghua Huang 885d503a60 dm: refine 'assert' in hugetlb.c and mem.c
cleanup 'assert' usage to avoid possible software vulnerabilities.

Tracked-On: #3252
Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
2019-06-20 08:55:44 +08:00
Tianhua Sun b0015963f5 dm: fix some potential memory leaks
This patch is to fix some potential memory leak issues

1, free mrp if the mmio_rb_lookup() function return 0;
2, free memory allocated by strdup in some error case handling.

Tracked-On: #3277
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2019-06-19 08:39:55 +08:00
Peter Fang 82fa9946e0 dm: safely access MMIO hint in MMIO emulation
mmio_hint in mem.c can potentially be accessed concurrently in
emulate_mem() because it only holds a read lock. Use a local variable to
make sure the same entry address is used throughout the function. Since
it only serves as a hint, it's okay if the function does not use the
most up-to-date version of mmio_hint, as long as mmio_hint is accessed
atomically.

Explicitly enforce natural alignment on mmio_hint to guarantee atomic
accesses on x86 and increase code portability, even though compilers
most likely always do it.

Entries in the RB tree are only removed in unregister_mem_int() while
holding a write lock, so accessing mmio_hint while holding a read lock
is safe.

Tracked-On: #2902
Signed-off-by: Peter Fang <peter.fang@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
2019-04-22 15:18:21 +08:00
Peter Fang 4c38ff00c6 dm: completely remove enable_bar()/disable_bar() functions
Following up on d648df766c, surgically
remove all the functions related to enable_bar()/disable_bar() that got
introduced in 8787b65fde.

Tracked-On: #2902
Signed-off-by: Peter Fang <peter.fang@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
2019-04-22 15:18:21 +08:00
Liu Shuo A fa7f6c2c83 dm: fix deadlock between emulate_mem and un/register_mem
There is a deadlock when emulate_mem is called on the memory region
of PCI extended configuration space. The call trace is something like:
    emulate_mem
 -> pci_emul_ecfg_handler
 -> pci_cfgrw
 -> pci_emul_cmdsts_write
 -> unregister_bar/register_bar
 -> modify_bar_registration
 -> unregister_mem/register_mem

mmio_rwlock is hold in emulate_mem when calling unregister_mem/
register_mem which is trying to acquire mmio_rwlock again, and deadlock
happened.

It is possible that bar address is changed just between a on-going
MMIO access which can bring a race condition in theroy. Guest needs to
take care of the serial operation between bar addess update and MMIO
access of that bar.

Tracked-On: #2962
Signed-off-by: Yu Wang <yu1.wang@intel.com>
Signed-off-by: Jian Jun Chen <jian.jun.chen@intel.com>
Signed-off-by: Liu Shuo A <shuo.a.liu@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2019-04-16 15:03:04 +08:00
Peter Fang 82e42cfa2a dm: clean up mem.c
- use strncmp() instead of comparing string pointers to make no
  assumptions about the toolchain's literal pool
- re-shuffle the functions so they're consistent with mem.h
- make non-public functions static
- increase code re-use

Tracked-On: #2792
Signed-off-by: Peter Fang <peter.fang@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Yin Fengwei <fengwei.yin@intel.com>
2019-03-21 10:28:17 +08:00
Peter Fang 4642269248 dm: vhpet: add vHPET support
vHPET is used as a source of system timer by UEFI (e.g. OVMF).

This provides an alternative to using vPIT, which OVMF assumes is always
connected to vPIC.

This is ported from Bhyve, with a few changes:

- move to user space, using acrn_timer
- enable timers only when necessary

Origin: FreeBSD
License: BSD-3-Clause
URL: https://svnweb.freebsd.org/
commit: 326257
Purpose: Adding vHPET support.
Maintained-by: External

Tracked-On: #2319
Signed-off-by: Peter Fang <peter.fang@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2019-01-23 10:33:28 +08:00
Yin Fengwei 8787b65fde dm: fix the issue when guest tries to disable memory range access
According to PCI spec 3.0 section 6.2.2 "Device Control", guest
could write the command register to control device response to
io/mem access.

The origial code register/unregister the memory range which is
not suitable because it can't handle the sequence:
  1. disble the device response to specific memory range
  2. reboot guest (DM will try to free the memory range which
     was freed in step 1 already)

Tracked-On: #1277
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-08 12:57:00 +08:00
Zide Chen df4ab92e81 DM: cleanup for header inclusions
used https://gitlab.com/esr/deheader to detect and remove unnecessary
header file inclusions

Signed-off-by: Zide Chen <zide.chen@intel.com>
2018-06-07 14:35:30 +08:00
Yin Fengwei 96085d960f DM: release mem range allocated in init_pci
Two memory ranges are allocated:
  - PCI ECFG
  - PCI hole
They should be released when deinit_pci. Old code mark
this two ranges not unregistered. Which is wrong for
warm reboot case. Make them could be unregistered.

Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-05-15 17:25:55 +08:00
Anthony Xu bd31b1c53e initial import
internal commit: 0ab1ea615e5cfbb0687a9d593a86a7b774386076

Signed-off-by: Anthony Xu <anthony.xu@intel.com>
2018-05-11 14:44:28 +08:00