Skip to content

Commit 933e217

Browse files
lifeixwenlingz
authored andcommitted
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>
1 parent 21b405d commit 933e217

File tree

3 files changed

+16
-38
lines changed

3 files changed

+16
-38
lines changed

devicemodel/core/main.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ usage(int code)
139139
" %*s [-s pci] [-U uuid] [--vsbl vsbl_file_name] [--ovmf ovmf_file_path]\n"
140140
" %*s [--part_info part_info_name] [--enable_trusty] [--intr_monitor param_setting]\n"
141141
" %*s [--vtpm2 sock_path] [--virtio_poll interval] [--mac_seed seed_string]\n"
142-
" %*s [--vmcfg sub_options] [--dump vm_idx] [--ptdev_no_reset] [--debugexit] \n"
142+
" %*s [--vmcfg sub_options] [--dump vm_idx] [--debugexit] \n"
143143
" %*s [--logger-setting param_setting] [--pm_notify_channel]\n"
144144
" %*s [--pm_by_vuart vuart_node] <vm>\n"
145145
" -A: create ACPI tables\n"
@@ -166,7 +166,6 @@ usage(int code)
166166
" --ovmf: ovmf file path\n"
167167
" --part_info: guest partition info file path\n"
168168
" --enable_trusty: enable trusty for guest\n"
169-
" --ptdev_no_reset: disable reset check for ptdev\n"
170169
" --debugexit: enable debug exit function\n"
171170
" --intr_monitor: enable interrupt storm monitor\n"
172171
" its params: threshold/s,probe-period(s),delay_time(ms),delay_duration(ms)\n"
@@ -722,7 +721,6 @@ enum {
722721
CMD_OPT_TRUSTY_ENABLE,
723722
CMD_OPT_VIRTIO_POLL_ENABLE,
724723
CMD_OPT_MAC_SEED,
725-
CMD_OPT_PTDEV_NO_RESET,
726724
CMD_OPT_DEBUGEXIT,
727725
CMD_OPT_VMCFG,
728726
CMD_OPT_DUMP,
@@ -763,8 +761,6 @@ static struct option long_options[] = {
763761
CMD_OPT_TRUSTY_ENABLE},
764762
{"virtio_poll", required_argument, 0, CMD_OPT_VIRTIO_POLL_ENABLE},
765763
{"mac_seed", required_argument, 0, CMD_OPT_MAC_SEED},
766-
{"ptdev_no_reset", no_argument, 0,
767-
CMD_OPT_PTDEV_NO_RESET},
768764
{"debugexit", no_argument, 0, CMD_OPT_DEBUGEXIT},
769765
{"intr_monitor", required_argument, 0, CMD_OPT_INTR_MONITOR},
770766
{"vtpm2", required_argument, 0, CMD_OPT_VTPM2},
@@ -899,9 +895,6 @@ main(int argc, char *argv[])
899895
mac_seed_str[sizeof(mac_seed_str) - 1] = '\0';
900896
mac_seed = mac_seed_str;
901897
break;
902-
case CMD_OPT_PTDEV_NO_RESET:
903-
ptdev_no_reset(true);
904-
break;
905898
case CMD_OPT_DEBUGEXIT:
906899
debugexit_enabled = true;
907900
break;

devicemodel/hw/pci/passthrough.c

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ extern uint64_t audio_nhlt_len;
7575
static int pciaccess_ref_cnt;
7676
static pthread_mutex_t ref_cnt_mtx = PTHREAD_MUTEX_INITIALIZER;
7777

78-
/* Not check reset capability before assign ptdev.
79-
* Set false by default, that is, always check.
80-
*/
81-
static bool no_reset = false;
82-
8378
struct mmio_map {
8479
uint64_t gpa;
8580
uint64_t hpa;
@@ -117,11 +112,6 @@ struct passthru_dev {
117112
struct mmio_map msix_bar_mmio[2];
118113
};
119114

120-
void ptdev_no_reset(bool enable)
121-
{
122-
no_reset = enable;
123-
}
124-
125115
static int
126116
msi_caplen(int msgctrl)
127117
{
@@ -671,22 +661,18 @@ cfginit(struct vmctx *ctx, struct passthru_dev *ptdev, int bus,
671661
* UOS reboot
672662
* - refuse to passthrough PCIe dev without any reset capability
673663
*/
674-
snprintf(reset_path, 40,
675-
"/sys/bus/pci/devices/0000:%02x:%02x.%x/reset",
676-
bus, slot, func);
677-
678-
fd = open(reset_path, O_WRONLY);
679-
if (fd >= 0) {
680-
if (ptdev->need_reset && write(fd, "1", 1) < 0)
681-
warnx("reset dev %x/%x/%x failed!\n",
682-
bus, slot, func);
683-
close(fd);
684-
} else if (errno == ENOENT && ptdev->pcie_cap) {
685-
warnx("No reset capability for PCIe %x/%x/%x, "
686-
"remove it from ptdev list!!\n",
687-
bus, slot, func);
688-
if (!no_reset)
689-
return -1;
664+
if (ptdev->need_reset) {
665+
snprintf(reset_path, 40,
666+
"/sys/bus/pci/devices/0000:%02x:%02x.%x/reset",
667+
bus, slot, func);
668+
669+
fd = open(reset_path, O_WRONLY);
670+
if (fd >= 0) {
671+
if (write(fd, "1", 1) < 0)
672+
warnx("reset dev %x/%x/%x failed!\n",
673+
bus, slot, func);
674+
close(fd);
675+
}
690676
}
691677

692678
if (cfginitbar(ctx, ptdev) != 0) {
@@ -767,7 +753,7 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
767753
struct pci_device *phys_dev;
768754
char *opt;
769755
bool keep_gsi = false;
770-
bool need_reset = false;
756+
bool need_reset = true;
771757

772758
ptdev = NULL;
773759
error = -EINVAL;
@@ -786,8 +772,8 @@ passthru_init(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
786772
while ((opt = strsep(&opts, ",")) != NULL) {
787773
if (!strncmp(opt, "keep_gsi", 8))
788774
keep_gsi = true;
789-
else if (!strncmp(opt, "reset", 5))
790-
need_reset = true;
775+
else if (!strncmp(opt, "no_reset", 8))
776+
need_reset = false;
791777
else
792778
warnx("Invalid passthru options:%s", opt);
793779
}

devicemodel/include/dm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ int vmexit_task_switch(struct vmctx *ctx, struct vhm_request *vhm_req,
6565
void *paddr_guest2host(struct vmctx *ctx, uintptr_t gaddr, size_t len);
6666
int virtio_uses_msix(void);
6767
size_t high_bios_size(void);
68-
void ptdev_no_reset(bool enable);
6968
void init_debugexit(void);
7069
void deinit_debugexit(void);
7170
#endif

0 commit comments

Comments
 (0)