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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0103EC433EF for ; Wed, 8 Jun 2022 04:20:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jnKPrYjHTfhLqF0DolWY/S+IxQrTrRGKpMXkgNsCAiM=; b=QUl1f178r4JCMx jDChH5UsFVq9ZO33TlsqacG0glZRzP5KqmNaUjtO/rlTmapfgOb8dXvyyt7vfdGznh6rZw5vFzCBO Z8Zw9tvSEbSS+m1msYuoSYH/aKlzOSxI+fhWbZKcq0GeYlbNTNtNkQhlk06dzyWXTfByhtxQGYVf+ ZXGgWb6gsR3f0sy8obfVtQ+fCYSLO/IwqP86kGgE0R5/7R/Pz572vUpl9m3XcQHQNSw1wiBlh5yd8 8PKDumDSCsJi0JmxsAW6vs6339XwP/PhgqWtBS7C/2FwSCjfnFQ8rehmR+9PBDT9Atg9Vthwi3tlH ALSeDs3Vz/gM7liPrqNg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nynA3-00B1PC-VG; Wed, 08 Jun 2022 04:19:16 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nynA0-00B1Ns-7d for linux-arm-kernel@lists.infradead.org; Wed, 08 Jun 2022 04:19:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654661951; 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: in-reply-to:in-reply-to:references:references; bh=sjie14sl+UUWdfLUeHqpm3M+18uxVtV8OsIS9/gQLdg=; b=TWwdPzAPojQHQpKg7DiJ8O0aNDmsCsELWjxmc8Q8zV8Nz/77nK3YMa5YruAFqzLyknzmur Vx9yluRvG4zQ2G30w8kROC6g2b/0aouBR21fmmjVFmmm7zGakeiVTrA5gluBx0Orqm788n TKh8ptxYgamF19GBdkxMW8sKrCGcRxY= 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-638-vLs6zPBvNQGuXCS4wHjl9Q-1; Wed, 08 Jun 2022 00:19:05 -0400 X-MC-Unique: vLs6zPBvNQGuXCS4wHjl9Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 645143C02B6D; Wed, 8 Jun 2022 04:19:05 +0000 (UTC) Received: from localhost (ovpn-12-81.pek2.redhat.com [10.72.12.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1357440CF8E8; Wed, 8 Jun 2022 04:19:03 +0000 (UTC) Date: Wed, 8 Jun 2022 12:18:59 +0800 From: Baoquan He To: Kefeng Wang Cc: catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, hch@infradead.org, arnd@arndb.de, anshuman.khandual@arm.com Subject: Re: [PATCH v5 4/6] mm: ioremap: Add ioremap/iounmap_allowed() Message-ID: References: <20220607125027.44946-1-wangkefeng.wang@huawei.com> <20220607125027.44946-5-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220607125027.44946-5-wangkefeng.wang@huawei.com> X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220607_211912_375648_FF5CDBD1 X-CRM114-Status: GOOD ( 22.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 06/07/22 at 08:50pm, Kefeng Wang wrote: > Add special hook for architecture to verify addr, size or prot > when ioremap() or iounmap(), which will make the generic ioremap > more useful. > > ioremap_allowed() return a bool, > - true means continue to remap > - false means skip remap and return directly > iounmap_allowed() return a bool, > - true means continue to vunmap > - false code means skip vunmap and return directly > > Meanwhile, only vunmap the address when it is in vmalloc area > as the generic ioremap only returns vmalloc addresses. LGTM, Reviewed-by: Baoquan He > > Acked-by: Andrew Morton > Signed-off-by: Kefeng Wang > --- > include/asm-generic/io.h | 26 ++++++++++++++++++++++++++ > mm/ioremap.c | 11 ++++++++++- > 2 files changed, 36 insertions(+), 1 deletion(-) > > diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h > index b76379628a02..db5b890eaff7 100644 > --- a/include/asm-generic/io.h > +++ b/include/asm-generic/io.h > @@ -964,6 +964,32 @@ static inline void iounmap(volatile void __iomem *addr) > #elif defined(CONFIG_GENERIC_IOREMAP) > #include > > +/* > + * 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 > + * iounmap_allowed() return a bool, > + * - true means continue to vunmap > + * - false 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, > + unsigned long prot) > +{ > + return true; > +} > +#endif > + > +#ifndef iounmap_allowed > +#define iounmap_allowed iounmap_allowed > +static inline bool iounmap_allowed(void *addr) > +{ > + return true; > +} > +#endif > + > void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, > unsigned long prot); > void iounmap(volatile void __iomem *addr); > diff --git a/mm/ioremap.c b/mm/ioremap.c > index e1d008e8f87f..8652426282cc 100644 > --- a/mm/ioremap.c > +++ b/mm/ioremap.c > @@ -28,6 +28,9 @@ 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)) > + return NULL; > + > area = get_vm_area_caller(size, VM_IOREMAP, > __builtin_return_address(0)); > if (!area) > @@ -47,6 +50,12 @@ EXPORT_SYMBOL(ioremap_prot); > > void iounmap(volatile void __iomem *addr) > { > - vunmap((void *)((unsigned long)addr & PAGE_MASK)); > + void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); > + > + if (!iounmap_allowed(vaddr)) > + return; > + > + if (is_vmalloc_addr(vaddr)) > + vunmap(vaddr); > } > EXPORT_SYMBOL(iounmap); > -- > 2.35.3 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel