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] [thread-next>] [day] [month] [year] [list]
Message-ID: <PH0PR11MB58305CA6B9ECA2005DC315CCD85D2@PH0PR11MB5830.namprd11.prod.outlook.com>
Date: Sat, 2 Mar 2024 04:04:08 +0000
From: "Song, Yoong Siang" <yoong.siang.song@...el.com>
To: John Fastabend <john.fastabend@...il.com>, "Brandeburg, Jesse"
	<jesse.brandeburg@...el.com>, "Nguyen, Anthony L"
	<anthony.l.nguyen@...el.com>, "David S . Miller" <davem@...emloft.net>, "Eric
 Dumazet" <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>, Paolo Abeni
	<pabeni@...hat.com>, Richard Cochran <richardcochran@...il.com>, "Alexei
 Starovoitov" <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
	"Jesper Dangaard Brouer" <hawk@...nel.org>, Stanislav Fomichev
	<sdf@...gle.com>, "Gomes, Vinicius" <vinicius.gomes@...el.com>, "Bezdeka,
 Florian" <florian.bezdeka@...mens.com>, Andrii Nakryiko <andrii@...nel.org>,
	"Eduard Zingerman" <eddyz87@...il.com>, Mykola Lysenko <mykolal@...com>,
	"Martin KaFai Lau" <martin.lau@...ux.dev>, Song Liu <song@...nel.org>,
	Yonghong Song <yonghong.song@...ux.dev>, KP Singh <kpsingh@...nel.org>, Hao
 Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>, Shuah Khan
	<shuah@...nel.org>
CC: "intel-wired-lan@...ts.osuosl.org" <intel-wired-lan@...ts.osuosl.org>,
	"netdev@...r.kernel.org" <netdev@...r.kernel.org>,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"bpf@...r.kernel.org" <bpf@...r.kernel.org>,
	"linux-kselftest@...r.kernel.org" <linux-kselftest@...r.kernel.org>,
	"xdp-hints@...-project.net" <xdp-hints@...-project.net>
Subject: RE: [PATCH iwl-next,v2 2/2] igc: Add Tx hardware timestamp request
 for AF_XDP zero-copy packet

On Saturday, March 2, 2024 1:55 AM, John Fastabend <john.fastabend@...il.com> wrote:
>Song Yoong Siang wrote:
>> This patch adds support to per-packet Tx hardware timestamp request to
>> AF_XDP zero-copy packet via XDP Tx metadata framework. Please note that
>> user needs to enable Tx HW timestamp capability via igc_ioctl() with
>> SIOCSHWTSTAMP cmd before sending xsk Tx hardware timestamp request.
>>
>> Same as implementation in RX timestamp XDP hints kfunc metadata, Timer 0
>> (adjustable clock) is used in xsk Tx hardware timestamp. i225/i226 have
>> four sets of timestamping registers. Both *skb and *xsk_tx_buffer pointers
>> are used to indicate whether the timestamping register is already occupied.
>>
>> Furthermore, a boolean variable named xsk_pending_ts is used to hold the
>> transmit completion until the tx hardware timestamp is ready. This is
>> because, for i225/i226, the timestamp notification event comes some time
>> after the transmit completion event. The driver will retrigger hardware irq
>> to clean the packet after retrieve the tx hardware timestamp.
>>
>> Besides, xsk_meta is added into struct igc_tx_timestamp_request as a hook
>> to the metadata location of the transmit packet. When the Tx timestamp
>> interrupt is fired, the interrupt handler will copy the value of Tx hwts
>> into metadata location via xsk_tx_metadata_complete().
>>
>> Co-developed-by: Lai Peter Jun Ann <jun.ann.lai@...el.com>
>> Signed-off-by: Lai Peter Jun Ann <jun.ann.lai@...el.com>
>> Signed-off-by: Song Yoong Siang <yoong.siang.song@...el.com>
>> ---
>
>[...]
>
>>
>> +static void igc_xsk_request_timestamp(void *_priv)
>> +{
>> +	struct igc_metadata_request *meta_req = _priv;
>> +	struct igc_ring *tx_ring = meta_req->tx_ring;
>> +	struct igc_tx_timestamp_request *tstamp;
>> +	u32 tx_flags = IGC_TX_FLAGS_TSTAMP;
>> +	struct igc_adapter *adapter;
>> +	unsigned long lock_flags;
>> +	bool found = false;
>> +	int i;
>> +
>> +	if (test_bit(IGC_RING_FLAG_TX_HWTSTAMP, &tx_ring->flags)) {
>> +		adapter = netdev_priv(tx_ring->netdev);
>> +
>> +		spin_lock_irqsave(&adapter->ptp_tx_lock, lock_flags);
>> +
>> +		/* Search for available tstamp regs */
>> +		for (i = 0; i < IGC_MAX_TX_TSTAMP_REGS; i++) {
>> +			tstamp = &adapter->tx_tstamp[i];
>> +
>> +			if (tstamp->skb)
>> +				continue;
>> +
>> +			found = true;
>> +			break;
>
>Not how I would have written this loop construct seems a bit odd
>to default break but it works.

Hi John,
First of all, thank you for reviewing the patch.
I agree that we can make the loop better. 
How about I change the loop to below:

for (i = 0; i < IGC_MAX_TX_TSTAMP_REGS; i++) {
	tstamp = &adapter->tx_tstamp[i];

	if (!tstamp->skb) {
		found = true;
		break;
	}
}

>
>> +		}
>> +
>> +		/* Return if no available tstamp regs */
>> +		if (!found) {
>> +			adapter->tx_hwtstamp_skipped++;
>> +			spin_unlock_irqrestore(&adapter->ptp_tx_lock,
>> +					       lock_flags);
>> +			return;
>> +		}
>
>[...]
>
>>
>> +static void igc_ptp_free_tx_buffer(struct igc_adapter *adapter,
>> +				   struct igc_tx_timestamp_request *tstamp)
>> +{
>> +	if (tstamp->buffer_type == IGC_TX_BUFFER_TYPE_XSK) {
>> +		/* Release the transmit completion */
>> +		tstamp->xsk_tx_buffer->xsk_pending_ts = false;
>> +		tstamp->xsk_tx_buffer = NULL;
>> +		tstamp->buffer_type = 0;
>> +
>> +		/* Trigger txrx interrupt for transmit completion */
>> +		igc_xsk_wakeup(adapter->netdev, tstamp->xsk_queue_index, 0);
>
>Just curious because I didn't find it. Fairly sure I just need to look more,
>but don't you want to still 'tstamp->skb = NULL' in this path somewhere?
>It looks like triggering the tx interrupt again with buffer_type == 0 wouldn't
>do the null.
>
>I suspect I just missed it.

Since the timestamp register will only be used by either skb or xsk,
So we make tstamp->xsk_tx_buffer and tstamp->skb as union,
Then based on tstamp->buffer_type to decide whether
tstamp->xsk_tx_buffer or tstamp->skb should be used.

My thought is, by setting tstamp->xsk_tx_buffer=NULL,
tstamp->skb will become NULL as well, and vice versa.

Thanks & Regards
Siang






Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