From patchwork Thu Jul 4 04:31:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723191 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 6F318C3271F for ; Thu, 4 Jul 2024 04:32:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA4856B00A0; Thu, 4 Jul 2024 00:32:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E22166B00A2; Thu, 4 Jul 2024 00:32:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C275A6B00A3; Thu, 4 Jul 2024 00:32:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A18FE6B00A0 for ; Thu, 4 Jul 2024 00:32:09 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5ABC0140AE0 for ; Thu, 4 Jul 2024 04:32:09 +0000 (UTC) X-FDA: 82300797978.21.FFB02E1 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf19.hostedemail.com (Postfix) with ESMTP id 51ACD1A000A for ; Thu, 4 Jul 2024 04:32:07 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067515; 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:in-reply-to:references:references; bh=jzvOqBRe34To4ICfaNP1mlZ4ayS8DrUPt1kh2NpZYUg=; b=gvPbhfttdhjaOAxb8qWQrvClTCS+GJBabjv2GEZxpvWPpi/xU5GVEbJMxvHz3Q7zzW0Yw/ f21PSzJAXx7ede4lg7keSrDhcEYkQ0UUnd0EVn8Rp52kyM3+QI/WoflSDig+RcuDHaVPez jbcPtSKtL5lprtdDggL9TJfcP4cXOyc= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; spf=pass (imf19.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067515; a=rsa-sha256; cv=none; b=Y5vs3/7vs2WqasENWxXlVHM9bwEvlEThjoHj3m49iT/gJbNryIgeklx5j6aUfiFIZGzn4j abF/7rQlw9LL3reBmhnF/8Gm0Z19XIVgBray4JdMKLixqRRsSRNE6E/TlzUbPM6S180MpD n0gfptWCLwxUboYb6LscInS6atqSjOY= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 2DFBF1FCF9; Thu, 4 Jul 2024 04:32:06 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id EC78E13889; Thu, 4 Jul 2024 04:32:04 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id MJ1iNMQlhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:04 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 13/45] mm: Implement pud-version uffd functions Date: Thu, 4 Jul 2024 06:31:00 +0200 Message-ID: <20240704043132.28501-14-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 51ACD1A000A X-Stat-Signature: aqp9jxrmzqmznwsni9hjazcasanqj33e X-HE-Tag: 1720067527-562181 X-HE-Meta: U2FsdGVkX19KdIAbe6juUsB55gcaZ/vw/220g60Ls6wSxarMNgagkbK3wSPyUh+ByqE2QvSDEXhrB9JHuy4hPIRDJDfBFty2nJMjybk4GjJrVbBD1b7uc8drPZb320VfSogHb24VbCcKw4GlFzbt3H5vkBNPecQzUEH4Gpe5QRnqQQDfvmAp27hlKTO0QZRVlMoNOO9RraT/yF3qUKy0oB4HRUlNDOe0lm9I8diS/uYd24T0Ynpxh0Wb2tiZLgHsfWJVZL10F5kD05O5SPngtB2ASljR2sY+OtbAkDpZD1Wv/xzF7j2ET114cHvlZdFeKlkIDMVABKY4nparu61KhuQyQgIFPGWhAud9qUXJWHXOJKtscMx/TLVlVgHsLLQOWSHQTdM/PLnRtNAfNt7Jn+nHdL3N5A0QPvfFSMeVmK2NayfUk42/boXeWFrD3DuJnGoKL3sdEqDDtb5rxR6IGlW8dWPaKeCPOdV4nnje85M4UFXAOU5twrat7UawFrJYUBm5xnkZ9AXJC7KcRTEigXRLg0X1Q8bLljmjSd3IzQPaePPgp+WjmFlCSVsxtrBS3p07vkX/3c+yPjUk+lOPiFn4ayEGH0T3xtIv7wYw1bjTHQDFl6OrhBSiYMUyqGLAR65hKp27Nlx/cSdPAwUCl2eANTvWM9cl5RYhMOsPjqTrG2MOJRpm4j6AJut8YuaGklxadkvnzi1RfYiHWdnlMWFlKXREDQmtl2rxjvy4HkVIL3iW9nG8dlELVs4CbJL1rv8+JbhBH91VoCO6uC75dVS4nVZUV9divsWVJgyWBlKq/t6Kg96CxSnnCUBMTaa21ii8dN70SFbRj8m2Sy5/JUlnutN4Hhd/Izuxy3ZIXMbNfU3ADlxqE1EPwzUtIALe4Q59JM60U1XxwTNFlQxbGlqiAxK4tWFoFxvTY0j3d+ei2lK+Nr9/ct8YbNXvG92OlR679eLvC6ie3eQQSCF 8xYw3MUR N1wDyY22RA+B0kFgIvHVrB5wyC0bjxwISIpctfpmPgK4v6xCuHiKwYItIWSoVmB4yTn5ee4zShI6R2bm4mTirqqg/qnv/KzvspQXTaNCWW4WT8RF6hZP4stZYH+buyDAbIqj+ 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: HugeTLB pages will be handled on pud level as well, so we need to implement pud-versions of uffd functions in order to properly handle it. Signed-off-by: Oscar Salvador --- arch/arm64/include/asm/pgtable.h | 7 ++ arch/x86/include/asm/pgtable.h | 158 +++++++++++++++++------------ include/asm-generic/pgtable_uffd.h | 30 ++++++ include/linux/pgtable.h | 5 + 4 files changed, 136 insertions(+), 64 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index f8efbc128446..936ed3a915a3 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -556,6 +556,9 @@ static inline int pmd_trans_huge(pmd_t pmd) #define pmd_mkyoung(pmd) pte_pmd(pte_mkyoung(pmd_pte(pmd))) #define pmd_mkinvalid(pmd) pte_pmd(pte_mkinvalid(pmd_pte(pmd))) #ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP +#define pud_uffd_wp(pud) pte_uffd_wp(pud_pte(pud)) +#define pud_mkuffd_wp(pud) pte_pud(pte_mkuffd_wp(pud_pte(pud))) +#define pud_clear_uffd_wp(pud) pte_pud(pte_clear_uffd_wp(pud_pte(pud))) #define pmd_uffd_wp(pmd) pte_uffd_wp(pmd_pte(pmd)) #define pmd_mkuffd_wp(pmd) pte_pmd(pte_mkuffd_wp(pmd_pte(pmd))) #define pmd_clear_uffd_wp(pmd) pte_pmd(pte_clear_uffd_wp(pmd_pte(pmd))) @@ -563,6 +566,10 @@ static inline int pmd_trans_huge(pmd_t pmd) #define pmd_swp_mkuffd_wp(pmd) pte_pmd(pte_swp_mkuffd_wp(pmd_pte(pmd))) #define pmd_swp_clear_uffd_wp(pmd) \ pte_pmd(pte_swp_clear_uffd_wp(pmd_pte(pmd))) +#define pud_swp_uffd_wp(pud) pte_swp_uffd_wp(pud_pte(pud)) +#define pud_swp_mkuffd_wp(pud) pte_pud(pte_swp_mkuffd_wp(pud_pte(pud))) +#define pud_swp_clear_uffd_wp(pud) \ + pte_pud(pte_swp_clear_uffd_wp(pud_pte(pud))) #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ #define pmd_write(pmd) pte_write(pmd_pte(pmd)) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 772f778bac06..640edc31962f 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -512,70 +512,6 @@ static inline pmd_t pmd_wrprotect(pmd_t pmd) return pmd_mksaveddirty(pmd); } -#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP -static inline int pmd_uffd_wp(pmd_t pmd) -{ - return pmd_flags(pmd) & _PAGE_UFFD_WP; -} - -static inline pmd_t pmd_mkuffd_wp(pmd_t pmd) -{ - return pmd_wrprotect(pmd_set_flags(pmd, _PAGE_UFFD_WP)); -} - -static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd) -{ - return pmd_clear_flags(pmd, _PAGE_UFFD_WP); -} -#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ - -static inline pmd_t pmd_mkold(pmd_t pmd) -{ - return pmd_clear_flags(pmd, _PAGE_ACCESSED); -} - -static inline pmd_t pmd_mkclean(pmd_t pmd) -{ - return pmd_clear_flags(pmd, _PAGE_DIRTY_BITS); -} - -static inline pmd_t pmd_mkdirty(pmd_t pmd) -{ - pmd = pmd_set_flags(pmd, _PAGE_DIRTY | _PAGE_SOFT_DIRTY); - - return pmd_mksaveddirty(pmd); -} - -static inline pmd_t pmd_mkwrite_shstk(pmd_t pmd) -{ - pmd = pmd_clear_flags(pmd, _PAGE_RW); - - return pmd_set_flags(pmd, _PAGE_DIRTY); -} - -static inline pmd_t pmd_mkdevmap(pmd_t pmd) -{ - return pmd_set_flags(pmd, _PAGE_DEVMAP); -} - -static inline pmd_t pmd_mkhuge(pmd_t pmd) -{ - return pmd_set_flags(pmd, _PAGE_PSE); -} - -static inline pmd_t pmd_mkyoung(pmd_t pmd) -{ - return pmd_set_flags(pmd, _PAGE_ACCESSED); -} - -static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) -{ - return pmd_set_flags(pmd, _PAGE_RW); -} - -pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma); -#define pmd_mkwrite pmd_mkwrite - static inline pud_t pud_set_flags(pud_t pud, pudval_t set) { pudval_t v = native_pud_val(pud); @@ -659,6 +595,85 @@ static inline pud_t pud_mkwrite(pud_t pud) return pud_clear_saveddirty(pud); } +#ifdef CONFIG_HAVE_ARCH_USERFAULTFD_WP +static inline int pud_uffd_wp(pud_t pud) +{ + return pud_flags(pud) & _PAGE_UFFD_WP; +} + +static inline pud_t pud_mkuffd_wp(pud_t pud) +{ + return pud_wrprotect(pud_set_flags(pud, _PAGE_UFFD_WP)); +} + +static inline pud_t pud_clear_uffd_wp(pud_t pud) +{ + return pud_clear_flags(pud, _PAGE_UFFD_WP); +} + +static inline int pmd_uffd_wp(pmd_t pmd) +{ + return pmd_flags(pmd) & _PAGE_UFFD_WP; +} + +static inline pmd_t pmd_mkuffd_wp(pmd_t pmd) +{ + return pmd_wrprotect(pmd_set_flags(pmd, _PAGE_UFFD_WP)); +} + +static inline pmd_t pmd_clear_uffd_wp(pmd_t pmd) +{ + return pmd_clear_flags(pmd, _PAGE_UFFD_WP); +} +#endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ + +static inline pmd_t pmd_mkold(pmd_t pmd) +{ + return pmd_clear_flags(pmd, _PAGE_ACCESSED); +} + +static inline pmd_t pmd_mkclean(pmd_t pmd) +{ + return pmd_clear_flags(pmd, _PAGE_DIRTY_BITS); +} + +static inline pmd_t pmd_mkdirty(pmd_t pmd) +{ + pmd = pmd_set_flags(pmd, _PAGE_DIRTY | _PAGE_SOFT_DIRTY); + + return pmd_mksaveddirty(pmd); +} + +static inline pmd_t pmd_mkwrite_shstk(pmd_t pmd) +{ + pmd = pmd_clear_flags(pmd, _PAGE_RW); + + return pmd_set_flags(pmd, _PAGE_DIRTY); +} + +static inline pmd_t pmd_mkdevmap(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_DEVMAP); +} + +static inline pmd_t pmd_mkhuge(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_PSE); +} + +static inline pmd_t pmd_mkyoung(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_ACCESSED); +} + +static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_RW); +} + +pmd_t pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma); +#define pmd_mkwrite pmd_mkwrite + #ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY static inline int pte_soft_dirty(pte_t pte) { @@ -1574,6 +1589,21 @@ static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd) { return pmd_clear_flags(pmd, _PAGE_SWP_UFFD_WP); } + +static inline pud_t pud_swp_mkuffd_wp(pud_t pud) +{ + return pud_set_flags(pud, _PAGE_SWP_UFFD_WP); +} + +static inline int pud_swp_uffd_wp(pud_t pud) +{ + return pud_flags(pud) & _PAGE_SWP_UFFD_WP; +} + +static inline pud_t pud_swp_clear_uffd_wp(pud_t pud) +{ + return pud_clear_flags(pud, _PAGE_SWP_UFFD_WP); +} #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ static inline u16 pte_flags_pkey(unsigned long pte_flags) diff --git a/include/asm-generic/pgtable_uffd.h b/include/asm-generic/pgtable_uffd.h index 828966d4c281..453118eb2161 100644 --- a/include/asm-generic/pgtable_uffd.h +++ b/include/asm-generic/pgtable_uffd.h @@ -12,6 +12,11 @@ static __always_inline int pmd_uffd_wp(pmd_t pmd) return 0; } +static __always_inline int pud_uffd_wp(pud_t pud) +{ + return 0; +} + static __always_inline pte_t pte_mkuffd_wp(pte_t pte) { return pte; @@ -22,6 +27,11 @@ static __always_inline pmd_t pmd_mkuffd_wp(pmd_t pmd) return pmd; } +static __always_inline pud_t pud_mkuffd_wp(pud_t pud) +{ + return pmd; +} + static __always_inline pte_t pte_clear_uffd_wp(pte_t pte) { return pte; @@ -32,6 +42,11 @@ static __always_inline pmd_t pmd_clear_uffd_wp(pmd_t pmd) return pmd; } +static __always_inline pud_t pud_clear_uffd_wp(pud_t pud) +{ + return pmd; +} + static __always_inline pte_t pte_swp_mkuffd_wp(pte_t pte) { return pte; @@ -61,6 +76,21 @@ static inline pmd_t pmd_swp_clear_uffd_wp(pmd_t pmd) { return pmd; } + +static inline pud_t pud_swp_mkuffd_wp(pud_t pud) +{ + return pud; +} + +static inline int pud_swp_uffd_wp(pud_t pud) +{ + return 0; +} + +static inline pud_t pud_swp_clear_uffd_wp(pud_t pud) +{ + return pud; +} #endif /* CONFIG_HAVE_ARCH_USERFAULTFD_WP */ #endif /* _ASM_GENERIC_PGTABLE_UFFD_H */ diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 991137dab87e..a2e2ebb93f21 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1433,6 +1433,11 @@ static inline int pmd_soft_dirty(pmd_t pmd) return 0; } +static inline int pud_soft_dirty(pud_t pud) +{ + return 0; +} + static inline pte_t pte_mksoft_dirty(pte_t pte) { return pte;