From patchwork Fri Jan 13 17:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101262 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 CE490C54EBE for ; Fri, 13 Jan 2023 17:13:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A60F900005; Fri, 13 Jan 2023 12:13:53 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 62F2B8E0001; Fri, 13 Jan 2023 12:13:53 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A901900005; Fri, 13 Jan 2023 12:13:53 -0500 (EST) 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 3B1D58E0001 for ; Fri, 13 Jan 2023 12:13:53 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1BD5EAB1B8 for ; Fri, 13 Jan 2023 17:13:53 +0000 (UTC) X-FDA: 80350423146.22.7873266 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf19.hostedemail.com (Postfix) with ESMTP id 96CFE1A0006 for ; Fri, 13 Jan 2023 17:13:50 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JSBuV3Lc; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@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=1673630030; 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:dkim-signature; bh=bmpIeZUQPW93vOhFIi7U44xqWezjAAUM6rotNAYg4/I=; b=rB+Od6e41MRS9xlP55Sy4T76xvBH+unWHcNaw3Qapz94FTOQhL+IMtLnIOLUWkcHpWRZgE k1P6vZ5nB/GUFqMgWy9IQJw62LWfV7ehbSI6bpgCQUavO9+3tzxZevpsZ2cNuinGjkZFah FbyqPk/pVIuUlc+C5w4ZVsVUNXRHwlk= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JSBuV3Lc; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673630030; a=rsa-sha256; cv=none; b=uP1UoWK5rKom6MgAj8xaFx9B7w/U9i9jLSTVDLOMA9Rz0sBtb114Ey/h18NNpmzZxiyXnN xpnia64KRC7de2OReRoI9QMfDFE2R9l8Lmdm3UHg/gOIpn/2fYk/UiJS9C912xKk6HRGJ3 QSokltvPGDQXMjvORmOhy2xDNB9LasU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673630030; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmpIeZUQPW93vOhFIi7U44xqWezjAAUM6rotNAYg4/I=; b=JSBuV3LcEZ87OGB45l2Ov7cAJfWEhDbsa624vU0PECfp29+Jw/MlHy1xguT0KUhhZfy9Uw oKzvS2N6OBs9KE0xqM+7v0OWcq/lU2jGvQlyh1q9p5r19Pj8AXWG9d1IODt8gO5X6tvbut 12J+V9KLR1vYyJDhA/9ynjTuCQShCNo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-221-_4owQC4lN0aWG8hTOfvPjQ-1; Fri, 13 Jan 2023 12:13:46 -0500 X-MC-Unique: _4owQC4lN0aWG8hTOfvPjQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 427DA101A52E; Fri, 13 Jan 2023 17:13:45 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id E323740C2064; Fri, 13 Jan 2023 17:13:37 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: Andrew Morton , Hugh Dickins , John Hubbard , Jason Gunthorpe , Mike Rapoport , Yang Shi , Vlastimil Babka , Nadav Amit , Andrea Arcangeli , Peter Xu , linux-mm@kvack.org, x86@kernel.org, linux-alpha@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, openrisc@lists.librecores.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-xtensa@linux-xtensa.org, David Hildenbrand , Chris Zankel , Max Filippov Subject: [PATCH mm-unstable v1 25/26] xtensa/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE Date: Fri, 13 Jan 2023 18:10:25 +0100 Message-Id: <20230113171026.582290-26-david@redhat.com> In-Reply-To: <20230113171026.582290-1-david@redhat.com> References: <20230113171026.582290-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 96CFE1A0006 X-Rspam-User: X-Stat-Signature: xgactqoz8ztjm5tj11aaz43t3hypxsa8 X-HE-Tag: 1673630030-612149 X-HE-Meta: U2FsdGVkX1+3VkMS00A35m+6+TG8PNMTtR2AGvTBSyAnA0XfM2DGEwSssILk1TxNAu3lQIa4IC3LzIEfi5j9Y0zn6BvEnqu/w/1oSIo/BYp0cuAAz7AeeKGKJnNSja3PABWusieCd9Y4Rmt/GL5rNGNoUys5rwbqeXDrLVoQ7BrWMNG2OpfrnC+RFKo85nDDeVh4Nm8d5iKF8OHFeiWayPQHAwol3zcXUX8L7kKLhWLCoic8DeFmk9BwrDdcE4gvT1zMPd0DL3/5JnR0YD3o/+vE+zR2ocD3pa44j2FB9NKouuTq4CC9gcoNaGJmOqcY+5RT/o9S4rTCkf+sKlx3aq5Dr8wZOpw/E7u9K7TMjU8njJmlf/Tb8i9pTH2UbDnElL4Ec50CtETofCTkPUCBIMs0FbO5Y6wJKRxVp7sN0+C+70dx4b6drH9CxO33zuJuA5XHahi71zJF6056kgq+qMkgOqacOdeW7wR/hCkZDR50drUBxaoFOuI4EP2ESzZ3QOs4T9iEJtTu2HjLzN4pshevQORnI6PQGUKkMjHpa3Vwjit82sl3UvSqEpCi9Hk89CbyjxAzVMFBo/KVka3K5f5IIUxwu20I/DxsU3vF493LPPyQotc2Pto9lmSrANjDv/Kyev2fyXCrUPJ59QYy7GUcn5BNnnll8MhoESCwLZnDEoWhQGsI6cpLJZXlp1JKTsnOQfyq+2+OqTi/Ab3ClcPMiwx1V9Y6lPWRCeLljyg0Ai6ixo7WO83mefR/+ASAy18I9lCLvzN6Yi8ItOCzzPOQkP2guhqesUR++HypHg7vD3KhCtqsXE7peu5NJTLpS5N0mVVLRCHKHv6/i2xRJo04eTnY1Z7j0EmJ2oDToCIc5/nW7aaD0q/cO2GnqLfjxHp1wBiuQp0FAPj8TfXlxL8G6tdKe5AmgxKnJo4kGnVLRiJbN8uqvdlSI5xvXgqUGxDrGJKKNgFXtPzHx5v dJdzgrBh g3f1CdnBwmtGfpvpS0fE2Dl4QWE11awULmVMt 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: Let's support __HAVE_ARCH_PTE_SWP_EXCLUSIVE by using bit 1. This bit should be safe to use for our usecase. Most importantly, we can still distinguish swap PTEs from PAGE_NONE PTEs (see pte_present()) and don't use one of the two reserved attribute masks (1101 and 1111). Attribute mask 1100 and 1110 now identify swap PTEs. While at it, remove SWP_TYPE_BITS (not really helpful as it's not used in the actual swap macros) and mask the type in __swp_entry(). Cc: Chris Zankel Cc: Max Filippov Signed-off-by: David Hildenbrand --- arch/xtensa/include/asm/pgtable.h | 32 ++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/xtensa/include/asm/pgtable.h b/arch/xtensa/include/asm/pgtable.h index 5b5484d707b2..1025e2dc292b 100644 --- a/arch/xtensa/include/asm/pgtable.h +++ b/arch/xtensa/include/asm/pgtable.h @@ -96,7 +96,7 @@ * +- - - - - - - - - - - - - - - - - - - - -+ * (PAGE_NONE)| PPN | 0 | 00 | ADW | 01 | 11 | 11 | * +-----------------------------------------+ - * swap | index | type | 01 | 11 | 00 | + * swap | index | type | 01 | 11 | e0 | * +-----------------------------------------+ * * For T1050 hardware and earlier the layout differs for present and (PAGE_NONE) @@ -112,6 +112,7 @@ * RI ring (0=privileged, 1=user, 2 and 3 are unused) * CA cache attribute: 00 bypass, 01 writeback, 10 writethrough * (11 is invalid and used to mark pages that are not present) + * e exclusive marker in swap PTEs * w page is writable (hw) * x page is executable (hw) * index swap offset / PAGE_SIZE (bit 11-31: 21 bits -> 8 GB) @@ -158,6 +159,9 @@ #define _PAGE_DIRTY (1<<7) /* software: page dirty */ #define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */ +/* We borrow bit 1 to store the exclusive marker in swap PTEs. */ +#define _PAGE_SWP_EXCLUSIVE (1<<1) + #ifdef CONFIG_MMU #define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) @@ -343,19 +347,37 @@ ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep) } /* - * Encode and decode a swap and file entry. + * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that + * are !pte_none() && !pte_present(). */ -#define SWP_TYPE_BITS 5 -#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > SWP_TYPE_BITS) +#define MAX_SWAPFILES_CHECK() BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > 5) #define __swp_type(entry) (((entry).val >> 6) & 0x1f) #define __swp_offset(entry) ((entry).val >> 11) #define __swp_entry(type,offs) \ - ((swp_entry_t){((type) << 6) | ((offs) << 11) | \ + ((swp_entry_t){(((type) & 0x1f) << 6) | ((offs) << 11) | \ _PAGE_CA_INVALID | _PAGE_USER}) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) #define __swp_entry_to_pte(x) ((pte_t) { (x).val }) +#define __HAVE_ARCH_PTE_SWP_EXCLUSIVE +static inline int pte_swp_exclusive(pte_t pte) +{ + return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_mkexclusive(pte_t pte) +{ + pte_val(pte) |= _PAGE_SWP_EXCLUSIVE; + return pte; +} + +static inline pte_t pte_swp_clear_exclusive(pte_t pte) +{ + pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE; + return pte; +} + #endif /* !defined (__ASSEMBLY__) */