Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2582771pxb; Tue, 13 Apr 2021 05:35:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGpjKk7TGTNr/kVkQpU0b6kkXmz/APYqi0oHnYwqkbJny5VyjQ7z+uayAA1Qzy3gMGfMAa X-Received: by 2002:aa7:d14a:: with SMTP id r10mr24567445edo.385.1618317341024; Tue, 13 Apr 2021 05:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618317341; cv=none; d=google.com; s=arc-20160816; b=azNzZezKXBr1BWvAQ9Vnp52Joo2/q66WzM/uFZkU4Y2B5PPJGmirvoY/a0Oc0mgOId CfMxYtdTN2FFXFqFf7JNavb3nzYfAeGRtvHPTWTLiX5Un0MoS6UACXGCZW5cABBol3d3 3evl2YLiYpyaWw2KsEHgeM1U4cGGFHX1XulJQ7wgwzOjbXeuVc9HVPOpdA/PcoqKQV0r D4q2xQYS7jzbCQpLyVmSOaDv1woDej3oRsDgWzoLUZnUoDr8Ice6HhBaxtsh48FM3IFX xORXfFckhWQf92ydyNTpQ65WQViwpQGk77yibyc5ZwEapnUsLuFHrGH2UO8SqvLyhIQj aeQw== 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:mime-version:message-id:date :dkim-signature; bh=wrbaVOYVgCtHDmQ7j5oVc9kHRwzikE6fRM9DNAMARAs=; b=Sez4egNwRIUVxom7EX3vNnPxRGbddFcU2hevC/yaHbvV/0uu6C7/PeMPuecbqR+XZo VRPjHJRE/NoAsvWGaY4UiagPk2jKSZe3X4q/QI1gQiFr73maTH12YfG54xiSECgR5fIN mTq9l8wo0/LVcc9aKyYlogYO+hlFsPYdp0PZPRWLFSoYOzOp91bTv+W4YZ9Mn5jb5vhV 1x+9x5XEw/mXJg77pmlYjbHIlQtv6zGWAQSB+652iejDGSjHjW4ER351ptIX3r0Udp7t 5gmFs9Grlrru0fnPcihCKqgvOUkRK00I2IDiJPNGTtUIj+frRFw5HsH8ow4QNbwT51N/ pe1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ZGD2PSv9; 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 md27si7082482ejb.620.2021.04.13.05.35.17; Tue, 13 Apr 2021 05:35:41 -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=ZGD2PSv9; 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 S244296AbhDMFRr (ORCPT + 99 others); Tue, 13 Apr 2021 01:17:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230173AbhDMFRp (ORCPT ); Tue, 13 Apr 2021 01:17:45 -0400 Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26877C061756 for ; Mon, 12 Apr 2021 22:17:26 -0700 (PDT) Received: by mail-qk1-x749.google.com with SMTP id o196so1841491qka.13 for ; Mon, 12 Apr 2021 22:17:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=wrbaVOYVgCtHDmQ7j5oVc9kHRwzikE6fRM9DNAMARAs=; b=ZGD2PSv90bQPpcK7ImkqdxJeL3mh0oBpLqIRyzGn3TPamps4ADC6Ha6Z1lp3ZChArz FYE4L8Ygcgoc7zV3RgtZSAewQqWFefjPu3FBOyCcqJyPh9TAjxvxQxMKXKe4MhWXiPL9 QlTF3H3CT0tkjpPIqB33NvonB1G43LMnC/p9UCQdAEaTlaFwukIB8uyn0RkFOwGoWvdW F6opuB/CEyRc1du8vcR2QCriYNIi+qI4CLa5f635Jtc8Qs8dRMEJZekk5JPSdlB9NDsP Hab2N4VkNBHBEqH4yI/6UJz7A6LzW+BohwZtJWT7nBSM1/lQJNewPX8yHrH6i4FdegNV gfiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=wrbaVOYVgCtHDmQ7j5oVc9kHRwzikE6fRM9DNAMARAs=; b=J3WUfeM9bmcMXg9aRmqR8Czf3hE0JVD4pes6mSNpIqKIf4gsZFIpDdXYCbW9Rc0DQR VFK1vhf2+nduQ77C1zzH0af7OM0qpFk0s8suEdE3dr1EmVffOk7voe/djYm75N/tsKfX kvZPo3XmObbSz1uNL3tl2n8ZOXT+qqzJ2bnOabERNEoq2M1ZxWOR7qgslN1ihges3Ta/ zBpbzXsLWmY7JPM1kRx4ScAw8Ukisdo0P/3uhO+zwn0S+pA2n+QIzZ9YmQtY60TdGlCI Jrsag+UhW8Av9l2tgtVpa5/pnhOLZyDKUHB847iCPLghBhxojYcXPPe4Y/enpiFH31Su uG8Q== X-Gm-Message-State: AOAM532PLBOV3D/Zh6tveuNc3677JNqQ0YEb8g/I0v0yGattItwrD9lQ UL8yv5m5s26QfvStDjg8NgD5H8kVmExrrlkYZqE7 X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:d508:eee5:2d57:3e32]) (user=axelrasmussen job=sendgmr) by 2002:a0c:8d44:: with SMTP id s4mr31548867qvb.53.1618291045176; Mon, 12 Apr 2021 22:17:25 -0700 (PDT) Date: Mon, 12 Apr 2021 22:17:12 -0700 Message-Id: <20210413051721.2896915-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.1.295.g9ea45b61b8-goog Subject: [PATCH v2 0/9] userfaultfd: add minor fault handling 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 Base ==== This series is based on (and therefore should apply cleanly to) the tag "v5.12-rc7-mmots-2021-04-11-20-49", additionally with Peter's selftest cleanup series applied *first*: https://lore.kernel.org/patchwork/cover/1412450/ Changelog ========= v1->v2: - Pick up Reviewed-by's. - Don't swapin page when a minor fault occurs. Notice that it needs to be swapped in, and just immediately fire the minor fault. Let a future CONTINUE deal with swapping in the page. [Peter] - Clarify comment about i_size checks in mm/userfaultfd.c. [Peter] - Only forward declare once (out of #ifdef) in hugetlb.h. [Peter] Changes since [2]: - Squash the fixes ([2]) in with the original series ([1]). This makes reviewing easier, as we no longer have to sift through deltas undoing what we had done before. [Hugh, Peter] - Modify shmem_mcopy_atomic_pte() to use the new mcopy_atomic_install_ptes() helper, reducing code duplication. [Hugh] - Properly trigger handle_userfault() in the shmem_swapin_page() case. [Hugh] - Use shmem_getpage() instead of find_lock_page() to lookup the existing page in for continue. This properly deals with swapped-out pages. [Hugh] - Unconditionally pte_mkdirty() for anon memory (as before). [Peter] - Don't include userfaultfd_k.h in either hugetlb.h or shmem_fs.h. [Hugh] - Add comment for UFFD_FEATURE_MINOR_SHMEM (to match _HUGETLBFS). [Hugh] - Fix some small cleanup issues (parens, reworded conditionals, reduced plumbing of some parameters, simplify labels/gotos, ...). [Hugh, Peter] Overview ======== See the series which added minor faults for hugetlbfs [3] for a detailed overview of minor fault handling in general. This series adds the same support for shmem-backed areas. This series is structured as follows: - Commits 1 and 2 are cleanups. - Commits 3 and 4 implement the new feature (minor fault handling for shmem). - Commits 5, 6, 7, 8 update the userfaultfd selftest to exercise the feature. - Commit 9 is one final cleanup, modifying an existing code path to re-use a new helper we've introduced. We rely on the selftest to show that this change doesn't break anything. Use Case ======== In some cases it is useful to have VM memory backed by tmpfs instead of hugetlbfs. So, this feature will be used to support the same VM live migration use case described in my original series. Additionally, Android folks (Lokesh Gidra ) hope to optimize the Android Runtime garbage collector using this feature: "The plan is to use userfaultfd for concurrently compacting the heap. With this feature, the heap can be shared-mapped at another location where the GC-thread(s) could continue the compaction operation without the need to invoke userfault ioctl(UFFDIO_COPY) each time. OTOH, if and when Java threads get faults on the heap, UFFDIO_CONTINUE can be used to resume execution. Furthermore, this feature enables updating references in the 'non-moving' portion of the heap efficiently. Without this feature, uneccessary page copying (ioctl(UFFDIO_COPY)) would be required." [1] https://lore.kernel.org/patchwork/cover/1388144/ [2] https://lore.kernel.org/patchwork/patch/1408161/ [3] https://lore.kernel.org/linux-fsdevel/20210301222728.176417-1-axelrasmussen@google.com/T/#t Axel Rasmussen (9): userfaultfd/hugetlbfs: avoid including userfaultfd_k.h in hugetlb.h userfaultfd/shmem: combine shmem_{mcopy_atomic,mfill_zeropage}_pte userfaultfd/shmem: support minor fault registration for shmem userfaultfd/shmem: support UFFDIO_CONTINUE for shmem userfaultfd/selftests: use memfd_create for shmem test type userfaultfd/selftests: create alias mappings in the shmem test userfaultfd/selftests: reinitialize test context in each test userfaultfd/selftests: exercise minor fault handling shmem support userfaultfd/shmem: modify shmem_mcopy_atomic_pte to use install_ptes fs/userfaultfd.c | 6 +- include/linux/hugetlb.h | 4 +- include/linux/shmem_fs.h | 15 +- include/linux/userfaultfd_k.h | 5 + include/uapi/linux/userfaultfd.h | 7 +- mm/hugetlb.c | 1 + mm/memory.c | 8 +- mm/shmem.c | 112 +++------ mm/userfaultfd.c | 183 ++++++++++----- tools/testing/selftests/vm/userfaultfd.c | 280 +++++++++++++++-------- 10 files changed, 377 insertions(+), 244 deletions(-) -- 2.31.1.295.g9ea45b61b8-goog