Message ID | 20230811-virt-to-phys-openrisc-v2-1-3500d015bcc0@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp906555vqi; Fri, 11 Aug 2023 00:10:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFd3D9NHACoLb01kh+ccwjCyc3uC76cl31MO9vugGr6QQbPyry4QUlWUNCa8kRMy+ib4F+r X-Received: by 2002:a17:906:76c2:b0:991:d9cb:247d with SMTP id q2-20020a17090676c200b00991d9cb247dmr1048968ejn.57.1691737813127; Fri, 11 Aug 2023 00:10:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691737813; cv=none; d=google.com; s=arc-20160816; b=t7HOTVhpsMhkV5zw0dPO7F1yu1uKZ75kL9/kPsTqmahFL+gZsHXn0dQf8mLZUQI8KP apGBtOaudy7y+aZi6Fik1AUDBOo5zVjuQ8pen4iUWiagllPnV2cbtqwAjml28jAIPxPG umtoFFfBoEMpDcjOWw7bHC9L5zXGkt39neQd+XcyUL4vneWcO7Kr01AHaj+TdYBULdOz 7/57rvuX9ACvUmrJLsCdj+OXE8BVAkn5sYo4f/84pDWPBaKWdDJWXDZS8zSxcNQ0eFon FHHMwOVDwemV0oZFfidDWfQFQqEM4TTufi2GGNz3dgaCHrhWN9VDFHV73/W++8pDThu5 kx4w== 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=fT3TYzmdwJ/MNgNgMofzXAXGmEmUnvc3SrKF/6LK3Sg=; fh=wM0ALekKma0UJp0bE5P6WdAs9hE9Kceamb9674WfrHI=; b=rfEueuVmVT1ghyl8xMvhvG1nyowsH88JTmi5/Ud5UcVIe+f7KxrsxzVvRtAW11Ywg3 IQ5+vU0OsJfUPHXoUwed88O/cgYQpUfYjVLHNeF0ucxUxaVUSRp03yNay9Mk/bNyYs6U uHYiZwKKergiqhEbHGfcPBiX9Xk0K/nwoElGdq+jqqCSqxkITm5QFD+kKbq+exTldkQs am3bA84BQccn5xYCyidEv3Tdhe+Xyh4FvQRo6PIM+lDzT67BTliaEjB+YmIHYZh+Ww4b u9XXNqM/ZiMxHOACp7kyhVoweDy628djpDdmilU88E+oLCeamxD3Rkqfyi7QCaiLvBph GrQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KG09fJfD; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a8-20020a1709064a4800b0098678728b52si2981039ejv.123.2023.08.11.00.09.48; Fri, 11 Aug 2023 00:10:13 -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=@linaro.org header.s=google header.b=KG09fJfD; 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=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232599AbjHKHBY (ORCPT <rfc822;shaohuahua6@gmail.com> + 99 others); Fri, 11 Aug 2023 03:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229927AbjHKHBX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Aug 2023 03:01:23 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0E7726AE for <linux-kernel@vger.kernel.org>; Fri, 11 Aug 2023 00:01:22 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fe0eb0ca75so2512248e87.2 for <linux-kernel@vger.kernel.org>; Fri, 11 Aug 2023 00:01:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691737280; x=1692342080; h=cc:to:message-id:content-transfer-encoding:mime-version:subject :date:from:from:to:cc:subject:date:message-id:reply-to; bh=fT3TYzmdwJ/MNgNgMofzXAXGmEmUnvc3SrKF/6LK3Sg=; b=KG09fJfDwl4FKObmon//fY9/heOSsiu21jbnUoYY6QFoUad0Bd1jUoaK4uNnaRP8Z4 6shu8rwFbJ9vLkl/nZglQqfBhBwuGdXKgteClW5laXHzy1htRYPFDswDnSlu6ZnuE7wQ szegPHRyk0lnaEf2pe86kixPQBEPfFD7XFlL+AV9L+VeJDp9G2cTmEaqd6sdcZJYLMzE PrDAZcBQgPV/JtcNaG8u7OiMfzJlrVCD+eUe9I4UNlQdUqEAIeLXWZPlY3zZ/3MXNZE1 vpz4TbU4D8rq9P3vyVNwVPtf3pvGDGgKv/hSqIITlL3oDWIl4h1vRInMDb54EhEqESxd JKZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691737280; x=1692342080; 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=fT3TYzmdwJ/MNgNgMofzXAXGmEmUnvc3SrKF/6LK3Sg=; b=N4hATYzOmDqvIrM7J7CZ1G+1ewRvwTyS2azBzZC6uk3UVoNa5bvwkTGccM5KweMewH 7+a0af4yz6EvFX+hfE/KOOkm5LMXlksMn0ejRzxCQHXfyYMx+/8d68a+9AwR12Iykm5r 7oewlPmX1cxHUFnQuUDJc7GiGGdYI1tzDfYKzwgZdvVDpYSw7W86zaF9euzSm9R62mHc pCBn0lR2pu9Q+UNy9rFRir9mpy72aNTbqCgqqZYV0Vsh92QoNFzP0tkxZWPrUHzJNMk/ kaqIaMjgRwPdZ3oRVHZMNA/IDvKU02uy3wsbkKzHsxM26Oirj94NBpK4mLXGhUIvHinx UPCw== X-Gm-Message-State: AOJu0YzDzK3xv8aCns6byYl+EkZAtDVdQ8otpKpuY7yA4sDeWOX+U3VJ Bn0CTeW3M6CPJbhf8kY7tq/jEQ92BM3oT3nSWqE= X-Received: by 2002:a05:6512:2011:b0:4fb:987b:ec3c with SMTP id a17-20020a056512201100b004fb987bec3cmr581223lfb.56.1691737280573; Fri, 11 Aug 2023 00:01:20 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id q28-20020ac25a1c000000b004fbc82dd1a5sm610463lfn.13.2023.08.11.00.01.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 00:01:19 -0700 (PDT) From: Linus Walleij <linus.walleij@linaro.org> Date: Fri, 11 Aug 2023 09:01:17 +0200 Subject: [PATCH v2] openrisc: Make pfn accessors statics inlines MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230811-virt-to-phys-openrisc-v2-1-3500d015bcc0@linaro.org> X-B4-Tracking: v=1; b=H4sIALzc1WQC/4WNQQrCMBBFr1Jm7cgkRQmuvId0EeOkHZCkTEqwl N7d2Au4fA/++xsUVuECt24D5SpFcmpgTx2EyaeRUV6NwZLtyZHDKrrgknGe1oJ55qRSAroY6RJ s33uO0LazcpTP0X0MjScpS9b1uKnmZ/8Vq0GDTxvMNUQi8u7+luQ1n7OOMOz7/gX8L4gBuwAAA A== To: Jonas Bonn <jonas@southpole.se>, Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>, Stafford Horne <shorne@gmail.com> Cc: linux-openrisc@vger.kernel.org, linux-kernel@vger.kernel.org, Linus Walleij <linus.walleij@linaro.org> X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773915669272563797 X-GMAIL-MSGID: 1773915669272563797 |
Series |
[v2] openrisc: Make pfn accessors statics inlines
|
|
Commit Message
Linus Walleij
Aug. 11, 2023, 7:01 a.m. UTC
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().
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
Changes in v2:
- Cast around a bit in the pfn_to_virt() function so we don't
get pointer violation complaints.
- Link to v1: https://lore.kernel.org/r/20230808-virt-to-phys-openrisc-v1-1-b2c16cf000a8@linaro.org
---
arch/openrisc/include/asm/page.h | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230808-virt-to-phys-openrisc-8ff05c233aef
Best regards,
Comments
On Fri, Aug 11, 2023 at 09:01:17AM +0200, Linus Walleij wrote: > 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(). > > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > Changes in v2: > - Cast around a bit in the pfn_to_virt() function so we don't > get pointer violation complaints. > - Link to v1: https://lore.kernel.org/r/20230808-virt-to-phys-openrisc-v1-1-b2c16cf000a8@linaro.org > --- > arch/openrisc/include/asm/page.h | 11 +++++++++-- > 1 file changed, 9 insertions(+), 2 deletions(-) > > diff --git a/arch/openrisc/include/asm/page.h b/arch/openrisc/include/asm/page.h > index 52b0d7e76446..44fc1fd56717 100644 > --- a/arch/openrisc/include/asm/page.h > +++ b/arch/openrisc/include/asm/page.h > @@ -72,8 +72,15 @@ typedef struct page *pgtable_t; > #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET)) > #define __pa(x) ((unsigned long) (x) - PAGE_OFFSET) > > -#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 virt_to_page(addr) \ > (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT)) > Thanks, applied to my queue of patches for 6.6. Note, I did some C=2 builds and booted 6.5-rc5 with this patch with no issues. -Stafford
diff --git a/arch/openrisc/include/asm/page.h b/arch/openrisc/include/asm/page.h index 52b0d7e76446..44fc1fd56717 100644 --- a/arch/openrisc/include/asm/page.h +++ b/arch/openrisc/include/asm/page.h @@ -72,8 +72,15 @@ typedef struct page *pgtable_t; #define __va(x) ((void *)((unsigned long)(x) + PAGE_OFFSET)) #define __pa(x) ((unsigned long) (x) - PAGE_OFFSET) -#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 virt_to_page(addr) \ (mem_map + (((unsigned long)(addr)-PAGE_OFFSET) >> PAGE_SHIFT))