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 B9C53E7E654 for ; Tue, 26 Sep 2023 17:58:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F1E206B0185; Tue, 26 Sep 2023 13:58:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ECE8D6B0187; Tue, 26 Sep 2023 13:58:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D953B6B018A; Tue, 26 Sep 2023 13:58:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CB7CD6B0185 for ; Tue, 26 Sep 2023 13:58:58 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9B864120941 for ; Tue, 26 Sep 2023 17:58:58 +0000 (UTC) X-FDA: 81279509556.01.63337DD Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf23.hostedemail.com (Postfix) with ESMTP id B82E2140006 for ; Tue, 26 Sep 2023 17:58:56 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MLJqRhnV; spf=pass (imf23.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695751136; a=rsa-sha256; cv=none; b=k2GIVXi0BYdRp8hlaRRce7Z/DQdgjS4CKAq24SYg8VMEQoISYJXCpWUUdrtmmDSi0ab7K4 pDet3Jgo5EMgCM1txWj3N5nPCGnlEuYYXPbq0Cc3sVrRgU48JJ4GSE7H5IVDPaiuvpRY07 ptrYbdXfEGw/+2kPHphqT/7Skmp2bvI= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MLJqRhnV; spf=pass (imf23.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.218.43 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695751136; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OFnOg1pHsHZEv3DUGjzvzkoO5rnnk2Rnu4AXIw+yFKI=; b=JpgNOzcjBRpMdpzOyNkjJTSEZe6jeS6+/BlicvlcsdFc9+l+QPAWhpSJx+vgZoZG+pWHVZ eFyrSTO+8F5NfIK0gOE3N7WWCoEdKWBFeXL7T7H7U6hEAfXbaRpI+P9S5K+StiW9T43VWl hqM7iDf+yf0QVa0biNPIIyHeYJ8wSx0= Received: by mail-ej1-f43.google.com with SMTP id a640c23a62f3a-9a58dbd5daeso1179087666b.2 for ; Tue, 26 Sep 2023 10:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695751135; x=1696355935; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=OFnOg1pHsHZEv3DUGjzvzkoO5rnnk2Rnu4AXIw+yFKI=; b=MLJqRhnVdzAQAmblqQXSPVAdfkTAw301H6aPJXwtnPfVSAdzhU9P8hnCH19pO4IbzC PTIU8hjW82N6N2HQsX0OsKax/c6Z7VsVpvog66TB+Buz/AAHHV+BrMbuG29MQi3Lm1cs 8zQWhLM9ckwN0QJSL5fO/dR9Q3CkyFN3gizIyInDf6mjtmlcrVXbGZnrAITUCANjswZh VwBtY4ecgYWJXR+NFEBXHM5rC5LTGhN81rJ95KfKlNHX2HD9orzZQ+AKpitRJGong5Sp U+yoaP22jk1lViJ35FSSIml4Afn9ZnTJkAOuow0tj4Urqy8AIaK5qNeCHHsF0gC6fPp+ AetA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695751135; x=1696355935; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OFnOg1pHsHZEv3DUGjzvzkoO5rnnk2Rnu4AXIw+yFKI=; b=mgQd114bQnWWabR8f/W78j+I6ZcjzrLAyS7e862M3NeHRjh0lWVVhX67Bgk2AXpyro oHZscWBat3qAtekTU2NoA0UShb/1bDw+4d1cHxrJ9ylmubU00uKVB8hUrMV5LwaUZK1o j2TRQ6uArCWgnDbPUaQeAQkS4ZF0a2SSOPUlqAcal91NS0+VShNwIobzvcSO4b2efgne tMwYRawEczYnfIrirAwPSmFuuKJTy0clBNLEvduM3h04QAQ77cREF6zPqxaTD7Sb1/pP fWlncUSlQpcazsII4z/+kDjAFSLgMg1IAY5mHbiaJ9zN3ZSegF5rcoOduGYmmaUuo9M3 c57g== X-Gm-Message-State: AOJu0Yzwwd0Nm6MCG23Xp+lVA0DGJ0+Bt7vZxg86irUh5B4+vwFma/8Y 8/gqHE4y2JJpSVcXS0aUGCRstD4vKl17klrj0YRsHA== X-Google-Smtp-Source: AGHT+IH1UvbPZN+AYVuNOlZ5+jvqeSn4QL2gxS1iQykyVPMWg3fp23GOvge4u4/OO7F77GHkmagIn5MVyEy5F7QLAnU= X-Received: by 2002:a17:906:319a:b0:9ae:659f:4d2b with SMTP id 26-20020a170906319a00b009ae659f4d2bmr9062850ejy.56.1695751134910; Tue, 26 Sep 2023 10:58:54 -0700 (PDT) MIME-Version: 1.0 References: <20230919190206.388896-1-axelrasmussen@google.com> <20230919190206.388896-9-axelrasmussen@google.com> In-Reply-To: From: Axel Rasmussen Date: Tue, 26 Sep 2023 10:58:18 -0700 Message-ID: Subject: Re: [PATCH 08/10] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error To: Alejandro Colomar Cc: Peter Xu , linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: B82E2140006 X-Stat-Signature: p8sjpptanusqumzndobyxjozxx48989n X-Rspam-User: X-HE-Tag: 1695751136-116323 X-HE-Meta: U2FsdGVkX19zqFH5rHcosu4esneovKdEI6Kbae93yNb3jwZG7kRHRGrTKdWOeQKzmMooQ/NONsKGgvDqAtqvdK8MNijlpDovZwEPoFAHKNf+UP+u8VtxYZnJno8WuiGgxlnNnUAj50fZFACco4Tegzd6AUTh8yH5F/Sgo0z/nbAt2csN8eh52gvgaxugh4zRrztpSFFG1r53VtJb8dbqa0/Xhiw6gtPllW//YOfiQpGEbOPPI92dFAWwFmZxusXhydIMXdW7nWyru4f63yvBfwmqplVB5z/KiPDUNGIC/4gKXynFhl2gQHx84IeOCMeZqJMzu2sWfiEFkZjGrguIgnpB8VMb4f8eU5mnBk3MwJzj1HyiCQpr3joi9qQwSEFnbCb7/vnSnikgdCom5ph37dBzrnZXftlxYSijt9flSeTOCjYv3GC0fEdg3XkYaLtcxwMHwDcp0vYMN0k/AwMU7qqQhwYDzGcayOzsb5OMuwqUqxXiIT0lHVPEgmVtl6ClNnG0mdKsBrx2qHmbsHB3M2xTncZ2n5zBGi+m/uQiA2/Foe7/DguUr8BVHu1h5hTs37DWUrMXSpRnuh08CxyRXRUrvDEN++7wYkmoqrfCozONZwcO3ZsYiDxu00i9Hijmy66inVV4Dxb6aU3tRHXEWHCuUnptDlcUXdPrxq2DujzG6keXyLrAsrbDPhHc11Hj3k/acv+KOZ3jPUxAQ9oyPo++wEd6ObEfB6qDw+8oFD6ZfwE6XVqwxz0sooDTfsjeAexJTvLawGf9TScBs3FfbqFiBHTMEqw/y7VoaGKT6yfd7AQMtzG//7h3EwVl5xzp7KP2WYJNYJxL+y+0yPA0tSZTQx4oJqZ6CiXq+Hc3bB6k5pNuyhOO2LZJN5dFZX1bvYk/xmTkpf8/VDg7YWjABGS/m3/7SWilYnfV3f2KkJE+A6KmvYusvHpb2IEt4y7NpcomgTorZJWP6/Yzpv6 Cb4h+Nx7 SpOgDo8bQZLp6syrout1hYRCf63S03AT578ldmlNH75zNeOiU4tfjifHJkaQk9OOL64B54ZsJMYdwFmswstxhtRdAEtoB5/r9iA5sk4KJmBpSeG7eC0VyeEkbzHaALr+48bomzWlKniqXz7k6RWTVXOMqh6X0djOHdfeApxiEeYcRO1Tz4hX1JRhmSgwGVpFPy9JbJAu1ftdfFReIu+QHAzfB195QzkSi3Ao+PMVocpviCb95bHRK1qnk2F/fxBsNkAqlOKCGGMrRH6bwrYhcMY4EEKSI6z2ke20xw+GAkQ81nBuQNXsM9C2BH7E6gXDbPSpHOySLY8FgUlN5Kts+afeqAg1oDQYYXDaa X-Bogosity: Ham, tests=bogofilter, spamicity=0.000013, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon, Sep 25, 2023 at 4:56=E2=80=AFPM Alejandro Colomar = wrote: > > 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. > > > > 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 a= s > > unspecified. Just re-initialize it before retrying UFFDIO_API again. > > > > 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. Thanks for the review Alex! I'll fix up the issues noted and send the remaining few patches this week. :) > > Cheers, > Alex > > > --- > > 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 manu= al 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 > >