Message ID | 20210115170907.24498-16-peterx@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show
Return-Path: <SRS0=uEqb=GS=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 68DDFC433DB for <linux-mm@archiver.kernel.org>; Fri, 15 Jan 2021 17:09:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 144FE222B3 for <linux-mm@archiver.kernel.org>; Fri, 15 Jan 2021 17:09:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 144FE222B3 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 7A4C18D01A9; Fri, 15 Jan 2021 12:09:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 77E9F8D01A4; Fri, 15 Jan 2021 12:09:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 66B9A8D01A9; Fri, 15 Jan 2021 12:09:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0178.hostedemail.com [216.40.44.178]) by kanga.kvack.org (Postfix) with ESMTP id 513A58D01A4 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 12:09:44 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 15871181AEF39 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:44 +0000 (UTC) X-FDA: 77708646288.29.women17_451859827531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin29.hostedemail.com (Postfix) with ESMTP id 4DC51181894E5 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:43 +0000 (UTC) X-HE-Tag: women17_451859827531 X-Filterd-Recvd-Size: 5787 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf41.hostedemail.com (Postfix) with ESMTP for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730582; 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=dvgubUamx9bzZRkUGwNzgfOj+y21NKvpsf3CqKI90Qc=; b=PP1T9fZZW0+El3M7TpwnIwynr4Y2CKuyq7PYQ20iz1R+30+7RYWFzi/ihPiUMrEsG5ktez 8n2/TtHBVqEpeb3qaECQEe8vqZ3jz5SOSYM4p1lIZZNdn1i07ea1d2kEfjn5VAvpUZVD9I Ydqmayi9juP00d4710/YLq+4WFxeGEY= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-480-ConrXKx9NBWgBqjmnTrfAA-1; Fri, 15 Jan 2021 12:09:40 -0500 X-MC-Unique: ConrXKx9NBWgBqjmnTrfAA-1 Received: by mail-qv1-f71.google.com with SMTP id l7so8260056qvp.15 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 09:09:40 -0800 (PST) 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=dvgubUamx9bzZRkUGwNzgfOj+y21NKvpsf3CqKI90Qc=; b=Z/tT/jI72mngBaPYfzloGH18MbIOBXfS+XXwaiwfKS3321emyGb7crGfBE8DhJqtCK tXglY6vqND0WPhHWuFhbh67ZN6W3x81klGwm8ZugpG1PSoMhU2kxmFPglPJu261H/9fI 4WggRjF46KsAglVyKd0emfpTQTL8x58ZTiaRnAvjsiTRHm1AjGtTblQ91vvJFxP0HmXi 8wD3t+7BQDGkzuv/4aCIW5VRpnLKR+ZROAgyXQTTUiQ+jY86/eAofLQvc4XAMhFWpzGw 5s8bhHpwUqG+cdGGvRUgx3Fixl07Oa+NoHVqlhxb3ruhY8SycGtwy1CSqcWpSbkRPfoK O4Ug== X-Gm-Message-State: AOAM532/0NHFKsyVAiq04PNCR+seKVa78c5oBcZzLpdJliZnkbJYX+qp ESDCsTKYO+3wyfFWPNnWkJpdEcww8BWIz8Si9YZ8u0fN41RxoX1pyJq0+v6ms5J495cPtoZ+1mU Xd9vKEsaZ5V4= X-Received: by 2002:a37:aa57:: with SMTP id t84mr13905356qke.348.1610730579783; Fri, 15 Jan 2021 09:09:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJypFNWmfzxwqGMAMXQdAVCpNR1NUiGkMMax+RIf/niA0GkwrkuRQrPyK91eLGDjgdLHnbwTGA== X-Received: by 2002:a37:aa57:: with SMTP id t84mr13905333qke.348.1610730579535; Fri, 15 Jan 2021 09:09:39 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d123sm5187840qke.95.2021.01.15.09.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:09:38 -0800 (PST) From: Peter Xu <peterx@redhat.com> To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Mike Rapoport <rppt@linux.vnet.ibm.com>, Mike Kravetz <mike.kravetz@oracle.com>, peterx@redhat.com, Jerome Glisse <jglisse@redhat.com>, "Kirill A . Shutemov" <kirill@shutemov.name>, Hugh Dickins <hughd@google.com>, Axel Rasmussen <axelrasmussen@google.com>, Matthew Wilcox <willy@infradead.org>, Andrew Morton <akpm@linux-foundation.org>, Andrea Arcangeli <aarcange@redhat.com>, Nadav Amit <nadav.amit@gmail.com> Subject: [PATCH RFC 15/30] shmem/userfaultfd: Allows file-back mem to be uffd wr-protected on thps Date: Fri, 15 Jan 2021 12:08:52 -0500 Message-Id: <20210115170907.24498-16-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210115170907.24498-1-peterx@redhat.com> References: <20210115170907.24498-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" 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 c9390fd673fe..055871322007 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(-)