Message ID | 20210115170907.24498-19-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 EE92EC433DB for <linux-mm@archiver.kernel.org>; Fri, 15 Jan 2021 17:10:02 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A90E62333E for <linux-mm@archiver.kernel.org>; Fri, 15 Jan 2021 17:10:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A90E62333E 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 E338A8D01AC; Fri, 15 Jan 2021 12:09:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E0AD18D01AA; Fri, 15 Jan 2021 12:09:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D022A8D01AC; Fri, 15 Jan 2021 12:09:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0253.hostedemail.com [216.40.44.253]) by kanga.kvack.org (Postfix) with ESMTP id 99A3C8D01AA for <linux-mm@kvack.org>; Fri, 15 Jan 2021 12:09:49 -0500 (EST) Received: from smtpin21.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 159D98792 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:49 +0000 (UTC) X-FDA: 77708646498.21.kite09_561648f27531 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin21.hostedemail.com (Postfix) with ESMTP id B4E871803978B for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:48 +0000 (UTC) X-HE-Tag: kite09_561648f27531 X-Filterd-Recvd-Size: 5175 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf27.hostedemail.com (Postfix) with ESMTP for <linux-mm@kvack.org>; Fri, 15 Jan 2021 17:09:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1610730587; 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=w6siyxttlu7KCpWlkxB4VjYp+yZ18KeXRH4qtrNiwZw=; b=CUlmXRNvtLBVK0Sacm668t5j2INSgakSXHRnxbl/PdKF+l27WBNFyannhnH59wEALoAfFI 6JRHaJoSYGI9oU5UVcMpoClbDdGmHgW76TuZ78tOwLL/ilguTSgNlPMwllviFH0DevbdwK GFTACjB2PGeanqB0Sq/046yYGZkO1Es= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-576-K8II2DFAOdCq0a9DAWHjCg-1; Fri, 15 Jan 2021 12:09:46 -0500 X-MC-Unique: K8II2DFAOdCq0a9DAWHjCg-1 Received: by mail-qk1-f199.google.com with SMTP id u17so8601469qku.17 for <linux-mm@kvack.org>; Fri, 15 Jan 2021 09:09:46 -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=w6siyxttlu7KCpWlkxB4VjYp+yZ18KeXRH4qtrNiwZw=; b=hpzVGaU3bx4wtCFQQYwS0pU4ifvyvdXDdudsX0frkt+DRE+Zuhcr2f3i8w2oQwER7U XoR5VhNaqds3MOrJjJVssZ4LKQJP3kVx+K/WQXOq8rGY+Ki0rPkfw8IZoOFNRGM3ZnvC BRizPK35YEEFq4C6lDnuSBN44VxWt8d6v4KIRc4DoYfSyrKZv5PFcjXsVRHuvdQ8B35o yhZBneqaCqWOfSnR5oOqngXi7Qt7sqezSEazkq5Mn1jbPeC/IV+7M2Jmv/4orTAoDW1L 5lrRtMVOd5z1cYBl9Q2Pb5naZkxetgA0bfB6RikqKXgEdstrn96hteFnfsJK/4tA2PuT tBMQ== X-Gm-Message-State: AOAM533T/G+BaZ88VTzfz/F8o6kCvrx9O9zus0rwE8felHnlWfkW4JEC UHAMG+P8Rt1dSCoGJIxhPpK7HJnyIyrgA4YMm3W5cLUHF/UlyF922CkYQBDgvKv83pfSx74Fdyx XOtnWca11Y3U= X-Received: by 2002:a37:4a4e:: with SMTP id x75mr13396449qka.89.1610730585802; Fri, 15 Jan 2021 09:09:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJy247OPfvvMBFwBHFtTUpj3tm1FUibXTgft3ZPmifm23yeptWRPKyFEZ5qXtk/qtx/VoM7IRQ== X-Received: by 2002:a37:4a4e:: with SMTP id x75mr13396416qka.89.1610730585574; Fri, 15 Jan 2021 09:09:45 -0800 (PST) Received: from localhost.localdomain ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id d123sm5187840qke.95.2021.01.15.09.09.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jan 2021 09:09:44 -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 18/30] hugetlb/userfaultfd: Hook page faults for uffd write protection Date: Fri, 15 Jan 2021 12:08:55 -0500 Message-Id: <20210115170907.24498-19-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/hugetlb.c b/mm/hugetlb.c index d029d938d26d..dcbbba53bd10 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -4544,6 +4544,25 @@ vm_fault_t hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma, if (unlikely(!pte_same(entry, huge_ptep_get(ptep)))) goto out_ptl; + /* Handle userfault-wp first, before trying to lock more pages */ + if (userfaultfd_pte_wp(vma, huge_ptep_get(ptep)) && + (flags & FAULT_FLAG_WRITE) && !huge_pte_write(entry)) { + struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .flags = flags, + }; + + spin_unlock(ptl); + if (pagecache_page) { + unlock_page(pagecache_page); + put_page(pagecache_page); + } + mutex_unlock(&hugetlb_fault_mutex_table[hash]); + i_mmap_unlock_read(mapping); + return handle_userfault(&vmf, VM_UFFD_WP); + } + /* * hugetlb_cow() requires page locks of pte_page(entry) and * pagecache_page, so here we need take the former one
Hook up hugetlbfs_fault() with the capability to handle userfaultfd-wp faults. We do this slightly earlier than hugetlb_cow() so that we can avoid taking some extra locks that we definitely don't need. Signed-off-by: Peter Xu <peterx@redhat.com> --- mm/hugetlb.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)