Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3460940rdg; Tue, 17 Oct 2023 16:07:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsxFd4jDw8z5LtSx0w8KWimp/EL+gzR7i2pF72pcuv1tbUGKRSMtHibvFNEq/E4rAXG0/K X-Received: by 2002:a05:6359:100e:b0:145:707f:ebe1 with SMTP id ib14-20020a056359100e00b00145707febe1mr3404272rwb.12.1697584077146; Tue, 17 Oct 2023 16:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697584077; cv=none; d=google.com; s=arc-20160816; b=W+S3pHzQRh1pLNacBdtDW3EgcSvws+x+T3sI+l6hXR0sfKzmI6EH0ItoQ7g/Si+y8G cJsfxXUXr7DmhzF+fR61qqxAJH6+brZpRvNgw9C2QR0mhFM6dAty8yAs1lEuDUZ15la3 W21J+/iqCU1yAy2s80kGFUI57srS3746uIw1sycUmbJrYQFKp/ek7INkIF+2HNr5JAsx w72bLnT2ZfWAU/1hLTDs/9uq9A18CbO0D195iUFKG3LC6Gpa9dqkaDoFEC+Cr9UGz84G XxchVKVuUhjN/FcMUsAt4izdFstogp68+4jAXHLBE6FXa52lLf7U54aUIXpl8acB7dZG TWSQ== 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=ourRoDn9ucMnxr5Xs5FvrnfBMF+4pQMUBKCv+c/WFtI=; fh=OxNTFWLvleFI0MvhCKNAD6iL+6/Ozgzt5PlGMZDxH8o=; b=Sc5Ecdwzx9cNXZv0CxYGzQ/UEheWqT48IZvH5jp3tAuVGd+syUmQMNpatH8lRZiZZb JQPBq+k5MYoNGa72xSk+LBMW1pF6R/m9puWANXaVY4RCCDmXZsdZN51No2ABsdBq1Nyk H9mOQViJsKiGdAvB95K+52CzBuVkf7KcVLZ/R/bVejJnNk65JoRAZ+/ZSyBLIPmpSWdC iQhp850+7rGV60E4xHkN/LtS296GD3aFBDLskpNfBlUWtuwhv5XQz4aldN5pFfZOX5OI 6NjriUxqNlSKFhiF/hN5GeQcuI1FYJsqI/vBgbYGfG5EMWN7/g9VwLXNmiHM0ck2hnMz 6j0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MzSnZNak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id d19-20020a056a00199300b006a15afe16adsi2714306pfl.258.2023.10.17.16.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 16:07:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=MzSnZNak; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 9535A80E6082; Tue, 17 Oct 2023 16:07:54 -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 S232568AbjJQXHm (ORCPT + 99 others); Tue, 17 Oct 2023 19:07:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbjJQXHl (ORCPT ); Tue, 17 Oct 2023 19:07:41 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F06A4; Tue, 17 Oct 2023 16:07:40 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B770C433C8; Tue, 17 Oct 2023 23:07:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697584059; bh=dQ/jJ2xxWGs7cQZAVsrD6X/7JuhRJv3DnLJDerRLn6s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MzSnZNakYO8sxlX35q0nBc9AmKMn5dI0a6pJkwlfB0nEcckuChl5ROBBpYOW4pCma DqNe4DaBP8tlIDBh5/NSxkjIdi7XMMMtLTgzWoSfP6IuW4/enOk0pS5eQOAny7HcD6 tCdEdyvJJMmlCwTqGlNzdL/X4Ro3reKuH353yK3js2sD5rBBztwovdVVDftl+WWO+a 9ZR0BnICVepJxlniffGYEPS/ln7jQPsS51xhyOqBb+Mus909l6zyBWpobbVrOZl80Z dEaBQhO6VuEccEm5u7O6H+t7JAhlxLsycBWTf1kHXLBLtGJlpGHLQu6dgEkmN+QNLe HQ7MKTkJz0eSw== Date: Wed, 18 Oct 2023 01:07:35 +0200 From: Alejandro Colomar To: Axel Rasmussen Cc: Mike Rapoport , Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/3] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error Message-ID: References: <20231017230110.3170850-1-axelrasmussen@google.com> <20231017230110.3170850-2-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="B7otR/Eb6YTSxL7p" Content-Disposition: inline In-Reply-To: <20231017230110.3170850-2-axelrasmussen@google.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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]); Tue, 17 Oct 2023 16:07:54 -0700 (PDT) --B7otR/Eb6YTSxL7p Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Date: Wed, 18 Oct 2023 01:07:35 +0200 From: Alejandro Colomar To: Axel Rasmussen Cc: Mike Rapoport , Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 1/3] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error On Tue, Oct 17, 2023 at 04:01:08PM -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 > Reviewed-by: Mike Rapoport (IBM) > Signed-off-by: Axel Rasmussen Hi Axel, Patch applied. Thanks, and thank you too Mike for the review. 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 e68085262..82aee667c 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 @@ 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. > -.\" > .SS UFFDIO_REGISTER > (Since Linux 4.3.) > Register a memory address range with the userfaultfd object. > --=20 > 2.42.0.655.g421f12c284-goog >=20 --=20 --B7otR/Eb6YTSxL7p Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmUvE7cACgkQnowa+77/ 2zIOhhAAjzb72Z6tKi3eHS6l+e35iLyzpvcPrNlSuUau0nB+QkBtcWHxa0Zkob4x rQ5LRqtu1D76dZT/v8jcYhgjaCmAPfKCuy31gZBm7ezxnGi3JLh5nGN6OaMtYMoV U7+XJPOcd1MezBHB+vIWRZ3KvpEpiBN7BiVAjogvUj6bXhchcOlTGTcI1Uc1XjQ2 JsB0a7N5VjI0tj1FAEtsmIY7tawA0AAzaZN/+CQQjOVarWFmG8w/1lOYMZLtY6o/ wtDMMwTTymKTUoJRlbGUS/HCQITcIu+xn+TbzZ4/hMR68Rtqvxb922fNavPpe16X 48h1MXKl38qfbEgX1HK/abwmBlTyA39FMLCCDlTYpZUBhEZl71ORdYoQFZdRXTKX UVSviOhjqd9Hj+u+fT60x1qO3cr/l+9l9GRn/Ow9NtGOWb/wtw+t4qiFaC0i9HQ/ dSv2Rtemyc4U6pL74Tvk/ZqW9qMJ3Zvr6sNtyxx8FX84dmEQkTNgOueUn85puOvB LNc4YYclgx0nrz50zz4rxyd24yjf/O4bI+hhmnmM7gFBd7GGkCEFvCM01B7ysOVU j+nu8XDcYUvfW69XgqYUqudjZNSBB1yNUjjiZMKOPEim2bWhccyrmLfgjOQVVpYW NVd5+wFUN1/oJbedwUb1zdMcrwtEoc3AJ/o03g59wse85LGbL7I= =A5RY -----END PGP SIGNATURE----- --B7otR/Eb6YTSxL7p--