From patchwork Fri Aug 9 16:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13758942 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 CD971C3DA4A for ; Fri, 9 Aug 2024 16:10:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 289A06B00B5; Fri, 9 Aug 2024 12:10:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 213476B00B6; Fri, 9 Aug 2024 12:10:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08E8C6B00B7; Fri, 9 Aug 2024 12:09:59 -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 C4BAC6B00B5 for ; Fri, 9 Aug 2024 12:09:59 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 790C681167 for ; Fri, 9 Aug 2024 16:09:59 +0000 (UTC) X-FDA: 82433193318.18.31182F8 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 6399E180032 for ; Fri, 9 Aug 2024 16:09:57 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DCqMayQp; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723219764; 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=YoGoBxg1RIhRUWN8551lXVuosUhfDUfYXVK/Rz8tB4Q=; b=sTrtgFCrrUANpMUrDpsFQM/tOlsncYDRTCU5AORBQoofRlbujcrGDhl77GBujKH4noCZmy BrfiU3nIX/o3xySKgZ5UBYospqr4m/J3M26GHl3d0kNJorAHkhE9nV92SzAXPFR0MbiVqU sp3zpBJXjnzgASB/leUmD7rDFkkz6Zo= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DCqMayQp; spf=pass (imf06.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723219764; a=rsa-sha256; cv=none; b=vbad3NU05rs+mDrO3g36L68kqUd0PiiuWsj3GGDGXucFIbtYruwWk2kGQ75ZZ8NPusFP+o CNyEBHVSERzGdx7UEy6PVx0VhkczQNKgdwHaM9ujWXmTQFoU+Wn5U+tRqQJXdgCCDmPUY6 kIJuSIO3r9XsHN+34kSybr0cW374sF0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1723219796; 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=YoGoBxg1RIhRUWN8551lXVuosUhfDUfYXVK/Rz8tB4Q=; b=DCqMayQpcVuHowf05xL+L7KKv4A/9fk/wXxHCwd/hJQqV9Cy05P4BPDCF5oa2ovdX0v6OK uFxM8f6uiW9v6oy9K9ifiCe4TYkk/f8Ji6uB3MI8nTOlIPU2nf9Z/xS9UaBMfaKcKEsDSI Qw70woQpQ9w8K/zBWCFkv7waYojf8Y0= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-687-I2RmvRsvOn-srxzu3sVoMg-1; Fri, 09 Aug 2024 12:09:54 -0400 X-MC-Unique: I2RmvRsvOn-srxzu3sVoMg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4503ee1b5d6so5447661cf.3 for ; Fri, 09 Aug 2024 09:09:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723219793; x=1723824593; 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=YoGoBxg1RIhRUWN8551lXVuosUhfDUfYXVK/Rz8tB4Q=; b=ZILmGWjb8SN+J9l2SY+l+9Q9fwrwshNq7ZQrXXZqWy5BaHGD0zSPBwh0EytquxpmVI SkWRUQ9O9mK26Pof3BHJT1dWPVOAR5Vf0YUTskbDjcU2+H/1gWuTYJDvgxvleutL3Nem Oon6SYmjPXrmCt/5IKm54Z/1zE2x/WoHOCftW2Hj4i49ipJ7Z1zEvWbn1VZoF39p1qGv aVaEw//oGSS9UigOfWJRHTBdomIHhIBFfRjivBOJdqKGybX38Gf9KWN1k3ms3OZXzvx8 /VI4EeeJZNi/R1I+GYI+dSGcQ9KC+pBB2jp8XKlyP9l9NyGaqwugpHRmjFl4hJv4QxS4 YR8Q== X-Gm-Message-State: AOJu0YwnPZVzflELRE1NfBD7Yno/E6sUsSPdSogMegNbNrl9p0HU/awh R0fixmxbyw/YSP08VTHLSWsKOymNQ9Bb4SOx9LCt1hJqN6FSs5ooICCxSy5sNsxc5gsG2pqgE9F dul+N8KmHkXL27lJeJcvjpohI6hMdp5SAFwDGRLzaiCzvZlGqonSE+02KIVuTubp8juISaW0FE6 9LdciAbGZfmNueNLz2EfoPo1gNEqim2/CS X-Received: by 2002:ac8:5e07:0:b0:44e:cff7:3741 with SMTP id d75a77b69052e-45312646da2mr14005871cf.7.1723219793423; Fri, 09 Aug 2024 09:09:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyC9JbjVCeQC7LVvckqh3sKVh2QUlZ0IzLJIVdarr6jR5vj53aOO53iHwQIsrAsjgq+0MAjA== X-Received: by 2002:ac8:5e07:0:b0:44e:cff7:3741 with SMTP id d75a77b69052e-45312646da2mr14005321cf.7.1723219792685; Fri, 09 Aug 2024 09:09:52 -0700 (PDT) Received: from x1n.redhat.com (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-451c870016csm22526741cf.19.2024.08.09.09.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Aug 2024 09:09:51 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Sean Christopherson , Oscar Salvador , Jason Gunthorpe , Axel Rasmussen , linux-arm-kernel@lists.infradead.org, x86@kernel.org, peterx@redhat.com, Will Deacon , Gavin Shan , Paolo Bonzini , Zi Yan , Andrew Morton , Catalin Marinas , Ingo Molnar , Alistair Popple , Borislav Petkov , David Hildenbrand , Thomas Gleixner , kvm@vger.kernel.org, Dave Hansen , Alex Williamson , Yan Zhao Subject: [PATCH 17/19] mm/x86: Support large pfn mappings Date: Fri, 9 Aug 2024 12:09:07 -0400 Message-ID: <20240809160909.1023470-18-peterx@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240809160909.1023470-1-peterx@redhat.com> References: <20240809160909.1023470-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd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P2X03m4p61/R9cLRodXV7ZJg7ZzOOVMgvArj5Gx8SBkJ7xkLb0nWcLpgys+mghAlJ47S+yO+1zscXjkQ6UqUxENBA1NcfqLMZtycmP9pA5fq44tZxgBokcZfYEaJiTy8w+metd8jvR9KSPyGjxCGUyD0UDRBJPwfbKTNweboEHQy3hE/ccMNXk3JyLD/bm8LswYuVwlGpmkrZJLqv9StmP6TWuT9d4ju2A45N1vUBOSjeV98Yp4EUuNZKF8yvUCuXGW5SeJNqA4vfS1+Mu9LG3U3960vaKwcICDtSciqF7Zonsw7vEPho5u9laXVrooAQUzOCUdzNgG10J0MtLvmqNHUveJxG1y4QHMMOzzdNC3Qt9cTXaoKnRUeFqjyD5YzfKbQckn3RbJOc/pxY1BZX0aYyzFYnYOQ/z8ATXLMZ+kdX6eGIMBnGIDj9U3nfo2SmN1Mza+lOe48D9IqJZSuD87W4+xRdSQkyyvCzknWbbyiG0ZEX44sZCAUkaaJgzw= 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: Helpers to install and detect special pmd/pud entries. In short, bit 9 on x86 is not used for pmd/pud, so we can directly define them the same as the pte level. One note is that it's also used in _PAGE_BIT_CPA_TEST but that is only used in the debug test, and shouldn't conflict in this case. One note is that pxx_set|clear_flags() for pmd/pud will need to be moved upper so that they can be referenced by the new special bit helpers. There's no change in the code that was moved. Cc: x86@kernel.org Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Signed-off-by: Peter Xu --- arch/x86/Kconfig | 1 + arch/x86/include/asm/pgtable.h | 80 ++++++++++++++++++++++------------ 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index acd9745bf2ae..7a3fb2ff3e72 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -28,6 +28,7 @@ config X86_64 select ARCH_HAS_GIGANTIC_PAGE select ARCH_SUPPORTS_INT128 if CC_HAS_INT128 select ARCH_SUPPORTS_PER_VMA_LOCK + select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE select HAVE_ARCH_SOFT_DIRTY select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index a7c1e9cfea41..1e463c9a650f 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -120,6 +120,34 @@ extern pmdval_t early_pmd_flags; #define arch_end_context_switch(prev) do {} while(0) #endif /* CONFIG_PARAVIRT_XXL */ +static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set) +{ + pmdval_t v = native_pmd_val(pmd); + + return native_make_pmd(v | set); +} + +static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear) +{ + pmdval_t v = native_pmd_val(pmd); + + return native_make_pmd(v & ~clear); +} + +static inline pud_t pud_set_flags(pud_t pud, pudval_t set) +{ + pudval_t v = native_pud_val(pud); + + return native_make_pud(v | set); +} + +static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear) +{ + pudval_t v = native_pud_val(pud); + + return native_make_pud(v & ~clear); +} + /* * The following only work if pte_present() is true. * Undefined behaviour if not.. @@ -317,6 +345,30 @@ static inline int pud_devmap(pud_t pud) } #endif +#ifdef CONFIG_ARCH_SUPPORTS_PMD_PFNMAP +static inline bool pmd_special(pmd_t pmd) +{ + return pmd_flags(pmd) & _PAGE_SPECIAL; +} + +static inline pmd_t pmd_mkspecial(pmd_t pmd) +{ + return pmd_set_flags(pmd, _PAGE_SPECIAL); +} +#endif /* CONFIG_ARCH_SUPPORTS_PMD_PFNMAP */ + +#ifdef CONFIG_ARCH_SUPPORTS_PUD_PFNMAP +static inline bool pud_special(pud_t pud) +{ + return pud_flags(pud) & _PAGE_SPECIAL; +} + +static inline pud_t pud_mkspecial(pud_t pud) +{ + return pud_set_flags(pud, _PAGE_SPECIAL); +} +#endif /* CONFIG_ARCH_SUPPORTS_PUD_PFNMAP */ + static inline int pgd_devmap(pgd_t pgd) { return 0; @@ -487,20 +539,6 @@ static inline pte_t pte_mkdevmap(pte_t pte) return pte_set_flags(pte, _PAGE_SPECIAL|_PAGE_DEVMAP); } -static inline pmd_t pmd_set_flags(pmd_t pmd, pmdval_t set) -{ - pmdval_t v = native_pmd_val(pmd); - - return native_make_pmd(v | set); -} - -static inline pmd_t pmd_clear_flags(pmd_t pmd, pmdval_t clear) -{ - pmdval_t v = native_pmd_val(pmd); - - return native_make_pmd(v & ~clear); -} - /* See comments above mksaveddirty_shift() */ static inline pmd_t pmd_mksaveddirty(pmd_t pmd) { @@ -595,20 +633,6 @@ static inline pmd_t pmd_mkwrite_novma(pmd_t pmd) 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); - - return native_make_pud(v | set); -} - -static inline pud_t pud_clear_flags(pud_t pud, pudval_t clear) -{ - pudval_t v = native_pud_val(pud); - - return native_make_pud(v & ~clear); -} - /* See comments above mksaveddirty_shift() */ static inline pud_t pud_mksaveddirty(pud_t pud) {