win-pvdrivers

changeset 897:0b3220aea661

Fix a crash when using very small (<88) MSS in TCP packets and large send offload
author James Harper <james.harper@bendigoit.com.au>
date Fri Mar 25 20:12:55 2011 +1100 (2011-03-25)
parents d7c96703155f
children dab0168f43c6
files xennet/xennet_common.c xennet/xennet_rx.c
line diff
     1.1 --- a/xennet/xennet_common.c	Thu Mar 24 13:25:16 2011 +1100
     1.2 +++ b/xennet/xennet_common.c	Fri Mar 25 20:12:55 2011 +1100
     1.3 @@ -65,7 +65,7 @@ XenNet_BuildHeader(packet_info_t *pi, PU
     1.4    }
     1.5    
     1.6    bytes_remaining = new_header_size - pi->header_length;
     1.7 -  // TODO: if there are only a small number of bytes left in the current buffer then increase to consume that too...
     1.8 +  // TODO: if there are only a small number of bytes left in the current buffer then increase to consume that too... it would have to be no more than the size of header+mss though
     1.9  
    1.10    //KdPrint((__DRIVER_NAME "     A bytes_remaining = %d, pi->curr_buffer = %p, pi->mdl_count = %d\n", bytes_remaining, pi->curr_buffer, pi->mdl_count));
    1.11    while (bytes_remaining && pi->curr_buffer)
     2.1 --- a/xennet/xennet_rx.c	Thu Mar 24 13:25:16 2011 +1100
     2.2 +++ b/xennet/xennet_rx.c	Fri Mar 25 20:12:55 2011 +1100
     2.3 @@ -234,7 +234,16 @@ XenNet_MakePacket(struct xennet_info *xi
     2.4    //KdPrint((__DRIVER_NAME "     ip4_header_length = %d\n", pi->ip4_header_length));
     2.5    //KdPrint((__DRIVER_NAME "     tcp_header_length = %d\n", pi->tcp_header_length));
     2.6    /* make sure we satisfy the lookahead requirement */
     2.7 -  XenNet_BuildHeader(pi, header_va, max(MIN_LOOKAHEAD_LENGTH, xi->current_lookahead) + MAX_ETH_HEADER_LENGTH);
     2.8 +  
     2.9 +  if (pi->split_required)
    2.10 +  {
    2.11 +    /* for split packets we need to make sure the 'header' is no bigger than header+mss bytes */
    2.12 +    XenNet_BuildHeader(pi, header_va, min((ULONG)MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length + pi->mss, MAX_ETH_HEADER_LENGTH + max(MIN_LOOKAHEAD_LENGTH, xi->current_lookahead)));
    2.13 +  }
    2.14 +  else
    2.15 +  {
    2.16 +    XenNet_BuildHeader(pi, header_va, max(MIN_LOOKAHEAD_LENGTH, xi->current_lookahead) + MAX_ETH_HEADER_LENGTH);
    2.17 +  }
    2.18    header_extra = pi->header_length - (MAX_ETH_HEADER_LENGTH + pi->ip4_header_length + pi->tcp_header_length);
    2.19    ASSERT(pi->header_length <= MAX_ETH_HEADER_LENGTH + MAX_LOOKAHEAD_LENGTH);
    2.20    NdisAllocateBuffer(&status, &out_buffer, xi->rx_buffer_pool, header_va, pi->header_length);
    2.21 @@ -251,11 +260,6 @@ XenNet_MakePacket(struct xennet_info *xi
    2.22  
    2.23    // TODO: if there are only a few bytes left on the first buffer then add them to the header buffer too... maybe
    2.24  
    2.25 -  //KdPrint((__DRIVER_NAME "     split_required = %d\n", pi->split_required));
    2.26 -  //KdPrint((__DRIVER_NAME "     tcp_length = %d, mss = %d\n", pi->tcp_length, pi->mss));
    2.27 -  //KdPrint((__DRIVER_NAME "     total_length = %d\n", pi->total_length));
    2.28 -  //KdPrint((__DRIVER_NAME "     header_length = %d\n", pi->header_length));
    2.29 -  //KdPrint((__DRIVER_NAME "     header_extra = %d\n", header_extra));
    2.30    if (pi->split_required)
    2.31    {
    2.32      tcp_length = (USHORT)min(pi->mss, pi->tcp_remaining);
    2.33 @@ -268,13 +272,15 @@ XenNet_MakePacket(struct xennet_info *xi
    2.34      pi->tcp_remaining = (USHORT)(pi->tcp_remaining - tcp_length);
    2.35      /* part of the packet is already present in the header buffer for lookahead */
    2.36      out_remaining = tcp_length - header_extra;
    2.37 +    ASSERT((LONG)out_remaining >= 0);
    2.38    }
    2.39    else
    2.40    {
    2.41      out_remaining = pi->total_length - pi->header_length;
    2.42 +    ASSERT((LONG)out_remaining >= 0);
    2.43    }
    2.44    //KdPrint((__DRIVER_NAME "     before loop - out_remaining = %d\n", out_remaining));
    2.45 -    
    2.46 +
    2.47    while (out_remaining != 0)
    2.48    {
    2.49      ULONG in_buffer_offset;
    2.50 @@ -622,9 +628,8 @@ XenNet_RxQueueDpcSynchronized(PVOID cont
    2.51  
    2.52  /* We limit the number of packets per interrupt so that acks get a chance
    2.53  under high rx load. The DPC is immediately re-scheduled */
    2.54 -/* this isn't actually done right now */
    2.55 -#define MAXIMUM_PACKETS_PER_INTERRUPT 32
    2.56 -#define MAXIMUM_DATA_PER_INTERRUPT (MAXIMUM_PACKETS_PER_INTERRUPT * 1500)
    2.57 +#define MAXIMUM_PACKETS_PER_INTERRUPT 32 /* this is calculated before large packet split */
    2.58 +#define MAXIMUM_DATA_PER_INTERRUPT (MAXIMUM_PACKETS_PER_INTERRUPT * 1500) /* help account for large packets */
    2.59  
    2.60  // Called at DISPATCH_LEVEL
    2.61  static VOID