Skip to content

Commit 0688854

Browse files
ecree-solarflaredavem330
authored andcommitted
sfc: check hash is valid before using it
On EF100, the RX hash field in the packet prefix may not be valid (e.g. if the header parse failed), and this is indicated by a one-bit flag elsewhere in the packet prefix. Only call skb_set_hash() if the RSS_HASH_VALID bit is set. Signed-off-by: Edward Cree <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e591d29 commit 0688854

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

drivers/net/ethernet/sfc/ef100_rx.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
#define ESF_GZ_RX_PREFIX_NT_OR_INNER_L3_CLASS_WIDTH \
3232
ESF_GZ_RX_PREFIX_HCLASS_NT_OR_INNER_L3_CLASS_WIDTH
3333

34+
bool ef100_rx_buf_hash_valid(const u8 *prefix)
35+
{
36+
return PREFIX_FIELD(prefix, RSS_HASH_VALID);
37+
}
38+
3439
static bool check_fcs(struct efx_channel *channel, u32 *prefix)
3540
{
3641
u16 rxclass;

drivers/net/ethernet/sfc/ef100_rx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#include "net_driver.h"
1616

17+
bool ef100_rx_buf_hash_valid(const u8 *prefix);
1718
void efx_ef100_ev_rx(struct efx_channel *channel, const efx_qword_t *p_event);
1819
void ef100_rx_write(struct efx_rx_queue *rx_queue);
1920
void __ef100_rx_packet(struct efx_channel *channel);

drivers/net/ethernet/sfc/efx.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ static inline void efx_rx_flush_packet(struct efx_channel *channel)
4545
__ef100_rx_packet, __efx_rx_packet,
4646
channel);
4747
}
48+
static inline bool efx_rx_buf_hash_valid(struct efx_nic *efx, const u8 *prefix)
49+
{
50+
if (efx->type->rx_buf_hash_valid)
51+
return INDIRECT_CALL_1(efx->type->rx_buf_hash_valid,
52+
ef100_rx_buf_hash_valid,
53+
prefix);
54+
return true;
55+
}
4856

4957
/* Maximum number of TCP segments we support for soft-TSO */
5058
#define EFX_TSO_MAX_SEGS 100

drivers/net/ethernet/sfc/net_driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ struct efx_udp_tunnel {
12651265
* @rx_write: Write RX descriptors and doorbell
12661266
* @rx_defer_refill: Generate a refill reminder event
12671267
* @rx_packet: Receive the queued RX buffer on a channel
1268+
* @rx_buf_hash_valid: Determine whether the RX prefix contains a valid hash
12681269
* @ev_probe: Allocate resources for event queue
12691270
* @ev_init: Initialise event queue on the NIC
12701271
* @ev_fini: Deinitialise event queue on the NIC
@@ -1409,6 +1410,7 @@ struct efx_nic_type {
14091410
void (*rx_write)(struct efx_rx_queue *rx_queue);
14101411
void (*rx_defer_refill)(struct efx_rx_queue *rx_queue);
14111412
void (*rx_packet)(struct efx_channel *channel);
1413+
bool (*rx_buf_hash_valid)(const u8 *prefix);
14121414
int (*ev_probe)(struct efx_channel *channel);
14131415
int (*ev_init)(struct efx_channel *channel);
14141416
void (*ev_fini)(struct efx_channel *channel);

drivers/net/ethernet/sfc/rx_common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,8 @@ efx_rx_packet_gro(struct efx_channel *channel, struct efx_rx_buffer *rx_buf,
525525
return;
526526
}
527527

528-
if (efx->net_dev->features & NETIF_F_RXHASH)
528+
if (efx->net_dev->features & NETIF_F_RXHASH &&
529+
efx_rx_buf_hash_valid(efx, eh))
529530
skb_set_hash(skb, efx_rx_buf_hash(efx, eh),
530531
PKT_HASH_TYPE_L3);
531532
if (csum) {

0 commit comments

Comments
 (0)