From patchwork Fri Jan 13 17:10:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101201 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 84FF2C3DA78 for ; Fri, 13 Jan 2023 17:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 23AED900006; Fri, 13 Jan 2023 12:11:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C3DB900004; Fri, 13 Jan 2023 12:11:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3188900006; Fri, 13 Jan 2023 12:11:49 -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 E112C900004 for ; Fri, 13 Jan 2023 12:11:49 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id B461F40D71 for ; Fri, 13 Jan 2023 17:11:49 +0000 (UTC) X-FDA: 80350417938.29.9A4B6AA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 1F3851C0019 for ; Fri, 13 Jan 2023 17:11:47 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dTTptcxt; spf=pass (imf18.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=1673629908; a=rsa-sha256; cv=none; b=fsdB+kM/ByzfLxEKLgvYKdaRPb1c8PHMyJ86cxZGbJUT+2g96HZ+GRwKYISPrIf0kPR7Ju FMK7fcpvMN7xibkyMBkV+OYMnIOOR62V6FlcFjk254kOPswTxfkipBAGc1E901SlwX5Fta SNeLgW8D+rTz9KNaUylWAydKdfJD36Y= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=dTTptcxt; spf=pass (imf18.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=1673629908; 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=VrUB2NRjghlzVoNQHKteBTC+XVSGThz3GjMZ7z8Kku8=; b=VNs2KU0fJj5fgF9ATXpWrKqPekaxjeaXw21wFvjPwUhVyketGWPenlKSUIBchXniBVZg6w 8p+xreKe0NhNpZ/Td3v7bjnQG683OwqoM/BwrYrHvN6WLuF84pH9IcIm0Vbc3jeuiwR2Ry ZwFY6bGWS/mr0Tc43jQACL1Lgr6XPaQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629907; 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=VrUB2NRjghlzVoNQHKteBTC+XVSGThz3GjMZ7z8Kku8=; b=dTTptcxtLjhFPpk2ea/kJKRxS5+leh6cRKEYjvj2KC6jODZ8MD+UhyT2jG94rWhUmIxXIo XqZQJGQr3q0LuUgd11Fn8BLG6B8soeLORnnLM16SimtD2jg+ZQ1g/KJUGTU4DEPlp4oeaK YOTTs9d/r6B/BnsIvQCPsTin1XN5vys= 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-458-LLf--PisOGC08DN12Vq3Xg-1; Fri, 13 Jan 2023 12:11:43 -0500 X-MC-Unique: LLf--PisOGC08DN12Vq3Xg-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 19FA9886462; Fri, 13 Jan 2023 17:11:42 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24A5940C2064; Fri, 13 Jan 2023 17:11:34 +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 , Huacai Chen , WANG Xuerui Subject: [PATCH mm-unstable v1 08/26] loongarch/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE Date: Fri, 13 Jan 2023 18:10:08 +0100 Message-Id: <20230113171026.582290-9-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-Rspam-User: X-Rspamd-Queue-Id: 1F3851C0019 X-Rspamd-Server: rspam01 X-Stat-Signature: pgj4go5njrnra4ychqqg7igf1gnaj3qt X-HE-Tag: 1673629907-950859 X-HE-Meta: U2FsdGVkX1+KOJn28F+Vz/07hg5jnRjHz6McgKF/V8eSlB/4a1RXZ1Xnfu088ZpLYDXP5FSli5Trymxjf+sPGGtJphfi0SNFmyPL5rVa615DQ8qBkkpHe6Mq3sYUOF3Aw30BCs7bl0+qo/lZImlh+7Qo7ZtFN7nCbjF/xd0YAyYxivCcV/KWdRKqcdar7zpmhMDyLDTXPdMbJztoDZmM6SZIomifbshdW5DAHb7cvZUxcPC1M1z8kgafQgbf+W6AOyvcnIcaF5BdjLKD0pu//gWRmWGyHcizzpJUksvfIYSlJCV5SV3FcGHC6noiMHpnRzJ6QFmvCl8D3TTIVyOTsilfEYUMa1QIuz/KFi8YK6nX8YB41fHdpcAGOyJSJAC+r7+5yI3ZrIhkPcPL682bqvI+MIHIwurWECITnPPJbP5+ZIEOF/30xyHDqvcsloI1U8WAg2pyJ2KqHRQVEDmKk62zV6M4e3BOdgg7lEtf7VSgiD7KxjJcyPdhbjpmd3eM1KrzYO7+EXJ2xD5vZXcGC9GvZ/qU1lOcShwVOR29mfFViU15XhVxq0ev3uMBEBGoaxLwHJ8lWMI1IkJrxp749PQugJ7iyaycXUAephoMiAAwgbDhGq1tQFq0U32CYYdmoiZW8S0k2MB8UBgv45hjsMuysYYOyDEB7GdMlps4q9b/3GO811jGqTnPCXEQ9Ewusl71Z8OgapBBTibcC7HRetlPDe1KutM0FGmP4TwSz8UIJ5DrISejVU6nzPM9FVwFSme9oqxYl9Wp5cZYIIj4lSB7DateHgD1hIQos4+BpDslyiT2/il3eUDYKmewzPb+HspQfsN6/kjLfXu+1lfTQG9Lv8KUF/puxClDqcYFKXxuKWAsOv53GO7vB4KRl6ui6g1w9YI5QsrmJe4JTRttgcp1r9kYKQCUzgcDwULq0YLWPHHMVRNpCEDJvR4VuxuDfjY8VDy0rPRdk/nSk1N 6Jc7i7I3 YzATUjnEAPBx6Na3BS1fEvI1TQLCJIdLHr1gj 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, also mask the type in mk_swap_pte(). Note that this bit does not conflict with swap PMDs and could also be used in swap PMD context later. Cc: Huacai Chen Cc: WANG Xuerui Signed-off-by: David Hildenbrand --- arch/loongarch/include/asm/pgtable-bits.h | 4 +++ arch/loongarch/include/asm/pgtable.h | 39 ++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/arch/loongarch/include/asm/pgtable-bits.h b/arch/loongarch/include/asm/pgtable-bits.h index 3d1e0a69975a..8b98d22a145b 100644 --- a/arch/loongarch/include/asm/pgtable-bits.h +++ b/arch/loongarch/include/asm/pgtable-bits.h @@ -20,6 +20,7 @@ #define _PAGE_SPECIAL_SHIFT 11 #define _PAGE_HGLOBAL_SHIFT 12 /* HGlobal is a PMD bit */ #define _PAGE_PFN_SHIFT 12 +#define _PAGE_SWP_EXCLUSIVE_SHIFT 23 #define _PAGE_PFN_END_SHIFT 48 #define _PAGE_NO_READ_SHIFT 61 #define _PAGE_NO_EXEC_SHIFT 62 @@ -33,6 +34,9 @@ #define _PAGE_PROTNONE (_ULCAST_(1) << _PAGE_PROTNONE_SHIFT) #define _PAGE_SPECIAL (_ULCAST_(1) << _PAGE_SPECIAL_SHIFT) +/* We borrow bit 23 to store the exclusive marker in swap PTEs. */ +#define _PAGE_SWP_EXCLUSIVE (_ULCAST_(1) << _PAGE_SWP_EXCLUSIVE_SHIFT) + /* Used by TLB hardware (placed in EntryLo*) */ #define _PAGE_VALID (_ULCAST_(1) << _PAGE_VALID_SHIFT) #define _PAGE_DIRTY (_ULCAST_(1) << _PAGE_DIRTY_SHIFT) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index 7a34e900d8c1..c6b8fe7ac43c 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -249,13 +249,26 @@ extern void pud_init(void *addr); extern void pmd_init(void *addr); /* - * Non-present pages: high 40 bits are offset, next 8 bits type, - * low 16 bits zero. + * 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 ----------> + * + * E is the exclusive marker that is not stored in swap entries. + * The zero'ed bits include _PAGE_PRESENT and _PAGE_PROTNONE. */ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) -{ pte_t pte; pte_val(pte) = (type << 16) | (offset << 24); return pte; } +{ pte_t pte; pte_val(pte) = ((type & 0x7f) << 16) | (offset << 24); return pte; } -#define __swp_type(x) (((x).val >> 16) & 0xff) +#define __swp_type(x) (((x).val >> 16) & 0x7f) #define __swp_offset(x) ((x).val >> 24) #define __swp_entry(type, offset) ((swp_entry_t) { pte_val(mk_swap_pte((type), (offset))) }) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) @@ -263,6 +276,24 @@ static inline pte_t mk_swap_pte(unsigned long type, unsigned long offset) #define __pmd_to_swp_entry(pmd) ((swp_entry_t) { pmd_val(pmd) }) #define __swp_entry_to_pmd(x) ((pmd_t) { (x).val | _PAGE_HUGE }) +#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; +} + extern void paging_init(void); #define pte_none(pte) (!(pte_val(pte) & ~_PAGE_GLOBAL))