Skip to contentSkip to conversation

Net patches

GIT PULL Applied Jason Wang 2 participants 5 messages Jan 6, 2017 Networking

lore
Share & tools
lore

Jason Wang

author
#0 lore raw

The following changes since commit e92fbc753df4fab9ee524b5ea07a51bee8b6bae4:

Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2017-01-05 12:44:23 +0000)

are available in the git repository at:

https://github.com/jasowang/qemu.git tags/net-pull-request

for you to fetch changes up to 7e354ed4df9787ff95cdb189374739e476be4f9a:

fsl_etsec: Fix Tx BD ring wrapping handling (2017-01-06 10:38:21 +0800)

----------------------------------------------------------------

- network support for record/replay

----------------------------------------------------------------
Andrey Smirnov (1):
fsl_etsec: Fix Tx BD ring wrapping handling

Hervé Poussineau (1):
rtl8139: correctly handle PHY reset

Pavel Dovgalyuk (1):
record/replay: add network support

 docs/replay.txt          |  14 +++++++
 hw/net/fsl_etsec/rings.c |  19 +++++----
 hw/net/rtl8139.c         |  34 ++++++++++------
 include/sysemu/replay.h  |  12 ++++++
 net/Makefile.objs        |   1 +
 net/filter-replay.c      |  92 ++++++++++++++++++++++++++++++++++++++++++
 replay/Makefile.objs     |   1 +
 replay/replay-events.c   |  11 +++++
 replay/replay-internal.h |  10 +++++
 replay/replay-net.c      | 102 +++++++++++++++++++++++++++++++++++++++++++++++
 replay/replay.c          |   2 +-
 vl.c                     |   3 +-
 12 files changed, 276 insertions(+), 25 deletions(-)
 create mode 100644 net/filter-replay.c
 create mode 100644 replay/replay-net.c
author
#1 lore raw

[Qemu-devel] [PULL 1/3] record/replay: add network support

From: Pavel Dovgalyuk <[email protected]>

This patch adds support of recording and replaying network packets in irount rr mode.

Record and replay for network interactions is performed with the network filter. Each backend must have its own instance of the replay filter as follows:
-netdev user,id=net1 -device rtl8139,netdev=net1
-object filter-replay,id=replay,netdev=net1

Replay network filter is used to record and replay network packets. While recording the virtual machine this filter puts all packets coming from the outer world into the log. In replay mode packets from the log are injected into the network device. All interactions with network backend in replay mode are disabled.

v5 changes:
- using iov_to_buf function instead of loop

---
 docs/replay.txt          |  14 +++++++
 include/sysemu/replay.h  |  12 ++++++
 net/Makefile.objs        |   1 +
 net/filter-replay.c      |  92 ++++++++++++++++++++++++++++++++++++++++++
 replay/Makefile.objs     |   1 +
 replay/replay-events.c   |  11 +++++
 replay/replay-internal.h |  10 +++++
 replay/replay-net.c      | 102 +++++++++++++++++++++++++++++++++++++++++++++++
 replay/replay.c          |   2 +-
 vl.c                     |   3 +-
 10 files changed, 246 insertions(+), 2 deletions(-)
 create mode 100644 net/filter-replay.c
 create mode 100644 replay/replay-net.c
docs/replay.txt +14 -0
index 779c6c0..347b2ff 100644
@@ -195,3 +195,17 @@ Queue is flushed at checkpoints and information about processed requests
 is recorded to the log. In replay phase the queue is matched with
 events read from the log. Therefore block devices requests are processed
 deterministically.
+
+Network devices
+---------------
+
+Record and replay for network interactions is performed with the network filter.
+Each backend must have its own instance of the replay filter as follows:
+ -netdev user,id=net1 -device rtl8139,netdev=net1
+ -object filter-replay,id=replay,netdev=net1
+
+Replay network filter is used to record and replay network packets. While
+recording the virtual machine this filter puts all packets coming from
+the outer world into the log. In replay mode packets from the log are
+injected into the network device. All interactions with network backend
+in replay mode are disabled.
include/sysemu/replay.h +12 -0
index f80d6d2..abb35ca 100644
@@ -39,6 +39,8 @@ enum ReplayCheckpoint {
 };
 typedef enum ReplayCheckpoint ReplayCheckpoint;
 
+typedef struct ReplayNetState ReplayNetState;
+
 extern ReplayMode replay_mode;
 
 /* Replay process control functions */
