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 0F6D2C43334 for ; Mon, 6 Jun 2022 15:14:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B96F6B0072; Mon, 6 Jun 2022 11:14:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 73F946B0073; Mon, 6 Jun 2022 11:14:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5DC8B8D0001; Mon, 6 Jun 2022 11:14:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4A39B6B0072 for ; Mon, 6 Jun 2022 11:14:27 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 2A48D60775 for ; Mon, 6 Jun 2022 15:14:27 +0000 (UTC) X-FDA: 79548157374.30.236124B 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 AB56520027 for ; Mon, 6 Jun 2022 15:13:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654528466; 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=wk21lmL5uU36CD8lVe7wGCPEFaiqg58cc32bIZsmo3E=; b=Jcc412Mi+oiWHIS5uPtl1dOEWBBIgE2gPBLLFSi9py06qRHnzqdSFYLX8eMdjKpVPIYe3L gBJjTqRG9D1safYcO3/zamAzxFTbXTuFFeDs2y+mRWuDFW8M9CWwP4A74A3eddz83l2S0H urBG11ErWi1BGQlcLZoMQx2ToQrlCd0= 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-330-vs9e1VvdNA-DS8MsSeislQ-1; Mon, 06 Jun 2022 11:14:22 -0400 X-MC-Unique: vs9e1VvdNA-DS8MsSeislQ-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 5A1C1100BABB; Mon, 6 Jun 2022 15:14:22 +0000 (UTC) Received: from localhost (ovpn-14-4.pek2.redhat.com [10.72.14.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 946081410DDB; Mon, 6 Jun 2022 15:14:21 +0000 (UTC) Date: Mon, 6 Jun 2022 23:14:18 +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 v4 4/6] mm: ioremap: Add ioremap/iounmap_allowed() Message-ID: References: <20220606074815.139265-1-wangkefeng.wang@huawei.com> <20220606074815.139265-5-wangkefeng.wang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220606074815.139265-5-wangkefeng.wang@huawei.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AB56520027 X-Stat-Signature: 1iigodpsdtaq6ocnuceukwmii8abop3j Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Jcc412Mi; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf13.hostedemail.com: domain of bhe@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=bhe@redhat.com X-HE-Tag: 1654528429-457492 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 06/06/22 at 03:48pm, 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 an int, > - NULL means continue to remap > - error code means skip remap and return directly > iounmap_allowed() return an int, > - 0 means continue to vunmap > - error code means skip vunmap and return directly Aren't they bool type function and better return bool value? > > Acked-by: Andrew Morton > Signed-off-by: Kefeng Wang > --- > include/asm-generic/io.h | 25 +++++++++++++++++++++++++ > mm/ioremap.c | 13 ++++++++++--- > 2 files changed, 35 insertions(+), 3 deletions(-) > > diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h > index e6ffa2519f08..9429387a3e65 100644 > --- a/include/asm-generic/io.h > +++ b/include/asm-generic/io.h > @@ -964,6 +964,31 @@ static inline void iounmap(volatile void __iomem *addr) > #elif defined(CONFIG_GENERIC_IOREMAP) > #include > > +/* > + * Arch code can implement the following two special hooks when using GENERIC_IOREMAP > + * ioremap_allowed() return an int, > + * - 0 means continue to remap > + * - error code means skip remap and return directly > + * iounmap_allowed() return an int, > + * - 0 means continue to vunmap > + * - error code means skip vunmap and return directly > + */ > +#ifndef ioremap_allowed > +#define ioremap_allowed ioremap_allowed > +static inline int ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) > +{ > + return 0; > +} > +#endif > + > +#ifndef iounmap_allowed > +#define iounmap_allowed iounmap_allowed > +static inline int iounmap_allowed(void __iomem *addr) > +{ > + return 0; > +} > +#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 7cb9996b0c12..196c93c0beb8 100644 > --- a/mm/ioremap.c > +++ b/mm/ioremap.c > @@ -27,8 +27,10 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, unsigned long pro > phys_addr -= offset; > size = PAGE_ALIGN(size + offset); > > - area = get_vm_area_caller(size, VM_IOREMAP, > - __builtin_return_address(0)); > + if (ioremap_allowed(phys_addr, size, prot)) > + return NULL; > + > + area = get_vm_area_caller(size, VM_IOREMAP, __builtin_return_address(0)); > if (!area) > return NULL; > vaddr = (unsigned long)area->addr; > @@ -45,6 +47,11 @@ EXPORT_SYMBOL(ioremap_prot); > > void iounmap(volatile void __iomem *addr) > { > - vunmap((void *)((unsigned long)addr & PAGE_MASK)); > + void __iomem *vaddr = (void __iomem *)((unsigned long)addr & PAGE_MASK); > + > + if (iounmap_allowed(vaddr)) > + return; > + > + vunmap((void __force *)vaddr); > } > EXPORT_SYMBOL(iounmap); > -- > 2.35.3 > >