Message ID | 20220304051708.86193-13-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 5011DC433EF for <linux-mm@archiver.kernel.org>; Fri, 4 Mar 2022 05:19:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E87288D0006; Fri, 4 Mar 2022 00:19:02 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E37518D0001; Fri, 4 Mar 2022 00:19:02 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFEBF8D0006; Fri, 4 Mar 2022 00:19:02 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id C36518D0001 for <linux-mm@kvack.org>; Fri, 4 Mar 2022 00:19:02 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 939FB2082C for <linux-mm@kvack.org>; Fri, 4 Mar 2022 05:19:02 +0000 (UTC) X-FDA: 79205549724.11.FF8FE77 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 05A584000D for <linux-mm@kvack.org>; Fri, 4 Mar 2022 05:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646371141; 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=n7rwO48JtzdkJuoHFZCI8H9KL9Pu0D4gPtoWSB8Kejg=; b=DR+OXZwEIbK4zFpJNB3sUIk0XVIPKbH/6dxa1+s3V510mqYhIysXBxJfUe3Qbaj8dS7gs5 h8UZDldlEDZXm+fG/C2FkCin24MvweSAVCVmTCPFTiaTEerlVzFX5N5YKt7MuMqaVFBSQf +ni6+twohUsp2L/Q8+Uo5Mn4lzVCNow= Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-240-gvG9xfgxPW6_sKTrCLMHlA-1; Fri, 04 Mar 2022 00:19:00 -0500 X-MC-Unique: gvG9xfgxPW6_sKTrCLMHlA-1 Received: by mail-pg1-f197.google.com with SMTP id bh9-20020a056a02020900b0036c0d29eb3eso3915796pgb.9 for <linux-mm@kvack.org>; Thu, 03 Mar 2022 21:19:00 -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=n7rwO48JtzdkJuoHFZCI8H9KL9Pu0D4gPtoWSB8Kejg=; b=W9Uc/9U+Xb6j7kmcvUNUGPTyYvrC1mkF745dJb6iKxPXNCeDl0ZZoFZgPDawP8hHnh /72LHVjhD4pDpJ8pDbzOt5T2qISez65xkHwVG8BrW0f79DF12/NWhux/Osr0atitNN7O V5V8D4UtfadOcnv5ScQPyCB8N5mswT9eFLCP29aK8kpormOtL4KD3StTPcqP2+sWBrsn WKe2/RRll7vg9xgrSInLqU4Uzq5LQCctYkiZ6BrfFVwvbE3HggWIuw+aQKHYdnaEZ1QA BgESJwDntl03Ozt3eYZD7IUTv51mdrEadjkxE28BXldbS/BSDYNYnJmXcN/AAjyuGYAP riqw== X-Gm-Message-State: AOAM530Jo37H1nOfsW3gOvwi5Cc2f+lVhE6tXpVnh4yf03coKAxrDnjg QAaxEe5v7mAybO55Do2NaDaELgImvqemEfuyPETWr63qcnNjZriTZrrPS9gBgf/leST2EV71Nk8 lnZtXea1k/ZcReVhMdVGpKDd/gJnh+oTgKY/ZB1gRtBg9o0lpQEawYRmLuHId X-Received: by 2002:a17:902:bc83:b0:14f:d9b7:ab3 with SMTP id bb3-20020a170902bc8300b0014fd9b70ab3mr38914597plb.23.1646371139447; Thu, 03 Mar 2022 21:18:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxQvXTM1bbdfv800pkAzqKOP1rVnQ9jp11rKIolBaZd7PJNXmzE+rE+wUwHWSuQvUScVEx9A== X-Received: by 2002:a17:902:bc83:b0:14f:d9b7:ab3 with SMTP id bb3-20020a170902bc8300b0014fd9b70ab3mr38914569plb.23.1646371139079; Thu, 03 Mar 2022 21:18:59 -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.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Mar 2022 21:18:58 -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 12/23] mm/hugetlb: Hook page faults for uffd write protection Date: Fri, 4 Mar 2022 13:16:57 +0800 Message-Id: <20220304051708.86193-13-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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 05A584000D X-Stat-Signature: qm5sa6gbfqa1hby9wfs4uwhfaoubwe5f Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=DR+OXZwE; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf27.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-HE-Tag: 1646371141-37535 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 b34f50156f7e..d2539e2fe066 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5680,6 +5680,26 @@ 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_wp(vma) && huge_pte_uffd_wp(huge_ptep_get(ptep)) && + (flags & FAULT_FLAG_WRITE) && !huge_pte_write(entry)) { + struct vm_fault vmf = { + .vma = vma, + .address = haddr, + .real_address = address, + .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