From patchwork Thu Sep 14 06:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 139413 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp179328vqi; Thu, 14 Sep 2023 00:49:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZfclQ4TtO73txR/7PlPSw3W5X80yliB16wktri4M6rNGgdPSHBSxRG0W2Krcu+QzZ/xje X-Received: by 2002:a05:6808:1a17:b0:3a7:26fd:b229 with SMTP id bk23-20020a0568081a1700b003a726fdb229mr5827166oib.48.1694677743214; Thu, 14 Sep 2023 00:49:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694677743; cv=none; d=google.com; s=arc-20160816; b=UXD2rDmItjGjMDgmieiAv5/8sQYS1RPZ0C8ZffJjM9/OFcyYSjJVYHNQmUBA06DxIw jsooupN3+BgoN6aEUWRtouAFcIlJ5O25rPOqx2wg2SVlwC1AP7qCyICCFszaysvwhu/N 9wTPXFGQNwJyOK/eJJO9G/KdBMQNXdltMFmVpJg8ZYmZqip2tL8wERkNKFNf8r5Hjkis relGix18J7gqqSP8Qax6EjDhK0UnvVPGXKuTnko3m4tdLWP19IeYrJpnQVPwFUUbssuM 6btJfM3NNzHS/IU4zsjIdOPHpRpnLC7+O2CcO1h0EfPoonuCeB/F7sBBICVZ2fFmT2D4 p9hw== 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 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id i6-20020a639d06000000b0057772079a9bsi961443pgd.662.2023.09.14.00.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 00:49:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; 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 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id EB6888219C12; Wed, 13 Sep 2023 23:32:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235839AbjINGcM (ORCPT + 35 others); Thu, 14 Sep 2023 02:32:12 -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 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 (agentk.vger.email [0.0.0.0]); Wed, 13 Sep 2023 23:32:19 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776998409629476539 X-GMAIL-MSGID: 1776998409629476539 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(-) --- base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d change-id: 20230913-virt-to-phys-arc-b0b613c689b0 Best regards, 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))