aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2021-06-11 09:21:48 +0100
committerPeter Maydell <peter.maydell@linaro.org>2021-06-11 09:21:48 +0100
commit894fc4fd670aaf04a67dc7507739f914ff4bacf2 (patch)
tree10b23f57efbea25f91d2cdbb630e83ecd0bce5fb
parent7fe7fae8b48e3f9c647fd685e5155ebc8e6fb84d (diff)
parent5a2d9929ac1f01a1e8ef2a3f56f69e6069863dad (diff)
downloadqemu-894fc4fd670aaf04a67dc7507739f914ff4bacf2.zip
qemu-894fc4fd670aaf04a67dc7507739f914ff4bacf2.tar.gz
qemu-894fc4fd670aaf04a67dc7507739f914ff4bacf2.tar.bz2
Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging
# gpg: Signature made Fri 11 Jun 2021 03:54:51 BST # gpg: using RSA key EF04965B398D6211 # gpg: Good signature from "Jason Wang (Jason Wang on RedHat) <jasowang@redhat.com>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: 215D 46F4 8246 689E C77F 3562 EF04 965B 398D 6211 * remotes/jasowang/tags/net-pull-request: Fixed calculation error of pkt->header_size in fill_pkt_tcp_info() Add the function of colo_compare_cleanup Add a function named packet_new_nocopy for COLO. Remove migrate_set_block_enabled in checkpoint Optimize the function of filter_send Fix the qemu crash when guest shutdown during checkpoint Remove some duplicate trace code. netdev: add more commands to preconfig mode vhost-vdpa: remove the unused vhost_vdpa_get_acked_features() vhost-vdpa: don't initialize backend_features vhost-vdpa: map virtqueue notification area if possible vhost-vdpa: skip ram device from the IOTLB mapping Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
-rw-r--r--hmp-commands.hx2
-rw-r--r--hw/virtio/vhost-vdpa.c100
-rw-r--r--include/hw/virtio/vhost-vdpa.h6
-rw-r--r--include/net/vhost-vdpa.h1
-rw-r--r--migration/colo.c6
-rw-r--r--migration/migration.c4
-rw-r--r--net/colo-compare.c25
-rw-r--r--net/colo-compare.h1
-rw-r--r--net/colo.c25
-rw-r--r--net/colo.h1
-rw-r--r--net/filter-mirror.c8
-rw-r--r--net/filter-rewriter.c3
-rw-r--r--net/net.c4
-rw-r--r--net/vhost-vdpa.c9
-rw-r--r--qapi/net.json6
-rw-r--r--softmmu/runstate.c1
16 files changed, 143 insertions, 59 deletions
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 84dcc3a..8e45bce 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1269,6 +1269,7 @@ ERST
.help = "add host network device",
.cmd = hmp_netdev_add,
.command_completion = netdev_add_completion,
+ .flags = "p",
},
SRST
@@ -1283,6 +1284,7 @@ ERST
.help = "remove host network device",
.cmd = hmp_netdev_del,
.command_completion = netdev_del_completion,
+ .flags = "p",
},
SRST
diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c
index ee51863..61ba313 100644
--- a/hw/virtio/vhost-vdpa.c
+++ b/hw/virtio/vhost-vdpa.c
@@ -28,6 +28,8 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section)
{
return (!memory_region_is_ram(section->mr) &&
!memory_region_is_iommu(section->mr)) ||
+ /* vhost-vDPA doesn't allow MMIO to be mapped */
+ memory_region_is_ram_device(section->mr) ||
/*
* Sizing an enabled 64-bit BAR can cause spurious mappings to
* addresses in the upper part of the 64-bit address space. These
@@ -172,22 +174,12 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener,
vaddr, section->readonly);
if (ret) {
error_report("vhost vdpa map fail!");
- if (memory_region_is_ram_device(section->mr)) {
- /* Allow unexpected mappings not to be fatal for RAM devices */
- error_report("map ram fail!");
- return ;
- }
goto fail;
}
return;
fail:
- if (memory_region_is_ram_device(section->mr)) {
- error_report("failed to vdpa_dma_map. pci p2p may not work");
- return;
-
- }
/*
* On the initfn path, store the first error in the container so we
* can gracefully fail. Runtime, there's not much we can do other
@@ -276,15 +268,12 @@ static void vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)
static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
{
struct vhost_vdpa *v;
- uint64_t features;
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
trace_vhost_vdpa_init(dev, opaque);
v = opaque;
v->dev = dev;
dev->opaque = opaque ;
- vhost_vdpa_call(dev, VHOST_GET_FEATURES, &features);
- dev->backend_features = features;
v->listener = vhost_vdpa_memory_listener;
v->msg_type = VHOST_IOTLB_MSG_V2;
@@ -294,12 +283,95 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque)
return 0;
}
+static void vhost_vdpa_host_notifier_uninit(struct vhost_dev *dev,
+ int queue_index)
+{
+ size_t page_size = qemu_real_host_page_size;
+ struct vhost_vdpa *v = dev->opaque;
+ VirtIODevice *vdev = dev->vdev;
+ VhostVDPAHostNotifier *n;
+
+ n = &v->notifier[queue_index];
+
+ if (n->addr) {
+ virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, false);
+ object_unparent(OBJECT(&n->mr));
+ munmap(n->addr, page_size);
+ n->addr = NULL;
+ }
+}
+
+static void vhost_vdpa_host_notifiers_uninit(struct vhost_dev *dev, int n)
+{
+ int i;
+
+ for (i = 0; i < n; i++) {
+ vhost_vdpa_host_notifier_uninit(dev, i);
+ }
+}
+
+static int vhost_vdpa_host_notifier_init(struct vhost_dev *dev, int queue_index)
+{
+ size_t page_size = qemu_real_host_page_size;
+ struct vhost_vdpa *v = dev->opaque;
+ VirtIODevice *vdev = dev->vdev;
+ VhostVDPAHostNotifier *n;
+ int fd = v->device_fd;
+ void *addr;
+ char *name;
+
+ vhost_vdpa_host_notifier_uninit(dev, queue_index);
+
+ n = &v->notifier[queue_index];
+
+ addr = mmap(NULL, page_size, PROT_WRITE, MAP_SHARED, fd,
+ queue_index * page_size);
+ if (addr == MAP_FAILED) {
+ goto err;
+ }
+
+ name = g_strdup_printf("vhost-vdpa/host-notifier@%p mmaps[%d]",
+ v, queue_index);
+ memory_region_init_ram_device_ptr(&n->mr, OBJECT(vdev), name,
+ page_size, addr);
+ g_free(name);
+
+ if (virtio_queue_set_host_notifier_mr(vdev, queue_index, &n->mr, true)) {
+ munmap(addr, page_size);
+ goto err;
+ }
+ n->addr = addr;
+
+ return 0;
+
+err:
+ return -1;
+}
+
+static void vhost_vdpa_host_notifiers_init(struct vhost_dev *dev)
+{
+ int i;
+
+ for (i = dev->vq_index; i < dev->vq_index + dev->nvqs; i++) {
+ if (vhost_vdpa_host_notifier_init(dev, i)) {
+ goto err;
+ }
+ }
+
+ return;
+
+err:
+ vhost_vdpa_host_notifiers_uninit(dev, i);
+ return;
+}
+
static int vhost_vdpa_cleanup(struct vhost_dev *dev)
{
struct vhost_vdpa *v;
assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_VDPA);
v = dev->opaque;
trace_vhost_vdpa_cleanup(dev, v);
+ vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
memory_listener_unregister(&v->listener);
dev->opaque = NULL;
@@ -476,6 +548,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
if (started) {
uint8_t status = 0;
memory_listener_register(&v->listener, &address_space_memory);
+ vhost_vdpa_host_notifiers_init(dev);
vhost_vdpa_set_vring_ready(dev);
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK);
vhost_vdpa_call(dev, VHOST_VDPA_GET_STATUS, &status);
@@ -485,6 +558,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev, bool started)
vhost_vdpa_reset_device(dev);
vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE |
VIRTIO_CONFIG_S_DRIVER);
+ vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs);
memory_listener_unregister(&v->listener);
return 0;
diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h
index ae9ee7a..9188226 100644
--- a/include/hw/virtio/vhost-vdpa.h
+++ b/include/hw/virtio/vhost-vdpa.h
@@ -14,11 +14,17 @@
#include "hw/virtio/virtio.h"
+typedef struct VhostVDPAHostNotifier {
+ MemoryRegion mr;
+ void *addr;
+} VhostVDPAHostNotifier;
+
typedef struct vhost_vdpa {
int device_fd;
uint32_t msg_type;
MemoryListener listener;
struct vhost_dev *dev;
+ VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
} VhostVDPA;
#endif
diff --git a/include/net/vhost-vdpa.h b/include/net/vhost-vdpa.h
index 45e34b7..b81f9a6 100644
--- a/include/net/vhost-vdpa.h
+++ b/include/net/vhost-vdpa.h
@@ -15,7 +15,6 @@
#define TYPE_VHOST_VDPA "vhost-vdpa"
struct vhost_net *vhost_vdpa_get_vhost_net(NetClientState *nc);
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc);
extern const int vdpa_feature_bits[];
diff --git a/migration/colo.c b/migration/colo.c
index e498fdb..79fa1f6 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -435,12 +435,6 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
if (failover_get_state() != FAILOVER_STATUS_NONE) {
goto out;
}
-
- /* Disable block migration */
- migrate_set_block_enabled(false, &local_err);
- if (local_err) {
- goto out;
- }
qemu_mutex_lock_iothread();
#ifdef CONFIG_REPLICATION
diff --git a/migration/migration.c b/migration/migration.c
index 393299e..4828997 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -2217,6 +2217,10 @@ static bool migrate_prepare(MigrationState *s, bool blk, bool blk_inc,
}
if (blk || blk_inc) {
+ if (migrate_colo_enabled()) {
+ error_setg(errp, "No disk migration is required in COLO mode");
+ return false;
+ }
if (migrate_use_block() || migrate_use_block_incremental()) {
error_setg(errp, "Command options are incompatible with "
"current migration capabilities");
diff --git a/net/colo-compare.c b/net/colo-compare.c
index 9d1ad99..b100e7b 100644
--- a/net/colo-compare.c
+++ b/net/colo-compare.c
@@ -211,7 +211,7 @@ static void fill_pkt_tcp_info(void *data, uint32_t *max_ack)
pkt->tcp_ack = ntohl(tcphd->th_ack);
*max_ack = *max_ack > pkt->tcp_ack ? *max_ack : pkt->tcp_ack;
pkt->header_size = pkt->transport_header - (uint8_t *)pkt->data
- + (tcphd->th_off << 2) - pkt->vnet_hdr_len;
+ + (tcphd->th_off << 2);
pkt->payload_size = pkt->size - pkt->header_size;
pkt->seq_end = pkt->tcp_seq + pkt->payload_size;
pkt->flags = tcphd->th_flags;
@@ -590,19 +590,6 @@ static int colo_packet_compare_other(Packet *spkt, Packet *ppkt)
uint16_t offset = ppkt->vnet_hdr_len;
trace_colo_compare_main("compare other");
- if (trace_event_get_state_backends(TRACE_COLO_COMPARE_IP_INFO)) {
- char pri_ip_src[20], pri_ip_dst[20], sec_ip_src[20], sec_ip_dst[20];
-
- strcpy(pri_ip_src, inet_ntoa(ppkt->ip->ip_src));
- strcpy(pri_ip_dst, inet_ntoa(ppkt->ip->ip_dst));
- strcpy(sec_ip_src, inet_ntoa(spkt->ip->ip_src));
- strcpy(sec_ip_dst, inet_ntoa(spkt->ip->ip_dst));
-
- trace_colo_compare_ip_info(ppkt->size, pri_ip_src,
- pri_ip_dst, spkt->size,
- sec_ip_src, sec_ip_dst);
- }
-
if (ppkt->size != spkt->size) {
trace_colo_compare_main("Other: payload size of packets are different");
return -1;
@@ -1415,6 +1402,16 @@ static void colo_compare_init(Object *obj)
compare_set_vnet_hdr);
}
+void colo_compare_cleanup(void)
+{
+ CompareState *tmp = NULL;
+ CompareState *n = NULL;
+
+ QTAILQ_FOREACH_SAFE(tmp, &net_compares, next, n) {
+ object_unparent(OBJECT(tmp));
+ }
+}
+
static void colo_compare_finalize(Object *obj)
{
CompareState *s = COLO_COMPARE(obj);
diff --git a/net/colo-compare.h b/net/colo-compare.h
index 22ddd51..b055270 100644
--- a/net/colo-compare.h
+++ b/net/colo-compare.h
@@ -20,5 +20,6 @@
void colo_notify_compares_event(void *opaque, int event, Error **errp);
void colo_compare_register_notifier(Notifier *notify);
void colo_compare_unregister_notifier(Notifier *notify);
+void colo_compare_cleanup(void);
#endif /* QEMU_COLO_COMPARE_H */
diff --git a/net/colo.c b/net/colo.c
index ef00609..3a3e6e8 100644
--- a/net/colo.c
+++ b/net/colo.c
@@ -157,19 +157,28 @@ void connection_destroy(void *opaque)
Packet *packet_new(const void *data, int size, int vnet_hdr_len)
{
- Packet *pkt = g_slice_new(Packet);
+ Packet *pkt = g_slice_new0(Packet);
pkt->data = g_memdup(data, size);
pkt->size = size;
pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
pkt->vnet_hdr_len = vnet_hdr_len;
- pkt->tcp_seq = 0;
- pkt->tcp_ack = 0;
- pkt->seq_end = 0;
- pkt->header_size = 0;
- pkt->payload_size = 0;
- pkt->offset = 0;
- pkt->flags = 0;
+
+ return pkt;
+}
+
+/*
+ * packet_new_nocopy will not copy data, so the caller can't release
+ * the data. And it will be released in packet_destroy.
+ */
+Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len)
+{
+ Packet *pkt = g_slice_new0(Packet);
+
+ pkt->data = data;
+ pkt->size = size;
+ pkt->creation_ms = qemu_clock_get_ms(QEMU_CLOCK_HOST);
+ pkt->vnet_hdr_len = vnet_hdr_len;
return pkt;
}
diff --git a/net/colo.h b/net/colo.h
index 573ab91..d91cd24 100644
--- a/net/colo.h
+++ b/net/colo.h
@@ -101,6 +101,7 @@ bool connection_has_tracked(GHashTable *connection_track_table,
ConnectionKey *key);
void connection_hashtable_reset(GHashTable *connection_track_table);
Packet *packet_new(const void *data, int size, int vnet_hdr_len);
+Packet *packet_new_nocopy(void *data, int size, int vnet_hdr_len);
void packet_destroy(void *opaque, void *user_data);
void packet_destroy_partial(void *opaque, void *user_data);
diff --git a/net/filter-mirror.c b/net/filter-mirror.c
index f8e6500..f20240c 100644
--- a/net/filter-mirror.c
+++ b/net/filter-mirror.c
@@ -88,7 +88,7 @@ static int filter_send(MirrorState *s,
goto err;
}
- return 0;
+ return size;
err:
return ret < 0 ? ret : -EIO;
@@ -159,7 +159,7 @@ static ssize_t filter_mirror_receive_iov(NetFilterState *nf,
int ret;
ret = filter_send(s, iov, iovcnt);
- if (ret) {
+ if (ret < 0) {
error_report("filter mirror send failed(%s)", strerror(-ret));
}
@@ -182,10 +182,10 @@ static ssize_t filter_redirector_receive_iov(NetFilterState *nf,
if (qemu_chr_fe_backend_connected(&s->chr_out)) {
ret = filter_send(s, iov, iovcnt);
- if (ret) {
+ if (ret < 0) {
error_report("filter redirector send failed(%s)", strerror(-ret));
}
- return iov_size(iov, iovcnt);
+ return ret;
} else {
return 0;
}
diff --git a/net/filter-rewriter.c b/net/filter-rewriter.c
index 10fe393..cb3a96c 100644
--- a/net/filter-rewriter.c
+++ b/net/filter-rewriter.c
@@ -270,8 +270,7 @@ static ssize_t colo_rewriter_receive_iov(NetFilterState *nf,
vnet_hdr_len = nf->netdev->vnet_hdr_len;
}
- pkt = packet_new(buf, size, vnet_hdr_len);
- g_free(buf);
+ pkt = packet_new_nocopy(buf, size, vnet_hdr_len);
/*
* if we get tcp packet
diff --git a/net/net.c b/net/net.c
index 2a47260..76bbb7c 100644
--- a/net/net.c
+++ b/net/net.c
@@ -52,6 +52,7 @@
#include "qapi/error.h"
#include "qapi/opts-visitor.h"
#include "sysemu/runstate.h"
+#include "net/colo-compare.h"
#include "net/filter.h"
#include "qapi/string-output-visitor.h"
@@ -1402,6 +1403,9 @@ void net_cleanup(void)
{
NetClientState *nc;
+ /*cleanup colo compare module for COLO*/
+ colo_compare_cleanup();
+
/* We may del multiple entries during qemu_del_net_client(),
* so QTAILQ_FOREACH_SAFE() is also not safe here.
*/
diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c
index 8b14215..19187dc 100644
--- a/net/vhost-vdpa.c
+++ b/net/vhost-vdpa.c
@@ -68,15 +68,6 @@ VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc)
return s->vhost_net;
}
-uint64_t vhost_vdpa_get_acked_features(NetClientState *nc)
-{
- VhostVDPAState *s = DO_UPCAST(VhostVDPAState, nc, nc);
- assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_VDPA);
- s->acked_features = vhost_net_get_acked_features(s->vhost_net);
-
- return s->acked_features;
-}
-
static int vhost_vdpa_net_check_device_id(struct vhost_net *net)
{
uint32_t device_id;
diff --git a/qapi/net.json b/qapi/net.json
index af3f5b0..7fab2e7 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -55,7 +55,8 @@
# <- { "return": {} }
#
##
-{ 'command': 'netdev_add', 'data': 'Netdev', 'boxed': true }
+{ 'command': 'netdev_add', 'data': 'Netdev', 'boxed': true,
+ 'allow-preconfig': true }
##
# @netdev_del:
@@ -75,7 +76,8 @@
# <- { "return": {} }
#
##
-{ 'command': 'netdev_del', 'data': {'id': 'str'} }
+{ 'command': 'netdev_del', 'data': {'id': 'str'},
+ 'allow-preconfig': true }
##
# @NetLegacyNicOptions:
diff --git a/softmmu/runstate.c b/softmmu/runstate.c
index ce8977c..1564057 100644
--- a/softmmu/runstate.c
+++ b/softmmu/runstate.c
@@ -126,6 +126,7 @@ static const RunStateTransition runstate_transitions_def[] = {
{ RUN_STATE_RESTORE_VM, RUN_STATE_PRELAUNCH },
{ RUN_STATE_COLO, RUN_STATE_RUNNING },
+ { RUN_STATE_COLO, RUN_STATE_SHUTDOWN},
{ RUN_STATE_RUNNING, RUN_STATE_DEBUG },
{ RUN_STATE_RUNNING, RUN_STATE_INTERNAL_ERROR },