Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7390260rwr; Tue, 2 May 2023 14:05:43 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xvXl4U+GK+epFmrmv0OU7dp2FMurkUuYIAC02cGTQ3Wkz7NEbtO4HSAJI6lf6n699pVA/ X-Received: by 2002:a9d:75ca:0:b0:6a7:cdb1:88ff with SMTP id c10-20020a9d75ca000000b006a7cdb188ffmr8806892otl.14.1683061543554; Tue, 02 May 2023 14:05:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683061543; cv=none; d=google.com; s=arc-20160816; b=tbbcjiWIRVi+5mVWcqNrRtqVseWiOh5eEhphAP7endX756EmmZtyjiPOq9qxCTfXtD VZGaPbeGOVp1IVr2UzKJEjqyNU1dAcffN1Z/RAkVSZeFjremQWaq4xAkolPaXAmEZM21 lW82R4KRAEP1duzdf4ZD+vrpcgzoZ6W+6AMwL0XkW7IiA8CuQKmJcGUBZ2i2Ee0d0dq9 fD5rWhBrn+4MkeJ8f1ORTAwcmX5ot0w4KLc4lcVJNeTTnaO4CBnnJBq4pSzt38JfWV9i Jk8bi2P5qKNrTPJ4av5p+6Zmw3J5OfweJDHSazyQNYtLJuEpci9IIFikc+4dZBK7AYIi q7uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Jeq6+nx3g2wrW78uPfEerLbf18qIDqHe8kQ7v5/JI60=; b=oFVPIWZ5oLSNTwIU0qefgnbZ7d1gRgc+ZpmAc3GcgiwDqpU7SiezCGGxKnA015V1ei KQhThp00OeCgmO2/2aDAKXHKWLp/vJdFYrGOnKYgwbTsbElceqrFYRiFuos7KBvy3hyd oRmnKuy9FY6nmJsq7IYJhdAftaTbAPUaRyX2YXNJhgnZ3k9GD5k+K29mrvo3q6qy0Ft9 5VL79s7vjYJN6aOrX0wotSB8W1cmlSoK2ldA2eZwa7O8OohSljwyVDhCbMnNo+EYXNV5 kZ0tlv135FyroKAa0QH20/EPsYCvGf/AXj7doITlJqaiLZ5U07hhQcWw8oRsMKr6mjku VFBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=USgXLop6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z17-20020a9d62d1000000b006a5ed583c9esi22907575otk.52.2023.05.02.14.05.14; Tue, 02 May 2023 14:05:43 -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=@google.com header.s=20221208 header.b=USgXLop6; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbjEBUmK (ORCPT + 99 others); Tue, 2 May 2023 16:42:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjEBUmF (ORCPT ); Tue, 2 May 2023 16:42:05 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 060C51FC4 for ; Tue, 2 May 2023 13:42:02 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id 3f1490d57ef6-b9a6eec8611so107487276.0 for ; Tue, 02 May 2023 13:42:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683060121; x=1685652121; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Jeq6+nx3g2wrW78uPfEerLbf18qIDqHe8kQ7v5/JI60=; b=USgXLop66yK89JWxFP/fxzpFn6QCWIJ873ogcbMDaInHtoy86T0N+nDV3beDNUkq/4 7c06Jya3MtjCRVJM+uNiMRs8RsEjcuOOGWIJrQZZueHpb8sE4DfQf9CM/q0ZS2jcLOLw Zxz0Iz+Ftxu+bdb4q4rBZ/RbfwNX8QwPVZ0QhmH+LWE19e3eVerx9UKRt0gEIZVUeoQU bQ9rPDFBUQenVP8rXbU2Tw3/ndUSRGc8QMnj9BCeiemAFsvcZKGpt9grfpkHrYcao6rB iJHXwyF5Ilbx83HWZbdXNDDSJARcklUlVWFftnhagZVtN2T4a20Nb9A365j2QrPSNgF4 B25Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683060121; x=1685652121; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Jeq6+nx3g2wrW78uPfEerLbf18qIDqHe8kQ7v5/JI60=; b=bX3bDS4dOURQxCrXl6Revg/bi5MD/CbJEOFh7B4/Fzub7FFDsBpAJUZxuGPZHjJ8h4 BjpjGwVPxMAl7wnof2F9KHr8yrpM6m/P5sEPc125oRJaNi2cA9Ez5y6ZgeDB/4H67ap8 q+imFZk7DrBy27K8UfQHy5KEAECOqIe77QOWvqpXroXLnjw21FI2Zb/EhJnF4ff0ERyC uRoQ4KgzYIfPraYcMUypPmDaqE3Y+uXZ099kHhUtvI/QeXwHP41zNU1dCN4Rgj6odibW 4jjRAzzkjLCU4aAtO1/hhjGZ1V9Iz7ga9XT8tJgBL3UjNMtEccchA9M2fXI15Qvxuhnm pfcg== X-Gm-Message-State: AC+VfDw7MCVLFAyc4QdmEkRCn+G8rpkFrjnTcozMeegEH4dsmzpicVNq 4rXRhOEKXlh2cKdFNH+XvUA761hDx5Dq4adWGzARng== X-Received: by 2002:a25:e78d:0:b0:b9a:6a19:8153 with SMTP id e135-20020a25e78d000000b00b9a6a198153mr17807199ybh.5.1683060120872; Tue, 02 May 2023 13:42:00 -0700 (PDT) MIME-Version: 1.0 References: <20230501165450.15352-1-surenb@google.com> <20230501165450.15352-20-surenb@google.com> <20230502175052.43814202@meshulam.tesarici.cz> <20230502220909.3f55ae41@meshulam.tesarici.cz> <20230502223915.6b38f8c4@meshulam.tesarici.cz> In-Reply-To: <20230502223915.6b38f8c4@meshulam.tesarici.cz> From: Suren Baghdasaryan Date: Tue, 2 May 2023 13:41:49 -0700 Message-ID: Subject: Re: [PATCH 19/40] change alloc_pages name in dma_map_ops to avoid name conflicts To: =?UTF-8?B?UGV0ciBUZXNhxZnDrWs=?= Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, ldufour@linux.ibm.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, keescook@chromium.org, ndesaulniers@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 On Tue, May 2, 2023 at 1:39=E2=80=AFPM Petr Tesa=C5=99=C3=ADk wrote: > > On Tue, 2 May 2023 13:24:37 -0700 > Suren Baghdasaryan wrote: > > > On Tue, May 2, 2023 at 1:09=E2=80=AFPM Petr Tesa=C5=99=C3=ADk wrote: > > > > > > On Tue, 2 May 2023 11:38:49 -0700 > > > Suren Baghdasaryan wrote: > > > > > > > On Tue, May 2, 2023 at 8:50=E2=80=AFAM Petr Tesa=C5=99=C3=ADk wrote: > > > > > > > > > > On Mon, 1 May 2023 09:54:29 -0700 > > > > > Suren Baghdasaryan wrote: > > > > > > > > > > > After redefining alloc_pages, all uses of that name are being r= eplaced. > > > > > > Change the conflicting names to prevent preprocessor from repla= cing them > > > > > > when it's not intended. > > > > > > > > > > > > Signed-off-by: Suren Baghdasaryan > > > > > > --- > > > > > > arch/x86/kernel/amd_gart_64.c | 2 +- > > > > > > drivers/iommu/dma-iommu.c | 2 +- > > > > > > drivers/xen/grant-dma-ops.c | 2 +- > > > > > > drivers/xen/swiotlb-xen.c | 2 +- > > > > > > include/linux/dma-map-ops.h | 2 +- > > > > > > kernel/dma/mapping.c | 4 ++-- > > > > > > 6 files changed, 7 insertions(+), 7 deletions(-) > > > > > > > > > > > > diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/am= d_gart_64.c > > > > > > index 56a917df410d..842a0ec5eaa9 100644 > > > > > > --- a/arch/x86/kernel/amd_gart_64.c > > > > > > +++ b/arch/x86/kernel/amd_gart_64.c > > > > > > @@ -676,7 +676,7 @@ static const struct dma_map_ops gart_dma_op= s =3D { > > > > > > .get_sgtable =3D dma_common_get_sgtabl= e, > > > > > > .dma_supported =3D dma_direct_supported, > > > > > > .get_required_mask =3D dma_direct_get_requir= ed_mask, > > > > > > - .alloc_pages =3D dma_direct_alloc_page= s, > > > > > > + .alloc_pages_op =3D dma_direct_alloc_page= s, > > > > > > .free_pages =3D dma_direct_free_pages= , > > > > > > }; > > > > > > > > > > > > diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iomm= u.c > > > > > > index 7a9f0b0bddbd..76a9d5ca4eee 100644 > > > > > > --- a/drivers/iommu/dma-iommu.c > > > > > > +++ b/drivers/iommu/dma-iommu.c > > > > > > @@ -1556,7 +1556,7 @@ static const struct dma_map_ops iommu_dma= _ops =3D { > > > > > > .flags =3D DMA_F_PCI_P2PDMA_SUPPORTED, > > > > > > .alloc =3D iommu_dma_alloc, > > > > > > .free =3D iommu_dma_free, > > > > > > - .alloc_pages =3D dma_common_alloc_pages, > > > > > > + .alloc_pages_op =3D dma_common_alloc_pages, > > > > > > .free_pages =3D dma_common_free_pages, > > > > > > .alloc_noncontiguous =3D iommu_dma_alloc_noncontiguous= , > > > > > > .free_noncontiguous =3D iommu_dma_free_noncontiguous, > > > > > > diff --git a/drivers/xen/grant-dma-ops.c b/drivers/xen/grant-dm= a-ops.c > > > > > > index 9784a77fa3c9..6c7d984f164d 100644 > > > > > > --- a/drivers/xen/grant-dma-ops.c > > > > > > +++ b/drivers/xen/grant-dma-ops.c > > > > > > @@ -282,7 +282,7 @@ static int xen_grant_dma_supported(struct d= evice *dev, u64 mask) > > > > > > static const struct dma_map_ops xen_grant_dma_ops =3D { > > > > > > .alloc =3D xen_grant_dma_alloc, > > > > > > .free =3D xen_grant_dma_free, > > > > > > - .alloc_pages =3D xen_grant_dma_alloc_pages, > > > > > > + .alloc_pages_op =3D xen_grant_dma_alloc_pages, > > > > > > .free_pages =3D xen_grant_dma_free_pages, > > > > > > .mmap =3D dma_common_mmap, > > > > > > .get_sgtable =3D dma_common_get_sgtable, > > > > > > diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xe= n.c > > > > > > index 67aa74d20162..5ab2616153f0 100644 > > > > > > --- a/drivers/xen/swiotlb-xen.c > > > > > > +++ b/drivers/xen/swiotlb-xen.c > > > > > > @@ -403,6 +403,6 @@ const struct dma_map_ops xen_swiotlb_dma_op= s =3D { > > > > > > .dma_supported =3D xen_swiotlb_dma_supported, > > > > > > .mmap =3D dma_common_mmap, > > > > > > .get_sgtable =3D dma_common_get_sgtable, > > > > > > - .alloc_pages =3D dma_common_alloc_pages, > > > > > > + .alloc_pages_op =3D dma_common_alloc_pages, > > > > > > .free_pages =3D dma_common_free_pages, > > > > > > }; > > > > > > diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-ma= p-ops.h > > > > > > index 31f114f486c4..d741940dcb3b 100644 > > > > > > --- a/include/linux/dma-map-ops.h > > > > > > +++ b/include/linux/dma-map-ops.h > > > > > > @@ -27,7 +27,7 @@ struct dma_map_ops { > > > > > > unsigned long attrs); > > > > > > void (*free)(struct device *dev, size_t size, void *vaddr= , > > > > > > dma_addr_t dma_handle, unsigned long attr= s); > > > > > > - struct page *(*alloc_pages)(struct device *dev, size_t si= ze, > > > > > > + struct page *(*alloc_pages_op)(struct device *dev, size_t= size, > > > > > > dma_addr_t *dma_handle, enum dma_data_dir= ection dir, > > > > > > gfp_t gfp); > > > > > > void (*free_pages)(struct device *dev, size_t size, struc= t page *vaddr, > > > > > > diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c > > > > > > index 9a4db5cce600..fc42930af14b 100644 > > > > > > --- a/kernel/dma/mapping.c > > > > > > +++ b/kernel/dma/mapping.c > > > > > > @@ -570,9 +570,9 @@ static struct page *__dma_alloc_pages(struc= t device *dev, size_t size, > > > > > > size =3D PAGE_ALIGN(size); > > > > > > if (dma_alloc_direct(dev, ops)) > > > > > > return dma_direct_alloc_pages(dev, size, dma_hand= le, dir, gfp); > > > > > > - if (!ops->alloc_pages) > > > > > > + if (!ops->alloc_pages_op) > > > > > > return NULL; > > > > > > - return ops->alloc_pages(dev, size, dma_handle, dir, gfp); > > > > > > + return ops->alloc_pages_op(dev, size, dma_handle, dir, gf= p); > > > > > > } > > > > > > > > > > > > struct page *dma_alloc_pages(struct device *dev, size_t size, > > > > > > > > > > I'm not impressed. This patch increases churn for code which does= not > > > > > (directly) benefit from the change, and that for limitations in y= our > > > > > tooling? > > > > > > > > > > Why not just rename the conflicting uses in your local tree, but = then > > > > > remove the rename from the final patch series? > > > > > > > > With alloc_pages function becoming a macro, the preprocessor ends u= p > > > > replacing all instances of that name, even when it's not used as a > > > > function. That what necessitates this change. If there is a way to > > > > work around this issue without changing all alloc_pages() calls in = the > > > > source base I would love to learn it but I'm not quite clear about > > > > your suggestion and if it solves the issue. Could you please provid= e > > > > more details? > > > > > > Ah, right, I admit I did not quite understand why this change is > > > needed. However, this is exactly what I don't like about preprocessor > > > macros. Each macro effectively adds a new keyword to the language. > > > > > > I believe everything can be solved with inline functions. What exactl= y > > > does not work if you rename alloc_pages() to e.g. alloc_pages_caller(= ) > > > and then add an alloc_pages() inline function which calls > > > alloc_pages_caller() with _RET_IP_ as a parameter? > > > > I don't think that would work because we need to inject the codetag at > > the file/line of the actual allocation call. If we pass _REP_IT_ then > > we would have to lookup the codetag associated with that _RET_IP_ > > which results in additional runtime overhead. > > OK. If the reference to source code itself must be recorded in the > kernel, and not resolved later (either by the debugfs read fops, or by > a tool which reads the file), then this information can only be > obtained with a preprocessor macro. > > I was hoping that a debugging feature could be less intrusive. OTOH > it's not my call to balance the tradeoffs. > > Thank you for your patient explanations. Thanks for reviewing and the suggestions! I'll address the actionable ones in the next version. Suren. > > Petr T > > -- > To unsubscribe from this group and stop receiving emails from it, send an= email to kernel-team+unsubscribe@android.com. >