Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1548327rdh; Mon, 25 Sep 2023 16:59:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhVYlmaAkvFi3OpUhEjbh/hlC027C9Zp9Q9JcMkVs6Udd++YGFsxZcyLMKYXjs10YeK4f7 X-Received: by 2002:a05:6870:890a:b0:1bf:9fa2:bf8e with SMTP id i10-20020a056870890a00b001bf9fa2bf8emr9704788oao.1.1695686391289; Mon, 25 Sep 2023 16:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695686391; cv=none; d=google.com; s=arc-20160816; b=IfGf024FTiFj50keyVzk6i1DSrVoLOl7iiKmFUGJGMCtaoL3NuKw/vr6if6BU2V4Gp FkuJRVMQY0xItvvxcsjfVs6tG53DUf0aVD0a0KTp9z+ona7rXrr5fpZV/Ao+dTt1Ki0h agZ7lLbgZuSZ53wxHxkDdgGFr6Tp9tiPiCKqJwiS3+KV4pzsYuBlL/7dqkm5KVuUcPYP LDvqvY8vIl2k2jlQJ2/QZ9bH3NYo7bUIDmPG4H5BdACW0McAiaEpV4hZ0Zh9HyLUn3Th nsTQ1z3zHkq3EFgTnqTZBLvA/E/20dIMJGK3Q+aPXrgMt4+emdG7svIiiZrEystX5jby yfpg== 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=K6GQ7ukJl+jUEVvtFVZciFHPhCJ68mHuFz4TQTNjyGI=; fh=wtPNz5QEtytCPPuNNoj9k3ZLKUvhc5S3xSbNrMwZr3o=; b=Q3heLVNPvsbiCR3NyRiEfbE1KdYrXYrDMM1fPMoatMsHg0lV09hM3uHgUJzv6d6O2s GZTv8P1CT/UUbjDuN40xREJnHWdhWZWmga6Y/Wx4+FY+2XZd8ubaCBP23sVc7+/RWOIZ LfavXytflz+buinxvZQJtHNH2FjusLw7JHc0zEDVjE3Gn7JY2yXZpFqBZO2lskPxMQ5W jmZkNI6jLynJk3NNAk5NTGIeWvUteQlIsHa4BQQkGXeS8dyFEX5ZjFVxlB5u5AkIWz5h lGZz68l3w9iTljplisQCjJsiR9r1jrVI6gGzm8QNLxdEiohxiYjOYdZc6LUz8b86ucmY CXmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lFJAIlat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id e21-20020a656795000000b0057760853711si11349667pgr.273.2023.09.25.16.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 16:59:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lFJAIlat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 7BD5B8029AF4; Mon, 25 Sep 2023 16:56:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229813AbjIYX4S (ORCPT + 99 others); Mon, 25 Sep 2023 19:56:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjIYX4R (ORCPT ); Mon, 25 Sep 2023 19:56:17 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF05C10A; Mon, 25 Sep 2023 16:56:10 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1CCCFC433C8; Mon, 25 Sep 2023 23:56:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1695686170; bh=BMrAGXuGExETbvl5OiPJxS7FFi7b70fqhN0uHMUVHQg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lFJAIlatXeyOUDs74QXRdl2atE/vvik57PP8PsLPzOPzYJIHXS5PUkApsT9KW+SAh wj7wy/yd8YtQh2GK39lImhNCGiQ/eLstIImoKBLHE7RkWNcjhwhK80pXtnjc0loFtB D6JbzCOyLvnmKJwkmM0ld75rz9qJiMkJ51o4KQfNmuYZ6sn4LKf7KX8ri2Jfm2ZFcG xj+691RvxkWxKF89n+bbEogBf2JTBElhAy6TLaWyp6/IhDubLMirWgnLtjf37UeM/+ zLlOTYxjVjc/trSXzY9KXs/veAdh8btFXZRNwjvJMpO8ChX6FLwCz3dKF/gMBVUT7Z nImkyVzEws5/w== Date: Tue, 26 Sep 2023 01:56:06 +0200 From: Alejandro Colomar To: Axel Rasmussen Cc: Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 08/10] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error Message-ID: References: <20230919190206.388896-1-axelrasmussen@google.com> <20230919190206.388896-9-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="sywgjbkq4kcpxg35" Content-Disposition: inline In-Reply-To: <20230919190206.388896-9-axelrasmussen@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 16:56:15 -0700 (PDT) --sywgjbkq4kcpxg35 Content-Type: text/plain; protected-headers=v1; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH 08/10] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error MIME-Version: 1.0 Hi Axel, On Tue, Sep 19, 2023 at 12:02:04PM -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 I can't apply this patch due to conflicts (due to not having applied two of the previous ones). Please resend all remaining patches in following revisions of the patch set. The applied ones are here: It's kind of like Linux's 'next' branch. Cheers, Alex > --- > 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 1aa9654be..29dca1f6b 100644 > --- a/man2/ioctl_userfaultfd.2 > +++ b/man2/ioctl_userfaultfd.2 > @@ -272,6 +272,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 > @@ -305,14 +313,6 @@ twice, > the first time with no features set, > is explicitly allowed > as per the two-step feature detection handshake. > -.\" 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. > -.\" > .SS UFFDIO_REGISTER > (Since Linux 4.3.) > Register a memory address range with the userfaultfd object. > --=20 > 2.42.0.459.ge4e396fd5e-goog >=20 --sywgjbkq4kcpxg35 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmUSHhYACgkQnowa+77/ 2zKnPw//YWI1d9zlIUx+sIQ+etTFDCgb9G1nFfGeE4qSWGNBDOFlK6D7cKCKBS9P mihPubSpiM1xaW281n2kDjxOolWeVwXTJFudUgeSoDPSp9895Pr3FImawj3EbnOp rnvn8jmihpy8MhgXMo9onszAC7fvY2vrzeb8e1ftDc6Y0We66Nhl2GtHHpzqtiuv G2SoAD7d1ZtK15iU/vYwaSGe/0NZ7HP19ROw2mx/WUDEu0HnzKaN0mgDP1XiMz8w Jk6Pxip6e10FeKRzawKps4znFFZP3SfoS6we7whdRkC/fXVTod7eTWMkmwdY+bN2 PnOQAxKQg7OT6FPcOcH0AgP8Dxgd+9OLiFwbsmYpkdKW4jy3FSq+I0dsCnX+luXd ILfApGDtwhhVwFniVq/KsRFkCnlFF/vU70WqUtF5ufpBfOgjcPsSK0PRdNYFojym vX+AZf5Gjc7nHysBGTkK3JRQNRTSYkvQY+ZjsWyMs5ATdgxbq5g/QkkS5iOL7ML3 Vv2AVbFCmcDX1Arx96nxntaaWI0nDixcRWd8QTgtbYdv5r0Bl4nevr+aRmCgGLST +XbKSLF4oT+eHAlOwUFNeUWZmhv97zTK3K5PIX6mk4vx8ETdvKQz8tn4d+vvKxJj 6qy3FiJc6w79ZIx5/zsx4jHMd9joKg39cgLxMhUVR5G6A8Canow= =Pua0 -----END PGP SIGNATURE----- --sywgjbkq4kcpxg35--