From patchwork Wed Mar 27 15:23:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13606785 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 C8562C54E67 for ; Wed, 27 Mar 2024 15:23:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90A2B6B0099; Wed, 27 Mar 2024 11:23:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8BB046B009A; Wed, 27 Mar 2024 11:23:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 696A56B009B; Wed, 27 Mar 2024 11:23:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 4989A6B0099 for ; Wed, 27 Mar 2024 11:23:52 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0E2C71A0E13 for ; Wed, 27 Mar 2024 15:23:52 +0000 (UTC) X-FDA: 81943189104.26.7DAAAE8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf24.hostedemail.com (Postfix) with ESMTP id 03A6218000F for ; Wed, 27 Mar 2024 15:23:49 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AVsJQ3ox; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711553030; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VkfUQlJiw2YmDi669w4oXgCkjfbnGDZMVpc2LJneNK4=; b=W5eykt6K1Rlaj9ohohWHBvje75V+qfFvfkJd7RLFjwIfC7ccDd0J4fDGsfu7EtRBNJ+ehX +56BhbqU+2C7QKrrqByZUZVp94xlpCPwCWW8y/+bTS0wl3gjduFgRSd9v4g3q7MniOKy36 QSNwMcRviaj5TqA0qyrb0AEHMIUzDog= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=AVsJQ3ox; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711553030; a=rsa-sha256; cv=none; b=UsRUQXn++3n+DPFOlmr+QzHsgdzue4PDxpvSGAWA5kO4jguO246I+3I00nugMd2uxiDJCI 7kLd/dBW7Rv4shNlD4VJipUAsMsh3g+jYDDoeQWU7xHNMysmqZfIhwReKKgHrQ9SrQSkM+ c46EgPywp6jvhIyFU0KGSBNCbb+L7Y4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711553029; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VkfUQlJiw2YmDi669w4oXgCkjfbnGDZMVpc2LJneNK4=; b=AVsJQ3oxZori/0jbiU/hEUHGTPyOIfF2KtXrxRs+X9qPY6bpKKg3pU3mS80iG+/rUMPxLq aQKTRNxV677HRcYDhyG05TlV3K7yqcgzl97J0robQAfWSrJEq7Qlz53NpFNy5DqVt8zadu G+7oNcVo6BMi+6axzYrp57Fo5oxz+yY= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-X4n5eIOTPlWScapNvWyJzw-1; Wed, 27 Mar 2024 11:23:48 -0400 X-MC-Unique: X4n5eIOTPlWScapNvWyJzw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-690c19ee50bso2421946d6.0 for ; Wed, 27 Mar 2024 08:23:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711553027; x=1712157827; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VkfUQlJiw2YmDi669w4oXgCkjfbnGDZMVpc2LJneNK4=; b=ECQz9JpO/hDmHvFH+JRpx//t5Z2Qod+MG3DcmhmNMHbrOuvD7DcQnafxjREInljGEp 56OfrOX3Bu6UOhzGoaiWAOyb3JO9LlqLWtK1wegtiNQgvvwDcHShabbCKOdqv7x6RKBd /mAobm31z0FH5nixmcuekbuN5/XW2+W8IVGGWYHvsicnzwvxNLmLCcL5uULUvi+nYYOG Sp0eJMqfZ56Pf69z5efk+GEfe2Gntg+xZF18mzmJAkktiypw7NwV/i5q3GVwUsR10pm7 +PYx8lwHatD4jGX+4ARu9AREuc44835vwMS+iIvOGm/O8pkbw1sOo/A+qUTITccZpX3D HLrg== X-Gm-Message-State: AOJu0YyCrSBiOauMk9GTTZgVu0q+M1c7tP2EwFfmjA3vwcbAzXJrSS5q wIDLzM1vAeF6EfkeXXpgtBOZnEIfA7e4uLocVnAxdF34JIjxDhpZS0hJlqM5uR6jVeb9QDHO5bP +aap4Z/q62rq0iEPPQPKli9jEftJ5FJ4anWZQwn5YApNQKanW3Ct1Mq9cUsh56LziVU6UPRBUf2 YRnVJsodkbGBuOgQcyi2z4E2SxFpKw6A== X-Received: by 2002:a05:6214:3105:b0:696:6f59:4d19 with SMTP id ks5-20020a056214310500b006966f594d19mr14917350qvb.1.1711553027130; Wed, 27 Mar 2024 08:23:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG/cvaZbNzejgmgOgxRck5pBSr/g3hsLSZETHWpBhBPVR+VZkVf7lYhXdSr9+e3t1xSA2Wfog== X-Received: by 2002:a05:6214:3105:b0:696:6f59:4d19 with SMTP id ks5-20020a056214310500b006966f594d19mr14917279qvb.1.1711553026413; Wed, 27 Mar 2024 08:23:46 -0700 (PDT) Received: from x1n.redhat.com ([99.254.121.117]) by smtp.gmail.com with ESMTPSA id hu4-20020a056214234400b00690dd47a41csm6412639qvb.86.2024.03.27.08.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 08:23:45 -0700 (PDT) From: peterx@redhat.com To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Yang Shi , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Michael Ellerman , peterx@redhat.com, Andrew Jones , Muchun Song , linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, Christophe Leroy , Andrew Morton , Christoph Hellwig , Lorenzo Stoakes , Matthew Wilcox , Rik van Riel , linux-arm-kernel@lists.infradead.org, Andrea Arcangeli , David Hildenbrand , "Aneesh Kumar K . V" , Vlastimil Babka , James Houghton , Jason Gunthorpe , Mike Rapoport , Axel Rasmussen Subject: [PATCH v4 05/13] mm/arch: Provide pud_pfn() fallback Date: Wed, 27 Mar 2024 11:23:24 -0400 Message-ID: <20240327152332.950956-6-peterx@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240327152332.950956-1-peterx@redhat.com> References: <20240327152332.950956-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 03A6218000F X-Stat-Signature: ybs43r9dpi1pwz89c3kmf6f3rwpgoth9 X-Rspam-User: X-HE-Tag: 1711553029-993992 X-HE-Meta: U2FsdGVkX19vQOgKu6hpk2rfz+V8IY/IkSFgaAruESuy7uxDBCpdyWfD5ZT3/pSysjTb/aP71hWTdSKOjinWEjHDRZdnUGC8S59+aybkDuXIfrQatXIOHXhGoz/qyP2wTmM9tOm7cM3aeyl2LQA8JhH21o6mJ0dmAmpR0oRBqpUnItDFtkePJprvUe2AhGijkbhnEx/QfdwCKysHMGeFbADrhC94lEmImBpcbWu1RJCwLXV9aP6sK2Sd1PE6cvr7diCXtmZQej9i0uBiaNPvLk1yLcaUSIF0HnZWpYVFXTuByngRqlGlwvsbT1wtoK8ktNQ5op81w+BfMNt0HTLkVCDh/nQB5SWkClALvRKgpFaa3wtwLPV0TUaXq2+yVaBschbpAGFSJlUBTWEiida0loSfQ1WzpFxa+97m7QSSfsYjFu8UcshuqXbJu0jU7RwJGtDrAVAxWEB34NOpg/QeThZtU8Xj7TtvafSEwDvgpxMdcbAhOriDjMSvMaECQ83P8zOSKERL/qHcH0GXM7iuBgv4i/Q9fesM/DcTQH0ZMWECv0jEdYSlADhNrNfTCz7hgt///T0HGCYWm9dzmDE8v8C86pE6d1eizMwBDWIpM8228EAczAhHLNjYJsbEv1rIJik2/dcIlmsii6ntv6Mg55wi/QW3YDjM6ty/QDOWnIfAe/e67JS4rSLJmsN+3xY+jKaIdCCYoszOqPUrJ+skH8our3i5Yh8A2VQmWJ8/mVNxEObLoP3kRVkMEMppW8XIjZ4OZVXuDK5VuBKY3zIweTX3Ky0u8q0xxhGYoq0psNcC4syRmJyxnf+UvY081uoLVSXuKxeQZ3+QDA/On7x0lcm4kp0RDYD0L8l0ed7D+twBQUiM58o9jII6whtv0Ei2Ng2BGlubrZNFfZCyNk7VglIujKRX85/Y5imQdh1RHUrUtan7ZlBMG++IX8qsHjpXQQnX0y7dsCRsr9RkHbO JAEmPYMZ Jp4M2HFe2ivKAI/3AtYniNHRnmapWWpcFACf2yWQ0tSPKV4CiSZavN+iXXgjh7bs1NDd7d4/iHwdM+IL0Kyp7/R5sbiNh6ZT/XWCDLE0V2uIp38DeY9tKjyEF4Cpu6olPOrljSIVK2EMFbvCaTZhwyilW5GSpWUVA48CfMC9N+rnSasFXT15Gk+Uo75GAKYltbdo78AG0F7OcqGFjGpnYDsyTRnIVIsMgzBs7pFQs9tcrAgCiBjW0p9kAA/4D0bns1MGs3l0sI3PflAD25pS0xaTCADNLf5z8xpbemXFh4+BVHNXpuvYd8IiN6jQ4kR92UzTMJzk2pJ2VoaPCe/TrDaDsNYI+GIA6cp0cayKtZLuDltEarMSGWadfqT7PJsw7IzwVk5aAEXbZMb1W7UNJ/9HFcTR0SeAMccpqGbovjacwU4PiSINcbb/IiGl60inq7Sa808AHekAyyVvggWSNu9klsSrc4An5qWZeqeeAwn7b13eyrwYgaycEUESxVsZhoD01yZ7ZzNCyTKKDFRCtbu0UuSaGqA0d22MxQODdaj8sCKORw5R5cvPFJ5blz8SxXqYTWOP/Jx5Vy1JO1Lq0NUcEAzWkysZhttELSvibJ1GGQy7Ck0M7YJW2Ew== 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: List-Subscribe: List-Unsubscribe: From: Peter Xu The comment in the code explains the reasons. We took a different approach comparing to pmd_pfn() by providing a fallback function. Another option is to provide some lower level config options (compare to HUGETLB_PAGE or THP) to identify which layer an arch can support for such huge mappings. However that can be an overkill. Cc: Mike Rapoport (IBM) Cc: Matthew Wilcox Reviewed-by: Jason Gunthorpe Signed-off-by: Peter Xu --- arch/riscv/include/asm/pgtable.h | 1 + arch/s390/include/asm/pgtable.h | 1 + arch/sparc/include/asm/pgtable_64.h | 1 + arch/x86/include/asm/pgtable.h | 1 + include/linux/pgtable.h | 10 ++++++++++ 5 files changed, 14 insertions(+) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 20242402fc11..0ca28cc8e3fa 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -646,6 +646,7 @@ static inline unsigned long pmd_pfn(pmd_t pmd) #define __pud_to_phys(pud) (__page_val_to_pfn(pud_val(pud)) << PAGE_SHIFT) +#define pud_pfn pud_pfn static inline unsigned long pud_pfn(pud_t pud) { return ((__pud_to_phys(pud) & PUD_MASK) >> PAGE_SHIFT); diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 1a71cb19c089..6cbbe473f680 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1414,6 +1414,7 @@ static inline unsigned long pud_deref(pud_t pud) return (unsigned long)__va(pud_val(pud) & origin_mask); } +#define pud_pfn pud_pfn static inline unsigned long pud_pfn(pud_t pud) { return __pa(pud_deref(pud)) >> PAGE_SHIFT; diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 4d1bafaba942..26efc9bb644a 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -875,6 +875,7 @@ static inline bool pud_leaf(pud_t pud) return pte_val(pte) & _PAGE_PMD_HUGE; } +#define pud_pfn pud_pfn static inline unsigned long pud_pfn(pud_t pud) { pte_t pte = __pte(pud_val(pud)); diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index cefc7a84f7a4..273f7557218c 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -234,6 +234,7 @@ static inline unsigned long pmd_pfn(pmd_t pmd) return (pfn & pmd_pfn_mask(pmd)) >> PAGE_SHIFT; } +#define pud_pfn pud_pfn static inline unsigned long pud_pfn(pud_t pud) { phys_addr_t pfn = pud_val(pud); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 600e17d03659..75fe309a4e10 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1817,6 +1817,16 @@ typedef unsigned int pgtbl_mod_mask; #define pte_leaf_size(x) PAGE_SIZE #endif +/* + * We always define pmd_pfn for all archs as it's used in lots of generic + * code. Now it happens too for pud_pfn (and can happen for larger + * mappings too in the future; we're not there yet). Instead of defining + * it for all archs (like pmd_pfn), provide a fallback. + */ +#ifndef pud_pfn +#define pud_pfn(x) ({ BUILD_BUG(); 0; }) +#endif + /* * Some architectures have MMUs that are configurable or selectable at boot * time. These lead to variable PTRS_PER_x. For statically allocated arrays it