From patchwork Mon Oct 24 20:48:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10365 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp685801wru; Mon, 24 Oct 2022 15:41:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5lOd+Q1iLhntkWjxRf7vdT3At/drYbvblL55MoMKu1KP2p4T3FWnXy25Zi5oQV6f2IB8m9 X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr32809013edi.121.1666651276510; Mon, 24 Oct 2022 15:41:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666651276; cv=none; d=google.com; s=arc-20160816; b=xfWTKxWYUpiBv/MKK3mpVPGTB+NKL1Hkx1nUG//E15v1jwBXJFdDrYjtnVWJf+NGas 1QDd1KgHeqmwigho7jjYoVJBCZNTz7Kk8cF2dTi/lNvhtp5zrxJES9F+MEhTJYji8lN+ EQHFvaQQDhY3iIQEOy3bo74+V6wmtNV8/DXpfS4Jba/mJn1F/IlHYP4c80r5GaOFOvEs T8lqdRFZfMilzFfr1HwryuncPXBiOTmzz3fOTEkgD3nrZtp5dPNBwP/11tzqn8PX9Xb1 73cPj1Sz8vc0ydmn8XHr5bqLYJ2fZRBiOKD4r2ecdZBSr5VV5ixI1VWIueBrPnQ+VAbC XUZQ== 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=DtjgD11+A1aHTX9ijK54hqLSilN13SGt8oWF8m3PTwE=; b=V9IHWof89EzS0j9UUEW9lSDJxN53hSQTkQ1gKhHoiepn9fRKqsHirWJliXnQiHoPES gQw+Ggtg1eePTDZdhS68U95BEwha+hnV/yLKGc7i3o9XM9Q9SluH3GtIr+MMu8IzSwOj 58tY9vD6IeZQuSBg5Q5oh4YrU8h0pwQjjA+GZHdUBrRbp/CQkiEIO8WtiNp7Gl4XnSd1 HQmtyj2Q86F26n3GMOrdoSsI9L7KdHnVh4yQgKTfwx0MTJssMdPUGL4kEpNCprjjkZbs 4NUWyOGB+uMsrk307Lo4aohAJt+M56SdpNNmjbSb1LbB19NsmGVGpZmOWxrxp3mdhNm3 7Ksw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CBuUvnxk; 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 ev15-20020a17090729cf00b0073da5c8de1asi833804ejc.178.2022.10.24.15.40.50; Mon, 24 Oct 2022 15:41:16 -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=CBuUvnxk; 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 S231698AbiJXWkX (ORCPT + 99 others); Mon, 24 Oct 2022 18:40:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232500AbiJXWjk (ORCPT ); Mon, 24 Oct 2022 18:39:40 -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 E432EF615F for ; Mon, 24 Oct 2022 14:03:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666645323; 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=DtjgD11+A1aHTX9ijK54hqLSilN13SGt8oWF8m3PTwE=; b=CBuUvnxkNwqNKVplwTRSKew9k6CUd9gp3TWw1ZVgpTqYfKE+zKlXXb0wzdmHQVNDr3eYA8 i7n6ZEXQ+Je6yEfXbgezi+cCtYes7kA5/KqTyxecK9NQ9wLd56S4vYbDydEatD1iGOP9Wm 2emm3nKtWqrNyJ7lN2QAmz2/b4HzHr4= 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-137-D6XI-4yAOcmMf0BzVEQIYA-1; Mon, 24 Oct 2022 16:48:46 -0400 X-MC-Unique: D6XI-4yAOcmMf0BzVEQIYA-1 Received: by mail-qt1-f198.google.com with SMTP id s14-20020a05622a1a8e00b00397eacd9c1aso7887661qtc.21 for ; Mon, 24 Oct 2022 13:48:46 -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=DtjgD11+A1aHTX9ijK54hqLSilN13SGt8oWF8m3PTwE=; b=IKMKcOlrelexkH8gcseiASICBsQR8zzKniDFdN9o3qMs6d4yk1nFP2dv9kBjwASGm/ mKPEwqoreNG8uOYC4ubhnjEjXQgOLvJUfe7RJlMC3t4IqhrF1uk8OsT7WXBT0YqYaNzu O+od22A433/ERrKTQ5DJnGMkIYzOtHWpk24DLB/BQR3oMRYgV0zwkG3EyEbuoDKvhwFJ lDYuZUUa4+jb6ZZkmKwsn9B4f/IZ/WYHLMK7RByFkMPu6H8IqSVKOZ/bkpPmSeyzSOLz Dx57g6WN5RwcDoRobyonyXKadvcM+/DuwjuSAOWP1yTn5ltDDNrho/3iXp4LlvoAN9pm ycDw== X-Gm-Message-State: ACrzQf0yuqeHcPs5hdjOQuArDB1IhxdWtevijdCe4/760YnrBZqJOQ55 R57jryIG9QT8dNsiIQ5JY0xj9U0Ga+B8c4zZCBWY3n+//Wus33HyhFNjcMv8C0CcUCMYznJGKyl JO5x0kU0pcOfssnf6x0NzFy9nB89cXN4lfYx7EQP7yCvuRGaZ6ZvMlO/nT60ytndLVY3W09uxrA == X-Received: by 2002:a05:622a:13c8:b0:39c:c0aa:cdfa with SMTP id p8-20020a05622a13c800b0039cc0aacdfamr29059103qtk.251.1666644525095; Mon, 24 Oct 2022 13:48:45 -0700 (PDT) X-Received: by 2002:a05:620a:12ec:b0:6ee:9e71:190 with SMTP id f12-20020a05620a12ec00b006ee9e710190mr23862434qkl.527.1666644514574; Mon, 24 Oct 2022 13:48:34 -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 d13-20020ac8544d000000b0038d9555b580sm498531qtq.44.2022.10.24.13.48.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 13:48:34 -0700 (PDT) From: Peter Xu To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Huang Ying , peterx@redhat.com, Andrew Morton , HORIGUCHI NAOYA , Miaohe Lin , David Hildenbrand , Andrea Arcangeli Subject: [PATCH RFC 1/2] mm: Always compile in pte markers Date: Mon, 24 Oct 2022 16:48:29 -0400 Message-Id: <20221024204830.1342169-2-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221024204830.1342169-1-peterx@redhat.com> References: <20221024204830.1342169-1-peterx@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Spam-Status: No, score=-2.6 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?1747610528941414452?= X-GMAIL-MSGID: =?utf-8?q?1747610528941414452?= 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. Signed-off-by: Peter Xu Reviewed-by: Miaohe Lin --- 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 86b95ccb81bb..41a6e7b23415 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 25b12d1a7db0..71114f05a68c 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3699,11 +3699,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))