dm: pci: reset passthrough device by default

Do reset for passthrough PCI device by default when assigning it to post-launched
VM:
1. modify opt "reset" to "no_reset" -- could enable no_reset for debug only
2. remove "ptdev_no_reset" opt. It could be replaced by setting "no_reset" for
each passthrough device.

Tracked-On: #3465
Signed-off-by: Li Fei1 <fei1.li@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
This commit is contained in:
Li Fei1 2019-12-25 21:29:04 +08:00 committed by wenlingz
parent 21b405d109
commit 933e2178d0
3 changed files with 15 additions and 37 deletions

View File

@ -139,7 +139,7 @@ usage(int code)
" %*s [-s pci] [-U uuid] [--vsbl vsbl_file_name] [--ovmf ovmf_file_path]\n"
" %*s [--part_info part_info_name] [--enable_trusty] [--intr_monitor param_setting]\n"
" %*s [--vtpm2 sock_path] [--virtio_poll interval] [--mac_seed seed_string]\n"
" %*s [--vmcfg sub_options] [--dump vm_idx] [--ptdev_no_reset] [--debugexit] \n"
" %*s [--vmcfg sub_options] [--dump vm_idx] [--debugexit] \n"
" %*s [--logger-setting param_setting] [--pm_notify_channel]\n"
" %*s [--pm_by_vuart vuart_node] <vm>\n"
" -A: create ACPI tables\n"
@ -166,7 +166,6 @@ usage(int code)
" --ovmf: ovmf file path\n"
" --part_info: guest partition info file path\n"
" --enable_trusty: enable trusty for guest\n"
" --ptdev_no_reset: disable reset check for ptdev\n"
" --debugexit: enable debug exit function\n"
" --intr_monitor: enable interrupt storm monitor\n"
" its params: threshold/s,probe-period(s),delay_time(ms),delay_duration(ms)\n"
@ -722,7 +721,6 @@ enum {
CMD_OPT_TRUSTY_ENABLE,
CMD_OPT_VIRTIO_POLL_ENABLE,
CMD_OPT_MAC_SEED,
CMD_OPT_PTDEV_NO_RESET,
CMD_OPT_DEBUGEXIT,
CMD_OPT_VMCFG,
CMD_OPT_DUMP,
@ -763,8 +761,6 @@ static struct option long_options[] = {
CMD_OPT_TRUSTY_ENABLE},
{"virtio_poll", required_argument, 0, CMD_OPT_VIRTIO_POLL_ENABLE},
{"mac_seed", required_argument, 0, CMD_OPT_MAC_SEED},
{"ptdev_no_reset", no_argument, 0,
CMD_OPT_PTDEV_NO_RESET},
{"debugexit", no_argument, 0, CMD_OPT_DEBUGEXIT},
{"intr_monitor", required_argument, 0, CMD_OPT_INTR_MONITOR},
{"vtpm2", required_argument, 0, CMD_OPT_VTPM2},
@ -899,9 +895,6 @@ main(int argc, char *argv[])
mac_seed_str[sizeof(mac_seed_str) - 1] = '\0';
mac_seed = mac_seed_str;
break;
case CMD_OPT_PTDEV_NO_RESET:
ptdev_no_reset(true);
break;
case CMD_OPT_DEBUGEXIT:
debugexit_enabled = true;
break;

View File

@ -75,11 +75,6 @@ extern uint64_t audio_nhlt_len;
static int pciaccess_ref_cnt;
static pthread_mutex_t ref_cnt_mtx = PTHREAD_MUTEX_INITIALIZER;
/* Not check reset capability before assign ptdev.
* Set false by default, that is, always check.
*/
static bool no_reset = false;
struct mmio_map {
uint64_t gpa;
uint64_t hpa;
@ -117,11 +112,6 @@ struct passthru_dev {
struct mmio_map msix_bar_mmio[2];
};
void ptdev_no_reset(bool enable)
{
no_reset = enable;
}
static int
msi_caplen(int msgctrl)
{
@ -671,22 +661,18 @@ cfginit(struct vmctx *ctx, struct passthru_dev *ptdev, int bus,
* UOS reboot
* - refuse to passthrough PCIe dev without any reset capability
*/
snprintf(reset_path, 40,
"/sys/bus/pci/devices/0000:%02x:%02x.%x/reset",
bus, slot, func);
if (ptdev->need_reset) {
snprintf(reset_path, 40,
"/sys/bus/pci/devices/0000:%02x:%02x.%x/reset",
bus, slot, func);
fd = open(reset_path, O_WRONLY);
if (fd >= 0) {
if (ptdev->need_reset && write(fd, "1", 1) < 0)
warnx("reset dev %x/%x/%x failed!\n",
bus, slot, func);
close(fd);
} else if (errno == ENOENT && ptdev->pcie_cap) {
warnx("No reset capability for PCIe %x/%x/%x, "
"remove it from ptdev list!!\n",
bus, slot, func);
if (!no_reset)
return -1;
fd = open(reset_path, O_WRONLY);
if (fd >= 0) {
if (write(fd, "1", 1) < 0)
warnx("reset dev %x/%x/%x failed!\n",
bus, slot, func);
close(fd);
}
}
if (cfginitbar(ctx, ptdev) != 0) {
@ -767,7 +753,7 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
struct pci_device *phys_dev;
char *opt;
bool keep_gsi = false;
bool need_reset = false;
bool need_reset = true;
ptdev = NULL;
error = -EINVAL;
@ -786,8 +772,8 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
while ((opt = strsep(&opts, ",")) != NULL) {
if (!strncmp(opt, "keep_gsi", 8))
keep_gsi = true;
else if (!strncmp(opt, "reset", 5))
need_reset = true;
else if (!strncmp(opt, "no_reset", 8))
need_reset = false;
else
warnx("Invalid passthru options:%s", opt);
}

View File

@ -65,7 +65,6 @@ int vmexit_task_switch(struct vmctx *ctx, struct vhm_request *vhm_req,
void *paddr_guest2host(struct vmctx *ctx, uintptr_t gaddr, size_t len);
int virtio_uses_msix(void);
size_t high_bios_size(void);
void ptdev_no_reset(bool enable);
void init_debugexit(void);
void deinit_debugexit(void);
#endif