From patchwork Fri Jan 13 17:10:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101214 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 87757C54EBD for ; Fri, 13 Jan 2023 17:13:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 239FB8E0001; Fri, 13 Jan 2023 12:13:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C29C900007; Fri, 13 Jan 2023 12:13:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 03C938E0006; Fri, 13 Jan 2023 12:13:23 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id E19F68E0001 for ; Fri, 13 Jan 2023 12:13:23 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id A7973120BA9 for ; Fri, 13 Jan 2023 17:13:23 +0000 (UTC) X-FDA: 80350421886.24.554D354 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf17.hostedemail.com (Postfix) with ESMTP id 2038140015 for ; Fri, 13 Jan 2023 17:13:20 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B699OvS3; spf=pass (imf17.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=1673630001; 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=u/qx8EisQ9cE7qGuacOvuCI0HccRFINdBBjLGJqKXis=; b=SEbVPWxNZWxia2Joy5Y86ONHELCrOsdZbTVhPjuCKxDO4R8JcAdfyaACm3IapWZ3YMx0Q7 OCJBtAb8+wZQqoRcnS1nh3eUC9oabSsRDaNPVF6ffhQoY+PyjcaxLaeh2OC8lfJXw6OvzS appH1Z9wyA4hmEFyT7G/llOj9OTtTdU= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=B699OvS3; spf=pass (imf17.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=1673630001; a=rsa-sha256; cv=none; b=kg8EwZw1ySAlCNvX0tVGthAZilP25UutxiNVKk1pF/igZZfDs2XCb8kX4IZz0nTluvYNkt 4pJCuOVv+sgLdB7u8Mzw8Oc73GsVrAVAP+OfQSDU5Wv70RYECB1ZpHmc1uDGSiEuwy6Onp WXFs0909JBLB9OfNZujoROUWrIq3HiQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673630000; 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=u/qx8EisQ9cE7qGuacOvuCI0HccRFINdBBjLGJqKXis=; b=B699OvS3KMTaHS/d9linrknw4FlDCAlAJTYkCrxtl/n5OvWoudTbmFJlQUFuET1IxL+Kxi X+XCuNCGNqfvCglDtGxxp0frtasrhac5eho66/RCmYwey0fDLO5qGYDhj/+J8aosv5Ki7h 48Y+g1ac683XkQE2sMQ/y0tKAUtQClE= 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-439-7TH0Gw_VMwKT5Wow9tu7iA-1; Fri, 13 Jan 2023 12:13:18 -0500 X-MC-Unique: 7TH0Gw_VMwKT5Wow9tu7iA-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 E587D811E6E; Fri, 13 Jan 2023 17:13:15 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51CB140C2064; Fri, 13 Jan 2023 17:13:09 +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 , "David S. Miller" Subject: [PATCH mm-unstable v1 21/26] sparc/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE on 32bit Date: Fri, 13 Jan 2023 18:10:21 +0100 Message-Id: <20230113171026.582290-22-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: rspam05 X-Rspamd-Queue-Id: 2038140015 X-Stat-Signature: hsinhoct7c4qtsyy1p3epmc7gtocp85r X-Rspam-User: X-HE-Tag: 1673630000-126305 X-HE-Meta: U2FsdGVkX1+PDt3Etv2IcDqQZl6xPSDr05+ehFA1bxRl+q92K7fDfbxyHvXEotEw6/cH9pVLi+RUBBYVfkqIbJefW6vOtUvRlpNRZAosaE+L5NFmxtEXOIBVOkxNzlc0MCOr0X/cbXytz20NvUUA8WDqZNPpxWACgB4BKxPphuY8J7PrdvuYM8PCrqd8BKrwpX3gVzJb/syIu4kAvYt4BiSqqy66w8ltJXq4p5YTTciHIp+Xi3HAY3A72Ksczylqq/dROMfYfoBCzLbmVIOHKMim1X+zgqZT6KAUtuRfpWEbMWOMaMalUZiqWoGHvphbOhm43fCclRqw6vkWbNe/QDN4jRwATAmNzHgKlqYlajFlEBZ7haD45wyupBmjGoAlOCZCBZb1nLPXe5ns6K3bS/7qyNMlOiAHzOKK40nRRn8EUE8KCK0Zu+IDfQNkH/ilUSYiLYz7b6kqqlQX30XKQ7HVN4Sl72xlytC1jiJCaLaUfL5Jis7lJcKTk5axiA+9JS0GQLEbYo45K4i/E2HWslhBBPQkZNF9B4g6i0SPTj8GrOmdB09iqv+BXGwGj0LZcVR1vDqHy+SKO8jcLK7KbRvVrkRnwvisCr1ifxqmeBiRG2lxnxsCVf0p7G+GaKroNTu+jX22+aiDc9yCGhuPQwfdpuutl6Z0GqxMw2UDRPDfmnsPwLjDD24+epRCpR3I69xCXvCzTmv+/Kl0LVjpAx/Av4Gk2QPoDBQI3bTulxq//unwv79xaLzAQ5biAznpxicyXOtJWhhmMsD2qnLzwllj8+6J6Sq9qOTvhETzEq0V3jN9HBscqreu1EUu0r8p7iSuGJU2Gwp+CFzA6eh5eY9rZBpAlaJmBtYLbVrNw/JWaGjlGab/lK1GYdmF0FPVS5qemYn7A8oRj4L6AHMl4gU6JKWomvCykyTbttqd9ZfzSQVQGx8C8wup7u6/+9s/zKfaqFn+5GLbBC2AnLJ SnJnIY9v VeQnJ7Bze/kz/9M1Oo8165m7cqOfAS4ER4BwR 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 reusing the SRMMU_DIRTY bit as that seems to be safe to reuse inside a swap PTE. This avoids having to steal one bit from the swap offset. While at it, relocate the swap PTE layout documentation and use the same style now used for most other archs. Note that the old documentation was wrong: we use 20 bit for the offset and the reserved bits were 8 instead of 7 bits in the ascii art. Cc: "David S. Miller" Signed-off-by: David Hildenbrand --- arch/sparc/include/asm/pgtable_32.h | 27 ++++++++++++++++++++++++++- arch/sparc/include/asm/pgtsrmmu.h | 14 +++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h index 5acc05b572e6..abf7a2601209 100644 --- a/arch/sparc/include/asm/pgtable_32.h +++ b/arch/sparc/include/asm/pgtable_32.h @@ -323,7 +323,16 @@ void srmmu_mapiorange(unsigned int bus, unsigned long xpa, unsigned long xva, unsigned int len); void srmmu_unmapiorange(unsigned long virt_addr, unsigned int len); -/* Encode and de-code a swap entry */ +/* + * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that + * are !pte_none() && !pte_present(). + * + * Format of swap PTEs: + * + * 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 + * <-------------- offset ---------------> < type -> E 0 0 0 0 0 0 + */ static inline unsigned long __swp_type(swp_entry_t entry) { return (entry.val >> SRMMU_SWP_TYPE_SHIFT) & SRMMU_SWP_TYPE_MASK; @@ -344,6 +353,22 @@ static inline swp_entry_t __swp_entry(unsigned long type, unsigned long offset) #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) & SRMMU_SWP_EXCLUSIVE; +} + +static inline pte_t pte_swp_mkexclusive(pte_t pte) +{ + return __pte(pte_val(pte) | SRMMU_SWP_EXCLUSIVE); +} + +static inline pte_t pte_swp_clear_exclusive(pte_t pte) +{ + return __pte(pte_val(pte) & ~SRMMU_SWP_EXCLUSIVE); +} + static inline unsigned long __get_phys (unsigned long addr) { diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h index 6067925972d9..18e68d43f036 100644 --- a/arch/sparc/include/asm/pgtsrmmu.h +++ b/arch/sparc/include/asm/pgtsrmmu.h @@ -53,21 +53,13 @@ #define SRMMU_CHG_MASK (0xffffff00 | SRMMU_REF | SRMMU_DIRTY) -/* SRMMU swap entry encoding - * - * We use 5 bits for the type and 19 for the offset. This gives us - * 32 swapfiles of 4GB each. Encoding looks like: - * - * oooooooooooooooooootttttRRRRRRRR - * fedcba9876543210fedcba9876543210 - * - * The bottom 7 bits are reserved for protection and status bits, especially - * PRESENT. - */ +/* SRMMU swap entry encoding */ #define SRMMU_SWP_TYPE_MASK 0x1f #define SRMMU_SWP_TYPE_SHIFT 7 #define SRMMU_SWP_OFF_MASK 0xfffff #define SRMMU_SWP_OFF_SHIFT (SRMMU_SWP_TYPE_SHIFT + 5) +/* We borrow bit 6 to store the exclusive marker in swap PTEs. */ +#define SRMMU_SWP_EXCLUSIVE SRMMU_DIRTY /* Some day I will implement true fine grained access bits for * user pages because the SRMMU gives us the capabilities to