Received: by 2002:ac8:45c5:0:b0:405:464a:c27a with SMTP id e5csp1266818qto; Thu, 27 Jul 2023 09:19:39 -0700 (PDT) X-Google-Smtp-Source: APBJJlFJVBFQsDFIQ9VSIb0NVXC/yJ8kJ3SFCBb2e5MNpz3RZSyhyvpZSCjwYqDP6szNS9ggy5zu X-Received: by 2002:a17:90a:bc8:b0:262:fe45:85f6 with SMTP id x8-20020a17090a0bc800b00262fe4585f6mr4509888pjd.0.1690474779354; Thu, 27 Jul 2023 09:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690474779; cv=none; d=google.com; s=arc-20160816; b=r5wNCWPPwQbfbcquIYgqfn0PtOx+VmMQ4bttcpuNN+Cz95sjpktchv8zSTw4te3omi u41eXrxEdpc0Y0ybySDlSBRzC0tW1tKSZ+E6xkBfqEEYph4mtbDWz8ddr/Ncx/2XJaqT EIiSWD0QWIu5xRbQm03MB9mfWQzhrffAAFSs2qFFBiB6pcXnc7RR2QgsbhipjY1qsnDU BszfegLFVgM8t158YmPtEkNII8DszD5gyY1piyVXqi5ZuR959wKlVjDfSHtWU2jSb0aQ cJ5dUjkTF7hHOA0HLInW/jXBhfmltxqw/numQltrcMXpbTuHXRzm9YzzdVKjxgk+7Q1/ Tb4Q== 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=7z0gLwcNsgULFHJy+w4ndgOM1rkJ0SjVu1N70b7LYUs=; fh=3HE1xXs4s0z3NpKSg+MkyPw1+1QpKlxno2HY1HR9bAc=; b=IsFKyt11BHXlcbM/cr5TsGMzADOnBwLkDZjpdtLbqUObCyt7e3yXfvfly6Z4yCEccD setTmVjVoHZbMjfsQ43gJOsMakLbqc88NtSVdm9jbQWOSESKoRtf7t40mdN6g5RQQJBc JiNMSlUj01hC4k9IImKKalEvu/5MYLcVZSlNF1+1KEaS9ZvWxvOLe+mfBbyP6uiuaK09 l0gXiNbF04IoMmcLqNXsuEoWE9XVEO+Zc3d8JPtjJMcMkEMxYfBMU8AG8mR39EaodJVO gZtDzDiSCe3WRjEwqlcr4aQsujWekzRt42TWPcfqOIHMDFIIo17t1vO9MOkJXZurEWuE Kcww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=c74bP8y3; 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 k2-20020a170902c40200b001b86e3129e2si1584075plk.9.2023.07.27.09.19.25; Thu, 27 Jul 2023 09:19:39 -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=c74bP8y3; 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 S234091AbjG0Oqk (ORCPT + 99 others); Thu, 27 Jul 2023 10:46:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234071AbjG0Oq0 (ORCPT ); Thu, 27 Jul 2023 10:46:26 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396BE35B6; Thu, 27 Jul 2023 07:45:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690469155; x=1722005155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5UQmg0hLv8TkdVz/X6+MyXQQIYyvi5xDXayA3nnMuec=; b=c74bP8y341PVLLh37xGgpNzZG+c1qCCKvaZ+BaipaxeL4e8wohqMWPQR o0GrclNJvoQGQSiaBEmVjXFyKRTwpAeY+pBUnRXpGfPAz2kItOBiX5Ns+ ayR9dxyAahTw9iYHUm5kYm3v/oGiHp5XcqhuMI0dRSLlY8VtRrQPTFKiS BzetrKHdI+YRCW8aNTsbR1GZMJmW9Yt/iLnl1Ok4KQdGumgYzauXz45fL ojTl7S44EGxnzAVWJsg8S6emAaPW9LpBvldZpsPPytJ7ZAjk/dEiD7gFD P7hCFE7/oe/Km54nTqJHsE5UAVcAJAEA4ZQUDLxysT94uWXzNd4mwPEwM w==; X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="432139821" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="432139821" 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:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10784"; a="817119944" X-IronPort-AV: E=Sophos;i="6.01,235,1684825200"; d="scan'208";a="817119944" Received: from newjersey.igk.intel.com ([10.102.20.203]) by FMSMGA003.fm.intel.com with ESMTP; 27 Jul 2023 07:45:51 -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 7/9] net: skbuff: avoid accessing page_pool if !napi_safe when returning page Date: Thu, 27 Jul 2023 16:43:34 +0200 Message-ID: <20230727144336.1646454-8-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 Currently, pp->p.napi is always read, but the actual variable it gets assigned to is read-only when @napi_safe is true. For the !napi_safe cases, which yet is still a pack, it's an unneeded operation. Moreover, it can lead to premature or even redundant page_pool cacheline access. For example, when page_pool_is_last_frag() returns false (with the recent frag improvements). Thus, read it only when @napi_safe is true. This also allows moving @napi inside the condition block itself. Constify it while we are here, because why not. Signed-off-by: Alexander Lobakin --- net/core/skbuff.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 3084ef59400b..e701401092d7 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -881,9 +881,8 @@ static void skb_clone_fraglist(struct sk_buff *skb) bool page_pool_return_skb_page(struct page *page, bool napi_safe) { - struct napi_struct *napi; + bool allow_direct = false; struct page_pool *pp; - bool allow_direct; page = compound_head(page); @@ -903,9 +902,12 @@ bool page_pool_return_skb_page(struct page *page, bool napi_safe) * in the same context as the consumer would run, so there's * no possible race. */ - napi = READ_ONCE(pp->p.napi); - allow_direct = napi_safe && napi && - READ_ONCE(napi->list_owner) == smp_processor_id(); + if (napi_safe) { + const struct napi_struct *napi = READ_ONCE(pp->p.napi); + + allow_direct = napi && + READ_ONCE(napi->list_owner) == smp_processor_id(); + } /* Driver set this to memory recycling info. Reset it on recycle. * This will *not* work for NIC using a split-page memory model. -- 2.41.0