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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09B94ECE579 for ; Mon, 9 Sep 2024 12:15:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A0426B0165; Mon, 9 Sep 2024 08:15:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 028B26B0166; Mon, 9 Sep 2024 08:15:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DE5146B0167; Mon, 9 Sep 2024 08:15:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id BFEC66B0165 for ; Mon, 9 Sep 2024 08:15:21 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0617F1411A2 for ; Mon, 9 Sep 2024 12:15:21 +0000 (UTC) X-FDA: 82545094842.30.0DC37F4 Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) by imf06.hostedemail.com (Postfix) with ESMTP id BB1F4180021 for ; Mon, 9 Sep 2024 12:15:18 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=arndb.de header.s=fm3 header.b=YvuDxi42; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="f imP6L2"; dmarc=pass (policy=none) header.from=arndb.de; spf=pass (imf06.hostedemail.com: domain of arnd@arndb.de designates 103.168.172.149 as permitted sender) smtp.mailfrom=arnd@arndb.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725884006; 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:in-reply-to:references:references:dkim-signature; bh=CgLgudbLDYfmS+qKBAFvUu698HtGa2VzY0t6nzClv+I=; b=3en6EJ43/xyXutFe/qdcQgcRS6crtmvdA/Ctvi97Oz1j/o0pFASMOHxj5mZBzr061DQyxR oSzMTNeR84tljz1xAoEGu0S1A4S9ybZLhjWahJPLoqWbtZXQmpJMQU4BT2UnLTRGUgntJX 7ofPbqLkO4s32nzDvbVsupKauNjz2rQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725884006; a=rsa-sha256; cv=none; b=jll10FnkSqJ6O7xpFq/OZQzHLhyBi8x4UCkfZOZdq1F+EJqsuveK5aFnxdPOzSum1YgyPh tYVvK+zFVT6i3aKuNx+M5ZAR6jzT8Vw/E/7BD57f/VB3l8DoiJ1bexnsztYnaJ/UMhkE+Q pYXAzs/+D/wZF+xh0qoa7lB9ULVC0KI= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=arndb.de header.s=fm3 header.b=YvuDxi42; dkim=pass header.d=messagingengine.com header.s=fm1 header.b="f imP6L2"; dmarc=pass (policy=none) header.from=arndb.de; spf=pass (imf06.hostedemail.com: domain of arnd@arndb.de designates 103.168.172.149 as permitted sender) smtp.mailfrom=arnd@arndb.de Received: from phl-compute-10.internal (phl-compute-10.phl.internal [10.202.2.50]) by mailfout.phl.internal (Postfix) with ESMTP id 0972313802DC; Mon, 9 Sep 2024 08:15:18 -0400 (EDT) Received: from phl-imap-11 ([10.202.2.101]) by phl-compute-10.internal (MEProxy); Mon, 09 Sep 2024 08:15:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arndb.de; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1725884118; x=1725970518; bh=CgLgudbLDYfmS+qKBAFvUu698HtGa2VzY0t6nzClv+I=; b= YvuDxi42ZCCkntXgFXcRWVMjSzZva7+zmGR8GolfAe/sZRzItLW7qKfDIMa0y07Z knIt24oWw2p89q1vt/LIGMavSwKEAQkGspQCNkQ9wmtyns4+Ormh0wbNnfigpkpE Yi1PZcmSN086ooQE9aPoi7YXiLH4ZhvCYEAyn4nHLiENHoBK0jmhfO2Sl9VsRVQz WIxn3WgCCl3khBAs7ehKeuB4B3f/fpc+MQ5PM+5Pa7UEg6j3fvN/384ZLfn3ToRc hcHI5EIuoghFouJ9xdHgAV9zBcpl+c//UweY2MyX6b2izfDDYxG95/up5Eqm/sJj rOL2s3bkcF5/sWCJNPsc4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1725884118; x= 1725970518; bh=CgLgudbLDYfmS+qKBAFvUu698HtGa2VzY0t6nzClv+I=; b=f imP6L2uMw+F+rBzvoPLBANmsy4F4xUq5V1z5KVXxFjNquMbVEQDcDzriw0xagOwg AY8Hnq0f1lBA2tDW7k534kyeSGHuDNWKwK5xsa3ljbFAxzr7s6jJ1RHDH7GqbfGI 3LFyILTuHZDojU22l867nka8uRNa79WDUWq9rRQQmw9M1hcAGiz6ZYjnVTLKD3sf oLJdaAzRjAmwibgWpfE2NkNxD+s/E68QAYqIR1tyj9RkfScCdOjmHSD3s1Lp0w5+ lCdKUJOCVgG8WUaCX7BqylADzcu36krHHzEBT6RBiap/y3sSeQwZOEvsyzZt/VlN bYjeTupAlDmzp/qvnwybQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudeijedgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepofggfffhvfevkfgjfhfutgfgsehtjeertdertddt necuhfhrohhmpedftehrnhguuceuvghrghhmrghnnhdfuceorghrnhgusegrrhhnuggsrd guvgeqnecuggftrfgrthhtvghrnhephfdthfdvtdefhedukeetgefggffhjeeggeetfefg gfevudegudevledvkefhvdeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpe hmrghilhhfrhhomheprghrnhgusegrrhhnuggsrdguvgdpnhgspghrtghpthhtohepuddu pdhmohguvgepshhmthhpohhuthdprhgtphhtthhopegthihphhgrrhestgihphhhrghrrd gtohhmpdhrtghpthhtoheprghmihhrjeefihhlsehgmhgrihhlrdgtohhmpdhrtghpthht ohepfihilhhlhiesihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopegsrhgruhhnvg hrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehrphhptheskhgvrhhnvghlrdhorhhg pdhrtghpthhtoheplhhinhhugidqmhhmsehkvhgrtghkrdhorhhgpdhrtghpthhtohepth hglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtohepthhorhhvrghlughssehl ihhnuhigqdhfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehjrggtkhesshhush gvrdgtii X-ME-Proxy: Feedback-ID: i56a14606:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 891F8222006F; Mon, 9 Sep 2024 08:15:17 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 Date: Mon, 09 Sep 2024 12:14:57 +0000 From: "Arnd Bergmann" To: "Christian Brauner" , "Thomas Gleixner" , "Jan Kara" , "Linus Torvalds" , "Amir Goldstein" , "Aleksa Sarai" , "Mike Rapoport" , "Vlastimil Babka" , "Matthew Wilcox" Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Message-Id: In-Reply-To: <20240909-zutrifft-seetang-ad1079d96d70@brauner> References: <4psosyj7qxdadmcrt7dpnk4xi2uj2ndhciimqnhzamwwijyxpi@feuo6jqg5y7u> <20240909-zutrifft-seetang-ad1079d96d70@brauner> Subject: Re: copying from/to user question Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: BB1F4180021 X-Stat-Signature: iuc65wgsm75fhcxp3cocbdes4h18ysp4 X-Rspam-User: X-HE-Tag: 1725884118-795772 X-HE-Meta: U2FsdGVkX1+E0BxiKUnEmpXqvGOhJTnNE1D5Hq1EtJV+wJZsRQC/2HHfJcV56UeWCZxez9NQPbBSFel4O6hNSDhUyGCEb5vBLArgf75h5o5KVHExO2xHfZfxu0RYiFi4sAvfVtxBQ9coG3IJEQFMoYmZFa4LQur8cSAU/zJt4efO0gJinc/UGEF/u5uiqHvtAqlL91lWgpuN71JT58rXbSAA/XuBbw41cRg2wKILbUixcuG7UZ0uumPpk8GiRr5ZVo3OSONgG/sp5c7E01tuIiRrxEPHFxIS+dofzFpMl3ACmonUsZoCrPNLJilrFTxpEEC9jxpnJJZjnHRBBBL/hu32u6de0XkCR9zjquTk+Y5OyDHQfCXPf4JxransheRI47lqHKpZpZe1ApB/WYti/iIm5oo3MJAfmEw0jD/1RTerEuGd8XtM4AFer58t0B5htIK3xvYrcTznJ1kWHjrfcCR1KaYNiccNhi6A+Xqa1gde0ymM3RSBbaYg6idr3su4ZqN8aQu8gRtKXfxIuSqm2qx6cwL5ft17JMLGeRr/HkRNw7F6MpFhFv7GbvsAk7usV54cxBq1XlZNQJZPm28fxjX00qSHs7RJH5yQ4Ffv17QlSdeYcxtQaxiO2mVDNkNTp1Cum1pTMQhY/zNpGYTvLlxZsLCiJu8hSiYrwmmM6sOzx9EipjkPrWDKLe5saLdh98aa31IGUFh85v8Ums1RDtVgrOk1EUNQNQgVSoCufIeER9gblXhbzC9mLvCzbWeADh1dWK67jSLYk67KuPoKw+fOngZIKMnkMrSnBsGE6X3vFPMK/7GlvIrkdmmzpaUZEtKYc+Vzeo4yYA0bWaUksBg9CQKM2fu4+Sp6oJkyt+W4sSOK8Uo9EmMzUeztJeX28UjX/R7AWnvX0Ri1k/JScpT8xga2C/H6lb7WQ47Nxi7AiDws4sdqWYidnFx1ulOnzWB7/WCTCZHKMz+DL/1 tejFL76L M9u0948E70GzrdFt6kejMvQi1JqpdwayKmy9rgQaBOuMIS9rZMFkuTGPOFrzTOwtGn26kNkZ93PbEkJY1Z/Mgd74FAizVUCuOn/BznNN7MVssnlOTKmKnHzeNQeaNIhlfR3iC7Zk4yozkNZOLLPDRYQXOOVrs36F9uSkPadvYsNAjyBk5YuHLlPJR+g== 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: List-Subscribe: List-Unsubscribe: On Mon, Sep 9, 2024, at 09:18, Christian Brauner wrote: > On Mon, Sep 09, 2024 at 10:50:10AM GMT, Christian Brauner wrote: >> >> This is another round of Christian's asking sus questions about kernel >> apis. I asked them a few people and generally the answers I got was >> "Good question, I don't know." or the reasoning varied a lot. So I take >> it I'm not the only one with that question. >> >> I was looking at a potential epoll() bug and it got me thinking about >> dos & don'ts for put_user()/copy_from_user() and related helpers as >> epoll does acquire the epoll mutex and then goes on to loop over a list >> of ready items and calls __put_user() for each item. Granted, it only >> puts a __u64 and an integer but still that seems adventurous to me and I >> wondered why. >> >> Generally, new vfs apis always try hard to call helpers that copy to or >> from userspace without any locks held as my understanding has been that >> this is best practice as to avoid risking taking page faults while >> holding a mutex or semaphore even though that's supposedly safe. >> >> Is this understanding correct? And aside from best practice is it in >> principle safe to copy to or from userspace with sleeping locks held? I would be very suspicious if it's an actual __put_user() rather than the normal put_user() since at least on x86 that skips the __might_fault() instrumentation. With the normal put_user() at least I would expect the might_lock_read(¤t->mm->mmap_lock) instrumentation in __might_fault() to cause a lockdep splat if you are holding a mutex that is also required during a page fault, which in turn would deadlock if your __user pointer is paged out. I have not seen that particular lockdep output, but I imagine that is why VFS code tends to avoids the put_user() inside of a mutex, while code that is nowhere near paging gets away with it. Arnd