From patchwork Wed Apr 28 22:50:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12230199 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 A83F0C433B4 for ; Wed, 28 Apr 2021 22:51:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A8856143F for ; Wed, 28 Apr 2021 22:51:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A8856143F 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 83AD96B0072; Wed, 28 Apr 2021 18:51:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8171C6B0073; Wed, 28 Apr 2021 18:51:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5A26B6B0074; Wed, 28 Apr 2021 18:51:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 3BBCB6B0072 for ; Wed, 28 Apr 2021 18:51:22 -0400 (EDT) Received: from smtpin39.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 0388A2C96 for ; Wed, 28 Apr 2021 22:51:22 +0000 (UTC) X-FDA: 78083273604.39.374565D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf10.hostedemail.com (Postfix) with ESMTP id E98ED40002C7 for ; Wed, 28 Apr 2021 22:51:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619650281; 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=qqKszEE/+R68ngYo71RnOXLGHoNHIK32QNLimL1RNSc=; b=IVJjk8NZi4QI+UO/1FOeHjxzw2ejbb0ZIc/r/fiv0OKlJ+WRJMEzXA+D53SluBhtlIAQgD nKvEYgj6REyIfhTXLha2f0RikE9LQlKXvD76N+a1UTjfqFDhl9R1+FB36T1lC20URP2Vab Ao4b3LzUFT1LuvoaoR7JgDEBNRXPxsY= 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-577-BBYZNn3rNjy8isENv0tApA-1; Wed, 28 Apr 2021 18:51:19 -0400 X-MC-Unique: BBYZNn3rNjy8isENv0tApA-1 Received: by mail-qt1-f200.google.com with SMTP id 10-20020ac8594a0000b02901b9f6ae286fso18193457qtz.23 for ; Wed, 28 Apr 2021 15:51:19 -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=qqKszEE/+R68ngYo71RnOXLGHoNHIK32QNLimL1RNSc=; b=monSuAwd9feBxQp/xjeagI1MrLdRcYnQlrW7/5+hXFEQQhg5kIVgd7blIiHO50gDHN O7uI4m7jYfn13s0pC1VFt+O5W8wqjpzER8kyEb3jnn0C7mqyT1r0XXESVKxCaOZvHyLO 6ZgHyOnL94MfNkAY1/2IXkN3xFLMCHfUy2094kRRT30VVzWx2PabTUbB9evV4ryUvuEp MVSs9EH5qBuKIBLNbXpLdLEqeez3Npt5eNgZ4ppB5giVgx5DtQXZ1/NLVJ2P7SyhLTuI CmvS8Grny+lcjJqI/rmut9mGrcqehqS4M4DTxybrM3baTXDW75x1P12fxNJ2qwW2AsFq zoTA== X-Gm-Message-State: AOAM532KduxVfbb+qABoqrSl2s4LW1Pqn8z9wR8PVJ5gFlZmOlr5wffj FN0JrKGcWlBztzilY4CPTFfNoO1L+vQ67yLypPTZtzPHig7Y32Cg8XqUEYWXBa3iB2zqXAaJfr9 MSh5o1ciWC9Xw+TQhRoJ+Bh4xtSLcqRL+6KWl+7WJUb15Q2lmfnV7lNk0RQXn X-Received: by 2002:a05:622a:94:: with SMTP id o20mr29753504qtw.158.1619650278450; Wed, 28 Apr 2021 15:51:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziX7HpqcsgsbqQA9N4s/mqNOzeFKuNqQnRXLynrFsn+2UQuu62PHd5dx6d2x3VzOCu4IwPXQ== X-Received: by 2002:a05:622a:94:: with SMTP id o20mr29753476qtw.158.1619650278187; Wed, 28 Apr 2021 15:51:18 -0700 (PDT) Received: from localhost.localdomain (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id 191sm897459qkk.31.2021.04.28.15.51.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 15:51:17 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , peterx@redhat.com, Mike Rapoport , Axel Rasmussen , Andrea Arcangeli , Hugh Dickins , "Kirill A . Shutemov" , Andrew Morton , Jerome Glisse Subject: [PATCH 3/6] mm/userfaultfd: Fix a few thp pmd missing uffd-wp bit Date: Wed, 28 Apr 2021 18:50:27 -0400 Message-Id: <20210428225030.9708-4-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210428225030.9708-1-peterx@redhat.com> References: <20210428225030.9708-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Queue-Id: E98ED40002C7 X-Stat-Signature: 8634adsnffghowx4rc8pj4ku3bxuansw X-Rspamd-Server: rspam02 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619650270-358158 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: These include: 1. When remove migration pmd entry, should keep the uffd-wp bit from swap pte. Note that we need to do this after setting write bit just in case we need to remove it. 2. When change huge pmd and convert write -> read migration entry, persist the same uffd-wp bit. 3. When convert pmd to swap entry, should drop the uffd-wp bit always. Signed-off-by: Peter Xu --- include/linux/swapops.h | 2 ++ mm/huge_memory.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/include/linux/swapops.h b/include/linux/swapops.h index d9b7c9132c2f6..7dd57303bb0c3 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -258,6 +258,8 @@ static inline swp_entry_t pmd_to_swp_entry(pmd_t pmd) if (pmd_swp_soft_dirty(pmd)) pmd = pmd_swp_clear_soft_dirty(pmd); + if (pmd_swp_uffd_wp(pmd)) + pmd = pmd_swp_clear_uffd_wp(pmd); arch_entry = __pmd_to_swp_entry(pmd); return swp_entry(__swp_type(arch_entry), __swp_offset(arch_entry)); } diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 20a4569895254..e6423fe11a8f2 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1823,6 +1823,8 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, newpmd = swp_entry_to_pmd(entry); if (pmd_swp_soft_dirty(*pmd)) newpmd = pmd_swp_mksoft_dirty(newpmd); + if (pmd_swp_uffd_wp(*pmd)) + newpmd = pmd_swp_mkuffd_wp(newpmd); set_pmd_at(mm, addr, pmd, newpmd); } goto unlock; @@ -3234,6 +3236,8 @@ void remove_migration_pmd(struct page_vma_mapped_walk *pvmw, struct page *new) pmde = pmd_mksoft_dirty(pmde); if (is_write_migration_entry(entry)) pmde = maybe_pmd_mkwrite(pmde, vma); + if (pmd_swp_uffd_wp(*pvmw->pmd)) + pmde = pmd_wrprotect(pmd_mkuffd_wp(pmde)); flush_cache_range(vma, mmun_start, mmun_start + HPAGE_PMD_SIZE); if (PageAnon(new))