Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4280423rwd; Tue, 30 May 2023 03:11:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6IieehoQ59jd75LvZ4ME+k4FR60SNHItar2N7TX2WsFx6/UL6q5Hwjxo71g2F3saHSDscO X-Received: by 2002:a17:90b:485:b0:256:8dbd:74fa with SMTP id bh5-20020a17090b048500b002568dbd74famr1756750pjb.22.1685441473620; Tue, 30 May 2023 03:11:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685441473; cv=none; d=google.com; s=arc-20160816; b=lbPrqc9Y2PjZRBchw0s2gUYbPEsjxocRdTMwfrHdbTbK+3fJpP82zndgn1R/WG52kZ lqcywHokguZah2XuTNnJiZ85YWDQaF/QePl+w1ohIQ+0pUPyvM/Si+oqKq4Zd4mi0fOF UiOHUutKjFdcWKbx2NY6Rr3NIWDPy+X/YE8UA/NXalYRZJCVsvz2Edj3AcukVPn2MpuG XRGCoJTRofnWdDVkeebbIl2EBbYgz/mn6nVKq2DMDlTCHCEsR8ABk6DKheyeIAx2y6lu X7YDEmKcvWA+8MkDo3XzCFRE1IsKqlcSvbkGEO8Eoxc26bXGXo7SAdyKHxkIcAiuGShc 5WJw== 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=g3KL3EHQXIEMhG+qF6ouz6Zrek1DaRJ8+MJLe7WdMsQ=; b=awN9uxuGbj/hP2rjUcXO5EFtBoWLiRLXz74f1fSqbMatLo9D8CEX8eIRbyIdzG4/yg IsKHwWqUAZ/2P7ex5/TbkJRQYT9m7HnZMRojQuY3GMRT0FF2sih7ycF31A3PkQ0Vy4B1 9gzFTRjhpkOaYZaCwOc3mtpfmYHPbsdgtMxdNpKBhBQSvpjq+6ebIUWgVGhvQhd7Z961 JT0YAThr2Aov0ixzNiU5ns4dAm+J5a/GUYGe+FrbCytBlLoDp738ZSh/EnRpboPxpnPF GFyznV4lsLHPy5Q6miUsYtuw8D5i9d/IP3r6aaJ1k5lyvqHpqCxEQCrsaXfIhMu0wJ4L BVtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WK3RWFE9; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cl14-20020a17090af68e00b0025645567eacsi750010pjb.94.2023.05.30.03.10.59; Tue, 30 May 2023 03:11:13 -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=@redhat.com header.s=mimecast20190719 header.b=WK3RWFE9; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjE3JiP (ORCPT + 99 others); Tue, 30 May 2023 05:38:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjE3JiO (ORCPT ); Tue, 30 May 2023 05:38:14 -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 ESMTPS id 59D2793 for ; Tue, 30 May 2023 02:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685439450; 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=g3KL3EHQXIEMhG+qF6ouz6Zrek1DaRJ8+MJLe7WdMsQ=; b=WK3RWFE9qBP8vf+Z3YYEOdOXQTKX8/1a0pBF7HkcT52TuHrGXrRquuTsLQLIiylRvsG9Uw 02FaVSXh6aJTEXlL9FHXw8trKEyelCiOKdFqMhdGfUcKbNyeWuK/24xz27yrrEHuaDSTX9 9TaC0tHWEjzdiKlILuVZGP9wgwc9a+Q= 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-590-1_ez37_sOBKnhBkfjuZVmg-1; Tue, 30 May 2023 05:37:29 -0400 X-MC-Unique: 1_ez37_sOBKnhBkfjuZVmg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 68A0C85A5BB; Tue, 30 May 2023 09:37:28 +0000 (UTC) Received: from localhost (ovpn-12-192.pek2.redhat.com [10.72.12.192]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3550F43E907; Tue, 30 May 2023 09:37:26 +0000 (UTC) Date: Tue, 30 May 2023 17:37:23 +0800 From: Baoquan He To: Christoph Hellwig Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, arnd@arndb.de, christophe.leroy@csgroup.eu, agordeev@linux.ibm.com, wangkefeng.wang@huawei.com, schnelle@linux.ibm.com, David.Laight@aculab.com, shorne@gmail.com, willy@infradead.org, deller@gmx.de Subject: Re: [PATCH v5 RESEND 14/17] mm/ioremap: Consider IOREMAP space in generic ioremap Message-ID: References: <20230515090848.833045-1-bhe@redhat.com> <20230515090848.833045-15-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 05/16/23 at 11:44pm, Christoph Hellwig wrote: > On Tue, May 16, 2023 at 11:41:26PM -0700, Christoph Hellwig wrote: > > I think this would be cleaner if we'd just always use > > __get_vm_area_caller and at the top of the file add a: > > > > #ifndef IOREMAP_START > > #define IOREMAP_START VMALLOC_START > > #define IOREMAP_END VMALLOC_END > > #endif > > > > Together with a little comment that ioremap often, but not always > > uses the generic vmalloc area. > > .. and with that we can also simply is_ioremap_addr by moving it > to ioremap.c and making it always operate on the IOREMAP constants. In the current code, is_ioremap_addr() is being used in kernel/iomem.c. However, mm/ioremap.c is only built in when CONFIG_GENERIC_IOREMAP is enabled. This will impact those architectures which haven't taken GENERIC_IOREMAP way. [~]$ git grep is_ioremap_addr arch/powerpc/include/asm/pgtable.h:#define is_ioremap_addr is_ioremap_addr arch/powerpc/include/asm/pgtable.h:static inline bool is_ioremap_addr(const void *x) include/linux/mm.h:static inline bool is_ioremap_addr(const void *x) include/linux/mm.h:static inline bool is_ioremap_addr(const void *x) kernel/iomem.c: if (is_ioremap_addr(addr)) mm/ioremap.c: if (is_ioremap_addr(vaddr)) [bhe@MiWiFi-R3L-srv linux-arm64]$ git grep ioremap mm/Makefile mm/Makefile:obj-$(CONFIG_GENERIC_EARLY_IOREMAP) += early_ioremap.o mm/Makefile:obj-$(CONFIG_GENERIC_IOREMAP) += ioremap.o If we want to consolidate code, we can move is_ioremap_addr() to include/linux/mm.h libe below. Not sure if it's fine. With it, both kernel/iomem.c and mm/ioremap.c can use is_ioremap_addr(). diff --git a/include/linux/mm.h b/include/linux/mm.h index 27ce77080c79..0fbb94f0f025 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1041,9 +1041,25 @@ unsigned long vmalloc_to_pfn(const void *addr); * On nommu, vmalloc/vfree wrap through kmalloc/kfree directly, so there * is no special casing required. */ - -#ifndef is_ioremap_addr -#define is_ioremap_addr(x) is_vmalloc_addr(x) +#if defined(CONFIG_HAS_IOMEM) || defined(CONFIG_GENERIC_IOREMAP) +/* + * Ioremap often, but not always uses the generic vmalloc area. E.g on + * Power ARCH, it could have different ioremap space. + */ +#ifndef IOREMAP_START +#define IOREMAP_START VMALLOC_START +#define IOREMAP_END VMALLOC_END +#endif +static inline bool is_ioremap_addr(const void *x) +{ + unsigned long addr = (unsigned long)kasan_reset_tag(x); + return addr >= IOREMAP_START && addr < IOREMAP_END; +} +#else +static inline bool is_ioremap_addr(const void *x) +{ + return false; +} #endif #ifdef CONFIG_MMU