From patchwork Fri Jan 13 17:10:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101261 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 6DFD6C3DA78 for ; Fri, 13 Jan 2023 17:13:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B2E0900007; Fri, 13 Jan 2023 12:13:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 03BED940009; Fri, 13 Jan 2023 12:13:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD0A6900009; Fri, 13 Jan 2023 12:13:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C96BE900007 for ; Fri, 13 Jan 2023 12:13:37 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 921DE120DD2 for ; Fri, 13 Jan 2023 17:13:37 +0000 (UTC) X-FDA: 80350422474.30.C63BBEA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id D3EBF4001B for ; Fri, 13 Jan 2023 17:13:35 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HJ5C/rCK"; spf=pass (imf11.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=1673630015; 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=UAWcST9nT133bZRxHkPhgB7f9R452T7ovMnNe/O4IaQ=; b=CySwV2/IyRTD2Wgab9wjQzjehugcyM53fl/6HUup1hkzZ2RhJ+8Q/IPe6CQyGcUpEJrlGE g9rWulvIXb4xUmqCtchmucDauoVXTOsvA9Tzyze8QzVYRpbRZ74hPev31Xf4Hf2I+0TTBJ Tjbrnc5ZV6ZQC1hXPuCh9rD5P0R4DIA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="HJ5C/rCK"; spf=pass (imf11.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=1673630015; a=rsa-sha256; cv=none; b=cJ/umd1OMzQnIV8GYJPd27No7UiFCobWUM6JhqRu33rR+5Pozn8hoAZdyMsisk/WpMS4fa VUxsD6vhrY9HirQgp4ZYSdzXmEARLnYyEq/fjXR4QtlBc0knVMH7HYxay6ep94maTf4/ug 17DqMhJ4UtVcZr68BR2QEM+KisWdMIM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673630015; 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=UAWcST9nT133bZRxHkPhgB7f9R452T7ovMnNe/O4IaQ=; b=HJ5C/rCKThSE2lmoEg20hwpqD1edKevS8fRTYFP+gn4JsVYg7adSw//eavlikVKb0zGy/1 hYOLrx3TCEumNLntxo0QC8LR/yyHBYBqdi6f04EYlLB8aJ5OdoGGCGQPaXBcDqcU8ksh0b Ek2wgqfosLGADeN/VlrxxaVvJ2LKxyQ= 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-493-jMJtEjLQNTeXWTaNoMr99w-1; Fri, 13 Jan 2023 12:13:31 -0500 X-MC-Unique: jMJtEjLQNTeXWTaNoMr99w-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 E37231C05136; Fri, 13 Jan 2023 17:13:29 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 95D1E40C2064; Fri, 13 Jan 2023 17:13:23 +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 , Richard Weinberger , Anton Ivanov , Johannes Berg Subject: [PATCH mm-unstable v1 23/26] um/mm: support __HAVE_ARCH_PTE_SWP_EXCLUSIVE Date: Fri, 13 Jan 2023 18:10:23 +0100 Message-Id: <20230113171026.582290-24-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: D3EBF4001B X-Stat-Signature: sq5g9k883q8zxf81zx4ozobut7eirt9q X-Rspam-User: X-HE-Tag: 1673630015-662956 X-HE-Meta: U2FsdGVkX1+5/S8OFjX2fA2jGVTLKNOC0s29i2F9pB/6/CE0d1LVdEPRClSMTBMv3pifB0zX2pOdpeXLn1u4hUcZIaufdD4J9di+hi+eD27Z6iQVEO+fVD8b6QENurGuj7YXwmfe0QgReiGDfgOMnexFxeAgOrFOfguk8FaS2fttdmAb6UBqzlak306hu0CamR5yMmOIIxdSa2AD/1LsUa/5Wbg8BrvgP7/mPxMDfKNgMdqHiINdorKWAYU8PdJiQ/aZC7GEGWBA4KfnooHakp9Umi/gsT/UA28SFwQGIoAhTMbrym+XWgVWV6K62rLcefdxAN0OwXvSG3E1tvFco586UA831Apbq+OLdkV3o8B+UE5H1ftvvuzV28h/ltf+bqU35WDrTNeBQ6RB5m1wbGEgCu59K9B5o1XSq6DkRJW6sPtdYv6aVnv3odAyt+/Jifg+u8tDa74W6wfvbznJgmiVm7LIFN9XwF5ezXtwnivygKBpxK0n7tHyxadgLZn5YY6aYtzfmcg1/setp/Cf1nXnX3SOf/X+dmatCzAaQm8OIe6OPs2uSuiur4FH2kt55ppHxoLQ9UGiGclDzyQhRxUPf6Tbbc3FeiNhsF2r04YJlC3UErmSjf0+HxAq2B47g7Q+k6eSH9gGjyQHlzIab/DzX6Ae7TZXQC28Eza2QwVjf1QJ8JlleIDWvbIL07qFUPre6SUpIcFdvhmAlzM3nNC5GVr6sJDJwXdfkPKDbi2etYedwsDKjkxt6A3YgSW51z3bGjiJgb8ZhWQ2z7/rTs7QkW1/rwtLz9qNQPUDiwZumrvlMjLm/75QV9KS+V14y/qg8tM6dWT372hw6Hy5aCStTco5W/0jf0NSlIc6cYDJorPKU8IC/YDqtXbrZ/vNzZfGbHwp+dvVEUmwIHmv6eeODO1O+t6fgK4/kqGiLaUPteh+kdP0YgKyTCSSaUfQpAsulkAyCtR8BKKR4bO UnGeGOTd UZ44EXX+UkMpUqKhL5Ia8VycwMHB8QkLPn65V 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 10, which is yet unused for swap PTEs. The pte_mkuptodate() is a bit weird in __pte_to_swp_entry() for a swap PTE ... but it only messes with bit 1 and 2 and there is a comment in set_pte(), so leave these bits alone. While at it, mask the type in __swp_entry(). Cc: Richard Weinberger Cc: Anton Ivanov Cc: Johannes Berg Signed-off-by: David Hildenbrand --- arch/um/include/asm/pgtable.h | 37 +++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/arch/um/include/asm/pgtable.h b/arch/um/include/asm/pgtable.h index 4e3052f2671a..cedc5fd451ce 100644 --- a/arch/um/include/asm/pgtable.h +++ b/arch/um/include/asm/pgtable.h @@ -21,6 +21,9 @@ #define _PAGE_PROTNONE 0x010 /* if the user mapped it with PROT_NONE; pte_present gives true */ +/* We borrow bit 10 to store the exclusive marker in swap PTEs. */ +#define _PAGE_SWP_EXCLUSIVE 0x400 + #ifdef CONFIG_3_LEVEL_PGTABLES #include #else @@ -288,16 +291,46 @@ extern pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr); #define update_mmu_cache(vma,address,ptep) do {} while (0) -/* 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 ----------------> E < type -> 0 0 0 1 0 + * + * E is the exclusive marker that is not stored in swap entries. + * _PAGE_NEWPAGE (bit 1) is always set to 1 in set_pte(). + */ #define __swp_type(x) (((x).val >> 5) & 0x1f) #define __swp_offset(x) ((x).val >> 11) #define __swp_entry(type, offset) \ - ((swp_entry_t) { ((type) << 5) | ((offset) << 11) }) + ((swp_entry_t) { (((type) & 0x1f) << 5) | ((offset) << 11) }) #define __pte_to_swp_entry(pte) \ ((swp_entry_t) { pte_val(pte_mkuptodate(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_get_bits(pte, _PAGE_SWP_EXCLUSIVE); +} + +static inline pte_t pte_swp_mkexclusive(pte_t pte) +{ + pte_set_bits(pte, _PAGE_SWP_EXCLUSIVE); + return pte; +} + +static inline pte_t pte_swp_clear_exclusive(pte_t pte) +{ + pte_clear_bits(pte, _PAGE_SWP_EXCLUSIVE); + return pte; +} + /* Clear a kernel PTE and flush it from the TLB */ #define kpte_clear_flush(ptep, vaddr) \ do { \