From patchwork Fri Jan 13 17:10:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101215 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 0A942C678D8 for ; Fri, 13 Jan 2023 17:13:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B339900008; Fri, 13 Jan 2023 12:13:33 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 93CE6900007; Fri, 13 Jan 2023 12:13:33 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B6E5900008; Fri, 13 Jan 2023 12:13:33 -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 69D0B900007 for ; Fri, 13 Jan 2023 12:13:33 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 35B78809B4 for ; Fri, 13 Jan 2023 17:13:33 +0000 (UTC) X-FDA: 80350422306.29.F457CC7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 83793120005 for ; Fri, 13 Jan 2023 17:13:31 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hfHIMIzV; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1673630011; 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=xYT8YWEwytZoLPvVTbowZpmJH8UYNybNjQxfoh3yd80=; b=SU9WjZJPaHJG8OI8o0oBqtWVmW1gEf6KQDsWIHuWrV52e588WcyDsYz9sX/nFR5p9qB4ZE O5Pibw0hsdrTs8XwuJYE/302mpuCn/GgnDRaB7lYIRMO2dqOn1GS9AsMkAFJg3v6Fqlj/B eYspQoLhwBennXVEYDUeLv7C3q2faLs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=hfHIMIzV; spf=pass (imf29.hostedemail.com: domain of david@redhat.com designates 170.10.133.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=1673630011; a=rsa-sha256; cv=none; b=vyqrWCTZkahuQ5La4yE7W6ypmR4W/d1CkwQtsU0f/+6ujyf5T2Jw5Hc7iLhOP5lRKfPGdF GF2eIkTMyXE0APg1bSV6vdzZnNKFX3eTHxpm0EVs7p4tOyy62RNCsMLi3LUxovwRTwvmn5 jL+6YZpuauYgfFYq07ZdSE96HeQnpNc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673630010; 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=xYT8YWEwytZoLPvVTbowZpmJH8UYNybNjQxfoh3yd80=; b=hfHIMIzV/taTqr9gOTUr6b1B1NVRfbUxp6n/O07VtgIHBqjXqi25/L/4T/GZC8qmsAcgl1 OgXkOgKRJTiqbitNI6XxXXbhvQxSk+FOvPGUjKgLfE581CN3ZaZmyNMbjcEPS3J9Ut+pp2 iCdM1p+qVjznJ6ncd6K8q5imsoT1W10= 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-364-qupXFAQ3M3-MdtqTDsLbnw-1; Fri, 13 Jan 2023 12:13:26 -0500 X-MC-Unique: qupXFAQ3M3-MdtqTDsLbnw-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 43D2F1869B6C; Fri, 13 Jan 2023 17:13:23 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 495B740C2064; Fri, 13 Jan 2023 17:13:16 +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 22/26] sparc/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE on 64bit Date: Fri, 13 Jan 2023 18:10:22 +0100 Message-Id: <20230113171026.582290-23-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: 83793120005 X-Rspam-User: X-Stat-Signature: cdukjhhseftuwxqhzstu1srzbi1gzgzc X-HE-Tag: 1673630011-618927 X-HE-Meta: U2FsdGVkX1/JkCN4D8NP4Qh27gMw46c1s6fbzU7NGyEyZSlV5cpbBSSz3PcmyTTn1xAbW9gtNhBqNrljgHxvQTCje5jCXsPKtyBWQpIeTXvsmTBekMmNFnusJKlctneE2vh7HRNQ3an2wUHIGK3CumvIwlcIBtIWY+fXh7W585OISKrTH5MzmXqWn+gMuvr2+72McKSFQide/VJhTJbcSeLjmNu+npa2hWvkFOF7P089tWS/NINb/qHc19x07y9DJOILOUpF//hyx8VguSTRMqnklwGpDxkq/anFocxWdyEp4Kw0gQhjNKlzIAXPKYSqbMwjaD363NnhNfC7JoN4bcWxJZacNYRNG7OX9xBF9HFpQ315nzAPj9pZ+X67Im869B5dAQJJJ1r8RZaCkEoKapI04tx3qeg2NI25O4q+1m+9FLgyCyqrerSCRrj0IBQvwj1jtF5+xq9IiwzD2VBvzbNsWdCAcZ1KbBTwAJN0K1sZRwllS5KLuaMoWXIHtu7AE0AiiK1lWvu2GXst6uGdJZoMJXGglCUKA7eDsajtif0zO9NMrj3o5SU3N4mXMYIg/I6FjL31XSu3NLwKDfjlkRKV9hg9WqLFQTyD7Os+m3P5NBihJBn2KXv6OBBXotdpZA0QNSaALdaaBDt+mva5JBFZ8RVKgENjTHiEJqWBwdwq8v3VoURewHxmC8hQciJ3c6DplX44yu7sCvi9sn3MbTo9yZtoc8IDdZZv1cIGamK+fYSCDMrq7H2wBUd+L/+b/z063b/k2lYG3r40VDDGZEMSGYQTur0wsyIbhqLxRmEs7vpTnFm7DgqaCYXCTGGlbl0frgYMr+dL06TB21U14VEe1X9UaW+BgYyWIUxCEh62ykeofOQaGBJpXXwQK3BPCmszsGTFP6mGPW1XzbUr8Pv8shobOpFfDghmgM1JcMtSlZ8jXfN9RTERwGddRStF4j7q3hxk1dNhh05OAon z+QfhhgL l9pns/XAjs37BVCj43KOA3tO6dWBfA8DPYB10 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 was effectively unused. While at it, mask the type in __swp_entry(). Cc: "David S. Miller" Signed-off-by: David Hildenbrand --- arch/sparc/include/asm/pgtable_64.h | 38 ++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 3bc9736bddb1..a1658eebd036 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -187,6 +187,9 @@ bool kern_addr_valid(unsigned long addr); #define _PAGE_SZHUGE_4U _PAGE_SZ4MB_4U #define _PAGE_SZHUGE_4V _PAGE_SZ4MB_4V +/* We borrow bit 20 to store the exclusive marker in swap PTEs. */ +#define _PAGE_SWP_EXCLUSIVE _AC(0x0000000000100000, UL) + #ifndef __ASSEMBLY__ pte_t mk_pte_io(unsigned long, pgprot_t, int, unsigned long); @@ -961,18 +964,47 @@ void pgtable_trans_huge_deposit(struct mm_struct *mm, pmd_t *pmdp, pgtable_t pgtable_trans_huge_withdraw(struct mm_struct *mm, pmd_t *pmdp); #endif -/* Encode and de-code a swap entry */ -#define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0xffUL) +/* + * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that + * are !pte_none() && !pte_present(). + * + * Format of swap PTEs: + * + * 6 6 6 6 5 5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 + * 3 2 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 + * <--------------------------- offset --------------------------- + * + * 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 + * --------------------> E <-- type ---> <------- zeroes --------> + */ +#define __swp_type(entry) (((entry).val >> PAGE_SHIFT) & 0x7fUL) #define __swp_offset(entry) ((entry).val >> (PAGE_SHIFT + 8UL)) #define __swp_entry(type, offset) \ ( (swp_entry_t) \ { \ - (((long)(type) << PAGE_SHIFT) | \ + ((((long)(type) & 0x7fUL) << PAGE_SHIFT) | \ ((long)(offset) << (PAGE_SHIFT + 8UL))) \ } ) #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) +{ + return __pte(pte_val(pte) | _PAGE_SWP_EXCLUSIVE); +} + +static inline pte_t pte_swp_clear_exclusive(pte_t pte) +{ + return __pte(pte_val(pte) & ~_PAGE_SWP_EXCLUSIVE); +} + int page_in_phys_avail(unsigned long paddr); /*