* [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
[not found] <20230922091138.18014-1-linyunsheng@huawei.com>
@ 2023-09-22 9:11 ` Yunsheng Lin
2023-10-03 7:45 ` Paolo Abeni
0 siblings, 1 reply; 7+ messages in thread
From: Yunsheng Lin @ 2023-09-22 9:11 UTC (permalink / raw)
To: davem, kuba, pabeni
Cc: netdev, linux-kernel, Yunsheng Lin, Lorenzo Bianconi,
Alexander Duyck, Liang Chen, Alexander Lobakin, Guillaume Tucker,
Matthew Wilcox, Linux-MM, Jesper Dangaard Brouer,
Ilias Apalodimas, Eric Dumazet
Currently page_pool_alloc_frag() is not supported in 32-bit
arch with 64-bit DMA because of the overlap issue between
pp_frag_count and dma_addr_upper in 'struct page' for those
arches, which seems to be quite common, see [1], which means
driver may need to handle it when using fragment API.
It is assumed that the combination of the above arch with an
address space >16TB does not exist, as all those arches have
64b equivalent, it seems logical to use the 64b version for a
system with a large address space. It is also assumed that dma
address is page aligned when we are dma mapping a page aligned
buffer, see [2].
That means we're storing 12 bits of 0 at the lower end for a
dma address, we can reuse those bits for the above arches to
support 32b+12b, which is 16TB of memory.
If we make a wrong assumption, a warning is emitted so that
user can report to us.
1. https://lore.kernel.org/all/20211117075652.58299-1-linyunsheng@huawei.com/
2. https://lore.kernel.org/all/20230818145145.4b357c89@kernel.org/
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
CC: Lorenzo Bianconi <lorenzo@kernel.org>
CC: Alexander Duyck <alexander.duyck@gmail.com>
CC: Liang Chen <liangchen.linux@gmail.com>
CC: Alexander Lobakin <aleksander.lobakin@intel.com>
CC: Guillaume Tucker <guillaume.tucker@collabora.com>
CC: Matthew Wilcox <willy@infradead.org>
CC: Linux-MM <linux-mm@kvack.org>
---
include/linux/mm_types.h | 13 +------------
include/net/page_pool/helpers.h | 20 ++++++++++++++------
net/core/page_pool.c | 14 +++++++++-----
3 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 36c5b43999e6..74b49c4c7a52 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -125,18 +125,7 @@ struct page {
struct page_pool *pp;
unsigned long _pp_mapping_pad;
unsigned long dma_addr;
- union {
- /**
- * dma_addr_upper: might require a 64-bit
- * value on 32-bit architectures.
- */
- unsigned long dma_addr_upper;
- /**
- * For frag page support, not supported in
- * 32-bit architectures with 64-bit DMA.
- */
- atomic_long_t pp_frag_count;
- };
+ atomic_long_t pp_frag_count;
};
struct { /* Tail pages of compound page */
unsigned long compound_head; /* Bit zero is set */
diff --git a/include/net/page_pool/helpers.h b/include/net/page_pool/helpers.h
index 94231533a369..8e1c85de4995 100644
--- a/include/net/page_pool/helpers.h
+++ b/include/net/page_pool/helpers.h
@@ -197,7 +197,7 @@ static inline void page_pool_recycle_direct(struct page_pool *pool,
page_pool_put_full_page(pool, page, true);
}
-#define PAGE_POOL_DMA_USE_PP_FRAG_COUNT \
+#define PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA \
(sizeof(dma_addr_t) > sizeof(unsigned long))
/**
@@ -211,17 +211,25 @@ static inline dma_addr_t page_pool_get_dma_addr(struct page *page)
{
dma_addr_t ret = page->dma_addr;
- if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT)
- ret |= (dma_addr_t)page->dma_addr_upper << 16 << 16;
+ if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA)
+ ret <<= PAGE_SHIFT;
return ret;
}
-static inline void page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
+static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr)
{
+ if (PAGE_POOL_32BIT_ARCH_WITH_64BIT_DMA) {
+ page->dma_addr = addr >> PAGE_SHIFT;
+
+ /* We assume page alignment to shave off bottom bits,
+ * if this "compression" doesn't work we need to drop.
+ */
+ return addr != (dma_addr_t)page->dma_addr << PAGE_SHIFT;
+ }
+
page->dma_addr = addr;
- if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT)
- page->dma_addr_upper = upper_32_bits(addr);
+ return false;
}
static inline bool page_pool_put(struct page_pool *pool)
diff --git a/net/core/page_pool.c b/net/core/page_pool.c
index 77cb75e63aca..8a9868ea5067 100644
--- a/net/core/page_pool.c
+++ b/net/core/page_pool.c
@@ -211,10 +211,6 @@ static int page_pool_init(struct page_pool *pool,
*/
}
- if (PAGE_POOL_DMA_USE_PP_FRAG_COUNT &&
- pool->p.flags & PP_FLAG_PAGE_FRAG)
- return -EINVAL;
-
#ifdef CONFIG_PAGE_POOL_STATS
pool->recycle_stats = alloc_percpu(struct page_pool_recycle_stats);
if (!pool->recycle_stats)
@@ -359,12 +355,20 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page)
if (dma_mapping_error(pool->p.dev, dma))
return false;
- page_pool_set_dma_addr(page, dma);
+ if (page_pool_set_dma_addr(page, dma))
+ goto unmap_failed;
if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV)
page_pool_dma_sync_for_device(pool, page, pool->p.max_len);
return true;
+
+unmap_failed:
+ WARN_ON_ONCE("unexpected DMA address, please report to netdev@");
+ dma_unmap_page_attrs(pool->p.dev, dma,
+ PAGE_SIZE << pool->p.order, pool->p.dma_dir,
+ DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING);
+ return false;
}
static void page_pool_set_pp_info(struct page_pool *pool,
--
2.33.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-09-22 9:11 ` [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA Yunsheng Lin
@ 2023-10-03 7:45 ` Paolo Abeni
2023-10-03 9:40 ` Ilias Apalodimas
2023-10-03 22:12 ` Jakub Kicinski
0 siblings, 2 replies; 7+ messages in thread
From: Paolo Abeni @ 2023-10-03 7:45 UTC (permalink / raw)
To: Yunsheng Lin, davem, kuba
Cc: netdev, linux-kernel, Lorenzo Bianconi, Alexander Duyck,
Liang Chen, Alexander Lobakin, Guillaume Tucker, Matthew Wilcox,
Linux-MM, Jesper Dangaard Brouer, Ilias Apalodimas, Eric Dumazet
On Fri, 2023-09-22 at 17:11 +0800, Yunsheng Lin wrote:
> Currently page_pool_alloc_frag() is not supported in 32-bit
> arch with 64-bit DMA because of the overlap issue between
> pp_frag_count and dma_addr_upper in 'struct page' for those
> arches, which seems to be quite common, see [1], which means
> driver may need to handle it when using fragment API.
>
> It is assumed that the combination of the above arch with an
> address space >16TB does not exist, as all those arches have
> 64b equivalent, it seems logical to use the 64b version for a
> system with a large address space. It is also assumed that dma
> address is page aligned when we are dma mapping a page aligned
> buffer, see [2].
>
> That means we're storing 12 bits of 0 at the lower end for a
> dma address, we can reuse those bits for the above arches to
> support 32b+12b, which is 16TB of memory.
>
> If we make a wrong assumption, a warning is emitted so that
> user can report to us.
>
> 1. https://lore.kernel.org/all/20211117075652.58299-1-linyunsheng@huawei.com/
> 2. https://lore.kernel.org/all/20230818145145.4b357c89@kernel.org/
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> CC: Lorenzo Bianconi <lorenzo@kernel.org>
> CC: Alexander Duyck <alexander.duyck@gmail.com>
> CC: Liang Chen <liangchen.linux@gmail.com>
> CC: Alexander Lobakin <aleksander.lobakin@intel.com>
> CC: Guillaume Tucker <guillaume.tucker@collabora.com>
> CC: Matthew Wilcox <willy@infradead.org>
> CC: Linux-MM <linux-mm@kvack.org>
> ---
> include/linux/mm_types.h | 13 +------------
> include/net/page_pool/helpers.h | 20 ++++++++++++++------
> net/core/page_pool.c | 14 +++++++++-----
> 3 files changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> index 36c5b43999e6..74b49c4c7a52 100644
> --- a/include/linux/mm_types.h
> +++ b/include/linux/mm_types.h
> @@ -125,18 +125,7 @@ struct page {
> struct page_pool *pp;
> unsigned long _pp_mapping_pad;
> unsigned long dma_addr;
> - union {
> - /**
> - * dma_addr_upper: might require a 64-bit
> - * value on 32-bit architectures.
> - */
> - unsigned long dma_addr_upper;
> - /**
> - * For frag page support, not supported in
> - * 32-bit architectures with 64-bit DMA.
> - */
> - atomic_long_t pp_frag_count;
> - };
> + atomic_long_t pp_frag_count;
> };
> struct { /* Tail pages of compound page */
> unsigned long compound_head; /* Bit zero is set */
As noted by Jesper, since this is touching the super-critcal struct
page, an explicit ack from the mm people is required.
@Matthew: could you please have a look?
I think it would be nice also an explicit ack from Jesper and/or Ilias.
Cheers,
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-10-03 7:45 ` Paolo Abeni
@ 2023-10-03 9:40 ` Ilias Apalodimas
2023-10-03 22:12 ` Jakub Kicinski
1 sibling, 0 replies; 7+ messages in thread
From: Ilias Apalodimas @ 2023-10-03 9:40 UTC (permalink / raw)
To: Paolo Abeni
Cc: Yunsheng Lin, davem, kuba, netdev, linux-kernel,
Lorenzo Bianconi, Alexander Duyck, Liang Chen, Alexander Lobakin,
Guillaume Tucker, Matthew Wilcox, Linux-MM,
Jesper Dangaard Brouer, Eric Dumazet
Hi Paolo
On Tue, 3 Oct 2023 at 10:46, Paolo Abeni <pabeni@redhat.com> wrote:
>
> On Fri, 2023-09-22 at 17:11 +0800, Yunsheng Lin wrote:
> > Currently page_pool_alloc_frag() is not supported in 32-bit
> > arch with 64-bit DMA because of the overlap issue between
> > pp_frag_count and dma_addr_upper in 'struct page' for those
> > arches, which seems to be quite common, see [1], which means
> > driver may need to handle it when using fragment API.
> >
> > It is assumed that the combination of the above arch with an
> > address space >16TB does not exist, as all those arches have
> > 64b equivalent, it seems logical to use the 64b version for a
> > system with a large address space. It is also assumed that dma
> > address is page aligned when we are dma mapping a page aligned
> > buffer, see [2].
> >
> > That means we're storing 12 bits of 0 at the lower end for a
> > dma address, we can reuse those bits for the above arches to
> > support 32b+12b, which is 16TB of memory.
> >
> > If we make a wrong assumption, a warning is emitted so that
> > user can report to us.
> >
> > 1. https://lore.kernel.org/all/20211117075652.58299-1-linyunsheng@huawei.com/
> > 2. https://lore.kernel.org/all/20230818145145.4b357c89@kernel.org/
> >
> > Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> > Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
> > CC: Lorenzo Bianconi <lorenzo@kernel.org>
> > CC: Alexander Duyck <alexander.duyck@gmail.com>
> > CC: Liang Chen <liangchen.linux@gmail.com>
> > CC: Alexander Lobakin <aleksander.lobakin@intel.com>
> > CC: Guillaume Tucker <guillaume.tucker@collabora.com>
> > CC: Matthew Wilcox <willy@infradead.org>
> > CC: Linux-MM <linux-mm@kvack.org>
> > ---
> > include/linux/mm_types.h | 13 +------------
> > include/net/page_pool/helpers.h | 20 ++++++++++++++------
> > net/core/page_pool.c | 14 +++++++++-----
> > 3 files changed, 24 insertions(+), 23 deletions(-)
> >
> > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
> > index 36c5b43999e6..74b49c4c7a52 100644
> > --- a/include/linux/mm_types.h
> > +++ b/include/linux/mm_types.h
> > @@ -125,18 +125,7 @@ struct page {
> > struct page_pool *pp;
> > unsigned long _pp_mapping_pad;
> > unsigned long dma_addr;
> > - union {
> > - /**
> > - * dma_addr_upper: might require a 64-bit
> > - * value on 32-bit architectures.
> > - */
> > - unsigned long dma_addr_upper;
> > - /**
> > - * For frag page support, not supported in
> > - * 32-bit architectures with 64-bit DMA.
> > - */
> > - atomic_long_t pp_frag_count;
> > - };
> > + atomic_long_t pp_frag_count;
> > };
> > struct { /* Tail pages of compound page */
> > unsigned long compound_head; /* Bit zero is set */
>
> As noted by Jesper, since this is touching the super-critcal struct
> page, an explicit ack from the mm people is required.
>
> @Matthew: could you please have a look?
>
> I think it would be nice also an explicit ack from Jesper and/or Ilias.
I am trying! Unfortunately, it's this time of the year when I have to
travel a lot. I'll be back in 15 days from now and I will be able to
have a look
Thanks and sorry for the delay
/Ilias
>
> Cheers,
>
> Paolo
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-10-03 7:45 ` Paolo Abeni
2023-10-03 9:40 ` Ilias Apalodimas
@ 2023-10-03 22:12 ` Jakub Kicinski
2023-10-04 9:31 ` Alexander Lobakin
1 sibling, 1 reply; 7+ messages in thread
From: Jakub Kicinski @ 2023-10-03 22:12 UTC (permalink / raw)
To: Alexander Duyck, Alexander Lobakin
Cc: Paolo Abeni, Yunsheng Lin, davem, netdev, linux-kernel,
Lorenzo Bianconi, Liang Chen, Guillaume Tucker, Matthew Wilcox,
Linux-MM, Jesper Dangaard Brouer, Ilias Apalodimas, Eric Dumazet
On Tue, 03 Oct 2023 09:45:56 +0200 Paolo Abeni wrote:
> I think it would be nice also an explicit ack from Jesper and/or Ilias.
Also a review tag from one or both of the Alexanders would be great!
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-10-03 22:12 ` Jakub Kicinski
@ 2023-10-04 9:31 ` Alexander Lobakin
2023-10-08 9:36 ` Yunsheng Lin
0 siblings, 1 reply; 7+ messages in thread
From: Alexander Lobakin @ 2023-10-04 9:31 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Alexander Duyck, Paolo Abeni, Yunsheng Lin, davem, netdev,
linux-kernel, Lorenzo Bianconi, Liang Chen, Guillaume Tucker,
Matthew Wilcox, Linux-MM, Jesper Dangaard Brouer,
Ilias Apalodimas, Eric Dumazet
From: Jakub Kicinski <kuba@kernel.org>
Date: Tue, 3 Oct 2023 15:12:16 -0700
> On Tue, 03 Oct 2023 09:45:56 +0200 Paolo Abeni wrote:
>> I think it would be nice also an explicit ack from Jesper and/or Ilias.
>
> Also a review tag from one or both of the Alexanders would be great!
I got back to libie/iavf this week, hoping I'll rebase without major
issues and will be able to give a Tested-by as well, will see :>
Thanks,
Olek
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-10-04 9:31 ` Alexander Lobakin
@ 2023-10-08 9:36 ` Yunsheng Lin
2023-10-10 17:49 ` Alexander Lobakin
0 siblings, 1 reply; 7+ messages in thread
From: Yunsheng Lin @ 2023-10-08 9:36 UTC (permalink / raw)
To: Alexander Lobakin, Jakub Kicinski
Cc: Alexander Duyck, Paolo Abeni, davem, netdev, linux-kernel,
Lorenzo Bianconi, Liang Chen, Guillaume Tucker, Matthew Wilcox,
Linux-MM, Jesper Dangaard Brouer, Ilias Apalodimas, Eric Dumazet
On 2023/10/4 17:31, Alexander Lobakin wrote:
> From: Jakub Kicinski <kuba@kernel.org>
> Date: Tue, 3 Oct 2023 15:12:16 -0700
>
>> On Tue, 03 Oct 2023 09:45:56 +0200 Paolo Abeni wrote:
>>> I think it would be nice also an explicit ack from Jesper and/or Ilias.
>>
>> Also a review tag from one or both of the Alexanders would be great!
>
> I got back to libie/iavf this week, hoping I'll rebase without major
> issues and will be able to give a Tested-by as well, will see :>
>
It is great to have some Tested-by tag to confirm that this patchset
works for other driver. Please let me know if there is any problem when
rebasing and testing, thanks.
> Thanks,
> Olek
>
> .
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA
2023-10-08 9:36 ` Yunsheng Lin
@ 2023-10-10 17:49 ` Alexander Lobakin
0 siblings, 0 replies; 7+ messages in thread
From: Alexander Lobakin @ 2023-10-10 17:49 UTC (permalink / raw)
To: Yunsheng Lin
Cc: Jakub Kicinski, Alexander Duyck, Paolo Abeni, davem, netdev,
linux-kernel, Lorenzo Bianconi, Liang Chen, Guillaume Tucker,
Matthew Wilcox, Linux-MM, Jesper Dangaard Brouer,
Ilias Apalodimas, Eric Dumazet
From: Yunsheng Lin <linyunsheng@huawei.com>
Date: Sun, 8 Oct 2023 17:36:59 +0800
> On 2023/10/4 17:31, Alexander Lobakin wrote:
>> From: Jakub Kicinski <kuba@kernel.org>
>> Date: Tue, 3 Oct 2023 15:12:16 -0700
>>
>>> On Tue, 03 Oct 2023 09:45:56 +0200 Paolo Abeni wrote:
>>>> I think it would be nice also an explicit ack from Jesper and/or Ilias.
>>>
>>> Also a review tag from one or both of the Alexanders would be great!
>>
>> I got back to libie/iavf this week, hoping I'll rebase without major
>> issues and will be able to give a Tested-by as well, will see :>
>>
>
> It is great to have some Tested-by tag to confirm that this patchset
> works for other driver. Please let me know if there is any problem when
> rebasing and testing, thanks.
IAVF with PP on the latest net-next from [0]:
Tested-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Still some stuff on my side to fix/improve before submitting a new
revision of libie / PP for IAVF, but at least the current code works
just as expected.
>
>
>> Thanks,
>> Olek
>>
>> .
>>
[0] https://github.com/alobakin/linux/commits/iavf-pp-frag
Thanks,
Olek
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-10-10 17:51 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20230922091138.18014-1-linyunsheng@huawei.com>
2023-09-22 9:11 ` [PATCH net-next v10 1/6] page_pool: fragment API support for 32-bit arch with 64-bit DMA Yunsheng Lin
2023-10-03 7:45 ` Paolo Abeni
2023-10-03 9:40 ` Ilias Apalodimas
2023-10-03 22:12 ` Jakub Kicinski
2023-10-04 9:31 ` Alexander Lobakin
2023-10-08 9:36 ` Yunsheng Lin
2023-10-10 17:49 ` Alexander Lobakin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox