Message ID | 20210715201602.211496-1-peterx@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <SRS0=osCV=MH=kvack.org=owner-linux-mm@kernel.org> 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 5EA88C636C8 for <linux-mm@archiver.kernel.org>; Thu, 15 Jul 2021 20:16:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0C952613C4 for <linux-mm@archiver.kernel.org>; Thu, 15 Jul 2021 20:16:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C952613C4 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 6F6CB8D00FF; Thu, 15 Jul 2021 16:16:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CE678D00EC; Thu, 15 Jul 2021 16:16:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5471D8D00FF; Thu, 15 Jul 2021 16:16:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 317428D00EC for <linux-mm@kvack.org>; Thu, 15 Jul 2021 16:16:09 -0400 (EDT) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 133931858B2A3 for <linux-mm@kvack.org>; Thu, 15 Jul 2021 20:16:08 +0000 (UTC) X-FDA: 78365928816.21.4BC1338 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf04.hostedemail.com (Postfix) with ESMTP id AE5ED50000A2 for <linux-mm@kvack.org>; Thu, 15 Jul 2021 20:16:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1626380167; 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=ltWxXgdsERQEx3E6ySA6em4pDoRaSyrvcOj0w7z20l8=; b=g/zypMast2po+aUSeei2tsMiMvoRzbAG68IUtyokNk05XF8RRAwOCFFqGJCKhl37RnBJGe nolsurXVXgXBvQ0Al6JINwIiBkPyIMZUQHbrivi/gfm4MbM91szuxLPl0Ig73XQ9LoJLhK WiJIc72kzAvsomhMAigRf1fuPQ58HSI= 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-313-MUpIF3McPjuRfpAetNjtLA-1; Thu, 15 Jul 2021 16:16:06 -0400 X-MC-Unique: MUpIF3McPjuRfpAetNjtLA-1 Received: by mail-qt1-f199.google.com with SMTP id d9-20020ac84e290000b0290256a44e9034so4870712qtw.22 for <linux-mm@kvack.org>; Thu, 15 Jul 2021 13:16:06 -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=ltWxXgdsERQEx3E6ySA6em4pDoRaSyrvcOj0w7z20l8=; b=ega3ksRV8KCaa4f6qVAmE+yRLs4DiMLXJCzTTiNpx301+11k99vr1YkW1ZKp7+VG5h NIgTOn78dv/fJIUz8oyt+q2z/8ho2OLs3nLyLsvaRl7Dr3JtNkpefqVysRx6itjuDr3c SloMD6I9F8NXEBRN6Gbm4LQx5PiBmi3EBXSWzuTRPwhvcXtgAvxBjhtOsjrYA02Se3YY 3Ezp+58Y1qiCRm98lYw2arKw7KZHIDANLuMDwRVGcpEDiJ+DsJOkVn9MjboGDv11c+Gn 8fwv3hSgJe0oAZ9AcTLuUgnA8iOf6Z4E/cns6hzmQ9ZSRClv5y8dqHCgABtGnoolHsqh kevw== X-Gm-Message-State: AOAM533WfLtQ+JqeSaHG51+IkmHiL/jtqSTE+t1p8jdlHzu1LVVJUuej sKyaNHa3v/aqjeUShExK2qEell35yYYMhs2uwiPsgarpu7Pd/tqLLAA1oFZVKhGpO3g5zmeYA3k 7GydH84Jp2SI= X-Received: by 2002:a05:620a:1eb:: with SMTP id x11mr5686346qkn.16.1626380165724; Thu, 15 Jul 2021 13:16:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTC10tfMm3pV49bd4wppQjkiX3paXGPpQYHfxNtmjnsg+u4bX3Eh1j3I/WypQ2MQKfcLIqUg== X-Received: by 2002:a05:620a:1eb:: with SMTP id x11mr5686323qkn.16.1626380165505; Thu, 15 Jul 2021 13:16:05 -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 j65sm3147909qkd.17.2021.07.15.13.16.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jul 2021 13:16:05 -0700 (PDT) From: Peter Xu <peterx@redhat.com> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Axel Rasmussen <axelrasmussen@google.com>, Nadav Amit <nadav.amit@gmail.com>, Jerome Glisse <jglisse@redhat.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, Jason Gunthorpe <jgg@ziepe.ca>, Alistair Popple <apopple@nvidia.com>, Andrew Morton <akpm@linux-foundation.org>, David Hildenbrand <david@redhat.com>, peterx@redhat.com, Andrea Arcangeli <aarcange@redhat.com>, Matthew Wilcox <willy@infradead.org>, Mike Kravetz <mike.kravetz@oracle.com>, Tiberiu Georgescu <tiberiu.georgescu@nutanix.com>, Hugh Dickins <hughd@google.com>, Miaohe Lin <linmiaohe@huawei.com>, Mike Rapoport <rppt@linux.vnet.ibm.com> Subject: [PATCH v5 12/26] shmem/userfaultfd: Allows file-back mem to be uffd wr-protected on thps Date: Thu, 15 Jul 2021 16:16:02 -0400 Message-Id: <20210715201602.211496-1-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715201422.211004-1-peterx@redhat.com> References: <20210715201422.211004-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="g/zypMas"; spf=none (imf04.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: rspam03 X-Rspamd-Queue-Id: AE5ED50000A2 X-Stat-Signature: 51h6ex6tmyr48zeuu7fhegruiwwfj9af X-HE-Tag: 1626380167-319966 Content-Transfer-Encoding: quoted-printable 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: <linux-mm.kvack.org> |
Series |
userfaultfd-wp: Support shmem and hugetlbfs
|
expand
|
diff --git a/mm/mprotect.c b/mm/mprotect.c index 8ec85b276975..3fcb87b59696 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -306,8 +306,16 @@ static inline unsigned long change_pmd_range(struct vm_area_struct *vma, } if (is_swap_pmd(*pmd) || pmd_trans_huge(*pmd) || pmd_devmap(*pmd)) { - if (next - addr != HPAGE_PMD_SIZE) { + if (next - addr != HPAGE_PMD_SIZE || + /* Uffd wr-protecting a file-backed memory range */ + unlikely(!vma_is_anonymous(vma) && + (cp_flags & MM_CP_UFFD_WP))) { __split_huge_pmd(vma, pmd, addr, false, NULL); + /* + * For file-backed, the pmd could have been + * gone; still provide a pte pgtable if needed. + */ + change_protection_prepare(vma, pmd, addr, cp_flags); } else { int nr_ptes = change_huge_pmd(vma, pmd, addr, newprot, cp_flags);
We don't have "huge" version of PTE_SWP_UFFD_WP_SPECIAL, instead when necessary we split the thp if the huge page is uffd wr-protected previously. However split the thp is not enough, because file-backed thp is handled totally differently comparing to anonymous thps - rather than doing a real split, the thp pmd will simply got dropped in __split_huge_pmd_locked(). That is definitely not enough if e.g. when there is a thp covers range [0, 2M) but we want to wr-protect small page resides in [4K, 8K) range, because after __split_huge_pmd() returns, there will be a none pmd. Here we leverage the previously introduced change_protection_prepare() macro so that we'll populate the pmd with a pgtable page. Then change_pte_range() will do all the rest for us, e.g., install the uffd-wp swap special pte marker at any pte that we'd like to wr-protect, under the protection of pgtable lock. Signed-off-by: Peter Xu <peterx@redhat.com> --- mm/mprotect.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)