Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2283202iof; Wed, 8 Jun 2022 01:22:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwGL6ig2KNd7T23+DM08V2UUzq3PdWLVDAE407E1HYmNrfmVRqB+JlI76Yyzh7/Iun190dT X-Received: by 2002:a17:90b:3b86:b0:1e8:6b89:2bb2 with SMTP id pc6-20020a17090b3b8600b001e86b892bb2mr19996273pjb.15.1654676552770; Wed, 08 Jun 2022 01:22:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654676552; cv=none; d=google.com; s=arc-20160816; b=bNqS9j/tEZV4SsP2Y/cqQf/VaK8HIn095ePd2khwLhAEHxBj6oZuzzfvXC2GBi51iE 87XlrLj8haM9DVZG+5LCZriYQllQhQIGhqs4idgM7YCR9o4El547TDkgnXcAbYW3D67d aQGAezPPNpUoPWRX4OBYmjewQfx+62LfxoaJuVkWHRe/ojAn44vpiKkgWxOreeehCIwE hgsULtxufBdF1C2pvsk1ItsaDSP+jY7IftJwFI2gDjXqoRgT5FqyMF2CwAsJLK9fleSU p9RC3MuoZSoIoxmRDNmd4ZzHfg2UeumaaUvw0Ns/gokJLPO3Cf/hRLnTWvr1d8L244jY CP6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sjie14sl+UUWdfLUeHqpm3M+18uxVtV8OsIS9/gQLdg=; b=i8OsIQ2kIL/iLkVA1a7rrTR+FQr7hN0qkerXEAnNVZBMabpV2J+j1HqRBZngRtKeBC ZlofF66cDf1ekAkHMQD4OPTNU8CjQnam7sYKxxpkULzqs/NAQ1rKR5rDr71Acq0aN5oI C6+rEeD3DjVtq4uKXkQSpMytBp5P11G+Un2NT7YAAzwy7NofmFxhchQx7eB4UGdka1BV gc3udFGkQg6hR8hDlPjAdfdHH2TruNjfV3YQ+uPe+qV7umy6lWQmRp90h7UguxHYluIx eA+9Y6pbA+TUtdLwV2zFgvloILiStrF/NtnrI6IEylRnWiytNuKnFso82g1kDTF4j1WS nOwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J+botJCG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k4-20020aa788c4000000b00518fc8adc58si16921571pff.380.2022.06.08.01.22.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 01:22:32 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=J+botJCG; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2033A3B4ECE; Wed, 8 Jun 2022 00:52:57 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238372AbiFHGFt (ORCPT + 99 others); Wed, 8 Jun 2022 02:05:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347007AbiFHF5n (ORCPT ); Wed, 8 Jun 2022 01:57:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1DE0D213AE4 for ; Tue, 7 Jun 2022 21:19:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654661949; 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=J+botJCGuUPgC08bPQFnQMD+vAZTZTfRpNlN+q1/dB88vFlTxQIEMVQQQt7DmcUKcNZfkd CxNorDHOrhes/4Y9Gq1sl45iKN9CIZEIlWhpiNgfx43LW86jqD4wEMXkZOEIBN14lzJTIj iuSvY5MlT6BcbnRivRal9QWZSp20ux8= 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-Type: text/plain; charset=us-ascii 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-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 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 > >