From mboxrd@z Thu Jan 1 00:00:00 1970 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 D3763ECAAD4 for ; Mon, 29 Aug 2022 06:32:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A44A940008; Mon, 29 Aug 2022 02:32:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4534E940007; Mon, 29 Aug 2022 02:32:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3420C940008; Mon, 29 Aug 2022 02:32:33 -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 210A1940007 for ; Mon, 29 Aug 2022 02:32:33 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E874BAB399 for ; Mon, 29 Aug 2022 06:32:32 +0000 (UTC) X-FDA: 79851661344.24.001A1F8 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) by imf31.hostedemail.com (Postfix) with ESMTP id 9F07E20011 for ; Mon, 29 Aug 2022 06:32:32 +0000 (UTC) Received: by mail-wm1-f43.google.com with SMTP id k6-20020a05600c1c8600b003a54ecc62f6so3886806wms.5 for ; Sun, 28 Aug 2022 23:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=Q9bG4C/lzqI/HkM4WnO4cpc4zH/UG8bBgrrBbgVdTS7NTL6FoUXymtUtiZUfLhdqlI vNzIoae9pjeuErhoyALL285mDB05G2HivjfavrPWWasdGfZT84ljgH4pYvpcNbsxUcLV Scd56sSMOoZmsJWX4b8B2QQ7QpRU4O5mCvX1JePJi5XRz9byLtTy+mhocyVmrumMRart snYeZv6DRt6CISmR49x82ARa3CCHmCzoPe8R7zutuqybLgFuiDijeQdE+D5jQ0/GP8eh vKOVYCPksydgN4/UL7Wx3rf/xkFtB8GAR3IB1EEAkom5tXbVaajM8S2Cmm7o52/u/r2q SoWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=4O+UjcatEuUOOybbH7jWQCzsvNzlbtVGhnRKXV9OKV1zHt1PdcHCIf3As58jOJUUHL B9AXxaSeA6utknX9UifvqG9675HA7kzK61vMqWkiH5GXo4XKdMiXMzxBbXO6lJBANTyd 8Qy/GOcqchwSMYturcjjuXb78cDDXvjH9YUl448PUYQ80xRzaqEmkSF8nBYH+i70UHoy Fm4fJvQuqr3zSrpxvpuFqQi2gGGkXO92RALzg6/ZNfYPOZ4EAQtwEiJxpwDjXW7q1yRk ob0ERaeM5nMO1DFYGWFc6EM0Flmy5Z6xw8nnHTLKBCzoBYGx2G7pOH3P/rZ3K3jMmSea ZvCw== X-Gm-Message-State: ACgBeo2kYjyZl1ETc4Ri1ZZUnZdVmxwTlWCLQu80q1W0aaiKy1tsd/+w fxHxVxJN6VDuHV/TZq2ISQY= X-Google-Smtp-Source: AA6agR7uMSQAUXvqF4+Dz9AUFt0qYpHytKUamL8rcU5KLzy/nN2z/dASIkuI+13tvn2+7XALg52gYA== X-Received: by 2002:a05:600c:348f:b0:3a5:e28c:a1d5 with SMTP id a15-20020a05600c348f00b003a5e28ca1d5mr5725442wmq.33.1661754751411; Sun, 28 Aug 2022 23:32:31 -0700 (PDT) Received: from localhost ([2a03:b0c0:1:d0::dee:c001]) by smtp.gmail.com with ESMTPSA id b8-20020adff908000000b00223a50b1be8sm6141149wrr.50.2022.08.28.23.32.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Aug 2022 23:32:30 -0700 (PDT) Date: Mon, 29 Aug 2022 06:32:30 +0000 From: Stafford Horne To: Baoquan He Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, linux-arm-kernel@lists.infradead.org, Jonas Bonn , Stefan Kristiansson , openrisc@lists.librecores.org Subject: Re: [PATCH v2 07/11] openrisc: mm: Convert to GENERIC_IOREMAP Message-ID: References: <20220820003125.353570-1-bhe@redhat.com> <20220820003125.353570-8-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220820003125.353570-8-bhe@redhat.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661754752; a=rsa-sha256; cv=none; b=mHDDfLjoS1ewIwoM5X/74HPY2Zii5dVadFB1/jEDvKCanQrk60DwPn7fTIGV+KCN98Wy67 rdzeLnMWumQUE8jayCPHc0rcsrvqsmhexaFiFEg7uouoPCujhnNKWvdg+APJkGWJvEX5y0 vnPXLDHtdnMTFq1YGmE+/6vQg0t8YQ8= ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Q9bG4C/l"; spf=pass (imf31.hostedemail.com: domain of shorne@gmail.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=shorne@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661754752; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=55VuaBCh3zKQULMorjkhEtdo9YxgKyyc9DWx8OVsrmM=; b=Wd2LjEbSjWUmdwqJgIQqEnHF+kwu1KkhK3yvgwOVJZQs/WKBuJzmi2uHfkwIy/+mPChxMf 9edrzwPVNxMJV7Hz5LYDudzqp62pWUoUPO3RjXo+F1dUPx7TYTsOZXHBJRjhnJrKx/DgON dl992pi3RQZuLhEmRs2d5Cue4m58Kwk= X-Stat-Signature: ucfi6xy8p14mbnqj5pjgaxzqwibk436t X-Rspamd-Queue-Id: 9F07E20011 X-Rspam-User: X-Rspamd-Server: rspam06 Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Q9bG4C/l"; spf=pass (imf31.hostedemail.com: domain of shorne@gmail.com designates 209.85.128.43 as permitted sender) smtp.mailfrom=shorne@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1661754752-916264 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: On Sat, Aug 20, 2022 at 08:31:21AM +0800, Baoquan He wrote: > Add hooks arch_ioremap() and arch_iounmap() 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 | 51 +++++++++++----------------------- > 3 files changed, 29 insertions(+), 39 deletions(-) > > diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig > index c7f282f60f64..fd9bb76a610b 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_PCI_IOMAP > + select GENERIC_IOREMAP > select GENERIC_CPU_DEVICES > select HAVE_PCI > select HAVE_UID16 > diff --git a/arch/openrisc/include/asm/io.h b/arch/openrisc/include/asm/io.h > index ee6043a03173..9db67938bfc4 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 This seems to cause a compilation issue when building virt_defconig: CC kernel/irq/generic-chip.o In file included from ./include/asm-generic/pgtable-nopud.h:7, from ./include/asm-generic/pgtable-nopmd.h:7, from ./arch/openrisc/include/asm/pgtable.h:24, from ./arch/openrisc/include/asm/io.h:18, from ./include/linux/io.h:13, from kernel/irq/generic-chip.c:7: ./include/asm-generic/pgtable-nop4d.h:9:18: error: unknown type name 'pgd_t' 9 | typedef struct { pgd_t pgd; } p4d_t; | ^~~~~ It works if we swap the order arround: +#include +#include Otherwise we need to add an asm/page.h include to asm/pgtable.h (which is more correct) but means you would touch more files. > /* > * PCI: We do not use IO ports in OpenRISC > @@ -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 * > +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); > +#define arch_ioremap arch_ioremap > + > +int arch_iounmap(void __iomem *addr); > +#define arch_iounmap arch_iounmap > > -#define iounmap iounmap > -extern void iounmap(volatile 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 8ec0dafecf25..bc41660e1fb0 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 * > +arch_ioremap(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; > + unsigned long offset, last_addr, addr = *paddr; > + 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(volatile void __iomem *addr) > +int arch_iounmap(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(volatile 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 > -- > 2.34.1 Other than that compiler issue, I fixed it and test booted this and it works well. Acked-by: Stafford Horne