From patchwork Tue Oct 17 23:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13426168 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 8C09DCDB474 for ; Tue, 17 Oct 2023 23:01:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E8558D0114; Tue, 17 Oct 2023 19:01:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 221EA8D0002; Tue, 17 Oct 2023 19:01:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 04D908D0114; Tue, 17 Oct 2023 19:01:20 -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 E60338D0002 for ; Tue, 17 Oct 2023 19:01:20 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B8F5B160E6E for ; Tue, 17 Oct 2023 23:01:20 +0000 (UTC) X-FDA: 81356476320.10.4E89464 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf23.hostedemail.com (Postfix) with ESMTP id ECC7214002D for ; Tue, 17 Oct 2023 23:01:18 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3P28VkVq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3PhIvZQ0KCE8rEv28r93B99v4x55x2v.t532z4BE-331Crt1.58x@flex--axelrasmussen.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3PhIvZQ0KCE8rEv28r93B99v4x55x2v.t532z4BE-331Crt1.58x@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697583679; 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=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; b=zKI2Vur9DnvxBzsxK/0EaVin7OX0MvJWNmLbUZ8E/w5m6mtSD7r2PmbMVvMmzMUSl5ij7Y DBph6C/gkwV4cgFfTYxlANGWDdVYYWLaeR6VCyMIxLPf7dXNhWxsnBJiCGGKvNRkyEbdcn SZsj9RaEFfxtTGAaNnMa4xY2mI2l1I0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=3P28VkVq; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3PhIvZQ0KCE8rEv28r93B99v4x55x2v.t532z4BE-331Crt1.58x@flex--axelrasmussen.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3PhIvZQ0KCE8rEv28r93B99v4x55x2v.t532z4BE-331Crt1.58x@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697583679; a=rsa-sha256; cv=none; b=qEAuSDtHhQQxvjXJtUhGBRm0LERuYNkz+uvHCUP9+R/pk9JQiqyk1/TdxNY82fdPdzkdWT cLF1EChG/Mgg++8ULa6CJ054bd7xVzmj680HaEqjpVbADe8vM+LYDkWeYsSIlKq4oXqXxw b3ZsHUBDddFcXTEoxLXWVTjdl82JH6Q= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5a7aa161b2fso95697427b3.2 for ; Tue, 17 Oct 2023 16:01:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697583678; x=1698188478; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; b=3P28VkVqnKFXLfR7Th15y2knCHE6oH+m9uUYMUSip5mgIj1NCl+xKet9K4JrRcd+uX Rh6SSSOAwQG460wDJblxkQu9IK0Z4lkN7ijRngLFtSkX3OYH1iIsWrxL1t/IPPI1ybI3 Ob5vy9UDcOYBk2ALVC2zPWy6b3senFMH39m596QLa64UovWiSY8rydeHsFOXizJcTqFK 3mah+6J9maWgdPw6RiNXBbY8z2erZvmftI30JW0Fhe5kKU+u3NWW947IcYUbjeGo1FIn 0O7U4WdeLxMQHtTWDO66/5qgy9Pw6n62fbHwrp6iLBWr2CSakhApzDSYsusN042tCORS uKxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697583678; x=1698188478; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JOKJf+aFkcLqb+vIwiVLl6niteK0lFsixSF6GjMiBCE=; b=wqKiFq8F1/ezzQFlyyBHzofVRzxindlGCqoldpLhM+JEuwvjegzbHhGwycBri8VF63 G2lWSrtrEcs+NFi6udMRGaxBr0qEkWLCEXAGoNXcYVxH7hk2hkvEqK/57bpq4N/sUN6j 1HF8ECLnFmOX5rHql2MMTC2l1FfekNRii/UdsJrBf18OUO8QD3H0pzRvWHO+CQ760BKT U812phQTB7In8wONrEwdx4qBHP/My4QeW04tnqg8DwK5csD01y3LnPaW+gqD3avyFj4K M5PHBF/6iBdj+bBQXdgLfWw/OhgqwBQthCNvP7v2paQ0oWp4haoP8BymfEliCVHjNilz jhvQ== X-Gm-Message-State: AOJu0YwzQkJD/EfIOhOjyT6BCcs6ho7mgb1r34URIG5J4gyU/4EC2IhC 1xC5YPak9hzSRXRQQZkhmI6DzJW+FBdpQd+UubK5 X-Google-Smtp-Source: AGHT+IGAw1OQNPEiWHUiooH43d5H85P1JTg3yn4uwHQG4ATI0Ap1hSLGIMAXTD6Z8FLwajxXq0T/etVDjId1uCwOy+fP X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:cd04:35d6:a586:5c86]) (user=axelrasmussen job=sendgmr) by 2002:a0d:d848:0:b0:59b:ec33:ec6d with SMTP id a69-20020a0dd848000000b0059bec33ec6dmr90025ywe.5.1697583678192; Tue, 17 Oct 2023 16:01:18 -0700 (PDT) Date: Tue, 17 Oct 2023 16:01:08 -0700 In-Reply-To: <20231017230110.3170850-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20231017230110.3170850-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog Message-ID: <20231017230110.3170850-2-axelrasmussen@google.com> Subject: [PATCH v3 1/3] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error From: Axel Rasmussen To: Alejandro Colomar , Mike Rapoport , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Rspamd-Queue-Id: ECC7214002D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: o9g1gbo7gzer8mmkt6egshna7reoqhgo X-HE-Tag: 1697583678-239124 X-HE-Meta: U2FsdGVkX1/PvM4ZLfEeE3zFKY6dG1RutXGuobSG+16ZIiOckM3+g5t0hIpZPuXnD4dW01RlemF76YP2JsPJLpmCg2aT4ymOOeG62wqtV+r5pp/BWR5ZAd3ZpD7G9CL+Q1ENt0rUlzciZ7p2O6XffXGM/qffw20vWLxBVNhQL4KffwYfI7Pe8BYJZhBwuMhcFuE7HCOlnG94U2+v35tknPwAuCv6+htc/01GM8bn4jOTH4TthpJlgQZ9PIpAWr0sAWXRcw65wegh/q25aCMkr34SVAfpgACfFDXOdjIPC8K3RK1Yj3C/jOsLbFFpfs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7ACPJUKU6ChktvzVQElqX4ZibQQA2R3E7X1rCizJN+lqjcej60Da86dTGg74qnfOYXvkiUVLyWHuT9qyl0jiPqA5zGyIEHo+gGaoG4volwn5kNZjysQe+MxX5/ypsJT5YSQy6F0Kp+Nx11FQVsP7NTbS8ydNTi4/SL1od8RatWt90brOqvP/SnMO7SvKdCRZ3i85X5BNo+/tCXGhGNIlv4bMH9q1wSQbqmpxrmSlJXmCOlojx+ue+l6y47wyC2kza0sC+BPGMremVtT1iK5Mnk33ArsehmHGkO8nQtteqwtYufbc3tg8mhRIESuHcE22lnTn5cjVCZk4m1sEIlqOfSi1yKbwNfXcORD2V3ZQBRl4JjgqIRMjg0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.002121, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. Reviewed-by: Mike Rapoport (IBM) Signed-off-by: Axel Rasmussen --- 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 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.