From patchwork Wed Aug 9 08:14:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2647905vqr; Wed, 9 Aug 2023 01:35:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeEKRtfg5Dl8ZhpgriN8gBloRbwiln4xG4iPLIgRPsY0HGIqJri6KnK7by18Q+e76omhRh X-Received: by 2002:a17:902:d2cf:b0:1b8:66f6:87a3 with SMTP id n15-20020a170902d2cf00b001b866f687a3mr2461686plc.52.1691570112366; Wed, 09 Aug 2023 01:35:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691570112; cv=none; d=google.com; s=arc-20160816; b=ikCzI5DUFCsyZ+S7eb/CdJ+pRqmlhIxEh9lL4lb0g3dnSZlpkD0SlSNuAg7wbTwBP4 DstrZlrxa3NmLw95WVCV2S/yYnbsAvn1zY58YUfawl6/lihQDjIL1dTzNA7c063t0Q9A DtIsW55Kmupfd2GfTF2PxGuDvBnu7Wv7z0pAuUS2lHFPWRJPuIuDqbcVBrEpBFrVtRwa uwCPtuUgovOdx8Vm5+1QdL0KqS7flcLNpNjOwdpMKRciurMu855c0f3C4XGAlIYkLaoC 9XAm9DVOjCIdEzdZuWMPPI51/lcIpzFclyPTgf8KiqldNYFELIQTs3qo4G3gmSnTjk0S +wyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=WPNuwr8BV2crYdR1HSxa9CVFwtJ2x4ORzKRyFk7VJAs=; fh=U9aMXhC4C3vp50RpX5/W/je1e0oxyhy5HPsCZC8XORg=; b=xil2rKYWzzQWoYy5CClDH7jtoePFIonKJf5I7Z+OkFQ/2407BSnl3+LVk6xtRe9+st ugwIpQNSEwraNdOY8E3WUXtdKmev1scVc35JaXyUHEd9pQNAgSO4utJCJraYkkqwj/4x 8oc5W2A/88aH/kOPy1IlBeGwR638m/sLo5U2KqXh4HmXw5xtjP0zbJ9X0CWDzdNxArDo 50DY7XEYZlH7X5ztVoM4OO3VhggJNBwUw+M47nFtbKhi1mBOP/NlWmSfpA4ZgROAxMJS /FsWEt0favzCAQHB2dDiMokf7GVr5fTQiIUQGORpVa4Nn6zhU/7g+G5hrA7Cn4uIOOdk wSLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S3NUfjB4; 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 13-20020a170902ee4d00b001b8a4519706si8619709plo.19.2023.08.09.01.34.59; Wed, 09 Aug 2023 01:35:12 -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=S3NUfjB4; 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 S231873AbjHIIOI (ORCPT + 99 others); Wed, 9 Aug 2023 04:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231867AbjHIIOG (ORCPT ); Wed, 9 Aug 2023 04:14:06 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFA6810FE for ; Wed, 9 Aug 2023 01:14:05 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fe655796faso5638386e87.2 for ; Wed, 09 Aug 2023 01:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691568844; x=1692173644; 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=WPNuwr8BV2crYdR1HSxa9CVFwtJ2x4ORzKRyFk7VJAs=; b=S3NUfjB4bsVe9j6vOvkgbzCiTwC+/LUZKHOJA+DVd1hF79XKEdcJLk5HeANwSJMNbE wFpiDbSv79eoDUKbFvABoRC4bzoj14hmJCAJZ+IEaSBva/ry7TZMziatdW3YEqIdCjgB YulVLM079c0A02u23M9dDfoB9cMLWz0IkCBNCjYoMH6qyb1qOSwKadguXMuWw3CgQUVQ 0+9kRZjClq3de5Y0DtfavbxvkIy/dspo/iG+vratIzTwZtvaM+YMiU76D9uExhAgJoxH 7UE9kG79yVX/aXKS7E+0xBKcFA0aQMmaJjFSi5930Xbdy/54AMjv26QFYnm5g9zPIY59 7OpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691568844; x=1692173644; 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=WPNuwr8BV2crYdR1HSxa9CVFwtJ2x4ORzKRyFk7VJAs=; b=YM+JCHBhiknO7e72aT3ClOgAthDdhq63FCU7P0swWj79Ees1dJaR/YTxerK5hKLKyi PUC917aynS2LI1nb5Jk/yrvIvrCxUEIFal01MwtnLvr2SQUtPtIdybeBX0Ab4mSChc7m Lrgi0LXxF+CA9KB5tYGHMEU4b0xjTs/kNi+MZaYn3hbOOoB5GsJUSKncde+tkf4aH/OP TsP/o/Sx/otKzh/2+MRaftBBX0oFeNG8mJuYIPEAklrBKani0DCmXKkbs/GafY+AJxgq 5jzfqsucY5eEsESaxhRaOwQ9pWdB7PmhMWStJDdKPClxJE45DU9Pro484SQdz5vBKl/W Z8TA== X-Gm-Message-State: AOJu0YwuTWQXtEd9mBHy46gVT7SghVUfR9C3yugIBCmi1+5FxhZr1vG8 O2MGTRB+oQexCYRa/aTqHn6w2A== X-Received: by 2002:a05:6512:3d24:b0:4f9:571d:c50e with SMTP id d36-20020a0565123d2400b004f9571dc50emr1501208lfv.36.1691568843947; Wed, 09 Aug 2023 01:14:03 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id w12-20020ac25d4c000000b004f84a92ba75sm2196916lfd.65.2023.08.09.01.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 01:14:03 -0700 (PDT) From: Linus Walleij Date: Wed, 09 Aug 2023 10:14:01 +0200 Subject: [PATCH v2 1/2] csky: Cast argument to virt_to_pfn() to (void *) MIME-Version: 1.0 Message-Id: <20230809-csky-virt-to-phys-v2-1-2697c93f60cf@linaro.org> References: <20230809-csky-virt-to-phys-v2-0-2697c93f60cf@linaro.org> In-Reply-To: <20230809-csky-virt-to-phys-v2-0-2697c93f60cf@linaro.org> To: Vineet Gupta , Guo Ren Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, Linus Walleij 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=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773739822219327654 X-GMAIL-MSGID: 1773739822219327654 The virt_to_pfn() function takes a (void *) as argument, fix this up to avoid exploiting the unintended polymorphism of virt_to_pfn. Acked-by: Guo Ren Signed-off-by: Linus Walleij --- arch/arc/include/asm/page.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arc/include/asm/page.h b/arch/arc/include/asm/page.h index e43fe27ec54d..02b53ad811fb 100644 --- a/arch/arc/include/asm/page.h +++ b/arch/arc/include/asm/page.h @@ -108,7 +108,7 @@ extern int pfn_valid(unsigned long pfn); #else /* CONFIG_HIGHMEM */ -#define ARCH_PFN_OFFSET virt_to_pfn(CONFIG_LINUX_RAM_BASE) +#define ARCH_PFN_OFFSET virt_to_pfn((void *)CONFIG_LINUX_RAM_BASE) #endif /* CONFIG_HIGHMEM */ From patchwork Wed Aug 9 08:14:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 133119 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp2648314vqr; Wed, 9 Aug 2023 01:36:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeVSnDLSB3yYtBdo6hB8cBKBO6ZVvyAcrjeLwsXZjYeJnjlmJ7jGwXqnBImFamZbtl8gXJ X-Received: by 2002:a05:6870:fb8b:b0:1b0:3637:2bbe with SMTP id kv11-20020a056870fb8b00b001b036372bbemr2191932oab.54.1691570166876; Wed, 09 Aug 2023 01:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691570166; cv=none; d=google.com; s=arc-20160816; b=juVhcLKXEEhvoZtLXlM9OQVEIei9147Z8WGS9oORnCjOI8LsRqopfZ2yJW24ZX5L3n mdp4NKJ1qQTwxTUr+Eay6bT4Unn07983PNQP3GgmR5gilHeYpOHQvvHUnclSIGVbejSV +B1mPU03Yjk20A8b7aU1wjWhI310tujvmt4hRkFrjRLlad2lkDyHVrD9fMIjFuGKlT3J D/R+GiwCCw8zpEMnXU/LGBZOC6VGSugl7PnV+1weJwyv0XYgHU/46j7nmUYmuPBBhXq1 NmH0rTSl1rnphd8x+6+nGtO+OzsYT1aRg6dGVAGraadLB9YUztzXqg7BfvX5fkGJlMkN W7LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=zTXAtK4LyKDOWesDbd7G0no9IFm0HYr1YL9cGl87EzQ=; fh=U9aMXhC4C3vp50RpX5/W/je1e0oxyhy5HPsCZC8XORg=; b=fU3l1Op9HYNzAk8M43IyNE8kbAU5SzrIMqWFcdnVivrCp3ivgFcnpVPFisMn8ZvjpR JuwU6R6Lf+SWip0cZl7wpCWRK7gmUip9PJRNRgGRMTIfqSbmwA+Ky7rq4a1hNKH8BJkr CUwjfAx6iIurkYc/eWQkmZYTqBU//28SvOQpcQlNeWrw37C3r7XNHX5Uld2NK+jIuJ0q fRnenszL952hCUTvkXC7Btln+0F3WzqujOhiv0H6Y+tHd/lRDEs4azVMJkj+oGnbTszv IWGp3bJiw9E7+MIbuGrADClZisOhEbFLON5N7GGD7ZlwplVb47nx/jevjd2JPjrHCkbl Iy/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AaZNvaOL; 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 l2-20020a654c42000000b005644c5717c1si8835506pgr.252.2023.08.09.01.35.54; Wed, 09 Aug 2023 01:36:06 -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=AaZNvaOL; 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 S231890AbjHIIOK (ORCPT + 99 others); Wed, 9 Aug 2023 04:14:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231879AbjHIIOH (ORCPT ); Wed, 9 Aug 2023 04:14:07 -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 B4B4E10F6 for ; Wed, 9 Aug 2023 01:14:06 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4fe28e4671dso10587850e87.0 for ; Wed, 09 Aug 2023 01:14:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1691568845; x=1692173645; 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=zTXAtK4LyKDOWesDbd7G0no9IFm0HYr1YL9cGl87EzQ=; b=AaZNvaOLHpTrWuNHOIAzKFkJD8Yhj84hT19T1S7uT/t4tAzdb7OJkojkl/IfOZM0ZT 9OINRO5D+ZqlDOHj1/yMIimjGzifYxI4yS9+jjO4Xn+E6Vya6HLMzKt3k76Dg/VjFSMI PvMctNeBYwj67QOe5HCfNpg6SS6/OFsOV5WrJIYEy4YlQhsGyTgb2yhcsak2KrWHzLtr KVOcpMyQfhALHBin9A/U1b/I5aJw2ovXVaIN6hjIeRn7l1HHNMV3eZ9i7JiLNF6zYT9v O1a1qb9IK2i/+JXmfbv24ygVsmeoyP4XXvc1d+Q636+IwmVApXCHvdX5yKKaco2Q556t ONfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691568845; x=1692173645; 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=zTXAtK4LyKDOWesDbd7G0no9IFm0HYr1YL9cGl87EzQ=; b=fsbEPf/FEfyZ5rgwEEsOgtjdGuCTOpvlc9YXESYRgdW1q4NCFH3Lso0FN9hOYhiTzV iIUQw68fGfMRWr0ytevO87Ts2ldyLgu1XMgz9Io3+hEXii1aL/55cWQTIy2qrajjO0JO WaU7Yl1AtdKLBRJGhmIqGEvPh+Zomd07y6TO0C7M3RSLLY+NU6UpaCJRVuCZpyhOKGNN lGv/y+hSYGa8v7zxS2xq6ZaNSbw/FEqWNTyVQnDDodr9nebuWLtcOj1Jbv+BD0Fo264/ xsgZ79VnX7BuH/EJoHYEh85kOv+IEcu+b+PXesezF13gCqnrHMXsHcKPfAiw+RIp19Sk 4kLg== X-Gm-Message-State: AOJu0YwWrGRD/FhbdY6meIJFldscMrMmp7HwWevJ+Qy0bCWLJW/fcKvZ mEst20ivNIuKac15nyFRxd/ZhA== X-Received: by 2002:a05:6512:2507:b0:4f8:770f:1b08 with SMTP id be7-20020a056512250700b004f8770f1b08mr1528563lfb.13.1691568844988; Wed, 09 Aug 2023 01:14:04 -0700 (PDT) Received: from [127.0.1.1] ([85.235.12.238]) by smtp.gmail.com with ESMTPSA id w12-20020ac25d4c000000b004f84a92ba75sm2196916lfd.65.2023.08.09.01.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 01:14:04 -0700 (PDT) From: Linus Walleij Date: Wed, 09 Aug 2023 10:14:02 +0200 Subject: [PATCH v2 2/2] csky: Make pfn accessors static inlines MIME-Version: 1.0 Message-Id: <20230809-csky-virt-to-phys-v2-2-2697c93f60cf@linaro.org> References: <20230809-csky-virt-to-phys-v2-0-2697c93f60cf@linaro.org> In-Reply-To: <20230809-csky-virt-to-phys-v2-0-2697c93f60cf@linaro.org> To: Vineet Gupta , Guo Ren Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org, linux-csky@vger.kernel.org, Linus Walleij 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=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773739879552062392 X-GMAIL-MSGID: 1773739879552062392 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 to the same thing with pfn_to_virt(). In order to do this we move the virt_to_phys() and phys_to_virt() below the definitions of the __pa() and __va() macros so it compiles. The macro version was also able to do recursive symbol resolution. Acked-by: Guo Ren Signed-off-by: Linus Walleij --- arch/csky/include/asm/page.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/arch/csky/include/asm/page.h b/arch/csky/include/asm/page.h index b23e3006a9e0..57b3f106ae77 100644 --- a/arch/csky/include/asm/page.h +++ b/arch/csky/include/asm/page.h @@ -34,9 +34,6 @@ #include -#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) -#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) - #define virt_addr_valid(kaddr) ((void *)(kaddr) >= (void *)PAGE_OFFSET && \ (void *)(kaddr) < high_memory) @@ -80,6 +77,16 @@ extern unsigned long va_pa_offset; #define __pa_symbol(x) __pa(RELOC_HIDE((unsigned long)(x), 0)) +static inline unsigned long virt_to_pfn(const void *kaddr) +{ + return __pa(kaddr) >> PAGE_SHIFT; +} + +static inline const void * pfn_to_virt(unsigned long pfn) +{ + return (const void *)((unsigned long)__va(pfn) << PAGE_SHIFT); +} + #define MAP_NR(x) PFN_DOWN((unsigned long)(x) - PAGE_OFFSET - \ PHYS_OFFSET_OFFSET) #define virt_to_page(x) (mem_map + MAP_NR(x))