Commit Graph

927 Commits

Author SHA1 Message Date
Xiangyang Wu 3027bfab10 HV: treewide: enforce unsignedness of pcpu_id
In the hypervisor, physical cpu id is defined as "int" or "uint32_t"
type in the hypervisor. So there are some sign conversion issues
about  physical cpu id (pcpu_id) reported by static analysis tool.
Sign conversion violates the rules of MISRA C:2012.

In this patch, define physical cpu id as "uint16_t" type for all
modules in the hypervisor and change related codes. The valid
range of pcpu_id is 0~65534, INVALID_PCPU_ID is defined to the
invalid pcpu_id for error detection, BROADCAST_PCPU_ID is
broadcast pcpu_id used to notify all valid pcpu.

The type of pcpu_id in the struct vcpu and vcpu_id is "int" type,
this will be fixed in another patch.

V1-->V2:
    *  Change the type of pcpu_id from uint32_t to uint16_t;
    *  Define INVALID_PCPU_ID for error detection;
    *  Define BROADCAST_PCPU_ID to notify all valid pcpu.

V2-->V3:
    *  Update comments for INVALID_PCPU_ID and BROADCAST_PCPU_ID;
    *  Update addtional pcpu_id;
    *  Convert hexadecimals to unsigned to meet the type of pcpu_id;
    *  Clean up for MIN_PCPU_ID and MAX_PCPU_ID, they will be
       defined by configuration.
Note: fix bug in the init_lapic(), the pcpu_id shall be less than 8,
this is constraint by implement in the init_lapic().
Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-21 16:59:21 +08:00
Cai Yulong 2922a657c9 hv: fix compile error
function definition in header file must be signed as static inline type

Signed-off-by: Cai Yulong <yulongc@hwtc.com.cn>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-21 13:13:04 +08:00
Junjie Mao aa505a28bb HV: treewide: convert hexadecimals used in bitops to unsigned
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Junjie Mao cdd38d0bc3 HV: msr: convert hexadecimals used in bitops to unsigned
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Junjie Mao d705970eb2 HV: vmx: convert hexadecimals used in bitops to unsigned
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Junjie Mao 41a1035f9b HV: irq: convert hexadecimals used in bitops to unsigned
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Junjie Mao f4bd0798e0 HV: mmu: convert hexadecimals used in bitops to unsigned
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Junjie Mao 7b548e87db HV: cpu: convert hexadecimals used in bitops to unsigned
Per MISRA C, operands to bit-wise operations should have unsigned
types. However, C99 prioritizes to use signed integers for hexadecimal constants
without the 'U' suffixes, leading to tons of bit operations on signed integers.

This patch series add the 'U' suffixes to the constants which are used in bit
operations, and add the intended width of these integers when applicable
(i.e. the target value is at least 32-bit wide) to avoid functional differences
due to signed vs. unsigned extensions. The rule of thumb is:

    '0' for signed char/short/int
    '0U' for unsigned char/short/int
    '0L' for signed long (should be 64-bit)
    '0UL' for unsigned long (should be 64-bit)

Signed-off-by: Junjie Mao <junjie.mao@intel.com>
2018-06-21 13:12:39 +08:00
Sainath Grandhi 5aca8b1cdd When guest frees vector, counts needs to be reset. "int" command
from hv shell ends up incrementing per cpu irq_count.

Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
2018-06-21 11:29:53 +08:00
xiaojin2 cb39badf82 tools: acrn-crashlog: fix potential issues under common and usercrash
This patch is to fix buffer overflow, return value not unified and
variable type not matched issues. And add some judge logic to improve
code quality.

Changes:
1. Handle the fd properly in the failing case.
2. Fix buffer overflow issues and null pointer access issues.
3. Fix the format issue in log_sys.c.
4. Remove the useless branch and adjust the function logic.
5. Add some checks for the string length before using strcpy/strcat/memcpy.
6. Fix strncpy null-terminated issues.
7. Change the return value to unify the return type.

