> [Severity: Medium] > > Can this trust HL for frames the MAC did not actually split? > > Commit 96147375d49f added the L34T gate on purpose. Its message says > "Split Header length is only available when L34T ...". After this change, > every FD=1/LD=0 descriptor uses RDES2.HL no matter what L34T says. > > Suppose the XGMAC writes a non-zero HL on the first descriptor of a > multi-descriptor frame it did not split, and that HL is smaller than what > buffer 1 really holds. Examples are a large non-IP frame, or a frame whose > headers exceed HDSMS. GPSL=16368 accepts both. stmmac_rx_buf1_len() then > returns hlen without any check: > > if (priv->sph_active && hlen) { > priv->xstats.rx_split_hdr_pkt_n++; > return hlen; > } > > Later descriptors count buf1 as 0 and buf2 as dma_buf_sz, so the running > len ends up too low. On the last descriptor, stmmac_rx_buf2_len() has a > floor but no dma_buf_sz cap: > > return plen > len ? plen - len : 0; > > stmmac_rx() then uses that value directly: > > dma_sync_single_for_cpu(priv->device, buf->sec_addr, > buf2_len, dma_dir); > skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, > buf->sec_page, 0, buf2_len, > priv->dma_conf.dma_buf_sz); > > Could buf2_len then be larger than what the DMA wrote into sec_page? That > would put stale page_pool bytes into the skb. When dma_buf_sz is close to > the page size, it would read past the end of the page. > > Before this patch, the FD && !LD case was mostly gated off by L34T. It > fell back to counting buffer 1 as a full dma_buf_sz, which under-counts > but never over-reads. > > A stale read-format des2 is a page-aligned DMA address, so it gives HL=0. > That leaves the question of what the hardware writes to HL for frames it > does not split. Does the databook guarantee that HL is either zero or > accurate in that case? >
>> *len = le32_to_cpu(p->des2) & XGMAC_RDES2_HL; >> }
Yes. The databook description of the RDES2 HL field says: "This field contains the length of the header of the packet split by the MAC [...] If header length is zero, it implies that the MAC did not identify and split the header and both Buffer 1 and Buffer 2 are used for storing the packet". So HL is only non-zero for a packet the MAC actually split, and then it is the length of the header written to buffer 1. For the two examples: - Non-IP packets are not split with the L3/L4 split mode used today   (table "Header Payload Split Support Depending on the Packet Type":   "The DMA does not split the header and payload"). - For headers larger than the buffer, the SPH bit description in   DMA_CH(#i)_Control says: "If the header length exceeds the receive   buffer size, the DMA does not split the header and payload". In both cases HL is 0 and buffer 1 is counted as dma_buf_sz, as before. Commit 96147375d49f added the L34T check because on a single-descriptor non-IP frame RDES2[1:0] holds the AVTDP/AVTCP bits and not HL[1:0]. This patch keeps that check for FD=1/LD=1. For FD=1/LD=0, the "Header Length Availability in RDES2" table says HL is in RDES2[9:0], and L34T is not valid on that descriptor, so it can't be used as the condition there.
> [Severity: High] > > This is a pre-existing issue, but is this des2 read ordered against the > OWN check in stmmac_rx()? > > In stmmac_rx(), the only dma_rmb() after the OWN check is behind > extend_desc: > > status = stmmac_rx_status(priv, &priv->xstats, p); > /* check if managed by the DMA otherwise go ahead */ > if (unlikely(status & dma_own)) > break; > ... > if (priv->extend_desc) { > /* Read the extended status after the own bit */ > dma_rmb(); > > extend_desc is only set in stmmac_dwmac1_quirks(), for dwmac1 enhanced > descriptors, so XGMAC and GMAC4 never get this barrier. stmmac_rx_zc() > has the same gap. > > On weakly ordered CPUs such as arm64, the des2 load in > stmmac_rx()->stmmac_rx_buf1_len()->dwxgmac2_get_rx_header_len() can be > satisfied before the des3 load that saw OWN clear. In that case des2 > still holds the read-format value written by stmmac_rx_refill() through > dwxgmac2_set_sec_addr(). That value is a page-aligned address, so HL > reads as 0. > > On an FD && !LD descriptor, this gives the same buf1_len = dma_buf_sz > misaccounting that this patch fixes. On a single-descriptor split frame, > buf2_len becomes 0. The skb then carries the header plus stale buffer 1 > bytes instead of the payload in buffer 2, and the frame is still marked > CHECKSUM_UNNECESSARY. The RSS hash (des1) and VLAN (des0) reads have the > same exposure. > > Documentation/memory-barriers.txt calls for dma_rmb() after checking the > descriptor ownership bit and before reading the other fields. Should > there be an unconditional dma_rmb() after the OWN check for these cores?
This is pre-existing and independent of this patch, which does not change the descriptor read ordering. Regards, Sagar