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 BB81AECE57B for ; Mon, 9 Sep 2024 09:18:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4AEA16B0147; Mon, 9 Sep 2024 05:18:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45F246B0148; Mon, 9 Sep 2024 05:18:33 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34D6A6B0149; Mon, 9 Sep 2024 05:18:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 160D96B0147 for ; Mon, 9 Sep 2024 05:18:33 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B596AC0CBB for ; Mon, 9 Sep 2024 09:18:32 +0000 (UTC) X-FDA: 82544649264.28.3103F5C Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf07.hostedemail.com (Postfix) with ESMTP id 2352140009 for ; Mon, 9 Sep 2024 09:18:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n6Q2qWZi; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725873484; a=rsa-sha256; cv=none; b=C/FGywLLgbINzM0gY1pIsHB42jKCuzzzsUVLJPkJButpNXi9dLQzL4u2aiJJTKHXSs18lY cMiSF6NqwEtgtq0s60m3y+RYZ45zjD6jgDocc3Yijy39WmCp3t5z80kiXNVcN5L4wsxhKR Van6W81ds2mhuNRv7iMj3COHkqedrTY= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=n6Q2qWZi; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf07.hostedemail.com: domain of brauner@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=brauner@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725873484; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=bG5bpoAow8TCG6GaGk90tt9+1jTaDrxKR9gDLiv/BM8=; b=OEYX7Ezi/A0s73uHf3j8BVKbGa6temRtM4MRnVj72z6OwXtrddEDi+EZf93E1zAfACZ7w2 ZojpdUvswLtiSl3b1h8TFPAzD8V7yINJZqsLX+wRhn1vgevrntz9MwzMUPynqpLEeyNlTz OYv9tH03372zm7CrcbVktusQNFVRiTQ= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 07FE5A429D5; Mon, 9 Sep 2024 09:18:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A17C4C4CEC6; Mon, 9 Sep 2024 09:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725873510; bh=GPzd0E7ui+aEseiBiClSy15vw20ljTBM0yt5ijjhDNk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=n6Q2qWZiBevm32pQmKwLGAwcryx2jNCCia6PPcjHTF5H3Wjn6AOINArmAl7pD7uve DVDQawuIUmmqEwUzss0Ow+9iaTz5W291Xqc1bve+6suDq82gHyzMeKjB39qK2852UD xshM+nXNr4/anZc0ws/yapnBawUc4YR+LSUe1ohscT4Wk3Rbu5ftSujgZLo7NYvXgd fC5QGgd1bPB5QfwwGLhb3BjqEtsGhCPRVZpXG3I/hrG/ScsxyUMt7Q6xejiiAoTBpa Kv6V1O97QpJU29KjSrn+LbQWx2bz4fLxrZd1P2mPDgnaJ/jPM49b8bFGW+ttePBuaA YUUm2ud6hI2Kg== Date: Mon, 9 Sep 2024 11:18:25 +0200 From: Christian Brauner To: Thomas Gleixner , Arnd Bergmann , Jan Kara , Linus Torvalds , Amir Goldstein , Aleksa Sarai , Mike Rapoport , Vlastimil Babka , Matthew Wilcox Cc: linux-mm@kvack.org, linux-fsdevel@vger.kernel.org Subject: Re: copying from/to user question Message-ID: <20240909-zutrifft-seetang-ad1079d96d70@brauner> References: <4psosyj7qxdadmcrt7dpnk4xi2uj2ndhciimqnhzamwwijyxpi@feuo6jqg5y7u> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4psosyj7qxdadmcrt7dpnk4xi2uj2ndhciimqnhzamwwijyxpi@feuo6jqg5y7u> X-Rspam-User: X-Rspamd-Queue-Id: 2352140009 X-Rspamd-Server: rspam01 X-Stat-Signature: uoytybtcadyrye7gehsy79yz3zhaurcb X-HE-Tag: 1725873510-79516 X-HE-Meta: U2FsdGVkX1+N73sibISEH7c2AuJo0fLbTb2249V1XtWmnwNf9fleT680dDGEN9r+4eTYMgqoyI/U38syLA5hA/Op7Mtxjy2mUUEqwLaAm99ywTe0AgczfucYm+CuuObvv7dglDWR8DkycDJ5qybez5pvn7uZDL4DCouAHCfAUAc5kZxIRk+/3hJMfa7m1plYFNmQhiFaPTDlYYbHpYCj67pOb7GclnirRvENMbH9+4HTQYCt9mqodqza2NqwilISlGt6UOrgPm5FavnufHppEj5SZ66LCnDc5nOaT9yeEHHy/D0G3lkgBecfYTbQi//fqVDhV7xgPdZsdGZkMNu53owDdRow6IjEJdg6rpRxbfgZqNrGucG69CUZ/1UbBlnZXAYY06P110SHzWhuD/8/AlLnKTlOiCzaqN19TGQgGNFF6y+YL/IydsulV1k3HJILR9eYdfCsVLYHc1a7/+jpB+A9MA3oZz8aoNBzVGW3MtTEfLPpW66vE7ewLD4IzcqX7GcESIlzv0v+ApVQuL0Dy5OtkXo6I0edGeqyNvTXTi/JPv6reRAVkdXjhfPEeLS6+F2ikc/A4/0RcWNgivyijRP9q3aSZWGBhEPm4YMuJ0HyA76glrxMhYaGEWkoNiDZakvpCLvgnqALXWi23+pgXV4AbhFU4wGgHbuxzdPtpIVXqiW0kF5tiWwcuPKPL+dB442r65hxLlvNEJTD0xD1AnYZIPOsYWi2ACr19N/TraqVQTHvIhhKOZxCMGNkNgqLT7DMhmmCLrWVTLBrI/DqzoJ3vt7LpT9N2dnPX643YBZyzpPdjynKAcdmkalRdWYtX8lWp9sF1u3vChICJ5XGN3DeaF4RxMu1USqSs8MHwNZlEJBo590awMX0NGlgMaFdWmXYb/fBalrJzfZiS9PTpti5bmkUJLr4z4igGmwrsgMw3vxq1p8v/WPaUrImhWPARzVTeUYVCSvFVbkldzj 57+paJl9 wTbflSqItwBma2ey2fUH21y0izzXwoqHnVDNm8k4NTnhN/lOC/nZKqggAvwweSZfLnK29BijD1nxQDnvfMXOCrPGNqNezt44UgtLfhrxO80uFhhyF1RdwKqb4p4FSYXiXM3dgzf/0ky3ZEaf7NdLg/seLyrDEsRsi7XLHPtGdYBUWd+ZZj03ROKRBsyagsmsmKVrRaPouSOGBHCQvI/TsXLD/NZoQkrQkZ5C4cymVE5q5hDJIf+6Wcp4JoHeRV9G/+lTRBcc8aAy2grD2zkimTZc7qNoa5QNjriwNYH/JTjTj6qg= 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: [Forgot to add Thomas and Arnd as Mike pointed out] On Mon, Sep 09, 2024 at 10:50:10AM GMT, Christian Brauner wrote: > Hey, > > 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?