net: Remove obsolete 32-bit DMA mask fallbacks
Subsystems (16)
cover net: Remove obsolete 32-bit DMA mask fallbacks
A lot of Ethernet drivers set a >32 bit DMA mask and retry with a 32-bit mask if the first call fails. This treats the return value of dma_set_mask_and_coherent() as an indication that the platform requires a narrower DMA width.
That is not a correct interpretation of dma_set_mask_and_coherent(). The mask describes the DMA addresses the device can accept and constrains subsequent mappings to that range. A wider mask includes every address permitted by a 32-bit mask, including addresses from a platform that only produces 32-bit DMA addresses. Retrying with 32 bits therefore adds a stricter constraint and cannot correct a failure to establish the wider mask. The DMA API HOWTO explicitly calls this fallback pattern incorrect [1]. See [2] and [3] for details.
A net subsystem tree-wide audit found 28 Ethernet drivers with this pattern. This series contains 14 straightforward cases where the fallback can be removed without changing the mask selected for the device. The return-value check is retained. DMA setup errors are still reported and still abort device initialization. The other 14 cases are less straightforward. So I will submit those as a separate follow-up after review of this series concludes and any issues are resolved.
Testing was compile-only. No hardware testing was performed.
[1] DMA API HOWTO, "DMA addressing capabilities"
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
[2] DMA direct addressability change, commit 91ef26f91417
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=91ef26f914171cf753330f13724fd9142b5b1640
[3] DMA HOWTO correction, commit f7ae20f2fc4e
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f7ae20f2fc4e
Best regards,
Ruizhe Zhou
Ruizhe Zhou (14):
net: atlantic: Remove obsolete 32-bit DMA mask fallback
net: alx: Remove obsolete 32-bit DMA mask fallback
net: systemport: Remove obsolete 32-bit DMA mask fallback
bnxt_en: Remove obsolete 32-bit DMA mask fallback
enic: Remove obsolete 32-bit DMA mask fallback
net: hns3: Remove obsolete 32-bit DMA mask fallback
fm10k: Remove obsolete 32-bit DMA mask fallback net/mlx4: Remove obsolete 32-bit DMA mask fallback net/mlx5: Remove obsolete 32-bit DMA mask fallback
mlxsw: pci: Remove obsolete 32-bit DMA mask fallback
eth: fbnic: Remove obsolete 32-bit DMA mask fallback
net: pch_gbe: Remove obsolete 32-bit DMA mask fallback
net: renesas: rswitch: Remove obsolete 32-bit DMA mask fallback
net: niu: Remove obsolete 32-bit DMA mask fallback
.../ethernet/aquantia/atlantic/aq_pci_func.c | 2 -- drivers/net/ethernet/atheros/alx/main.c | 13 +++++-------- drivers/net/ethernet/broadcom/bcmsysport.c | 2 -- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 ++-- drivers/net/ethernet/cisco/enic/enic_main.c | 19 ++++--------------- .../hisilicon/hns3/hns3pf/hclge_main.c | 9 ++------- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 2 -- drivers/net/ethernet/mellanox/mlx4/main.c | 8 ++------ .../net/ethernet/mellanox/mlx5/core/main.c | 8 ++------ drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 ++----- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 2 -- .../ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 10 ++++------ drivers/net/ethernet/renesas/rswitch_main.c | 7 ++----- drivers/net/ethernet/sun/niu.c | 10 +++------- 14 files changed, 28 insertions(+), 75 deletions(-)
base-commit: e16acadb9a0f7a0f04318e4b3a8e89e8ddd0c905 --
2.27.0
PATCH 1/14 net: atlantic: Remove obsolete 32-bit DMA mask fallback
The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure still aborts initialization.
--- drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/aquantia/atlantic/aq_pci_func.c +0 -2
@@ -125,8 +125,6 @@ static int aq_pci_func_init(struct pci_dev *pdev)int err; err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); -if (err) - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));if (err) { err = -ENOSR ; goto err_exit;
Signature · 1 line
2.27.0
PATCH 2/14 net: alx: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/atheros/alx/main.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
drivers/net/ethernet/atheros/alx/main.c +5 -8
@@ -1727,15 +1727,12 @@ static int alx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)* shared register for the high 32 bits, so only a single, aligned, * 4 GB physical address range can be used for descriptors. */ -if (!dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ))) { -dev_dbg (&pdev->dev,"DMA to 64-BIT addresses\n" ); - }else { - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"No usable DMA config, aborting\n" ); - goto out_pci_disable; - } + err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); +if (err) { +dev_err (&pdev->dev,"No usable DMA config, aborting\n" ); + goto out_pci_disable; } +dev_dbg (&pdev->dev,"DMA to 64-BIT addresses\n" ); err =pci_request_mem_regions (pdev, alx_drv_name);if (err) {
Signature · 1 line
2.27.0
PATCH 3/14 net: systemport: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/broadcom/bcmsysport.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/broadcom/bcmsysport.c +0 -2
@@ -2453,8 +2453,6 @@ static int bcm_sysport_probe(struct platform_device *pdev)return -EINVAL ; ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 )); -if (ret) - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));if (ret) {dev_err (&pdev->dev,"unable to set DMA mask: %d\n" , ret);return ret;
Signature · 1 line
2.27.0
PATCH 4/14 bnxt_en: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt.c +2 -2
@@ -15610,8 +15610,8 @@ static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) goto init_err_disable; } -if (dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )) !=0 && -dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )) !=0 ) { + rc =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); +if (rc) {dev_err (&pdev->dev,"System does not support DMA, aborting\n" ); rc = -EIO ; goto init_err_release;
Signature · 1 line
2.27.0
PATCH 5/14 enic: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. A successful setup now necessarily uses the 47-bit mask, so remove the redundant using_dac flag and advertise NETIF_F_HIGHDMA directly.
--- drivers/net/ethernet/cisco/enic/enic_main.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
drivers/net/ethernet/cisco/enic/enic_main.c +4 -15
@@ -2991,7 +2991,6 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)struct device *dev = &pdev->dev;struct net_device *netdev;struct enic *enic; -int using_dac =0 ;unsigned int i;int err;#ifdef CONFIG_PCI_IOV
@@ -3033,20 +3032,11 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)pci_set_master (pdev); -/* Query PCI controller on system for DMA addressing -* limitation for the device. Try 47-bit first, and -* fail to 32-bit. -*/ - +/* The device supports DMA addresses up to 47 bits. */ err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (47 ));if (err) { - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (dev,"No usable DMA configuration, aborting\n" ); - goto err_out_release_regions; - } - }else { - using_dac =1 ; +dev_err (dev,"No usable DMA configuration, aborting\n" ); + goto err_out_release_regions; }/* Map vNIC resources from BAR0-5
@@ -3319,8 +3309,7 @@ static int enic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) netdev->hw_features |=NETIF_F_NTUPLE ;#endif -if (using_dac) - netdev->features |=NETIF_F_HIGHDMA ; + netdev->features |=NETIF_F_HIGHDMA ; netdev->priv_flags |=IFF_UNICAST_FLT ;
Signature · 1 line
2.27.0
PATCH 6/14 net: hns3: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c +2 -7
@@ -9156,13 +9156,8 @@ static int hclge_pci_init(struct hclge_dev *hdev) ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (ret) { - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (ret) { -dev_err (&pdev->dev, -"can't set consistent PCI DMA\n" ); - goto err_disable_device; - } -dev_warn (&pdev->dev,"set DMA mask to 32 bits\n" ); +dev_err (&pdev->dev,"can't set consistent PCI DMA\n" ); + goto err_disable_device; } ret =pci_request_regions (pdev,HCLGE_DRIVER_NAME );
Signature · 1 line
2.27.0
PATCH 7/14 fm10k: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/intel/fm10k/fm10k_pci.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/intel/fm10k/fm10k_pci.c +0 -2
@@ -2111,8 +2111,6 @@ static int fm10k_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (48 )); -if (err) - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));if (err) {dev_err (&pdev->dev,"DMA configuration failed: %d\n" , err);
Signature · 1 line
2.27.0
PATCH 8/14 net/mlx4: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/mellanox/mlx4/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx4/main.c +2 -6
@@ -3863,12 +3863,8 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data, err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { -dev_warn (&pdev->dev,"Warning: couldn't set 64-bit PCI DMA mask\n" ); - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); - goto err_release_regions; - } +dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); + goto err_release_regions; }/* Allow large DMA segments, up to the firmware limit of 1 GB */
Signature · 1 line
2.27.0
Re: [PATCH net-next 08/14] net/mlx4: Remove obsolete 32-bit DMA mask fallback
Quoted 8 lines · Ruizhe Zhou
The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilitiesRemove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
You also switched dev_warn into dev_err.
Patch LGTM.
Quoted 26 lines
Signed-off-by Ruizhe Zhou <[email protected]>--- drivers/net/ethernet/mellanox/mlx4/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/net/ethernet/mellanox/mlx4/main.c +2
-6@@ -3863,12 +3863,8 @@ static int __mlx4_init_one(struct pci_dev *pdev, int pci_dev_data, err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { -dev_warn (&pdev->dev,"Warning: couldn't set 64-bit PCI DMA mask\n" ); - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); - goto err_release_regions; - } +dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); + goto err_release_regions; }/* Allow large DMA segments, up to the firmware limit of 1 GB */
PATCH 9/14 net/mlx5: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/main.c +2 -6
@@ -184,12 +184,8 @@ static int set_dma_caps(struct pci_dev *pdev) err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { -dev_warn (&pdev->dev,"Warning: couldn't set 64-bit PCI DMA mask\n" ); - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); -return err; - } +dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); +return err; }dma_set_max_seg_size (&pdev->dev,2u *1024 *1024 *1024 );
Signature · 1 line
2.27.0
Re: [PATCH net-next 09/14] net/mlx5: Remove obsolete 32-bit DMA mask fallback
Quoted 22 lines · Ruizhe Zhou
The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilitiesRemove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
Signed-off-by Ruizhe Zhou <[email protected]>--- drivers/net/ethernet/mellanox/mlx5/core/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)drivers/net/ethernet/mellanox/mlx5/core/main.c +0
-1@@ -184,12 +184,8 @@ static int set_dma_caps(struct pci_dev *pdev) err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { -dev_warn (&pdev->dev,"Warning: couldn't set 64-bit PCI DMA mask\n" );
drivers/net/ethernet/mellanox/mlx5/core/main.c static int set_dma_caps(struct pci_dev *pdev) · line 191
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/main.c +2
-5- err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); -return err; - } +dev_err (&pdev->dev,"Can't set PCI DMA mask, aborting\n" ); +return err; }dma_set_max_seg_size (&pdev->dev,2u *1024 *1024 *1024 );
PATCH 10/14 mlxsw: pci: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Update the error message to identify the combined streaming and coherent DMA mask operation.
--- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/pci.c +2 -5
@@ -2429,11 +2429,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { - err =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"dma_set_mask failed\n" ); - goto err_pci_set_dma_mask; - } +dev_err (&pdev->dev,"dma_set_mask_and_coherent failed\n" ); + goto err_pci_set_dma_mask; }if (pci_resource_len (pdev,0 ) <MLXSW_PCI_BAR0_SIZE ) {
Signature · 1 line
2.27.0
Re: [PATCH net-next 10/14] mlxsw: pci: Remove obsolete 32-bit DMA mask fallback
Quoted 11 lines · Ruizhe Zhou
The DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilitiesRemove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. Update the error message to identify the combined streaming and coherent DMA mask operation.
Signed-off-by Ruizhe Zhou <[email protected]>
Doco: "dma_set_mask_and_coherent() never return fail when DMA_BIT_MASK(64)."
Checking code, the only way that I see that dma_set_mask_and_coherent() returns error is if dma_supported() returns 0. This could happen if:
- use_dma_iommu() fails, but that doesn't consider mask, so retrying with 32 doesn't help.
- if ops->dma_supported fails. But I checked several architectures where mlxsw could even theoretically be relevant, and it's basically always some mask > X type of expression, so retrying with a smaller mask does not help.
- The fallback of dma_direct_supported() is like that as well.
So yeah. I think this is correct.
Quoted 22 lines
--- drivers/net/ethernet/mellanox/mlxsw/pci.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/net/ethernet/mellanox/mlxsw/pci.c +2
-5@@ -2429,11 +2429,8 @@ static int mlxsw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ));if (err) { - err =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"dma_set_mask failed\n" ); - goto err_pci_set_dma_mask; - } +dev_err (&pdev->dev,"dma_set_mask_and_coherent failed\n" ); + goto err_pci_set_dma_mask; }if (pci_resource_len (pdev,0 ) <MLXSW_PCI_BAR0_SIZE ) {
PATCH 11/14 eth: fbnic: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/meta/fbnic/fbnic_pci.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/ethernet/meta/fbnic/fbnic_pci.c +0 -2
@@ -276,8 +276,6 @@ static int fbnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent) } err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (46 )); -if (err) - err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 ));if (err) {dev_err (&pdev->dev,"DMA configuration failed: %d\n" , err);return err;
Signature · 1 line
2.27.0
PATCH 12/14 net: pch_gbe: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a 64-bit request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization.
--- drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +4 -6
@@ -2504,12 +2504,10 @@ static int pch_gbe_probe(struct pci_dev *pdev,if (ret)return ret; -if (dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ))) { - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (ret) { -dev_err (&pdev->dev,"ERR: No usable DMA configuration, aborting\n" ); -return ret; - } + ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); +if (ret) { +dev_err (&pdev->dev,"ERR: No usable DMA configuration, aborting\n" ); +return ret; } ret =pcim_iomap_regions (pdev,1 <<PCH_GBE_PCI_BAR ,pci_name (pdev));
Signature · 1 line
2.27.0
[email protected]
AI reviewRe: [PATCH net-next 12/14] net: pch_gbe: Remove obsolete 32-bit DMA mask fallback
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Critical: 0 · High: 1 · Medium: 0 · Low: 0
- [High] pch_gbe (Intel EG20T / OKI ML7223/ML7831 GbE) is a 32-bit-DMA- only controller, but after this patch pch_gbe_probe() requests…
--
net: pch_gbe: Remove obsolete 32-bit DMA mask fallback
This removes the DMA_BIT_MASK(32) retry in pch_gbe_probe() and keeps only the DMA_BIT_MASK(64) request, on the grounds that the DMA API guarantees masks of 32 bits or wider and that retrying a narrower mask is incorrect. The error check and dev_err() are retained.
Quoted 9 lines
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +0
-1@@ -2504,12 +2504,10 @@ static int pch_gbe_probe(struct pci_dev *pdev,if (ret)return ret; -if (dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 ))) {
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c static int pch_gbe_probe(struct pci_dev *pdev, · line 2511
Quoted 10 lines
drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c +4
-5- ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (ret) { -dev_err (&pdev->dev,"ERR: No usable DMA configuration, aborting\n" ); -return ret; - } + ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (64 )); +if (ret) { +dev_err (&pdev->dev,"ERR: No usable DMA configuration, aborting\n" ); +return ret; }
[Severity: High]
Can this device actually address 64 bits? After this change the 64-bit request is the only mask pch_gbe_probe() ever installs, and the fallback that used to leave the device with a 32-bit mask is gone.
The descriptors in pch_gbe.h only carry a 32-bit address:
struct pch_gbe_rx_desc {
u32 buffer_addr;
...
};
struct pch_gbe_tx_desc {
u32 buffer_addr;
...
};and the ring registers in struct pch_gbe_regs are 32-bit with no companion high-address register:
u32 RX_DSC_BASE; u32 RX_DSC_SIZE; ... u32 TX_DSC_BASE;
pch_gbe_configure_tx() narrows the coherent ring address into a u32 local and programs it with one iowrite32():
u32 tdba, tdlen, dctrl; ... tdba = adapter->tx_ring->dma; tdlen = adapter->tx_ring->size - 0x10; iowrite32(tdba, &hw->reg->TX_DSC_BASE); iowrite32(tdlen, &hw->reg->TX_DSC_SIZE); iowrite32(tdba, &hw->reg->TX_DSC_SW_P);
pch_gbe_configure_rx() does the same with rdba, and the per-packet paths store dma_addr_t straight into the u32 descriptor fields:
pch_gbe_tx_queue(): tx_desc->buffer_addr = (buffer_info->dma); pch_gbe_alloc_rx_buffers(): rx_desc->buffer_addr = (buffer_info->dma);
There is no lower_32_bits()/upper_32_bits() handling anywhere in the driver. With a 64-bit mask declared, dma_alloc_coherent() and dma_map_single() may return addresses above 4 GB, which are then silently truncated into these u32 fields and registers. Does that leave the MAC bus-mastering to the truncated address, writing received frames into unrelated memory, transmitting unrelated memory, or walking a bogus descriptor ring, with nothing reported?
Since dma_direct_supported() accepts any mask of 32 bits or wider, the 64-bit request always succeeds under direct mapping, so this looks like the live path rather than a theoretical one. The driver is buildable for MIPS_GENERIC and X86_32 (dma_addr_t is 64-bit with PAE) as well as COMPILE_TEST:
depends on PCI && (MIPS_GENERIC || X86_32 || COMPILE_TEST)
Would requesting DMA_BIT_MASK(32) here, i.e. the width the hardware actually implements, be the right way to apply the cited dma-api-howto guidance instead of keeping the 64-bit request?
One smaller point on the changelog. It says the error check is retained "so that a genuine DMA setup failure is still reported and aborts initialization", but by the same premise quoted just above it ("The DMA API guarantees support for masks of 32 bits or wider"), can that dev_err()/return ret branch ever be taken for a mask of 32 bits or wider?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260903084339.870562-1-zhouruizhe%40resnics.com
PATCH 13/14 net: renesas: rswitch: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure still aborts initialization.
--- drivers/net/ethernet/renesas/rswitch_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/renesas/rswitch_main.c +2 -5
@@ -2162,11 +2162,8 @@ static int renesas_eth_sw_probe(struct platform_device *pdev)return -ENOMEM ; ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 )); -if (ret <0 ) { - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (ret <0 ) -return ret; - } +if (ret) +return ret; priv->gwca.index =AGENT_INDEX_GWCA ; priv->gwca.num_queues = min(RSWITCH_NUM_PORTS * NUM_QUEUES_PER_NDEV,
Signature · 1 line
2.27.0
Re: [PATCH net-next 13/14] net: renesas: rswitch: Remove obsolete 32-bit DMA mask fallback
Hi Ruizhe,
Thanks for your patch!
Quoted 1 line · Ruizhe Zhou
The DMA API guarantees support for masks of 32 bits or wider and
Really?
Quoted 3 lines
explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
AFAIUI, that is only true iff the wider request is DMA_BIT_MASK(64).
Quoted 2 lines
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure still aborts initialization.
Have you tested this on actual hardware, with/without IOMMU support?
Quoted 13 lines
Signed-off-by Ruizhe Zhou <[email protected]>--- drivers/net/ethernet/renesas/rswitch_main.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)drivers/net/ethernet/renesas/rswitch_main.c +0
-0@@ -2162,11 +2162,8 @@ static int renesas_eth_sw_probe(struct platform_device *pdev)return -ENOMEM ; ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 ));
drivers/net/ethernet/renesas/rswitch_main.c static int renesas_eth_sw_probe(struct platform_device *pdev) · line 2169
Quoted 10 lines
drivers/net/ethernet/renesas/rswitch_main.c +2
-5-if (ret <0 ) { - ret =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (32 )); -if (ret <0 ) -return ret; - } +if (ret) +return ret; priv->gwca.index =AGENT_INDEX_GWCA ; priv->gwca.num_queues = min(RSWITCH_NUM_PORTS * NUM_QUEUES_PER_NDEV,
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds
PATCH 14/14 net: niu: Remove obsolete 32-bit DMA mask fallback
In reply to Ruizhe ZhouThe DMA API guarantees support for masks of 32 bits or wider and explicitly identifies retrying a 32-bit mask after a wider request as incorrect:
https://docs.kernel.org/core-api/dma-api-howto.html#dma-addressing-capabilities
Remove the obsolete fallback while retaining the error check so that a genuine DMA setup failure is still reported and aborts initialization. A successful setup now necessarily uses the 44-bit mask, so advertise NETIF_F_HIGHDMA directly after checking the result.
--- drivers/net/ethernet/sun/niu.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/ethernet/sun/niu.c +3 -7
@@ -9835,15 +9835,11 @@ static int niu_pci_init_one(struct pci_dev *pdev, PCI_EXP_DEVCTL_RELAX_EN); err =dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (44 )); -if (!err) - dev->features |=NETIF_F_HIGHDMA ;if (err) { - err =dma_set_mask (&pdev->dev,DMA_BIT_MASK (32 )); -if (err) { -dev_err (&pdev->dev,"No usable DMA configuration, aborting\n" ); - goto err_out_release_parent; - } +dev_err (&pdev->dev,"No usable DMA configuration, aborting\n" ); + goto err_out_release_parent; } + dev->features |=NETIF_F_HIGHDMA ;niu_set_basic_features (dev);
Signature · 1 line
2.27.0
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 14 lines · On Thu, 3 Sep 2026 16:43:25 +0800 you wrote:
A lot of Ethernet drivers set a >32 bit DMA mask and retry with a 32-bit mask if the first call fails. This treats the return value of
dma_set_mask_and_coherent()as an indication that the platform requires a narrower DMA width.That is not a correct interpretation of
dma_set_mask_and_coherent(). The mask describes the DMA addresses the device can accept and constrains subsequent mappings to that range. A wider mask includes every address permitted by a 32-bit mask, including addresses from a platform that only produces 32-bit DMA addresses. Retrying with 32 bits therefore adds a stricter constraint and cannot correct a failure to establish the wider mask. The DMA API HOWTO explicitly calls this fallback pattern incorrect [1]. See [2] and [3] for details.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,01/14] net: atlantic: Remove obsolete 32-bit DMA mask fallback
https://git.kernel.org/netdev/net-next/c/78113e4c4002 - [net-next,02/14] net: alx: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/fc5a6ed4992c - [net-next,03/14] net: systemport: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/12a924aebcf5 - [net-next,04/14] bnxt_en: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/f60b86ea8864 - [net-next,05/14] enic: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/0b861b6ee2ec - [net-next,06/14] net: hns3: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/e7d0cff7773b - [net-next,07/14] fm10k: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/f7cf8452c58f - [net-next,08/14] net/mlx4: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/ee95313d1aef - [net-next,09/14] net/mlx5: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/7b85fba09ebe - [net-next,10/14] mlxsw: pci: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/68161cab4810 - [net-next,11/14] eth: fbnic: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/453248082a5d - [net-next,12/14] net: pch_gbe: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/85996f110325 - [net-next,13/14] net: renesas: rswitch: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/0a8bc1ad90ad - [net-next,14/14] net: niu: Remove obsolete 32-bit DMA mask fallback https://git.kernel.org/netdev/net-next/c/03011820f02f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html