From patchwork Mon Aug 1 14:40:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933821 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D822C19F2A for ; Mon, 1 Aug 2022 14:40:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A371C6B0072; Mon, 1 Aug 2022 10:40:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9E6AE6B0073; Mon, 1 Aug 2022 10:40:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 888E06B0074; Mon, 1 Aug 2022 10:40:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7B3EB6B0072 for ; Mon, 1 Aug 2022 10:40:46 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 52EE1A056E for ; Mon, 1 Aug 2022 14:40:46 +0000 (UTC) X-FDA: 79751285292.11.D0710D0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 390FB1400F6 for ; Mon, 1 Aug 2022 14:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364843; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yqh7FeHFMtI+kW+10TKPDeJZiXYb/xwqaqaRSxDfiUM=; b=SMZjKf3Axp8tnLCKx2e+R89Q2xaS/6656vW9Ho7bRtgAiBUTryanxj6E5kNWuRATIgp8rf MDrTsG5VXiGh9SmEROBFDsXfCcA3brhseM87hKL4TBCe63t3IbD/3LoV1TQDRrbCyWYI4y q1rB3OeAHmO/MhSjz8NkUARCDAnBRds= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-460-j3vyREzDPkeg7ERZPn0gvA-1; Mon, 01 Aug 2022 10:40:42 -0400 X-MC-Unique: j3vyREzDPkeg7ERZPn0gvA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 40404382ECC6; Mon, 1 Aug 2022 14:40:42 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6C6C141510F; Mon, 1 Aug 2022 14:40:37 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed Date: Mon, 1 Aug 2022 22:40:19 +0800 Message-Id: <20220801144029.57829-2-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SMZjKf3A; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364844; a=rsa-sha256; cv=none; b=S6y6seeJG8oKwwTDkzvFP3N4D9bl0wVSKrJyruWaM1d4TDrNCTS8j5p8Jg6IoCtJ6asiIe RNGu5x0aIYRdN7qOA+sxqFR2EYjkh7ZQUW2aipYk902T4t1OxzVFHgmj2+ex8JMck58Dq2 XZAE29abxdttcuoy/z9HUO9P+FC2Jps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364844; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=yqh7FeHFMtI+kW+10TKPDeJZiXYb/xwqaqaRSxDfiUM=; b=8DJnxXvNltTTLU6O7gq99cWatJwVGoqhOrddehN0/Psl0TdnaErpuGRtGFmcvjCVgwKRBd iS3SfTyUATRL6P0+kujaauY1nv1v19w441CT89a3s99iFtruQykUGOAdGozPzqdz/mZiR0 sELwyq+E/RsIYIjARWZMOEZKU9ECJ5I= X-Stat-Signature: f5fcjixbowgs4x8um6jtcjjiwmp36nia X-Rspamd-Queue-Id: 390FB1400F6 Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SMZjKf3A; spf=pass (imf26.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1659364844-836533 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In some architectures, there are arch specifici io address mapping handling when calling ioremap() or ioremap_prot(), e.g, arc, ia64, openrisc, s390, sh. In oder to convert them to take GENERIC_IOREMAP method, we need change the return value of ioremap_allowed() and iounmap_allowed() as below. === ioremap_allowed() return a bool, - IS_ERR means return an error - NULL means continue to remap - a non-NULL, non-IS_ERR pointer is returned directly iounmap_allowed() return a bool, - 0 means continue to vunmap - error code means skip vunmap and return directly This is taken from Kefeng's below old patch. Christoph suggested the return value because he foresaw the doablity of converting to take GENERIC_IOREMAP on more architectures. - [PATCH v3 4/6] mm: ioremap: Add arch_ioremap/iounmap() - https://lore.kernel.org/all/20220519082552.117736-5-wangkefeng.wang@huawei.com/T/#u This is preparation for later patch, no functionality change. Signed-off-by: Baoquan He --- arch/arm64/include/asm/io.h | 2 +- arch/arm64/mm/ioremap.c | 9 +++++---- include/asm-generic/io.h | 17 +++++++++-------- mm/ioremap.c | 10 +++++++--- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 87dd42d74afe..9c56a077b687 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -164,7 +164,7 @@ extern void __memset_io(volatile void __iomem *, int, size_t); * I/O memory mapping functions. */ -bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot); +void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot); #define ioremap_allowed ioremap_allowed #define _PAGE_IOREMAP PROT_DEVICE_nGnRE diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index c5af103d4ad4..49467c781283 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,19 +3,20 @@ #include #include -bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) +void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) { unsigned long last_addr = phys_addr + size - 1; + int ret = -EINVAL; /* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK) - return false; + return IOMEM_ERR_PTR(ret); /* Don't allow RAM to be mapped. */ if (WARN_ON(pfn_is_map_memory(__phys_to_pfn(phys_addr)))) - return false; + return IOMEM_ERR_PTR(ret); - return true; + return NULL; } /* diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 72974cb81343..d72eb310fb3c 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr) /* * Arch code can implement the following two hooks when using GENERIC_IOREMAP * ioremap_allowed() return a bool, - * - true means continue to remap - * - false means skip remap and return directly + * - IS_ERR means return an error + * - NULL means continue to remap + * - a non-NULL, non-IS_ERR pointer is returned directly * iounmap_allowed() return a bool, - * - true means continue to vunmap - * - false means skip vunmap and return directly + * - 0 means continue to vunmap + * - error code means skip vunmap and return directly */ #ifndef ioremap_allowed #define ioremap_allowed ioremap_allowed -static inline bool ioremap_allowed(phys_addr_t phys_addr, size_t size, +static inline void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) { - return true; + return NULL; } #endif #ifndef iounmap_allowed #define iounmap_allowed iounmap_allowed -static inline bool iounmap_allowed(void *addr) +static inline int iounmap_allowed(void *addr) { - return true; + return 0; } #endif diff --git a/mm/ioremap.c b/mm/ioremap.c index 8652426282cc..b16ee9debea2 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -17,6 +17,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long offset, vaddr; phys_addr_t last_addr; struct vm_struct *area; + void __iomem *base; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size = PAGE_ALIGN(size + offset); - if (!ioremap_allowed(phys_addr, size, prot)) + base = ioremap_allowed(phys_addr, size, prot); + if (IS_ERR(base)) return NULL; + else if (base) + return base; area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); @@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot); void iounmap(volatile void __iomem *addr) { - void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); + void __iomem *vaddr = (void __iomem *)((unsigned long)addr & PAGE_MASK); - if (!iounmap_allowed(vaddr)) + if (iounmap_allowed(vaddr)) return; if (is_vmalloc_addr(vaddr)) From patchwork Mon Aug 1 14:40:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933822 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19EB8C19F2A for ; Mon, 1 Aug 2022 14:40:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A5EB66B0074; Mon, 1 Aug 2022 10:40:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A12E86B0075; Mon, 1 Aug 2022 10:40:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8124B8E0001; Mon, 1 Aug 2022 10:40:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 71B566B0074 for ; Mon, 1 Aug 2022 10:40:51 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4FF3D405BF for ; Mon, 1 Aug 2022 14:40:51 +0000 (UTC) X-FDA: 79751285502.11.CBA8336 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf16.hostedemail.com (Postfix) with ESMTP id D3C051800F8 for ; Mon, 1 Aug 2022 14:40:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364850; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uxopdcFQVMy5FY+0KKOo/rz2PC4Nm+RMZNyohtkWr+0=; b=IL//n9NmRS9v15e1pkuox96ULDTfv2BkSUK/flZJ9XzxKc6mAbFmgvANBCD/B7biAyMVum 8uYV2CrOP0AiXjnYa339oBE5efWM3mk8TrZQjulrwfHQ0ljzZoCSaTK7FqIZLOzMNKLIsl 8hC/LsapVndPqGumfRFqu8dm0aOjvZs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-381-LeGhaKzCMLSYNGV72SviRQ-1; Mon, 01 Aug 2022 10:40:47 -0400 X-MC-Unique: LeGhaKzCMLSYNGV72SviRQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8C2C618E6C4B; Mon, 1 Aug 2022 14:40:46 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED2B51415116; Mon, 1 Aug 2022 14:40:42 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH 02/11] mm: ioremap: fixup the physical address Date: Mon, 1 Aug 2022 22:40:20 +0800 Message-Id: <20220801144029.57829-3-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364851; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uxopdcFQVMy5FY+0KKOo/rz2PC4Nm+RMZNyohtkWr+0=; b=1g3+lmR8z+hk+eqa3VOHHQQYnNG9PZNnEzHRf17Tt1H0lAr0WevaqAlrZ+JRAY/ZOSqpm0 yYROOk6j05aCy5EKZcOEITUDSPQ1SCfS9ZhlrLGCqqt378usjqeew7vEx1fQBXOOoyyoiZ ikhp9SpHHkIpSvZr+5CvkMfaIruf7Kk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="IL//n9Nm"; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364851; a=rsa-sha256; cv=none; b=XWoBAtHhbmAB2YTRmj7KdBbOsKyGUt5ES8X/p4alL74zhWEZl1T5hw1aTDXrxZRnw6xgc3 81qkceG+Y0b7FzGGd9WJYfFmXZWCCdfA5VOx3uzdk7bW0Y0dmhuKc23HzvsW52a55CVjQd PPJpPc/iMxw/P5sZUKH8QUeuHAdADoo= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="IL//n9Nm"; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: D3C051800F8 X-Stat-Signature: th3dwn1wry533jp98rt6883w78fjk114 X-HE-Tag: 1659364850-435958 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In some architectures, the io address will be fixed up before doing mapping, e.g, parisc, mips. In oder to convert them to take GENERIC_IOREMAP method, we need wrap the address fixing up code into ioremap_allowed() and pass the new address out for ioremap_prot() handling. This is a preparation patch, no functionality change. Signed-off-by: Baoquan He --- arch/arm64/include/asm/io.h | 3 ++- arch/arm64/mm/ioremap.c | 10 ++++++++-- include/asm-generic/io.h | 6 +++--- mm/ioremap.c | 19 ++++++++++--------- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h index 9c56a077b687..7f0c5f60d946 100644 --- a/arch/arm64/include/asm/io.h +++ b/arch/arm64/include/asm/io.h @@ -164,7 +164,8 @@ extern void __memset_io(volatile void __iomem *, int, size_t); * I/O memory mapping functions. */ -void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot); +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); #define ioremap_allowed ioremap_allowed #define _PAGE_IOREMAP PROT_DEVICE_nGnRE diff --git a/arch/arm64/mm/ioremap.c b/arch/arm64/mm/ioremap.c index 49467c781283..b9febcf0f5f4 100644 --- a/arch/arm64/mm/ioremap.c +++ b/arch/arm64/mm/ioremap.c @@ -3,11 +3,17 @@ #include #include -void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long last_addr = phys_addr + size - 1; + unsigned long last_addr, offset, phys_addr = *paddr; int ret = -EINVAL; + offset = phys_addr & (~PAGE_MASK); + phys_addr -= offset; + size = PAGE_ALIGN(size + offset); + last_addr = phys_addr + size - 1; + /* Don't allow outside PHYS_MASK */ if (last_addr & ~PHYS_MASK) return IOMEM_ERR_PTR(ret); diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index d72eb310fb3c..0b5cd3cef99d 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -976,8 +976,8 @@ static inline void iounmap(volatile void __iomem *addr) */ #ifndef ioremap_allowed #define ioremap_allowed ioremap_allowed -static inline void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, - unsigned long prot) +static inline void __iomem *ioremap_allowed(phys_addr_t *paddr, size_t size, + unsigned long *prot_val) { return NULL; } @@ -991,7 +991,7 @@ static inline int iounmap_allowed(void *addr) } #endif -void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, +void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); diff --git a/mm/ioremap.c b/mm/ioremap.c index b16ee9debea2..01439882112e 100644 --- a/mm/ioremap.c +++ b/mm/ioremap.c @@ -11,13 +11,20 @@ #include #include -void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, +void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, unsigned long prot) { unsigned long offset, vaddr; - phys_addr_t last_addr; + phys_addr_t last_addr, phys_addr = paddr; struct vm_struct *area; void __iomem *base; + unsigned long prot_val = prot; + + base = ioremap_allowed(&phys_addr, size, &prot_val); + if (IS_ERR(base)) + return NULL; + else if (base) + return base; /* Disallow wrap-around or zero size */ last_addr = phys_addr + size - 1; @@ -29,12 +36,6 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, phys_addr -= offset; size = PAGE_ALIGN(size + offset); - base = ioremap_allowed(phys_addr, size, prot); - if (IS_ERR(base)) - return NULL; - else if (base) - return base; - area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); if (!area) @@ -43,7 +44,7 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, area->phys_addr = phys_addr; if (ioremap_page_range(vaddr, vaddr + size, phys_addr, - __pgprot(prot))) { + __pgprot(prot_val))) { free_vm_area(area); return NULL; } From patchwork Mon Aug 1 14:40:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933826 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B0EEC00144 for ; Mon, 1 Aug 2022 14:41:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C59336B0078; Mon, 1 Aug 2022 10:41:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C08236B007B; Mon, 1 Aug 2022 10:41:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD12D8E0001; Mon, 1 Aug 2022 10:41:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id A015E6B0078 for ; Mon, 1 Aug 2022 10:41:13 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 82B29808B1 for ; Mon, 1 Aug 2022 14:41:10 +0000 (UTC) X-FDA: 79751286300.24.3143C08 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf01.hostedemail.com (Postfix) with ESMTP id C37BC40109 for ; Mon, 1 Aug 2022 14:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CKrUoRnDZ3N/f9AupvreAkywYQigdqg4xJd8FTCpS7Q=; b=dzuElEUbn/xc4Ofz7QEV36JfAenKndM2RHzHOUR68a5BfE/NeqXd1E4KXpkhyqV9raXOVW xm+K+09gMiRoanNB2SqhBq+PmjpN/Q39uHnxOwhsqpupXoZBpx+UT+65QpzZl8JbLEY/vU Ko//ZEyhqSYykLliG+gwvZ/+WBaR9p0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-639-L8yZD93EODmWXar_uTWN_A-1; Mon, 01 Aug 2022 10:40:58 -0400 X-MC-Unique: L8yZD93EODmWXar_uTWN_A-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4845882404E; Mon, 1 Aug 2022 14:40:51 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 411F6141510F; Mon, 1 Aug 2022 14:40:46 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He Subject: [PATCH 03/11] mm: ioremap: allow ARCH to have its own ioremap definition Date: Mon, 1 Aug 2022 22:40:21 +0800 Message-Id: <20220801144029.57829-4-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dzuElEUb; spf=pass (imf01.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364870; a=rsa-sha256; cv=none; b=uY7q3tCOdQLlTzdI80razE8cptZmVaO6xKkmurmEPR9W00pLmeN7dMdpHPmxHgZqusaaeF QYVkINs6n4nw+iDdRU9yTStxtsOi44CwM0wBVMTA7dRFrjV4bUHEq97IK1bcLMGpH23Q1e fu5Y+ten/beAqIHTmiMJLejMIa64WAs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364870; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CKrUoRnDZ3N/f9AupvreAkywYQigdqg4xJd8FTCpS7Q=; b=CnBhUiZwO/R+cr8X+YZgMh16V6yX/zqVQWK4Amwwmr+gj+6wDdMj36y4YEF0cr4lzpRmaN hR1qHq+yEPYJvGn2mzHDVO0Vdd/BdNvfFJGTRryiPJrEoSE/yEfaPm0dct0eADGVsUYVkj f/zEax+xB6cao/YMCOpjUuRD1N9yJu8= X-Stat-Signature: 4pcjwrtm9w5199x51g3te7ndpbwsnjgq X-Rspamd-Queue-Id: C37BC40109 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dzuElEUb; spf=pass (imf01.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam12 X-HE-Tag: 1659364867-445940 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Architectures like xtensa, arc, can be converted to GENERIC_IOREMAP, to take standard ioremap_prot() and ioremap_xxx() way. But they have ARCH specific handling for ioremap() method, then standard ioremap() method. In oder to convert them to take GENERIC_IOREMAP method, allow ARCH to have its own ioremap definition. This is a preparation patch, no functionality change. Signed-off-by: Baoquan He --- include/asm-generic/io.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h index 0b5cd3cef99d..444761c3a44b 100644 --- a/include/asm-generic/io.h +++ b/include/asm-generic/io.h @@ -995,11 +995,14 @@ void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, unsigned long prot); void iounmap(volatile void __iomem *addr); +#ifndef ioremap +#define ioremap ioremap static inline void __iomem *ioremap(phys_addr_t addr, size_t size) { /* _PAGE_IOREMAP needs to be supplied by the architecture */ return ioremap_prot(addr, size, _PAGE_IOREMAP); } +#endif #endif /* !CONFIG_MMU || CONFIG_GENERIC_IOREMAP */ #ifndef ioremap_wc From patchwork Mon Aug 1 14:40:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933823 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB0B2C00144 for ; Mon, 1 Aug 2022 14:41:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B3906B0075; Mon, 1 Aug 2022 10:41:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 662ED6B0078; Mon, 1 Aug 2022 10:41:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52B6C6B007B; Mon, 1 Aug 2022 10:41:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 43DC66B0075 for ; Mon, 1 Aug 2022 10:41:09 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 24ADA1C5D20 for ; Mon, 1 Aug 2022 14:41:09 +0000 (UTC) X-FDA: 79751286258.18.8853C6D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id B6B6F180009 for ; Mon, 1 Aug 2022 14:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4t1/0IxJa6CSuWSxZNOTLOA5QGMU9OZhYQRkkYe7p6I=; b=EvoYBXbfKQ43qQhMamAf479uJfTR3VI/d+x7vpf6d75Zps1rImoD1R3Z5YTKE5EtSvmH83 R1uGV/l2tqnTAw78q/cI3lF3dP+77AkV/R9X7natcHZcdJQM+RaOqlSuJBPaxUlAAPqvCs aT9GCf98Vm/7cQGgfN1OyvoxUlTOXwU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-526-0zvBQuswOaeEa8TYB4iQBQ-1; Mon, 01 Aug 2022 10:41:03 -0400 X-MC-Unique: 0zvBQuswOaeEa8TYB4iQBQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B1CD33C2F761; Mon, 1 Aug 2022 14:41:02 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 13F21141510F; Mon, 1 Aug 2022 14:40:51 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Vineet Gupta , linux-snps-arc@lists.infradead.org Subject: [PATCH 04/11] arc: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:22 +0800 Message-Id: <20220801144029.57829-5-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EvoYBXbf; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364867; a=rsa-sha256; cv=none; b=Gu41ZsUm06wPh27+MHeIgZ0UEDq2LjXt4ERgsqLsc/3DkJIHQCxYjoTx+T1pAjF9rykwwY ILOplgON/yhBy8c1cj5Y7LzF9RC6FQFLoJthKPH19ynIzkf8UUjUt3hFsg0/fngAWv6+iF nTHN8zdJ0yGxVzt48o09dEK4Enki0q8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364867; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4t1/0IxJa6CSuWSxZNOTLOA5QGMU9OZhYQRkkYe7p6I=; b=0gQ+mHvQQVEBPYPBxC/qKOLbLjTMPGogaHoVk32NWzeXlfRYTAZK8UHNtNMyDL598hSmwv sJUIrIUj+1xihsoaSWHWXER2c9ZIrVsJYoFx3L936nUzU9dUoIKb79udQ0RTrSN6iHXJ5p ePX2YXqIlR6rStd72rESi5IBv52Nggo= Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EvoYBXbf; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: am7jo3sg5ykh68kqu11x4odc6z59wc9w X-Rspamd-Queue-Id: B6B6F180009 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1659364867-220301 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hooks ioremap_allowed() and iounmap_allowed() for arc's special operation when ioremap_prot() and iounmap(). Meanwhile define and implement arc's own ioremap() because arc has some special handling in ioremap() than standard ioremap(). Signed-off-by: Baoquan He Cc: Vineet Gupta Cc: linux-snps-arc@lists.infradead.org --- arch/arc/Kconfig | 1 + arch/arc/include/asm/io.h | 19 +++++++++---- arch/arc/mm/ioremap.c | 60 ++++++--------------------------------- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig index 9e3653253ef2..a08d2abfaf61 100644 --- a/arch/arc/Kconfig +++ b/arch/arc/Kconfig @@ -26,6 +26,7 @@ config ARC select GENERIC_PENDING_IRQ if SMP select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD + select GENERIC_IOREMAP select HAVE_ARCH_KGDB select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE if ARC_MMU_V4 diff --git a/arch/arc/include/asm/io.h b/arch/arc/include/asm/io.h index 8f777d6441a5..10d7ed9dfa61 100644 --- a/arch/arc/include/asm/io.h +++ b/arch/arc/include/asm/io.h @@ -20,9 +20,20 @@ #define __iowmb() do { } while (0) #endif -extern void __iomem *ioremap(phys_addr_t paddr, unsigned long size); -extern void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, - unsigned long flags); +/* + * I/O memory mapping functions. + */ + +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed(void __iomem *addr); +#define iounmap_allowed iounmap_allowed + +void __iomem *ioremap(phys_addr_t paddr, unsigned long size); +#define ioremap ioremap + static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { return (void __iomem *)port; @@ -32,8 +43,6 @@ static inline void ioport_unmap(void __iomem *addr) { } -extern void iounmap(const void __iomem *addr); - /* * io{read,write}{16,32}be() macros */ diff --git a/arch/arc/mm/ioremap.c b/arch/arc/mm/ioremap.c index 0ee75aca6e10..7be73e3645da 100644 --- a/arch/arc/mm/ioremap.c +++ b/arch/arc/mm/ioremap.c @@ -25,13 +25,6 @@ static inline bool arc_uncached_addr_space(phys_addr_t paddr) void __iomem *ioremap(phys_addr_t paddr, unsigned long size) { - phys_addr_t end; - - /* Don't allow wraparound or zero size */ - end = paddr + size - 1; - if (!size || (end < paddr)) - return NULL; - /* * If the region is h/w uncached, MMU mapping can be elided as optim * The cast to u32 is fine as this region can only be inside 4GB @@ -44,62 +37,27 @@ void __iomem *ioremap(phys_addr_t paddr, unsigned long size) } EXPORT_SYMBOL(ioremap); -/* - * ioremap with access flags - * Cache semantics wise it is same as ioremap - "forced" uncached. - * However unlike vanilla ioremap which bypasses ARC MMU for addresses in - * ARC hardware uncached region, this one still goes thru the MMU as caller - * might need finer access control (R/W/X) - */ -void __iomem *ioremap_prot(phys_addr_t paddr, unsigned long size, - unsigned long flags) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned int off; - unsigned long vaddr; - struct vm_struct *area; - phys_addr_t end; - pgprot_t prot = __pgprot(flags); - - /* Don't allow wraparound, zero size */ - end = paddr + size - 1; - if ((!size) || (end < paddr)) - return NULL; + int ret = -EINVAL; /* An early platform driver might end up here */ if (!slab_is_available()) - return NULL; + return IOMEM_ERR_PTR(ret); /* force uncached */ - prot = pgprot_noncached(prot); + *prot_val = pgprot_val(pgprot_noncached(__pgprot(*prot_val))); - /* Mappings have to be page-aligned */ - off = paddr & ~PAGE_MASK; - paddr &= PAGE_MASK_PHYS; - size = PAGE_ALIGN(end + 1) - paddr; + return NULL; - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - area->phys_addr = paddr; - vaddr = (unsigned long)area->addr; - if (ioremap_page_range(vaddr, vaddr + size, paddr, prot)) { - vunmap((void __force *)vaddr); - return NULL; - } - return (void __iomem *)(off + (char __iomem *)vaddr); } -EXPORT_SYMBOL(ioremap_prot); - -void iounmap(const void __iomem *addr) +int iounmap_allowed(void __iomem *addr) { /* weird double cast to handle phys_addr_t > 32 bits */ if (arc_uncached_addr_space((phys_addr_t)(u32)addr)) - return; + return -EINVAL; - vfree((void *)(PAGE_MASK & (unsigned long __force)addr)); + return 0; } -EXPORT_SYMBOL(iounmap); From patchwork Mon Aug 1 14:40:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933824 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50A85C19F2B for ; Mon, 1 Aug 2022 14:41:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CF69E6B007B; Mon, 1 Aug 2022 10:41:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CA68A6B007D; Mon, 1 Aug 2022 10:41:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AD1648E0001; Mon, 1 Aug 2022 10:41:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 99A0B6B007B for ; Mon, 1 Aug 2022 10:41:14 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 74FEF16065B for ; Mon, 1 Aug 2022 14:41:14 +0000 (UTC) X-FDA: 79751286468.03.2E7766D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 04502800EE for ; Mon, 1 Aug 2022 14:41:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CaolBDp29uFoy9EJOCmc+prflA1CqUFRD61xKQq994g=; b=QPXn761MXakxin8zN0MBptkYKVnZQ2HhztbIwcgyLAUVRzz6WTJcjn7Uol5tb0DElmMUpF HQW8LhC8y5opaHScll4yML/jS/3j62k7K4l/89zWhImtk2dRNqBrrGcXhaJaWxtBafVi4b x2n2HGlc2rklINsxsSSYH+b8k65AnGI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-449-cE1DPRyqM1KTgUoCRiT8Iw-1; Mon, 01 Aug 2022 10:41:07 -0400 X-MC-Unique: cE1DPRyqM1KTgUoCRiT8Iw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D51A22932482; Mon, 1 Aug 2022 14:41:06 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 56727141510F; Mon, 1 Aug 2022 14:41:03 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Brian Cain , linux-hexagon@vger.kernel.org Subject: [PATCH 05/11] hexagon: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:23 +0800 Message-Id: <20220801144029.57829-6-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364874; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=CaolBDp29uFoy9EJOCmc+prflA1CqUFRD61xKQq994g=; b=DLCAbS6JVafcY6ndKy/sEJJwTTIv7kBoaH0HlFsrsD0DlqLnBiwN0/UbhbD5c132iSZGgp iF5S8pI/6zqxIkp35oveRyTeS632CtNBULSQ4WhPQiSNaxz62gK1FTHY9lIcz2IAg1UOIq zKASgqqt7V2jO+pESzJnVxWe15tLcwg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QPXn761M; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364874; a=rsa-sha256; cv=none; b=FmP6DNGoqk3GAdEpCDj8dQGFiwdggQuCtqliBFXScwOfLSxK4BZu7MMXcORerlTT/fAOTS IZh/BqllPrlAmYp6yU7ydLSu/8IPHSZX0GyLCemG4z+K8lMjXtsGpvAhR+RhJNOnP3rWpY moVIIr/nd/JR9bgPjMPZOqNyHbxx3fQ= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=QPXn761M; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 04502800EE X-Stat-Signature: bi459xjd5dy59r8akgcpn9wgcedksoug X-HE-Tag: 1659364873-825468 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With it, the old ioremap() and iounmap() can be perfectly removed since they are duplicated with the standard functions. Signed-off-by: Baoquan He Cc: Brian Cain Cc: linux-hexagon@vger.kernel.org --- arch/hexagon/Kconfig | 1 + arch/hexagon/include/asm/io.h | 9 +++++-- arch/hexagon/mm/ioremap.c | 44 ----------------------------------- 3 files changed, 8 insertions(+), 46 deletions(-) delete mode 100644 arch/hexagon/mm/ioremap.c diff --git a/arch/hexagon/Kconfig b/arch/hexagon/Kconfig index 54eadf265178..17afffde1a7f 100644 --- a/arch/hexagon/Kconfig +++ b/arch/hexagon/Kconfig @@ -25,6 +25,7 @@ config HEXAGON select NEED_SG_DMA_LENGTH select NO_IOPORT_MAP select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select STACKTRACE_SUPPORT select GENERIC_CLOCKEVENTS_BROADCAST diff --git a/arch/hexagon/include/asm/io.h b/arch/hexagon/include/asm/io.h index c33241425a5c..e2d3091ec9d6 100644 --- a/arch/hexagon/include/asm/io.h +++ b/arch/hexagon/include/asm/io.h @@ -170,8 +170,13 @@ static inline void writel(u32 data, volatile void __iomem *addr) #define writew_relaxed __raw_writew #define writel_relaxed __raw_writel -void __iomem *ioremap(unsigned long phys_addr, unsigned long size); -#define ioremap_uc(X, Y) ioremap((X), (Y)) +/* + * I/O memory mapping functions. + */ +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_READ | _PAGE_WRITE | \ + (__HEXAGON_C_DEV << 6)) + +#define ioremap_uc(addr, size) ioremap((addr), (size)) #define __raw_writel writel diff --git a/arch/hexagon/mm/ioremap.c b/arch/hexagon/mm/ioremap.c deleted file mode 100644 index 255c5b1ee1a7..000000000000 --- a/arch/hexagon/mm/ioremap.c +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only -/* - * I/O remap functions for Hexagon - * - * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. - */ - -#include -#include -#include - -void __iomem *ioremap(unsigned long phys_addr, unsigned long size) -{ - unsigned long last_addr, addr; - unsigned long offset = phys_addr & ~PAGE_MASK; - struct vm_struct *area; - - pgprot_t prot = __pgprot(_PAGE_PRESENT|_PAGE_READ|_PAGE_WRITE - |(__HEXAGON_C_DEV << 6)); - - last_addr = phys_addr + size - 1; - - /* Wrapping not allowed */ - if (!size || (last_addr < phys_addr)) - return NULL; - - /* Rounds up to next page size, including whole-page offset */ - size = PAGE_ALIGN(offset + size); - - area = get_vm_area(size, VM_IOREMAP); - addr = (unsigned long)area->addr; - - if (ioremap_page_range(addr, addr+size, phys_addr, prot)) { - vunmap((void *)addr); - return NULL; - } - - return (void __iomem *) (offset + addr); -} - -void iounmap(const volatile void __iomem *addr) -{ - vunmap((void *) ((unsigned long) addr & PAGE_MASK)); -} From patchwork Mon Aug 1 14:40:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933825 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D443BC19F2A for ; Mon, 1 Aug 2022 14:41:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B7A26B007D; Mon, 1 Aug 2022 10:41:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 63C3A6B007E; Mon, 1 Aug 2022 10:41:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6C28E0001; Mon, 1 Aug 2022 10:41:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3DFC96B007D for ; Mon, 1 Aug 2022 10:41:16 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 12034120453 for ; Mon, 1 Aug 2022 14:41:16 +0000 (UTC) X-FDA: 79751286552.09.A4A08F9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 525C72000D for ; Mon, 1 Aug 2022 14:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364874; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DZmD4gmIo8KLSmraeqPFjgSNee5vsKDTmBijYPzkavM=; b=bUoKZd3t4ZR19O562iaEj0uUmEpbppOyR3z7Y5U0MhILI3F4bOQNTsJzg6s3fQgqq5Wd1l S8IiQPJOVeFifD8Qrrw3UKSlV1sRDhwTpuMeknnUm/zQF5+oPrHxvka3CLik3z9VTKOzIc Xpp7HlmFnwchVOUFDcDRLqLkxxf8eqo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-Bc1CqywKPOqktrrGQSxCeg-1; Mon, 01 Aug 2022 10:41:11 -0400 X-MC-Unique: Bc1CqywKPOqktrrGQSxCeg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5505A85A587; Mon, 1 Aug 2022 14:41:11 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8538D1415116; Mon, 1 Aug 2022 14:41:07 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , linux-ia64@vger.kernel.org Subject: [PATCH 06/11] ia64: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:24 +0800 Message-Id: <20220801144029.57829-7-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bUoKZd3t; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364875; a=rsa-sha256; cv=none; b=aFlSdjO6Fu8Pf0F7sZptAQ+kIoGU8Q8HYlBUNLeQKiEhDsSUUOo4c6RFvV8zaPPHqh9NaX esfeLrDg1wuju5DSVyGLTqt8S7w4GEj4VOjBo3kIqgivzZGMsABf1cPwtZzVnbz5xmMe/i BNsOzS4Jhloq9Duofs+UuFJ0UrG3J40= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364875; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DZmD4gmIo8KLSmraeqPFjgSNee5vsKDTmBijYPzkavM=; b=CUGw3ySOV0O78FRGKO7xDJoWUm2l9KEj+7ACbMHbPyjYIQx0G0LBPUC9lOf+jk+H1KPB4m 2kgOftYGJ3GNNwh2C6CnMOsDJQo54x3SkunjwbQ5XDcyGu6PlvZ4X/OcWQV5e14Bls1PTL WTLueDKiq7SEaDfTdY3A2XGramSG8m4= X-Stat-Signature: bh6tz9bb15a6xikn6dncxnodh4pyah6g X-Rspamd-Queue-Id: 525C72000D X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=bUoKZd3t; spf=pass (imf13.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1659364875-85935 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hooks ioremap_allowed() and iounmap_allowed() for ia64's special operation when ioremap() and iounmap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP. The old ioremap_uc() is kept and add its macro definittion. Signed-off-by: Baoquan He Cc: linux-ia64@vger.kernel.org --- arch/ia64/Kconfig | 1 + arch/ia64/include/asm/io.h | 26 ++++++++++++-------- arch/ia64/mm/ioremap.c | 50 +++++++++----------------------------- 3 files changed, 28 insertions(+), 49 deletions(-) diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig index cb93769a9f2a..075ffe27dee5 100644 --- a/arch/ia64/Kconfig +++ b/arch/ia64/Kconfig @@ -46,6 +46,7 @@ config IA64 select GENERIC_IRQ_LEGACY select ARCH_HAVE_NMI_SAFE_CMPXCHG select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_SMP_IDLE_THREAD select ARCH_TASK_STRUCT_ON_STACK select ARCH_TASK_STRUCT_ALLOCATOR diff --git a/arch/ia64/include/asm/io.h b/arch/ia64/include/asm/io.h index 6d93b923b379..a972dc284bbb 100644 --- a/arch/ia64/include/asm/io.h +++ b/arch/ia64/include/asm/io.h @@ -255,17 +255,23 @@ static inline void outsl(unsigned long port, const void *src, # ifdef __KERNEL__ -extern void __iomem * ioremap(unsigned long offset, unsigned long size); -extern void __iomem * ioremap_uc(unsigned long offset, unsigned long size); -extern void iounmap (volatile void __iomem *addr); -static inline void __iomem * ioremap_cache (unsigned long phys_addr, unsigned long size) -{ - return ioremap(phys_addr, size); -} -#define ioremap ioremap -#define ioremap_cache ioremap_cache +/* + * I/O memory mapping functions. + */ +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) + +void __iomem *ioremap_uc(unsigned long offset, unsigned long size); #define ioremap_uc ioremap_uc -#define iounmap iounmap /* * String version of IO memory access ops: diff --git a/arch/ia64/mm/ioremap.c b/arch/ia64/mm/ioremap.c index 55fd3eb753ff..75c995e9442f 100644 --- a/arch/ia64/mm/ioremap.c +++ b/arch/ia64/mm/ioremap.c @@ -30,15 +30,12 @@ early_ioremap (unsigned long phys_addr, unsigned long size) } void __iomem * -ioremap (unsigned long phys_addr, unsigned long size) +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - void __iomem *addr; - struct vm_struct *area; - unsigned long offset; - pgprot_t prot; - u64 attr; + phys_addr_t phys_addr = *paddr; unsigned long gran_base, gran_size; unsigned long page_base; + u64 attr; /* * For things in kern_memmap, we must use the same attribute @@ -69,35 +66,18 @@ ioremap (unsigned long phys_addr, unsigned long size) page_base = phys_addr & PAGE_MASK; size = PAGE_ALIGN(phys_addr + size) - page_base; if (efi_mem_attribute(page_base, size) & EFI_MEMORY_WB) { - prot = PAGE_KERNEL; - - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - area->phys_addr = phys_addr; - addr = (void __iomem *) area->addr; - if (ioremap_page_range((unsigned long) addr, - (unsigned long) addr + size, phys_addr, prot)) { - vunmap((void __force *) addr); - return NULL; - } - - return (void __iomem *) (offset + (char __iomem *)addr); + return NULL; } return __ioremap_uc(phys_addr); } -EXPORT_SYMBOL(ioremap); + +int iounmap_allowed(void __iomem *addr) +{ + if (REGION_NUMBER(addr) != RGN_GATE) + return -EINVAL; + return 0; +} void __iomem * ioremap_uc(unsigned long phys_addr, unsigned long size) @@ -113,11 +93,3 @@ void early_iounmap (volatile void __iomem *addr, unsigned long size) { } - -void -iounmap (volatile void __iomem *addr) -{ - if (REGION_NUMBER(addr) == RGN_GATE) - vunmap((void *) ((unsigned long) addr & PAGE_MASK)); -} -EXPORT_SYMBOL(iounmap); From patchwork Mon Aug 1 14:40:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933827 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A480FC00144 for ; Mon, 1 Aug 2022 14:41:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CD9F6B007E; Mon, 1 Aug 2022 10:41:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37D918E0001; Mon, 1 Aug 2022 10:41:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21EDC6B0081; Mon, 1 Aug 2022 10:41:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 109A46B007E for ; Mon, 1 Aug 2022 10:41:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D6074140316 for ; Mon, 1 Aug 2022 14:41:21 +0000 (UTC) X-FDA: 79751286762.10.16CA6EE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 5BE4E180031 for ; Mon, 1 Aug 2022 14:41:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364880; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lrcGo2VjlmbeUcV8YVny+PT0CCF9ywqcopB5qQcKwTQ=; b=ZRprI8SWyHCkTA2X2piJKYyFxhjM4ESbVsWzs3MhrQethx9FefO/v4a20mK4ofAzH7BYhr wCD91A0pNX2aTSfsAGIOLW/IsQs75LL2mpki3o5V2N85lMRFMgHkjq827jZ6FypZukgmAJ sDxK2/AEnyP/+ZLuAxHylyRoNLTeVDI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-562-n4sgo9WMP_y0ca4olRObJw-1; Mon, 01 Aug 2022 10:41:17 -0400 X-MC-Unique: n4sgo9WMP_y0ca4olRObJw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4EDAB18E6C5E; Mon, 1 Aug 2022 14:41:17 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24ED1141510F; Mon, 1 Aug 2022 14:41:11 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Jonas Bonn , Stefan Kristiansson , Stafford Horne , openrisc@lists.librecores.org Subject: [PATCH 07/11] openrisc: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:25 +0800 Message-Id: <20220801144029.57829-8-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364881; a=rsa-sha256; cv=none; b=W6LqVhxjGdwFygt+KUcKAM85JjRKBI5nUc59p1ed90PxdwXkz+wNqpPXNNTiAzSdsrfY/V KDHmsa25sZubYMXXMYlullIpIogwW2DpYTaKrhqdNel87FJ6c4Bv78AZjjQxU1o9ixy5h0 YeySOkc9XvQ9AvzoYD+JOzMn29aOLJs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZRprI8SW; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364881; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lrcGo2VjlmbeUcV8YVny+PT0CCF9ywqcopB5qQcKwTQ=; b=OiPIwPleJou9MdaWDBsMHVSbM7uu6QnnTotyIrvuH5/lR6s/SwMmVH4t2PlVjevWr5SX5O CESVy5I2S8sf8c7WN4s3mKbh06sfDThgMQhGMFTgrmRBRN1YhhpGlUMHWbUOv5SVAN0JmA PrMkwsqTvj0j0CO2eUcaMsDp3ZUiM3M= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZRprI8SW; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: mb1ztrtjsfjj7ij7itxrmcnb39tqkcbh X-Rspamd-Queue-Id: 5BE4E180031 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1659364881-627047 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hooks ioremap_allowed() and iounmap_allowed() for operisc's special operation when ioremap() and iounmap. Signed-off-by: Baoquan He Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: openrisc@lists.librecores.org --- arch/openrisc/Kconfig | 1 + arch/openrisc/include/asm/io.h | 16 ++++++++--- arch/openrisc/mm/ioremap.c | 49 +++++++++++----------------------- 3 files changed, 28 insertions(+), 38 deletions(-) diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index e814df4c483c..77505f2a2767 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -21,6 +21,7 @@ config OPENRISC select GENERIC_IRQ_PROBE select GENERIC_IRQ_SHOW select GENERIC_IOMAP + select GENERIC_IOREMAP select GENERIC_CPU_DEVICES select HAVE_UID16 select GENERIC_ATOMIC64 diff --git a/arch/openrisc/include/asm/io.h b/arch/openrisc/include/asm/io.h index c298061c70a7..8948df501464 100644 --- a/arch/openrisc/include/asm/io.h +++ b/arch/openrisc/include/asm/io.h @@ -15,6 +15,8 @@ #define __ASM_OPENRISC_IO_H #include +#include +#include /* * PCI: can we really do 0 here if we have no port IO? @@ -27,11 +29,17 @@ #define PIO_OFFSET 0 #define PIO_MASK 0 -#define ioremap ioremap -void __iomem *ioremap(phys_addr_t offset, unsigned long size); +/* + * I/O memory mapping functions. + */ +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed -#define iounmap iounmap -extern void iounmap(void __iomem *addr); +#define _PAGE_IOREMAP (pgprot_val(PAGE_KERNEL) | _PAGE_CI) #include diff --git a/arch/openrisc/mm/ioremap.c b/arch/openrisc/mm/ioremap.c index daae13a76743..d30b6cc65548 100644 --- a/arch/openrisc/mm/ioremap.c +++ b/arch/openrisc/mm/ioremap.c @@ -24,26 +24,18 @@ extern int mem_init_done; static unsigned int fixmaps_used __initdata; -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. Needed when the kernel wants to access high addresses - * directly. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { phys_addr_t p; unsigned long v; unsigned long offset, last_addr; - struct vm_struct *area = NULL; + int ret = -EINVAL; /* Don't allow wraparound or zero size */ last_addr = addr + size - 1; if (!size || last_addr < addr) - return NULL; + return IOMEM_ERR_PTR(ret); /* * Mappings have to be page-aligned @@ -52,32 +44,24 @@ void __iomem *__ref ioremap(phys_addr_t addr, unsigned long size) p = addr & PAGE_MASK; size = PAGE_ALIGN(last_addr + 1) - p; - if (likely(mem_init_done)) { - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - v = (unsigned long)area->addr; - } else { + if (unlikely(!mem_init_done)) { if ((fixmaps_used + (size >> PAGE_SHIFT)) > FIX_N_IOREMAPS) - return NULL; + return IOMEM_ERR_PTR(ret); v = fix_to_virt(FIX_IOREMAP_BEGIN + fixmaps_used); fixmaps_used += (size >> PAGE_SHIFT); - } - if (ioremap_page_range(v, v + size, p, - __pgprot(pgprot_val(PAGE_KERNEL) | _PAGE_CI))) { - if (likely(mem_init_done)) - vfree(area->addr); - else + if (ioremap_page_range(v, v + size, p, __pgprot(*prot_val))) { fixmaps_used -= (size >> PAGE_SHIFT); - return NULL; + return IOMEM_ERR_PTR(ret); + } + + return (void __iomem *)(offset + (char *)v); } - return (void __iomem *)(offset + (char *)v); + return NULL; } -EXPORT_SYMBOL(ioremap); -void iounmap(void __iomem *addr) +int iounmap_allowed(void __iomem *addr) { /* If the page is from the fixmap pool then we just clear out * the fixmap mapping. @@ -97,13 +81,10 @@ void iounmap(void __iomem *addr) * ii) invalid accesses to the freed areas aren't made */ flush_tlb_all(); - return; + return -EINVAL; } - - return vfree((void *)(PAGE_MASK & (unsigned long)addr)); + return 0; } -EXPORT_SYMBOL(iounmap); - /** * OK, this one's a bit tricky... ioremap can get called before memory is * initialized (early serial console does this) and will want to alloc a page From patchwork Mon Aug 1 14:40:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933828 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2F1FC00144 for ; Mon, 1 Aug 2022 14:41:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EC866B0080; Mon, 1 Aug 2022 10:41:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B9D6B0081; Mon, 1 Aug 2022 10:41:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 63C796B0082; Mon, 1 Aug 2022 10:41:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 54F706B0080 for ; Mon, 1 Aug 2022 10:41:27 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 30BE440195 for ; Mon, 1 Aug 2022 14:41:27 +0000 (UTC) X-FDA: 79751287014.24.C54E3DA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf16.hostedemail.com (Postfix) with ESMTP id BEF241800F8 for ; Mon, 1 Aug 2022 14:41:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7btrmOvCwxUbWnRbGW9HAB+h/F7WiYkudy0+tZC07Ew=; b=U7ZmsN8hSTutuuTFU5V7AmeuXkV35bn72Xsx3ku+VxAph+i+/S741ps8d0NjeZUobXHK64 Zf5F518y30gnqlRTCzWPBccdjbvnInnNJM2p05zUMLUnsSolfuCPSrWDeDUpXX3KI8zqkv iLGl4rkmAfQtxoMtyCzaat6OyOGXvC4= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-518-mR9E7DbFOuOXnfVfrRdWoA-1; Mon, 01 Aug 2022 10:41:23 -0400 X-MC-Unique: mR9E7DbFOuOXnfVfrRdWoA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B253780602A; Mon, 1 Aug 2022 14:41:22 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B528141510F; Mon, 1 Aug 2022 14:41:17 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , "James E.J. Bottomley" , Helge Deller , linux-parisc@vger.kernel.org Subject: [PATCH 08/11] parisc: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:26 +0800 Message-Id: <20220801144029.57829-9-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364886; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7btrmOvCwxUbWnRbGW9HAB+h/F7WiYkudy0+tZC07Ew=; b=oISxAKWXw2si8oO+or99TWTqm9j7Zh2+H3jim2my2echrVpNkBwaQJxNyIZbVIR5NLSfK4 qzHlU6tjIwyvQIBQK5KzvqRGVetsjJeni6oa2lZrzij3z/2wtKXFzuvfgUwupUqu3Q+tfC 3ClrpOQmGqQ1BUYGozgjnB6g+5nL/rU= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U7ZmsN8h; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364886; a=rsa-sha256; cv=none; b=daQZFoAoQj25Cz8A0l5QQrc/TpW0Nhm6Cs8PB+smcS6Bxt/DUQ4qqcL1UFMrkAQy+JHvGj ryImGuQrv8zavHnQ4gJ/Yk1seZS/FNtZSHyxIUIfY5CoGzPVOnVUsvyQJmC30gJyvw8xqq kqR4OE6NJOBA/lC1PpqoRh1BetnkxfE= X-Rspamd-Server: rspam02 X-Rspam-User: Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=U7ZmsN8h; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf16.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com X-Stat-Signature: u4rsm41ebuutb3gfshwtwfgtmo3as1nr X-Rspamd-Queue-Id: BEF241800F8 X-HE-Tag: 1659364886-947286 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hook ioremap_allowed() for parisc's special operation when ioremap(), then ioremap_[wc|uc]() are converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: "James E.J. Bottomley" Cc: Helge Deller Cc: linux-parisc@vger.kernel.org --- arch/parisc/include/asm/io.h | 16 ++++++--- arch/parisc/mm/ioremap.c | 66 ++++-------------------------------- 2 files changed, 18 insertions(+), 64 deletions(-) diff --git a/arch/parisc/include/asm/io.h b/arch/parisc/include/asm/io.h index 837ddddbac6a..4183f05ca1c4 100644 --- a/arch/parisc/include/asm/io.h +++ b/arch/parisc/include/asm/io.h @@ -125,13 +125,19 @@ static inline void gsc_writeq(unsigned long long val, unsigned long addr) } /* - * The standard PCI ioremap interfaces + * I/O memory mapping functions. */ -void __iomem *ioremap(unsigned long offset, unsigned long size); -#define ioremap_wc ioremap -#define ioremap_uc ioremap +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long prot); +#define ioremap_allowed ioremap_allowed -extern void iounmap(const volatile void __iomem *addr); +#define _PAGE_IOREMAP (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | \ + _PAGE_ACCESSED | _PAGE_NO_CACHE) + +#define ioremap_wc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) +#define ioremap_uc(addr, size) \ + ioremap_prot((addr), (size), _PAGE_IOREMAP) static inline unsigned char __raw_readb(const volatile void __iomem *addr) { diff --git a/arch/parisc/mm/ioremap.c b/arch/parisc/mm/ioremap.c index 345ff0b66499..1a6f928e8339 100644 --- a/arch/parisc/mm/ioremap.c +++ b/arch/parisc/mm/ioremap.c @@ -13,38 +13,20 @@ #include #include -/* - * Generic mapping function (not visible outside): - */ - -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem *ioremap(unsigned long phys_addr, unsigned long size) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - void __iomem *addr; - struct vm_struct *area; - unsigned long offset, last_addr; - pgprot_t pgprot; + phys_addr_t phys_addr = *paddr; + int ret = -EINVAL; #ifdef CONFIG_EISA unsigned long end = phys_addr + size - 1; /* Support EISA addresses */ if ((phys_addr >= 0x00080000 && end < 0x000fffff) || (phys_addr >= 0x00500000 && end < 0x03bfffff)) - phys_addr |= F_EXTEND(0xfc000000); + *paddr = phys_addr |= F_EXTEND(0xfc000000); #endif - /* Don't allow wraparound or zero size */ - last_addr = phys_addr + size - 1; - if (!size || last_addr < phys_addr) - return NULL; - /* * Don't allow anybody to remap normal RAM that we're using.. */ @@ -58,43 +40,9 @@ void __iomem *ioremap(unsigned long phys_addr, unsigned long size) for (page = virt_to_page(t_addr); page <= virt_to_page(t_end); page++) { if(!PageReserved(page)) - return NULL; + return IOMEM_ERR_PTR(ret); } } - pgprot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | - _PAGE_ACCESSED | _PAGE_NO_CACHE); - - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(last_addr + 1) - phys_addr; - - /* - * Ok, go for it.. - */ - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - addr = (void __iomem *) area->addr; - if (ioremap_page_range((unsigned long)addr, (unsigned long)addr + size, - phys_addr, pgprot)) { - vunmap(addr); - return NULL; - } - - return (void __iomem *) (offset + (char __iomem *)addr); -} -EXPORT_SYMBOL(ioremap); - -void iounmap(const volatile void __iomem *io_addr) -{ - unsigned long addr = (unsigned long)io_addr & PAGE_MASK; - - if (is_vmalloc_addr((void *)addr)) - vunmap((void *)addr); + return NULL; } -EXPORT_SYMBOL(iounmap); From patchwork Mon Aug 1 14:40:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51BB7C00144 for ; Mon, 1 Aug 2022 14:41:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E06B66B0081; Mon, 1 Aug 2022 10:41:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB5EC8E0001; Mon, 1 Aug 2022 10:41:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C7E4C6B0083; Mon, 1 Aug 2022 10:41:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B93BA6B0081 for ; Mon, 1 Aug 2022 10:41:34 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8062DC074C for ; Mon, 1 Aug 2022 14:41:34 +0000 (UTC) X-FDA: 79751287308.19.886DA11 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 0B50B180037 for ; Mon, 1 Aug 2022 14:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364893; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BBzCb2fiH7fH28l+Pr9dt4AWIkSmNoXCY2kDwl5mvZY=; b=Cm9ecKXAHgOroxT9BqTWpiT76ELql+z+K6wfwcqqmdgiEJnCKusGHp14RfOrp/+S2FxRKw asT6ZHPGnEg47Yfva3hDlq+y5nxPqo/mYrKuKVgxnLFxZ8Fy94/nQ+lyQnS6ZKiKTxyZUj NZWSFK+VCnOMEwoG7UONbmmvhomKHBA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-315-lTb-YXtxO6C8tkOzXucoeQ-1; Mon, 01 Aug 2022 10:41:30 -0400 X-MC-Unique: lTb-YXtxO6C8tkOzXucoeQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 754BC806030; Mon, 1 Aug 2022 14:41:29 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 66F84141510F; Mon, 1 Aug 2022 14:41:23 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org Subject: [PATCH 09/11] s390: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:27 +0800 Message-Id: <20220801144029.57829-10-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cm9ecKXA; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364894; a=rsa-sha256; cv=none; b=GaT3EHGHT6FEE0tzGq+5xtxSLbP6YpObzLkoyEafeXyJ/dTlxhkdpHSMaCP3pJEGAidSDt RUqQuDPAWjt6zYj3YLrJFMu9v2Lz/G81w8R8jWviY4ttE7Sl11K4XDuzkzN1v25qIQjP69 4HV2xwwzHc/ebqRjV0JRKN+MdBbuk2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364894; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=BBzCb2fiH7fH28l+Pr9dt4AWIkSmNoXCY2kDwl5mvZY=; b=YjkPeYR8JJdQOAjkrTlVpswLR1SK6qFhDhmh0kqNPlBCqtXoExOYF/FrObSskW9ZIHEM+k 7gktTx33A5ty7IWnhcg7VjRrE/L5MTVG6AJjt1HVinuLlAu5Amhu/fvwHf0sxy8PyVvwFM eV2ac+Xz7RgZQ/ETCCE9oQ5tiXrjHa4= Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Cm9ecKXA; spf=pass (imf24.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 7gshx8ij4w9qbcjjjmdn3osdxui49sh7 X-Rspamd-Queue-Id: 0B50B180037 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1659364893-790808 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hooks ioremap_allowed() and iounmap_allowed() for s390's special operation when ioremap() and iounmap(), then ioremap_[wc|wt]() are converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Alexander Gordeev Cc: Christian Borntraeger Cc: Sven Schnelle Cc: linux-s390@vger.kernel.org --- arch/s390/Kconfig | 1 + arch/s390/include/asm/io.h | 26 +++++++++++------ arch/s390/pci/pci.c | 60 +++++--------------------------------- 3 files changed, 26 insertions(+), 61 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 5a1a8dfda6f8..60ed181dfba5 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -135,6 +135,7 @@ config S390 select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select GENERIC_VDSO_TIME_NS + select GENERIC_IOREMAP select HAVE_ALIGNED_STRUCT_PAGE if SLUB select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL diff --git a/arch/s390/include/asm/io.h b/arch/s390/include/asm/io.h index e3882b012bfa..b0f823850ef1 100644 --- a/arch/s390/include/asm/io.h +++ b/arch/s390/include/asm/io.h @@ -22,11 +22,23 @@ void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr); #define IO_SPACE_LIMIT 0 -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot); -void __iomem *ioremap(phys_addr_t addr, size_t size); -void __iomem *ioremap_wc(phys_addr_t addr, size_t size); -void __iomem *ioremap_wt(phys_addr_t addr, size_t size); -void iounmap(volatile void __iomem *addr); + +/* + * I/O memory mapping functions. + */ +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed + +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL) + +#define ioremap_wc(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writecombine(PAGE_KERNEL))) +#define ioremap_wt(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(pgprot_writethrough(PAGE_KERNEL))) static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { @@ -51,10 +63,6 @@ static inline void ioport_unmap(void __iomem *p) #define pci_iomap_wc pci_iomap_wc #define pci_iomap_wc_range pci_iomap_wc_range -#define ioremap ioremap -#define ioremap_wt ioremap_wt -#define ioremap_wc ioremap_wc - #define memcpy_fromio(dst, src, count) zpci_memcpy_fromio(dst, src, count) #define memcpy_toio(dst, src, count) zpci_memcpy_toio(dst, src, count) #define memset_io(dst, val, count) zpci_memset_io(dst, val, count) diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index bc980fd313d5..dcd17366a064 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -231,64 +231,20 @@ void __iowrite64_copy(void __iomem *to, const void *from, size_t count) zpci_memcpy_toio(to, from, count); } -static void __iomem *__ioremap(phys_addr_t addr, size_t size, pgprot_t prot) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long offset, vaddr; - struct vm_struct *area; - phys_addr_t last_addr; - - last_addr = addr + size - 1; - if (!size || last_addr < addr) - return NULL; - if (!static_branch_unlikely(&have_mio)) - return (void __iomem *) addr; - - offset = addr & ~PAGE_MASK; - addr &= PAGE_MASK; - size = PAGE_ALIGN(size + offset); - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - vaddr = (unsigned long) area->addr; - if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) { - free_vm_area(area); - return NULL; - } - return (void __iomem *) ((unsigned long) area->addr + offset); -} - -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) -{ - return __ioremap(addr, size, __pgprot(prot)); + return (void __iomem *) *paddr; + return NULL; } -EXPORT_SYMBOL(ioremap_prot); -void __iomem *ioremap(phys_addr_t addr, size_t size) +int iounmap_allowed(void __iomem *addr) { - return __ioremap(addr, size, PAGE_KERNEL); -} -EXPORT_SYMBOL(ioremap); - -void __iomem *ioremap_wc(phys_addr_t addr, size_t size) -{ - return __ioremap(addr, size, pgprot_writecombine(PAGE_KERNEL)); -} -EXPORT_SYMBOL(ioremap_wc); - -void __iomem *ioremap_wt(phys_addr_t addr, size_t size) -{ - return __ioremap(addr, size, pgprot_writethrough(PAGE_KERNEL)); -} -EXPORT_SYMBOL(ioremap_wt); - -void iounmap(volatile void __iomem *addr) -{ - if (static_branch_likely(&have_mio)) - vunmap((__force void *) ((unsigned long) addr & PAGE_MASK)); + if (!static_branch_likely(&have_mio)) + return -EINVAL; + return 0; } -EXPORT_SYMBOL(iounmap); /* Create a virtual mapping cookie for a PCI BAR */ static void __iomem *pci_iomap_range_fh(struct pci_dev *pdev, int bar, From patchwork Mon Aug 1 14:40:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8EFACC00144 for ; Mon, 1 Aug 2022 14:41:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26E116B0082; Mon, 1 Aug 2022 10:41:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1CFBC6B0083; Mon, 1 Aug 2022 10:41:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 022A66B0085; Mon, 1 Aug 2022 10:41:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DF7646B0082 for ; Mon, 1 Aug 2022 10:41:40 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B3508120921 for ; Mon, 1 Aug 2022 14:41:40 +0000 (UTC) X-FDA: 79751287560.12.594B5FF Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 4F2D4800FB for ; Mon, 1 Aug 2022 14:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364899; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ptpjQvYrPBtNMmTt+fSGBKQ4r5nKNcyczY5FXLDon0A=; b=ZB7xuHVF3r2ceLCQ5jTngSXRWT0HB6OAiF33oZ0/dHsMFZ8WaWBhJz8IM9Pcn45WGmrhtc bJfdBMvc7J4kPgoYDA/Eqz/o1bD8lmMZ3nEFh8UAAnKz3xPh0F2lNCKKWAfLSaR9YXVKi5 bxJjzT+/YJUPwLbwz8h/V/FB2INRWtk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-630-TzC6v2iRMeKK-f73vIXnIw-1; Mon, 01 Aug 2022 10:41:35 -0400 X-MC-Unique: TzC6v2iRMeKK-f73vIXnIw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1FFA23C30000; Mon, 1 Aug 2022 14:41:35 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 433A6141510F; Mon, 1 Aug 2022 14:41:29 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Yoshinori Sato , Rich Felker , linux-sh@vger.kernel.org Subject: [PATCH 10/11] sh: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:28 +0800 Message-Id: <20220801144029.57829-11-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364900; a=rsa-sha256; cv=none; b=UuSN5WNlMmvhxdqDmjrWJtXDhmBbGqLoN6Q5HPqWlOk5JniP/MlzwR4rUXU6fjeORxWOEq E0Mxfe0W4cWDd88KcU0XWjXeFCB8md+HGIhxJ2gntww5DrqWero8D35nSYF9FA+I4aaEHM wQc1iPycAI12sXGWzpurRYc8xYCMKZI= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZB7xuHVF; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364900; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ptpjQvYrPBtNMmTt+fSGBKQ4r5nKNcyczY5FXLDon0A=; b=lG6nF2F07aTv+mk7gppnay8sou0ALhBGhiypg58/jAjdcwuENlLmoO0rD7bUJk3FEKTTLY 9NHSuEikGiH8033NYWE3FFJGNzAwl3s/LE8KKKTluDeWtROe9DH8rtjNH2CRz7yMXtH65j aQeFrHBKY6xYIpMee+2GooZF2i4nb+k= Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZB7xuHVF; spf=pass (imf02.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 7nwrdp1ic5fngnkrwyixzuusq7xed6is X-Rspamd-Queue-Id: 4F2D4800FB X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1659364900-464921 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hook ioremap_allowed() for sh's special operation when ioremap(), then ioremap_cache() is converted to use ioremap_prot() from GENERIC_IOREMAP. Signed-off-by: Baoquan He Cc: Yoshinori Sato Cc: Rich Felker Cc: linux-sh@vger.kernel.org --- arch/sh/Kconfig | 1 + arch/sh/include/asm/io.h | 47 +++++++++--------------------- arch/sh/mm/ioremap.c | 62 ++++++++-------------------------------- 3 files changed, 27 insertions(+), 83 deletions(-) diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig index 5f220e903e5a..b63ad4698cf8 100644 --- a/arch/sh/Kconfig +++ b/arch/sh/Kconfig @@ -25,6 +25,7 @@ config SUPERH select GENERIC_SCHED_CLOCK select GENERIC_SMP_IDLE_THREAD select GUP_GET_PTE_LOW_HIGH if X2TLB + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_KGDB select HAVE_ARCH_SECCOMP_FILTER diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h index fba90e670ed4..b2cba511a73b 100644 --- a/arch/sh/include/asm/io.h +++ b/arch/sh/include/asm/io.h @@ -242,45 +242,26 @@ unsigned long long poke_real_address_q(unsigned long long addr, #define phys_to_virt(address) (__va(address)) #endif -#ifdef CONFIG_MMU -void iounmap(void __iomem *addr); -void __iomem *__ioremap_caller(phys_addr_t offset, unsigned long size, - pgprot_t prot, void *caller); - -static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size) -{ - return __ioremap_caller(offset, size, PAGE_KERNEL_NOCACHE, - __builtin_return_address(0)); -} - -static inline void __iomem * -ioremap_cache(phys_addr_t offset, unsigned long size) -{ - return __ioremap_caller(offset, size, PAGE_KERNEL, - __builtin_return_address(0)); -} -#define ioremap_cache ioremap_cache +/* + * I/O memory mapping functions. + */ +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed -#ifdef CONFIG_HAVE_IOREMAP_PROT -static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size, - unsigned long flags) -{ - return __ioremap_caller(offset, size, __pgprot(flags), - __builtin_return_address(0)); -} -#endif /* CONFIG_HAVE_IOREMAP_PROT */ +int iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed -#else /* CONFIG_MMU */ -static inline void __iomem *ioremap(phys_addr_t offset, size_t size) -{ - return (void __iomem *)(unsigned long)offset; -} +#define _PAGE_IOREMAP pgprot_val(PAGE_KERNEL_NOCACHE) -static inline void iounmap(volatile void __iomem *addr) { } -#endif /* CONFIG_MMU */ +#define ioremap_cache(addr, size) \ + ioremap_prot((addr), (size), pgprot_val(PAGE_KERNEL)) +#define ioremap_cache ioremap_cache #define ioremap_uc ioremap +#include + /* * Convert a physical pointer to a virtual kernel pointer for /dev/mem * access diff --git a/arch/sh/mm/ioremap.c b/arch/sh/mm/ioremap.c index 21342581144d..66637a6cc6f8 100644 --- a/arch/sh/mm/ioremap.c +++ b/arch/sh/mm/ioremap.c @@ -72,22 +72,13 @@ __ioremap_29bit(phys_addr_t offset, unsigned long size, pgprot_t prot) #define __ioremap_29bit(offset, size, prot) NULL #endif /* CONFIG_29BIT */ -/* - * Remap an arbitrary physical address space into the kernel virtual - * address space. Needed when the kernel wants to access high addresses - * directly. - * - * NOTE! We need to allow non-page-aligned mappings too: we will obviously - * have to convert them into an offset in a page-aligned mapping, but the - * caller shouldn't need to know that small detail. - */ -void __iomem * __ref -__ioremap_caller(phys_addr_t phys_addr, unsigned long size, - pgprot_t pgprot, void *caller) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - struct vm_struct *area; - unsigned long offset, last_addr, addr, orig_addr; + unsigned long last_addr, phys_addr = *paddr; void __iomem *mapped; + pgprot_t pgprot = __pgprot(*prot_val); + int ret = -EINVAL; mapped = __ioremap_trapped(phys_addr, size); if (mapped) @@ -100,7 +91,7 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size, /* Don't allow wraparound or zero size */ last_addr = phys_addr + size - 1; if (!size || last_addr < phys_addr) - return NULL; + return IOMEM_ERR_PTR(ret); /* * If we can't yet use the regular approach, go the fixmap route. @@ -116,30 +107,8 @@ __ioremap_caller(phys_addr_t phys_addr, unsigned long size, if (mapped && !IS_ERR(mapped)) return mapped; - /* - * Mappings have to be page-aligned - */ - offset = phys_addr & ~PAGE_MASK; - phys_addr &= PAGE_MASK; - size = PAGE_ALIGN(last_addr+1) - phys_addr; - - /* - * Ok, go for it.. - */ - area = get_vm_area_caller(size, VM_IOREMAP, caller); - if (!area) - return NULL; - area->phys_addr = phys_addr; - orig_addr = addr = (unsigned long)area->addr; - - if (ioremap_page_range(addr, addr + size, phys_addr, pgprot)) { - vunmap((void *)orig_addr); - return NULL; - } - - return (void __iomem *)(offset + (char *)orig_addr); + return NULL; } -EXPORT_SYMBOL(__ioremap_caller); /* * Simple checks for non-translatable mappings. @@ -158,7 +127,7 @@ static inline int iomapping_nontranslatable(unsigned long offset) return 0; } -void iounmap(void __iomem *addr) +int iounmap_allowed(void __iomem *addr) { unsigned long vaddr = (unsigned long __force)addr; struct vm_struct *p; @@ -167,26 +136,19 @@ void iounmap(void __iomem *addr) * Nothing to do if there is no translatable mapping. */ if (iomapping_nontranslatable(vaddr)) - return; + return -EINVAL; /* * There's no VMA if it's from an early fixed mapping. */ if (iounmap_fixed(addr) == 0) - return; + return -EINVAL; /* * If the PMB handled it, there's nothing else to do. */ if (pmb_unmap(addr) == 0) - return; + return -EINVAL; - p = remove_vm_area((void *)(vaddr & PAGE_MASK)); - if (!p) { - printk(KERN_ERR "%s: bad address %p\n", __func__, addr); - return; - } - - kfree(p); + return 0; } -EXPORT_SYMBOL(iounmap); From patchwork Mon Aug 1 14:40:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 12933832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 875EDC19F2B for ; Mon, 1 Aug 2022 14:41:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F9176B0071; Mon, 1 Aug 2022 10:41:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 181B36B0083; Mon, 1 Aug 2022 10:41:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3F066B0085; Mon, 1 Aug 2022 10:41:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DDFB56B0071 for ; Mon, 1 Aug 2022 10:41:50 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A4D121C21C6 for ; Mon, 1 Aug 2022 14:41:50 +0000 (UTC) X-FDA: 79751287980.21.2CB38ED Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 454DC400F5 for ; Mon, 1 Aug 2022 14:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659364909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hmWLgk9mxYZv12nkrvH4NBGBZ/tnKJeEmUWq6HAqO4g=; b=VTcxaCdt2MsUvMHlfwKxG87TXt6JWWNSOIwIM3/jkrBbfcTW1Eoffuidty2cGxieHLtn1g 5Sreq4r5KheldrHGg1/9LDaSFG+F9AgFUCwWV8Cud2e2yR8Au/9qLOee4FJewRtAoETvGF S7CxOwKQcKVFmGu/c6ceuOtpZEdA8ik= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-623-On80zDDoNia6S4F6gjcXbw-1; Mon, 01 Aug 2022 10:41:40 -0400 X-MC-Unique: On80zDDoNia6S4F6gjcXbw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5231F8039C3; Mon, 1 Aug 2022 14:41:40 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-103.pek2.redhat.com [10.72.12.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB0AB141DC28; Mon, 1 Aug 2022 14:41:35 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Baoquan He , Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org Subject: [PATCH 11/11] xtensa: mm: Convert to GENERIC_IOREMAP Date: Mon, 1 Aug 2022 22:40:29 +0800 Message-Id: <20220801144029.57829-12-bhe@redhat.com> In-Reply-To: <20220801144029.57829-1-bhe@redhat.com> References: <20220801144029.57829-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VTcxaCdt; spf=pass (imf12.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659364910; a=rsa-sha256; cv=none; b=aSUCR96Yl41wZ7BJE19rnr5snSW6AXGPN0nqU2d+5Q9tEknxJM5tPmAt8VceRR36I/f266 3gTu5AWcS3rGknYwVSwmwtkT+Ew6wAjHS6E46jJuYX68vgeFC8BiNS2O/iCOLVlRouDsrz 2x7kTUR0BZnuBeN6h6NJVFvJRbZeBFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659364910; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hmWLgk9mxYZv12nkrvH4NBGBZ/tnKJeEmUWq6HAqO4g=; b=8cL58g+ymoNhaujU/etK4wPE7dvL9aRlt4n2tLlKa3Y/+USFLt0Zr6fOijaot/U7M81jA4 wF3QPo0Uls1r2Mc1iD6xPySit19ZJqSojs7Zt62EYuFkWLHSgJXXWr186/y8zSn4oksuRV U9UP/WbzpUfY0HyOYxf96ZHmerkfF9Y= X-Stat-Signature: pg4zjwaa6s3et3cqiqejremid7swizme X-Rspamd-Queue-Id: 454DC400F5 X-Rspam-User: X-Rspamd-Server: rspam05 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=VTcxaCdt; spf=pass (imf12.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1659364910-931920 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add hooks ioremap_allowed() and iounmap_allowed() for xtensa's special operation when ioremap() and iounmap(). Then define and implement its own ioremap() and ioremap_cache(). Signed-off-by: Baoquan He Cc: Chris Zankel Cc: Max Filippov Cc: linux-xtensa@linux-xtensa.org --- arch/xtensa/Kconfig | 1 + arch/xtensa/include/asm/io.h | 39 ++++++++++++------------- arch/xtensa/mm/ioremap.c | 56 +++++++++--------------------------- 3 files changed, 32 insertions(+), 64 deletions(-) diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 0b0f0172cced..8edc1a049673 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -27,6 +27,7 @@ config XTENSA select GENERIC_LIB_UCMPDI2 select GENERIC_PCI_IOMAP select GENERIC_SCHED_CLOCK + select GENERIC_IOREMAP if MMU select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL select HAVE_ARCH_KASAN if MMU && !XIP_KERNEL diff --git a/arch/xtensa/include/asm/io.h b/arch/xtensa/include/asm/io.h index 54188e69b988..ca890b7d9f91 100644 --- a/arch/xtensa/include/asm/io.h +++ b/arch/xtensa/include/asm/io.h @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -23,23 +24,29 @@ #define IO_SPACE_LIMIT ~0 #define PCI_IOBASE ((void __iomem *)XCHAL_KIO_BYPASS_VADDR) -#ifdef CONFIG_MMU - -void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size); -void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size); -void xtensa_iounmap(volatile void __iomem *addr); - /* - * Return the virtual address for the specified bus memory. + * I/O memory mapping functions. */ +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val); +#define ioremap_allowed ioremap_allowed + +int iounmap_allowed(void *addr); +#define iounmap_allowed iounmap_allowed + +void __iomem *ioremap_prot(phys_addr_t paddr, size_t size, + unsigned long prot); + static inline void __iomem *ioremap(unsigned long offset, unsigned long size) { if (offset >= XCHAL_KIO_PADDR && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE) return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_BYPASS_VADDR); else - return xtensa_ioremap_nocache(offset, size); + return ioremap_prot(offset, size, + pgprot_val(pgprot_noncached(PAGE_KERNEL))); } +#define ioremap ioremap static inline void __iomem *ioremap_cache(unsigned long offset, unsigned long size) @@ -48,24 +55,14 @@ static inline void __iomem *ioremap_cache(unsigned long offset, && offset - XCHAL_KIO_PADDR < XCHAL_KIO_SIZE) return (void*)(offset-XCHAL_KIO_PADDR+XCHAL_KIO_CACHED_VADDR); else - return xtensa_ioremap_cache(offset, size); -} -#define ioremap_cache ioremap_cache - -static inline void iounmap(volatile void __iomem *addr) -{ - unsigned long va = (unsigned long) addr; + return ioremap_prot(offset, size, pgprot_val(PAGE_KERNEL)); - if (!(va >= XCHAL_KIO_CACHED_VADDR && - va - XCHAL_KIO_CACHED_VADDR < XCHAL_KIO_SIZE) && - !(va >= XCHAL_KIO_BYPASS_VADDR && - va - XCHAL_KIO_BYPASS_VADDR < XCHAL_KIO_SIZE)) - xtensa_iounmap(addr); } +#define ioremap_cache ioremap_cache +#ifdef CONFIG_MMU #define virt_to_bus virt_to_phys #define bus_to_virt phys_to_virt - #endif /* CONFIG_MMU */ #include diff --git a/arch/xtensa/mm/ioremap.c b/arch/xtensa/mm/ioremap.c index a400188c16b9..76733528f06d 100644 --- a/arch/xtensa/mm/ioremap.c +++ b/arch/xtensa/mm/ioremap.c @@ -6,60 +6,30 @@ */ #include -#include #include #include #include -static void __iomem *xtensa_ioremap(unsigned long paddr, unsigned long size, - pgprot_t prot) +void __iomem * +ioremap_allowed(phys_addr_t *paddr, size_t size, unsigned long *prot_val) { - unsigned long offset = paddr & ~PAGE_MASK; - unsigned long pfn = __phys_to_pfn(paddr); - struct vm_struct *area; - unsigned long vaddr; - int err; - - paddr &= PAGE_MASK; + unsigned long phys_addr = *paddr; + unsigned long pfn = __phys_to_pfn(phys_addr); WARN_ON(pfn_valid(pfn)); - size = PAGE_ALIGN(offset + size); - - area = get_vm_area(size, VM_IOREMAP); - if (!area) - return NULL; - - vaddr = (unsigned long)area->addr; - area->phys_addr = paddr; - - err = ioremap_page_range(vaddr, vaddr + size, paddr, prot); - - if (err) { - vunmap((void *)vaddr); - return NULL; - } - - flush_cache_vmap(vaddr, vaddr + size); - return (void __iomem *)(offset + vaddr); + return NULL; } -void __iomem *xtensa_ioremap_nocache(unsigned long addr, unsigned long size) +int iounmap_allowed(void __iomem *addr) { - return xtensa_ioremap(addr, size, pgprot_noncached(PAGE_KERNEL)); -} -EXPORT_SYMBOL(xtensa_ioremap_nocache); + unsigned long va = (unsigned long) addr; -void __iomem *xtensa_ioremap_cache(unsigned long addr, unsigned long size) -{ - return xtensa_ioremap(addr, size, PAGE_KERNEL); -} -EXPORT_SYMBOL(xtensa_ioremap_cache); - -void xtensa_iounmap(volatile void __iomem *io_addr) -{ - void *addr = (void *)(PAGE_MASK & (unsigned long)io_addr); + if ((va >= XCHAL_KIO_CACHED_VADDR && + va - XCHAL_KIO_CACHED_VADDR < XCHAL_KIO_SIZE) || + (va >= XCHAL_KIO_BYPASS_VADDR && + va - XCHAL_KIO_BYPASS_VADDR < XCHAL_KIO_SIZE)) + return -EINVAL; - vunmap(addr); + return 0; } -EXPORT_SYMBOL(xtensa_iounmap);