Message ID | 20220304051708.86193-10-peterx@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show
Return-Path: <owner-linux-mm@kvack.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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 406EFC433FE for <linux-mm@archiver.kernel.org>; Fri, 4 Mar 2022 05:18:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D76738D0002; Fri, 4 Mar 2022 00:18:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D257E8D0001; Fri, 4 Mar 2022 00:18:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEFB48D0002; Fri, 4 Mar 2022 00:18:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.27]) by kanga.kvack.org (Postfix) with ESMTP id B24BF8D0001 for <linux-mm@kvack.org>; Fri, 4 Mar 2022 00:18:40 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8D0B0607EF for <linux-mm@kvack.org>; Fri, 4 Mar 2022 05:18:40 +0000 (UTC) X-FDA: 79205548800.04.209FC0D Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf05.hostedemail.com (Postfix) with ESMTP id EA1AE100006 for <linux-mm@kvack.org>; Fri, 4 Mar 2022 05:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646371119; 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=cWQZRYNGI2cSzJcmY2NeIfodfPZX4V25Mo1spySEF5s=; b=DY1ane5qIndpnSkPRvPltE7BZBl1rxjHQgGdPuuQCgTyb+0iK0eia0XvP/VDzbciplZlWH c0UIYJyxQ6ttjMwQTnIp4CopBa2RkePIBJow28eixzTTjyR5shctryaFbZqdRPefzcWFxZ gk8WVUdN7Uo1owuEx/BcIJYkeRw1iU0= Received: from mail-pg1-f199.google.com (mail-pg1-f199.google.com [209.85.215.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-166-BxG1HIjCOzWmAjAYZtGFBQ-1; Fri, 04 Mar 2022 00:18:36 -0500 X-MC-Unique: BxG1HIjCOzWmAjAYZtGFBQ-1 Received: by mail-pg1-f199.google.com with SMTP id bm16-20020a656e90000000b00372932b1d83so3904542pgb.10 for <linux-mm@kvack.org>; Thu, 03 Mar 2022 21:18:36 -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=cWQZRYNGI2cSzJcmY2NeIfodfPZX4V25Mo1spySEF5s=; b=f3o/W2fZvwiqIDXwz0F2GNPzPc+LiYnAeNGDwOb1iv0b1iirzx/GND5O7cV/SMx4N5 1jZIs6Q5cgscmtgL9LIYUccZUfyzXb+ek2KM8+94bsEPErcr8dAi+5Z5VaMr7ekE3iAY ZR40H2LqPGhASrJlbtoKHS5xgSgCi/Mjq61VdSuhsMUZTrL0ESuM2EtMm6wAzVte2fqU KZ8zWfEZKFyOt0ZpHYRpqAJDf3aIcHxGAOKVvZmVFmjuYeOAz2EvnktuzQJkjC18EYz7 POTm68Q5p94UiCrGeKSWv4TljTtdvm4wJqsJzoVb5l0x12gBn9GXBubgUkqdhL27z3fl ag8Q== X-Gm-Message-State: AOAM5313X4cDEduWQSHJJIajR1M3UMXzh9QUtMQBv60HVnfT8a+cKZVN fyYcPjeuQGmHVVEiaBSiJiFLQOpO2vENdFZueSXWB55Cr5uCvi23TN2t0xM2Yxq9Rix8nbOEu8w GeXt7/hiyaJnFxvNfJnJEjK8dITCp0r4v3Cq17WSmH100Iaq73CzUH/6p8zql X-Received: by 2002:a63:af02:0:b0:375:57f0:8af1 with SMTP id w2-20020a63af02000000b0037557f08af1mr32843647pge.188.1646371115511; Thu, 03 Mar 2022 21:18:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJx4jOImxHShOaqYtf+LhwSwkfO4VXJz5d+7rIaM+Vv6wcTRt41/dvgoYP9dxEas9oL3cZidzQ== X-Received: by 2002:a63:af02:0:b0:375:57f0:8af1 with SMTP id w2-20020a63af02000000b0037557f08af1mr32843618pge.188.1646371115135; Thu, 03 Mar 2022 21:18:35 -0800 (PST) Received: from localhost.localdomain ([94.177.118.59]) by smtp.gmail.com with ESMTPSA id p16-20020a056a000b5000b004f669806cd9sm4323865pfo.87.2022.03.03.21.18.27 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Mar 2022 21:18:34 -0800 (PST) From: Peter Xu <peterx@redhat.com> To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: peterx@redhat.com, Nadav Amit <nadav.amit@gmail.com>, Hugh Dickins <hughd@google.com>, David Hildenbrand <david@redhat.com>, Axel Rasmussen <axelrasmussen@google.com>, Matthew Wilcox <willy@infradead.org>, Alistair Popple <apopple@nvidia.com>, Mike Rapoport <rppt@linux.vnet.ibm.com>, Andrew Morton <akpm@linux-foundation.org>, Jerome Glisse <jglisse@redhat.com>, Mike Kravetz <mike.kravetz@oracle.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, Andrea Arcangeli <aarcange@redhat.com> Subject: [PATCH v7 09/23] mm/shmem: Allows file-back mem to be uffd wr-protected on thps Date: Fri, 4 Mar 2022 13:16:54 +0800 Message-Id: <20220304051708.86193-10-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220304051708.86193-1-peterx@redhat.com> References: <20220304051708.86193-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" X-Rspamd-Queue-Id: EA1AE100006 X-Stat-Signature: fanp5o4twg569pi5z4hofpairrphnjcd X-Rspam-User: Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DY1ane5q; spf=none (imf05.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam07 X-HE-Tag: 1646371119-524919 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 4878b6b99df9..95b307d4766d 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -329,8 +329,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(-)