From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2FB5FC07E9C for ; Mon, 12 Jul 2021 18:08:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E03C6120A for ; Mon, 12 Jul 2021 18:08:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235813AbhGLSLA (ORCPT ); Mon, 12 Jul 2021 14:11:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230477AbhGLSK6 (ORCPT ); Mon, 12 Jul 2021 14:10:58 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2726FC0613E8 for ; Mon, 12 Jul 2021 11:08:09 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id p8so26851916wrr.1 for ; Mon, 12 Jul 2021 11:08:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=i6hQVPx+EWsErV36SN8DcoM1K7uuDP9qwuJ95kliV9o=; b=Lw4n++onOoSV9FKzYyWsw0MLXqGOzg1r0P8KtwpssCbT+WVi0+v7xtjysRltf3FHOQ w/gk/KS/RULvIeAGu69CKBqJC+4tZRBcVBgkKjTtRmQ4WZhKOvU/5IJmecpcnRp/3d7R hddgIU6qcSSGu4p986kNsnHUq4aUmugE2ifhp5aRCcc+4Vo8FBNdeunHuf8FBJ6Rkfha h9HHTIWxON4CXzhBepf1D2nyh89wo97V9eWzX/QU4wWCIn99/AiLKt8qxZbv6V4MByWK dnsDc9eb1yPGLI7VhPuGcMhdbnjHgxpipyCICkSiKRBmkZ3c/B4shABsOCPpaV/lOl3L PFuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=i6hQVPx+EWsErV36SN8DcoM1K7uuDP9qwuJ95kliV9o=; b=ggng1qadtXGjECNBAujxgTVib6NAuOCSfr+ibI1fCVzZOj/4gDV8F0jUiM1qHi/XZw cD0XpXQ1nB7Q3FNrH5GTFm1cwmlemaCSFR+S9IDIkHNLHoybt+8wvV74xrAluQPZB9mI yICADiG26WaxjxHQe7ylqI0Q1q/IwghKWePZ3g7YuvF6wc7+XG9BmxGUHs69RaHKSDn0 5d/ncFNAJGeSQQ/TnuCq8W2WnuERD8fHU+TEGlg0H2KRsELr+5MJh5KfETlEjwRoTCe8 TVdERq7uSYjUsZzFYyRVWnAJ9jSLxMxTGvCOVyVMFuNpcLYQ+1ZBp4zhR/h5XPH2JlFO A+ng== X-Gm-Message-State: AOAM533xDufF+9czfr1riPKxBAqDh9hepsvvU/PMzZWBRW+cAuQpzSvg ew7InNEq3cgQczv4+CKIUrhmzg== X-Google-Smtp-Source: ABdhPJyPH98FymxmjebpmtQJ8yqxAa2EiK7GzTfVWNSBbPGYsXlw0+Y3Gyv5pP0tZ1prnKSZ7UTDnA== X-Received: by 2002:a5d:5989:: with SMTP id n9mr329096wri.8.1626113287568; Mon, 12 Jul 2021 11:08:07 -0700 (PDT) Received: from enceladus (athedsl-417902.home.otenet.gr. [79.131.184.108]) by smtp.gmail.com with ESMTPSA id w22sm171693wmc.4.2021.07.12.11.08.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Jul 2021 11:08:07 -0700 (PDT) Date: Mon, 12 Jul 2021 21:08:02 +0300 From: Ilias Apalodimas To: Jesper Dangaard Brouer Cc: Alexander Duyck , Yunsheng Lin , brouer@redhat.com, David Miller , Jakub Kicinski , Russell King - ARM Linux , Marcin Wojtas , linuxarm@openeuler.org, yisen.zhuang@huawei.com, Salil Mehta , thomas.petazzoni@bootlin.com, hawk@kernel.org, Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrew Morton , Peter Zijlstra , Will Deacon , Matthew Wilcox , Vlastimil Babka , fenghua.yu@intel.com, guro@fb.com, Peter Xu , Feng Tang , Jason Gunthorpe , Matteo Croce , Hugh Dickins , Jonathan Lemon , Alexander Lobakin , Willem de Bruijn , wenxu@ucloud.cn, Cong Wang , Kevin Hao , nogikh@google.com, Marco Elver , Yonghong Song , kpsingh@kernel.org, andrii@kernel.org, Martin KaFai Lau , songliubraving@fb.com, Netdev , LKML , bpf Subject: Re: [PATCH rfc v3 2/4] page_pool: add interface for getting and setting pagecnt_bias Message-ID: References: <1626092196-44697-1-git-send-email-linyunsheng@huawei.com> <1626092196-44697-3-git-send-email-linyunsheng@huawei.com> <2d9a3d29-8e6b-8462-c410-6b7fd4518c9d@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2d9a3d29-8e6b-8462-c410-6b7fd4518c9d@redhat.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [...] > > > +static inline bool page_pool_set_dma_addr(struct page *page, dma_addr_t addr) > > > { > > > + if (WARN_ON(addr & ~PAGE_MASK)) > > > + return false; > > > + > > > page->dma_addr[0] = addr; > > > if (sizeof(dma_addr_t) > sizeof(unsigned long)) > > > page->dma_addr[1] = upper_32_bits(addr); > > > + > > > + return true; > > > +} > > > + > > > > Rather than making this a part of the check here it might make more > > sense to pull this out and perform the WARN_ON after the check for > > dma_mapping_error. > > I need to point out that I don't like WARN_ON and BUG_ON code in fast-path > code, because compiler adds 'ud2' assembler instructions that influences the > instruction-cache fetching in the CPU. Yes, I have seen a measuresable > impact from this before. > > > > Also it occurs to me that we only really have to do this in the case > > where dma_addr_t is larger than the size of a long. Otherwise we could > > just have the code split things so that dma_addr[0] is the dma_addr > > and dma_addr[1] is our pagecnt_bias value in which case we could > > probably just skip the check. > > The dance to get 64-bit DMA addr on 32-bit systems is rather ugly and > confusing, sadly. We could take advantage of this, I just hope this will > not make it uglier. Note here that we can only use this because dma_addr is not aliased to compound page anymore (after the initial page_pool recycling patchset). We must keep this in mind if we even restructure struct page. Can we do something more radical for this? The 64/32 bit dance is only there for 32 bit systems with 64 bit dma. Since the last time we asked about this no one seemed to care about these, and I really doubt we'll get an ethernet driver for them (that needs recycling....), can we *only* support frag allocation and recycling for 'normal' systems? We could always just r e-purpose dma_addr[1] for those. Regards /Ilias > > > > > +static inline int page_pool_get_pagecnt_bias(struct page *page) > > > +{ > > > + return READ_ONCE(page->dma_addr[0]) & ~PAGE_MASK; > > > +} > > > + > > > +static inline unsigned long *page_pool_pagecnt_bias_ptr(struct page *page) > > > +{ > > > + return page->dma_addr; > > > +} > > > + > > > +static inline void page_pool_set_pagecnt_bias(struct page *page, int bias) > > > +{ > > > + unsigned long dma_addr_0 = READ_ONCE(page->dma_addr[0]); > > > + > > > + dma_addr_0 &= PAGE_MASK; > > > + dma_addr_0 |= bias; > > > + > > > + WRITE_ONCE(page->dma_addr[0], dma_addr_0); > > > } > > > > > > static inline bool is_page_pool_compiled_in(void) > > > diff --git a/net/core/page_pool.c b/net/core/page_pool.c > > > index 78838c6..1abefc6 100644 > > > --- a/net/core/page_pool.c > > > +++ b/net/core/page_pool.c > > > @@ -198,7 +198,13 @@ static bool page_pool_dma_map(struct page_pool *pool, struct page *page) > > > if (dma_mapping_error(pool->p.dev, dma)) > > > return false; > > > > > > > So instead of adding to the function below you could just add your > > WARN_ON check here with the unmapping call. > > > > > - page_pool_set_dma_addr(page, dma); > > > + if (unlikely(!page_pool_set_dma_addr(page, dma))) { > > > + dma_unmap_page_attrs(pool->p.dev, dma, > > > + PAGE_SIZE << pool->p.order, > > > + pool->p.dma_dir, > > > + DMA_ATTR_SKIP_CPU_SYNC); > > > + return false; > > > + } > > > > > > if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) > > > page_pool_dma_sync_for_device(pool, page, pool->p.max_len); > > > -- > > > 2.7.4 > > > > > >