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 28DECE95A8E for ; Mon, 9 Oct 2023 09:13:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B44D98D0034; Mon, 9 Oct 2023 05:13:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AD8F78D0031; Mon, 9 Oct 2023 05:13:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9BC168D0034; Mon, 9 Oct 2023 05:13:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 893C78D0031 for ; Mon, 9 Oct 2023 05:13:56 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 41753401A0 for ; Mon, 9 Oct 2023 09:13:56 +0000 (UTC) X-FDA: 81325360872.13.37B88C0 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf15.hostedemail.com (Postfix) with ESMTP id 346EBA0020 for ; Mon, 9 Oct 2023 09:13:53 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="XoVD/LVv"; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696842834; 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=/bNBfzadQWIHGQ2DOV+RDjrnYF1gyxXlPVcMan1/Zz8=; b=OdD1Mur41Tfem902/ij8+O7sDjxBxtnZUMIM1UdoJIfbH38U5bKWrIkLjKAQXN76N7oUkD Dwo4lSjN5U8pnFfvP/zkRasIy37MsTLtEGCTqZ4+pXjUT/Cw78PZPKTX20mr1wcTn/8e6v nqkAtLree4DTEQLiLv/7ZKklaSzZptU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696842834; a=rsa-sha256; cv=none; b=GiBqF/6ocjn+kBtVbG7lWC8251u1jDy9c3qmxrzV4m9X4dKyfCaQ1RNsulzIUmU5ydjWNM WsI/0msBQkdwckJJicHXMFvKRi7fy6Qqo5Xu+vg1vjw+ZNispuayMJx8/H7/AjsO0QK6hd HWuPByeGi2I9O/gWbnD5XH5jRW5rE98= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b="XoVD/LVv"; spf=pass (imf15.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 4D719CE1129; Mon, 9 Oct 2023 09:13:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D231C433C7; Mon, 9 Oct 2023 09:13:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696842830; bh=jhipQjsWiEs+Ekubf342gQBtzevOfGi2BJ5QvrVCXa8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XoVD/LVv8aVw/fiyc7REZB4iBGjkQiMDiIXjJ1NUvGS912djNzCzSccBrjVnA+B8p QuINxv9JhjARUPo061A4lil0hWTiXPcrh+ZqqouR3fDxSnMnSajcFWBvPm9d1WPLe4 PuSmHoiF9ObcPxlL4eujAkAUsCkEMj7YZzWL8VuvPqtwuWm0mVpu3Xt8eQji7zPR81 sgg9LhNcKSushKV2A2D1/k+twz+uWzbWBdJdkiYqcVT8K38J6uUy0T0SrCfYddWkBu YiS+jP7rYMqxhA3i9wjwmIAtIgC+zMWjw1BsCeQescVFaEsFNdRaPIrYH0nZnzX28w IVrbomr9ZLrRA== Date: Mon, 9 Oct 2023 12:12:56 +0300 From: Mike Rapoport To: Alejandro Colomar Cc: Axel Rasmussen , Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/5] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error Message-ID: <20231009091256.GN3303@kernel.org> References: <20231003194547.2237424-1-axelrasmussen@google.com> <20231003194547.2237424-4-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Queue-Id: 346EBA0020 X-Rspam-User: X-Stat-Signature: qfmnhngtrqktigi7usfym383hxujwtf7 X-Rspamd-Server: rspam03 X-HE-Tag: 1696842833-158536 X-HE-Meta: U2FsdGVkX1/yGRHrfBlRGmHoyT8u/PIdpVougbn4g/WzHStUX147KC8FQXsd9SO2xXutwPd9U9CPjDS+oYPuqS6PC6LevCxSQm28ZjopMwDvqm4+3qCHWFo6EGjqNfpSlvg+0ZkPTg5EABZ1AHZBvVj32qOwMRK5CMRFfsjP44S5WGpQXBTRMpFQhbwVQejfhN58sLpSLdHl/qRpPbwY2T80NZd5pyLN3Ybck23PpbVzR1QgE+pNeKW+D6YN5MtffLkqtc62XeBUifGYimSr6rjiiwOnH6qPovoWYh/Gvh7t9kjDfalnEDbEzZuVFDcptuR98e71tkdDF67dGOc9cQUXU1e4ftQeNDexFYPmx7nkKe5hvUnRDfKT8w4RTRHI9ldnyu4C9/dbnJAZ5MHLz0Y4wFV015HgJm2EtscuQhS62N+IHOsAftjRJKD0txcSuofxAXdRVRdD+UvHPSRsjPirOAANTWLPhnj4/4HF+HrKZ/b6JCotw+k8yb385OjuyqyMq5eoOajbaY4vf8YPK4bMOH8nAwdF2zoksKs1sJNch6t8pXhpmOjgjb7uhlY2Z0eqivlLVDYj+MMYXL+qCm7P5cqz+UE5BCsxqHDNCR69LO4RRKfDPc4CvbxOfv3EuoCIeXRLM1HJmmddhKe4yK2iDsb1y3fePi/pyiHi0pa2k3uh6IidPoELsldfqVomfcWo8Hs260Y/NZWp2DQ3Bor1n/m6HQchjx4evOLldbrL2o09Vz0SIxycCdZx0BeoKFLwjfCyrRWfPpxJMhkNYXlyQ3S+HBwA74py/nd2FgBUnEyLKWs0uECTRoqQYdILtDCGpPVERKfbL4gI/k4vtzBVyuSa4TC8muSGD8prHcIRKtcUIbw9l2OmOH8/OK48HZk0EfmVNdT5TzPBytSS/PqPTwTm0+tG4L12hiCEYHNSI7UpWOi4Qe/4mCycO+nLg+cOEuZr+r4+o2o7UhR KbuQPX5h 4djTBWh5yk/x44RxDf1gYExPD9n95WFLctmvvkz/KWaCF2P6JEzki+MqP3iDPtr8FCpg8DcSgtyjBkTHwmhWrl6g40HsayyGZzAYuZxpPGf8rU+3HL5T7Vi7Qldcp+m8+ooyQRDGg643zhuub06S0g8zqfSB5o0w5wKJ8BcJVXEqLBgucyL4I50t7sD8Iq51IbtIq1hD8DUAdAzpNwmCDw+rlvPyE0yzI/cmgWFd/Y1M89Uol2LSS+tcARSRP8HOv1+qn1ZRFGg7xCdJXykfXpOcfR5cZSiEOQnN5kHMoGSHI0cf92mWTlCO9mP7mg4xFoNTo 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: On Sun, Oct 08, 2023 at 11:52:56PM +0200, Alejandro Colomar wrote: > Hi Axel, > > On Tue, Oct 03, 2023 at 12:45:45PM -0700, Axel Rasmussen wrote: > > The old FIXME noted that the zeroing was done to differentiate the two > > EINVAL cases. It's possible something like this was true historically, > > but in current Linux we zero it in *both* EINVAL cases, so this is at > > least no longer true. > > > > After reading the code, I can't determine any clear reason why we zero > > it in some cases but not in others. So, some simple advice we can give > > userspace is: if an error occurs, treat the contents of the structure as > > unspecified. Just re-initialize it before retrying UFFDIO_API again. > > > > Signed-off-by: Axel Rasmussen > > --- > > man2/ioctl_userfaultfd.2 | 16 ++++++++-------- > > 1 file changed, 8 insertions(+), 8 deletions(-) > > > > diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 > > index 28dd2fcdd..2ee6a0532 100644 > > --- a/man2/ioctl_userfaultfd.2 > > +++ b/man2/ioctl_userfaultfd.2 > > @@ -248,6 +248,14 @@ operation returns 0 on success. > > On error, \-1 is returned and > > .I errno > > is set to indicate the error. > > +If an error occurs, > > +the kernel may zero the provided > > +.I uffdio_api > > +structure. > > +The caller should treat its contents as unspecified, > > +and reinitialize it before re-attempting another > > +.B UFFDIO_API > > +call. > > Possible errors include: > > .TP > > .B EFAULT > > @@ -281,14 +289,6 @@ feature was enabled, > > but the calling process doesn't have the > > .B CAP_SYS_PTRACE > > capability. > > -.\" FIXME In the above error case, the returned 'uffdio_api' structure is > > -.\" zeroed out. Why is this done? This should be explained in the manual page. > > -.\" > > -.\" Mike Rapoport: > > -.\" In my understanding the uffdio_api > > -.\" structure is zeroed to allow the caller > > -.\" to distinguish the reasons for -EINVAL. > > -.\" > > I've added Mike to the thread in case he wants to comment. Thanks, Alex! It looks like I reviewed v1 of the patchset though :) > Thanks, > Alex > > > .SS UFFDIO_REGISTER > > (Since Linux 4.3.) > > Register a memory address range with the userfaultfd object. > > -- > > 2.42.0.609.gbb76f46606-goog > > > > -- > -- Sincerely yours, Mike.