Signed-off-by: CHEN Gang <gang.c.chen@intel.com>
Signed-off-by: xiaojin2 <xiaojing.liu@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Reviewed-by: Liu Xinwu <xinwu.liu@intel.com>
Acked-by: Zhang Di <di.zhang@intel.com>
2018-06-21 11:29:20 +08:00
Yuan Liu 48067b1cab IOC mediator: Implement VM monitor operations
This patch implements VM monitor operations including stop/suspend/resume.
For other VM monitor operations(pause/unpause/query), IOC mediator would not
register callbacks for them since there is no requirements from VM Manager.

Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Reviewed-by: Yu Wang <yu1.wang@intel.com>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
2018-06-21 11:27:15 +08:00
Yonghua Huang 32fccb2f43 HV: 'vlapic_set_local_intr()' code cleanup
change the argument 'cpu_id' to 'vcpu_id'

Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2018-06-20 15:06:49 +08:00
Huihuang Shi 3ee1f8dfbf HV:x86:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Huihuang Shi cb56086239 HV:guest:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Huihuang Shi be0f5e6c16 HV:treewide:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Huihuang Shi f92931c879 HV:common:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Huihuang Shi 23921384d0 HV:debug:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Huihuang Shi fe0314e8c3 HV:header:fix "expression is not Boolean"
MISRA C explicit required expression should be boolean when
in branch statements (if,while...).

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 14:19:47 +08:00
Min He e3174bb50a script: add plane restriction parameters for NUC
This patch added GVT-g feature and support of plane restriction for APL
NUC platforms.

Signed-off-by: Min He <min.he@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Reviewed-by: Jiang, Fei <fei.jiang@intel.com>
2018-06-20 13:24:08 +08:00
Yan, Like 20b50ad4e8 HV: correct loglevel definitions and default values
1. remove duplicated definitions of mem_loglevel/console_loglevel;
2. Set default loglevels to display important messages:
 - CONSOLE_LOGLEVEL_DEFALUT is changed from 2 to 3;
 - MEM_LOGLEVEL_DEFAULT is changed from 4 to 5.

Acked-by: Eddie Dong <eddie.dong@intel.com>
Signed-off-by: Yan, Like <like.yan@intel.com>
2018-06-20 13:23:46 +08:00
Kaige Fu 6137ccd6d6 tools: acrn-crashlog: fix format-security warning
We will get the following warning when build acrn. This patch fix it.
No functional change.

In file included from log_sys.c:8:0:
log_sys.c: In function ‘do_log’:
log_sys.c:44:26: warning: format not a string literal and no format arguments [-Wformat-security]
  sd_journal_print(level, log);
                          ^

Signed-off-by: Kaige Fu <kaige.fu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-06-20 12:27:58 +08:00
Kaige Fu 1f8f1a4ecb HV: fix unused warning at RELEASE version
We will get following warnings when build acrn as release version. This patch
fix those warnings.

No functional change.

...
arch/x86/cpu.c: In function ‘stop_cpus’:
arch/x86/cpu.c:727:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (get_cpu_id() == i) /* avoid offline itself */
                    ^~
arch/x86/vtd.c: In function ‘dmar_enable_translation’:
arch/x86/vtd.c:84:12: warning: unused variable ‘start’ [-Wunused-variable]
   uint64_t start = rdtsc();                       \
...
arch/x86/guest/instr_emul.c: In function ‘get_gla’:
arch/x86/guest/instr_emul.c:615:6: warning: variable ‘error’ set but not used [-Wunused-but-set-variable]
  int error;
...

Signed-off-by: Kaige Fu <kaige.fu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 12:27:58 +08:00
Jason Chen CJ e84d4dee19 trusty: init & switch world fix
- when init, cr0 & cr4 should read from VMCS
- when world switch, cr0/cr4 read shadow should also be save/restore

v2:
- use context->vmx_cr0/cr4 to save/restore VMX_GUEST_CR0/CR4
- use context->cr0/cr4 to save/restore VMX_CR0/CR4_READ_SHADOW

Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-20 11:30:28 +08:00
Jason Chen CJ 75c1573aff ept: set trusty eptp to 0 after destroy and only invalidate it when exist
set trusty eptp to 0 after destroy, and only invalidate trusty eptp when it
exist.

Signed-off-by: Jason Chen CJ <jason.cj.chen@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Xu, Anthony <anthony.xu@intel.com>
2018-06-20 11:30:28 +08:00
Xinyun Liu fb723efa48 dm: check pci_vdev before using
acrn-dm runs to segmentation fault when failed to create VMs with
improper parameters.

If vdevs failed to be created, they are still be freed in deinit(),
and dereference the null pointers leads to segfault.

Signed-off-by: Xinyun Liu <xinyun.liu@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
2018-06-20 11:29:21 +08:00
David B. Kinder 685d82cdcc doc: fix formatting in acrnlog doc
A merged change had problems with the formatting of acrnlog options.

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-06-20 11:28:36 +08:00
xiaojin2 3e8e607d5b tools: acrn-crashlog: Fix potential issues under acrnprobe
This patch is to fix potential issues, which are reported by static
analysis tool, for acrnprobe.

