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 414D0C7EE23 for ; Tue, 30 May 2023 09:37:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C17E76B0072; Tue, 30 May 2023 05:37:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC88D900002; Tue, 30 May 2023 05:37:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8F506B0075; Tue, 30 May 2023 05:37:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 99C486B0072 for ; Tue, 30 May 2023 05:37:39 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7954DC0184 for ; Tue, 30 May 2023 09:37:39 +0000 (UTC) X-FDA: 80846419038.12.6E578F1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf23.hostedemail.com (Postfix) with ESMTP id 6252014000B for ; Tue, 30 May 2023 09:37:37 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WM3ybxdR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1685439457; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=g3KL3EHQXIEMhG+qF6ouz6Zrek1DaRJ8+MJLe7WdMsQ=; b=JAnpCp+HrBJG2v3FJDHnfGWxzYx3eJqZ4O7zaGfcJUliKs7RjZ/MCH3LFcPuIFf9++5275 fzU9a1t9U/DfhNSRsoZQ85DTGwr0Mz+D635bHrUMhXBDQVFInpsiwPrJEYCdqQ162f63pf 51tuNqBvuCArYCBFQrdk2T6LlksIVO8= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=WM3ybxdR; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf23.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1685439457; a=rsa-sha256; cv=none; b=BKtsRG9tc4ISGXw1KoAr7/zUqc5OsR55T6kfcqJmlTAlJmjnMV66slg27iz/QuBCmI+H7u rkPT8PP9lkBYzNnuOG2g9NTaP8t6wWIzrkDFVe/E5hQLrcosSHcwrE67D6c06QgSqjtJpC ohsyu1d5UoxJTm2aiCSqnG7L+To604c= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685439456; 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=WM3ybxdReamDtkP+Widibpjma4lfKQeEUmrqqaSD4SCGT1F7iWJoMr7sE2DxLh5CTJEQnq RCOMdm0iC+zdhrMzcfjCmitxZkNOje5kdmQG8u2UTrai9djxWkWaSHco0VtOvwyYjcFWYR GvWHzd3s5f+kIxrMMXilI0FImvC9gjg= 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-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6252014000B X-Stat-Signature: pexindrygzaeeihbt6887jezboyrut9c X-HE-Tag: 1685439457-357970 X-HE-Meta: U2FsdGVkX1+kBlOqyYb/gRPBB1WgH5XhEsjzEXiUq2st24bZVCzStlM7WJcen/8PPv9mKJ2s4deCE2NmALk29RyLrEDEDaNlOg1n828rloN95WIbA3vrOrSaFOUOnhsbJcyJe5EyER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ofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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