Skip to contentSkip to conversation

page_pool: store detach_time as ktime_t to avoid false-negatives

PATCH Superseded Jakub Kicinski 4 participants 8 messages Mar 7 – Mar 9

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jakub Kicinski

author maintainer
#0 lore raw

PATCH 1/1 page_pool: store detach_time as ktime_t to avoid false-negatives

While testing other changes in vng I noticed that nl_netdev.page_pool_check flakes. This never happens in real CI.

Turns out vng may boot and get to that test in less than a second. page_pool_detached() records the detach time in seconds, so if vng is fast enough detach time is set to 0. Other code treats 0 as "not detached". detach_time is only used to report the state to the user, so it's not a huge deal in practice but let's fix it. Store the raw ktime_t (nanoseconds) instead. A nanosecond value of 0 is practically impossible.

Fixes 69cb4952b6f6 ("net: page_pool: report when page pool was destroyed")

---
CC: [email protected]
CC: [email protected]

---
 include/net/page_pool/types.h | 2 +-
 net/core/page_pool_user.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/page_pool/types.h +1 -1
index 0d453484a585..cdd95477af7a 100644
@@ -247,7 +247,7 @@ struct page_pool {
 	/* User-facing fields, protected by page_pools_lock */
 	struct {
 		struct hlist_node list;
-		u64 detach_time;
+		ktime_t detach_time;
 		u32 id;
 	} user;
 };
net/core/page_pool_user.c +2 -2
index c82a95beceff..fb4ca27358cd 100644
@@ -245,7 +245,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
 		goto err_cancel;
 	if (pool->user.detach_time &&
 	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,
-			 pool->user.detach_time))
+			 ktime_to_seconds(pool->user.detach_time)))
 		goto err_cancel;
 
 	if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
@@ -337,7 +337,7 @@ int page_pool_list(struct page_pool *pool)
 void page_pool_detached(struct page_pool *pool)
 {
 	mutex_lock(&page_pools_lock);
-	pool->user.detach_time = ktime_get_boottime_seconds();
+	pool->user.detach_time = ktime_get_boottime();
 	netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
 	mutex_unlock(&page_pools_lock);
 }
Signature · 1 line
2.53.0
#1 lore raw
Quoted 40 lines · Jakub Kicinski

While testing other changes in vng I noticed that nl_netdev.page_pool_check flakes. This never happens in real CI.

Turns out vng may boot and get to that test in less than a second. page_pool_detached() records the detach time in seconds, so if vng is fast enough detach time is set to 0. Other code treats 0 as "not detached". detach_time is only used to report the state to the user, so it's not a huge deal in practice but let's fix it. Store the raw ktime_t (nanoseconds) instead. A nanosecond value of 0 is practically impossible.

Fixes 69cb4952b6f6 ("net: page_pool: report when page pool was destroyed")

---
CC: [email protected]
CC: [email protected]

---
 include/net/page_pool/types.h | 2 +-
 net/core/page_pool_user.c     | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
include/net/page_pool/types.h +1 -1
index 0d453484a585..cdd95477af7a 100644
@@ -247,7 +247,7 @@ struct page_pool {
        /* User-facing fields, protected by page_pools_lock */
        struct {
                struct hlist_node list;
-               u64 detach_time;
+               ktime_t detach_time;
                u32 id;
        } user;
 };
net/core/page_pool_user.c +0 -0
index c82a95beceff..fb4ca27358cd 100644

net/core/page_pool_user.c page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, · line 245

Quoted 1 line
net/core/page_pool_user.c +0 -0
@@ -245,7 +245,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
                goto err_cancel;

It is a bit unclear if we always hold page_pools_lock at this point.

If not, a READ_ONCE(pool->user.detach_time) here would be needed, and a corresponding WRITE_ONCE() in page_pool_detached()

Quoted 19 lines
net/core/page_pool_user.c +2 -3
        if (pool->user.detach_time &&
            nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,
-                        pool->user.detach_time))
+                        ktime_to_seconds(pool->user.detach_time)))
                goto err_cancel;
 
        if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
@@ -337,7 +337,7 @@ int page_pool_list(struct page_pool *pool)
 void page_pool_detached(struct page_pool *pool)
 {
        mutex_lock(&page_pools_lock);
-       pool->user.detach_time = ktime_get_boottime_seconds();
+       pool->user.detach_time = ktime_get_boottime();
        netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
        mutex_unlock(&page_pools_lock);
 }
