From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 B46C9C433DB for ; Thu, 21 Jan 2021 18:49:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3694A230F9 for ; Thu, 21 Jan 2021 18:49:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3694A230F9 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 A03CC6B0006; Thu, 21 Jan 2021 13:49:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B4D96B0007; Thu, 21 Jan 2021 13:49:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82EA56B000A; Thu, 21 Jan 2021 13:49:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 61A8F6B0006 for ; Thu, 21 Jan 2021 13:49:45 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2C93E8249980 for ; Thu, 21 Jan 2021 18:49:45 +0000 (UTC) X-FDA: 77730671130.13.eye96_3e0882727565 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin13.hostedemail.com (Postfix) with ESMTP id 0686718140B60 for ; Thu, 21 Jan 2021 18:49:45 +0000 (UTC) X-HE-Tag: eye96_3e0882727565 X-Filterd-Recvd-Size: 8122 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf13.hostedemail.com (Postfix) with ESMTP for ; Thu, 21 Jan 2021 18:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1611254983; 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: in-reply-to:in-reply-to:references:references; bh=6TBkn8Pkdag13BDPCcX3RZw7vW2DCMiBVqUE7wTSuKQ=; b=N/W/eGS514uLuH2Be5Xnx8QE1alamD88qlbvxHzI8NXXzK6IxMUISbvh2cxUzBkOvhGk32 vUpyCHLJcX6CjFfqTRy6cmrHUXsbY55hoe6AkJzUUAKfcYNLMDX0q/1b8acWOexuomJqr0 we2Zo1X6y0ljFR6oB5WvEwuAU54EGWY= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-311-6Mq5R3Z5PWSKYHb2_t7SIw-1; Thu, 21 Jan 2021 13:49:42 -0500 X-MC-Unique: 6Mq5R3Z5PWSKYHb2_t7SIw-1 Received: by mail-qv1-f69.google.com with SMTP id u8so2106800qvm.5 for ; Thu, 21 Jan 2021 10:49:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6TBkn8Pkdag13BDPCcX3RZw7vW2DCMiBVqUE7wTSuKQ=; b=hCrkra69b4Bg3xbM/4SYxmrDknatRGhTmAL38kFRNGlAbxnb+ur0LQrYQSEQy2zaCg Zgww5BlSCfz9Q0y3l/3ZT6In30qHq4e6SS/I+O5e7kiEHdiIUzZ22ZNcpiigqMrAp3Rz XnZO7MMznnxvZDeV7n1zt/uUugqH+WZA683hoE0/ouW5HM+3lDv/1iAGFQKIbFrXdQ9W P98cuoZXmCD4ttSfTsp4VIjDarQ1TQhbd8W3OfImbd3vmeowAotoMnTRuYW7b/8rL0Q7 GWR3lXtIB0YcVlTPcFMZ3jAYX7bcIAInBBV8tmeWgVG7iLHlqZ2/LXZeQId7RV8cVAPL vIGw== X-Gm-Message-State: AOAM532fhmUB2kxk2lO4MME6fra2ra9EiPbFHxVkNHFr1K8BEmHUC9Ry Dv2qa9NXPOo7zGyHGxC9FW8rNd0RMzbV7DEM0HpGUbrmu8TJgj7Rfj4ewu3y1OK5Yhy8Ue9np/F eSwoD7+NwLBM= X-Received: by 2002:aed:232d:: with SMTP id h42mr969227qtc.143.1611254981800; Thu, 21 Jan 2021 10:49:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJx9EXEbSwwBAfssfPtJdgfpx76Zd/+F9KwLJUZY61Z2fBXkPSvOmQovBQztwF+Z2ca8S+P7cw== X-Received: by 2002:aed:232d:: with SMTP id h42mr969190qtc.143.1611254981496; Thu, 21 Jan 2021 10:49:41 -0800 (PST) Received: from xz-x1 ([142.126.83.202]) by smtp.gmail.com with ESMTPSA id c7sm3846216qtc.82.2021.01.21.10.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jan 2021 10:49:40 -0800 (PST) Date: Thu, 21 Jan 2021 13:49:38 -0500 From: Peter Xu To: Axel Rasmussen Cc: Alexander Viro , Alexey Dobriyan , Andrea Arcangeli , Andrew Morton , Anshuman Khandual , Catalin Marinas , Chinwen Chang , Huang Ying , Ingo Molnar , Jann Horn , Jerome Glisse , Lokesh Gidra , "Matthew Wilcox (Oracle)" , Michael Ellerman , Michal =?utf-8?Q?Koutn=C3=BD?= , Michel Lespinasse , Mike Kravetz , Mike Rapoport , Nicholas Piggin , Shaohua Li , Shawn Anastasio , Steven Rostedt , Steven Price , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Adam Ruprecht , Cannon Matthews , "Dr . David Alan Gilbert" , David Rientjes , Oliver Upton Subject: Re: [PATCH 5/9] userfaultfd: add minor fault registration mode Message-ID: <20210121184938.GD260413@xz-x1> References: <20210115190451.3135416-1-axelrasmussen@google.com> <20210115190451.3135416-6-axelrasmussen@google.com> MIME-Version: 1.0 In-Reply-To: <20210115190451.3135416-6-axelrasmussen@google.com> 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=utf-8 Content-Disposition: inline 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: Hi, Axel, On Fri, Jan 15, 2021 at 11:04:47AM -0800, Axel Rasmussen wrote: > diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h > index c63ccdae3eab..7aa1461e1a8b 100644 > --- a/include/linux/userfaultfd_k.h > +++ b/include/linux/userfaultfd_k.h > @@ -71,6 +71,11 @@ static inline bool userfaultfd_wp(struct vm_area_struct *vma) > return vma->vm_flags & VM_UFFD_WP; > } > > +static inline bool userfaultfd_minor(struct vm_area_struct *vma) > +{ > + return vma->vm_flags & VM_UFFD_MINOR; > +} > + > static inline bool userfaultfd_pte_wp(struct vm_area_struct *vma, > pte_t pte) > { > @@ -85,7 +90,7 @@ static inline bool userfaultfd_huge_pmd_wp(struct vm_area_struct *vma, > > static inline bool userfaultfd_armed(struct vm_area_struct *vma) > { > - return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP); > + return vma->vm_flags & (VM_UFFD_MISSING | VM_UFFD_WP | VM_UFFD_MINOR); > } Maybe move the __VM_UFFD_FLAGS into this header so use it too here? [...] > diff --git a/include/uapi/linux/userfaultfd.h b/include/uapi/linux/userfaultfd.h > index 5f2d88212f7c..1cc2cd8a5279 100644 > --- a/include/uapi/linux/userfaultfd.h > +++ b/include/uapi/linux/userfaultfd.h > @@ -19,15 +19,19 @@ > * means the userland is reading). > */ > #define UFFD_API ((__u64)0xAA) > +#define UFFD_API_REGISTER_MODES (UFFDIO_REGISTER_MODE_MISSING | \ > + UFFDIO_REGISTER_MODE_WP | \ > + UFFDIO_REGISTER_MODE_MINOR) > #define UFFD_API_FEATURES (UFFD_FEATURE_PAGEFAULT_FLAG_WP | \ > UFFD_FEATURE_EVENT_FORK | \ > UFFD_FEATURE_EVENT_REMAP | \ > - UFFD_FEATURE_EVENT_REMOVE | \ > + UFFD_FEATURE_EVENT_REMOVE | \ > UFFD_FEATURE_EVENT_UNMAP | \ > UFFD_FEATURE_MISSING_HUGETLBFS | \ > UFFD_FEATURE_MISSING_SHMEM | \ > UFFD_FEATURE_SIGBUS | \ > - UFFD_FEATURE_THREAD_ID) > + UFFD_FEATURE_THREAD_ID | \ > + UFFD_FEATURE_MINOR_FAULT_HUGETLBFS) I'd remove the "_FAULT" to align with the missing features... > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > index 61d6346ed009..2b3741d6130c 100644 > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -4377,6 +4377,37 @@ static vm_fault_t hugetlb_no_page(struct mm_struct *mm, > } > } > > + /* Check for page in userfault range. */ > + if (!new_page && userfaultfd_minor(vma)) { > + u32 hash; > + struct vm_fault vmf = { > + .vma = vma, > + .address = haddr, > + .flags = flags, > + /* > + * Hard to debug if it ends up being used by a callee > + * that assumes something about the other uninitialized > + * fields... same as in memory.c > + */ > + }; > + > + unlock_page(page); > + > + /* > + * hugetlb_fault_mutex and i_mmap_rwsem must be dropped before > + * handling userfault. Reacquire after handling fault to make > + * calling code simpler. > + */ > + > + hash = hugetlb_fault_mutex_hash(mapping, idx); > + mutex_unlock(&hugetlb_fault_mutex_table[hash]); > + i_mmap_unlock_read(mapping); > + ret = handle_userfault(&vmf, VM_UFFD_MINOR); > + i_mmap_lock_read(mapping); > + mutex_lock(&hugetlb_fault_mutex_table[hash]); > + goto out; I figured it easier if the whole chunk be put into the else block right after find_lock_page(); will that work the same? It's just not obviously clear on when we'll go into this block otherwise, basically the dependency of new_page variable and when it's unset. Thanks, -- Peter Xu