Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2434068rwi; Tue, 11 Oct 2022 08:43:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM55XPySY0z4lNGsYz6Bz/AOFlDjlawamc7ualfdDPTja5TYh1jH5OG+G8z0ydxh3exge/5m X-Received: by 2002:a05:6a00:1828:b0:563:24ea:5728 with SMTP id y40-20020a056a00182800b0056324ea5728mr15362956pfa.3.1665503002321; Tue, 11 Oct 2022 08:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665503002; cv=none; d=google.com; s=arc-20160816; b=p1S/eUhuG6rBRdRv9zYKWxEqNfpeIS8gr+QCPek4xudIo45gXBnRz0G1QakY0Kpcro rfItlSDHvHX4UUdwTzn9Z9HXQtE5pOPfq2xHPVJelvtHHaRisiI6tVbyZzoZil0wRoSD X4xGVaqU1xnNr3ljiY4j6CuK/X5pgVYhc5UfHA58h2u8uJNS6QxHJlFZttI3HX4Pt7+W JCoo2A+PwcPww6b5r6ZTneXx6hFuGl1fd8lL9ULy1ATV0ywaQprHV4+50d5QoEQLYDD9 2IIZxSn+5bqcQd3CBqeUPIsqB1wAmaynhU5xLHENI/7WekTYFhamhZCaA1+Nuia1yQ5i IW+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=aX4BDwGXtmjSFLoZblRZbyxfJQsKH9xJCvc0H0bEub0=; b=pwUZ9PDDUdzoq6DWwxf2pppwTXn7saFioSYWukgDInR/ahTfhVbs39/WmJfuw73fpu sqEeH3OD3g3Xya75zY2ZsVY3f9tqNLp127dE22miIQ6vZS8OOo/PBOkkaAKMYIJgKeTd D9sgIP4xIQhNCWxoNPjkPquLJak0OeDCp2Lfl4A9TA4yd8U1am5reyS47bXpZCVqtuls 2bJDoUsnfG3FEbAWi15T3aWvTuXJNPyeyp3Ar1IMbzCQEe2n+dHxC+j25Ys8gdNATMFw PcaKggkviAHr1SwDCXiAaPlOSlUjnOOYBDaqCweghY3zKcw6HhyIP/wfP4FVbHTax+in EZWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=MHmO7yDi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v18-20020a17090ae99200b002024f3f1f8bsi14212503pjy.70.2022.10.11.08.43.09; Tue, 11 Oct 2022 08:43:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=MHmO7yDi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbiJKP2P (ORCPT + 99 others); Tue, 11 Oct 2022 11:28:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbiJKP1s (ORCPT ); Tue, 11 Oct 2022 11:27:48 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 312CAAC386; Tue, 11 Oct 2022 08:18:31 -0700 (PDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 29BF7Kbb024309; Tue, 11 Oct 2022 15:17:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : subject : from : to : cc : date : in-reply-to : references : content-type : mime-version : content-transfer-encoding; s=pp1; bh=aX4BDwGXtmjSFLoZblRZbyxfJQsKH9xJCvc0H0bEub0=; b=MHmO7yDiT5ElVYY2nc3w3My0jxZiHWk8QnObkUx+I/Sjnw2Sy0N1v3WFsLgUSNVZ70+v jqObBpKCSmf61KfBDB0J38BZ0Xh02dl3Gvs9YShxCTe6C5ssVtMEas2dTYQW6i85y4MG 2bTmkttfWp7MJ+8J14zhCEv8ywzk/G82SmMPreK/LHtipe0xWU2lsYdrwShNzaiQ+Edv cR2EiaqfBOeouQa+X+truvMW1taOIQrVnXRaYvza/wKehEOfbLG5HpRSPX0/mCSAWyJC 87/GkUT1XGQGPGkvkLu9uiIcSyCge3u7/nnhwDi8AlBBnB1i6a2INpnvCEET3eSxvN8Y 8Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k58t1n6d9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Oct 2022 15:17:01 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 29BF7qtn027496; Tue, 11 Oct 2022 15:17:01 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3k58t1n6c3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Oct 2022 15:17:01 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 29BF6QRj015220; Tue, 11 Oct 2022 15:16:58 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 3k30fjcnx1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Oct 2022 15:16:58 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 29BFGt1Z32768272 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Oct 2022 15:16:55 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 899DFA405C; Tue, 11 Oct 2022 15:16:55 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0CBACA405B; Tue, 11 Oct 2022 15:16:55 +0000 (GMT) Received: from oc-nschnelle.boeblingen.de.ibm.com (unknown [9.155.199.46]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 11 Oct 2022 15:16:54 +0000 (GMT) Message-ID: Subject: Re: [PATCH v3 09/11] s390: mm: Convert to GENERIC_IOREMAP From: Niklas Schnelle To: Baoquan He , linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, hch@infradead.org, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, christophe.leroy@csgroup.eu, David.Laight@ACULAB.COM, shorne@gmail.com, Gerald Schaefer , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Sven Schnelle , linux-s390@vger.kernel.org Date: Tue, 11 Oct 2022 17:16:54 +0200 In-Reply-To: <20221009103114.149036-10-bhe@redhat.com> References: <20221009103114.149036-1-bhe@redhat.com> <20221009103114.149036-10-bhe@redhat.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5 (3.28.5-18.el8) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: YJnXTHy0uGOqENjmA5h8EJhYAqEww7ZR X-Proofpoint-GUID: 4GiiOhBtnJ99UoJEwGzWIrV6d3svBqhI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-10-11_08,2022-10-11_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 suspectscore=0 priorityscore=1501 impostorscore=0 spamscore=0 mlxlogscore=999 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2209130000 definitions=main-2210110086 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 2022-10-09 at 18:31 +0800, Baoquan He wrote: > By taking GENERIC_IOREMAP method, the generic ioremap_prot() and > iounmap() are visible and available to arch. Arch only needs to > provide implementation of arch_ioremap() or arch_iounmap() if there's > arch specific handling needed in its ioremap() or iounmap(). This > change will simplify implementation by removing duplicated codes with > generic ioremap() and iounmap(), and has the equivalent functioality > as before. > > For s390, add hooks arch_ioremap() and arch_iounmap() 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: Niklas Schnelle > Cc: Gerald Schaefer > Cc: Heiko Carstens > Cc: Vasily Gorbik > Cc: Alexander Gordeev > Cc: Christian Borntraeger > Cc: Sven Schnelle > Cc: linux-s390@vger.kernel.org > --- > v2->v3: > - Add code comment inside arch_ioremap() to help uderstand the > obsucre code. Christoph suggested this, Niklas provided the > paragraph of text. > > arch/s390/Kconfig | 1 + > arch/s390/include/asm/io.h | 25 +++++++++------ > arch/s390/pci/pci.c | 65 ++++++++------------------------------ > 3 files changed, 30 insertions(+), 61 deletions(-) > > diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig > index 318fce77601d..c59e1b25f59d 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 I think you should add the "if PCI" from the diff in your last mail to this patch. > 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..db201563baa6 100644 > --- a/arch/s390/include/asm/io.h > +++ b/arch/s390/include/asm/io.h > @@ -22,11 +22,22 @@ 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 * > +arch_ioremap(phys_addr_t *paddr, size_t size, unsigned long *prot_val); > +#define arch_ioremap arch_ioremap > + > +bool arch_iounmap(void __iomem *addr); > +#define arch_iounmap arch_iounmap > + > +#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 +62,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 73cdc5539384..3c00dc7d79bc 100644 > --- a/arch/s390/pci/pci.c > +++ b/arch/s390/pci/pci.c > @@ -244,64 +244,25 @@ 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 * > +arch_ioremap(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; > - > + /* > + * When PCI MIO instructions are unavailable the "physical" address > + * encodes a hint for accessing the PCI memory space it represents. > + * Just pass it unchanged such that ioread/iowrite can decode it. > + */ > 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); > + return (void __iomem *) *paddr; nit: no space after the cast > + return NULL; > } > > -void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot) > +bool arch_iounmap(void __iomem *addr) > { > - return __ioremap(addr, size, __pgprot(prot)); > -} > -EXPORT_SYMBOL(ioremap_prot); > - > -void __iomem *ioremap(phys_addr_t addr, size_t size) > -{ > - 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 false; > + return true; > } > -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, Gave this a round of testing on s390 with both the MIO and non-MIO cases. I also see you addressed my previous comments and it looks good to me. As you showed in the other mail the compile error is a pre existing problem so shouldn't influence this change. So assuming you add the "if PCI" and the nit above you can add my: Tested-by: Niklas Schnelle Reviewed-by: Niklas Schnelle