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 863CCE95A67 for ; Sun, 8 Oct 2023 21:53:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C59DB6B018F; Sun, 8 Oct 2023 17:53:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C09EC6B0190; Sun, 8 Oct 2023 17:53:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF82E6B0191; Sun, 8 Oct 2023 17:53:07 -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 A000C6B018F for ; Sun, 8 Oct 2023 17:53:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 583911401BF for ; Sun, 8 Oct 2023 21:53:07 +0000 (UTC) X-FDA: 81323645214.24.2AF9E56 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf02.hostedemail.com (Postfix) with ESMTP id 0AB4280004 for ; Sun, 8 Oct 2023 21:53:04 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Vo0lYbMx; spf=pass (imf02.hostedemail.com: domain of alx@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alx@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696801985; a=rsa-sha256; cv=none; b=nIoaOzH7cyFemh9W6eq0/HFvQT0HFwgxX20Vho50uPQF9voZx3NIhXvJB/OIoKpOA/EkeB DdvBhr+qONn+Ei9BaAFgrzNZWLSXjeW0PBgZXBdqJ6muyvqJ2Gokxjkzdkf6PPXU83Bt4p BlNCucRo9/4E1HPAzsL92kYXFtsJesE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=Vo0lYbMx; spf=pass (imf02.hostedemail.com: domain of alx@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=alx@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=1696801985; 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=S3m9znLPo2CYBgBefdramvPQaJ0vGGuCFLYvim8CmdI=; b=gIDOSAkvJzgBBGcpxFVonf5SZ+OWufniGXkokUp496CzKbvuij+KmrEj98tsAIH+1Mb/ek 9F4/CI5pyBAZ+oI6r+3wTXAicpt3k+0ZRNg/lON+FIG34bvGSdcQoVB53s2RPt3qNqfBX6 hLqlO2s5FzNmT5WrxqRfc/nr1FjRGUc= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 9AA7DCE0CDA; Sun, 8 Oct 2023 21:53:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE02C433C7; Sun, 8 Oct 2023 21:52:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696801980; bh=ej6qPerfgZFriLCt1FOJ2SBffAjDi+XhXPfeurlTIS4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Vo0lYbMxYE1jZbuGiDMltJMLV0Pgv2mgTDphI5PciHHC96mK4tZ9LAnJtnEMSoIx6 02Kz4WKhsLlGWxkOe2/DYc/7ML0J2M9S9sPYwcqI1KZFZwawu/nKPJ1Xd0n6Yj3FIV BL/u4mtE++faoS2T1v0g8jsALK4LcdWFB8jys7vhryvQPKCIIa5/dESzOIGPT7tk1n OVl9cMubf+kMWfIeYVcmXwa4zZGLJImH0RvQbh7fEds5hYBc4C06WkWgGZlZxYWVlK fnjdHOSKMFFj3/DMkbpvGdHr5hbt64102ipxZZDzTBNkGSlsyf8YlrhIQ9IlV0FgP4 fUYwADfGASApg== Date: Sun, 8 Oct 2023 23:52:56 +0200 From: Alejandro Colomar To: Axel Rasmussen , Mike Rapoport Cc: 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: References: <20231003194547.2237424-1-axelrasmussen@google.com> <20231003194547.2237424-4-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="q07TwbX2z1RRAfBB" Content-Disposition: inline In-Reply-To: <20231003194547.2237424-4-axelrasmussen@google.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 0AB4280004 X-Stat-Signature: yamadf3jpuwqfgpgirksxgukpperqzg7 X-Rspam-User: X-HE-Tag: 1696801984-1043 X-HE-Meta: U2FsdGVkX19oekJGArnszilCU3qPta/S0VxUyhKJSCwWuTb7IbZVn+gDYGnf2F8iDb1e0m06w8xzVB5PqZfM9Af+BxVuiZ+R6ZB/axj/W6DW1ki/e8oO+M0AwAFUiO/q4TDPAB5h1KFiH1JmL/hghDfBOdiBC1eZJ8a9vkX3t8cFJHYZVt9WAhFAZS+INsnlVxcD7mS1zIAz8vnTyv+34SLBpVjaK7Mc/m86QmNiHUI+r81OLKmshbv0YSDe/pBEnrpYe6kccTR2yQW+YEkBRAgkgvLlgYYcInJG3yVEhi0Yh3+r3ojBAbqOFzjQqhgWMA5UxgbLLZ2cmNK424vWIvxA7kA84+t3pI6XN90I6wr7AboWK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ter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --q07TwbX2z1RRAfBB Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Date: Sun, 8 Oct 2023 23:52:56 +0200 From: Alejandro Colomar To: Axel Rasmussen , Mike Rapoport Cc: 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 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. >=20 > 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. >=20 > Signed-off-by: Axel Rasmussen > --- > man2/ioctl_userfaultfd.2 | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) >=20 > 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 > .SS UFFDIO_REGISTER > (Since Linux 4.3.) > Register a memory address range with the userfaultfd object. > --=20 > 2.42.0.609.gbb76f46606-goog >=20 --=20 --q07TwbX2z1RRAfBB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmUjJLgACgkQnowa+77/ 2zIvAA/9GYOyYYlNERqW/yXmh5Tg3E/gssJaue4y2SGAdTQzuSiyqiRu41V1fUbX 381Ma4SrFvhgGwREJc0xucH/Nj+WsJT1JtgCXjJjkFhT3S7+m4XRZBx2jt/9Hnhq 49GZHokw2As9MHioJ6k5Q5plrUN5451KbHEPL4yuvk6jD7JfeY9DhXZy+Hftye4A gxIPOweAaXUkWbVJQQeDFX0GtK8yY2VO9TkoNkPI0Ec1cJjIWAQ1w7i9cdW3VIw5 Uy3IzdqW3ovZ3dx1FrGKLrtM/3NaI00N0BzXKOQz3EZ8vfpzga57+YOK+SJEDZIm AgJ5zNkJPl+5wpQRdCv1A51X8EoYO+ZiN418i9mClP9IhMNvczOTZ4tKUcMlXMJn i69i/0AWFoecCCVZqe/g7KVg0IiJUUE4HblyfsAhOiqz4XhUw69uCfqtaKzBGG34 bxttfeqm2I2WWGBe/pluAg1I8uQtcCBhog7/J1Mz20LPbFxrGzz/jpWT5UVaxuJP QivbRf0yxsLy/mzAC70Vm0P6JndrfXGr5nTvWunco7y5/SSagA9QDmYfmodgTliG eQh0ghyYx+wf5EXmdNS02KqH4+GPXW9/3XtypNLy3oLIqimmDWIQE2LQ4/MRPq69 knb/wWn6LkwA2Ta0TFF7QHYKPtFzgpFi1eBYI3ySuqUlYkOGE5U= =tpHy -----END PGP SIGNATURE----- --q07TwbX2z1RRAfBB--