Skip to content

Commit d47761d

Browse files
kot-begemot-ukrichardweinberger
authored andcommitted
um: Error handling fixes in vector drivers
With the addition of bess support which uses connection oriented SEQPACKET sockets the vector routines can now encounter a "remote end closed the connection" scenario. This adds handling code to detect it in the TX path and the legacy RX path. There is no way to detect it in the vector RX path because that can legitimately return 0 even if the remote end has not closed the connection. As a result the detection is delayed until the first TX event after the close. Signed-off-by: Anton Ivanov <anton.ivanov@cambridgegreys.com> Signed-off-by: Richard Weinberger <richard@nod.at>
1 parent 5853193 commit d47761d

3 files changed

Lines changed: 35 additions & 7 deletions

File tree

‎arch/um/drivers/vector_kern.c‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static void vector_eth_configure(int n, struct arglist *def);
7676
#define DEFAULT_VECTOR_SIZE 64
7777
#define TX_SMALL_PACKET 128
7878
#define MAX_IOV_SIZE (MAX_SKB_FRAGS + 1)
79+
#define MAX_ITERATIONS 64
7980

8081
static const struct {
8182
const char string[ETH_GSTRING_LEN];
@@ -418,6 +419,7 @@ static int vector_send(struct vector_queue *qi)
418419
if (net_ratelimit())
419420
netdev_err(vp->dev, "sendmmsg err=%i\n",
420421
result);
422+
vp->in_error = true;
421423
result = send_len;
422424
}
423425
if (result > 0) {
@@ -845,6 +847,10 @@ static int vector_legacy_rx(struct vector_private *vp)
845847
}
846848

847849
pkt_len = uml_vector_recvmsg(vp->fds->rx_fd, &hdr, 0);
850+
if (pkt_len < 0) {
851+
vp->in_error = true;
852+
return pkt_len;
853+
}
848854

849855
if (skb != NULL) {
850856
if (pkt_len > vp->header_size) {
@@ -891,12 +897,16 @@ static int writev_tx(struct vector_private *vp, struct sk_buff *skb)
891897

892898
if (iov_count < 1)
893899
goto drop;
900+
894901
pkt_len = uml_vector_writev(
895902
vp->fds->tx_fd,
896903
(struct iovec *) &iov,
897904
iov_count
898905
);
899906

907+
if (pkt_len < 0)
908+
goto drop;
909+
900910
netif_trans_update(vp->dev);
901911
netif_wake_queue(vp->dev);
902912

@@ -911,6 +921,8 @@ static int writev_tx(struct vector_private *vp, struct sk_buff *skb)
911921
drop:
912922
vp->dev->stats.tx_dropped++;
913923
consume_skb(skb);
924+
if (pkt_len < 0)
925+
vp->in_error = true;
914926
return pkt_len;
915927
}
916928

@@ -939,6 +951,9 @@ static int vector_mmsg_rx(struct vector_private *vp)
939951
packet_count = uml_vector_recvmmsg(
940952
vp->fds->rx_fd, qi->mmsg_vector, qi->max_depth, 0);
941953

954+
if (packet_count < 0)
955+
vp->in_error = true;
956+
942957
if (packet_count <= 0)
943958
return packet_count;
944959

@@ -1008,22 +1023,32 @@ static int vector_mmsg_rx(struct vector_private *vp)
10081023
static void vector_rx(struct vector_private *vp)
10091024
{
10101025
int err;
1026+
int iter = 0;
10111027

10121028
if ((vp->options & VECTOR_RX) > 0)
1013-
while ((err = vector_mmsg_rx(vp)) > 0)
1014-
;
1029+
while (((err = vector_mmsg_rx(vp)) > 0) && (iter < MAX_ITERATIONS))
1030+
iter++;
10151031
else
1016-
while ((err = vector_legacy_rx(vp)) > 0)
1017-
;
1032+
while (((err = vector_legacy_rx(vp)) > 0) && (iter < MAX_ITERATIONS))
1033+
iter++;
10181034
if ((err != 0) && net_ratelimit())
10191035
netdev_err(vp->dev, "vector_rx: error(%d)\n", err);
1036+
if (iter == MAX_ITERATIONS)
1037+
netdev_err(vp->dev, "vector_rx: device stuck, remote end may have closed the connection\n");
10201038
}
10211039

10221040
static int vector_net_start_xmit(struct sk_buff *skb, struct net_device *dev)
10231041
{
10241042
struct vector_private *vp = netdev_priv(dev);
10251043
int queue_depth = 0;
10261044

1045+
if (vp->in_error) {
1046+
deactivate_fd(vp->fds->rx_fd, vp->rx_irq);
1047+
if ((vp->fds->rx_fd != vp->fds->tx_fd) && (vp->tx_irq != 0))
1048+
deactivate_fd(vp->fds->tx_fd, vp->tx_irq);
1049+
return NETDEV_TX_BUSY;
1050+
}
1051+
10271052
if ((vp->options & VECTOR_TX) == 0) {
10281053
writev_tx(vp, skb);
10291054
return NETDEV_TX_OK;
@@ -1134,6 +1159,7 @@ static int vector_net_close(struct net_device *dev)
11341159
vp->fds = NULL;
11351160
spin_lock_irqsave(&vp->lock, flags);
11361161
vp->opened = false;
1162+
vp->in_error = false;
11371163
spin_unlock_irqrestore(&vp->lock, flags);
11381164
return 0;
11391165
}
@@ -1501,7 +1527,8 @@ static void vector_eth_configure(
15011527
.transport_data = NULL,
15021528
.in_write_poll = false,
15031529
.coalesce = 2,
1504-
.req_size = get_req_size(def)
1530+
.req_size = get_req_size(def),
1531+
.in_error = false
15051532
});
15061533

15071534
dev->features = dev->hw_features = (NETIF_F_SG | NETIF_F_FRAGLIST);

‎arch/um/drivers/vector_kern.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ struct vector_private {
116116
bool rexmit_scheduled;
117117
bool opened;
118118
bool in_write_poll;
119+
bool in_error;
119120

120121
/* ethtool stats */
121122

‎arch/um/drivers/vector_user.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ int uml_vector_writev(int fd, void *hdr, int iovcount)
618618
int n;
619619

620620
CATCH_EINTR(n = writev(fd, (struct iovec *) hdr, iovcount));
621-
if ((n < 0) && (errno == EAGAIN))
621+
if ((n < 0) && ((errno == EAGAIN) || (errno == ENOBUFS)))
622622
return 0;
623623
if (n >= 0)
624624
return n;
@@ -635,7 +635,7 @@ int uml_vector_sendmmsg(
635635
int n;
636636

637637
CATCH_EINTR(n = sendmmsg(fd, (struct mmsghdr *) msgvec, vlen, flags));
638-
if ((n < 0) && (errno == EAGAIN))
638+
if ((n < 0) && ((errno == EAGAIN) || (errno == ENOBUFS)))
639639
return 0;
640640
if (n >= 0)
641641
return n;

0 commit comments

Comments
 (0)