lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
 <PAXPR04MB8510FA96CB9A5DE5288902A088E32@PAXPR04MB8510.eurprd04.prod.outlook.com>
Date: Fri, 24 Jan 2025 01:39:46 +0000
From: Wei Fang <wei.fang@....com>
To: Dheeraj Reddy Jonnalagadda <dheeraj.linuxdev@...il.com>
CC: Shenwei Wang <shenwei.wang@....com>, Clark Wang <xiaoning.wang@....com>,
	"andrew+netdev@...n.ch" <andrew+netdev@...n.ch>, "davem@...emloft.net"
	<davem@...emloft.net>, "edumazet@...gle.com" <edumazet@...gle.com>,
	"kuba@...nel.org" <kuba@...nel.org>, "pabeni@...hat.com" <pabeni@...hat.com>,
	"imx@...ts.linux.dev" <imx@...ts.linux.dev>, "netdev@...r.kernel.org"
	<netdev@...r.kernel.org>, "linux-kernel@...r.kernel.org"
	<linux-kernel@...r.kernel.org>, Simon Horman <horms@...nel.org>
Subject: RE: [PATCH net] net: fec: remove unnecessary DMA mapping of TSO
 header

> > Hi Dheeraj,
> >
> > I must admit that I misread it too. There is another case in the TSO
> > header where txq->tx_bounce may be used in some cases. I think
> > the most correct fix is to make txq->tso_hdrs aligned to 32/64 bytes
> > when allocating tso_hdrs, then we do not need to use txq->tx_bounce
> > in fec_enet_txq_put_hdr_tso(), because (bufaddr) & fep->tx_align)
> > will not be true. This way we can safely remove dma_map_single()
> > from fec_enet_txq_put_hdr_tso().
> 
> Hi Fang, Simon,
> 
> Thank you for the feedback. I have a clarification question regarding
> the alignment of txq->tso_hdrs.
> 
> In the current code, txq->tso_hdrs is allocated using fec_dma_alloc(),
> which internally calls dma_alloc_coherent(). As I understand it,
> dma_alloc_coherent() guarantees that the allocated buffer is properly aligned.
> 
> Given this, should we remove the alignment check
> ((unsigned long)bufaddr) & fep->tx_align and the associated dma_map_single()
> logic entirely from fec_enet_txq_put_hdr_tso() as you have suggested?
> 

The maximum of fep->tx_align is 0xf, so we need to ensure the buffer
allocated by dma_alloc_coherent() is at least 16-byte aligned, but I'm
not sure whether dma_alloc_coherent() guarantees this alignment.
A safe approach is to apply for a memory block longer than expected,
for example, if we want the alignment is 32-byte, we can apply for a
memory block that is 32 bytes longer than the expected length. Then
use ALGIN and PTR_ALIGN to get the aligned addr.

txq->tso_hdrs_base = fec_dma_alloc(&fep->pdev->dev,
					     	  txq->bd.ring_size * TSO_HEADER_SIZE + 32,
					     	  &txq->tso_hdrs_dma_base, GFP_KERNEL);
txq->tso_hdrs = PTR_ALIGN(txq->tso_hdrs_base, 32);
txq->tso_hdrs_dma = ALIGN(txq->tso_hdrs_dma_base, 32);

This is just my personal experience, if you have a better way that would
be great.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