Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1577924rdb; Sun, 8 Oct 2023 14:53:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9S6NX3ntATpx0S5nnnuPWptqEJkhll3wI/gAenXsSjiHrpItJICKI9FfNXpHFqmdtrXXG X-Received: by 2002:a05:6358:2917:b0:13a:a85b:ce00 with SMTP id y23-20020a056358291700b0013aa85bce00mr10605710rwb.31.1696801993434; Sun, 08 Oct 2023 14:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696801993; cv=none; d=google.com; s=arc-20160816; b=GqzPgEHajuixLAkthyUZUfFVfRkiIFnu6e61M7B4c1fpleXxdU8eQGYxFJij7gFX3Z 34+qUggF24FXXt/QarCN5ksuvt8PPw+0UDDR93yi2u3+bdBnIEXoYvobpWYrnUOGzLRj mkwDYLMF7tXlHAfSB8/8+q+5DA1SBLzjiGjXw4R0mvT/IL5v6YGr/mkHAJ4G3iHoPCNt OmZCKl3MPseEfXgvn7HO1vpk3CEmj1j06mbOg0pFnQxHuJ7itI3DoZnpphG8gQnj1uJK XNYYNBZ+xZ/qtfpAfS27ksZhPkxlTUglK63RMiunaNhTXuM62taf9MNArSMgYBTMCap2 3oPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=S3m9znLPo2CYBgBefdramvPQaJ0vGGuCFLYvim8CmdI=; fh=dmQPU9nHLXihakYBzt3iQZ6H+x79F72+twZdiUrg86I=; b=krdm48ePveSeE1BB5RlK0Tsko9rY2dOYYUYUy98M6b+TjvbgMvqzcRLmRBomlGnLaY Jb6KGCl4mfSsJSfrN7ASK7paWxKtpfMDyJ3HbtRQklA3f72/8XhEXLhf1zsVr+Kx027o Qcaon8C1a0fXwupcjDU6Fnfoe2WrBoveunuZKUiEB58ndW0O3EdKRgs6pwGaqMAA2syM xuXMrWhw+pE+L0CEsDz/hDH/eSrcz5J0pj9Q6yYB7EAOOM9WtVYwxpohsi2T6pgKmd0k ACcLDBnFjQwxjpKfERc0vCj32c78iMkEI/4UAM6/5wihIOqGCt5FTUyj7ccyW6s3g8GZ ROIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vo0lYbMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id y13-20020a17090a1f4d00b002792831692csi10078946pjy.58.2023.10.08.14.53.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 14:53:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Vo0lYbMx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 277D38024DDE; Sun, 8 Oct 2023 14:53:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344697AbjJHVxE (ORCPT + 99 others); Sun, 8 Oct 2023 17:53:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344437AbjJHVxC (ORCPT ); Sun, 8 Oct 2023 17:53:02 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39A369D; Sun, 8 Oct 2023 14:53:01 -0700 (PDT) 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-Spam-Status: No, score=2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Sun, 08 Oct 2023 14:53:11 -0700 (PDT) X-Spam-Level: ** --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--