Skip to content

Commit f2c1489

Browse files
IronShenPaolo Abeni
authored andcommitted
net: hns3: add sync command to sync io-pgtable
To avoid errors in pgtable prefectch, add a sync command to sync io-pagtable. This is a supplement for the previous patch. We want all the tx packet can be handled with tx bounce buffer path. But it depends on the remain space of the spare buffer, checked by the hns3_can_use_tx_bounce(). In most cases, maybe 99.99%, it returns true. But once it return false by no available space, the packet will be handled with the former path, which will map/unmap the skb buffer. Then the driver will face the smmu prefetch risk again. So add a sync command in this case to avoid smmu prefectch, just protects corner scenes. Fixes: 295ba23 ("net: hns3: add device version to replace pci revision") Signed-off-by: Jian Shen <[email protected]> Signed-off-by: Peiyang Wang <[email protected]> Signed-off-by: Jijie Shao <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent e6ab194 commit f2c1489

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

drivers/net/ethernet/hisilicon/hns3/hns3_enet.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,24 @@ static const struct hns3_rx_ptype hns3_rx_ptype_tbl[] = {
381381
#define HNS3_INVALID_PTYPE \
382382
ARRAY_SIZE(hns3_rx_ptype_tbl)
383383

384+
static void hns3_dma_map_sync(struct device *dev, unsigned long iova)
385+
{
386+
struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
387+
struct iommu_iotlb_gather iotlb_gather;
388+
size_t granule;
389+
390+
if (!domain || !iommu_is_dma_domain(domain))
391+
return;
392+
393+
granule = 1 << __ffs(domain->pgsize_bitmap);
394+
iova = ALIGN_DOWN(iova, granule);
395+
iotlb_gather.start = iova;
396+
iotlb_gather.end = iova + granule - 1;
397+
iotlb_gather.pgsize = granule;
398+
399+
iommu_iotlb_sync(domain, &iotlb_gather);
400+
}
401+
384402
static irqreturn_t hns3_irq_handle(int irq, void *vector)
385403
{
386404
struct hns3_enet_tqp_vector *tqp_vector = vector;
@@ -1728,7 +1746,9 @@ static int hns3_map_and_fill_desc(struct hns3_enet_ring *ring, void *priv,
17281746
unsigned int type)
17291747
{
17301748
struct hns3_desc_cb *desc_cb = &ring->desc_cb[ring->next_to_use];
1749+
struct hnae3_handle *handle = ring->tqp->handle;
17311750
struct device *dev = ring_to_dev(ring);
1751+
struct hnae3_ae_dev *ae_dev;
17321752
unsigned int size;
17331753
dma_addr_t dma;
17341754

@@ -1760,6 +1780,13 @@ static int hns3_map_and_fill_desc(struct hns3_enet_ring *ring, void *priv,
17601780
return -ENOMEM;
17611781
}
17621782

1783+
/* Add a SYNC command to sync io-pgtale to avoid errors in pgtable
1784+
* prefetch
1785+
*/
1786+
ae_dev = hns3_get_ae_dev(handle);
1787+
if (ae_dev->dev_version >= HNAE3_DEVICE_VERSION_V3)
1788+
hns3_dma_map_sync(dev, dma);
1789+
17631790
desc_cb->priv = priv;
17641791
desc_cb->length = size;
17651792
desc_cb->dma = dma;

0 commit comments

Comments
 (0)