Message ID | 20211115080048.74584-1-peterx@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <SRS0=Pe7y=QC=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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 949A4C433FE for <linux-mm@archiver.kernel.org>; Mon, 15 Nov 2021 08:01:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3CDC163218 for <linux-mm@archiver.kernel.org>; Mon, 15 Nov 2021 08:01:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3CDC163218 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id D40486B007D; Mon, 15 Nov 2021 03:01:06 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CEF5E6B007E; Mon, 15 Nov 2021 03:01:06 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB8D26B0080; Mon, 15 Nov 2021 03:01:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id AC4C86B007D for <linux-mm@kvack.org>; Mon, 15 Nov 2021 03:01:06 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 71B9C8249980 for <linux-mm@kvack.org>; Mon, 15 Nov 2021 08:01:06 +0000 (UTC) X-FDA: 78810418932.26.99C2694 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id D8B24801A8A8 for <linux-mm@kvack.org>; Mon, 15 Nov 2021 08:01:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636963265; 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=CT33CO1P4m9z3srlG1n5DsePRxe7FxchG1iBDIBzjEc=; b=Vv+rmHjmWBIATdCl3qzqdi4NPMq6fhB8zLJGeVCERxRPCuLPHs+Z36HnurlNK0KUJ+fsyU TfA20hNsHwbFW7+JEDJqzRXzkwhWLjSqhetJJEw+2O1vQ3yzMC0/pgGQ5Vp6L3H5qm1gYB 2Bs1e+hcjn1LYo5fcEr7JrARIADGfOE= Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-197-z_nWslYOMquK314kRVi8Bg-1; Mon, 15 Nov 2021 03:01:04 -0500 X-MC-Unique: z_nWslYOMquK314kRVi8Bg-1 Received: by mail-pf1-f199.google.com with SMTP id m16-20020a628c10000000b004a282d715b2so4192668pfd.11 for <linux-mm@kvack.org>; Mon, 15 Nov 2021 00:01:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CT33CO1P4m9z3srlG1n5DsePRxe7FxchG1iBDIBzjEc=; b=PZVsD4SPnvjrOn9YTuIDt7DvnRVUvEUFV/PrZOHzlOGKJ5//EKYo/skaeP+UTFRCVC 8VHGwq1WIDRUkVp8ZDLbc3wmuClHN6D2/ZfTnJ1e8j3vDTeN7QRjHNRpvTSWhK8N0OSu 5cmkwGh2IA+C5hW4pcZ+rDnaBCAfQrPNW5XCCwMFx32gHRwEBTMp394+b+9KBNl9gLUS zMBLD/0nuxrnxG7HjyMggCdrLo/EhZeZdaqPDxHiK75rVrx2qSliz982Hx1DynKcYCpD mmrH0OvQpqiiRUDRtuci7pmRiFmhDL0cj3nSCfFecNySNhk+wdYfrgIPaRhBoLUtEebQ gryg== X-Gm-Message-State: AOAM532PfE2JPbptxDBqJUDduz+5AaTG2h46/lYqtD78ZYjobdQikrP+ eHaNrzNjx7NjEzYBdDwiOlEO/ofdk6BxEGAVqDa57OGhDuD7nHCriwFM6UMtJyLUn2y8Ue31Byx FlnlPi1qxc6rOtAPBboOtwBw6mDB1r43gw2gjiDCC68uKsxUt9MOq9HymaP7J X-Received: by 2002:a17:90a:e60a:: with SMTP id j10mr63679980pjy.169.1636963262812; Mon, 15 Nov 2021 00:01:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJw5fbAzVfzXaTeCmw8VY664lWE42EUqztZ2N89jbHIauCly+ZiaTzVAzB2oLqZABMH3u9HTaw== X-Received: by 2002:a17:90a:e60a:: with SMTP id j10mr63679926pjy.169.1636963262451; Mon, 15 Nov 2021 00:01:02 -0800 (PST) Received: from localhost.localdomain ([94.177.118.89]) by smtp.gmail.com with ESMTPSA id rj8sm2841393pjb.0.2021.11.15.00.00.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Nov 2021 00:01:01 -0800 (PST) From: Peter Xu <peterx@redhat.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Nadav Amit <nadav.amit@gmail.com>, peterx@redhat.com, Alistair Popple <apopple@nvidia.com>, Andrew Morton <akpm@linux-foundation.org>, Mike Kravetz <mike.kravetz@oracle.com>, Mike Rapoport <rppt@linux.vnet.ibm.com>, Matthew Wilcox <willy@infradead.org>, Jerome Glisse <jglisse@redhat.com>, Axel Rasmussen <axelrasmussen@google.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, David Hildenbrand <david@redhat.com>, Andrea Arcangeli <aarcange@redhat.com>, Hugh Dickins <hughd@google.com> Subject: [PATCH v6 09/23] mm/shmem: Allows file-back mem to be uffd wr-protected on thps Date: Mon, 15 Nov 2021 16:00:48 +0800 Message-Id: <20211115080048.74584-1-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211115075522.73795-1-peterx@redhat.com> References: <20211115075522.73795-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: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Vv+rmHjm; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D8B24801A8A8 X-Stat-Signature: 1r4ib184zwt7ndkkipz5hjyw4aiqysrt X-HE-Tag: 1636963265-732335 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 be837c4dbc64..0d4bf755cee8 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -319,8 +319,15 @@ 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_wp_protect_file(vma, cp_flags)) { __split_huge_pmd(vma, pmd, addr, false, NULL); + /* + * For file-backed, the pmd could have been + * cleared; make sure pmd populated if + * necessary, then fall-through to pte level. + */ + change_pmd_prepare(vma, pmd, cp_flags); } else { int nr_ptes = change_huge_pmd(vma, pmd, addr, newprot, cp_flags);
We don't have "huge" version of pte markers, instead when necessary we split the thp. 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 cleared in __split_huge_pmd_locked(). That is 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, and change_pmd_range() will just skip it right after the split. Here we leverage the previously introduced change_pmd_prepare() macro so that we'll populate the pmd with a pgtable page after the pmd split (in which process the pmd will be cleared for cases like shmem). Then change_pte_range() will do all the rest for us by installing the uffd-wp pte marker at any none pte that we'd like to wr-protect. Signed-off-by: Peter Xu <peterx@redhat.com> --- mm/mprotect.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)