From patchwork Wed Jan 4 22:52:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 13089173 Return-Path: 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 25011C53210 for ; Wed, 4 Jan 2023 22:52:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57B1E8E0002; Wed, 4 Jan 2023 17:52:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 52B5A8E0001; Wed, 4 Jan 2023 17:52:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3F2C48E0002; Wed, 4 Jan 2023 17:52:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 312878E0001 for ; Wed, 4 Jan 2023 17:52:16 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E4C03801C0 for ; Wed, 4 Jan 2023 22:52:15 +0000 (UTC) X-FDA: 80318616630.04.1128948 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf30.hostedemail.com (Postfix) with ESMTP id 2D1238000B for ; Wed, 4 Jan 2023 22:52:12 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XYA+Upsm; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1672872733; a=rsa-sha256; cv=none; b=1FQbnR8wH6wL4me8yb8rWwl+ttXLWPe9W84jv3BeZHDkmfT8M8YqxgtRw1bPDieuCqpqC1 h+Mszj6K8BJXvift9hm39704qDx8jT5WTXgzNno6/DxeHJ8drLx7QkIg5l9EO6hSnb58Mp X8pgUAoKo3/TwVPgJQ8c87Ovr2PNnnI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=XYA+Upsm; spf=pass (imf30.hostedemail.com: domain of peterx@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1672872733; h=from:from:sender: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: references:dkim-signature; bh=ZyTLJHuaFPBCABjbLPe2M3+m2RCTfeHYSklpqyimWbc=; b=GY2bX9LilHNq9fEf8JzjCCfk/qzBPpMHuDLDjT7gBXe9kEAUvAgsutorP/6jbQKn1gfjUr bUjF50XYc6VFzmJKduziwWphKZX7xylT9+lC1s86NZ44JEp0b/2ndmWOAUKWa2RwePcX3T cP9URgmraoynTpaNISKXWCdt0mFTC2Q= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1672872732; 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; bh=ZyTLJHuaFPBCABjbLPe2M3+m2RCTfeHYSklpqyimWbc=; b=XYA+Upsm69gz8Qv5d1wyoZ0PK99lIaKQ2JkI67jxF9pIP8i+c19C7JtATGRdAu+vl4FMFE weQmStoIQV5Uy1Puo5JawY9iqNbRMQua1nc7HFZjfsiBOwjBm7U/DWtT+W967i44Oo3UXl fKFe3Gl3JJthKQdYvMnejSw/DO5IXa4= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-653-q4eOJ9ghPXiqossQU2ov-g-1; Wed, 04 Jan 2023 17:52:11 -0500 X-MC-Unique: q4eOJ9ghPXiqossQU2ov-g-1 Received: by mail-qv1-f70.google.com with SMTP id o95-20020a0c9068000000b005320eb4e959so471590qvo.16 for ; Wed, 04 Jan 2023 14:52:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ZyTLJHuaFPBCABjbLPe2M3+m2RCTfeHYSklpqyimWbc=; b=SxixNDw9QRO3lj9Y/Rc8OmS1TUKhKOA00zeOzKe92xu3yYXOyQRg/EXbjOmKVPSQSQ 6NVNXzA37JkLw0HxgRyBTPOD6QU4EGRfkpBC9aLc0Eqr+xUcyJpFo73cxmOf7jFj5c70 7z4j47UKZS1wzSDz8DaI/LRFzsbcUUzttobjZLPnWTzUDlkKOCyUq+yrXlYoVQLj3ZUe jEiIKni7UcbEAfDiEerbs6V61ZhTxyJN1TX+deD28lIlqkfjs7PuJRghZvd3WrqzLi8/ 5Q6wG/q4z+f44CPsYr+sP5QhTI9fZKmwRQYewigLmxc2/P0GfZKibOJQUPBQ2uA/sD8l vBxw== X-Gm-Message-State: AFqh2kqMD6p9Csy0Dfg0PnUHa4GXL/fU7sP1ZzB5k9aUvYkwn+W8kSss Q4JPaJ26XAjkxteY7hL/1wv9DOtkRvA/62JVU0tyY1lZX5X2vYVpvMK6nrhLkKi1/76ugS2uXWC B6BCV63Nav3og7wkiohSbGsLTFf6nsRAiC6LnmvBaeZSQwe8ibKNagYKUgxT8 X-Received: by 2002:ad4:4507:0:b0:532:de3:9b7d with SMTP id k7-20020ad44507000000b005320de39b7dmr2272131qvu.9.1672872730557; Wed, 04 Jan 2023 14:52:10 -0800 (PST) X-Google-Smtp-Source: AMrXdXttMw1zpmySJ1jlN/fXgDbyJj/7czFDfLKTRd1p2aZYSUC76jFCepdyVyNTX6QT2vSi43W2DA== X-Received: by 2002:ad4:4507:0:b0:532:de3:9b7d with SMTP id k7-20020ad44507000000b005320de39b7dmr2272101qvu.9.1672872730163; Wed, 04 Jan 2023 14:52:10 -0800 (PST) Received: from x1n.redhat.com (bras-base-aurron9127w-grc-39-70-52-228-144.dsl.bell.ca. [70.52.228.144]) by smtp.gmail.com with ESMTPSA id r1-20020a05620a298100b006eeb3165565sm24654710qkp.80.2023.01.04.14.52.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Jan 2023 14:52:09 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Mike Kravetz , Muchun Song , peterx@redhat.com, Nadav Amit , Andrea Arcangeli , David Hildenbrand , James Houghton , Axel Rasmussen , Andrew Morton Subject: [PATCH 0/3] mm/uffd: Fix missing markers on hugetlb Date: Wed, 4 Jan 2023 17:52:04 -0500 Message-Id: <20230104225207.1066932-1-peterx@redhat.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 2D1238000B X-Stat-Signature: wgggdb1cizibttc9ewuj9q5dakicejxr X-HE-Tag: 1672872732-511149 X-HE-Meta: U2FsdGVkX19JSBCoxQLbmwdjoyVBKugJXdmA+SLuYv+Uy0ynz7W9YOduSoz3YRmxYLAuRcxeGZE4ExAH0Hs9W1i3WhubJB5QKMlvWIQnGOI6oCHpsCdjd9by3CwOdaZlWW3dYxFgyWpBaXGK4dUb/jhJSOe5ImNsa3DdN8JFyQQMLH7o1XmeDZAMaW9R2eiMv0P87NWae3B5qnSkgmR2txVfFkLIaBWCJVHzy2MnAfATkd3Dju0HF5kRlQWN3FhCK5H8tRiIOTVaUXyS5l3/X++fhPI6a5UHgLKXxgizAAJmc8R4Kme/B9DX7FZTMC85HZ0pFjATUZ9VRRwO9BZNcDV0sRdPL+gAwXSBxYq5/928hsseiT+xjLCuvU9ZKCIwFsjQJpQG4EaPc9aMDYAyMLjpl0UFs5gk7e+eps/CsqtnUUNvGanQWQc4PRMOgE744fnI8khVBKWbkT48mhprT9oatn7O/xj2/2Lt/M03JQC/77kv9mUZVc0/nc8QsGEYTiZckmErwFcjIOY6OC2IV0VLwxg6rktf9DFBEpziEc7ntCQqILZ9SIqq7TTO7Ni0doOPrTf2wH9Z0Gsw5B++ckjmiIQO3Txs7Qv9HVq1aLVvJlvH2wxgFSRsAFhuNOwcDac72/clt2wvFMDSXtnLTtVVoucarSlPORp7DHsMjjWOLzdNjQS+Q6AXm+Oxbqr2h4kFrAgNSMQ27QToLAcAmTNt3M4kH2MuyQMGH3PUG/R6bM7jIFuqolgplrtc9/fg6pb94I+CbRG2RqWNEE1dcr4WJA2pxKjV7yYj/2sm7QF+yKxQo2MNXNqC5vbICv2vOcnwxMdiWmYGr2nqF+mcG5upqELJtyWiVNUvaHNy3TdN361lCJ3vnmGQsHn5sqO44z4qpPLCGGXX4GQ3lDGC61Lenz+9zuNEuV3n6Ej8s6qBmybiwqvs7R7HCW+ONKKSTibu647JsLSVOu27qew k3CWakga gyoD+17tvgqm2sGyMmZwicncydVpQm2sgYjSi5RO+i116CNJZuy1ob6WLsE7THzAqqyOGo4f17gAf4eGQF3H0K9boYQTd1jJkdctZOHZew/Z7mXmLK0pWN4lwIDfhMSUbK8qOQyvIeYhX8+nSpgh/vF9kXmeu9oVtBlKSklknQHvLvqVGE1LZ39vF7g== 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: When James was developing the vma split fix for hugetlb pmd sharing, he found that hugetlb uffd-wp is broken with the test case he developed [1]: https://lore.kernel.org/r/CADrL8HWSym93=yNpTUdWebOEzUOTR2ffbfUk04XdK6O+PNJNoA@mail.gmail.com Missing hugetlb pgtable pages caused uffd-wp to lose message when vma split happens to be across a shared huge pmd range in the test. The issue is pgtable pre-allocation on hugetlb path was overlooked. That was fixed in patch 1. Meanwhile there's another issue on proper reporting of pgtable allocation failures during UFFDIO_WRITEPROTECT. When pgtable allocation failed during the ioctl(UFFDIO_WRITEPROTECT), we will silent the error so the user cannot detect it (even if extremely rare). This issue can happen not only on hugetlb but also shmem. Anon is not affected because anon doesn't require pgtable allocation during wr-protection. Patch 2 prepares for such a change, then patch 3 allows the error to be reported to the users. This set only marks patch 1 to copy stable, because it's a real bug to be fixed for all kernels 5.19+. Patch 2-3 will be an enhancement to process pgtable allocation errors, it should hardly be hit even during heavy workloads in the past of my tests, but it should make the interface clearer. Not copying stable for patch 2-3 due to that. I'll prepare a man page update after patch 2-3 lands. Tested with: - James's reproducer above [1] so it'll start to pass with the vma split fix: https://lore.kernel.org/r/20230101230042.244286-1-jthoughton@google.com - Faked memory pressures to make sure -ENOMEM returned with either shmem and hugetlbfs - Some uffd general routines Peter Xu (3): mm/hugetlb: Pre-allocate pgtable pages for uffd wr-protects mm/mprotect: Use long for page accountings and retval mm/uffd: Detect pgtable allocation failures include/linux/hugetlb.h | 4 +- include/linux/mm.h | 2 +- include/linux/userfaultfd_k.h | 2 +- mm/hugetlb.c | 21 +++++++-- mm/mempolicy.c | 4 +- mm/mprotect.c | 89 ++++++++++++++++++++++------------- mm/userfaultfd.c | 16 +++++-- 7 files changed, 88 insertions(+), 50 deletions(-)