From patchwork Fri Sep 20 05:30:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anshuman Khandual X-Patchwork-Id: 13808138 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 DC6FBCF58CD for ; Fri, 20 Sep 2024 05:30:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5A9756B0085; Fri, 20 Sep 2024 01:30:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 532E06B0088; Fri, 20 Sep 2024 01:30:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FB166B0089; Fri, 20 Sep 2024 01:30:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 20A7A6B0085 for ; Fri, 20 Sep 2024 01:30:30 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 97964811D4 for ; Fri, 20 Sep 2024 05:30:29 +0000 (UTC) X-FDA: 82583991378.02.E6CBF08 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf05.hostedemail.com (Postfix) with ESMTP id 16F37100002 for ; Fri, 20 Sep 2024 05:30:26 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.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=1726810112; 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=hT/ttVF15PEvWvFE4Jmojx2NOyfoJ3JXnWAMwy45gG0=; b=mWLKN9grl2p7+erktZ7sh2XHe9p38bv5X06QzwtCuK0YmQY7E3bKQDrnZUhTMgLpvNDqN8 61mQvwuENlQejZF+FoAdVT2f2cDvYhWGnhnOPJfN//T8cSaU9BiXgJW1XS9rFqPy6aDRjx wKfLepZKpbBnt7297VV55pCt7j99nek= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1726810112; a=rsa-sha256; cv=none; b=rfnK/vrs6FK2Vu+KU82JKatr+1Y/aWX0bS4t4jtVSJJs1vd/wrjmIY5OjqYjFEhuUcwgUb /4kTdqgp7cBWLov8FQJKtQHsEqZ/vz0Vyw7Ib/KE/B3dO4EqxL/Kx5ljkqu+8TNTwzVMOi 08CqtRzxP7tfJJWx2mGjlLEaLFO0rFE= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.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 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 A223AFEC; Thu, 19 Sep 2024 22:30:55 -0700 (PDT) Received: from a077893.arm.com (unknown [10.163.35.184]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id EFA933F66E; Thu, 19 Sep 2024 22:30:21 -0700 (PDT) From: Anshuman Khandual To: linux-mm@kvack.org, akpm@linux-foundation.org Cc: Anshuman Khandual , Paul Walmsley , Palmer Dabbelt , Thomas Gleixner , Dave Hansen , David Hildenbrand , Ryan Roberts , x86@kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] mm: Move set_pxd_safe() helpers from generic to platform Date: Fri, 20 Sep 2024 11:00:17 +0530 Message-Id: <20240920053017.2514920-1-anshuman.khandual@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: h13fxny9aqg4d7j5ct8yuzirsomyx5of X-Rspamd-Queue-Id: 16F37100002 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1726810226-209117 X-HE-Meta: U2FsdGVkX1+cWe9WrFMjhrwutfheKCcbUJDpdByENXUgQpkZAKhELgVOPW5+1CBuRvBHRml1CvgqhddrPyRbMoZR0iS66+FWQgdZn252IRidZXqx5rh/wL4bb+SVPFNHo8SnfugJ95x20KkT2DEpiVmzuV/zLkBABw92txbmnjX1dbTgtTzelFPBeFmKEMS8btGkyUoVSJtwBBlKibiHHtFWWEFHsDdGWnT1AijxvnjLrtFGgl8olmW/L20WkCKCUEloih3b4UxZYuRskaHMGKP4/e9AnzF+rKrgRKGcwspVdLycfglbwnNJBKEx3nVXJxLyqDpmoB2FwA8dN2DSiJ9NlCWF2qomzHWOAagZhKscibjh9unqjQG0gcz6g6wk7by8dAeJPdxxCn23PkoloIeWYDcR5Y6n+gxNlTWr3JHMBejjWJPm5IAGgXH/bafHaimbJAJGCLu9KiEXtldvqfL/aqWoZrjQW2mqT7rwqDsW5s9+7M5vZIvTN4PxqEk9qtEi6bCC2U0+A3/t3xMGOK7pi3jFV+8Cj46c/Te5imhDNFfIMcPi1IjyccnSkho1/BDA/tbeTbTqH8aIodOGzWbCQWPGwqFKgWzqz2esZ/Lrgj9S8QH4EtRUhA+2sdHYYfdWckhWwS8MeLOgrf3Dt5/X932h+FPsPYABzxALGcUqrF1HK+QLrtN+/IEOGSCG5zVz5r3wjVL7Rb0OniRJ9SspBaPYvspKNuDo3UzWr1/WdTzlZQczYKb91X0fTB9soM5q84XmAfBs9sKHTl8I+KwLmpSQ3lmQgMGKN3odGTWBgC0NbiaVwffIEMP5HuEuiquAsqOKEO4JKtve4ZKWkg73aUPwxto1B6mrfdZlJ5Gf6RWgmJeZQYwjlq9vCp3ZiU4SVgBxz1FNe5c30QOBKOrGSFkum91eLLC5obSIyi6S762AqdINSCa7E/6sl6d3bhVaSDxM4mp/M/PNwQ6 BJ6dId80 x+v3T6+Lyre+FdiHVWo5uqMoj/uqF/APH0DagKI06Labc3nMwivw/Q9BkXmw2GVFXIPFQuKXAwA6UWc7NU7Nlh43G6VGgyOf6BFTpeeq4SJTOBPp3YocK3C/PGbzu/lW12d3iy1hPSFE/Js85JNbgZVB2co4ktfQ6D7nkio1Z6tXj94dkJltpEsMkFJRIy+hhY280wRhyzHgImhOX/8IGPoY77hpTMurnge92dwONJrlJvHnfSeP2PtXUlzD+16pO0uDkgtbANS+b3PAf2y5UsPIYr6W55oTJcYWecR7+dtkYKjg66jpN8U0ZIt8IQtu7Z2E3kwiSVXh7vp9kD7j1Ihdr3BM3JwETyE2lYA3RdXo5eMBCU7PIlyJsV+5q5XxhQs4OidElL1YrARcmiYmC3kk/baBVI/If8+Eq6EHCIoMVKukjzDlOl7rUWJg+e1B8N/ckhg6TbylBLnfluWBnGkKTJzYJYdpYBgWdbrPMKa8X/v3lzSdnO3tXHS+8v7BXbz6MDbiDDuxzgGPKfrdcF8gVfW8MwjPRVogBx2a1yt2ucALA56Afwjiy8iDidzOa2i38 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 --- 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 089f3c9f56a3..39ca652c5ebe 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -957,6 +957,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 e39311a89bf4..fefb52bb6b4d 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1701,6 +1701,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 2a6a3cccfc36..0bf88e505aad 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1050,44 +1050,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,