--

2.53.0

#3 lore raw
In reply to Jakub Kicinski
kernel test robot noticed the following build errors:

Hi Jakub,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/page_pool-store-detach_time-as-ktime_t-to-avoid-false-negatives/20260308-044057
base:   net/main
patch link:    https://lore.kernel.org/r/20260307204022.1897614-1-kuba%40kernel.org
patch subject: [PATCH net] page_pool: store detach_time as ktime_t to avoid false-negatives
config: mips-decstation_defconfig (https://download.01.org/0day-ci/archive/20260308/[email protected]/config)
compiler: mips-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

net/core/page_pool_user.c: In function 'page_pool_nl_fill':

>> net/core/page_pool_user.c:248:26: error: implicit declaration of function 'ktime_to_seconds'; did you mean 'ktime_get_seconds'? [-Wimplicit-function-declaration]
     248 |                          ktime_to_seconds(pool->user.detach_time)))
         |                          ^~~~~~~~~~~~~~~~
         |                          ktime_get_seconds

vim +248 net/core/page_pool_user.c

214
215 static int
216 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
217 const struct genl_info *info)
218 {
219 size_t inflight, refsz;
220 unsigned int napi_id;
221 void *hdr;
222
223 hdr = genlmsg_iput(rsp, info);
224 if (!hdr)
225 return -EMSGSIZE;
226
227 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_ID, pool->user.id))
228 goto err_cancel;
229
230 if (pool->slow.netdev->ifindex != LOOPBACK_IFINDEX &&
231 nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
232 pool->slow.netdev->ifindex))
233 goto err_cancel;
234
235 napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
236 if (napi_id_valid(napi_id) &&
237 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
238 goto err_cancel;
239
240 inflight = page_pool_inflight(pool, false);
241 refsz = PAGE_SIZE << pool->p.order;
242 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
243 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
244 inflight * refsz))
245 goto err_cancel;
246 if (pool->user.detach_time &&
247 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,

 > 248				 ktime_to_seconds(pool->user.detach_time)))

249 goto err_cancel;
250
251 if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
252 goto err_cancel;
253
254 genlmsg_end(rsp, hdr);
255
256 return 0;
257 err_cancel:
258 genlmsg_cancel(rsp, hdr);
259 return -EMSGSIZE;
260 }
261

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw
In reply to Jakub Kicinski
kernel test robot noticed the following build errors:

Hi Jakub,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/page_pool-store-detach_time-as-ktime_t-to-avoid-false-negatives/20260308-044057
base:   net/main
patch link:    https://lore.kernel.org/r/20260307204022.1897614-1-kuba%40kernel.org
patch subject: [PATCH net] page_pool: store detach_time as ktime_t to avoid false-negatives
config: loongarch-randconfig-001-20260308 (https://download.01.org/0day-ci/archive/20260308/[email protected]/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/core/page_pool_user.c:248:5: error: call to undeclared function 'ktime_to_seconds'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     248 |                          ktime_to_seconds(pool->user.detach_time)))
         |                          ^
   net/core/page_pool_user.c:248:5: note: did you mean 'ktime_get_seconds'?
   include/linux/timekeeping.h:59:17: note: 'ktime_get_seconds' declared here
      59 | extern time64_t ktime_get_seconds(void);
         |                 ^

1 error generated.

vim +/ktime_to_seconds +248 net/core/page_pool_user.c

214
215 static int
216 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
217 const struct genl_info *info)
218 {
219 size_t inflight, refsz;
220 unsigned int napi_id;
221 void *hdr;
222
223 hdr = genlmsg_iput(rsp, info);
224 if (!hdr)
225 return -EMSGSIZE;
226
227 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_ID, pool->user.id))
228 goto err_cancel;
229
230 if (pool->slow.netdev->ifindex != LOOPBACK_IFINDEX &&
231 nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
232 pool->slow.netdev->ifindex))
233 goto err_cancel;
234
235 napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
236 if (napi_id_valid(napi_id) &&
237 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
238 goto err_cancel;
239
240 inflight = page_pool_inflight(pool, false);
241 refsz = PAGE_SIZE << pool->p.order;
242 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
243 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
244 inflight * refsz))
245 goto err_cancel;
246 if (pool->user.detach_time &&
247 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,

 > 248				 ktime_to_seconds(pool->user.detach_time)))

