Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp1228171rwb; Fri, 13 Jan 2023 09:25:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXtB5nga1563ES4BTNCmMgTAtJvoa+8OEtc8+uige9LSIix1M861oEs4UUZCsIRLuJRxHYm/ X-Received: by 2002:a17:907:340e:b0:7c1:23f2:c052 with SMTP id ab14-20020a170907340e00b007c123f2c052mr2847061ejc.45.1673630749744; Fri, 13 Jan 2023 09:25:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673630749; cv=none; d=google.com; s=arc-20160816; b=T2TqHQnGVLCrzw+67ynrkCENvAFPB6hn30oZmQEPmwrg+bOdg1HlmLlnYkbNzI/JB+ toZCXT4ngZOd8MutVYnnT8AGTHrgOnP12PHxOtV5EiSUgs/pjBiSh8EP372ZbIFvUCll QU8Z39rg0Ps4z/EBR7IOltjhgUHXq2ajqREVFuz7d3oPZxBZblWK4xbgHI7i9y56EzdC goHcAECu7M8RFDeSaal05ZTgr5voLVjx5ZpkxjTavq46Wu9jeM23sI+WHyJ9Pscbpb/k VZ6SXgzgdwAvzx9JIN9w0EtOPmcypXT2teQhKutJ3WkadTVja73O8cC9Ib01GJFWsEN9 KuNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=KugC5IzCnqRMc64O7OXoMEHEE6o8464VZZ+3WYeoi2w=; b=QX4qN7GTfp8+iIXRaI1Gaf9O5C8O5yKL+KyEWbAUsmQCGDdWWacBSVXEaeJTuLRpFC lhMycgQ8QjYaXpRPtG3kZvxEToDhtshzTIdsx/FcBBflX9GzhDiklj8BNCycOT1CNDBX jWyNVLDBMWdFdLsMxWMGZlzB8dy1/0rF9ddeviJVgXPxke0ds+qtpALG89PbXRSzfZ5b tg1h4lOm8qhgivWIGpY1YsDx4UpMPREMk/EZ79qyqijPdlBMSZBmE8w17sDZYNkEW496 zywL8b/x2JCDC6pIhiqLBUnQH+v24QlmeSMdT0D/D7dUXUtcx0nCxEwoGNuI9m50Br03 hNqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Q+K/HdJ4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh19-20020a1709076e9300b00741c0bd7061si23094692ejc.644.2023.01.13.09.25.37; Fri, 13 Jan 2023 09:25:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Q+K/HdJ4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbjAMRQT (ORCPT + 51 others); Fri, 13 Jan 2023 12:16:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbjAMROz (ORCPT ); Fri, 13 Jan 2023 12:14:55 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D6928B74B for ; Fri, 13 Jan 2023 09:12:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673629941; 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=Q+K/HdJ4vQwiJcAA24zancsVQ+TdVn8QctYdL/55unaj2oeGIiE6TyDO7LdRDXDHtI8L/I Z8NX/knh4qKjuL+eSJcBIHKAfi9ffHbQno4clORHWu07GD7qm3RZR5lLSdyhe2Zse+qnqs 8EDPXrNaNUGw5neOMJMFyZ9SfzwLlPs= 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) }) -- 2.39.0