From patchwork Thu Oct 3 04:48:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13820664 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 6D737CF31BA for ; Thu, 3 Oct 2024 04:48:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B73A26B02AD; Thu, 3 Oct 2024 00:48:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B21A56B02B7; Thu, 3 Oct 2024 00:48:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E8DB6B02B8; Thu, 3 Oct 2024 00:48:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 704C86B02AD for ; Thu, 3 Oct 2024 00:48:54 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id CA33140B9F for ; Thu, 3 Oct 2024 04:48:53 +0000 (UTC) X-FDA: 82631060946.01.4FFF003 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf12.hostedemail.com (Postfix) with ESMTP id 4F97E4000A for ; Thu, 3 Oct 2024 04:48:51 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727930866; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=gyW0hNCdL2BoDBC+MG8HwOYt5F+biRYDpp2Uqa4frMo=; b=B0/TIpWPUw8NYDk8vuck36MRBDWKKy9XhB0kZQoo0fs17wiH4EkYddlEkeSW7zEbqBKMSn xFrN9ycFSyXBfImmyjxns28mkcW4p5GtKVBL6BwazAdlyHYLuLKZiwX5cW4ou9MI8p9j+y ufgCTbt0yZJ9hDxQcGYfHWbMj/W9TYY= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of anshuman.khandual@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=anshuman.khandual@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727930866; a=rsa-sha256; cv=none; b=jMmxqGbmxS7nb3O9+iOnjL88I6RRmKF495z461GZWIPunXnxR7sIzyswtCaoAncsSHgYl9 V3Aqq/n9vrWKd7uLIWbn+ZzSrpg/D2noB2FNUy5wGDsMRuB0LzR2nmd4yBrSynPHzaoUnC 8NMX6p70buOAnZxhEPRIogsACP9tSvk= Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D8AC4339; Wed, 2 Oct 2024 21:49:19 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.37.202]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 90A133F64C; Wed, 2 Oct 2024 21:48:45 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org, akpm@linux-foundation.org, paul.walmsley@sifive.com, dave.hansen@linux.intel.com Cc: Anshuman Khandual , Palmer Dabbelt , Thomas Gleixner , David Hildenbrand , Ryan Roberts , x86@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [RESEND PATCH] mm: Move set_pxd_safe() helpers from generic to platform Date: Thu, 3 Oct 2024 10:18:42 +0530 Message-Id: <20241003044842.246016-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 4F97E4000A X-Stat-Signature: us9gd5a7o8tjztqrdw5cw7mzcoshp4gx X-HE-Tag: 1727930931-747996 X-HE-Meta: U2FsdGVkX1+DxjuXt/pd2zpoyjKWCtyLdKJ+dbKf3CGxs629ghYBP4vaRHEn6OMXax/t5M21Irtm8mqwsNsD5LGWUetMuY8/BrVYpnUoYBXkkfAp3fsBl/8W3XPJiyWLq6XlCSvL0RZTY38sU9pzTIsCDHRN9Gioa6G0e1/CLP7q1shg6plJI3RnZhQtjSlNCteMYfJRCsdSYHJC9hghaDyLqfvLGmwdec45jOFnJ+KwKXWvkcBPVrONLtoXYzw7oCs1WjxfdCvdRNMV2fUak5TEzCZgOWlxJY6JbixMD2EtTrcQMmQKft1vwFDvCYibF+AgEFbST3CFB+drzyFZoA+Q3PE+l8Kr0nRv3TZuRAXOIDqKBbDYjtRBkWUZTjG9JVok+mwtXoJ7xD2QFIUk1YOY8cVQ/F9zjLN0bEnnawIPoGhN4nTPht+GjwwH79IZOPnf5DCAEAVdy2OxYJAfSHD35oD+TD8BKP8txSokNxgez6YuNTxLDbXvdpV3WfpF0/huDGvbhqb3UMD9F8ul4Myr6OK3Vv0Mi0MQAK6f9ZjfDoWxSNUOxZWhZIVutFwPWv9ytcyqyOJLnaZwz8hp5LdAlGsdaSKXHuRX47y10xwWDFC24/6606Q/yj43tK7YS0hTJqh7wmeEZxi7N301L7YZvoVxo8aIP+Hq9AC2M1FujTVYxYLV67Py1IdnjvzZC7GiFgJq7tXB80cEunhBAtr7PVow1mbSPxWV9AQ0iFyB1xP8k3afTTgA0B3FTK3Iz1aB5AHOgYI34brXhyWqtNYs+fPppLOofkZA1JMuPCAaHSTW053x/jeQVI7ABhdkRspVcWJxnlzGNVcxYLE1LUMGKHNyoBRhngJ+4+lB/A15OyNvdbn6as/4yyzBCDrywfGxGYd8ZxGQpbGThGnTxJqo18ScoX2T7ean0GZxRVpxUbHD0Gb/doE9ZFNxLu72qwAp98dKZVhi9aO6QvS I73w0JW/ 5ngH1hG2uDsK4u/jFf5xmFKeDCATdc6px/Hkr9kvBDqC4hIQisURC2Q74aZw0WlOo39CQKPa1DQvuHcr2ueAvJq+aeNqBb+ZHkBMa/PpSfLelsazIQ7uCSoqHWwA2dklsJONtGhqj36GDgD9yrGNz5cC7w9w71s76I0exT22aOzxohOIPLk69OE64AA7oZs8aSEQO2iMY+2jJ9NEhBy4PI/HGn4SSiIWdwgjPXUNoU53Gjt3R52ElFEnnoNChG2Fec28Zo/p70RHifUFNHOEhUadN4Y0ffyQt7JzJEV6mKAm1Imw2m9ntGgDC1J8Jx1q1KY3yfpbu3mHUc85bkevFGZbvaNySls/Pja369WbSEoCxJBEZb17auTgdNexBDY56VEgekcv2EkoRSqnqOjtHACqYZc2uw0pRI8YIXs5mJNIjbn1Jdu8bZEjeR0dRFfey/3koS66siWr4icYe6cGhPeAs5q0pjmaoAEXw3pQGPcRZ0W2t4rjrkt2jG/odKoo3WgY9cYoF7DQ8ShfuFjf/QOVpyu9Qyvv3Xux7z9DW8kj4gRb6MsQ9vbTcKpqJrUH8tJ6Q 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: set_pxd_safe() helpers that serve a specific purpose for both x86 and riscv platforms, do not need to be in the common memory code. Otherwise they just unnecessarily make the common API more complicated. This moves the helpers from common code to platform instead. Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Thomas Gleixner Cc: Dave Hansen Cc: David Hildenbrand Cc: Ryan Roberts Cc: Andrew Morton Cc: x86@kernel.org Cc: linux-mm@kvack.org Cc: linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org Suggested-by: David Hildenbrand Signed-off-by: Anshuman Khandual Acked-by: Dave Hansen Acked-by: David Hildenbrand --- This patch applies on v6.12-rc1 This patch is just a resend for an earlier patch https://lore.kernel.org/all/20240920053017.2514920-1-anshuman.khandual@arm.com/ arch/riscv/include/asm/pgtable.h | 19 ++++++++++++++++ arch/x86/include/asm/pgtable.h | 37 +++++++++++++++++++++++++++++++ include/linux/pgtable.h | 38 -------------------------------- 3 files changed, 56 insertions(+), 38 deletions(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index e79f15293492..5d7f3e8c2e50 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -963,6 +963,25 @@ void misc_mem_init(void); extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) +/* + * Use set_p*_safe(), and elide TLB flushing, when confident that *no* + * TLB flush will be required as a result of the "set". For example, use + * in scenarios where it is known ahead of time that the routine is + * setting non-present entries, or re-setting an existing entry to the + * same value. Otherwise, use the typical "set" helpers and flush the + * TLB. + */ +#define set_p4d_safe(p4dp, p4d) \ +({ \ + WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ + set_p4d(p4dp, p4d); \ +}) + +#define set_pgd_safe(pgdp, pgd) \ +({ \ + WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ + set_pgd(pgdp, pgd); \ +}) #endif /* !__ASSEMBLY__ */ #endif /* _ASM_RISCV_PGTABLE_H */ diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 4c2d080d26b4..593f10aabd45 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1775,6 +1775,43 @@ bool arch_is_platform_page(u64 paddr); #define arch_is_platform_page arch_is_platform_page #endif +/* + * Use set_p*_safe(), and elide TLB flushing, when confident that *no* + * TLB flush will be required as a result of the "set". For example, use + * in scenarios where it is known ahead of time that the routine is + * setting non-present entries, or re-setting an existing entry to the + * same value. Otherwise, use the typical "set" helpers and flush the + * TLB. + */ +#define set_pte_safe(ptep, pte) \ +({ \ + WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ + set_pte(ptep, pte); \ +}) + +#define set_pmd_safe(pmdp, pmd) \ +({ \ + WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ + set_pmd(pmdp, pmd); \ +}) + +#define set_pud_safe(pudp, pud) \ +({ \ + WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ + set_pud(pudp, pud); \ +}) + +#define set_p4d_safe(p4dp, p4d) \ +({ \ + WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ + set_p4d(p4dp, p4d); \ +}) + +#define set_pgd_safe(pgdp, pgd) \ +({ \ + WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ + set_pgd(pgdp, pgd); \ +}) #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_PGTABLE_H */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index e8b2ac6bd2ae..23aeffd89a4e 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1056,44 +1056,6 @@ static inline int pgd_same(pgd_t pgd_a, pgd_t pgd_b) } #endif -/* - * Use set_p*_safe(), and elide TLB flushing, when confident that *no* - * TLB flush will be required as a result of the "set". For example, use - * in scenarios where it is known ahead of time that the routine is - * setting non-present entries, or re-setting an existing entry to the - * same value. Otherwise, use the typical "set" helpers and flush the - * TLB. - */ -#define set_pte_safe(ptep, pte) \ -({ \ - WARN_ON_ONCE(pte_present(*ptep) && !pte_same(*ptep, pte)); \ - set_pte(ptep, pte); \ -}) - -#define set_pmd_safe(pmdp, pmd) \ -({ \ - WARN_ON_ONCE(pmd_present(*pmdp) && !pmd_same(*pmdp, pmd)); \ - set_pmd(pmdp, pmd); \ -}) - -#define set_pud_safe(pudp, pud) \ -({ \ - WARN_ON_ONCE(pud_present(*pudp) && !pud_same(*pudp, pud)); \ - set_pud(pudp, pud); \ -}) - -#define set_p4d_safe(p4dp, p4d) \ -({ \ - WARN_ON_ONCE(p4d_present(*p4dp) && !p4d_same(*p4dp, p4d)); \ - set_p4d(p4dp, p4d); \ -}) - -#define set_pgd_safe(pgdp, pgd) \ -({ \ - WARN_ON_ONCE(pgd_present(*pgdp) && !pgd_same(*pgdp, pgd)); \ - set_pgd(pgdp, pgd); \ -}) - #ifndef __HAVE_ARCH_DO_SWAP_PAGE static inline void arch_do_swap_page_nr(struct mm_struct *mm, struct vm_area_struct *vma,