Message ID | 20210427161317.50682-13-peterx@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <SRS0=Z8q0=JY=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 81C38C433ED for <linux-mm@archiver.kernel.org>; Tue, 27 Apr 2021 16:13:53 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1046A613E7 for <linux-mm@archiver.kernel.org>; Tue, 27 Apr 2021 16:13:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1046A613E7 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 8FA856B0080; Tue, 27 Apr 2021 12:13:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 883E06B0081; Tue, 27 Apr 2021 12:13:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D8E86B0082; Tue, 27 Apr 2021 12:13:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0047.hostedemail.com [216.40.44.47]) by kanga.kvack.org (Postfix) with ESMTP id 46DED6B0080 for <linux-mm@kvack.org>; Tue, 27 Apr 2021 12:13:45 -0400 (EDT) Received: from smtpin35.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id F40295DE6 for <linux-mm@kvack.org>; Tue, 27 Apr 2021 16:13:44 +0000 (UTC) X-FDA: 78078642810.35.2594227 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf22.hostedemail.com (Postfix) with ESMTP id F11B1C0007FA for <linux-mm@kvack.org>; Tue, 27 Apr 2021 16:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619540024; 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=bJUKYR7hr17ohgPo/T1v5XQHyXxi59fVxEqscfG7/f8=; b=gKu26c/ZJyIzZSeJvI543OTWahwg0KTt2cTjsJEcQetRNCpzLT8FAqKbu5jslYQqunzxMH A9iR4I2dwa6T/XsLFszynZyAlKDVoWwBnebEUpcB7GtA2lsgPQYVfTTyaq/G5aUzfBylQ/ XgUFyvoBtFbOnoaKLoeZGEpT/9v1Ghg= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-tatHiBwYMC2Ht318Ycsy7A-1; Tue, 27 Apr 2021 12:13:42 -0400 X-MC-Unique: tatHiBwYMC2Ht318Ycsy7A-1 Received: by mail-qt1-f197.google.com with SMTP id b8-20020a05622a0208b02901b5b18f4f91so20772727qtx.18 for <linux-mm@kvack.org>; Tue, 27 Apr 2021 09:13:42 -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=bJUKYR7hr17ohgPo/T1v5XQHyXxi59fVxEqscfG7/f8=; b=iqlBlYV/vqOPBQ4j3J5v/QNtEaZkTLimm0cE38UiOpaDZeUBFRqFC1+sOaLT6Dc/4Y zE6PywcJUqzbhHBWDp8zIeWjSZGZ5oUcHEJVxkUBfh0YuLE72kH3dLx9jeFjWSk0ttUI ZWsKpnBrRU6lBiSD4dX+4iy3pmsOpfGSEKfp8crIrvILkuYSeIRvL53kXvutrhm/tzL4 YT06ldlO0bam00A/vs/XKQw7L3L3jhLZvyMVa85/EKjN3gPJxltKbq3v9kJFqwoxWP8w mZbSQNXkHcMjlPcmRj0obXWvxwp70zosYI4NGHONaqC83JRlsPD0hpT7N4FUXIoqcvUg 6C+w== X-Gm-Message-State: AOAM5330/hIE7Jx2Can4IBSHwb6df0/kfKQsOjuFjmnbQ4krtq8RbCsK 5HksyU5x+V4S+HQZ6sVuJaFT2VLG6fBsV+jD3+td03lgZJ3CdVWnPSk8UbGl9zJRYMh8w86CsMw cqM9tlBPh8au3A4qq9G9NBkhVsvjD1XbvkNcS/M/vAoAlHzaJ9l7iCtG7ng1y X-Received: by 2002:a37:a510:: with SMTP id o16mr5597698qke.306.1619540021761; Tue, 27 Apr 2021 09:13:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK0i3RBqZsx2OzwuTxGkQwSJmhVwmVOV/gMvcyErmc0haHIIYmda75zIZFKivMWbj/kuK6pA== X-Received: by 2002:a37:a510:: with SMTP id o16mr5597661qke.306.1619540021451; Tue, 27 Apr 2021 09:13:41 -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.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Apr 2021 09:13:40 -0700 (PDT) From: Peter Xu <peterx@redhat.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit <nadav.amit@gmail.com>, Miaohe Lin <linmiaohe@huawei.com>, Mike Rapoport <rppt@linux.vnet.ibm.com>, Andrea Arcangeli <aarcange@redhat.com>, Hugh Dickins <hughd@google.com>, peterx@redhat.com, Jerome Glisse <jglisse@redhat.com>, Mike Kravetz <mike.kravetz@oracle.com>, Jason Gunthorpe <jgg@ziepe.ca>, Matthew Wilcox <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, Axel Rasmussen <axelrasmussen@google.com>, "Kirill A . Shutemov" <kirill@shutemov.name> Subject: [PATCH v2 12/24] shmem/userfaultfd: Allows file-back mem to be uffd wr-protected on thps Date: Tue, 27 Apr 2021 12:13:05 -0400 Message-Id: <20210427161317.50682-13-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 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 Content-Type: text/plain; charset="US-ASCII" X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: F11B1C0007FA X-Stat-Signature: hceqskwthfexsqo64kesfik83n4gebp8 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf22; identity=mailfrom; envelope-from="<peterx@redhat.com>"; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619540017-293025 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 6b63e3544b470..51c954afa4069 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -296,8 +296,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(-)