@@ -795,6 +795,7 @@ __page_pool_put_page(struct page_pool *pool, netmem_ref netmem,
static bool page_pool_napi_local(const struct page_pool *pool)
{
const struct napi_struct *napi;
+ bool napi_local;
u32 cpuid;
if (unlikely(!in_softirq()))
@@ -810,9 +811,15 @@ static bool page_pool_napi_local(const struct page_pool *pool)
if (READ_ONCE(pool->cpuid) == cpuid)
return true;
+ /* Synchronizated with page_pool_destory() to avoid use-after-free
+ * for 'napi'.
+ */
+ rcu_read_lock();
napi = READ_ONCE(pool->p.napi);
+ napi_local = napi && READ_ONCE(napi->list_owner) == cpuid;
+ rcu_read_unlock();
- return napi && READ_ONCE(napi->list_owner) == cpuid;
+ return napi_local;
}
void page_pool_put_unrefed_netmem(struct page_pool *pool, netmem_ref netmem,
@@ -1126,6 +1133,12 @@ void page_pool_destroy(struct page_pool *pool)
if (!page_pool_release(pool))
return;
+ /* Paired with rcu lock in page_pool_napi_local() to enable clearing
+ * of pool->p.napi in page_pool_disable_direct_recycling() is seen
+ * before returning to driver to free the napi instance.
+ */
+ synchronize_rcu();
+
page_pool_detached(pool);
pool->defer_start = jiffies;
pool->defer_warn = jiffies + DEFER_WARN_INTERVAL;