From patchwork Fri Jan 15 16:58:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 12023263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A0F25C433DB for ; Fri, 15 Jan 2021 17:05:37 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 60D1523136 for ; Fri, 15 Jan 2021 17:05:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60D1523136 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=kL4tUay9/C1+rdmacvcalAQfT4MiOSug5ysanc8m8FI=; b=hLtFseMSM2w0TQyRVyfZOlvps dXCytkJME4/Zq5hHSDwrL038x5wculWk+GTTFVmgoluAxw+4Aij9ySmmyStcIvPbwtjMNapAxnGWc hJ5UvpHf21kWbIr/BDlONiEgSW5t5vnIkeR5J4/iYV/8Q0rECwK61oqtGAmMN7I98PCSjqrRnvh7e YkoVfegQNHs/URUC2mdGlxu8A7HyqEto3tMMVw3MrsDooGeSuIQJYh+1baIBCZgSyX8y+dIcqwKry tcUJC3nLO4Erwa1ZPYX0rwtKr9O1thxvJYMyrTMijM2YsxxvjDEnQWG39PDIdpGXWfG7tL+YAd697 JQab53uCg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SW9-0007SN-MD; Fri, 15 Jan 2021 17:04:09 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SW7-0007QO-9w for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:04:08 +0000 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DHSDB5GBfzj8Gd; Sat, 16 Jan 2021 01:02:50 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 16 Jan 2021 01:03:47 +0800 From: John Garry To: , , , , , , , , Subject: [PATCH RFC 1/4] arm64: io: Introduce IO_SPACE_BASE Date: Sat, 16 Jan 2021 00:58:46 +0800 Message-ID: <1610729929-188490-2-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1610729929-188490-1-git-send-email-john.garry@huawei.com> References: <1610729929-188490-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_120407_627987_65E216DC X-CRM114-Status: UNSURE ( 9.50 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-pci@vger.kernel.org, John Garry , linuxarm@openeuler.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Introduce IO_SPACE_BASE, which is the base address of the IO port region. 0x10000 is chosen intentionally to exclude legacy ISA IO port address range. Signed-off-by: John Garry --- arch/arm64/include/asm/io.h | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index fd172c41df90..2bcf55704bee 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -148,6 +148,7 @@ static inline u64 __raw_readq(const volatile void __iomem *addr) #define arch_has_dev_port() (1) #define IO_SPACE_LIMIT (PCI_IO_SIZE - 1) #define PCI_IOBASE ((void __iomem *)PCI_IO_START) +#define IO_SPACE_BASE (0x10000) /* * String version of I/O memory access operations. From patchwork Fri Jan 15 16:58:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 12023265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F406C433DB for ; Fri, 15 Jan 2021 17:05:48 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3506E222B3 for ; Fri, 15 Jan 2021 17:05:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3506E222B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Aglt3r82d+YDwJw97uURiS28tVLesOwMNtR94XSLK48=; b=jtxC1xohQB/X/Ggxw5trho2mS xjmC+rU5Lfs0ynECisvY0MVa+4UeZdPtmgWv3qIjVbaJ3OOgcWVkT6mC1Td0UtQCS7rDO3VPjSQWE f0fl4j1WbK+k3ttWTWvl79tZdE9CaJPLLSCbpDkzAxBrvTH4oCxIMA0oXaab1Fq8iukdblERDDmnE /jfmS4WZJLpFTpICH7qOtNXsx9SS91WX8lijlMBaVnHrud+Zem3ClEuJAqujre9HQbrHpcCLGQuXR 7LRozCXjnNrYvmIQm2L42rHshvlLKgiEuItvMuimfiB+FkZdAsGEANya/fnxeKNkZZ42OOJaX92wm LvA3Q+62A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SWJ-0007UD-JI; Fri, 15 Jan 2021 17:04:19 +0000 Received: from szxga05-in.huawei.com ([45.249.212.191]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SWF-0007QV-0y for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:04:15 +0000 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DHSCy3tRQzMKdS; Sat, 16 Jan 2021 01:02:38 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 16 Jan 2021 01:03:47 +0800 From: John Garry To: , , , , , , , , Subject: [PATCH RFC 2/4] asm-generic/io.h: Add IO_SPACE_BASE Date: Sat, 16 Jan 2021 00:58:47 +0800 Message-ID: <1610729929-188490-3-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1610729929-188490-1-git-send-email-john.garry@huawei.com> References: <1610729929-188490-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_120415_341389_9C98DDC2 X-CRM114-Status: UNSURE ( 8.37 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-pci@vger.kernel.org, John Garry , linuxarm@openeuler.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a fallback default for IO_SPACE_BASE (at 0) for when an architecture does not define a value. Signed-off-by: John Garry --- include/asm-generic/io.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 9ea83d80eb6f..4d74a0c696ca 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -448,6 +448,10 @@ static inline void writesq(volatile void __iomem *addr, const void *buffer, #define IO_SPACE_LIMIT 0xffff #endif +#ifndef IO_SPACE_BASE +#define IO_SPACE_BASE 0x0 +#endif + /* * {in,out}{b,w,l}() access little endian I/O. {in,out}{b,w,l}_p() can be * implemented on hardware that needs an additional delay for I/O accesses to From patchwork Fri Jan 15 16:58:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 12023291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE9ECC433DB for ; Fri, 15 Jan 2021 17:07:50 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8F00F222B3 for ; Fri, 15 Jan 2021 17:07:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F00F222B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AhEZO0tjNAH7ix6NJTLLIUqwDnh5DAW4OVSo7trX+eE=; b=TFjTHM9W1kE0yaBLw37Vq28XA UNc/y1OlK4/8Y/tsRu4y493BZa6zgDSUbfPdP+o0pztBAfTkCESkFA6cSL/y4P+56iBeYZVwAagZB 2M5Lxmej9MSKLPEKaVLbzNMTbvYuRHEK0M/7CyTMRMHzWSBtnyDw0EbafB0KT7lGpuoTVn9qqjhle SxysHe2ZSqBezxtkLGGtEt999h8mSJlAYaajz7Kfl4Ba62YCuCjrvuojDBA4U2mExzBf6gSZOTihl ppc/+83DUFLv8clzF4yvDoXzlx6F+pQOiUfLmEiQoce9aFzgPrg537LeLARAYoKCIKWGKMcWyD0dm IhZNHr8ow==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SYC-00083d-RG; Fri, 15 Jan 2021 17:06:16 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SY2-0007QR-2h for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:06:15 +0000 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DHSDH3K0Kz15t3w; Sat, 16 Jan 2021 01:02:55 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 16 Jan 2021 01:03:48 +0800 From: John Garry To: , , , , , , , , Subject: [PATCH RFC 3/4] kernel/resource: Make ioport_resource.start configurable Date: Sat, 16 Jan 2021 00:58:48 +0800 Message-ID: <1610729929-188490-4-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1610729929-188490-1-git-send-email-john.garry@huawei.com> References: <1610729929-188490-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_120607_203492_604C5AEE X-CRM114-Status: GOOD ( 11.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-pci@vger.kernel.org, John Garry , linuxarm@openeuler.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Make IO space base address to be configurable through IO_SPACE_BASE. This will allow architectures which do not natively support IO ports - like arm64 - to harden against legacy ISA-based drivers which use hardcoded addresses to access IO ports. Any attempts for these drivers to request a resource region will now fail for architectures with set IO_SPACE_BASE above legacy ISA IO port region (0xffff). Signed-off-by: John Garry --- kernel/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/resource.c b/kernel/resource.c index 3ae2f56cc79d..d191c4d796c7 100644 --- a/kernel/resource.c +++ b/kernel/resource.c @@ -29,7 +29,7 @@ struct resource ioport_resource = { .name = "PCI IO", - .start = 0, + .start = IO_SPACE_BASE, .end = IO_SPACE_LIMIT, .flags = IORESOURCE_IO, }; From patchwork Fri Jan 15 16:58:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 12023267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61120C433E6 for ; Fri, 15 Jan 2021 17:05:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 12DF4222B3 for ; Fri, 15 Jan 2021 17:05:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12DF4222B3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Mggc76v5HbVC/G0xXBdEA/WF/273GxCrjWCzeAxQ7EQ=; b=A7Zmw6UpsgfOM2Kx7cb8DQ5DH HdggLYdnlsI6Zq+IdvZnNpu7kaMKWGSsKeJpCCS5ekwwGaspP3IObrGMJE3w7zU2ATd9Pf44L3UYP mxUKuGFGoUY7CqneoMItkGH/sbZ7mcbBEg19mWnO2atfrqd0qco7lNWno2ewg334zoi8PZE3DDdsg o4ntCTtCdoG+mEhVIB/FtRK2HvXEqWDDZ+y53N/zUnOba8iEh3A6e4mGnLu28HwH7hZQEigea5cIn peM5HlqptN+oouUAjwAQ7Ur3TfzvcQPUFeXzBRC/YnWKVZ7uWlNBD7fPav6Rb/7uuMt3XU2ILB4zC PKeH3YS0Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SWL-0007UY-Os; Fri, 15 Jan 2021 17:04:21 +0000 Received: from szxga04-in.huawei.com ([45.249.212.190]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l0SW9-0007QS-Oi for linux-arm-kernel@lists.infradead.org; Fri, 15 Jan 2021 17:04:16 +0000 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DHSDH3lPDz15tQD; Sat, 16 Jan 2021 01:02:55 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 16 Jan 2021 01:03:48 +0800 From: John Garry To: , , , , , , , , Subject: [PATCH RFC 4/4] logic_pio: Warn on and discard accesses to addresses below IO_SPACE_BASE Date: Sat, 16 Jan 2021 00:58:49 +0800 Message-ID: <1610729929-188490-5-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1610729929-188490-1-git-send-email-john.garry@huawei.com> References: <1610729929-188490-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210115_120415_509208_88315393 X-CRM114-Status: GOOD ( 13.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, linux-pci@vger.kernel.org, John Garry , linuxarm@openeuler.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Start the PCI MMIO region at IO_SPACE_BASE, and warn on any accesses below that address. Those accesses are also discarded. This is only for CONFIG_INDIRECT_PIO currently, and support can be added later for !CONFIG_INDIRECT_PIO. Signed-off-by: John Garry --- include/linux/logic_pio.h | 5 +++++ lib/logic_pio.c | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/linux/logic_pio.h b/include/linux/logic_pio.h index 54945aa824b4..425369f2ddd5 100644 --- a/include/linux/logic_pio.h +++ b/include/linux/logic_pio.h @@ -111,7 +111,12 @@ void logic_outsl(unsigned long addr, const void *buffer, unsigned int count); #else #define PIO_INDIRECT_SIZE 0 #endif /* CONFIG_INDIRECT_PIO */ + #define MMIO_UPPER_LIMIT (IO_SPACE_LIMIT - PIO_INDIRECT_SIZE) +#define MMIO_LOWER_LIMIT IO_SPACE_BASE +#if MMIO_LOWER_LIMIT >= MMIO_UPPER_LIMIT +#error MMIO_UPPPER_LIMIT should be above MMIO_LOWER_LIMIT +#endif struct logic_pio_hwaddr *find_io_range_by_fwnode(struct fwnode_handle *fwnode); unsigned long logic_pio_trans_hwaddr(struct fwnode_handle *fwnode, diff --git a/lib/logic_pio.c b/lib/logic_pio.c index f32fe481b492..cbb12260ede6 100644 --- a/lib/logic_pio.c +++ b/lib/logic_pio.c @@ -36,7 +36,7 @@ int logic_pio_register_range(struct logic_pio_hwaddr *new_range) struct logic_pio_hwaddr *range; resource_size_t start; resource_size_t end; - resource_size_t mmio_end = 0; + resource_size_t mmio_end = MMIO_LOWER_LIMIT; resource_size_t iio_sz = MMIO_UPPER_LIMIT; int ret = 0; @@ -234,7 +234,9 @@ type logic_in##bwl(unsigned long addr) \ { \ type ret = (type)~0; \ \ - if (addr < MMIO_UPPER_LIMIT) { \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ ret = _in##bwl(addr); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ @@ -250,8 +252,10 @@ type logic_in##bwl(unsigned long addr) \ \ void logic_out##bwl(type value, unsigned long addr) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ - _out##bwl(value, addr); \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ + _out##bwl(value, addr); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ \ @@ -266,7 +270,9 @@ void logic_out##bwl(type value, unsigned long addr) \ void logic_ins##bwl(unsigned long addr, void *buffer, \ unsigned int count) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ reads##bwl(PCI_IOBASE + addr, buffer, count); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \ @@ -283,7 +289,9 @@ void logic_ins##bwl(unsigned long addr, void *buffer, \ void logic_outs##bwl(unsigned long addr, const void *buffer, \ unsigned int count) \ { \ - if (addr < MMIO_UPPER_LIMIT) { \ + if (addr < MMIO_LOWER_LIMIT) { \ + WARN_ON_ONCE(1); \ + } else if (addr < MMIO_UPPER_LIMIT) { \ writes##bwl(PCI_IOBASE + addr, buffer, count); \ } else if (addr >= MMIO_UPPER_LIMIT && addr < IO_SPACE_LIMIT) { \ struct logic_pio_hwaddr *entry = find_io_range(addr); \