@@ -137,4 +139,14 @@ void replay_char_read_all_save_error(int res);
 /*! Writes character read_all execution result into the replay log. */
 void replay_char_read_all_save_buf(uint8_t *buf, int offset);
 
+/* Network */
+
+/*! Registers replay network filter attached to some backend. */
+ReplayNetState *replay_register_net(NetFilterState *nfs);
+/*! Unregisters replay network filter. */
+void replay_unregister_net(ReplayNetState *rns);
+/*! Called to write network packet to the replay log. */
+void replay_net_packet_event(ReplayNetState *rns, unsigned flags,
+                             const struct iovec *iov, int iovcnt);
+
 #endif
net/Makefile.objs +1 -0
index 2a80df5..2e2fd43 100644
@@ -19,3 +19,4 @@ common-obj-y += filter-mirror.o
 common-obj-y += colo-compare.o
 common-obj-y += colo.o
 common-obj-y += filter-rewriter.o
+common-obj-y += filter-replay.o
net/filter-replay.c new file +92 -0

92 lines not on this page · raw message

replay/Makefile.objs +1 -0
index c8ad3eb..b2afd40 100644
@@ -5,3 +5,4 @@ common-obj-y += replay-time.o
 common-obj-y += replay-input.o
 common-obj-y += replay-char.o
 common-obj-y += replay-snapshot.o
+common-obj-y += replay-net.o
replay/replay-events.c +11 -0
index c513913..94a6dcc 100644
@@ -54,6 +54,9 @@ static void replay_run_event(Event *event)
     case REPLAY_ASYNC_EVENT_BLOCK:
         aio_bh_call(event->opaque);
         break;
+    case REPLAY_ASYNC_EVENT_NET:
+        replay_event_net_run(event->opaque);
+        break;
     default:
         error_report("Replay: invalid async event ID (%d) in the queue",
                     event->event_kind);
@@ -189,6 +192,9 @@ static void replay_save_event(Event *event, int checkpoint)
         case REPLAY_ASYNC_EVENT_BLOCK:
             replay_put_qword(event->id);
             break;
+        case REPLAY_ASYNC_EVENT_NET:
+            replay_event_net_save(event->opaque);
+            break;
         default:
             error_report("Unknown ID %" PRId64 " of replay event", event->id);
             exit(1);
@@ -252,6 +258,11 @@ static Event *replay_read_event(int checkpoint)
             read_id = replay_get_qword();
         }
         break;
+    case REPLAY_ASYNC_EVENT_NET:
+        event = g_malloc0(sizeof(Event));
+        event->event_kind = read_event_kind;
+        event->opaque = replay_event_net_load();
+        return event;
     default:
         error_report("Unknown ID %d of replay event", read_event_kind);
         exit(1);
replay/replay-internal.h +10 -0
index 9117e44..c26d079 100644
@@ -50,6 +50,7 @@ enum ReplayAsyncEventKind {
     REPLAY_ASYNC_EVENT_INPUT_SYNC,
     REPLAY_ASYNC_EVENT_CHAR_READ,
     REPLAY_ASYNC_EVENT_BLOCK,
+    REPLAY_ASYNC_EVENT_NET,
     REPLAY_ASYNC_COUNT
 };
 
@@ -161,6 +162,15 @@ void replay_event_char_read_save(void *opaque);
 /*! Reads char event read from the file. */
 void *replay_event_char_read_load(void);
 
+/* Network devices */
+
+/*! Called to run network event. */
+void replay_event_net_run(void *opaque);
+/*! Writes network event to the file. */
+void replay_event_net_save(void *opaque);
+/*! Reads network from the file. */
+void *replay_event_net_load(void);
+
 /* VMState-related functions */
 
 /* Registers replay VMState.
replay/replay-net.c new file +102 -0

102 lines not on this page · raw message

replay/replay.c +1 -1
index c797aea..7f27cf1 100644
@@ -21,7 +21,7 @@
 
 /* Current version of the replay mechanism.
    Increase it when file format changes. */
-#define REPLAY_VERSION              0xe02004
+#define REPLAY_VERSION              0xe02005
 /* Size of replay log header */
 #define HEADER_SIZE                 (sizeof(uint32_t) + sizeof(uint64_t))
 
vl.c +2 -1
index d77dd86..a23de18 100644
@@ -2859,7 +2859,8 @@ static bool object_create_initial(const char *type)
         g_str_equal(type, "filter-mirror") ||
         g_str_equal(type, "filter-redirector") ||
         g_str_equal(type, "colo-compare") ||
