Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4322107rdb; Thu, 14 Sep 2023 20:43:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF1O0vVZ6zTs76D2gxt+bFyifT+mH5//k9aGaXLuyOxKCWjOnKIu+IUuhyEtLJOsUl2542F X-Received: by 2002:a17:90b:390d:b0:274:77df:50d1 with SMTP id ob13-20020a17090b390d00b0027477df50d1mr390239pjb.21.1694749392189; Thu, 14 Sep 2023 20:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694749392; cv=none; d=google.com; s=arc-20160816; b=XQthfGgMLjU+zHaD1k6tDDVT/mqiazgozbl539mfQoon6/C8lXqHFS1NwGDrmG02DI Y5gwavFIDxsarZrbKHoT73WjsCrJN0uGjB4flRw/lmZHC3hh/VsHsCLqroMKAKrgsWRU vaaN59U26OHj/WpK8w6IbAN+Q8TL8t5aPcoI5hvj+8M/tYICm1sjWxbcbWa52PWQ0rIM 4lYX59B437taZmJK4SqYoneeSJYCLK6WLhZku0VBipoFmerWvX3aiL8dkCBBeI8bhoVF udPhaFbMi7eyBWFQhx8oPGRnle8gyQNZGetZrqmMusQDnwFy5W4ufKFo2sVMGtOKcU/S uCCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=V9y3W4w8Vrvb3itSQ1aZxY0flcAM2wszFYoNzBZyBoc=; fh=HHNKukIa5gI9x02JtRm/GwyS2fYhSID0gzYNWOiM7XI=; b=zxUatQOtOQ/1427JrLBadqSlU9+EjGo8NormSrNtx40/J0WKtiqvKWjy8QmvC2UlyQ zwjYNk9Kr1yWxSIAuGcAYv5WeAYQrylDmgqZ5K9c/Mli5H5WiapWLY+7K+sYVA2u29Z6 Ny1N1VLhTQsroJCKP0quvRTuoQKBh3kOvsCtZ8SVNTnDLSbz9T9BioJT98y+y/+35H+N IJ6Zu9iI8Mvbpjx7X6kiZwZ1qlmDzFRUKMl9InS7pY8ZEOFtQoUnV4tYEuP9GdDfWIvW cVHQ+DiZM9mLHHtTmiCt5RIQnRCXmukEd6A90BOw8gg8pjiH+1tt7igIl7OUrYDTo4Lx AKAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HNlHriWI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id p15-20020a170902ebcf00b001bf0917df73si2520409plg.581.2023.09.14.20.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 20:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HNlHriWI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0A7D9825E502; Wed, 13 Sep 2023 23:32:10 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235835AbjINGcL (ORCPT + 99 others); Thu, 14 Sep 2023 02:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235910AbjINGb6 (ORCPT ); Thu, 14 Sep 2023 02:31:58 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE76BCF1 for ; Wed, 13 Sep 2023 23:31:38 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-501bd7711e8so936695e87.1 for ; Wed, 13 Sep 2023 23:31:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694673097; x=1695277897; darn=vger.kernel.org; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=V9y3W4w8Vrvb3itSQ1aZxY0flcAM2wszFYoNzBZyBoc=; b=HNlHriWIC+fTrXsbXmor1+yeLntBpO6AvNlKd1bszG63N1+7p2+d/ZFTXK01sBwADx G+R7ZNEEligoRZmEVYDzoriL6dWYFOXWcTdWDeZNXII8FUiSgUKLCPred62GIriQ+k6L 0El1xHHKbT564UCp9+cCow5/fNOsL+TSfz37rng211mDLapV3gh0bF8lOqUJJ1e1f3tm mk9YUHVV7BR9TBnCY+kSs/BQSe+GsF9RPiZ909Iw4wk2hhM7neGjWjwxQQrAiOX/5SUC emJTi54pY3XqhqJ9EHpLgGUXg2ehfoOkDkoklGAgL2z7TNQgmyCpnt3/IpB+yKAYgwVh Os9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694673097; x=1695277897; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=V9y3W4w8Vrvb3itSQ1aZxY0flcAM2wszFYoNzBZyBoc=; b=USluBVJzSpY/1rUKpDX0e9yGp2EjjBrhWlz8PxazLxA2CAOtMvnLYF0UxthZy68lc4 bpxOwzdFfhf9newQnjtgF1tOU2X8VQGe+4gzTH47sOPg3OhqI+GCvCdzvaLWhXoyzkNv S9FRnzgUQnnKdwukgvMeJxo/VqTyDRx5jo4lx89ppoy4wxF5NI4Hw6pojJXT4TH0mfUW c5sPh0IvwmZ4insT/LtkQj7v4oM9S8DkJPUcDMi+xKJoLZGp1jx4mRnN3hp3FgKJj0n8 BIy7x9XaPMr8ZCvzVj1i6cnibJjqdi/qUqFfAQ2LXT11JUEbu59umGAKh91rj2WdMgLi 2lew== X-Gm-Message-State: AOJu0YxnQiWTyGxtm6lRi3+352YrzLAJaeXVxQ/ha0soGHBYlxcBawU5 cnHVLIezMWIYC+Hj+fWc6G2H/EAxsYhvSH+DS1Y= X-Received: by 2002:a05:6512:2311:b0:500:7cab:efc3 with SMTP id o17-20020a056512231100b005007cabefc3mr4731734lfu.11.1694673096532; Wed, 13 Sep 2023 23:31:36 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id a26-20020a056512021a00b004ffad0ec2d5sm145003lfo.111.2023.09.13.23.31.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 23:31:36 -0700 (PDT) From: Linus Walleij Date: Thu, 14 Sep 2023 08:31:35 +0200 Subject: [PATCH] ARC: mm: Make virt_to_pfn() a static inline MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230914-virt-to-phys-arc-v1-1-9dc0008dc0b0@linaro.org> X-B4-Tracking: v=1; b=H4sIAMaoAmUC/x3MQQqAIBBA0avErBvQBMmuEi3SppxNxRhRiHdPW r7F/xkSCVOCockgdHPiY6/QbQMhzvtGyEs1dKozymmDN8uF14FnfBPOEtArb7UJtndeQc1OoZW ffzlOpXwV57JzYgAAAA== To: Vineet Gupta Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 23:32:10 -0700 (PDT) Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. In order to do this we move the virt_to_phys() and below the definition of the __pa() and __va() macros so it compiles. The macro version was also able to do recursive symbol resolution. Signed-off-by: Linus Walleij --- arch/arc/include/asm/page.h | 21 ++++++++++++--------- arch/arc/include/asm/pgtable-levels.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h index 02b53ad811fb..def0dfb95b43 100644 --- a/arch/arc/include/asm/page.h +++ b/arch/arc/include/asm/page.h @@ -84,15 +84,6 @@ typedef struct { typedef struct page *pgtable_t; -/* - * Use virt_to_pfn with caution: - * If used in pte or paddr related macros, it could cause truncation - * in PAE40 builds - * As a rule of thumb, only use it in helpers starting with virt_ - * You have been warned ! - */ -#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) - /* * When HIGHMEM is enabled we have holes in the memory map so we need * pfn_valid() that takes into account the actual extents of the physical @@ -122,6 +113,18 @@ extern int pfn_valid(unsigned long pfn); #define __pa(vaddr) ((unsigned long)(vaddr)) #define __va(paddr) ((void *)((unsigned long)(paddr))) +/* + * Use virt_to_pfn with caution: + * If used in pte or paddr related macros, it could cause truncation + * in PAE40 builds + * As a rule of thumb, only use it in helpers starting with virt_ + * You have been warned ! + */ +static inline unsigned long virt_to_pfn(const void *kaddr) +{ + return __pa(kaddr) >> PAGE_SHIFT; +} + #define virt_to_page(kaddr) pfn_to_page(virt_to_pfn(kaddr)) #define virt_addr_valid(kaddr) pfn_valid(virt_to_pfn(kaddr)) diff --git a/arch/arc/include/asm/pgtable-levels.h b/arch/arc/include/asm/pgtable-levels.h index fc417c75c24d..86e148226463 100644 --- a/arch/arc/include/asm/pgtable-levels.h +++ b/arch/arc/include/asm/pgtable-levels.h @@ -159,7 +159,7 @@ #define pmd_clear(xp) do { pmd_val(*(xp)) = 0; } while (0) #define pmd_page_vaddr(pmd) (pmd_val(pmd) & PAGE_MASK) #define pmd_pfn(pmd) ((pmd_val(pmd) & PAGE_MASK) >> PAGE_SHIFT) -#define pmd_page(pmd) virt_to_page(pmd_page_vaddr(pmd)) +#define pmd_page(pmd) virt_to_page((void *)pmd_page_vaddr(pmd)) #define set_pmd(pmdp, pmd) (*(pmdp) = pmd) #define pmd_pgtable(pmd) ((pgtable_t) pmd_page(pmd)) --- base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d change-id: 20230913-virt-to-phys-arc-b0b613c689b0 Best regards, -- Linus Walleij