Skip to content

Commit

Permalink
idpf: add read memory barrier when checking descriptor done bit
Browse files Browse the repository at this point in the history
Add read memory barrier to ensure the order of operations when accessing
control queue descriptors. Specifically, we want to avoid cases where loads
can be reordered:

1. Load kernel-patches#1 is dispatched to read descriptor flags.
2. Load kernel-patches#2 is dispatched to read some other field from the descriptor.
3. Load kernel-patches#2 completes, accessing memory/cache at a point in time when the DD
   flag is zero.
4. NIC DMA overwrites the descriptor, now the DD flag is one.
5. Any fields loaded before step 4 are now inconsistent with the actual
   descriptor state.

Add read memory barrier between steps 1 and 2, so that load kernel-patches#2 is not
executed until load kernel-patches#1 has completed.

Fixes: 8077c72 ("idpf: add controlq init and reset checks")
Reviewed-by: Przemek Kitszel <[email protected]>
Reviewed-by: Sridhar Samudrala <[email protected]>
Suggested-by: Lance Richardson <[email protected]>
Signed-off-by: Emil Tantilov <[email protected]>
Tested-by: Krishneil Singh <[email protected]>
Signed-off-by: Tony Nguyen <[email protected]>
Signed-off-by: NipaLocal <nipa@local>
  • Loading branch information
etantilov authored and NipaLocal committed Jan 26, 2025
1 parent 710997b commit a9eb634
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/net/ethernet/intel/idpf/idpf_controlq.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,9 @@ int idpf_ctlq_clean_sq(struct idpf_ctlq_info *cq, u16 *clean_count,
if (!(le16_to_cpu(desc->flags) & IDPF_CTLQ_FLAG_DD))
break;

/* Ensure no other fields are read until DD flag is checked */
dma_rmb();

/* strip off FW internal code */
desc_err = le16_to_cpu(desc->ret_val) & 0xff;

Expand Down Expand Up @@ -563,6 +566,9 @@ int idpf_ctlq_recv(struct idpf_ctlq_info *cq, u16 *num_q_msg,
if (!(flags & IDPF_CTLQ_FLAG_DD))
break;

/* Ensure no other fields are read until DD flag is checked */
dma_rmb();

q_msg[i].vmvf_type = (flags &
(IDPF_CTLQ_FLAG_FTYPE_VM |
IDPF_CTLQ_FLAG_FTYPE_PF)) >>
Expand Down

0 comments on commit a9eb634

Please sign in to comment.