From patchwork Fri Jan 13 17:10:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13101206 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 C6969C54EBD for ; Fri, 13 Jan 2023 17:12:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5E418900008; Fri, 13 Jan 2023 12:12:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 56D28900006; Fri, 13 Jan 2023 12:12:23 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3E73A900008; Fri, 13 Jan 2023 12:12:23 -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 2AA7B900006 for ; Fri, 13 Jan 2023 12:12:23 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 064C0120810 for ; Fri, 13 Jan 2023 17:12:23 +0000 (UTC) X-FDA: 80350419366.15.0AB296F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 662B91C0018 for ; Fri, 13 Jan 2023 17:12:21 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GnyKDU8g; spf=pass (imf20.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=1673629941; 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=KugC5IzCnqRMc64O7OXoMEHEE6o8464VZZ+3WYeoi2w=; b=Snxu02IV11t9Sbqjo1sv2fim4ytzRdBOYk0SZ6BeBAghljkj7Pz8T994jVJHUrXyEAa1nG S7OaV1cjDb3JTtVxSsOS2/3U4GOSSPjYNSgNIujYyBYlKWuYKUGrUleJxd9+cthvZjjA8s zdrtvPD8o585MYNAj/d8qmXQ+pOceec= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=GnyKDU8g; spf=pass (imf20.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=1673629941; a=rsa-sha256; cv=none; b=CjXdl+pALgmu25bo/WCdoR6GXoJLKiJbeUzTDgC+U7iDp3rRq1mnATyYyQsviXMPhGDeXa aukY2DXKlMgNZ7V+zmtCiG/sxmi7KISIFptNboFnkCn+/tb0gPfDSwT11bJEXAxiswjCY6 /67z1UJ1jwf/J/S3HXIAToZ+1nrlmaU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629940; 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=KugC5IzCnqRMc64O7OXoMEHEE6o8464VZZ+3WYeoi2w=; b=GnyKDU8gSoXpmCiykmcs+nqP4PP2YicHrOQMPDW70Nk3s9rwqyilUQGql7hyScp76Q3s1b UVTaSUuFom7QdOHMTHcRn8tX+5tFdBd/BPTF63p1lRlk8dhbebeN2LQww2DoaPycOdATjd h4FPf32kzoDtFSYiUwqtr66R6Ri+FOE= 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-646-jLSXMt2pNqeaF2AAD5XPMQ-1; Fri, 13 Jan 2023 12:12:19 -0500 X-MC-Unique: jLSXMt2pNqeaF2AAD5XPMQ-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 9D212380671B; Fri, 13 Jan 2023 17:12:17 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.193.196]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02EDF40C2064; Fri, 13 Jan 2023 17:12:10 +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 , Dinh Nguyen Subject: [PATCH mm-unstable v1 13/26] nios2/mm: refactor swap PTE layout Date: Fri, 13 Jan 2023 18:10:13 +0100 Message-Id: <20230113171026.582290-14-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: 662B91C0018 X-Stat-Signature: d59hxpge7xypwapbrukbbq3uqx7yyo68 X-Rspam-User: X-HE-Tag: 1673629941-356904 X-HE-Meta: U2FsdGVkX18bsswhoCq5iuVhfcT85Iwivocm3llrTUF8W7mL0Li8kFlcscd/MsFmX36GmX4cP6T/Abg3L1880BhVbwUzCLhj4tIiYQI4XtweXPCf3GMXpZ8qPggVJ/dg1EKL5k31fNYoYvo5AncGFKlSifyYkQsxzwOa4PT0TBC8qxAUr1qSwu+5gO38LWLBhsmTU5LUJKyQSLSinTi26RgHd0poC1qAOUTrXrYbZvfQGQXLf8rs0ucD5Hq5DxDrDpyw5tNp5zEt1SiDpVnc8Y3Pmyu4qQ5RMGXNNdVUlkARiWTeTlYSKTpxVRK7kE++5Y/ish2Dt8bOaTAMcpbNoUyOn59xToImbahqgar7mPSCCXNHJQ1En+JtyREKPTbJ8Nn9J56WDKX4/3WGoa+mJgiYCvZPQMxQ+cvngexzfxxBEBfLIMrUnEZSinGegkimhyttX0sYV9xiOQ5e9Ry2U7uQEJazaklMM05c7e0X1q3bOysOpjVQkgnaK4o2uz5PubUdZP1Rto2pae5x5N6hdEGWckOYFUvIieYI4T6w3Rrgc9zWc0/hzRTPn4rBIIHvXKA2EsG4fv6jXxo86ptpfT09ec2oadfSqLvc0p/Elp1dC/31dLNu41ME+Ot4F78V5JywBwwCvrSc3eXcQ9sGZD8ecw6wssooivcTgFEQLdSPdUDdFpyVMd/lCGub+DOzJkuiXQXY1OEj1HVabGw6/tSdtY/afaBWqOz0PK2AATOewvuqtrY2DOhW/4dWXHR9r4N8YSHB3t0stJWcDeoJyrUbCxy6WtoSxQH0lM34maQEdJgthZEiGGCZDJZt1vvGk4Xu1Gf5NOZElFIwjlmVtVQp/7rtJctXpncTG9416AyhERYyeOZrj9xdYCjZ4l9YTovJI4llBx8iFwtpfjXyNQUgBi4GK6/ATsiZ0BrC080CJ0IUhCKqikd0h+6dJnq/ic6agy/dnc0= 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: nios2 disables swap for a good reason: it doesn't even provide sufficient type bits as required by core MM. However, swap entries are nowadays also used for other purposes (migration entries, PTE markers, HWPoison, ...), and accidential use could be problematic. Let's properly use 5 bits for the swap type and document the layout. Bits 26--31 should get ignored by hardware completely, so they can be used. Cc: Dinh Nguyen Signed-off-by: David Hildenbrand --- arch/nios2/include/asm/pgtable.h | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index ab793bc517f5..d1e5c9eb4643 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -232,19 +232,21 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) __FILE__, __LINE__, pgd_val(e)) /* - * Encode and decode a swap entry (must be !pte_none(pte) && !pte_present(pte): + * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that + * are !pte_none() && !pte_present(). * - * 31 30 29 28 27 26 25 24 23 22 21 20 19 18 ... 1 0 - * 0 0 0 0 type. 0 0 0 0 0 0 offset......... + * Format of swap PTEs: * - * This gives us up to 2**2 = 4 swap files and 2**20 * 4K = 4G per swap file. + * 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 + * 0 < type -> 0 0 0 0 0 0 <-------------- offset ---------------> * - * Note that the offset field is always non-zero, thus !pte_none(pte) is always - * true. + * Note that the offset field is always non-zero if the swap type is 0, thus + * !pte_none() is always true. */ -#define __swp_type(swp) (((swp).val >> 26) & 0x3) +#define __swp_type(swp) (((swp).val >> 26) & 0x1f) #define __swp_offset(swp) ((swp).val & 0xfffff) -#define __swp_entry(type, off) ((swp_entry_t) { (((type) & 0x3) << 26) \ +#define __swp_entry(type, off) ((swp_entry_t) { (((type) & 0x1f) << 26) \ | ((off) & 0xfffff) }) #define __swp_entry_to_pte(swp) ((pte_t) { (swp).val }) #define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })