From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.170 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796132983; b=OXNsblaVIi7Dt5sdi2USMf+F7ztAeR7kbyDMiLzCZeQJ2ekQETEi66CUs1Quh10Bz5X/ j1LI92SW5ZD4nP4kJZkIohSc/6YcxpEnVUXiWIgs0IccbPi4ywzlcAjK/3Zf/l3w8T7IP rgbuUXPsqPKeK3OYqOcTO/0nTxjbw/CElH6jZeR84kn1qdxsX1Hll8YgPVQuBYZOYRPKs ezr5JDHgKVfkRMmS01U79/R2wvdzFQDWIQbkWRRY/yrpM37BrgIlG2J0ykiyeFGpBsqWK iu6Y5rchMd/7bFgrKVRm4tJefiTk1Y5xZRtdQbUk0zXCwddaMTcZJ3PCbMdu83P3I1g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796132983; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: MIME-Version:Content-Type:Content-Transfer-Encoding:Subject:From:To: Cc:In-Reply-To:References:Date:Message-Id:X-Mailer; bh=6f6FP4jPvC/+c1Nwfn/nIxtqFlqI8vkXKmMomK7y/4I=; b=Km0aM+NXTMlOWtjTZD1O3/BybOEvEhOsGPBLkyxWSNjEgXMeTbCGFo9hu6i2yZChAseC iaZOZRlA7Jec0oKfcu5QxE12sfxpi6dPoyVFB0iALd0k630l8nsqHArCstsNph8gPfq4G ufTfBVBafnbwJeePW/A0k9DdHalLAUx5EGmCa6Via7066AD06gK4bLhRIUwhdh6+sWYfq jzUGxY5eBM3yIkwhCWB7n6wTDxICXDS0OCJehYwb8jBvpJSLW4clC+lfnfztkHI3xldJU V0Tj6BgXCrg6gq80qU5kB0n06XsFxCO+Zn5Nzhegpfl/uoN7qey6Dqut0EgKjtxTZMg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=gourry.net; spf=pass smtp.mailfrom=gourry.net; dkim=pass header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=LDYkOBf7; arc=none smtp.remote-ip=209.85.160.170 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3C6A606A329 for ; Tue, 1 Dec 2026 13:49:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3C6A606A329 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=gourry.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gourry.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gourry.net header.i=@gourry.net header.a=rsa-sha256 header.s=google header.b=LDYkOBf7 Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-55d846e884eso74281901cf.2 for ; Tue, 01 Dec 2026 05:49:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1796132982; x=1796737782; darn=vger.kernel.org; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:from:to:cc :subject:date:message-id:reply-to:content-type; bh=6f6FP4jPvC/+c1Nwfn/nIxtqFlqI8vkXKmMomK7y/4I=; b=LDYkOBf7HcRN/Qb9PczCaksd43T1XsMfXE/cmb2iabHCrFeATddTwWrJVISHHNJXGy rVNt+GbHe8XnXECfoOHT5uxirjuHmtlgA1cAYEAVfnZxf5GeJkj/21CIwSuCMwdy8Ojs yjyGULBHNiXTm58UMr0EId/Rha+I5ST0YGkPNbnnlYMYAO9fCqcCr8v4QpHYFrFCyheZ 6BKVNM884CcGxkjpEwQB4J6iH8+dEsxje12aSrUFQrWkSFIAbHQH+yVskMxaWHfg5LKJ T+EWmq4tuETMN0D2HX3TPJ9G8HMMfDDKUdEX80uyqUHC/rUWuoiRV/9QakyR7E6qVv2I 54ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796132982; x=1796737782; h=message-id:date:references:in-reply-to:cc:to:from:subject :content-transfer-encoding:content-type:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=6f6FP4jPvC/+c1Nwfn/nIxtqFlqI8vkXKmMomK7y/4I=; b=qpO9WOhhC+VEoWT7KEM6UHR1mlAyZNXlWLwkzgpw0QPfP5TEwr59g3vcxz7RqoXi8y KOJD1Qow9xsyTyjwSaBcIOisIW7ypRaW86XLlqzUULkdkA/QSfCfGwaKljEIJirsoRFi q3jUjrQoCLrtksqJ0Roh79/oX1zk8JfmUH5MiJOJMoZ6STKzSjJMB4v0HzILJMVKaTKd 8RiE40C0r1b0SGr90RKnriJfPkaiFK7f/O0FmvHFKzvrJgaFG/4aIe5kWqu+lGKSVqna s54YxcHhOdW0HMsHmZxBW77MnF2I2vh5FsIIFOdpcCPKRgC0x4LRyNc/xx9rdmsJRFjs FWfQ== X-Forwarded-Encrypted: i=1; AL+hErHIjjl/lZP8/HpHrJiVIkM1lRos6EOV+JjISPgNtqcnbUC82HiBw3MXVqBfvLyVsMllPiH2931K/q2rIZQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9Bv3WT5cmVnEzTWRhTXj2Ygj1FrK0EToXLvJj4ZY/qWbZT93rj q8f+n1yZFvzYJ/oh+wLlU4yk8XeV0/WMgWmhEQ9hgNRqlY6J5n5Vjvho136EzwHV37E= X-Gm-Gg: AZFdTZdJSR7S5rW1/vVaoOHMmseyywPI933WoNx4vg4f4C3Ryz7j/CPRCl4vH4035WS IsgfJUhIVHcBoP9fW9M12qd7SbIB7Fv2ID0x7LRpH6XYZDovNYNT4hf3wQ0KC5Oyh7IY/Yv39/W 16aDzFBgQ5wGPMzTxlOFRWFt/CKJU4PfmMsTGjf64Ozbu3grOpm0ZP+lOmaBeJNVy/0DdwNL4sE EyVT24oyTPffsldCVWUgDhzEzexmlAvKLZ/6P4NcE51DeQKpGP0NZgddGwZpYO2jFv+2kNbGGNw tCfwLNgO/0l8zTrVHLwKJ6RA+3u4vDsjFDzJkbnbaLaCDfoW6cBXy1OMxTFQBaWNFCd7Rpn5AIv ggTChVBiWb7L2zaddjji329G/HO3gjXidkNbnA1TkvKhpQybWPO5XM19ysNgW3+ZJ4f4GG3bEcb /svSDDdDveaayDfjQNqWnVMVhaV6kTNM+r+a/N9S2tMLcD3WfXkHHGUUvh5OXfKkdA0I3DyLFc/ wSwR4BPom0qxEusyOsz70e3fSfriQJaYbDpTSKFH1MRF8yenjZtOHf+yXPHiFp8UL8xA8JcNySh Z7MIuWWQQaZOWQbzuSZjMHpNqsoaJZN8sebQnlBPvKuWFa1p2QFBPze8Eeewak/PFnobrByVCAP SrVQFGNQ= X-Received: by 2002:a05:622a:4894:b0:532:9ef1:729e with SMTP id d75a77b69052e-55d7693d3e4mr699960511cf.10.1796132981903; Tue, 01 Dec 2026 05:49:41 -0800 (PST) Received: from [192.168.50.231] (pool-71-191-145-202.washdc.fios.verizon.net. [71.191.145.202]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d7882e2d1sm309556111cf.14.2026.12.01.05.49.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 05:49:41 -0800 (PST) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: Re: [PATCH 03/32] mm/shmem: reject userfaultfd fills during hole punch From: "Gregory Price (Meta)" To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , stable@vger.kernel.org, Chris Mason In-Reply-To: <20261129-fixes_core_3-v1-3-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-3-f66094116801@kernel.org> Date: Tue, 01 Dec 2026 08:49:39 -0500 Message-Id: <179613297931.412063.11723247459504916236.b4-reply@b4> X-Mailer: b4 0.17-dev On 2026-11-29 11:06 +0100, David Hildenbrand (Arm) wrote: > While punching a shmem/tmpfs hole, regular page faults in the range wait > for the hole punch to finish, but UFFDIO_COPY, UFFDIO_ZEROPAGE and > UFFDIO_CONTINUE keep mapping pages into it. The hole punch must then > repeatedly walk the file's VMAs to unmap these pages, while holding > i_rwsem. > > Consequently, punching a hole can become very slow if userfaultfd keeps > filling the range, blocking other writers. Any user that can read the > file can trigger that through a MAP_PRIVATE mapping and UFFDIO_CONTINUE. > > Let's fix it by making UFFDIO_COPY, UFFDIO_ZEROPAGE and UFFDIO_CONTINUE > return -EAGAIN when faults in the range are blocked, so user space can > retry, instead of waiting in the uffd code. > > Returning -EAGAIN simplifies the implementation. These ioctls already > return -EAGAIN, including before making any progress: for example, > UFFDIO_CONTINUE can encounter this when khugepaged removes a shmem page > table concurrently. > > QEMU, for example, prevents concurrent RAM discards and page placement > during incoming postcopy entirely. Applications that allow concurrent > hole punching and do not handle -EAGAIN could be affected, although > existing races would already require proper -EAGAIN handling. > > The existing uffd code already handles partial progress and wakes > resolved faults properly. > > Share the range check with shmem_falloc_wait() and preserve -EAGAIN from > the filesystem in the UFFDIO_CONTINUE path. > > This has medium urgency, as unprivileged users can make a hole punch, > and writers of the file, stall for minutes. > > Fixes: 4c27fe4c4c84 ("userfaultfd: shmem: add shmem_mcopy_atomic_pte for userfaultfd support") > Cc: stable@vger.kernel.org > Reported-by: Chris Mason > Signed-off-by: David Hildenbrand (Arm) Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) -- ~Gregory