Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B39BDBE7B for ; Wed, 23 Aug 2023 12:54:55 +0000 (UTC) Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B205EE5C for ; Wed, 23 Aug 2023 05:54:52 -0700 (PDT) Date: Wed, 23 Aug 2023 14:54:48 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1692795290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zBRWiMnYP/bWCOqgyAMEagaSdQUvqpL4iQXSl2tEboU=; b=hB3VH8XOSfalQPLY1p7a054BXteOwPt9NKSgkTs/9EyyRWz+1DkiJ8LrXyLsKDQTdzjiDA s/OK7MwNkDlfoy6jB+k4purMTAPqHugBstTx35EbYv4GU/Kqw7PuvlT2jmD6JRbfZYYQLS +1D21FfbBIDWxrrjEBrmj4kiWX/qWthwagtgv62M2AbAWk4voN+ZAvbS7XyPGi9NGhuNXu 2vgE4lECbk2z7oSgpu/Qylgxkr9x5+LnqFLcovvga944wZEFsJl2kudypN/UwqKgHVlBJ0 KRNF4WAuUfQMAU2qBEq+iD1m7071t9ithltxbt95WLGU4E0rZNURROq1jme28Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1692795290; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=zBRWiMnYP/bWCOqgyAMEagaSdQUvqpL4iQXSl2tEboU=; b=oAstP5cYpLZDT3Wf4/65/Nd5PYvoWXINs9govrFBlWhIXtpAtJJcNFciAqEXjFXB2ietmr gdSZms4NXIIe4BAw== From: Sebastian Andrzej Siewior To: Ratheesh Kannoth Cc: "netdev@vger.kernel.org" , "David S. Miller" , Eric Dumazet , Geethasowjanya Akula , Ilias Apalodimas , Jakub Kicinski , Jesper Dangaard Brouer , Paolo Abeni , Subbaraya Sundeep Bhatta , Sunil Kovvuri Goutham , Thomas Gleixner , Hariprasad Kelam Subject: Re: RE: [EXT] [BUG] Possible unsafe page_pool usage in octeontx2 Message-ID: <20230823125448.Q89O9wFB@linutronix.de> References: <20230823094757.gxvCEOBi@linutronix.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On 2023-08-23 12:28:58 [+0000], Ratheesh Kannoth wrote: > > From: Sebastian Andrzej Siewior > > Sent: Wednesday, August 23, 2023 3:18 PM > > Subject: [EXT] [BUG] Possible unsafe page_pool usage in octeontx2 > > > > This breaks in octeontx2 where a worker is used to fill the buffer: > > otx2_pool_refill_task() -> otx2_alloc_rbuf() -> __otx2_alloc_rbuf() -> > > otx2_alloc_pool_buf() -> page_pool_alloc_frag(). > > > As I understand, the problem is due to workqueue may get scheduled on > other CPU. If we use BOUND workqueue, do you think this problem can be > solved ? It would but is still open to less obvious races for instance if the IRQ/ NAPI is assigned to another CPU while the workqueue is scheduled. You would have to additional synchronisation to ensure that bad can happen. This does not make it any simpler nor prettier or serves as a good example. I would suggest to stay away from the lock-less buffer if not in NAPI and feed the pool->ring instead. > > BH is disabled but the add of a page can still happen while NAPI callback runs > > on a remote CPU and so corrupting the index/ array. > > > > API wise I would suggest to > > > > diff --git a/net/core/page_pool.c b/net/core/page_pool.c index > > 7ff80b80a6f9f..b50e219470a36 100644 > > --- a/net/core/page_pool.c > > +++ b/net/core/page_pool.c > > @@ -612,7 +612,7 @@ __page_pool_put_page(struct page_pool *pool, > > struct page *page, > > page_pool_dma_sync_for_device(pool, page, > > dma_sync_size); > > > > - if (allow_direct && in_softirq() && > > + if (allow_direct && in_serving_softirq() && > > page_pool_recycle_in_cache(page, pool)) > > return NULL; > > > > because the intention (as I understand it) is to be invoked from within the > > NAPI callback (while softirq is served) and not if BH is just disabled due to a > > lock or so. > Could you help me understand where in_softirq() check will break ? If > we TX a packet (dev_queue_xmit()) in > Process context on same core, in_serving_softirq() check will prevent > it from recycling ? If a check is added to page_pool_alloc_pages() then it will trigger if you fill the buffer from your ->ndo_open() callback. Also, if you invoke dev_queue_xmit() from process context. But It will be added to &pool->ring instead. Sebastian