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: 13064 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1981009wru; Sun, 30 Oct 2022 15:02:17 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4+ZFLZ0SDoNGvIIygmkmX/Wxw7cP10nYyPuzt9u+jbfFXb9vpGJQEofAydgeM9zKJmBLCb X-Received: by 2002:a63:26c3:0:b0:46b:1dab:fd88 with SMTP id m186-20020a6326c3000000b0046b1dabfd88mr9946078pgm.251.1667167337501; Sun, 30 Oct 2022 15:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667167337; cv=none; d=google.com; s=arc-20160816; b=gb1yH3cE+Mk2ZYIIaUAGLG1qB2eKk4XR217SnxY9qv4VcQqYSS4tKHVEl69lYyP1LZ ZwFu+eSZjoY3uLoEtB1+BMRcWCFRO/oCIt2Gi2UQDt5nHT77JyVFMVXYexaQi/jJx994 LhheDw2uMlUmiRhLLfkerikFLGzqJunN8HDuLOz4/8uJa7uTnyLOXSKE6dRGtGe7zLk6 mgvGwPI9gH+T81R4NwJk2gmxs128sRoWt86f8mV//fFQ7G1cau6yTRgTTovkq2zZaIXZ YxK0Tgrp4vKju8TpdhLtGd5mGwYdGoFC6kIikzYs3SUPW58GRPr0V4+lx6Nxi7Cevc9X XSow== 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=fX+JSCnPsldLCzmeklskU5n+7tkjCg8wbYp4w0X13YE=; b=x7ALcOaoF4Sk0EdcOcOxNGp+gRYmyy3ERTTkEqCvpVnl8xCarErb6bz3ShDwVsddj8 u9cMzzvlP4KqpzSeutV+8gkf8J0qniWDLu9LN9HyOLhH5P/pdWRm+13BijFK8I7Tluex 2A6Q2MJBPJOsFYd6muXA7Fgu/TpX29YqbqmoyJZWRAXA70qUX8p8AHDDBQbXEPudjWgD Vee/x95XuZByP5SshTZis9CDHZ2h2MCn8rqdzGTLMnTsFVHTslAvlG2H1hJxlSDBhqn9 M83WRUA85dnsaRIm3o7FiyxWVQEQkVRYNr9EnTaoKH+CAq51dQCFj8VRRanv+zrbFZZ/ lEAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Aev14zKG; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g19-20020a056a0023d300b00537fe344fa8si6889078pfc.34.2022.10.30.15.02.03; Sun, 30 Oct 2022 15:02:17 -0700 (PDT) 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=Aev14zKG; 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 S229730AbiJ3Vm4 (ORCPT + 99 others); Sun, 30 Oct 2022 17:42:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbiJ3Vmy (ORCPT ); Sun, 30 Oct 2022 17:42:54 -0400 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 8157DB85D for ; Sun, 30 Oct 2022 14:41:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667166117; 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=Aev14zKGKoEAuo/CRNHCFyG5eUIH4cxzqg1XYrln883eftTXVUl5Q7K6U4SzyX3Tbla0LZ 9hv+ecr8KA5mUzkkbsyi1xKi1olaLzYYB/0ers8JM3jwy9xshVqJo4vsKbsPzHTPBZnS81 EslYcfDGHTYsrJFv1wGXk8lsRij9Go8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-434-RMyrHXN8OAG7b5_1xEMnUQ-1; Sun, 30 Oct 2022 17:41:56 -0400 X-MC-Unique: RMyrHXN8OAG7b5_1xEMnUQ-1 Received: by mail-qt1-f200.google.com with SMTP id ew11-20020a05622a514b00b003a524196d31so741426qtb.2 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=rcZga9bkMQe2NRlQm1lGvYOe5J2i9fM6nER+/3fYWVSXDfJm0LKuwUzvNwQFSTxAW6 EbFsFJSAGftn1qU1IWAFY5UC3sKswd5gMYmda7k56XN7jXtInASZgNn1w+LtmeFHsoZ5 UHNoKBjQlOzHCYpc0dOrlOhTMKL6eQYvFZ/9NGCDd4t7cIP1zgM6+RfOncmPefbWkDXN iFNUrI1VdXR5XExnwmgON+T0n6NIBmT+W9kKpSa7xTOVvvFqETaPjPewG6Oyk2hRwz7X myRMFPceY0AfLsNlL1HS4wZH966W+SwzMWWnEuEmzfcFbdhVMJeYo/aGw+CHSgntQX5A zJtw== X-Gm-Message-State: ACrzQf3ckRLj/7rbmrm5NQDQiemY/OKAGenMXx3u3vHH2L/jBPsqXJXi wtGD7FhJJCtXhqC46hpidj2525Z0E3m6ezuzps4PDMMCVk1kVJNcK84tzJ+agL/m4QQv+gZ/d7u vNDF84UZdtfc0LI8pm+A7CLuy+1WZDfrcTv5UvWUeB5Jb4eJFAZeZQh+WZrPe9h2zkqFfOZPUiQ == X-Received: by 2002:ac8:455a:0:b0:3a5:2848:6684 with SMTP id z26-20020ac8455a000000b003a528486684mr151489qtn.339.1667166115707; Sun, 30 Oct 2022 14:41:55 -0700 (PDT) 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 Content-type: text/plain X-Spam-Status: No, score=-3.2 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748151658094082364?= X-GMAIL-MSGID: =?utf-8?q?1748151658094082364?= 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: 13065 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1981342wru; Sun, 30 Oct 2022 15:02:50 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6fZA6RYTrpu5WZH2XfIrprN4VD6FVZX5xdSJEuDieidMyXBWUs5UktFxWn1IcCqWLTXRkt X-Received: by 2002:a17:90b:1809:b0:213:aeae:64a1 with SMTP id lw9-20020a17090b180900b00213aeae64a1mr9680812pjb.226.1667167370156; Sun, 30 Oct 2022 15:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667167370; cv=none; d=google.com; s=arc-20160816; b=hNRj++FM6iznZLxLofY64Q+qtR4uDA7cdEfFSrNu6hF/y+7l1H1NBxvK3fX/IfhSK9 0oRozuxho23K4YqLWTIDCohLeb5XQxb2sxajU5TEf+glKT9QYj1d12wKaSejYwDJeH/F UQQ2NWhAoYpSuYO5ZGiOjA9p5ugcuUdD6AcGKh3pzPepJr+QNVBTy54QCbLgYoP4TD25 VhKZKb3AAliLeLxZIY1dBI9Ejhn4B+5f1xsZrDD4nWhgBdjZXEctQfB6KUQlQKjLgPyV KTldFeFBgL488hNEHHp857ciZCM4fkiTPVJdEvF694vghpO/85HBsTBxRaNT00OY1MSE mrsA== 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=NZG/muIaKD33S7kiyrIGCOhfJaL7l1CctwcarwRduoM=; b=U1dsmZ/UMniXgA30jrJwI7wCUKuDj9BTeDQOyEWyH/1ibJ4ykBJKD/WcKY6xNa8Az1 xkDC5rlr08zoxJ4+SXqG4XtFGBH/oMECurT0W3lpjx3VWRUWahklaOStkIRSlOP8fAbe kq3S9soAV4pIGSE3kITquDmKe9oYHkuNA7deYJwIFzp28mXdH4Ly7RPPlRRhOTQql6wn QomExDL9Y6ZPEVw4lGteLFDEZpzd9XHvBcXT1hWMjv/NBIeshjxBmA4hJCevCeUMbn/l Lpp5hTlDu0GX9AIInyYGvX028MdOgnI8WxcFjx5WpfQxBvUmfIrtSQgEH3KDId3gL+3b YO5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IomWZYC6; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a635a0a000000b0046f63d17422si7417899pgb.359.2022.10.30.15.02.37; Sun, 30 Oct 2022 15:02:50 -0700 (PDT) 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=IomWZYC6; 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 S229839AbiJ3VnE (ORCPT + 99 others); Sun, 30 Oct 2022 17:43:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229500AbiJ3Vmy (ORCPT ); Sun, 30 Oct 2022 17:42:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEEF7A190 for ; Sun, 30 Oct 2022 14:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667166119; 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=IomWZYC6XAVLEwb+5KIDpu9vNkUj0TRGDS8Qx8XihyLBwh6dDFT1bde1tRDH8e+XEJxGOd fpXcpNkRQHBkthri1zJZ0lsIydJwpoWHHZUPnFzvgz0htVMVKqCd4KFGQd0PIt3m6vW9Rv qroWSA2XLoyKKN2Muj8d96N5cSgNs+Y= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-621-vzFiwdq4PRamhtu6GGsoaw-1; Sun, 30 Oct 2022 17:41:57 -0400 X-MC-Unique: vzFiwdq4PRamhtu6GGsoaw-1 Received: by mail-qt1-f200.google.com with SMTP id gd8-20020a05622a5c0800b0039cb77202eeso6528669qtb.0 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=lvN2OKoCG8aBSWTRhMlC5Ourq3xhxnFvYadgNSJ3aemqY9eyb2J9TqR9+KnyJaAZKI FtenKZqI3XFV5B246S059jZcMk4Lj2lSNdaNIudnRutmBgTCvgUCX7+6pT87le73qJ2D huz7WzfptxO5glbAqDsG+IyMxEY5G1TVvt6wLFEs+46+FSUmrwPQXVgDiVjrVsgQ8DUE EA7nUcI2SIA+/L8fpKUXUmCuDHSBfE8xc3t1TUS4lKeuUHayouPJlDSEQPjYoDEJPSOI ttiLS/INcUE0X2tzrP+7/GsQo+9kTYG/0YDGlW5VBVZERNJtyW8Zyga8ez/IRR+efZgG 6csA== X-Gm-Message-State: ACrzQf3yZL3hScUTR1Q7kPkCHW4+gpkDKzrEB1JJkRru5XJ2FddOyLFc yLGribzjJKlMENy9GXlAEvM8meboLX6c21eIzBIQG+8hBtgQP9cdMm0d9wubyeddwsxO94zCIOQ C7qIco4FrxJ84ZlBFeGO/KNKqASKdiWBDYIMu8G0lbvWbO/cSbn1CDKG8Ocb+5w7clsitqKpHpg == X-Received: by 2002:a0c:e34f:0:b0:4bb:5d3a:bd25 with SMTP id a15-20020a0ce34f000000b004bb5d3abd25mr8593509qvm.23.1667166116960; Sun, 30 Oct 2022 14:41:56 -0700 (PDT) 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 Content-type: text/plain X-Spam-Status: No, score=-3.2 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748151691931312931?= X-GMAIL-MSGID: =?utf-8?q?1748151691931312931?= 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;