From patchwork Fri Jan 13 17:10:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101208 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 CDDB5C3DA78 for ; Fri, 13 Jan 2023 17:12:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E3A18E0002; Fri, 13 Jan 2023 12:12:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56CB18E0001; Fri, 13 Jan 2023 12:12:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3BF7F8E0002; Fri, 13 Jan 2023 12:12:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 28BA38E0001 for ; Fri, 13 Jan 2023 12:12:40 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E37FC120B62 for ; Fri, 13 Jan 2023 17:12:39 +0000 (UTC) X-FDA: 80350420038.28.AC399A7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 64957A0018 for ; Fri, 13 Jan 2023 17:12:37 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="K/R0asA1"; spf=pass (imf15.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=1673629957; 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=Yg5//Yy7TNKL4+cSLuxDja5DgwYoaRFdwhUA2l2XqT4=; b=8ca38s2S2rYkgoMC2ajDCBWakn1NUDyEd463oo3oOpBmUcVMSyu0cCQaG5iK3PqnjYaxdA /jv/tQXXfZPfZs9krEFAHCSz3usMD/Sgs2nHrr8bqomhzWLQc3w2G4uysyAZNqFDn8xQSL aU7i3e5COeqMp0MWtVwVMUvDp+FMtJU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="K/R0asA1"; spf=pass (imf15.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=1673629957; a=rsa-sha256; cv=none; b=hghC266egHAjwtrumGo7brT7x4ocZUHQINo34QM3lyWR2KXwIk8vEP3hydSmnfOBnfHnxI tpB+vFoqXux2pobguYU9NDCQ6vtaVWcXenTqLld429HaBsyUfWmVWmdw2t97X5ylEMj1Ot j5faC0XwqaFWTLsiVGgM3b6TVsrVk/g= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629956; 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=Yg5//Yy7TNKL4+cSLuxDja5DgwYoaRFdwhUA2l2XqT4=; b=K/R0asA1g7rI08+IVWKoIyCcZmIHxJWl49AzyQfmHfy17m43+6fMCf9x/xIcHLYjwCgMzN 9YkKru6Ya8YxOerM391QdtLMVlSm1/MchLKVIgaGaxIbPh7zv5lf4dOQbj6jQqDsm7kEgK XA7r7c6OukF25lDLkJq3TTrcDra/Igk= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-533-CQX355qCMESVPPSct6yrTA-1; Fri, 13 Jan 2023 12:12:33 -0500 X-MC-Unique: CQX355qCMESVPPSct6yrTA-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 991F4380610A; Fri, 13 Jan 2023 17:12:31 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA27840C2064; Fri, 13 Jan 2023 17:12:24 +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 , Stefan Kristiansson , Stafford Horne Subject: [PATCH mm-unstable v1 15/26] openrisc/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE Date: Fri, 13 Jan 2023 18:10:15 +0100 Message-Id: <20230113171026.582290-16-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-Stat-Signature: tbsityn3irn7tde8gqf5gcrf6cpdkj3y X-Rspam-User: X-Rspamd-Queue-Id: 64957A0018 X-Rspamd-Server: rspam06 X-HE-Tag: 1673629957-756047 X-HE-Meta: U2FsdGVkX1+DWjACG31qpFo0TYK1eNtkLcwWU4rjhAAWM1EpjO7hjddUhQlMdVPIgo6nrnL4WnwtoYWPhr9FTz+QoaERcJZtcKuX0B/IFdhdUimmDLNynD5U8gQg4MY0M01m1wpK7I695FSrgm7Bo8whElroi3UodhYLj2akkw91DXxHdgMXL7d7nMpidSikGhuN5CBQ67pJcO8p6WUWMBqlO6NulMdJWb2gEOgO+IcmUq+wGwNLycGMX+CYL7Pz99SRr0EzDhcDCHXOAXRVNCYe6WXJbkZ1nvxPyRUPlyZnud6bk6hADeHVRSW3IB6wG4NYtHakLD63cxUwW3BJUed+afMboASfRTLGT8e/rtpBYn5wTaXqdnvx+LFBjPutmLwC9U3J+SxlmgmE+35vZoYfMpoCaijrJq8puJIhlhKg6/vzMmnufdMlpSvPCjVb9YXjFUWlYjp9D2HmUYMEdbHLMhAJFO1ntvOYror1sAQnHjKFvK6TGtyWIX0b+wFdzDSW258VdtJlXYCDeYEyOvBNGP6KS+WjXL6PafHEihhENWRTwvEYaFlJPffgiMbrnXb5It1svwwJxwbE+ZFwRVBP/Ttclyh4LO/P84Hc9Mvr4IrCdUczIZiTf01cX2gjVpZfNOySRQTx7bmetTekXXuhbK7l0VMN+qGob0lFe4mhFpT39kzbQ+3y8qIcCLTA2N35c4Qx+77QW5Jx+WVF9U/Trp7WQgA07cohGYvKzi0ki18Nix8IdxuB6rFp937co/XZND3vBjmdmprWSEk7LjuXd6avjkKIhZmsd7MZx7MEdQ51+Ps5DKDSH/0UZCubjg21dJZ6vRUDt1cAFVmefqf4mcKScqxukikUPD1Kg4TUd0gZHeC6+2RgRR22seh/ZEtpKnqlBKaKYzfJGIEvjDV+vumzW68ZWyASs9N7o33mNM9Skjuji0JgoeYHegx86HE43GapFldTWpEj/Xb HH7yXUOD /Lw/q1Sd2KTkE3v6fqESmFlAlJsyl9x7YMIyE 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 stealing one bit from the type. Generic MM currently only uses 5 bits for the type (MAX_SWAPFILES_SHIFT), so the stolen bit is effectively unused. While at it, mask the type in __swp_entry(). Cc: Stefan Kristiansson Cc: Stafford Horne Signed-off-by: David Hildenbrand --- arch/openrisc/include/asm/pgtable.h | 41 +++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h index 6477c17b3062..903b32d662ab 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -154,6 +154,9 @@ extern void paging_init(void); #define _KERNPG_TABLE \ (_PAGE_BASE | _PAGE_SRE | _PAGE_SWE | _PAGE_ACCESSED | _PAGE_DIRTY) +/* We borrow bit 11 to store the exclusive marker in swap PTEs. */ +#define _PAGE_SWP_EXCLUSIVE _PAGE_U_SHARED + #define PAGE_NONE __pgprot(_PAGE_ALL) #define PAGE_READONLY __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE) #define PAGE_READONLY_X __pgprot(_PAGE_ALL | _PAGE_URE | _PAGE_SRE | _PAGE_EXEC) @@ -385,16 +388,44 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, /* __PHX__ FIXME, SWAP, this probably doesn't work */ -/* Encode and de-code a swap entry (must be !pte_none(e) && !pte_present(e)) */ -/* Since the PAGE_PRESENT bit is bit 4, we can use the bits above */ - -#define __swp_type(x) (((x).val >> 5) & 0x7f) +/* + * 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 ---------------> E <- type --> 0 0 0 0 0 + * + * E is the exclusive marker that is not stored in swap entries. + * The zero'ed bits include _PAGE_PRESENT. + */ +#define __swp_type(x) (((x).val >> 5) & 0x3f) #define __swp_offset(x) ((x).val >> 12) #define __swp_entry(type, offset) \ - ((swp_entry_t) { ((type) << 5) | ((offset) << 12) }) + ((swp_entry_t) { (((type) & 0x3f) << 5) | ((offset) << 12) }) #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; +} + typedef pte_t *pte_addr_t; #endif /* __ASSEMBLY__ */