On Little Endian platforms, everything we need from the completion
descriptor is read at once, while on Big Endian we read it
field-by-field. Depending on the compiler and optimization settings,
reads can be combined or stay distinct. The latter leaves us with no
barrier and with possible stale completion index or tag.

Change the logic a bit and read only the "readiness" field first on
Big Endian, then perform strictly-ordered read of the cookie after
making sure it is valid.

The Little Endian code remains intact. Found by Sashiko.

Fixes: cba102cd7190 ("idpf: add support for XDP on Rx")
Cc: [email protected] # 6.18+
Signed-off-by: Alexander Lobakin <[email protected]>
---
 drivers/net/ethernet/intel/idpf/xdp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/intel/idpf/xdp.c 
b/drivers/net/ethernet/intel/idpf/xdp.c
index 1d8ed7ac3e17..48320ea004df 100644
--- a/drivers/net/ethernet/intel/idpf/xdp.c
+++ b/drivers/net/ethernet/intel/idpf/xdp.c
@@ -236,8 +236,7 @@ static int idpf_xdp_parse_cqe(const struct 
idpf_splitq_4b_tx_compl_desc *desc,
 #ifdef __LIBETH_WORD_ACCESS
        val = *(const u32 *)desc;
 #else
-       val = ((u32)le16_to_cpu(desc->q_head_compl_tag.q_head) << 16) |
-             le16_to_cpu(desc->qid_comptype_gen);
+       val = le16_to_cpu(desc->qid_comptype_gen);
 #endif
        if (!!(val & IDPF_TXD_COMPLQ_GEN_M) != gen)
                return -ENODATA;
@@ -247,7 +246,13 @@ static int idpf_xdp_parse_cqe(const struct 
idpf_splitq_4b_tx_compl_desc *desc,
                                IDPF_TXD_COMPLT_RS)))
                return -EINVAL;
 
+#ifdef __LIBETH_WORD_ACCESS
        return upper_16_bits(val);
+#else
+       dma_rmb();
+
+       return le16_to_cpu(desc->q_head_compl_tag.q_head);
+#endif
 }
 
 u32 idpf_xdpsq_poll(struct idpf_tx_queue *xdpsq, u32 budget)
-- 
2.56.1

Reply via email to