From patchwork Sun Oct 30 21:41:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025230 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 F30D5ECAAA1 for ; Sun, 30 Oct 2022 21:42:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 88E746B0074; Sun, 30 Oct 2022 17:42:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 83E6D6B0075; Sun, 30 Oct 2022 17:42:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B8A76B0078; Sun, 30 Oct 2022 17:42:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5C1E66B0074 for ; Sun, 30 Oct 2022 17:42:06 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3CA3A80712 for ; Sun, 30 Oct 2022 21:42:06 +0000 (UTC) X-FDA: 80078939052.29.608D4F0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf17.hostedemail.com (Postfix) with ESMTP id BFD954001A for ; Sun, 30 Oct 2022 21:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667166125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fX+JSCnPsldLCzmeklskU5n+7tkjCg8wbYp4w0X13YE=; b=cnwiqk92UQlOFJF9vAU1FIR/uvhZ3oZ7rUfKmdkldh+/pzv5zye+ByDMNOwMEdH8jxaEor gN2ks/m52xHJccUecu6FVKp8NSZrF8PsisAram/QkTvZoquqnOZIYvId0bpaXqg4PWL+lJ vRrNRAEE2itzunbOqDeTCv7ENlKNrUw= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-48-4X5yY64cN0qFAxgoxaz6WA-1; Sun, 30 Oct 2022 17:41:56 -0400 X-MC-Unique: 4X5yY64cN0qFAxgoxaz6WA-1 Received: by mail-qk1-f198.google.com with SMTP id bj1-20020a05620a190100b006fa12a05188so3862852qkb.4 for ; Sun, 30 Oct 2022 14:41:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fX+JSCnPsldLCzmeklskU5n+7tkjCg8wbYp4w0X13YE=; b=TDGDr5KHHaX/S9lQErmOOjPiKTCHaIOOoqWG4BO5tpXyMHGI5PLtwiDJjYPQD+HiO3 O1Lgpg5ofi6sBQGypV2Ysz2hCriNp5x9Q2qOHpsNTrdprUYcxJjT/jz0QYTV9mg6lv+X 61ozxZwu+ydBx3i+UNeJOXQ1Fe8mJ003HPfZC8rUPQxKAm0wxGLNw1pyxl3mdVc/K5T9 oy1J12eBxu/IgAedZKbc1mKVyIEjBqmP5XTpKPrMfdBG5tKknAbVep5mv8BZYfYqibwa u/GwKoa50X7H/Y6PzEEEUDw+x3amRIwwW0eTj46Azm5mW413U//81qJ8FgpZL7uflIpP +4iw== X-Gm-Message-State: ACrzQf2ySnZKm8YaQAtE+6VWTFaNYNOXVTOTgRWfeWU1JAf7Y/vmrkcM iqX6dXCQLJ4pyQxHhF0hBkhTC6TX79N9osyTU+F8bjJlriAyaSut2uC5z3sRNY/nP2d8Q1XA+dF dAbNJelkiYhY= X-Received: by 2002:ac8:455a:0:b0:3a5:2848:6684 with SMTP id z26-20020ac8455a000000b003a528486684mr151482qtn.339.1667166115648; Sun, 30 Oct 2022 14:41:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5USleFlEkZVYw3WrJWxBoYASvDZKqgoasGEWME223t3xhHNLGEwzMnQF0Osvb31iqHDNPp7A== X-Received: by 2002:ac8:455a:0:b0:3a5:2848:6684 with SMTP id z26-20020ac8455a000000b003a528486684mr151472qtn.339.1667166115387; Sun, 30 Oct 2022 14:41:55 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id az42-20020a05620a172a00b006bb87c4833asm3506450qkb.109.2022.10.30.14.41.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:41:54 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Miaohe Lin , Huang Ying , David Hildenbrand , HORIGUCHI NAOYA , Andrea Arcangeli , peterx@redhat.com Subject: [PATCH 1/2] mm: Always compile in pte markers Date: Sun, 30 Oct 2022 17:41:50 -0400 Message-Id: <20221030214151.402274-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030214151.402274-1-peterx@redhat.com> References: <20221030214151.402274-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667166125; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fX+JSCnPsldLCzmeklskU5n+7tkjCg8wbYp4w0X13YE=; b=I9zqML246u1zpOAOtQuiGWcWn2596bfVBjROup0sCWkdk5Wczut+itBLyZop959IKqzwkk J8PsOOmB4mg8kUJ2ZI9iX3cPnLUD+VCr7PNnw6lc5UPv6gXP8bTj0yOvu50AV8H18DXjHP 7FeOa0RFAywXQoUJSBtdaxJuw4v+Rhg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cnwiqk92; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667166125; a=rsa-sha256; cv=none; b=L8/2BJ4N7olnynOs74b6TyYvAp68/c2/XNpZpEOU/3C6bgsxWBpGI+gQBM4AR0eWw5rea1 5WN7UkXDTG93nMZU4cH7G7Phx18GsR7F0WHoaT3SBaHrqwEi/S8RSKv8qtI3HXU9I9nozO y5fb1aw2EWehlKZgDrmkVLhS3ciaI6U= X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: BFD954001A Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=cnwiqk92; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf17.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com X-Stat-Signature: x8cp3bjwwabbcymhjye6hqki6kwzfbe5 X-Rspam-User: X-HE-Tag: 1667166125-417417 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: The PTE markers code is tiny and now it's enabled for most of the distributions. It's fine to keep it as-is, but to make a broader use of it (e.g. replacing read error swap entry) it needs to be there always otherwise we need special code path to take care of !PTE_MARKER case. It'll be easier just make pte marker always exist. Use this chance to extend its usage to anonymous too by simply touching up some of the old comments, because it'll be used for anonymous pages in the follow up patches. Reviewed-by: Huang Ying Reviewed-by: Miaohe Lin Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- include/linux/swap.h | 10 +++------- include/linux/swapops.h | 31 ------------------------------- mm/Kconfig | 7 ------- mm/memory.c | 7 +++---- 4 files changed, 6 insertions(+), 49 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 369d7799205d..211aeca9bfa7 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -60,17 +60,13 @@ static inline int current_is_kswapd(void) SWP_MIGRATION_NUM + SWP_DEVICE_NUM + \ SWP_PTE_MARKER_NUM) /* - * PTE markers are used to persist information onto PTEs that are mapped with - * file-backed memories. As its name "PTE" hints, it should only be applied to - * the leaves of pgtables. + * PTE markers are used to persist information onto PTEs that otherwise + * should be a none pte. As its name "PTE" hints, it should only be + * applied to the leaves of pgtables. */ -#ifdef CONFIG_PTE_MARKER #define SWP_PTE_MARKER_NUM 1 #define SWP_PTE_MARKER (MAX_SWAPFILES + SWP_HWPOISON_NUM + \ SWP_MIGRATION_NUM + SWP_DEVICE_NUM) -#else -#define SWP_PTE_MARKER_NUM 0 -#endif /* * Unaddressable device memory support. See include/linux/hmm.h and diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 3ba9bf56899d..35c1fe62d2e1 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -412,8 +412,6 @@ typedef unsigned long pte_marker; #define PTE_MARKER_UFFD_WP BIT(0) #define PTE_MARKER_MASK (PTE_MARKER_UFFD_WP) -#ifdef CONFIG_PTE_MARKER - static inline swp_entry_t make_pte_marker_entry(pte_marker marker) { return swp_entry(SWP_PTE_MARKER, marker); @@ -434,32 +432,6 @@ static inline bool is_pte_marker(pte_t pte) return is_swap_pte(pte) && is_pte_marker_entry(pte_to_swp_entry(pte)); } -#else /* CONFIG_PTE_MARKER */ - -static inline swp_entry_t make_pte_marker_entry(pte_marker marker) -{ - /* This should never be called if !CONFIG_PTE_MARKER */ - WARN_ON_ONCE(1); - return swp_entry(0, 0); -} - -static inline bool is_pte_marker_entry(swp_entry_t entry) -{ - return false; -} - -static inline pte_marker pte_marker_get(swp_entry_t entry) -{ - return 0; -} - -static inline bool is_pte_marker(pte_t pte) -{ - return false; -} - -#endif /* CONFIG_PTE_MARKER */ - static inline pte_t make_pte_marker(pte_marker marker) { return swp_entry_to_pte(make_pte_marker_entry(marker)); @@ -477,9 +449,6 @@ static inline pte_t make_pte_marker(pte_marker marker) * memory, kernel-only memory (including when the system is during-boot), * non-ram based generic file-system. It's fine to be used even there, but the * extra pte marker check will be pure overhead. - * - * For systems configured with !CONFIG_PTE_MARKER this will be automatically - * optimized to pte_none(). */ static inline int pte_none_mostly(pte_t pte) { diff --git a/mm/Kconfig b/mm/Kconfig index 57e1d8c5b505..4b28800d9be1 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -1107,17 +1107,10 @@ config HAVE_ARCH_USERFAULTFD_MINOR help Arch has userfaultfd minor fault support -config PTE_MARKER - bool - - help - Allows to create marker PTEs for file-backed memory. - config PTE_MARKER_UFFD_WP bool "Userfaultfd write protection support for shmem/hugetlbfs" default y depends on HAVE_ARCH_USERFAULTFD_WP - select PTE_MARKER help Allows to create marker PTEs for userfaultfd write protection diff --git a/mm/memory.c b/mm/memory.c index c5599a9279b1..63718094163f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3663,11 +3663,10 @@ static vm_fault_t handle_pte_marker(struct vm_fault *vmf) unsigned long marker = pte_marker_get(entry); /* - * PTE markers should always be with file-backed memories, and the - * marker should never be empty. If anything weird happened, the best - * thing to do is to kill the process along with its mm. + * PTE markers should never be empty. If anything weird happened, + * the best thing to do is to kill the process along with its mm. */ - if (WARN_ON_ONCE(vma_is_anonymous(vmf->vma) || !marker)) + if (WARN_ON_ONCE(!marker)) return VM_FAULT_SIGBUS; if (pte_marker_entry_uffd_wp(entry)) From patchwork Sun Oct 30 21:41:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13025229 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 81070ECAAA1 for ; Sun, 30 Oct 2022 21:42:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1D7A06B0073; Sun, 30 Oct 2022 17:42:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1887B6B0074; Sun, 30 Oct 2022 17:42:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 029006B0075; Sun, 30 Oct 2022 17:41:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id E7CDB6B0073 for ; Sun, 30 Oct 2022 17:41:59 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id B64F21C448D for ; Sun, 30 Oct 2022 21:41:59 +0000 (UTC) X-FDA: 80078938758.10.47F5021 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 55F28A0002 for ; Sun, 30 Oct 2022 21:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667166118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NZG/muIaKD33S7kiyrIGCOhfJaL7l1CctwcarwRduoM=; b=T4jcqmAAxpUdeOnD8QapoZ8RsTTT5Pz1fsJdzBon7BOykV0JyIx9M/6/tpmb/pPiaLp+G2 UUsL2ZQ8M328YPSHaCfb+snqjlvoK5Rs52fltsD/34krd6BWHTnxe22v8grZM5mWPMikgZ mO6fFQSzb7PpGS9xajtN6CzJh/URtgY= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-665-ElKgdj5FO4G2l-sL3SC-5g-1; Sun, 30 Oct 2022 17:41:57 -0400 X-MC-Unique: ElKgdj5FO4G2l-sL3SC-5g-1 Received: by mail-qt1-f198.google.com with SMTP id i13-20020ac8764d000000b003a4ec8693dcso6566920qtr.14 for ; Sun, 30 Oct 2022 14:41:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NZG/muIaKD33S7kiyrIGCOhfJaL7l1CctwcarwRduoM=; b=tEb2toRqVJlAg40MgrpvTFF/fT3whdA0/mRh5l7nneJyRhQpSFka+uUEYgTb2aZ1rO Ci1Mb7QdPfo41XbRYs44soQ9F32nSJeeBfYQ39RA3O22DPhqGu4bjrKUmXNGWqWNSro6 bxe5ikgnE3G5dpRVT5zzKmOf7d3/EQfdkHFauywm7PNJ/iD4pHyICI+qzPP0bh+bcdI4 8lDFpF0ePd48/9Agu2te81srV9dX9j79t4cuxVynK3gqw3mnT4PIy2/d5hgnz7Dxa137 WwsUZ2QFenKDU67ImSB7a8hEMbq8axKEPYirx75hQIKhZ7ACkGcICHJakkmJSlFyGB0N JB8g== X-Gm-Message-State: ACrzQf0UT1B8XDFdcH3hvgsMV0BK90kIQZBw4/Ir10hugo6LLeY1tTKP kFFsgi5cvoBvJ+4Gtb8z4Tmr5eTN+9DgXM8onWv2OXtfVI2oboRwG95SLs49um2uXoCNTApODCn 6ip/5pDUSne8= X-Received: by 2002:a0c:e34f:0:b0:4bb:5d3a:bd25 with SMTP id a15-20020a0ce34f000000b004bb5d3abd25mr8593497qvm.23.1667166116905; Sun, 30 Oct 2022 14:41:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM56/nGCvuzs0NWrECQA7YHom5BUeTUz2vyEagoYhNV4gX5mhHytcEPx886ymP4yKSA1jjDsCA== X-Received: by 2002:a0c:e34f:0:b0:4bb:5d3a:bd25 with SMTP id a15-20020a0ce34f000000b004bb5d3abd25mr8593489qvm.23.1667166116680; Sun, 30 Oct 2022 14:41:56 -0700 (PDT) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id az42-20020a05620a172a00b006bb87c4833asm3506450qkb.109.2022.10.30.14.41.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 14:41:56 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Miaohe Lin , Huang Ying , David Hildenbrand , HORIGUCHI NAOYA , Andrea Arcangeli , peterx@redhat.com Subject: [PATCH 2/2] mm: Use pte markers for swap errors Date: Sun, 30 Oct 2022 17:41:51 -0400 Message-Id: <20221030214151.402274-3-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221030214151.402274-1-peterx@redhat.com> References: <20221030214151.402274-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-type: text/plain ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667166119; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NZG/muIaKD33S7kiyrIGCOhfJaL7l1CctwcarwRduoM=; b=qekSt8y7UfmiV5kww4OhQBiE8ehJOi1l9eIwmO8acuDTGBRrQ4qP+zwJ95Fshih63VI/Pr +GnDu524rjMY5asM3sSYYxWIsbOGPDv5gckDe/eTmtPOULKML//3WJ0jgyNKerEPQVXJim /QB+zTDwhBckyE7feLdszmkJ6rasBpA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T4jcqmAA; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667166119; a=rsa-sha256; cv=none; b=j6LTfLa/VpowKJ6qBtkW7NGMK86TLYcJX35dt0mtE1vZtcQ4O9j4BsEJOi0Rwj1fsInvr6 j3ywN8gnIUoYWvwUcj/87Dq+xoBcG+7G12IOGeQzTlis40gs1Rr4rJDcG/d/2P6kv28e4/ hxBc2Mptp/CObSeOxbq7w68iaE9CozE= X-Stat-Signature: 59gxzogyh5met3mmh4ikbni46srgdmmk X-Rspamd-Queue-Id: 55F28A0002 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T4jcqmAA; spf=pass (imf25.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1667166119-104010 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: PTE markers are ideal mechanism for things like SWP_SWAPIN_ERROR. Using a whole swap entry type for this purpose can be an overkill, especially if we already have PTE markers. Define a new bit for swapin error and replace it with pte markers. Then we can safely drop SWP_SWAPIN_ERROR and give one device slot back to swap. We used to have SWP_SWAPIN_ERROR taking the page pfn as part of the swap entry, but it's never used. Neither do I see how it can be useful because normally the swapin failure should not be caused by a bad page but bad swap device. Drop it alongside. Reviewed-by: Huang Ying Reviewed-by: Miaohe Lin Signed-off-by: Peter Xu Acked-by: David Hildenbrand --- include/linux/swap.h | 6 +----- include/linux/swapops.h | 26 ++++++++++++++------------ mm/memory.c | 6 ++++-- mm/shmem.c | 2 +- mm/swapfile.c | 2 +- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/include/linux/swap.h b/include/linux/swap.h index 211aeca9bfa7..fec6647a289a 100644 --- a/include/linux/swap.h +++ b/include/linux/swap.h @@ -55,10 +55,6 @@ static inline int current_is_kswapd(void) * actions on faults. */ -#define SWP_SWAPIN_ERROR_NUM 1 -#define SWP_SWAPIN_ERROR (MAX_SWAPFILES + SWP_HWPOISON_NUM + \ - SWP_MIGRATION_NUM + SWP_DEVICE_NUM + \ - SWP_PTE_MARKER_NUM) /* * PTE markers are used to persist information onto PTEs that otherwise * should be a none pte. As its name "PTE" hints, it should only be @@ -121,7 +117,7 @@ static inline int current_is_kswapd(void) #define MAX_SWAPFILES \ ((1 << MAX_SWAPFILES_SHIFT) - SWP_DEVICE_NUM - \ SWP_MIGRATION_NUM - SWP_HWPOISON_NUM - \ - SWP_PTE_MARKER_NUM - SWP_SWAPIN_ERROR_NUM) + SWP_PTE_MARKER_NUM) /* * Magic header for a swap area. The first part of the union is diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 35c1fe62d2e1..27ade4f22abb 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -162,16 +162,6 @@ static inline void *swp_to_radix_entry(swp_entry_t entry) return xa_mk_value(entry.val); } -static inline swp_entry_t make_swapin_error_entry(struct page *page) -{ - return swp_entry(SWP_SWAPIN_ERROR, page_to_pfn(page)); -} - -static inline int is_swapin_error_entry(swp_entry_t entry) -{ - return swp_type(entry) == SWP_SWAPIN_ERROR; -} - #if IS_ENABLED(CONFIG_DEVICE_PRIVATE) static inline swp_entry_t make_readable_device_private_entry(pgoff_t offset) { @@ -409,8 +399,9 @@ static inline bool is_migration_entry_dirty(swp_entry_t entry) typedef unsigned long pte_marker; -#define PTE_MARKER_UFFD_WP BIT(0) -#define PTE_MARKER_MASK (PTE_MARKER_UFFD_WP) +#define PTE_MARKER_UFFD_WP BIT(0) +#define PTE_MARKER_SWAPIN_ERROR BIT(1) +#define PTE_MARKER_MASK (BIT(2) - 1) static inline swp_entry_t make_pte_marker_entry(pte_marker marker) { @@ -437,6 +428,17 @@ static inline pte_t make_pte_marker(pte_marker marker) return swp_entry_to_pte(make_pte_marker_entry(marker)); } +static inline swp_entry_t make_swapin_error_entry(void) +{ + return make_pte_marker_entry(PTE_MARKER_SWAPIN_ERROR); +} + +static inline int is_swapin_error_entry(swp_entry_t entry) +{ + return is_pte_marker_entry(entry) && + (pte_marker_get(entry) & PTE_MARKER_SWAPIN_ERROR); +} + /* * This is a special version to check pte_none() just to cover the case when * the pte is a pte marker. It existed because in many cases the pte marker diff --git a/mm/memory.c b/mm/memory.c index 63718094163f..6090124b64f1 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3669,6 +3669,10 @@ static vm_fault_t handle_pte_marker(struct vm_fault *vmf) if (WARN_ON_ONCE(!marker)) return VM_FAULT_SIGBUS; + /* Higher priority than uffd-wp when data corrupted */ + if (marker & PTE_MARKER_SWAPIN_ERROR) + return VM_FAULT_SIGBUS; + if (pte_marker_entry_uffd_wp(entry)) return pte_marker_handle_uffd_wp(vmf); @@ -3728,8 +3732,6 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) put_page(vmf->page); } else if (is_hwpoison_entry(entry)) { ret = VM_FAULT_HWPOISON; - } else if (is_swapin_error_entry(entry)) { - ret = VM_FAULT_SIGBUS; } else if (is_pte_marker_entry(entry)) { ret = handle_pte_marker(vmf); } else { diff --git a/mm/shmem.c b/mm/shmem.c index 0a7c4a748811..7428ae3fa4b9 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1682,7 +1682,7 @@ static void shmem_set_folio_swapin_error(struct inode *inode, pgoff_t index, swp_entry_t swapin_error; void *old; - swapin_error = make_swapin_error_entry(&folio->page); + swapin_error = make_swapin_error_entry(); old = xa_cmpxchg_irq(&mapping->i_pages, index, swp_to_radix_entry(swap), swp_to_radix_entry(swapin_error), 0); diff --git a/mm/swapfile.c b/mm/swapfile.c index 5fc1237a9f21..13f2569a6719 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -1781,7 +1781,7 @@ static int unuse_pte(struct vm_area_struct *vma, pmd_t *pmd, pte_t pteval; dec_mm_counter(vma->vm_mm, MM_SWAPENTS); - pteval = swp_entry_to_pte(make_swapin_error_entry(page)); + pteval = swp_entry_to_pte(make_swapin_error_entry()); set_pte_at(vma->vm_mm, addr, pte, pteval); swap_free(entry); ret = 0;