249 goto err_cancel;
250
251 if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
252 goto err_cancel;
253
254 genlmsg_end(rsp, hdr);
255
256 return 0;
257 err_cancel:
258 genlmsg_cancel(rsp, hdr);
259 return -EMSGSIZE;
260 }
261

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Jakub Kicinski
kernel test robot noticed the following build errors:

Hi Jakub,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/page_pool-store-detach_time-as-ktime_t-to-avoid-false-negatives/20260308-044057
base:   net/main
patch link:    https://lore.kernel.org/r/20260307204022.1897614-1-kuba%40kernel.org
patch subject: [PATCH net] page_pool: store detach_time as ktime_t to avoid false-negatives
config: x86_64-kexec (https://download.01.org/0day-ci/archive/20260308/[email protected]/config)
compiler: clang version 20.1.8 (https://github.com/llvm/llvm-project 87f0227cb60147a26a1eeb4fb06e3b505e9c7261)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> net/core/page_pool_user.c:248:5: error: call to undeclared function 'ktime_to_seconds'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
     248 |                          ktime_to_seconds(pool->user.detach_time)))
         |                          ^
   net/core/page_pool_user.c:248:5: note: did you mean 'ktime_get_seconds'?
   include/linux/timekeeping.h:59:17: note: 'ktime_get_seconds' declared here
      59 | extern time64_t ktime_get_seconds(void);
         |                 ^

1 error generated.

vim +/ktime_to_seconds +248 net/core/page_pool_user.c

214
215 static int
216 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
217 const struct genl_info *info)
218 {
219 size_t inflight, refsz;
220 unsigned int napi_id;
221 void *hdr;
222
223 hdr = genlmsg_iput(rsp, info);
224 if (!hdr)
225 return -EMSGSIZE;
226
227 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_ID, pool->user.id))
228 goto err_cancel;
229
230 if (pool->slow.netdev->ifindex != LOOPBACK_IFINDEX &&
231 nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
232 pool->slow.netdev->ifindex))
233 goto err_cancel;
234
235 napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
236 if (napi_id_valid(napi_id) &&
237 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
238 goto err_cancel;
239
240 inflight = page_pool_inflight(pool, false);
241 refsz = PAGE_SIZE << pool->p.order;
242 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
243 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
244 inflight * refsz))
245 goto err_cancel;
246 if (pool->user.detach_time &&
247 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,

 > 248				 ktime_to_seconds(pool->user.detach_time)))

249 goto err_cancel;
250
251 if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
252 goto err_cancel;
253
254 genlmsg_end(rsp, hdr);
255
256 return 0;
257 err_cancel:
258 genlmsg_cancel(rsp, hdr);
259 return -EMSGSIZE;
260 }
261

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw
In reply to Jakub Kicinski
kernel test robot noticed the following build errors:

Hi Jakub,

kernel test robot noticed the following build errors:

[auto build test ERROR on net/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Jakub-Kicinski/page_pool-store-detach_time-as-ktime_t-to-avoid-false-negatives/20260308-044057
base:   net/main
patch link:    https://lore.kernel.org/r/20260307204022.1897614-1-kuba%40kernel.org
patch subject: [PATCH net] page_pool: store detach_time as ktime_t to avoid false-negatives
config: x86_64-rhel-9.4 (https://download.01.org/0day-ci/archive/20260308/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

net/core/page_pool_user.c: In function 'page_pool_nl_fill':

>> net/core/page_pool_user.c:248:26: error: implicit declaration of function 'ktime_to_seconds'; did you mean 'ktime_get_seconds'? [-Wimplicit-function-declaration]
     248 |                          ktime_to_seconds(pool->user.detach_time)))
         |                          ^~~~~~~~~~~~~~~~
         |                          ktime_get_seconds

vim +248 net/core/page_pool_user.c

214
215 static int
216 page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
217 const struct genl_info *info)
218 {
219 size_t inflight, refsz;
220 unsigned int napi_id;
221 void *hdr;
222
223 hdr = genlmsg_iput(rsp, info);
224 if (!hdr)
225 return -EMSGSIZE;
226
227 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_ID, pool->user.id))
228 goto err_cancel;
229
230 if (pool->slow.netdev->ifindex != LOOPBACK_IFINDEX &&
231 nla_put_u32(rsp, NETDEV_A_PAGE_POOL_IFINDEX,
232 pool->slow.netdev->ifindex))
233 goto err_cancel;
234
235 napi_id = pool->p.napi ? READ_ONCE(pool->p.napi->napi_id) : 0;
236 if (napi_id_valid(napi_id) &&
237 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_NAPI_ID, napi_id))
238 goto err_cancel;
239
240 inflight = page_pool_inflight(pool, false);
241 refsz = PAGE_SIZE << pool->p.order;
242 if (nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT, inflight) ||
243 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_INFLIGHT_MEM,
244 inflight * refsz))
245 goto err_cancel;
246 if (pool->user.detach_time &&
247 nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,

 > 248				 ktime_to_seconds(pool->user.detach_time)))

