From: Thomas Huth <thuth@redhat.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
qemu-s390x@nongnu.org,
Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Cc: Cornelia Huck <cohuck@redhat.com>,
qemu-devel@nongnu.org, Collin Walling <walling@linux.ibm.com>
Subject: [Qemu-devel] [PATCH v1 for-2.13 2/4] pc-bios/s390-ccw/net: Stop virtio-net device before jumping into the OS
Date: Wed, 18 Apr 2018 14:31:45 +0200 [thread overview]
Message-ID: <1524054707-20663-3-git-send-email-thuth@redhat.com> (raw)
In-Reply-To: <1524054707-20663-1-git-send-email-thuth@redhat.com>
The virtio-net receive buffers are filled asynchronously, so we should
make sure to properly shut down the virtio-net device before we jump into
the loaded kernel. Otherwise an incoming packet could destroy memory of
the OS kernel if it did not re-initialize the virtio-net device fast
enough yet.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
pc-bios/s390-ccw/netmain.c | 1 +
pc-bios/s390-ccw/virtio-net.c | 8 ++++++++
pc-bios/s390-ccw/virtio.c | 19 ++++++++++++++-----
pc-bios/s390-ccw/virtio.h | 3 +++
4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c
index ebdc440..e11ed4e 100644
--- a/pc-bios/s390-ccw/netmain.c
+++ b/pc-bios/s390-ccw/netmain.c
@@ -273,6 +273,7 @@ static void net_uninit(filename_ip_t *fn_ip)
if (ip_version == 4) {
dhcp_send_release(fn_ip->fd);
}
+ virtio_net_uninit();
}
void panic(const char *string)
diff --git a/pc-bios/s390-ccw/virtio-net.c b/pc-bios/s390-ccw/virtio-net.c
index ff7f4da..339fe53 100644
--- a/pc-bios/s390-ccw/virtio-net.c
+++ b/pc-bios/s390-ccw/virtio-net.c
@@ -67,6 +67,14 @@ int virtio_net_init(void *mac_addr)
return 0;
}
+void virtio_net_uninit(void)
+{
+ VDev *vdev = virtio_get_device();
+
+ virtio_status_set(vdev, VIRTIO_CONFIG_S_FAILED);
+ virtio_reset_dev(vdev);
+}
+
int send(int fd, const void *buf, int len, int flags)
{
VirtioNetHdr tx_hdr;
diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
index cdb66f4..1d15b03 100644
--- a/pc-bios/s390-ccw/virtio.c
+++ b/pc-bios/s390-ccw/virtio.c
@@ -248,10 +248,21 @@ int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd)
return 0;
}
+void virtio_status_set(VDev *vdev, uint8_t status)
+{
+ IPL_assert(
+ run_ccw(vdev, CCW_CMD_WRITE_STATUS, &status, sizeof(status)) == 0,
+ "Could not write status to host");
+}
+
+void virtio_reset_dev(VDev *vdev)
+{
+ run_ccw(vdev, CCW_CMD_VDEV_RESET, NULL, 0);
+}
+
void virtio_setup_ccw(VDev *vdev)
{
int i, rc, cfg_size = 0;
- unsigned char status = VIRTIO_CONFIG_S_DRIVER_OK;
struct VirtioFeatureDesc {
uint32_t features;
uint8_t index;
@@ -263,7 +274,7 @@ void virtio_setup_ccw(VDev *vdev)
vdev->config.blk.blk_size = 0; /* mark "illegal" - setup started... */
vdev->guessed_disk_nature = VIRTIO_GDN_NONE;
- run_ccw(vdev, CCW_CMD_VDEV_RESET, NULL, 0);
+ virtio_reset_dev(vdev);
switch (vdev->senseid.cu_model) {
case VIRTIO_ID_NET:
@@ -320,9 +331,7 @@ void virtio_setup_ccw(VDev *vdev)
IPL_assert(run_ccw(vdev, CCW_CMD_SET_VQ, &info, sizeof(info)) == 0,
"Cannot set VQ info");
}
- IPL_assert(
- run_ccw(vdev, CCW_CMD_WRITE_STATUS, &status, sizeof(status)) == 0,
- "Could not write status to host");
+ virtio_status_set(vdev, VIRTIO_CONFIG_S_DRIVER_OK);
}
bool virtio_is_supported(SubChannelId schid)
diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h
index 19fceb6..c2479be 100644
--- a/pc-bios/s390-ccw/virtio.h
+++ b/pc-bios/s390-ccw/virtio.h
@@ -277,8 +277,11 @@ void vring_send_buf(VRing *vr, void *p, int len, int flags);
int vr_poll(VRing *vr);
int vring_wait_reply(void);
int virtio_run(VDev *vdev, int vqid, VirtioCmd *cmd);
+void virtio_status_set(VDev *vdev, uint8_t status);
+void virtio_reset_dev(VDev *vdev);
void virtio_setup_ccw(VDev *vdev);
int virtio_net_init(void *mac_addr);
+void virtio_net_uninit(void);
#endif /* VIRTIO_H */
--
1.8.3.1
next prev parent reply other threads:[~2018-04-18 12:31 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-18 12:31 [Qemu-devel] [PATCH v1 for-2.13 0/4] pc-bios/s390-ccw: Network boot improvements Thomas Huth
2018-04-18 12:31 ` [Qemu-devel] [PATCH v1 for-2.13 1/4] pc-bios/s390-ccw/net: Split up net_load() into init, load and uninit parts Thomas Huth
2018-04-18 18:11 ` Farhan Ali
2018-04-19 5:20 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-04-18 12:31 ` Thomas Huth [this message]
2018-04-19 15:49 ` [Qemu-devel] [PATCH v1 for-2.13 2/4] pc-bios/s390-ccw/net: Stop virtio-net device before jumping into the OS Christian Borntraeger
2018-04-20 6:31 ` Thomas Huth
2018-04-20 7:25 ` Christian Borntraeger
2018-04-18 12:31 ` [Qemu-devel] [PATCH v1 for-2.13 3/4] pc-bios/s390-ccw/net: Add support for pxelinux-style config files Thomas Huth
2018-04-19 7:41 ` Viktor VM Mihajlovski
2018-04-19 8:17 ` Thomas Huth
2018-04-19 12:40 ` Viktor VM Mihajlovski
2018-04-19 16:55 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-04-20 6:53 ` Viktor VM Mihajlovski
2018-04-20 7:36 ` Thomas Huth
2018-04-20 7:54 ` Viktor VM Mihajlovski
2018-04-20 8:40 ` Thomas Huth
2018-04-20 12:11 ` Viktor VM Mihajlovski
2018-04-18 12:31 ` [Qemu-devel] [PATCH v1 for-2.13 4/4] pc-bios/s390-ccw/net: Add support for .INS " Thomas Huth
2018-04-19 8:02 ` Viktor VM Mihajlovski
2018-04-19 8:20 ` Thomas Huth
2018-04-18 18:21 ` [Qemu-devel] [PATCH v1 for-2.13 0/4] pc-bios/s390-ccw: Network boot improvements Farhan Ali
2018-04-19 5:27 ` [Qemu-devel] [qemu-s390x] " Thomas Huth
2018-04-19 12:03 ` Farhan Ali
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524054707-20663-3-git-send-email-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=mihajlov@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=walling@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).