Changes:
1. Check the return value of sender_id() and get_sender_by_name(),
   since it could be -1 or NULL.
2. Remove the parameter len from create_event, take parameter path
   as a NULL-terminated string as default.
3. Modify for_each_* functions to avoid overflow.

Signed-off-by: Liu Xinwu <xinwu.liu@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Acked-by: Chen Gang <gang.c.chen@intel.com>
2018-06-20 11:27:55 +08:00
xiaojin2 0c39b9cddc tools: acrn-crashlog: Fix potential issues for load_conf module of acrnprobe
This patch is to fix potential issues, which are reported by static
analysis tool, for load_conf module of acrnprobe.

Changes:
1. Check the range of id while loading configuration, to avoid
   memory corruption.
2. Use strncpy instead of strcpy to avoid buf overflow.

Signed-off-by: Liu Xinwu <xinwu.liu@intel.com>
Reviewed-by: Zhi Jin <zhi.jin@intel.com>
Acked-by: Chen Gang <gang.c.chen@intel.com>
2018-06-20 11:27:55 +08:00
Tan Shen Joon b3ca8f43ff add acrnbridge-install to Makefile install target
This was missed out. Added
to fix the makefile install target.

Signed-off-by: Tan Shen Joon <shen.joon.tan@intel.com>
2018-06-20 11:27:24 +08:00
Liu, Xinwu fa5229052c tools: acrn-crashlog: Improve the efficiency of do_log
Get the header size by receiving return value of snprintf instead
of initialize log buffer and strlen.

Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com>
Reviewed-by: Eddie Dong <eddie.dong@intel.com>
Acked-by: Chen Gang <gang.c.chen@intel.com>
2018-06-20 11:26:24 +08:00
Li, Fei1 c52afb1452 hv: fix error use of list_del for delete timer
We should use list_del_init here. Otherwise it would misorder the
timer list if we would delete timer more than once if there're more
than one timer on it.

Change-Id: I2d18248173ced1ea1b723352327d2c3d0efc4900
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
2018-06-20 11:25:44 +08:00
zhouji3x ad2d855302 hv: save registers on exception
This patch is for crashmode/ramdump. when exception occur:
1) save registers;
2) flush cache

Signed-off-by: zhouji3x <jianfengx.zhou@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-19 17:30:24 +08:00
Huihuang Shi 977c4b20b5 fix parted of "missing for discarded return value"
MISRA C required that return value should be used, missing for it should
add "(void)" prefix before the function call.
Some function can be declared without return value to avoid this problem.

Signed-off-by: Huihuang Shi <huihuang.shi@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-19 16:21:45 +08:00
Yan, Like b8bdf171eb tools: acrnlog: improve for log incompleteness problem
1. add warning when log incompleteness observed;
2. decrease default polling interval to reduce chance of log incompleteness;
3. add option "-t" to allow user to specify the polling interval;
4. modified README.rst to reflect the options.

Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Signed-off-by: Yan, Like <like.yan@intel.com>
2018-06-19 16:20:31 +08:00
Yan, Like 57d6a933f6 tools: correct several Makefile problems
1. mkdir ./tools/build if it does not exist;
2. correct static lib path for acrn-manager;
3. do not remove acrnlog.service if build under source code dir by default.

Reviewed-by: Geoffroy VanCutsem <geoffroy.vancutsem@intel.com>
Signed-off-by: Yan, Like <like.yan@intel.com>
2018-06-19 15:33:31 +08:00
zhouji3x 0f842cd38d DM samples: trigger warm reboot on panic
this patch add "reboot_panic=p,w" to command line of SOS to trigger
warm reboot on panic

Signed-off-by: zhouji3x <jianfengx.zhou@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-19 15:32:38 +08:00
zhouji3x 5f5c16dc15 hv: add shell command to trigger crash
this patch add shell command trigger crash for testing crashmode/ramdump

Signed-off-by: zhouji3x <jianfengx.zhou@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-19 15:32:04 +08:00
Chris Ye 59f1f005aa bugfix: make remove_intx_remapping static
remove_intx_remapping is not global function, make static.

Unlike global functions in C, access to static functions is restricted to the file where they are declared. Another reason for making functions static can be reuse of the same function name in other files