249 goto err_cancel;
250
251 if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
252 goto err_cancel;
253
254 genlmsg_end(rsp, hdr);
255
256 return 0;
257 err_cancel:
258 genlmsg_cancel(rsp, hdr);
259 return -EMSGSIZE;
260 }
261

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#2 lore raw
In reply to Eric Dumazet
Quoted 9 lines · On Sun, 8 Mar 2026 01:10:55 +0100 Eric Dumazet wrote:

net/core/page_pool_user.c page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, · line 245

Quoted 4 lines
net/core/page_pool_user.c +0 -0
@@ -245,7 +245,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
                goto err_cancel;  

It is a bit unclear if we always hold page_pools_lock at this point.

If not, a READ_ONCE(pool->user.detach_time) here would be needed, and a corresponding WRITE_ONCE() in page_pool_detached()

There's a bit of convoluted wrapping to share the code between page pool access and access to stats, but AFAICT page_pools_lock should be consistently held by readers and writers.

maintainer Acked-by on v1 1/1
#7 lore raw
In reply to Jakub Kicinski
Quoted 11 lines · Jakub Kicinski

While testing other changes in vng I noticed that nl_netdev.page_pool_check flakes. This never happens in real CI.

Turns out vng may boot and get to that test in less than a second. page_pool_detached() records the detach time in seconds, so if vng is fast enough detach time is set to 0. Other code treats 0 as "not detached". detach_time is only used to report the state to the user, so it's not a huge deal in practice but let's fix it. Store the raw ktime_t (nanoseconds) instead. A nanosecond value of 0 is practically impossible.

Quoted 4 lines
Fixes 69cb4952b6f6 ("net: page_pool: report when page pool was destroyed")

---
CC: [email protected]

LGTM -- after addressing in build errors... likely a missing include?

Quoted 24 lines
---
  include/net/page_pool/types.h | 2 +-
  net/core/page_pool_user.c     | 4 ++--
  2 files changed, 3 insertions(+), 3 deletions(-)
include/net/page_pool/types.h +1 -1
index 0d453484a585..cdd95477af7a 100644
@@ -247,7 +247,7 @@ struct page_pool {
  	/* User-facing fields, protected by page_pools_lock */
  	struct {
  		struct hlist_node list;
-		u64 detach_time;
+		ktime_t detach_time;
  		u32 id;
  	} user;
  };
net/core/page_pool_user.c +0 -0
index c82a95beceff..fb4ca27358cd 100644

net/core/page_pool_user.c page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool, · line 248

Quoted 5 lines
net/core/page_pool_user.c +1 -1
@@ -245,7 +245,7 @@ page_pool_nl_fill(struct sk_buff *rsp, const struct page_pool *pool,
  		goto err_cancel;
  	if (pool->user.detach_time &&
  	    nla_put_uint(rsp, NETDEV_A_PAGE_POOL_DETACH_TIME,
-			 pool->user.detach_time))
+			 ktime_to_seconds(pool->user.detach_time)))

Hmm.. is this ktime_to_seconds even defined?

A quick look tells me that we could use:

ktime_divns(pool->user.detach_time, NSEC_PER_SEC)

Quoted 12 lines
net/core/page_pool_user.c +1 -1
  		goto err_cancel;
 
  	if (pool->mp_ops && pool->mp_ops->nl_fill(pool->mp_priv, rsp, NULL))
@@ -337,7 +337,7 @@ int page_pool_list(struct page_pool *pool)
  void page_pool_detached(struct page_pool *pool)
  {
  	mutex_lock(&page_pools_lock);
-	pool->user.detach_time = ktime_get_boottime_seconds();
+	pool->user.detach_time = ktime_get_boottime();
  	netdev_nl_page_pool_event(pool, NETDEV_CMD_PAGE_POOL_CHANGE_NTF);
  	mutex_unlock(&page_pools_lock);
  }