Received: by 2002:ac8:45c5:0:b0:405:464a:c27a with SMTP id e5csp1236968qto; Thu, 27 Jul 2023 08:33:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlEZ6ZKolr/ojJ0nZUaU/gxFDRFabyIAJxtoH6oBRtnodpyTupQlRBDX4GJbPNlouJoypEv1 X-Received: by 2002:a17:906:9bd0:b0:99b:cddb:cf42 with SMTP id de16-20020a1709069bd000b0099bcddbcf42mr2169001ejc.69.1690472027651; Thu, 27 Jul 2023 08:33:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690472027; cv=none; d=google.com; s=arc-20160816; b=by1RUUDpL5OTROY/DP5PCk6va+zAPHp7r4oMFWbFmAHN0h9wjkRajlkZwpQ6Xpa3Ji nCFzHsQ0V4e4WNAlwTxmTP73uAFmE8nYWfyTgIetYFs6LI4qcu0XedBxDgI3IoHIR+je 4erFMpzaL9SULyBz7yJ8maMKVst9HJZqeGxU51x6hdo/jsOWcfcn46jkNmdTBxSbWmQ5 1wIZxEkjgJCn2oW9zq/9hMSYdZy9OJZjEWCzcwcCd7pttn6IITTwRlkMh7lookZEHuVh oIFokwm+fm8IDHraLtlUXKSkPTMv+zp/lQs5rdrZRA+FTzIkhjDoG+9nQF64qgdbUW4V COtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vhAons5/pd1uGUwYpWdWJPRFHMq70h55jOgp8PZoeWA=; fh=3HE1xXs4s0z3NpKSg+MkyPw1+1QpKlxno2HY1HR9bAc=; b=mfjrQhXbIKwpftv9FEa8byQaJsvOIQbG2rxkFRAxSdoEsAUtqNFBrzg1QnL10OPWCM UrCbJN3RRybX2zVbsGmoUdYhI+HkueVcA+rdJCGchZf/XL+JYhTS3N+qWIc9B7iyxmYB wbE7a7+C6cpRUvGgtJgEV9GFEsiTjrO6EnavAsdXDHeSM6pCg/MoTnT8SA8ac1zsyyw7 plm8+D5iboioQzuT1prufExGbuNVxJBOX07ezrYsrPLzNiWhd14PGONMsCbgW8Vf2h75 /uExfKKPMILhrp9V1Hw1DaNh5TOwq7LkQjCSyNgFeASduq9sCgsdOUahQE09HhynqUkF dUSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="E1rw8pp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j25-20020a170906255900b0099bd5926bedsi1176306ejb.669.2023.07.27.08.33.03; Thu, 27 Jul 2023 08:33:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b="E1rw8pp/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233450AbjG0Oqm (ORCPT + 99 others); Thu, 27 Jul 2023 10:46:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234028AbjG0Oq1 (ORCPT ); Thu, 27 Jul 2023 10:46:27 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EBB230DA; Thu, 27 Jul 2023 07:45:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690469158; x=1722005158; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KlYBSALGjCnGn6k2NRIvrpGdhSLAEVVLVU2ig0CAvyw=; b=E1rw8pp/7blEWzZ30GBezU/a32XZ1bZtX4JhsYd9TC6z0+LkW5HwkN+N A0r1ZIDYW7v7OYEriIAzfvItykKq51XJ5dGIdeDx8IjGz6Z9dfUtnYd7p bnRwUF0MfiZZ54rcadt5OVV26Wn9NsuqRpEBa07V+ibWpcHWwkWBKhAws 9rCk502nY6mm5j98ZIbKxwLyaQSS7OWdb6UrAqc9cb4J4jaAMoB4+e8Eb n82LFweB6wFPBOMntjWukbjOA4XCTKYA1wH5RWiNgEhIY7YmURFWfGhh2 gMHutjSJbBaOESLaQMQU6bXLL83AEfCu6Nvm6sx/LNVU1UKp9JaxRAxqT Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="432139848" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="432139848" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2023 07:45:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="817119955" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="817119955" Received: from newjersey.igk.intel.com ([10.102.20.203]) by FMSMGA003.fm.intel.com with ESMTP; 27 Jul 2023 07:45:54 -0700 From: Alexander Lobakin To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Alexander Lobakin , Maciej Fijalkowski , Larysa Zaremba , Yunsheng Lin , Alexander Duyck , Jesper Dangaard Brouer , Ilias Apalodimas , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 8/9] page_pool: add a lockdep check for recycling in hardirq Date: Thu, 27 Jul 2023 16:43:35 +0200 Message-ID: <20230727144336.1646454-9-aleksander.lobakin@intel.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230727144336.1646454-1-aleksander.lobakin@intel.com> References: <20230727144336.1646454-1-aleksander.lobakin@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jakub Kicinski Page pool use in hardirq is prohibited, add debug checks to catch misuses. IIRC we previously discussed using DEBUG_NET_WARN_ON_ONCE() for this, but there were concerns that people will have DEBUG_NET enabled in perf testing. I don't think anyone enables lockdep in perf testing, so use lockdep to avoid pushback and arguing :) Signed-off-by: Jakub Kicinski Signed-off-by: Alexander Lobakin --- include/linux/lockdep.h | 7 +++++++ net/core/page_pool.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 310f85903c91..dc2844b071c2 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -625,6 +625,12 @@ do { \ WARN_ON_ONCE(__lockdep_enabled && !this_cpu_read(hardirq_context)); \ } while (0) +#define lockdep_assert_no_hardirq() \ +do { \ + WARN_ON_ONCE(__lockdep_enabled && (this_cpu_read(hardirq_context) || \ + !this_cpu_read(hardirqs_enabled))); \ +} while (0) + #define lockdep_assert_preemption_enabled() \ do { \ WARN_ON_ONCE(IS_ENABLED(CONFIG_PREEMPT_COUNT) && \ @@ -659,6 +665,7 @@ do { \ # define lockdep_assert_irqs_enabled() do { } while (0) # define lockdep_assert_irqs_disabled() do { } while (0) # define lockdep_assert_in_irq() do { } while (0) +# define lockdep_assert_no_hardirq() do { } while (0) # define lockdep_assert_preemption_enabled() do { } while (0) # define lockdep_assert_preemption_disabled() do { } while (0) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 529e4b41e9eb..be9371cd9ac7 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -579,6 +579,8 @@ static __always_inline struct page * __page_pool_put_page(struct page_pool *pool, struct page *page, unsigned int dma_sync_size, bool allow_direct) { + lockdep_assert_no_hardirq(); + /* This allocator is optimized for the XDP mode that uses * one-frame-per-page, but have fallbacks that act like the * regular page allocator APIs. -- 2.41.0