Signed-off-by: Chris Ye <chris.ye@intel.com>
2018-06-19 12:05:24 +08:00
Sainath Grandhi 417d17e031 udelay waits for corresponding number of milliseconds passed to API.
Changed the CYCLES_PER_MS to US_TO_TICKS

Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com>
2018-06-19 11:12:19 +08:00
Huang Yang 18c355f663 DM: Fix build failure with Openssl 1.1+
Some APIs of Openssl 1.0 are deprecated in Openssl 1.1+.
Two different API implementations are adaptable to both
Openssl 1.1- and 1.1+.

Fixes: #305

Signed-off-by: Huang Yang <yang.huang@intel.com>
Signed-off-by: Du Min <minx.du@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-19 10:35:47 +08:00
David B. Kinder 287fc4cb7f doc: add hypervisor kconfig option reference
Modify the Zephyr project script for creating documentation from Kconfig
files to generate the hypervisor option configuration docs. While Zephyr
uses a modified version of kconfiglib, we can use the standard
kconfiglib from Pypi (added to the requirements.txt file).

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-06-15 15:20:43 -07:00
David B. Kinder 37f33fd389 doc: update doc building tools versions
The latest versions of Sphinx and Breathe work well together so we're
updating the requirements.txt installation information (and
documentation) to use the latest versions of these tools.

Fixes: #395
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2018-06-15 11:58:58 -07:00
Victor Sun 5754d367ce HV: remove redundant code in cpu_secondary_init
cpu_find_logical_id() is called redundantly, remove one.

Signed-off-by: Victor Sun <victor.sun@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-15 17:13:12 +08:00
Minggui Cao a0b8da77fd handle failure when add/create vcpu for a VM in DM
when add/create vcpu failed, before it just exits,
and the resource will not released; now if failed,
let DM release the resource.

Signed-off-by: Minggui Cao <minggui.cao@intel.com>
Reviewed-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-15 17:12:29 +08:00
Yonghua Huang 098c2e6788 HV: enable SMEP in hypervisor
- this patch is to enable SMEP in hypervisor, SMEP protects
   guests' memory from supervisor-mode instruction fetches,
   in other words, hypervisor which operating in supervisor
   mode can't fetch instructions from (guests' memory)
   linear addresses that are accessible in user mode.

Signed-off-by: Yonghua Huang <yonghua.huang@intel.com>
2018-06-15 17:11:03 +08:00
Fei Jiang b2b49a64a9 Revert "VMX: change PAT register default value"
This reverts commit 3a3aeac09f.
MTRR has been emulated in hypervisor, then don't need this workaround
patch.

Signed-off-by: Fei Jiang <fei.jiang@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
2018-06-15 17:10:51 +08:00
Edwin Zhai 8202ba0a70 HV: move common stuff from assign.c
Move common stuff, like ptdev entry and softirq, to new ptdev.c

Signed-off-by: Edwin Zhai <edwin.zhai@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
2018-06-15 17:10:41 +08:00
Li, Fei1 46f64b55b4 hv: vlapic_timer: add vlapic one-shot/periodic timer support
Enable guest LAPIC one-shot/periodic timer support.

Change-Id: I368e28beaa81d6566de2626bbe26c9f8972f0891
Signed-off-by: Li, Fei1 <fei1.li@intel.com>
2018-06-15 17:10:28 +08:00
Fei Jiang 47116e8c4b DM sample: force enabling HDMI1 and HDMI2 connectors
When initial_modeset is enabled, will check EDID in early stage,
while sometime didn't get EDID in time through I2C, and will cause
CRTC not used correctly in some corner cases. Then we need force
enabling two HDMI connectors to attach CRTC in initial modeset stage.

Signed-off-by: Fei Jiang <fei.jiang@intel.com>
Reviewed-by: Zhao, Yakui <yakui.zhao@intel.com>
Reviewed-by: Min He <min.he@intel.com>
2018-06-15 17:10:16 +08:00
Junjie Mao 3d0c6cbc00 doc: add steps for modifying configs and generating defconfigs
This patch adds two sections which describe how configurations can be modified
and how minimized configurations can be generated.

Also switch prerequisite python version from 2 to 3 since menuconfig.py is
python3 only.

v1 -> v2:

    * Add the link to EPEL.
    * Rename minimalconfig to savedefconfig in the guide.
    * Split the step using a defconfig from those generating a defconfig.

Signed-off-by: Junjie Mao <junjie.mao@intel.com>
Acked-by: Anthony Xu <anthony.xu@intel.com>
Acked-by: Geoffroy VanCutsem <geoffroy.vancutsem@intel.com>
2018-06-15 15:50:09 +08:00