1
The following changes since commit 9db6ffc76676731a25a5538ab71e8ca6ac234f80:
1
The following changes since commit 23895cbd82be95428e90168b12e925d0d3ca2f06:
2
2
3
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging (2017-08-11 15:11:50 +0100)
3
Merge remote-tracking branch 'remotes/awilliam/tags/vfio-update-20201123.0' into staging (2020-11-23 18:51:13 +0000)
4
4
5
are available in the git repository at:
5
are available in the git repository at:
6
6
7
https://github.com/jasowang/qemu.git tags/net-pull-request
7
https://github.com/jasowang/qemu.git tags/net-pull-request
8
8
9
for you to fetch changes up to 131f6055f1f0eba4cd2e862a8ff907dbde4d94d1:
9
for you to fetch changes up to 9925990d01a92564af55f6f69d0f5f59b47609b1:
10
10
11
qemu-doc: Mention host_net_add/-remove in the deprecation chapter (2017-08-14 10:56:47 +0800)
11
net: Use correct default-path macro for downscript (2020-11-24 10:40:17 +0800)
12
12
13
----------------------------------------------------------------
13
----------------------------------------------------------------
14
14
15
----------------------------------------------------------------
15
----------------------------------------------------------------
16
Mao Zhongyi (4):
16
Keqian Zhu (1):
17
net/rocker: Remove the dead error handling
17
net: Use correct default-path macro for downscript
18
net/rocker: Plug memory leak in pci_rocker_init()
19
net/rocker: Convert to realize()
20
net/rocker: Fix the unusual macro name
21
18
22
Thomas Huth (1):
19
Paolo Bonzini (1):
23
qemu-doc: Mention host_net_add/-remove in the deprecation chapter
20
net: do not exit on "netdev_add help" monitor command
24
21
25
hw/net/rocker/rocker.c | 94 +++++++++++--------------------------------
22
Prasad J Pandit (1):
26
hw/net/rocker/rocker_desc.c | 10 -----
23
hw/net/e1000e: advance desc_offset in case of null descriptor
27
hw/net/rocker/rocker_fp.c | 4 --
24
28
hw/net/rocker/rocker_of_dpa.c | 20 ---------
25
Yuri Benditovich (1):
29
hw/net/rocker/rocker_world.c | 12 +++---
26
net: purge queued rx packets on queue deletion
30
qemu-doc.texi | 8 ++++
27
31
6 files changed, 36 insertions(+), 112 deletions(-)
28
yuanjungong (1):
29
tap: fix a memory leak
30
31
hw/net/e1000e_core.c | 8 +++---
32
include/net/net.h | 1 +
33
monitor/hmp-cmds.c | 6 ++++
34
net/net.c | 80 +++++++++++++++++++++++++++-------------------------
35
net/tap.c | 5 +++-
36
5 files changed, 57 insertions(+), 43 deletions(-)
32
37
33
38
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Prasad J Pandit <pjp@fedoraproject.org>
2
2
3
The two HMP commands host_net_add and -remove have recently been
3
While receiving packets via e1000e_write_packet_to_guest() routine,
4
marked as deprecated, too, so we should now mention them in the
4
'desc_offset' is advanced only when RX descriptor is processed. And
5
chapter of deprecated features.
5
RX descriptor is not processed if it has NULL buffer address.
6
This may lead to an infinite loop condition. Increament 'desc_offset'
7
to process next descriptor in the ring to avoid infinite loop.
6
8
7
Signed-off-by: Thomas Huth <thuth@redhat.com>
9
Reported-by: Cheol-woo Myung <330cjfdn@gmail.com>
10
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
8
Signed-off-by: Jason Wang <jasowang@redhat.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
---
12
---
10
qemu-doc.texi | 8 ++++++++
13
hw/net/e1000e_core.c | 8 ++++----
11
1 file changed, 8 insertions(+)
14
1 file changed, 4 insertions(+), 4 deletions(-)
12
15
13
diff --git a/qemu-doc.texi b/qemu-doc.texi
16
diff --git a/hw/net/e1000e_core.c b/hw/net/e1000e_core.c
14
index XXXXXXX..XXXXXXX 100644
17
index XXXXXXX..XXXXXXX 100644
15
--- a/qemu-doc.texi
18
--- a/hw/net/e1000e_core.c
16
+++ b/qemu-doc.texi
19
+++ b/hw/net/e1000e_core.c
17
@@ -XXX,XX +XXX,XX @@ by the ``convert -l snapshot_param'' argument instead.
20
@@ -XXX,XX +XXX,XX @@ e1000e_write_packet_to_guest(E1000ECore *core, struct NetRxPkt *pkt,
18
21
(const char *) &fcs_pad, e1000x_fcs_len(core->mac));
19
@section System emulator human monitor commands
22
}
20
23
}
21
+@subsection host_net_add (since 2.10.0)
24
- desc_offset += desc_size;
22
+
25
- if (desc_offset >= total_size) {
23
+The ``host_net_add'' command is replaced by the ``netdev_add'' command.
26
- is_last = true;
24
+
27
- }
25
+@subsection host_net_remove (since 2.10.0)
28
} else { /* as per intel docs; skip descriptors with null buf addr */
26
+
29
trace_e1000e_rx_null_descriptor();
27
+The ``host_net_remove'' command is replaced by the ``host_net_remove'' command.
30
}
28
+
31
+ desc_offset += desc_size;
29
@subsection usb_add (since 2.10.0)
32
+ if (desc_offset >= total_size) {
30
33
+ is_last = true;
31
The ``usb_add'' command is replaced by the ``device_add'' command.
34
+ }
35
36
e1000e_write_rx_descr(core, desc, is_last ? core->rx_pkt : NULL,
37
rss_info, do_ps ? ps_hdr_len : 0, &bastate.written);
32
--
38
--
33
2.7.4
39
2.7.4
34
40
35
41
diff view generated by jsdifflib
1
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
1
From: Paolo Bonzini <pbonzini@redhat.com>
2
2
3
The rocker device still implements the old PCIDeviceClass .init()
3
"netdev_add help" is causing QEMU to exit because the code that
4
instead of the new .realize(). All devices need to be converted to
4
invokes show_netdevs is shared between CLI and HMP processing.
5
.realize().
5
Move the check to the callers so that exit(0) remains only
6
in the CLI flow.
6
7
7
.init() reports errors with fprintf() and return 0 on success, negative
8
"netdev_add help" is not fixed by this patch; that is left for
8
number on failure. Meanwhile, when -device rocker fails, it first report
9
later work.
9
a specific error, then a generic one, like this:
10
10
11
$ x86_64-softmmu/qemu-system-x86_64 -device rocker,name=qemu-rocker
11
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12
rocker: name too long; please shorten to at most 9 chars
13
qemu-system-x86_64: -device rocker,name=qemu-rocker: Device initialization failed
14
15
Now, convert it to .realize() that passes errors to its callers via its
16
errp argument. Also avoid the superfluous second error message. After
17
the patch, effect like this:
18
19
$ x86_64-softmmu/qemu-system-x86_64 -device rocker,name=qemu-rocker
20
qemu-system-x86_64: -device rocker,name=qemu-rocker: name too long; please shorten to at most 9 chars
21
22
Cc: jasowang@redhat.com
23
Cc: jiri@resnulli.us
24
Cc: armbru@redhat.com
25
Cc: f4bug@amsat.org
26
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
27
Reviewed-by: Markus Armbruster <armbru@redhat.com>
28
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
29
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
Signed-off-by: Jason Wang <jasowang@redhat.com>
30
---
13
---
31
hw/net/rocker/rocker.c | 27 +++++++++++----------------
14
include/net/net.h | 1 +
32
1 file changed, 11 insertions(+), 16 deletions(-)
15
monitor/hmp-cmds.c | 6 +++++
16
net/net.c | 68 +++++++++++++++++++++++++++---------------------------
17
3 files changed, 41 insertions(+), 34 deletions(-)
33
18
34
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
19
diff --git a/include/net/net.h b/include/net/net.h
35
index XXXXXXX..XXXXXXX 100644
20
index XXXXXXX..XXXXXXX 100644
36
--- a/hw/net/rocker/rocker.c
21
--- a/include/net/net.h
37
+++ b/hw/net/rocker/rocker.c
22
+++ b/include/net/net.h
38
@@ -XXX,XX +XXX,XX @@ rollback:
23
@@ -XXX,XX +XXX,XX @@ extern const char *host_net_devices[];
39
return err;
24
25
/* from net.c */
26
int net_client_parse(QemuOptsList *opts_list, const char *str);
27
+void show_netdevs(void);
28
int net_init_clients(Error **errp);
29
void net_check_clients(void);
30
void net_cleanup(void);
31
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/monitor/hmp-cmds.c
34
+++ b/monitor/hmp-cmds.c
35
@@ -XXX,XX +XXX,XX @@
36
#include "qemu/option.h"
37
#include "qemu/timer.h"
38
#include "qemu/sockets.h"
39
+#include "qemu/help_option.h"
40
#include "monitor/monitor-internal.h"
41
#include "qapi/error.h"
42
#include "qapi/clone-visitor.h"
43
@@ -XXX,XX +XXX,XX @@ void hmp_netdev_add(Monitor *mon, const QDict *qdict)
44
{
45
Error *err = NULL;
46
QemuOpts *opts;
47
+ const char *type = qdict_get_try_str(qdict, "type");
48
49
+ if (type && is_help_option(type)) {
50
+ show_netdevs();
51
+ return;
52
+ }
53
opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict, &err);
54
if (err) {
55
goto out;
56
diff --git a/net/net.c b/net/net.c
57
index XXXXXXX..XXXXXXX 100644
58
--- a/net/net.c
59
+++ b/net/net.c
60
@@ -XXX,XX +XXX,XX @@
61
#include "qemu/config-file.h"
62
#include "qemu/ctype.h"
63
#include "qemu/iov.h"
64
+#include "qemu/qemu-print.h"
65
#include "qemu/main-loop.h"
66
#include "qemu/option.h"
67
#include "qapi/error.h"
68
@@ -XXX,XX +XXX,XX @@ static int net_client_init1(const Netdev *netdev, bool is_netdev, Error **errp)
69
return 0;
40
}
70
}
41
71
42
-static int rocker_msix_init(Rocker *r)
72
-static void show_netdevs(void)
43
+static int rocker_msix_init(Rocker *r, Error **errp)
73
+void show_netdevs(void)
44
{
74
{
45
PCIDevice *dev = PCI_DEVICE(r);
75
int idx;
46
int err;
76
const char *available_netdevs[] = {
47
- Error *local_err = NULL;
77
@@ -XXX,XX +XXX,XX @@ static void show_netdevs(void)
48
78
#endif
49
err = msix_init(dev, ROCKER_MSIX_VEC_COUNT(r->fp_ports),
79
};
50
&r->msix_bar,
80
51
ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_TABLE_OFFSET,
81
- printf("Available netdev backend types:\n");
52
&r->msix_bar,
82
+ qemu_printf("Available netdev backend types:\n");
53
ROCKER_PCI_MSIX_BAR_IDX, ROCKER_PCI_MSIX_PBA_OFFSET,
83
for (idx = 0; idx < ARRAY_SIZE(available_netdevs); idx++) {
54
- 0, &local_err);
84
- puts(available_netdevs[idx]);
55
+ 0, errp);
85
+ qemu_printf("%s\n", available_netdevs[idx]);
56
if (err) {
57
- error_report_err(local_err);
58
return err;
59
}
86
}
60
61
@@ -XXX,XX +XXX,XX @@ static World *rocker_world_type_by_name(Rocker *r, const char *name)
62
return NULL;
63
}
87
}
64
88
65
-static int pci_rocker_init(PCIDevice *dev)
89
@@ -XXX,XX +XXX,XX @@ static int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp)
66
+static void pci_rocker_realize(PCIDevice *dev, Error **errp)
90
int ret = -1;
91
Visitor *v = opts_visitor_new(opts);
92
93
- const char *type = qemu_opt_get(opts, "type");
94
-
95
- if (is_netdev && type && is_help_option(type)) {
96
- show_netdevs();
97
- exit(0);
98
- } else {
99
- /* Parse convenience option format ip6-net=fec0::0[/64] */
100
- const char *ip6_net = qemu_opt_get(opts, "ipv6-net");
101
+ /* Parse convenience option format ip6-net=fec0::0[/64] */
102
+ const char *ip6_net = qemu_opt_get(opts, "ipv6-net");
103
104
- if (ip6_net) {
105
- char *prefix_addr;
106
- unsigned long prefix_len = 64; /* Default 64bit prefix length. */
107
+ if (ip6_net) {
108
+ char *prefix_addr;
109
+ unsigned long prefix_len = 64; /* Default 64bit prefix length. */
110
111
- substrings = g_strsplit(ip6_net, "/", 2);
112
- if (!substrings || !substrings[0]) {
113
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "ipv6-net",
114
- "a valid IPv6 prefix");
115
- goto out;
116
- }
117
+ substrings = g_strsplit(ip6_net, "/", 2);
118
+ if (!substrings || !substrings[0]) {
119
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "ipv6-net",
120
+ "a valid IPv6 prefix");
121
+ goto out;
122
+ }
123
124
- prefix_addr = substrings[0];
125
+ prefix_addr = substrings[0];
126
127
- /* Handle user-specified prefix length. */
128
- if (substrings[1] &&
129
- qemu_strtoul(substrings[1], NULL, 10, &prefix_len))
130
- {
131
- error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
132
- "ipv6-prefixlen", "a number");
133
- goto out;
134
- }
135
-
136
- qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort);
137
- qemu_opt_set_number(opts, "ipv6-prefixlen", prefix_len,
138
- &error_abort);
139
- qemu_opt_unset(opts, "ipv6-net");
140
+ /* Handle user-specified prefix length. */
141
+ if (substrings[1] &&
142
+ qemu_strtoul(substrings[1], NULL, 10, &prefix_len))
143
+ {
144
+ error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
145
+ "ipv6-prefixlen", "a number");
146
+ goto out;
147
}
148
+
149
+ qemu_opt_set(opts, "ipv6-prefix", prefix_addr, &error_abort);
150
+ qemu_opt_set_number(opts, "ipv6-prefixlen", prefix_len,
151
+ &error_abort);
152
+ qemu_opt_unset(opts, "ipv6-net");
153
}
154
155
/* Create an ID for -net if the user did not specify one */
156
@@ -XXX,XX +XXX,XX @@ static int net_init_client(void *dummy, QemuOpts *opts, Error **errp)
157
158
static int net_init_netdev(void *dummy, QemuOpts *opts, Error **errp)
67
{
159
{
68
Rocker *r = to_rocker(dev);
160
+ const char *type = qemu_opt_get(opts, "type");
69
const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
161
+
70
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
162
+ if (type && is_help_option(type)) {
71
163
+ show_netdevs();
72
r->world_dflt = rocker_world_type_by_name(r, r->world_name);
164
+ exit(0);
73
if (!r->world_dflt) {
165
+ }
74
- fprintf(stderr,
166
return net_client_init(opts, true, errp);
75
- "rocker: requested world \"%s\" does not exist\n",
76
+ error_setg(errp,
77
+ "invalid argument requested world %s does not exist",
78
r->world_name);
79
- err = -EINVAL;
80
goto err_world_type_by_name;
81
}
82
83
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
84
85
/* MSI-X init */
86
87
- err = rocker_msix_init(r);
88
+ err = rocker_msix_init(r, errp);
89
if (err) {
90
goto err_msix_init;
91
}
92
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
93
}
94
95
if (rocker_find(r->name)) {
96
- err = -EEXIST;
97
+ error_setg(errp, "%s already exists", r->name);
98
goto err_duplicate;
99
}
100
101
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
102
#define ROCKER_IFNAMSIZ 16
103
#define MAX_ROCKER_NAME_LEN (ROCKER_IFNAMSIZ - 1 - 3 - 3)
104
if (strlen(r->name) > MAX_ROCKER_NAME_LEN) {
105
- fprintf(stderr,
106
- "rocker: name too long; please shorten to at most %d chars\n",
107
+ error_setg(errp,
108
+ "name too long; please shorten to at most %d chars",
109
MAX_ROCKER_NAME_LEN);
110
- err = -EINVAL;
111
goto err_name_too_long;
112
}
113
114
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
115
116
QLIST_INSERT_HEAD(&rockers, r, next);
117
118
- return 0;
119
+ return;
120
121
err_name_too_long:
122
err_duplicate:
123
@@ -XXX,XX +XXX,XX @@ err_world_type_by_name:
124
world_free(r->worlds[i]);
125
}
126
}
127
- return err;
128
}
167
}
129
168
130
static void pci_rocker_uninit(PCIDevice *dev)
131
@@ -XXX,XX +XXX,XX @@ static void rocker_class_init(ObjectClass *klass, void *data)
132
DeviceClass *dc = DEVICE_CLASS(klass);
133
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
134
135
- k->init = pci_rocker_init;
136
+ k->realize = pci_rocker_realize;
137
k->exit = pci_rocker_uninit;
138
k->vendor_id = PCI_VENDOR_ID_REDHAT;
139
k->device_id = PCI_DEVICE_ID_REDHAT_ROCKER;
140
--
169
--
141
2.7.4
170
2.7.4
142
171
143
172
diff view generated by jsdifflib
1
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
1
From: Yuri Benditovich <yuri.benditovich@daynix.com>
2
2
3
Cc: jasowang@redhat.com
3
https://bugzilla.redhat.com/show_bug.cgi?id=1829272
4
Cc: jiri@resnulli.us
4
When deleting queue pair, purge pending RX packets if any.
5
Cc: armbru@redhat.com
5
Example of problematic flow:
6
Cc: f4bug@amsat.org
6
1. Bring up q35 VM with tap (vhost off) and virtio-net or e1000e
7
Suggested-by: Markus Armbruster <armbru@redhat.com>
7
2. Run ping flood to the VM NIC ( 1 ms interval)
8
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
8
3. Hot unplug the NIC device (device_del)
9
Reviewed-by: Markus Armbruster <armbru@redhat.com>
9
During unplug process one or more packets come, the NIC
10
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
can't receive, tap disables read_poll
11
4. Hot plug the device (device_add) with the same netdev
12
The tap stays with read_poll disabled and does not receive
13
any packets anymore (tap_send never triggered)
14
15
Signed-off-by: Yuri Benditovich <yuri.benditovich@daynix.com>
11
Signed-off-by: Jason Wang <jasowang@redhat.com>
16
Signed-off-by: Jason Wang <jasowang@redhat.com>
12
---
17
---
13
hw/net/rocker/rocker.c | 18 +++++++++---------
18
net/net.c | 12 ++++++++----
14
1 file changed, 9 insertions(+), 9 deletions(-)
19
1 file changed, 8 insertions(+), 4 deletions(-)
15
20
16
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
21
diff --git a/net/net.c b/net/net.c
17
index XXXXXXX..XXXXXXX 100644
22
index XXXXXXX..XXXXXXX 100644
18
--- a/hw/net/rocker/rocker.c
23
--- a/net/net.c
19
+++ b/hw/net/rocker/rocker.c
24
+++ b/net/net.c
20
@@ -XXX,XX +XXX,XX @@ struct rocker {
25
@@ -XXX,XX +XXX,XX @@ void qemu_del_nic(NICState *nic)
21
QLIST_ENTRY(rocker) next;
26
22
};
27
qemu_macaddr_set_free(&nic->conf->macaddr);
23
28
24
-#define ROCKER "rocker"
29
- /* If this is a peer NIC and peer has already been deleted, free it now. */
25
+#define TYPE_ROCKER "rocker"
30
- if (nic->peer_deleted) {
26
31
- for (i = 0; i < queues; i++) {
27
-#define to_rocker(obj) \
32
- qemu_free_net_client(qemu_get_subqueue(nic, i)->peer);
28
- OBJECT_CHECK(Rocker, (obj), ROCKER)
33
+ for (i = 0; i < queues; i++) {
29
+#define ROCKER(obj) \
34
+ NetClientState *nc = qemu_get_subqueue(nic, i);
30
+ OBJECT_CHECK(Rocker, (obj), TYPE_ROCKER)
35
+ /* If this is a peer NIC and peer has already been deleted, free it now. */
31
36
+ if (nic->peer_deleted) {
32
static QLIST_HEAD(, rocker) rockers;
37
+ qemu_free_net_client(nc->peer);
33
38
+ } else if (nc->peer) {
34
@@ -XXX,XX +XXX,XX @@ static World *rocker_world_type_by_name(Rocker *r, const char *name)
39
+ /* if there are RX packets pending, complete them */
35
40
+ qemu_purge_queued_packets(nc->peer);
36
static void pci_rocker_realize(PCIDevice *dev, Error **errp)
41
}
37
{
38
- Rocker *r = to_rocker(dev);
39
+ Rocker *r = ROCKER(dev);
40
const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };
41
const MACAddr dflt = { .a = { 0x52, 0x54, 0x00, 0x12, 0x35, 0x01 } };
42
static int sw_index;
43
@@ -XXX,XX +XXX,XX @@ static void pci_rocker_realize(PCIDevice *dev, Error **errp)
44
/* validate switch properties */
45
46
if (!r->name) {
47
- r->name = g_strdup(ROCKER);
48
+ r->name = g_strdup(TYPE_ROCKER);
49
}
42
}
50
43
51
if (rocker_find(r->name)) {
52
@@ -XXX,XX +XXX,XX @@ err_world_type_by_name:
53
54
static void pci_rocker_uninit(PCIDevice *dev)
55
{
56
- Rocker *r = to_rocker(dev);
57
+ Rocker *r = ROCKER(dev);
58
int i;
59
60
QLIST_REMOVE(r, next);
61
@@ -XXX,XX +XXX,XX @@ static void pci_rocker_uninit(PCIDevice *dev)
62
63
static void rocker_reset(DeviceState *dev)
64
{
65
- Rocker *r = to_rocker(dev);
66
+ Rocker *r = ROCKER(dev);
67
int i;
68
69
for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {
70
@@ -XXX,XX +XXX,XX @@ static Property rocker_properties[] = {
71
};
72
73
static const VMStateDescription rocker_vmsd = {
74
- .name = ROCKER,
75
+ .name = TYPE_ROCKER,
76
.unmigratable = 1,
77
};
78
79
@@ -XXX,XX +XXX,XX @@ static void rocker_class_init(ObjectClass *klass, void *data)
80
}
81
82
static const TypeInfo rocker_info = {
83
- .name = ROCKER,
84
+ .name = TYPE_ROCKER,
85
.parent = TYPE_PCI_DEVICE,
86
.instance_size = sizeof(Rocker),
87
.class_init = rocker_class_init,
88
--
44
--
89
2.7.4
45
2.7.4
90
46
91
47
diff view generated by jsdifflib
1
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
1
From: yuanjungong <ruc_gongyuanjun@163.com>
2
2
3
pci_rocker_init() leaks a World when the name more than 9 chars,
3
Close fd before returning.
4
then return a negative value directly, doesn't make a correct
5
cleanup. So add a new goto label to fix it.
6
4
7
Cc: jasowang@redhat.com
5
Buglink: https://bugs.launchpad.net/qemu/+bug/1904486
8
Cc: jiri@resnulli.us
6
9
Cc: armbru@redhat.com
7
Signed-off-by: yuanjungong <ruc_gongyuanjun@163.com>
10
Cc: f4bug@amsat.org
8
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
11
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
12
Reviewed-by: Markus Armbruster <armbru@redhat.com>
13
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
14
Signed-off-by: Jason Wang <jasowang@redhat.com>
9
Signed-off-by: Jason Wang <jasowang@redhat.com>
15
---
10
---
16
hw/net/rocker/rocker.c | 4 +++-
11
net/tap.c | 2 ++
17
1 file changed, 3 insertions(+), 1 deletion(-)
12
1 file changed, 2 insertions(+)
18
13
19
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
14
diff --git a/net/tap.c b/net/tap.c
20
index XXXXXXX..XXXXXXX 100644
15
index XXXXXXX..XXXXXXX 100644
21
--- a/hw/net/rocker/rocker.c
16
--- a/net/tap.c
22
+++ b/hw/net/rocker/rocker.c
17
+++ b/net/tap.c
23
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
18
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
24
fprintf(stderr,
19
if (ret < 0) {
25
"rocker: name too long; please shorten to at most %d chars\n",
20
error_setg_errno(errp, -ret, "%s: Can't use file descriptor %d",
26
MAX_ROCKER_NAME_LEN);
21
name, fd);
27
- return -EINVAL;
22
+ close(fd);
28
+ err = -EINVAL;
23
return -1;
29
+ goto err_name_too_long;
24
}
30
}
25
31
26
@@ -XXX,XX +XXX,XX @@ int net_init_tap(const Netdev *netdev, const char *name,
32
if (memcmp(&r->fp_start_macaddr, &zero, sizeof(zero)) == 0) {
27
vhostfdname, vnet_hdr, fd, &err);
33
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
28
if (err) {
34
29
error_propagate(errp, err);
35
return 0;
30
+ close(fd);
36
31
return -1;
37
+err_name_too_long:
32
}
38
err_duplicate:
33
} else if (tap->has_fds) {
39
rocker_msix_uninit(r);
40
err_msix_init:
41
--
34
--
42
2.7.4
35
2.7.4
43
36
44
37
diff view generated by jsdifflib
1
From: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
1
From: Keqian Zhu <zhukeqian1@huawei.com>
2
2
3
Memory allocation functions like world_alloc, desc_ring_alloc etc,
3
Fixes: 63c4db4c2e6d (net: relocate paths to helpers and scripts)
4
they are all wrappers around g_malloc, g_new etc. But g_malloc and
4
Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com>
5
similar functions doesn't return null. Because they ignore the fact
6
that g_malloc() of 0 bytes returns null. So error checks for these
7
allocation failure are superfluous. Now, remove them entirely.
8
9
Cc: jasowang@redhat.com
10
Cc: jiri@resnulli.us
11
Cc: armbru@redhat.com
12
Cc: f4bug@amsat.org
13
Signed-off-by: Mao Zhongyi <maozy.fnst@cn.fujitsu.com>
14
Reviewed-by: Markus Armbruster <armbru@redhat.com>
15
Signed-off-by: Jason Wang <jasowang@redhat.com>
5
Signed-off-by: Jason Wang <jasowang@redhat.com>
16
---
6
---
17
hw/net/rocker/rocker.c | 47 +------------------------------------------
7
net/tap.c | 3 ++-
18
hw/net/rocker/rocker_desc.c | 10 ---------
8
1 file changed, 2 insertions(+), 1 deletion(-)
19
hw/net/rocker/rocker_fp.c | 4 ----
20
hw/net/rocker/rocker_of_dpa.c | 20 ------------------
21
hw/net/rocker/rocker_world.c | 12 +++++------
22
5 files changed, 6 insertions(+), 87 deletions(-)
23
9
24
diff --git a/hw/net/rocker/rocker.c b/hw/net/rocker/rocker.c
10
diff --git a/net/tap.c b/net/tap.c
25
index XXXXXXX..XXXXXXX 100644
11
index XXXXXXX..XXXXXXX 100644
26
--- a/hw/net/rocker/rocker.c
12
--- a/net/tap.c
27
+++ b/hw/net/rocker/rocker.c
13
+++ b/net/tap.c
28
@@ -XXX,XX +XXX,XX @@ static int tx_consume(Rocker *r, DescInfo *info)
14
@@ -XXX,XX +XXX,XX @@ free_fail:
15
script = default_script = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
29
}
16
}
30
iov[iovcnt].iov_len = frag_len;
17
if (!downscript) {
31
iov[iovcnt].iov_base = g_malloc(frag_len);
18
- downscript = default_downscript = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
32
- if (!iov[iovcnt].iov_base) {
19
+ downscript = default_downscript =
33
- err = -ROCKER_ENOMEM;
20
+ get_relocated_path(DEFAULT_NETWORK_DOWN_SCRIPT);
34
- goto err_no_mem;
21
}
35
- }
22
36
23
if (tap->has_ifname) {
37
pci_dma_read(dev, frag_addr, iov[iovcnt].iov_base,
38
iov[iovcnt].iov_len);
39
@@ -XXX,XX +XXX,XX @@ static int tx_consume(Rocker *r, DescInfo *info)
40
err = fp_port_eg(r->fp_port[port], iov, iovcnt);
41
42
err_too_many_frags:
43
-err_no_mem:
44
err_bad_attr:
45
for (i = 0; i < ROCKER_TX_FRAGS_MAX; i++) {
46
g_free(iov[i].iov_base);
47
@@ -XXX,XX +XXX,XX @@ int rx_produce(World *world, uint32_t pport,
48
*/
49
50
data = g_malloc(data_size);
51
- if (!data) {
52
- err = -ROCKER_ENOMEM;
53
- goto out;
54
- }
55
+
56
iov_to_buf(iov, iovcnt, 0, data, data_size);
57
pci_dma_write(dev, frag_addr, data, data_size);
58
g_free(data);
59
@@ -XXX,XX +XXX,XX @@ static void rocker_test_dma_ctrl(Rocker *r, uint32_t val)
60
61
buf = g_malloc(r->test_dma_size);
62
63
- if (!buf) {
64
- DPRINTF("test dma buffer alloc failed");
65
- return;
66
- }
67
-
68
switch (val) {
69
case ROCKER_TEST_DMA_CTRL_CLEAR:
70
memset(buf, 0, r->test_dma_size);
71
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
72
73
r->worlds[ROCKER_WORLD_TYPE_OF_DPA] = of_dpa_world_alloc(r);
74
75
- for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {
76
- if (!r->worlds[i]) {
77
- err = -ENOMEM;
78
- goto err_world_alloc;
79
- }
80
- }
81
-
82
if (!r->world_name) {
83
r->world_name = g_strdup(world_name(r->worlds[ROCKER_WORLD_TYPE_OF_DPA]));
84
}
85
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
86
}
87
88
r->rings = g_new(DescRing *, rocker_pci_ring_count(r));
89
- if (!r->rings) {
90
- goto err_rings_alloc;
91
- }
92
93
/* Rings are ordered like this:
94
* - command ring
95
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
96
* .....
97
*/
98
99
- err = -ENOMEM;
100
for (i = 0; i < rocker_pci_ring_count(r); i++) {
101
DescRing *ring = desc_ring_alloc(r, i);
102
103
- if (!ring) {
104
- goto err_ring_alloc;
105
- }
106
-
107
if (i == ROCKER_RING_CMD) {
108
desc_ring_set_consume(ring, cmd_consume, ROCKER_MSIX_VEC_CMD);
109
} else if (i == ROCKER_RING_EVENT) {
110
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
111
fp_port_alloc(r, r->name, &r->fp_start_macaddr,
112
i, &r->fp_ports_peers[i]);
113
114
- if (!port) {
115
- goto err_port_alloc;
116
- }
117
-
118
r->fp_port[i] = port;
119
fp_port_set_world(port, r->world_dflt);
120
}
121
@@ -XXX,XX +XXX,XX @@ static int pci_rocker_init(PCIDevice *dev)
122
123
return 0;
124
125
-err_port_alloc:
126
- for (--i; i >= 0; i--) {
127
- FpPort *port = r->fp_port[i];
128
- fp_port_free(port);
129
- }
130
- i = rocker_pci_ring_count(r);
131
-err_ring_alloc:
132
- for (--i; i >= 0; i--) {
133
- desc_ring_free(r->rings[i]);
134
- }
135
- g_free(r->rings);
136
-err_rings_alloc:
137
err_duplicate:
138
rocker_msix_uninit(r);
139
err_msix_init:
140
object_unparent(OBJECT(&r->msix_bar));
141
object_unparent(OBJECT(&r->mmio));
142
err_world_type_by_name:
143
-err_world_alloc:
144
for (i = 0; i < ROCKER_WORLD_TYPE_MAX; i++) {
145
if (r->worlds[i]) {
146
world_free(r->worlds[i]);
147
diff --git a/hw/net/rocker/rocker_desc.c b/hw/net/rocker/rocker_desc.c
148
index XXXXXXX..XXXXXXX 100644
149
--- a/hw/net/rocker/rocker_desc.c
150
+++ b/hw/net/rocker/rocker_desc.c
151
@@ -XXX,XX +XXX,XX @@ char *desc_get_buf(DescInfo *info, bool read_only)
152
info->buf_size = size;
153
}
154
155
- if (!info->buf) {
156
- return NULL;
157
- }
158
-
159
pci_dma_read(dev, le64_to_cpu(info->desc.buf_addr), info->buf, size);
160
161
return info->buf;
162
@@ -XXX,XX +XXX,XX @@ bool desc_ring_set_size(DescRing *ring, uint32_t size)
163
ring->head = ring->tail = 0;
164
165
ring->info = g_renew(DescInfo, ring->info, size);
166
- if (!ring->info) {
167
- return false;
168
- }
169
170
memset(ring->info, 0, size * sizeof(DescInfo));
171
172
@@ -XXX,XX +XXX,XX @@ DescRing *desc_ring_alloc(Rocker *r, int index)
173
DescRing *ring;
174
175
ring = g_new0(DescRing, 1);
176
- if (!ring) {
177
- return NULL;
178
- }
179
180
ring->r = r;
181
ring->index = index;
182
diff --git a/hw/net/rocker/rocker_fp.c b/hw/net/rocker/rocker_fp.c
183
index XXXXXXX..XXXXXXX 100644
184
--- a/hw/net/rocker/rocker_fp.c
185
+++ b/hw/net/rocker/rocker_fp.c
186
@@ -XXX,XX +XXX,XX @@ FpPort *fp_port_alloc(Rocker *r, char *sw_name,
187
{
188
FpPort *port = g_new0(FpPort, 1);
189
190
- if (!port) {
191
- return NULL;
192
- }
193
-
194
port->r = r;
195
port->index = index;
196
port->pport = index + 1;
197
diff --git a/hw/net/rocker/rocker_of_dpa.c b/hw/net/rocker/rocker_of_dpa.c
198
index XXXXXXX..XXXXXXX 100644
199
--- a/hw/net/rocker/rocker_of_dpa.c
200
+++ b/hw/net/rocker/rocker_of_dpa.c
201
@@ -XXX,XX +XXX,XX @@ static OfDpaFlow *of_dpa_flow_alloc(uint64_t cookie)
202
int64_t now = qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) / 1000;
203
204
flow = g_new0(OfDpaFlow, 1);
205
- if (!flow) {
206
- return NULL;
207
- }
208
209
flow->cookie = cookie;
210
flow->mask.tbl_id = 0xffffffff;
211
@@ -XXX,XX +XXX,XX @@ static OfDpaGroup *of_dpa_group_alloc(uint32_t id)
212
{
213
OfDpaGroup *group = g_new0(OfDpaGroup, 1);
214
215
- if (!group) {
216
- return NULL;
217
- }
218
-
219
group->id = id;
220
221
return group;
222
@@ -XXX,XX +XXX,XX @@ static int of_dpa_cmd_flow_add(OfDpa *of_dpa, uint64_t cookie,
223
}
224
225
flow = of_dpa_flow_alloc(cookie);
226
- if (!flow) {
227
- return -ROCKER_ENOMEM;
228
- }
229
230
err = of_dpa_cmd_flow_add_mod(of_dpa, flow, flow_tlvs);
231
if (err) {
232
@@ -XXX,XX +XXX,XX @@ static int of_dpa_cmd_add_l2_flood(OfDpa *of_dpa, OfDpaGroup *group,
233
rocker_tlv_get_le16(group_tlvs[ROCKER_TLV_OF_DPA_GROUP_COUNT]);
234
235
tlvs = g_new0(RockerTlv *, group->l2_flood.group_count + 1);
236
- if (!tlvs) {
237
- return -ROCKER_ENOMEM;
238
- }
239
240
g_free(group->l2_flood.group_ids);
241
group->l2_flood.group_ids =
242
g_new0(uint32_t, group->l2_flood.group_count);
243
- if (!group->l2_flood.group_ids) {
244
- err = -ROCKER_ENOMEM;
245
- goto err_out;
246
- }
247
248
rocker_tlv_parse_nested(tlvs, group->l2_flood.group_count,
249
group_tlvs[ROCKER_TLV_OF_DPA_GROUP_IDS]);
250
@@ -XXX,XX +XXX,XX @@ static int of_dpa_cmd_group_add(OfDpa *of_dpa, uint32_t group_id,
251
}
252
253
group = of_dpa_group_alloc(group_id);
254
- if (!group) {
255
- return -ROCKER_ENOMEM;
256
- }
257
258
err = of_dpa_cmd_group_do(of_dpa, group_id, group, group_tlvs);
259
if (err) {
260
diff --git a/hw/net/rocker/rocker_world.c b/hw/net/rocker/rocker_world.c
261
index XXXXXXX..XXXXXXX 100644
262
--- a/hw/net/rocker/rocker_world.c
263
+++ b/hw/net/rocker/rocker_world.c
264
@@ -XXX,XX +XXX,XX @@ World *world_alloc(Rocker *r, size_t sizeof_private,
265
{
266
World *w = g_malloc0(sizeof(World) + sizeof_private);
267
268
- if (w) {
269
- w->r = r;
270
- w->type = type;
271
- w->ops = ops;
272
- if (w->ops->init) {
273
- w->ops->init(w);
274
- }
275
+ w->r = r;
276
+ w->type = type;
277
+ w->ops = ops;
278
+ if (w->ops->init) {
279
+ w->ops->init(w);
280
}
281
282
return w;
283
--
24
--
284
2.7.4
25
2.7.4
285
26
286
27
diff view generated by jsdifflib