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 08C0CE95A96 for ; Mon, 9 Oct 2023 09:04:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 942858D0032; Mon, 9 Oct 2023 05:04:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8F28B8D0001; Mon, 9 Oct 2023 05:04:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7BA688D0032; Mon, 9 Oct 2023 05:04:52 -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 686C78D0031 for ; Mon, 9 Oct 2023 05:04:52 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 3F63C120196 for ; Mon, 9 Oct 2023 09:04:52 +0000 (UTC) X-FDA: 81325338024.30.87C01D1 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf27.hostedemail.com (Postfix) with ESMTP id 2BCA24002B for ; Mon, 9 Oct 2023 09:04:49 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DtkLS4x3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1696842290; a=rsa-sha256; cv=none; b=pW0378+pcNb9mR4oMvaJ9rqh+kox8JG2auLbtjH0MYELguNqpvoc1jWvt5z/RvKNE5AbYT 3Z5Es8Nxed8a30Ho61PuPfXZtN4p57W8oxgPQrZTA1LtLRfbfvRksRdvFjvnuAOpYnD/7N rx3ewdpbLDQ5VlMD3LUyfbPHXtu79nk= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=DtkLS4x3; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf27.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1696842290; 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=B/HAD/aDakZafsyMhfJDsShdzQRyKs+vspcrukKoMPY=; b=XDG36fT6gxRftyOt3PgPmEZMlNgow99uwX0GLYiJUucskDoL3KDCW/SPKwSEmRa7U1KQha lF453PqMj09ixIPyhHk/jJtlRNLUNsGQvIu0CKRwg9Sh1mBZAqDVSGIaX3wm82jH8sifWO J/xaaI45favWHo4vVNuICiP8OxNMOw0= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 0EC78CE10F9; Mon, 9 Oct 2023 09:04:46 +0000 (UTC) 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2BCA24002B X-Stat-Signature: hqofnjf614yitwu6op1gk75r1asjmf56 X-HE-Tag: 1696842289-110077 X-HE-Meta: U2FsdGVkX1/cny8PG08WDE22B1xQWdpdYvIHEEArINClItOURQ0LzG9AJa+KtM5FKRmbwfrXRLXh4IOumPbf5HQZ/5/nXOZpJFx/f7P5HuvcYCtUNgpO7e7nAe/U7IOBPFzDQwV4zeKbMDnwrvqgUr9R/Bbu747Q8EwM4Kw8/1z8mupPHih7mbhxGm6nXe7sa4QWz4sj6RGj2e8zJ86W8EZ2EgQ/jTosHm7OxKJu52efHLiEQYYRaiOWrO5XPYUxKomD/wJCI62c1ZMQ48vhXoXh/RhH8ypvfiVCfpc0IzSRZSG9WaeV48/CEUpK/xMnd2J56fbHSty8xUpquVQP8TKDtaQ52/8Q5udRRANNPxbp9ffSCVtw3Sgo5wzyMopWWlitSuOFgHVMWifblyvdasV5e8oWhPBZYgmz4Ce1O8Uans1KvgmFhyayJI6NzkPo62y6pkqDaRzR/5nk3pPnMULDjYgrxQQo8TNkqmzoG9Gdt01AjyIWQFL+gUyzHR9A9bIj95l2W61sVLtLcgcd49ayauIaei/jcjtwHRZExpjZ95xYCCEkB2PGxq6ijmRie/lF8UR/PU3ImnSOWXh7a4AyDNsnSydIHwqlGkk+rUwYtNtVSLjQNct8Db72QwkyvF4Tlo2OqrtwcEbQiQqX5MWD53op8huxEt2h+/2OUgYznaItblnPk4fMQLE/wf10jDU4pBvpuk0U3SCuZVEe504nnU/2CNaFJVEthf8wI8odO8U3VPgxUU+Z/vbc22e0VAJwmbViJuhfpbTlLxH9jmnoA2/Yflun/aOzPN/a8JoIUU2NZ4q8/YnLp9wnTYrMFNJfoeaq6o9ycez/pIkAZXeaKdlVRrAk9oVrIt4cugDMH+xMObQ6icCEyRPVf+wvt3IvYz/n/qXusc2SMbB7S/nNfNu/OJc2ekhAHTU2FNGCofgsQo7botgX9a4q65BBZfxLw3Vhz1r3Bi6syFO nFd4MbvZ XOlwTigmkbP1GCPJYM0p5ZUjK/j+MTQIg/jVw9nmm3nf8vok4cdE0N7ua7LD1F6uOwgvgP1bvI+RYBtlwP1aMYiejU6lgClKJQLD9YEOdO8xpOE2YJMiqdrew6tr2lbTBZh+JuyznMnpiXLJ6XcIYhF08X41Bnn3B+o7JXpuWBMx4VUkFtFfMZQa1jS/q/fqX1y4XCY8mIJ2jo5EBlyPFDeA4G83bRpUrZtuSojV/tWvS7/wiqCU6C6+qZdWGd5P5MzFFDYkqppuer98Jg4OzAFJy9Ghe2yNYz2bXdjN3rbnBWRUPfi3kTZZdm4EggYBMjXfx X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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.