From patchwork Wed Sep 13 11:28: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: 138781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1051932vqx; Wed, 13 Sep 2023 05:34:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGS7hrotgeD/9/1GT0JBiAjoFjn0GC7WUWudytgOM/EouMTJ4QhuDspy3to3z4KLnurR7jo X-Received: by 2002:a05:6808:200c:b0:3a8:a4bd:ceed with SMTP id q12-20020a056808200c00b003a8a4bdceedmr3063570oiw.9.1694608483289; Wed, 13 Sep 2023 05:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694608483; cv=none; d=google.com; s=arc-20160816; b=pViSyeRugA21cjB/74o0gT8+247JiED/nsxc+OVyFjenC/dvonDf3yvbQZP+5YvB+b hq9Kr8/FatnAKxEnuTBR5252tWnsVIcoQmSrydoPe7MkeLuG9ttXvBZcsBxlKiyRbL/x hWpy2D/3l7gu9eKkynyR9i5xwmzup/75iouv6/yD19XnnqXxHpyw/RfGdbyLlnUp7/3w lfP76YZcmvQi0rqyRRRR4V3HZVXvwQg+tjcLhAmj11xNh+l9VEY0RACclf3BUMLbJSgo WpUghawseUM63BIedO3J0QjXj1atTnhQ3d2ucs1nbgKPWTBeQs4V+6B09rTdbBzxScx6 0tkA== 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=wbyHNNsN+Rn8ywOWxCv7Wlqb7uh+vWNRuvfamsm2vmc=; fh=LgZsv2gc8QRfiS0F3hzgKsC4Zxi58+qad7Fk7VPbXEM=; b=PAzbOhQM9o5luFzouoVraddPSxzEL53UBDtbagKeKMtGIkD0velCqeBmBavk60ahdW CzH5ptsBI2fyXvBo4T1HEy4JrKqd44m36kqHqvazLwjFyGShBrLQc1KBNXTNTyPxzzYd mH8IXZpVooxveOcu+TWoOYCR0E/E2cWaZusw3d5Z52z6sXVBYbv42nl9hAOx9heRAdpK qBahIAT/CgNpyfNYPW76OVtxgZZKaoq3/pYiKWLRdatrM95VuNd2bcoJu+vwH5ZW26Zd hgyVDoOXP3MiBLy9MvxO6tpgR/Jch7rvjCwFJSRM1s0fZjpLE50xzaCOsvB2ZD071Cvi +PBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=somuFy2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u16-20020a656710000000b00573f7d0944dsi10141062pgf.326.2023.09.13.05.34.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 05:34:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=somuFy2n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id C6F8F80FF025; Wed, 13 Sep 2023 04:29:12 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240198AbjIML2v (ORCPT + 36 others); Wed, 13 Sep 2023 07:28:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240192AbjIML2r (ORCPT ); Wed, 13 Sep 2023 07:28:47 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B74A41BC2 for ; Wed, 13 Sep 2023 04:28:42 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-501eec0a373so10961242e87.3 for ; Wed, 13 Sep 2023 04:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1694604521; x=1695209321; 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=wbyHNNsN+Rn8ywOWxCv7Wlqb7uh+vWNRuvfamsm2vmc=; b=somuFy2nBKLNXqD6nDqNDRMxknIZMZnCRmH97Z6Y+b94Vi3ZOS9VJJYc8sX0WUt7Fo P0fNdCCWH9SnZCosdaiIBGrtDzzWtJZ1cVqxVhS1TxjtX/+dvtjp/8fc9swnFFYgn+AM Ke2x8gTJyDuAQMWpgUR9Kcvx4qrkdIkOHw9ZhJZDt1ruZnH+CPl7ALwSYOwOqizKDX1U UDZC4zM6Zg8cD5Sg5/AvPT0JhGhrAEthHDEircOvGfarAR8njzhg1OqE11j2oJcJjQoz 7lLxCEt6TpRbDwz53/yytdE7qDSWw7VW6AOdiQItce4o5hsc5zBJLIaXnTZxH30tRqMw wlEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694604521; x=1695209321; 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=wbyHNNsN+Rn8ywOWxCv7Wlqb7uh+vWNRuvfamsm2vmc=; b=f3vyoQNvF2E9YBiL3L08OH7PWR0CKUca/5xPkfm286ITcoW2GG4rcut5sulJrTiIZM RM06VnVFi1MN/Ghgwaed63+D6jesY1WYcM1Im9KAcukY4H4aj3RSiEtKKOGIMkINFCsV 7zPo9h2hapJNhW4RPdCSxkMCDgziX/nXW20oUf7TEeW+Zvu1ZZENE4R5mwSE9UXxO4Bg eCFbzf0U4cFdT/tmu4NEKZMOUOBeAAUfm9T7MuBiQvslxhvhCLh25amMBW7KR++xdlhT cz/FufIH6/nRSaN8FwEe4c41+BtaOnNTW7Rv8CexccFCkAllw4hJTzefpMKrTJqsVaYi RA+Q== X-Gm-Message-State: AOJu0Yz2etsouz+z30fwBPr+mhvv8qYHlEtkHkxJ8IY/qRcmxS1D4+yR QfIVZuZT+E1G+mNYpCezj8dgfQ== X-Received: by 2002:ac2:510f:0:b0:500:c765:bbe with SMTP id q15-20020ac2510f000000b00500c7650bbemr1778015lfb.0.1694604520898; Wed, 13 Sep 2023 04:28:40 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id v17-20020ac25931000000b004ff8f448343sm2082639lfi.33.2023.09.13.04.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:28:40 -0700 (PDT) From: Linus Walleij Date: Wed, 13 Sep 2023 13:28:35 +0200 Subject: [PATCH v3] Hexagon: Make pfn accessors statics inlines MIME-Version: 1.0 Message-Id: <20230913-hexagon-virt-to-pfn-v3-1-8bed34005011@linaro.org> X-B4-Tracking: v=1; b=H4sIAOKcAWUC/33NTQrCMBCG4atI1o4kaWKiK+8hLvozaQckKUkJl dK7m3alIC7fD+aZhSWMhIldDwuLmClR8CWq44G1Q+17BOpKM8llxS23MOBc98FDpjjBFGB0HpQ 2TadFrY1SrFyOER3Nu3p/lB4oTSG+9idZbOt/LwsQcLYdN62Uwglze5KvYziF2LMNzPIDEfw3I guCrW2U0NJdHH4h67q+AZrjTkn8AAAA To: Brian Cain Cc: linux-hexagon@vger.kernel.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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:29:12 -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 morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776925784839380719 X-GMAIL-MSGID: 1776925784839380719 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 --- Changes in v3: - Rebase on kernel v6.6-rc1 - Link to v2: https://lore.kernel.org/r/20230810-hexagon-virt-to-pfn-v2-1-ec8b4152f9fe@linaro.org Changes in v2: - Use more elaborate casting back to unsigned long before shifting in pfn_to_virt and back to void * after that. - Link to v1: https://lore.kernel.org/r/20230808-hexagon-virt-to-pfn-v1-1-68d07c221f17@linaro.org --- arch/hexagon/include/asm/page.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d change-id: 20230808-hexagon-virt-to-pfn-457bd51a5744 Best regards, 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))