-        g_str_equal(type, "filter-rewriter")) {
+        g_str_equal(type, "filter-rewriter") ||
+        g_str_equal(type, "filter-replay")) {
         return false;
     }
 
Signature · 1 line
2.7.4
author
#2 lore raw

[Qemu-devel] [PULL 2/3] rtl8139: correctly handle PHY reset

In reply to Jason Wang

From: Hervé Poussineau <[email protected]>

According to datasheet:
"[Bit 15 of Basic Mode Control Register] sets the status and control registers of the PHY (register 0062-0074) in a default state. This bit is self-clearing. 1 = software reset; 0 = normal operation."

This fixes the netcard detection failure in Minoca OS.

---
 hw/net/rtl8139.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)
hw/net/rtl8139.c +21 -13
index f05e59c..671c7e4 100644
@@ -1205,6 +1205,20 @@ static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
     s->RxBufAddr = 0;
 }
 
+static void rtl8139_reset_phy(RTL8139State *s)
+{
+    s->BasicModeStatus  = 0x7809;
+    s->BasicModeStatus |= 0x0020; /* autonegotiation completed */
+    /* preserve link state */
+    s->BasicModeStatus |= qemu_get_queue(s->nic)->link_down ? 0 : 0x04;
+
+    s->NWayAdvert    = 0x05e1; /* all modes, full duplex */
+    s->NWayLPAR      = 0x05e1; /* all modes, full duplex */
+    s->NWayExpansion = 0x0001; /* autonegotiation supported */
+
+    s->CSCR = CSCR_F_LINK_100 | CSCR_HEART_BIT | CSCR_LD;
+}
+
 static void rtl8139_reset(DeviceState *d)
 {
     RTL8139State *s = RTL8139(d);
@@ -1256,25 +1270,14 @@ static void rtl8139_reset(DeviceState *d)
     s->Config3 = 0x1; /* fast back-to-back compatible */
     s->Config5 = 0x0;
 
-    s->CSCR = CSCR_F_LINK_100 | CSCR_HEART_BIT | CSCR_LD;
-
     s->CpCmd   = 0x0; /* reset C+ mode */
     s->cplus_enabled = 0;
 
-
 //    s->BasicModeCtrl = 0x3100; // 100Mbps, full duplex, autonegotiation
 //    s->BasicModeCtrl = 0x2100; // 100Mbps, full duplex
     s->BasicModeCtrl = 0x1000; // autonegotiation
 
-    s->BasicModeStatus  = 0x7809;
-    //s->BasicModeStatus |= 0x0040; /* UTP medium */
-    s->BasicModeStatus |= 0x0020; /* autonegotiation completed */
-    /* preserve link state */
-    s->BasicModeStatus |= qemu_get_queue(s->nic)->link_down ? 0 : 0x04;
-
-    s->NWayAdvert    = 0x05e1; /* all modes, full duplex */
-    s->NWayLPAR      = 0x05e1; /* all modes, full duplex */
-    s->NWayExpansion = 0x0001; /* autonegotiation supported */
+    rtl8139_reset_phy(s);
 
     /* also reset timer and disable timer interrupt */
     s->TCTR = 0;
@@ -1469,7 +1472,7 @@ static void rtl8139_BasicModeCtrl_write(RTL8139State *s, uint32_t val)
     DPRINTF("BasicModeCtrl register write(w) val=0x%04x\n", val);
 
     /* mask unwritable bits */
-    uint32_t mask = 0x4cff;
+    uint32_t mask = 0xccff;
 
     if (1 || !rtl8139_config_writable(s))
     {
@@ -1479,6 +1482,11 @@ static void rtl8139_BasicModeCtrl_write(RTL8139State *s, uint32_t val)
         mask |= 0x0100;
     }
 
+    if (val & 0x8000) {
+        /* Reset PHY */
+        rtl8139_reset_phy(s);
+    }
+
     val = SET_MASKED(val, mask, s->BasicModeCtrl);
 
     s->BasicModeCtrl = val;
Signature · 1 line
2.7.4
author
#3 lore raw

[Qemu-devel] [PULL 3/3] fsl_etsec: Fix Tx BD ring wrapping handling

In reply to Jason Wang

From: Andrey Smirnov <[email protected]>

Current code that handles Tx buffer desciprtor ring scanning employs the following algorithm:

1. Restore current buffer descriptor pointer from TBPTRn

2. Process current descriptor

3. If current descriptor has BD_WRAP flag set set current descriptor pointer to start of the descriptor ring

4. If current descriptor points to start of the ring exit the loop, otherwise increment current descriptor pointer and go to #2

5. Store current descriptor in TBPTRn

The way the code is implemented results in buffer descriptor ring being scanned starting at offset/descriptor #0. While covering 99% of the cases, this algorithm becomes problematic for a number of edge cases.

Consider the following scenario: guest OS driver initializes descriptor ring to N individual descriptors and starts sending data out. Depending on the volume of traffic and probably guest OS driver implementation it is possible that an edge case where a packet, spread across 2 descriptors is placed in descriptors N - 1 and 0 in that order(it is easy to imagine similar examples involving more than 2 descriptors).

What happens then is aforementioned algorithm starts at descriptor 0, sees a descriptor marked as BD_LAST, which it happily sends out as a separate packet(very much malformed at this point) then the iteration continues and the first part of the original packet is tacked to the next transmission which ends up being bogus as well.

This behvaiour can be pretty reliably observed when scp'ing data from a guest OS via TAP interface for files larger than 160K (every time for 700K+).

This patch changes the scanning algorithm to do the following:

1. Restore "current" buffer descriptor pointer from TBPTRn

2. If "current" descriptor does not have BD_TX_READY set, goto #6

3. Process current descriptor

4. If "current" descriptor has BD_WRAP flag set "current" descriptor pointer to start of the descriptor ring otherwise set increment "current" by the size of one descriptor

5. Goto #1

6. Save "current" buffer descriptor in TBPTRn

This way we preserve the information about which descriptor was processed last and always start where we left off avoiding the original problem. On top of that, judging by the following excerpt from MPC8548ERM (p. 14-48):

"... When the end of the TxBD ring is reached, eTSEC initializes TBPTRn to the value in the corresponding TBASEn. The TBPTR register is internally written by the eTSEC’s DMA controller during transmission. The pointer increments by eight (bytes) each time a descriptor is closed successfully by the eTSEC..."

revised algorithm might also a more correct way of emulating this aspect of eTSEC peripheral.

---
 hw/net/fsl_etsec/rings.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
hw/net/fsl_etsec/rings.c +9 -10
index 54c0127..d0f93ee 100644
@@ -358,25 +358,24 @@ void etsec_walk_tx_ring(eTSEC *etsec, int ring_nbr)
         /* Save flags before BD update */
         bd_flags = bd.flags;
 
-        if (bd_flags & BD_TX_READY) {
-            process_tx_bd(etsec, &bd);
-
-            /* Write back BD after update */
-            write_buffer_descriptor(etsec, bd_addr, &bd);
+        if (!(bd_flags & BD_TX_READY)) {
+            break;
         }
 
+        process_tx_bd(etsec, &bd);
+        /* Write back BD after update */
+        write_buffer_descriptor(etsec, bd_addr, &bd);
+
         /* Wrap or next BD */
         if (bd_flags & BD_WRAP) {
             bd_addr = ring_base;
         } else {
             bd_addr += sizeof(eTSEC_rxtx_bd);
         }
+    } while (TRUE);
 
-    } while (bd_addr != ring_base);
-
-    bd_addr = ring_base;
-
-    /* Save the Buffer Descriptor Pointers to current bd */
+    /* Save the Buffer Descriptor Pointers to last bd that was not
+     * succesfully closed */
     etsec->regs[TBPTR0 + ring_nbr].value = bd_addr;
 
     /* Set transmit halt THLTx */
Signature · 1 line
2.7.4
#4 lore raw
In reply to Jason Wang
Quoted 20 lines · Jason Wang

The following changes since commit e92fbc753df4fab9ee524b5ea07a51bee8b6bae4:

Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2017-01-05 12:44:23 +0000)

are available in the git repository at:

https://github.com/jasowang/qemu.git tags/net-pull-request

for you to fetch changes up to 7e354ed4df9787ff95cdb189374739e476be4f9a:

fsl_etsec: Fix Tx BD ring wrapping handling (2017-01-06 10:38:21 +0800)

----------------------------------------------------------------

- network support for record/replay

----------------------------------------------------------------
Andrey Smirnov (1):
fsl_etsec: Fix Tx BD ring wrapping handling

Quoted 5 lines

Hervé Poussineau (1):
rtl8139: correctly handle PHY reset

Pavel Dovgalyuk (1):
record/replay: add network support

Applied, thanks.

-- PMM