Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4643268pxy; Tue, 27 Apr 2021 09:25:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/6HZ5eiyQcufOw8VyWg/WlEUoZ8HcIFgACNOSscxH6BdOwO/QxgqWb4c2JBUsMuH+s0cF X-Received: by 2002:a17:906:1fca:: with SMTP id e10mr12028380ejt.486.1619540708957; Tue, 27 Apr 2021 09:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619540708; cv=none; d=google.com; s=arc-20160816; b=aKFCswY1+5tQBfJ1TLzh2Lmm2SvG0zsHccp0cGHnNQAE2EWBkNhoEPCgHYCLvv+98r vhhknTSHd7pzwCzKk78IfaJrd+f6I4P5pf7mp5EoWGPnDuvfhSThDDtX96NX9qlfuw49 mNPC2wcMvv5/PFZWEwkN2FsLMXvJo2Uykh8ptsPNY0x73XaUuRMiSXTuXqJinjmZXBIu 8o7ovdw8Q34gIO9kMy7YL/Vf33TpEjaui6pwZm8Adn0VCHDI3lSb+tDlL1uM7C+ohD7q UPInWK30AnjMmGvvtXxyCQIX2nTGxOZhu3bvHEReaqwMBv3LhDAIGkqQdd0OVMca5e9D gXbw== 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=dXTRKapTK7xkWfcmUhC675oNCWp18cl/MiRtGAKeqgk=; b=kDcFEAiWDNE1Kti2Ptm9lBr9LzdBf/h7fOfAAhECCmBtF6MOG2kcIGPQQU9ZGfWrVn EigFVRB3QAb5PYyFhZ0USkuHBOcIifMf5/TVEaryCX/O5tXvM3EMOdRzdvNqNfruJAWi 7VAT6G9MJ+8xSPel6wns5jqjbcBmZSaptZgF4IYeu7FTEPP08p6I9UFP6wflFApoYnVZ ZJzPGn66Oz9aTs8XzHj1dVtpj0l8dDWiZM62bqpg07PNeDSB2KfqDjW9KFd7+hhwJiXj TSiNDEDUVjeMw/oJ7nZMkMt14aIRYJpPHeMn7VEh5TW0w1V534j4CSsMP0HGTpMRsy14 hpCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X6Q84FGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p22si270497ejg.624.2021.04.27.09.24.45; Tue, 27 Apr 2021 09:25:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X6Q84FGV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S236641AbhD0QYc (ORCPT + 99 others); Tue, 27 Apr 2021 12:24:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:37460 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237577AbhD0QOb (ORCPT ); Tue, 27 Apr 2021 12:14:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619540027; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dXTRKapTK7xkWfcmUhC675oNCWp18cl/MiRtGAKeqgk=; b=X6Q84FGVoIVNQ7NBaxrHHTRXfwpHm3g09NDkkKRlOxlb3sWhNfVCqMPQCtXShYIT56BMmF BF0e1OR0ZAbj2IdTzO4Otpje6W4H+7sP0hNbgs0xofsttXGOYKcSjpTK7/ZioD3dK6+kmu PGQGlMbozEHhHIi+D7I3+kvJ0S6fjeU= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-342-7_1jmiv8Oa-BisvjxeRExw-1; Tue, 27 Apr 2021 12:13:45 -0400 X-MC-Unique: 7_1jmiv8Oa-BisvjxeRExw-1 Received: by mail-qt1-f199.google.com with SMTP id b8-20020a05622a0208b02901b5b18f4f91so20772819qtx.18 for ; Tue, 27 Apr 2021 09:13:45 -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=dXTRKapTK7xkWfcmUhC675oNCWp18cl/MiRtGAKeqgk=; b=CjetkRmnAaPaw94LTXf9x/GCwFAwTZGZtvajMavOPYYhalJ+s4dHpEbQb0CQsGVibO Axq9b2odtL3elXTIslQ2RJpBnStS7+1hh5BFfGMKutTZIMgdTccT5DCGVWjUGUU4pKS8 f6IUkisvSexwBciURHbxMwMV8ASUCzAKgiVLRfAPOAB1CeLGCYWbgVDlsfqihKPivMEk EY1D4vZVhMngwiZw8ezELih/bJXidH91aXEmE+IN3x6/Q8+9umYSqDG3T8GDk5F1BFkq fzmU3I+LEys2Jmy/l+wH2x5LtCBkZbAGDSkPe5nrcWZ8dxitmvC+rOwww0U8ENCl6RrV FzRQ== X-Gm-Message-State: AOAM531NJX7cYzh+CAtxett3CM28Jwvlit2rpkJLq74VrGQaoq2WzTzx TXTPSjKFmIeWXuKMK9rWeMHLGgsWqzv+0Clb9beayGuT79/FB6o6Z8vyk1CGtTlhRMogmulAx8s J+lKj0qeMU9rCXTxT3RsswBEO X-Received: by 2002:a37:390:: with SMTP id 138mr23732925qkd.136.1619540024996; Tue, 27 Apr 2021 09:13:44 -0700 (PDT) X-Received: by 2002:a37:390:: with SMTP id 138mr23732903qkd.136.1619540024751; Tue, 27 Apr 2021 09:13:44 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id v66sm3103621qkd.113.2021.04.27.09.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 09:13:44 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit , Miaohe Lin , Mike Rapoport , Andrea Arcangeli , Hugh Dickins , peterx@redhat.com, Jerome Glisse , Mike Kravetz , Jason Gunthorpe , Matthew Wilcox , Andrew Morton , Axel Rasmussen , "Kirill A . Shutemov" Subject: [PATCH v2 14/24] shmem/userfaultfd: Pass over uffd-wp special swap pte when fork() Date: Tue, 27 Apr 2021 12:13:07 -0400 Message-Id: <20210427161317.50682-15-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210427161317.50682-1-peterx@redhat.com> References: <20210427161317.50682-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 872fb59192277..f1cdc613b5887 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -715,8 +715,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 entry.val; -- 2.26.2