From patchwork Wed Nov 15 13:28:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1864253 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=YJYtE2+R; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=l9hZOfTd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SVkWg6Hv0z1yRM for ; Thu, 16 Nov 2023 00:28:31 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CrhZVZxLFrI4F9SNUjdonfRYTj2AsfPkYFzLqwPu8Fs=; b=YJYtE2+REeQHVR 5yhGTuMqT337aVYj1MSNaNb9vnoZrKeFpB6AT4L+l9UtxlWwpx+WQjdT5zTcyybjiOvVR8qhY2pme xLCS0KkCXqM51YsT7GZIVvm7umAGV8T69mGKdaM5NGxEIEUF/X5seXHi71gNZRPTDXcKDl34wfwNm OU4JrmY250nNQbmK3DIL235Neyt/wyC57vha2XPUTawVaTFcDuGbsQp4WMMusC5zhQimoUYguE5Ay 6Lb+emSHivC7E3xc0IaEj+QffsgxlsLyFS2X01aBBDay0px4aThe6jJep0Q1ffq5TOzlJAEFVdnGo budSHwGS0zcogd+cEqDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3FwS-000s9K-2u; Wed, 15 Nov 2023 13:28:28 +0000 Received: from mail-lf1-x136.google.com ([2a00:1450:4864:20::136]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r3FwI-000rya-39 for linux-snps-arc@lists.infradead.org; Wed, 15 Nov 2023 13:28:21 +0000 Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-507a55302e0so9579150e87.0 for ; Wed, 15 Nov 2023 05:28:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700054897; x=1700659697; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=HrVNEt2cc/SjP2EDNi8Ypx4BpRW+YQfrsXMUopTWpaU=; b=l9hZOfTd3fVMQiWvGQMV+oeSlAHr95hLlHSpsHY5m8p5asT0H+cXra8CRIxRlQgAX1 fl7xuFngpKl8+jtsjEbR315H1x7QUL33TIP+4ikGH45ab72RHCd9IcPZoOWp3ysDaQID 5Wf0aRyXp+fgrCJP/azaxk4NHIHUeM+OkK9Sl0v4FCQ4BdHUF3gGIVBnNrgyH0O97aiQ m2z96s2kDkgt0Z75DTR89V0AujLQzdNOamwilTwr+WQrGol2Z+zNgWiJwpQeHS3tntrA GYPqBexOkfRYrVWC3f3j6NB4KK6xthQIzUjT1dQXMwJQUaaJHBovH0RBNpGNqTTSsHzi hwLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700054897; x=1700659697; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=HrVNEt2cc/SjP2EDNi8Ypx4BpRW+YQfrsXMUopTWpaU=; b=MO45R53geoGCXusBGTx1XALYXmM00qSt/tAzxcjSgX2ISlzbGQlE35+6UIREpjOiFK V5jTsPddoaVhJf/xOzKPBIqQCClOvVBaF77XKEBH7a5mz94O6mpWMHvB2rrBbULInO+x O58VIHiPubJw4eGu2JCSfnj5zxnbc6Yz86nB35cwPUX0UXEZaCXCxKOVSS6WmiVfScky H5hbzKuzqFkWvKZd5fK/U5YRMECS6qohOHRHa2+Bz9zy0s46BcKlEj7FSml73cARmZ4I rANTg4EYABU3F+/yg9t7ibUtaeksSzD+ay194Yz2lP08CTl9g0LqL0B9C2fX6AvcpJY2 GcfQ== X-Gm-Message-State: AOJu0Yx+i4e5Fblj09yi5McIyXLNFygLVwAA/9PkVR1WqWKxuTt95zeO w1uxn/W21yF5rGjOPM+GygqyAA== X-Google-Smtp-Source: AGHT+IEZfdzsNM4pOVpdQmBfJck2ud0jjVkPzsGxSYAG5htEb3fgmCm3DK8SVrja4wL8Daoz/Qy5GA== X-Received: by 2002:a05:6512:4846:b0:507:9702:8e09 with SMTP id ep6-20020a056512484600b0050797028e09mr8331107lfb.2.1700054896889; Wed, 15 Nov 2023 05:28:16 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id l12-20020a19c20c000000b00507b1da672bsm1648705lfc.174.2023.11.15.05.28.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:28:16 -0800 (PST) From: Linus Walleij Date: Wed, 15 Nov 2023 14:28:14 +0100 Subject: [PATCH 1/2] ARC: mm: Make virt_to_pfn() a static inline MIME-Version: 1.0 Message-Id: <20231115-virt-to-phy-arch-tree-v1-1-8b61296eae73@linaro.org> References: <20231115-virt-to-phy-arch-tree-v1-0-8b61296eae73@linaro.org> In-Reply-To: <20231115-virt-to-phy-arch-tree-v1-0-8b61296eae73@linaro.org> To: Arnd Bergmann , Vineet Gupta , Brian Cain Cc: linux-arch@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hexagon@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_052819_036942_A2E31F25 X-CRM114-Status: GOOD ( 14.98 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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_ [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:136 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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)) From patchwork Wed Nov 15 13:28:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 1864254 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=lXDICr8z; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=hEoTrGl3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SVkWh4YSCz1yRV for ; Thu, 16 Nov 2023 00:28:32 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=De0Rj007lI5yQGK7/idAAIKtlyvCodOoB+dHvU4T9Js=; b=lXDICr8ztOBNxu f9AcifFgdBz9k2+LiZbbaBx2Xt6/3N/vFWgnjSrF+FnV+HmjI2w3+2WC93laDDwpKBhje0DRANJ9r VzXcViraEp5ME6U7cRhSaxc4f8gBBF7k/DRKP4LMbktXO6gU9IyZ4fo7pC7bslC4dxSns5VKoz6xs EDwtuIdlTB5b+eZCl7dd1RGus/ow3pz4bp+/yH9+wNYLVgd0MGRLGLqJift5lAw+ol1xwvSCr+l9p XVIkvOoiZGO5tNP4uEUG6FkHENhhXrtGsB+bjiQ6IYBiymirjND7RgPIu0ilD0fjGeS7fIoisXlwO +qPMoGTljp58YSSCtdMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r3FwT-000sAG-2E; Wed, 15 Nov 2023 13:28:29 +0000 Received: from mail-lf1-x135.google.com ([2a00:1450:4864:20::135]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r3FwJ-000rzM-2c for linux-snps-arc@lists.infradead.org; Wed, 15 Nov 2023 13:28:21 +0000 Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-507a5f2193bso920598e87.1 for ; Wed, 15 Nov 2023 05:28:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700054898; x=1700659698; darn=lists.infradead.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=27kbaYc9o/j9wTLBAVP45tsETwTbQIy8zKNs3tAOssU=; b=hEoTrGl3yzHtHo6RCF2G/+39GwCg2E87ygnmlMibAIMNfxU1daKqAyq09XnHiv17tK Dh0XeKNJHliUT0vv4nDcSVr5CuGqJFCE6bpiTT2qRgOgEb2FGNGWNvDX0laLnoNGJwZH 0qqB2QRivmqJnqlV8iye/qtROWHIUG0nsJLvFbFeb0Z8MXFumxk9NC/R4JhpVG4l4dyQ Eya6SOBxa1ZyprYVExEk5ke2LGvZI42LQDo3AGT+wZCHs21by0cJr0ee3yojsfhumWut ux/+iGX8mkgVIL5vCiSuudB81tkyWEzdKq7BvNDndx0vA6CzNzhtPZq/z0mgi9vCszW1 FddQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700054898; x=1700659698; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=27kbaYc9o/j9wTLBAVP45tsETwTbQIy8zKNs3tAOssU=; b=diPFNfVFfTnU8LNwN055CtmLisrGj1PNASfXK81232GVTsyjrDyJsoe7KJ8NZVXf+b ImiRCqt0LBSYyB3Jk4y4wlslAQ2SmKmx2hAfKsAMkpbGGVQJd1Z/te56+CYxdlYHag/j pyR9eXvVHNuJd5SjlWntcYfQqsrtYts61dYQSvZ2iQIUg5GYZOugm27SEz2YAx65dXEv UwRN4DKoad+QPQ3rJM0QsuZ9cTILPFqn1nhkxLKMRut/9J6g5DPtfPDKfN2YyjWd1We7 5kh01VZWl2AuTTHWTi79JsvFpiblxzK+r6uJDoeg35jDAXm96LeY52Si80EmOcp4klAk ag5g== X-Gm-Message-State: AOJu0Yz66HGK5qdKSy2Ky+p9XGh5FoAaus0fe/vgRbr50crN+7Mz55GB HPJhpCN5uS0EYPHpI9aWbHlhdw== X-Google-Smtp-Source: AGHT+IF1ifJjaPJepmn4jpc4ZHMqCS1sjn+6cBfSpPYvLaA1BjCWNuLVV5igC58y6bNOjVoqNakptg== X-Received: by 2002:a05:6512:2248:b0:4fe:4896:b6ab with SMTP id i8-20020a056512224800b004fe4896b6abmr2401582lfu.15.1700054897725; Wed, 15 Nov 2023 05:28:17 -0800 (PST) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id l12-20020a19c20c000000b00507b1da672bsm1648705lfc.174.2023.11.15.05.28.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 05:28:17 -0800 (PST) From: Linus Walleij Date: Wed, 15 Nov 2023 14:28:15 +0100 Subject: [PATCH 2/2] Hexagon: Make pfn accessors statics inlines MIME-Version: 1.0 Message-Id: <20231115-virt-to-phy-arch-tree-v1-2-8b61296eae73@linaro.org> References: <20231115-virt-to-phy-arch-tree-v1-0-8b61296eae73@linaro.org> In-Reply-To: <20231115-virt-to-phy-arch-tree-v1-0-8b61296eae73@linaro.org> To: Arnd Bergmann , Vineet Gupta , Brian Cain Cc: linux-arch@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hexagon@vger.kernel.org, Linus Walleij X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231115_052819_875916_91B3DE23 X-CRM114-Status: GOOD ( 10.50 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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_ [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:135 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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. For symmetry do the same with pfn_to_virt(). For compiletime resolution of __pa() we need PAGE_OFFSET which was not available to __pa() and resolved by the preprocessor wherever __pa() was used. Fix this by explicitly including where required, following the pattern of the architectures page.h file. Acked-by: Brian Cain Signed-off-by: Linus Walleij --- arch/hexagon/include/asm/page.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/hexagon/include/asm/page.h b/arch/hexagon/include/asm/page.h index 9c03b9965f07..10f1bc07423c 100644 --- a/arch/hexagon/include/asm/page.h +++ b/arch/hexagon/include/asm/page.h @@ -78,6 +78,9 @@ typedef struct page *pgtable_t; #define __pgd(x) ((pgd_t) { (x) }) #define __pgprot(x) ((pgprot_t) { (x) }) +/* Needed for PAGE_OFFSET used in the macro right below */ +#include + /* * We need a __pa and a __va routine for kernel space. * MIPS says they're only used during mem_init. @@ -125,8 +128,16 @@ static inline void clear_page(void *page) */ #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) -#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) -#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) +static inline unsigned long virt_to_pfn(const void *kaddr) +{ + return __pa(kaddr) >> PAGE_SHIFT; +} + +static inline void *pfn_to_virt(unsigned long pfn) +{ + return (void *)((unsigned long)__va(pfn) << PAGE_SHIFT); +} + #define page_to_virt(page) __va(page_to_phys(page))