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 08E9EC433EF for ; Mon, 6 Jun 2022 15:16:01 +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=t/EHirIqddwVAToN4/yntBBasKyitUHC5b/dOEOWV9w=; b=Bgm8fef0nynI8D H6lWfgwz+Q0OY/6UqkJciqZ5RGqLDK0cwFvkrN9yTM9Tsqhk2W70llrhSsGjdWk/ltLoQAd0Y5yev s29zyKlx7mKJ8pkaD9kuR7gjXk265k4qihol14wQx9LM9IFhcg7GkVXy9jL7eHv/kuvWWbykawMdi wPQLrHffh2VzsaOAPwWGtp1krAP3yFzsoaQHAwQitfnxH38EcEA1Hs6xTon/jt+wFEpv+vYICCLeE ESUO5EL7OUECcLSg+nN1OYNnSEEfaEDATIPpLUBAm/hiaIo5/9bEYh9rJcr2aHXD5wNudcXeCorJB dBpkbKXCqGyUWiV5Jxbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyER6-001jZD-KC; Mon, 06 Jun 2022 15:14:32 +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 1nyER2-001jXD-BT for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2022 15:14:30 +0000 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-Disposition: inline In-Reply-To: <20220606074815.139265-5-wangkefeng.wang@huawei.com> X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220606_081428_570712_C1906FAA X-CRM114-Status: GOOD ( 22.42 ) 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/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 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel