Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp28178824rwd; Tue, 4 Jul 2023 14:37:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6pADNjiR0e/om/jzvWZtHNgC+0XMOEqCjsIa+YSug0qrtq78O+vm20z5BP4Ma+oLNJ0FJ5 X-Received: by 2002:a05:6830:1352:b0:6b4:60f1:e074 with SMTP id r18-20020a056830135200b006b460f1e074mr13818118otq.28.1688506633198; Tue, 04 Jul 2023 14:37:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688506633; cv=none; d=google.com; s=arc-20160816; b=MtXjDpsT5jokz6xKtBEIKri48hmfCjyxLDczjjtakAruVZU9AwxObCkhJDCI6uE0/z fv+ZV2Zw8ZRh6G+85wXJad2MTUHmFRZlHWQJseLIr/+YdEI20JtLrI3sPQAVrfryi7eI I5qIhnwk7yiNA1qekS62wFCj2znIdqMcri/R64Is2aD/Nc+XohYtGKBGATn/tTp+6Uhg tNLlUcyHeoRy2HTB8IdwlYilew7rJUCIL2c9Poe+9u0PM7kJulxJvgijEEXElPDdtpin S4vTrn1gwzWEi5CgatU9ozADYkq8vnL1SZJtavzbQ7uesqJCfzJvDhXSPgVdafN48D+b JpEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GI5b35dMc1KdLtRTJt9n7EYcXqIPCpvszX0gw0M88kM=; fh=0t4louP/8+xP3ORiRbUZtig8/xKb5OX3R1/WptJFEDo=; b=NYF0UhSG5MyOZq5F96VEHKMUiln1pIn8uDUv75I9kKgk8rfM0+VJYKDO6ADLaYi0C0 WBlYD2NiqKPu02ddN8sF7EMv1OSkTWovV4hVgl6ACiEX/9ig00sp4465p8mcjG8SbOn0 1gsxtvo+VfMRxNS2Vpm59mUl/yryhv2+uGaUpDAIMDknC7JduYDfV+Fj2S50XWxuvIIr Y8BXhjeYrXePLnnwkQRSAD7AY8QUHwVaADoT1q0ruMvIACvuV0i7EGNy/sXjk1mygV1m 8RIyvZfMO+rDwrV5RG+v6z+9fcJyEW+BlWWMM2EQHDGVZnP4nMPPtnO9JcuF59A6IIjH XxHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BRz9WfHp; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a7-20020a634d07000000b00553854417d8si21701849pgb.617.2023.07.04.14.36.58; Tue, 04 Jul 2023 14:37:13 -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=BRz9WfHp; 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 S230187AbjGDVAp (ORCPT + 99 others); Tue, 4 Jul 2023 17:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230334AbjGDVAo (ORCPT ); Tue, 4 Jul 2023 17:00:44 -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 323AA10C8 for ; Tue, 4 Jul 2023 13:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688504395; 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: in-reply-to:in-reply-to:references:references; bh=GI5b35dMc1KdLtRTJt9n7EYcXqIPCpvszX0gw0M88kM=; b=BRz9WfHpJptwM4RUDm0STDUbAlgfACtDIfuWfBrF90uu88q1rPaVdc5FiJ4Y8UdBCNmphB 5AD5nuXG8/jJaGeGfY8nIfL45SGdEwAXy37D45AG7Rx0MHldhhPa73X+SEcOEE6YHDZ7bP foCoWeOibk7LZemGq/0PRhsRYU0ln0c= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-f0vCLg4VPB2z9qi3jpvikg-1; Tue, 04 Jul 2023 16:59:54 -0400 X-MC-Unique: f0vCLg4VPB2z9qi3jpvikg-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-6340023ffbbso11589976d6.1 for ; Tue, 04 Jul 2023 13:59:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688504394; x=1691096394; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=GI5b35dMc1KdLtRTJt9n7EYcXqIPCpvszX0gw0M88kM=; b=HQqLCQg+dUOietk4qfy00nPi0i3/o4Pj4R7uv+6/dqSDh9BvsH5qFmEIeNzcIyd+zF ez1wkVBYeYLA4bwPlOUWnzVm8O9xDY3JPOY5K2xZu86Mynjk4ZHpSOTaDLIQZ7qwrg7v Cg6dpSHD1FMyiUG81ON7G81OxH29nprXL0uaGQFWRUZ7d028V8jDapHg1QztU9g2mg7f yt6oW3Tvq2PeUGZ8k5iRXpdgHeJ9yOMF6EPjZ3omzbxUJts1tfRlvD2CPsprQcJH16++ RWqGK5SWgLDMhQwcBASmw8l7mD+AzTYO8V3YGqcbwOjoT0OaevTAOYRIc+j0D35z5gQ8 vb3Q== X-Gm-Message-State: ABy/qLa5sbFBFi5/AkAxmzCiNmbAQgPQjljmLn7Xxfr5nPH0ugelMIsW GTUAwK1NjlCosnWMINsfnBSBDRli97/QV2aVXx18mbbMuMsNhhYxr7xLKtxYSICAIKF3/7XP+rf zor1AHooGoGi3w4nBeITKWMID X-Received: by 2002:a05:6214:3018:b0:635:e528:521a with SMTP id ke24-20020a056214301800b00635e528521amr6683195qvb.5.1688504393766; Tue, 04 Jul 2023 13:59:53 -0700 (PDT) X-Received: by 2002:a05:6214:3018:b0:635:e528:521a with SMTP id ke24-20020a056214301800b00635e528521amr6683169qvb.5.1688504393448; Tue, 04 Jul 2023 13:59:53 -0700 (PDT) Received: from x1n (cpe5c7695f3aee0-cm5c7695f3aede.cpe.net.cable.rogers.com. [99.254.144.39]) by smtp.gmail.com with ESMTPSA id y11-20020ad457cb000000b00631eb444e6esm12777291qvx.51.2023.07.04.13.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 13:59:53 -0700 (PDT) Date: Tue, 4 Jul 2023 16:59:51 -0400 From: Peter Xu To: Axel Rasmussen Cc: Alexander Viro , Andrew Morton , Christian Brauner , David Hildenbrand , Huang Ying , Hugh Dickins , James Houghton , Jiaqi Yan , Jonathan Corbet , "Liam R. Howlett" , Miaohe Lin , Mike Kravetz , "Mike Rapoport (IBM)" , Muchun Song , Nadav Amit , Naoya Horiguchi , Shuah Khan , 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 v2 3/6] mm: userfaultfd: support UFFDIO_POISON for hugetlbfs Message-ID: References: <20230629205040.665834-1-axelrasmussen@google.com> <20230629205040.665834-3-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230629205040.665834-3-axelrasmussen@google.com> X-Spam-Status: No, score=-2.1 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_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Thu, Jun 29, 2023 at 01:50:37PM -0700, Axel Rasmussen wrote: > The behavior here is the same as it is for anon/shmem. This is done > separately because hugetlb pte marker handling is a bit different. > > Signed-off-by: Axel Rasmussen > --- > mm/hugetlb.c | 33 +++++++++++++++++++++++++++++++-- > mm/userfaultfd.c | 6 +----- > 2 files changed, 32 insertions(+), 7 deletions(-) > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 38711d49e4db..05abe88986b6 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -6090,14 +6090,24 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, > } > > entry = huge_ptep_get(ptep); > - /* PTE markers should be handled the same way as none pte */ > - if (huge_pte_none_mostly(entry)) > + if (huge_pte_none_mostly(entry)) { > + if (is_pte_marker(entry)) { > + unsigned long marker = pte_marker_get(pte_to_swp_entry(entry)); > + > + if (marker & PTE_MARKER_UFFD_POISON) { > + ret = VM_FAULT_HWPOISON_LARGE; > + goto out_mutex; > + } > + } > /* > + * Other PTE markers should be handled the same way as none PTE. > + * > * hugetlb_no_page will drop vma lock and hugetlb fault > * mutex internally, which make us return immediately. > */ > return hugetlb_no_page(mm, vma, mapping, idx, address, ptep, > entry, flags); > + } > > ret = 0; > > @@ -6253,6 +6263,25 @@ int hugetlb_mfill_atomic_pte(pte_t *dst_pte, > int writable; > bool folio_in_pagecache = false; > > + if (uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { > + ptl = huge_pte_lock(h, dst_mm, dst_pte); > + > + /* Don't overwrite any existing PTEs (even markers) */ > + if (!huge_pte_none(huge_ptep_get(dst_pte))) { > + spin_unlock(ptl); > + return -EEXIST; > + } > + > + _dst_pte = make_pte_marker(PTE_MARKER_UFFD_POISON); > + set_huge_pte_at(dst_mm, dst_addr, dst_pte, _dst_pte); > + > + /* No need to invalidate - it was non-present before */ > + update_mmu_cache(dst_vma, dst_addr, dst_pte); > + > + spin_unlock(ptl); > + return 0; > + } > + > if (is_continue) { > ret = -EFAULT; > folio = filemap_lock_folio(mapping, idx); > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 87b62ca1e09e..4436cae1c7a8 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -381,12 +381,8 @@ static __always_inline ssize_t mfill_atomic_hugetlb( > * supported by hugetlb. A PMD_SIZE huge pages may exist as used > * by THP. Since we can not reliably insert a zero page, this > * feature is not supported. > - * > - * PTE marker handling for hugetlb is a bit special, so for now > - * UFFDIO_POISON is not supported. > */ > - if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE) || > - uffd_flags_mode_is(flags, MFILL_ATOMIC_POISON)) { > + if (uffd_flags_mode_is(flags, MFILL_ATOMIC_ZEROPAGE)) { > mmap_read_unlock(dst_mm); > return -EINVAL; If we have the last patch declaring the feature bits and so on, IIUC we don'tt need this change back and forth. Other than that looks good. Thanks, > } > -- > 2.41.0.255.g8b1d071c50-goog > -- Peter Xu