From mboxrd@z Thu Jan 1 00:00:00 1970 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 33C7FEB64DD for ; Sun, 9 Jul 2023 01:08:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B52116B0075; Sat, 8 Jul 2023 21:08:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADAB66B0078; Sat, 8 Jul 2023 21:08:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 97B278D0001; Sat, 8 Jul 2023 21:08:56 -0400 (EDT) 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 829896B0075 for ; Sat, 8 Jul 2023 21:08:56 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 57BC6140266 for ; Sun, 9 Jul 2023 01:08:56 +0000 (UTC) X-FDA: 80990289072.24.ACD646A Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf22.hostedemail.com (Postfix) with ESMTP id 8BAF5C0011 for ; Sun, 9 Jul 2023 01:08:54 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=aDLhQEW2; dmarc=none; spf=pass (imf22.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688864934; 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=7lVwT3KE1l7/7bzeaASdzoOzVVwpii5Mb7T9SNYs3os=; b=G5Ei498mF2/GwWaL+qjr9btu0ltA6wrJ6KxSXecKYIcBPqRxDLGPxw8qqX6XFliNU5NVOE H4cAGbmLtsbug39eoRGfNr5FmkvEYkr30Pq79K7nPQTTRRCvxAroDQzXxg9OXggwg5SJPF kwYwsvbYF6zNTrRjzdIgLMa9H+zDjFs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=aDLhQEW2; dmarc=none; spf=pass (imf22.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688864934; a=rsa-sha256; cv=none; b=M0Qq7mZrnUenVc6ESgebgQeqnD1kPogR0jKN3IGgjNaq7aFjLcMMIeJZt4QxQd5KN3UYgS n3kUQzlnsWrEY3k/JtyuvOoRO3fIecac21k6NB0Pm2jLCEGNMu+qfsPNbxFWZCkNbi+4eH 5nq7pPDaO8TkGQLI1O7qiNYBhdqV8v0= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 66F5F60B6C; Sun, 9 Jul 2023 01:08:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E62EC433C7; Sun, 9 Jul 2023 01:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1688864932; bh=k5nxP9jbAM1IeZ9Pjabku0MSbBxiNxaBsjdLI65+RGc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aDLhQEW2U/Ce5YKFULJhO1iXzIZEfMh0qIsf91fXpGlDLKAGl3S4x1zHAzXaZBqJH nDmSl0JnGqMiPVvyfXbiGQ7aK4uWDFVOT66Xf9WlGRZ+ubThBc9LOVAk+jKmRgDST6 vyy7ru4yQOv31Bb5r0zp+BxYYD2eUa+mISzsqUDQ= Date: Sat, 8 Jul 2023 18:08:50 -0700 From: Andrew Morton To: Axel Rasmussen Cc: Alexander Viro , Brian Geffon , Christian Brauner , David Hildenbrand , Gaosheng Cui , Huang Ying , Hugh Dickins , James Houghton , "Jan Alexander Steffens (heftig)" , Jiaqi Yan , Jonathan Corbet , Kefeng Wang , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Peter Xu , Ryan Roberts , Shuah Khan , Suleiman Souhlal , Suren Baghdasaryan , "T.J. Alumbaugh" , Yu Zhao , ZhangPeng , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v4 1/8] mm: make PTE_MARKER_SWAPIN_ERROR more general Message-Id: <20230708180850.bc938ab49fbfb38b83c367c8@linux-foundation.org> In-Reply-To: <20230707215540.2324998-2-axelrasmussen@google.com> References: <20230707215540.2324998-1-axelrasmussen@google.com> <20230707215540.2324998-2-axelrasmussen@google.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 8BAF5C0011 X-Stat-Signature: rmhzbkpdzb9567thxyn4ik8f73bo4uxf X-HE-Tag: 1688864934-268695 X-HE-Meta: U2FsdGVkX1+vF0Ti/Ar2O3txWX1SdX6VwDaiW7lzB/cVBWj8f53TV8M5oqSVVPGfn492qcPPNOfV/87hjJUFyMdkPVHtkzcISk/wGAk+GnhXObkmPrJX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BVt/Emt0q675Slmw9R8AGEtkrQg7Isy2paikpA6WYd+i7LbzUvc0myDGJFqZEeLBn5e5ptgPEpRbkxPuHLnCmd1nM8qn4d2u4IuSx31KCsMxFnKVqwqigvINykZyOxYD3SwkmuHQ6+wOP+2TQ/c9fHdYRCwMBkyublXCQZ9lzeYWF2MUomQ1tZYPe3rUm8cPD6DFIC2g3Ml3rPE0i4ObpzzUzj25VSdPTQGLDhSJ3Y8dgLi5EJ7yKcqlg== 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: On Fri, 7 Jul 2023 14:55:33 -0700 Axel Rasmussen wrote: > Future patches will re-use PTE_MARKER_SWAPIN_ERROR to implement > UFFDIO_POISON, so make some various preparations for that: > > First, rename it to just PTE_MARKER_POISONED. The "SWAPIN" can be > confusing since we're going to re-use it for something not really > related to swap. This can be particularly confusing for things like > hugetlbfs, which doesn't support swap whatsoever. Also rename some > various helper functions. > > Next, fix pte marker copying for hugetlbfs. Previously, it would WARN on > seeing a PTE_MARKER_SWAPIN_ERROR, since hugetlbfs doesn't support swap. > But, since we're going to re-use it, we want it to go ahead and copy it > just like non-hugetlbfs memory does today. Since the code to do this is > more complicated now, pull it out into a helper which can be re-used in > both places. While we're at it, also make it slightly more explicit in > its handling of e.g. uffd wp markers. > > For non-hugetlbfs page faults, instead of returning VM_FAULT_SIGBUS for > an error entry, return VM_FAULT_HWPOISON. For most cases this change > doesn't matter, e.g. a userspace program would receive a SIGBUS either > way. But for UFFDIO_POISON, this change will let KVM guests get an MCE > out of the box, instead of giving a SIGBUS to the hypervisor and > requiring it to somehow inject an MCE. > > Finally, for hugetlbfs faults, handle PTE_MARKER_POISONED, and return > VM_FAULT_HWPOISON_LARGE in such cases. Note that this can't happen today > because the lack of swap support means we'll never end up with such a > PTE anyway, but this behavior will be needed once such entries *can* > show up via UFFDIO_POISON. > > --- a/include/linux/mm_inline.h > +++ b/include/linux/mm_inline.h > @@ -523,6 +523,25 @@ static inline bool mm_tlb_flush_nested(struct mm_struct *mm) > return atomic_read(&mm->tlb_flush_pending) > 1; > } > > +/* > + * Computes the pte marker to copy from the given source entry into dst_vma. > + * If no marker should be copied, returns 0. > + * The caller should insert a new pte created with make_pte_marker(). > + */ > +static inline pte_marker copy_pte_marker( > + swp_entry_t entry, struct vm_area_struct *dst_vma) > +{ > + pte_marker srcm = pte_marker_get(entry); > + /* Always copy error entries. */ > + pte_marker dstm = srcm & PTE_MARKER_POISONED; > + > + /* Only copy PTE markers if UFFD register matches. */ > + if ((srcm & PTE_MARKER_UFFD_WP) && userfaultfd_wp(dst_vma)) > + dstm |= PTE_MARKER_UFFD_WP; > + > + return dstm; > +} Breaks the build with CONFIG_MMU=n (arm allnoconfig). pte_marker isn't defined. I'll slap #ifdef CONFIG_MMU around this function, but probably somethng more fine-grained could be used, like CONFIG_PTE_MARKER_UFFD_WP. Please consider. btw, both copy_pte_marker() and pte_install_uffd_wp_if_needed() look far too large to justify inlining. Please review the desirability of this.