Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp33686950rwd; Sat, 8 Jul 2023 18:45:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlHI+ZNW1zevgZNh4BAiqdxSToQH+i+93DITnDocgOGVKPcrNpulGg0gyhpSWgQ2t6fG+NNx X-Received: by 2002:a17:902:ec88:b0:1b5:532e:33b8 with SMTP id x8-20020a170902ec8800b001b5532e33b8mr7464614plg.35.1688867137052; Sat, 08 Jul 2023 18:45:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688867137; cv=none; d=google.com; s=arc-20160816; b=RYq/cqOsfJYpS39RRcYWN6rYBh1EgQAWUM37rmRQLdEKeXJNp+QtcXHfi2KnB9foBZ /eRoZ0myyNhVHKILgH7X00CUwB9mOc5UUzoMb92a2biB0MpjMZH99Vo0cQoE+7noymbi Q78sSY1s3eOLNIi/9rD02WAhFU8bpumuv5ohVAz/8ct3aSEzjG89ndifZUgyxTuoEAdS gcBkR2VOoclAGpu6sb3RtcpiYe+l0VCYkFspYx1/PLberk+OvcPeM3lGhqrji6aEQh4H EdxWrRfcNzYk+cReOJxuSUKoozldsdRnOSgRBgUQqe46rhd0UAonoGXO5RmXx38TzGjU T1YA== 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:subject:cc:to:from:date :dkim-signature; bh=7lVwT3KE1l7/7bzeaASdzoOzVVwpii5Mb7T9SNYs3os=; fh=rCDVbNq0XWeyQ9NramohratcpQ014bte1wxssVt96Sg=; b=Xweptwpl9qRfvYPA18bG9BS1T2NCkBZQKPdQD9frhDcRelocy9hul8P+AYmJmD/fll vM159WYURdAkUi6w/UBOzvdkoyfpKrfswd0nZQIoJ0VZjQLDUJtezITq3a/pC45j5P+t QRe9LBfA+S+cczTxTLtNoThQ2kQxZQ951e+Q0SvAteqiEN2QhQmWdHKcQc7Vh141yEqT +O8lnK6aQXFxiHL/F02sBsSP18HY9/zjzU8J0Vi28GSneV8HD3u/uQrwZXp8ED6TAdbo 9qwz/smNFFqFMFbnn0CyiYZ3BkdJ2XHSCPmxJDLmrIMzoDFV6+ODEKDxA9IZIYVM3uOa 0r8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=aDLhQEW2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020a1709027e8200b001b8c47563e7si5960494pla.28.2023.07.08.18.45.25; Sat, 08 Jul 2023 18:45:37 -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=@linux-foundation.org header.s=korg header.b=aDLhQEW2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229690AbjGIBIz (ORCPT + 99 others); Sat, 8 Jul 2023 21:08:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGIBIy (ORCPT ); Sat, 8 Jul 2023 21:08:54 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7B571BC; Sat, 8 Jul 2023 18:08:53 -0700 (PDT) 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 63EB260B6A; 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-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 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.