All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Måns Rullgård" <mans@mansr.com>
Cc: Pantelis Antoniou <pantelis.antoniou@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Vitaly Bordug <vbordug@ru.mvista.com>,
	Dan Malek <dan@embeddededge.com>,
	Joakim Tjernlund <joakim.tjernlund@lumentis.se>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] net: fs_enet: sync rx dma buffer before reading
Date: Fri, 20 May 2022 12:54:56 +0000	[thread overview]
Message-ID: <b11dcb32-5915-c1c8-9f0e-3cfc57b55792@csgroup.eu> (raw)
In-Reply-To: <yw1xmtfc9yaj.fsf@mansr.com>



Le 20/05/2022 à 14:35, Måns Rullgård a écrit :
> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> 
>> Le 19/05/2022 à 21:24, Mans Rullgard a écrit :
>>> The dma_sync_single_for_cpu() call must precede reading the received
>>> data. Fix this.
>>
>> See original commit 070e1f01827c. It explicitely says that the cache
>> must be invalidate _AFTER_ the copy.
>>
>> The cache is initialy invalidated by dma_map_single(), so before the
>> copy the cache is already clean.
>>
>> After the copy, data is in the cache. In order to allow re-use of the
>> skb, it must be put back in the same condition as before, in extenso the
>> cache must be invalidated in order to be in the same situation as after
>> dma_map_single().
>>
>> So I think your change is wrong.
> 
> OK, looking at it more closely, the change is at least unnecessary since
> there will be a cache invalidation between each use of the buffer either
> way.  Please disregard the patch.  Sorry for the noise.
> 

I also looked deeper.

Indeed it was implemented in kernel 4.9 or 4.8. At that time 
dma_unmap_single() was a no-op, it was not doing any sync/invalidation 
at all, invalidation was done only at mapping, so when we were reusing 
the skb it was necessary to clean the cache _AFTER_ the copy as if it 
was a new mapping.

Today a sync is done at both map and unmap, so it doesn't really matter 
whether we do the invalidation before or after the copy when we re-use 
the skb.

Christophe

WARNING: multiple messages have this Message-ID (diff)
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: "Måns Rullgård" <mans@mansr.com>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	Dan Malek <dan@embeddededge.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	Vitaly Bordug <vbordug@ru.mvista.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Joakim Tjernlund <joakim.tjernlund@lumentis.se>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH] net: fs_enet: sync rx dma buffer before reading
Date: Fri, 20 May 2022 12:54:56 +0000	[thread overview]
Message-ID: <b11dcb32-5915-c1c8-9f0e-3cfc57b55792@csgroup.eu> (raw)
In-Reply-To: <yw1xmtfc9yaj.fsf@mansr.com>



Le 20/05/2022 à 14:35, Måns Rullgård a écrit :
> Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> 
>> Le 19/05/2022 à 21:24, Mans Rullgard a écrit :
>>> The dma_sync_single_for_cpu() call must precede reading the received
>>> data. Fix this.
>>
>> See original commit 070e1f01827c. It explicitely says that the cache
>> must be invalidate _AFTER_ the copy.
>>
>> The cache is initialy invalidated by dma_map_single(), so before the
>> copy the cache is already clean.
>>
>> After the copy, data is in the cache. In order to allow re-use of the
>> skb, it must be put back in the same condition as before, in extenso the
>> cache must be invalidated in order to be in the same situation as after
>> dma_map_single().
>>
>> So I think your change is wrong.
> 
> OK, looking at it more closely, the change is at least unnecessary since
> there will be a cache invalidation between each use of the buffer either
> way.  Please disregard the patch.  Sorry for the noise.
> 

I also looked deeper.

Indeed it was implemented in kernel 4.9 or 4.8. At that time 
dma_unmap_single() was a no-op, it was not doing any sync/invalidation 
at all, invalidation was done only at mapping, so when we were reusing 
the skb it was necessary to clean the cache _AFTER_ the copy as if it 
was a new mapping.

Today a sync is done at both map and unmap, so it doesn't really matter 
whether we do the invalidation before or after the copy when we re-use 
the skb.

Christophe

  reply	other threads:[~2022-05-20 12:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-19 19:24 [PATCH] net: fs_enet: sync rx dma buffer before reading Mans Rullgard
2022-05-20  5:39 ` Christophe Leroy
2022-05-20 12:35   ` Måns Rullgård
2022-05-20 12:35     ` Måns Rullgård
2022-05-20 12:54     ` Christophe Leroy [this message]
2022-05-20 12:54       ` Christophe Leroy
2022-05-20 17:43       ` Jakub Kicinski
2022-05-20 17:43         ` Jakub Kicinski
2022-05-21  6:44         ` Christophe Leroy
2022-05-21  6:44           ` Christophe Leroy
2022-05-21 17:44           ` Jakub Kicinski
2022-05-21 17:44             ` Jakub Kicinski
2022-05-23 20:23             ` Jakub Kicinski
2022-05-23 20:23               ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b11dcb32-5915-c1c8-9f0e-3cfc57b55792@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=dan@embeddededge.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=joakim.tjernlund@lumentis.se \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mans@mansr.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pantelis.antoniou@gmail.com \
    --cc=vbordug@ru.mvista.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.