Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp2939320pxy; Mon, 3 May 2021 11:18:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa+xp9gy4BWqlnUj8Y9nNllJSRlmdzLcwJSVXyCAOTtIVzec/a7GwTncnFP/VUYYmNXhPj X-Received: by 2002:a05:6402:b2c:: with SMTP id bo12mr21638473edb.196.1620065880900; Mon, 03 May 2021 11:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620065880; cv=none; d=google.com; s=arc-20160816; b=W9pST9Oi35Vyx7PAB+7gXFDGizC8v/USBmL3KT4Lmpg+hXzJYXyhYU8cndVqWN4Lxz 6nWodF69SJig53NXksMvra3HSRYXqqa/1wbg+X7EEt4I4MR7c4oMmh1WP/HF+Hwu11JO 0hMKypAFXzYhzfP/VtBRNDtfcXEWZiTMBVBAXv5RA5IMQdMkM4Hh/IfQzg2T6GfXCGOe xZj/Rj+nOTGpryncVw0p7rFoyOwOUIxH1eWHAAAVQETJPTh5eKA0czrugFuvQ6BbKR+c nBAOrMEV78B5HVe0+9qKxJNi8QLVaa+kht1pgzbqLqWJbUBRObqLoAWJG4wTbXIkqgxB kWwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=B2Y1PjHbI7aJoqQQgo4Vnp4m6n0XR/I22GG3IBxep44=; b=T1PzuNGWXtPRcAr7/eOAJUHeR5sE9rafGu+rdD1dHPZGxyXDo/AlfW0ukQef1n3cLr aOfQleldUWx6sRCcaB6XHCcBTZQmrryis/3pgoO48Wv3K46zQpBr0A74mCHlYMR+JEfL oXSuRd5JWIzoO6rX8nCi2telJtJE9dpIkWiDTEWJE9zg4OI48mSGxjgpirJANWdeUJnF 7BAVm8jAN4XLxQAx7Ghgms8gIWtLWwbm7x75CfhF3O4bcF+W78sOxK3W6aRZTgbx4OgY V9a/ouQAF49tHq/3P6Rq4Ns7RuQwnGkH7AOHuGEbsCGziigCXcHj/0tAHCClJVyDmhAy Nllg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gTsFZvf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si11296647edr.163.2021.05.03.11.17.36; Mon, 03 May 2021 11:18:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gTsFZvf1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231946AbhECSJA (ORCPT + 99 others); Mon, 3 May 2021 14:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231640AbhECSIs (ORCPT ); Mon, 3 May 2021 14:08:48 -0400 Received: from mail-qv1-xf49.google.com (mail-qv1-xf49.google.com [IPv6:2607:f8b0:4864:20::f49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60780C061342 for ; Mon, 3 May 2021 11:07:49 -0700 (PDT) Received: by mail-qv1-xf49.google.com with SMTP id c5-20020a0ca9c50000b02901aede9b5061so5539472qvb.14 for ; Mon, 03 May 2021 11:07:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=B2Y1PjHbI7aJoqQQgo4Vnp4m6n0XR/I22GG3IBxep44=; b=gTsFZvf1qsTwVhu74lp9LkD4evRddnT0OUCq2nktgrb7Qeqfhtqry+E72YR++T84jj FXO/yrAwTZLbPQiAAwfvf+aY5r3B+UVXp4W+z4eCVdecIu2KlkEWmJ+eEDTsnajop9KT hod3LhJUwoDlsuDkjH6nvfEyBxo2prHq/2niF4ikBsp1fVCf7ubjwJI2Sbd/I7z+CzoO 08wNutl5oqSAMliZ/wvffe/EPSYnMJoN93ATlRsVdEBqx0kc4GxVW4CfIU1H4OANm343 BG/ERYek+C20/S9UsylvbaAOgQSKEWJUxx/0wKow/xe2GzjB7U3gDEfnlKV66ErHLrQc 8/Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=B2Y1PjHbI7aJoqQQgo4Vnp4m6n0XR/I22GG3IBxep44=; b=GPgyons8asICvcjjCo6P2240hi598M9fkt000uCeBOYv7WYaHM41hkxAkwgxWKJc7T T4AUrjZhNN6b396XPYSV7HgQmjTCBeHCQFocVbGnNIw5KOYVPlQgYR9BzPka1qWUssiS utb2VFP0VSYkfkV55+ML00uhmObcKw9PNDODiIvoipqlrHxuH5t3Ic0htSWGqBOrKG4s SVPYlP+O1hj18OAZnZs1s5gwISsah6CJs8UapXXA2Pe+HS+qz4+Go1KNxrYq8hLwfUvB /vG52GbTYy1StaVKH6T5qZ9e417xfEg7+d32zstNA3HJMrrf3c/ZDcQYBhXDlSIo8RP2 uXWA== X-Gm-Message-State: AOAM531wtxa8XJn8pYjSDpib++625cZC8rH+9E1Hvm6e+TZ2prlGOMxe nRG81oQRKuJ2ruMFO5OnrgEK2kCH4+/V04LPdhYd X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:3d79:e69a:a4f9:ef0]) (user=axelrasmussen job=sendgmr) by 2002:a0c:c446:: with SMTP id t6mr11124075qvi.3.1620065268499; Mon, 03 May 2021 11:07:48 -0700 (PDT) Date: Mon, 3 May 2021 11:07:30 -0700 In-Reply-To: <20210503180737.2487560-1-axelrasmussen@google.com> Message-Id: <20210503180737.2487560-4-axelrasmussen@google.com> Mime-Version: 1.0 References: <20210503180737.2487560-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.31.1.527.g47e6f16901-goog Subject: [PATCH v6 03/10] userfaultfd/shmem: support minor fault registration for shmem From: Axel Rasmussen To: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing Cc: linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Axel Rasmussen , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch allows shmem-backed VMAs to be registered for minor faults. Minor faults are appropriately relayed to userspace in the fault path, for VMAs with the relevant flag. This commit doesn't hook up the UFFDIO_CONTINUE ioctl for shmem-backed minor faults, though, so userspace doesn't yet have a way to resolve such faults. Because of this, we also don't yet advertise this as a supported feature. That will be done in a separate commit when the feature is fully implemented. Acked-by: Peter Xu Acked-by: Hugh Dickins Signed-off-by: Axel Rasmussen --- fs/userfaultfd.c | 3 +-- mm/memory.c | 8 +++++--- mm/shmem.c | 12 +++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 14f92285d04f..468556fb04a9 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1267,8 +1267,7 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, } if (vm_flags & VM_UFFD_MINOR) { - /* FIXME: Add minor fault interception for shmem. */ - if (!is_vm_hugetlb_page(vma)) + if (!(is_vm_hugetlb_page(vma) || vma_is_shmem(vma))) return false; } diff --git a/mm/memory.c b/mm/memory.c index 86ba6c1f6821..9a536cfde7c8 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3972,9 +3972,11 @@ static vm_fault_t do_read_fault(struct vm_fault *vmf) * something). */ if (vma->vm_ops->map_pages && fault_around_bytes >> PAGE_SHIFT > 1) { - ret = do_fault_around(vmf); - if (ret) - return ret; + if (likely(!userfaultfd_minor(vmf->vma))) { + ret = do_fault_around(vmf); + if (ret) + return ret; + } } ret = __do_fault(vmf); diff --git a/mm/shmem.c b/mm/shmem.c index 04de845b50b3..e361f1d81c8d 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1785,7 +1785,7 @@ static int shmem_swapin_page(struct inode *inode, pgoff_t index, * vm. If we swap it in we mark it dirty since we also free the swap * entry since a page cannot live in both the swap and page cache. * - * vmf and fault_type are only supplied by shmem_fault: + * vma, vmf, and fault_type are only supplied by shmem_fault: * otherwise they are NULL. */ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, @@ -1820,6 +1820,16 @@ static int shmem_getpage_gfp(struct inode *inode, pgoff_t index, page = pagecache_get_page(mapping, index, FGP_ENTRY | FGP_HEAD | FGP_LOCK, 0); + + if (page && vma && userfaultfd_minor(vma)) { + if (!xa_is_value(page)) { + unlock_page(page); + put_page(page); + } + *fault_type = handle_userfault(vmf, VM_UFFD_MINOR); + return 0; + } + if (xa_is_value(page)) { error = shmem_swapin_page(inode, index, &page, sgp, gfp, vma, fault_type); -- 2.31.1.527.g47e6f16901-goog