From patchwork Wed Jul 14 22:24:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12377967 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6B68C1B08C for ; Wed, 14 Jul 2021 22:24:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8D87B613C9 for ; Wed, 14 Jul 2021 22:24:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D87B613C9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DE5E96B00C3; Wed, 14 Jul 2021 18:24:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DBCFA6B00C4; Wed, 14 Jul 2021 18:24:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C36E06B00C5; Wed, 14 Jul 2021 18:24:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0043.hostedemail.com [216.40.44.43]) by kanga.kvack.org (Postfix) with ESMTP id A132E6B00C3 for ; Wed, 14 Jul 2021 18:24:55 -0400 (EDT) Received: from smtpin36.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 8ABB2184799F3 for ; Wed, 14 Jul 2021 22:24:54 +0000 (UTC) X-FDA: 78362624508.36.F3A0994 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 36605D0000A4 for ; Wed, 14 Jul 2021 22:24:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626301493; 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=l/r2tEksA7iAG8svGDApMzfpTe7AXzjcSqF0fovWgO0=; b=RJbrB6Bgp7xAH3ltkdtkyxjq4e2mVkPetCuJ+kPAqcNv/939JYkDTEWbzezsdTyd4bb++E vcWiNI5RAH4M7n3E+fjv8rgn6iuYaPJ0zMn1jCOzREm9ulQn0ddGvH36I6ddf3B3teZMc2 yjf+JGAeIx3d+uOhdK1DwDahwyxuzXk= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-587-mAuTaMZVOYqoBpG6VfAV9g-1; Wed, 14 Jul 2021 18:24:50 -0400 X-MC-Unique: mAuTaMZVOYqoBpG6VfAV9g-1 Received: by mail-qt1-f200.google.com with SMTP id b6-20020a05622a0206b029025eb726dd9bso389344qtx.8 for ; Wed, 14 Jul 2021 15:24:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=l/r2tEksA7iAG8svGDApMzfpTe7AXzjcSqF0fovWgO0=; b=WaD2vGPju4kJR/nnL9QBhH7XeKhWEPkImCqjzGq4ovsoYF62Hi3LBhpP/aHuQInLsF zqZs/7RF9LHn3vp3l769SkJp+ijyRAohm8lsAfGpNmt79R2Yzk+TkvijbctD06qiO6IT Fb5OtmrqB7b6IpR4s1rWtZmAlzA6D7Rn9BKPOUl3wu/BhL5R6Q3qZtwAtT0bkF0fysMb Oqfp2cNrUog9kx4Cb03DsS6BvxHATDmeyoV9p0OI6lL0i+ychU4xHmhbSG4WUR7h+B1/ /0y3Cq5El/+0mKORC7kN/A2BDFmVqlOwtjUIZEpuP5hqs00CE4VPxaIA40PIHS9d9Cr0 5CTw== X-Gm-Message-State: AOAM532+5UX9DLIDliNch7cCPF35y7HpW0fOFqPF8KCydO8eeBo+MPG5 zoY+72iOfmzH63G0FoJPUbp7AvQCr/TpG2wxPiGnRYvpAZsl7s67DCaY7hLruYdt8YVwKEdNZpD ApkQmXFcVHYtnasz4BmAlRLOWI0u1X8As4LIAcNpp9lg7HJorS/fTH7zyIkUd X-Received: by 2002:ac8:764e:: with SMTP id i14mr320346qtr.247.1626301490117; Wed, 14 Jul 2021 15:24:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxke+1R9jvCzeFeO4Xhy524xOIxKblC2IZ31epDh9hl1os1ZvwizYxkPAeMEaZbjJZGzGEjNQ== X-Received: by 2002:ac8:764e:: with SMTP id i14mr320312qtr.247.1626301489853; Wed, 14 Jul 2021 15:24:49 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-65-184-144-111-238.dsl.bell.ca. [184.144.111.238]) by smtp.gmail.com with ESMTPSA id u184sm1655517qkd.53.2021.07.14.15.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Jul 2021 15:24:49 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Andrew Morton , Mike Kravetz , Axel Rasmussen , Miaohe Lin , "Kirill A . Shutemov" , Hugh Dickins , Jason Gunthorpe , Alistair Popple , Matthew Wilcox , peterx@redhat.com, Jerome Glisse , Andrea Arcangeli , Mike Rapoport , Nadav Amit , David Hildenbrand Subject: [PATCH v4 14/26] shmem/userfaultfd: Pass over uffd-wp special swap pte when fork() Date: Wed, 14 Jul 2021 18:24:46 -0400 Message-Id: <20210714222446.48788-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210714222117.47648-1-peterx@redhat.com> References: <20210714222117.47648-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=RJbrB6Bg; spf=none (imf20.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam05 X-Stat-Signature: j3oeaedonf6pm94ihyfjoke5b4m5dk9b X-Rspamd-Queue-Id: 36605D0000A4 X-HE-Tag: 1626301494-257948 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: It should be handled similarly like other uffd-wp wr-protected ptes: we should pass it over when the dst_vma has VM_UFFD_WP armed, otherwise drop it. Signed-off-by: Peter Xu --- mm/memory.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mm/memory.c b/mm/memory.c index 223781f115e9..af91bee934c7 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -776,8 +776,21 @@ copy_nonpresent_pte(struct mm_struct *dst_mm, struct mm_struct *src_mm, unsigned long vm_flags = dst_vma->vm_flags; pte_t pte = *src_pte; struct page *page; - swp_entry_t entry = pte_to_swp_entry(pte); + swp_entry_t entry; + + if (unlikely(is_swap_special_pte(pte))) { + /* + * uffd-wp special swap pte is the only possibility for now. + * If dst vma is registered with uffd-wp, copy it over. + * Otherwise, ignore this pte as if it's a none pte would work. + */ + WARN_ON_ONCE(!pte_swp_uffd_wp_special(pte)); + if (userfaultfd_wp(dst_vma)) + set_pte_at(dst_mm, addr, dst_pte, pte); + return 0; + } + entry = pte_to_swp_entry(pte); if (likely(!non_swap_entry(entry))) { if (swap_duplicate(entry) < 0) return -EIO;