Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1766967rdb; Mon, 9 Oct 2023 02:06:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBmZFT+TuEm8gYStVhsl6tGV4nZiGvz4o/rLg0y7vDhk8/EHFIwTjcMkk1NYx8Ln11j0Q/ X-Received: by 2002:a05:6a00:1a14:b0:686:6e90:a99b with SMTP id g20-20020a056a001a1400b006866e90a99bmr14550757pfv.25.1696842382703; Mon, 09 Oct 2023 02:06:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696842382; cv=none; d=google.com; s=arc-20160816; b=m9RIdetQQpjodHfAYKUhY/nVg8FFCAj233h2xHlUrpN8I/hVlHxaPm846G5jl4flQi bneq0sMlfnBrpYI3QMTOi7FtmEwEbO4Dc1h8Ze9STJjpH0RIrRArwMpuLhH+m04O+dWE azf/441aYpWKUpFRF6WcOqb4PamxdJdBrDlMuuOCfhP21XkIQ61/SWtzd+YiPaHYoQMx BBw1mjjRhpWyH5aJsVZxVHzwGMjKl6QKYeu8Qi5lz6ZFUn3dzUNPeQNdIn/33+gTPa4a TX5bHtzDpMlr5ocJxsOUlm2XiJ4fNTKcvmpnKlh9gfFkN16A2xAWzYrvxlSZnTE/trRS mD6g== 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=B/HAD/aDakZafsyMhfJDsShdzQRyKs+vspcrukKoMPY=; fh=F5M/07vUqNxvrCSEZSXffLFlrqXZOtORyIukROoamOM=; b=oYP3RoQ+d/fE+aKmxmrUgHHj8PDZT39PHhz1Uv4HW15yR19RmZGADfQ/YQzZxmzXR5 lYSJ4Y1emhsUn+EAEXZw1OwSSqcu+ZH5dTvJPVqShacCw35+75pkyfR2tLfAHwao+HMb ZLpi8FCMsrfDGkJYyhv8VZDF38ULieyCzYO1rfpCWa9lY98I+NHhQHo97PTz5Me0btQ0 ZIuDHUV8uUd+qwDVmesWR80Gb8fMfTgp5wAG/iQ4ML0WhU1yAWpFQTQ82I8H/gFTgxz0 5qfPXLbBoAP+uVbwVBiBYfHZXLdfVaQvTElAdYBNjQ9ULBjqSAyn4D5TpThG1UQbm6+V JXWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DtkLS4x3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a8-20020a62bd08000000b006933c57195esi6361148pff.399.2023.10.09.02.06.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 02:06:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DtkLS4x3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 83D7F807C746; Mon, 9 Oct 2023 02:05:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345856AbjJIJFP (ORCPT + 99 others); Mon, 9 Oct 2023 05:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345728AbjJIJE6 (ORCPT ); Mon, 9 Oct 2023 05:04:58 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0DA1112; Mon, 9 Oct 2023 02:04:45 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05DC7C433C8; Mon, 9 Oct 2023 09:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1696842285; bh=ExSTeG0S5N1PTLbbaSlmaXZRGf5NsQQSh7p1UChNEJ0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DtkLS4x3TILpdQvSob4UvXg4FKFvgI3Ua6vfjQQIT553zp+yfukNKLXMd9qy7IcI4 kuF2Snnnf15yim0DE1N2tgN0Uri40cVnUmXvwQZWMRXNinUBevse07GvMqTrqNSbsv /eR3k8K2wLO/aRg+ril9lzuCtqOVleFIbIN9KXDHHniqFvSLlcvdclp2G3qh/LT62T j1DZZQ4aQ7jdSqJ1IKmMReKfWz8d3LGtebFumsgRHB4Guxa8H5Z8VGmtphAie3bPdy J7l8Npqv61QJjB4YYI6/P0KWHHYslVPmw06z4FGIAZAi263xRVdd9x6ZrhKPj5drr8 wJR0mHsmopnpg== Date: Mon, 9 Oct 2023 12:03:51 +0300 From: Mike Rapoport To: Axel Rasmussen Cc: Alejandro Colomar , 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: <20231009090351.GL3303@kernel.org> References: <20230919190206.388896-1-axelrasmussen@google.com> <20230919190206.388896-9-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230919190206.388896-9-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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 09 Oct 2023 02:05:42 -0700 (PDT) X-Spam-Level: ** 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. > > 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. In old kernels (e.g. 4.20 and I didn't go to check when this changed) we had two -EINVALS: one when UFFDIO_API was called when state != UFFD_STATE_WAIT_API and another for API version or features mismatch and we zeroed uffd_api struct only in the second case. In the current code the first case does not exits anymore. > Signed-off-by: Axel Rasmussen Reviewed-by: Mike Rapoport (IBM) > --- > 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 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. > -- > 2.42.0.459.ge4e396fd5e-goog > > -- Sincerely yours, Mike.