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: 12023279 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=-16.8 required=3.0 tests=BAYES_00, 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 EF75BC43603 for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CBB8F239FE for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbhAOREh (ORCPT ); Fri, 15 Jan 2021 12:04:37 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11024 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725910AbhAOREh (ORCPT ); Fri, 15 Jan 2021 12:04:37 -0500 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: , , , , , , , , CC: , , , , , , John Garry 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 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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: 12023273 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=-16.8 required=3.0 tests=BAYES_00, 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 37052C4332E for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 13A9D23136 for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728095AbhAOREq (ORCPT ); Fri, 15 Jan 2021 12:04:46 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11546 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727808AbhAOREp (ORCPT ); Fri, 15 Jan 2021 12:04:45 -0500 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: , , , , , , , , CC: , , , , , , John Garry 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 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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: 12023271 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=-16.8 required=3.0 tests=BAYES_00, 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 CB54BC433E9 for ; Fri, 15 Jan 2021 17:05:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF3F12313E for ; Fri, 15 Jan 2021 17:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728540AbhAOREu (ORCPT ); Fri, 15 Jan 2021 12:04:50 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10664 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727973AbhAOREu (ORCPT ); Fri, 15 Jan 2021 12:04:50 -0500 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: , , , , , , , , CC: , , , , , , John Garry 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 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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: 12023275 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=-16.8 required=3.0 tests=BAYES_00, 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 707BFC43333 for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4857423136 for ; Fri, 15 Jan 2021 17:05:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727856AbhAOREl (ORCPT ); Fri, 15 Jan 2021 12:04:41 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10665 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725923AbhAOREk (ORCPT ); Fri, 15 Jan 2021 12:04:40 -0500 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: , , , , , , , , CC: , , , , , , John Garry 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 Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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); \