From patchwork Tue Sep 19 19:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Axel Rasmussen X-Patchwork-Id: 13391777 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 3B6A8CE79AC for ; Tue, 19 Sep 2023 19:02:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADB886B00BF; Tue, 19 Sep 2023 15:02:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A157B6B00C0; Tue, 19 Sep 2023 15:02:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 890586B00C1; Tue, 19 Sep 2023 15:02:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 740366B00BF for ; Tue, 19 Sep 2023 15:02:32 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 491E3C0DFF for ; Tue, 19 Sep 2023 19:02:32 +0000 (UTC) X-FDA: 81254268144.04.6DAC985 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf30.hostedemail.com (Postfix) with ESMTP id 639DB80036 for ; Tue, 19 Sep 2023 19:02:30 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lfC1rVxa; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3RfAJZQ0KCHwf2jqwfxrzxxjslttlqj.htrqnsz2-rrp0fhp.twl@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3RfAJZQ0KCHwf2jqwfxrzxxjslttlqj.htrqnsz2-rrp0fhp.twl@flex--axelrasmussen.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695150150; 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=5/ZA4nlbby3TSOXQeGLhY3RgtFATqmihyuOhsYNku5o=; b=VAgUSJ0W7g6JSVgzRf9Y5deU3dj8ut5k7LK6V6i7fwhH3YPTKKXjFeFiYV3Z7HT8Yzc0mk BUvSVVSEnpeEju8vyl7Ogayv/l6h89fNLv5+q9FVukYUij28mEGAeGzbqpGxJ9X3CD5kD3 Y/Dtb3lN4sQaajxqCXg88jCOMic8+sE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=lfC1rVxa; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf30.hostedemail.com: domain of 3RfAJZQ0KCHwf2jqwfxrzxxjslttlqj.htrqnsz2-rrp0fhp.twl@flex--axelrasmussen.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3RfAJZQ0KCHwf2jqwfxrzxxjslttlqj.htrqnsz2-rrp0fhp.twl@flex--axelrasmussen.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695150150; a=rsa-sha256; cv=none; b=V3cQjg/8VXi4HZUBT7+ppkYBR2sBo4PNQe2AKUkVbkc94KhPa4glTB10Gh7FJOdCtWMS6d IJj4kZd7gbJJPdsVQTB1t6Ac/T1r/gb7wvoVNUhdEb3ArSRFQ7yWdn4c/EK8rtrYDT3P2w MzyRDJAHlR1ed6uQOWNds9mbAdiZrOY= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-59b6a51f360so68228307b3.1 for ; Tue, 19 Sep 2023 12:02:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695150149; x=1695754949; 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=5/ZA4nlbby3TSOXQeGLhY3RgtFATqmihyuOhsYNku5o=; b=lfC1rVxaISsaYOJ+z1L9w1IYo9FtOXnQKKVhgv2fiqcKfim/yK+9kYhOmx0RbAxVrP iIqrmxjibuQ7zYBMVYB1YNkUpy1UIwa6KNPHQYE3ZvXV9uDEnrxuDYRHwV+Mw2AlEiZg hfR/y/5DKXQrPY8nn0zEFYfMP+nrXoOAehGv7cFI/ZnZZLDVotgyL5fofT3se71yPFSO h84kKbZpdwaat/ndUDtFlPRTsOKqseWVy8GVdFItP9o15yscnUxz8WlbVbRqF6Em1Tdm WC2orPjhilxUNGkNVBKT8S7It48DQBth5lZOZmNwBIQNdWSnSdpgJSUdw7ADnxe/kQnU WIEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695150149; x=1695754949; 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=5/ZA4nlbby3TSOXQeGLhY3RgtFATqmihyuOhsYNku5o=; b=TmwAdLXG3S8yJ24oT5hCrPiqeaH6Wo9NGmPSOpf7YUvBcoqoTIsGmWrkSB77tLeV9L GgiUB8BJuKKJyVLsUH3V4NYBhxAyjtxC0d0qJ70nH6x2HhfCbX8EPpMiRUjKsSWCFMFm 6JowwL1HHKKn4YsRhAuHMgscC8aT0agc2fYDjUApgS/Fg0+H71P+ewdtjSsgB48zi/Ex vEaqKTEEjetY7hDP1hn/5XKk+9EVm84HnjGxupy/zuwLAQIDkKqrvo2ZkMLCbflhxYxX VTCC/uIXzqVhAbAN7Ud9/uE5WvGK9HCEylqwnEIM92L4Qa6wLGSPbq5XqCTIBWqWqIRl 2/XQ== X-Gm-Message-State: AOJu0YxKVEJZAXj3jX5kXcGKHQ/1foyeekh/EicXMzDYDM/yoyqB+kfk CdH0GIoAc4QWiTFllsdVCgdLOLumAps+kQI5oM+P X-Google-Smtp-Source: AGHT+IG8eaTU7hxdY5mgOyKHs6IeTw13//TND4ha10SPnops/i3jjzvDx1XteSAjjRbmIb2msTY9QDo9nytSfSAHrvmQ X-Received: from axel.svl.corp.google.com ([2620:15c:2a3:200:8f5a:6a6a:cafc:a3ad]) (user=axelrasmussen job=sendgmr) by 2002:a05:6902:1805:b0:d77:f7c3:37db with SMTP id cf5-20020a056902180500b00d77f7c337dbmr7876ybb.8.1695150149582; Tue, 19 Sep 2023 12:02:29 -0700 (PDT) Date: Tue, 19 Sep 2023 12:02:04 -0700 In-Reply-To: <20230919190206.388896-1-axelrasmussen@google.com> Mime-Version: 1.0 References: <20230919190206.388896-1-axelrasmussen@google.com> X-Mailer: git-send-email 2.42.0.459.ge4e396fd5e-goog Message-ID: <20230919190206.388896-9-axelrasmussen@google.com> Subject: [PATCH 08/10] ioctl_userfaultfd.2: clarify the state of the uffdio_api structure on error From: Axel Rasmussen To: Alejandro Colomar , Peter Xu Cc: linux-man@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Axel Rasmussen X-Rspamd-Queue-Id: 639DB80036 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: a6uarcp5ihgtn5zuig5dyxgy8bjq9re8 X-HE-Tag: 1695150150-290460 X-HE-Meta: U2FsdGVkX1+fl2cI8GfDxKh27NcN26L+78ynvAYx+wXtoza7QPfIxo/d2GcC8dOGsF+5UjBe1SlCFCVoKgXChT+jwl3t00UWOS7l+oVOH2XV1he+lBLdeM2uzwAwa3LBYEmnDxKo6lFTjVmAhoUyI6dF2zZbkyuzZGZv0XqZK8mRNBfcaceCx4GGmUHBTmH0WIXXPoO85oZn+TFkzfrnkWQAksD4AJZe1SJbex8cqOZ6vFYxekQIWv06fj2woQOWPf8unUdEzXKe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osIM8t0v9guMld3/JGxpqB9tYMc/+/zKMeM/+jG7+C7RwjOa12IH8n/Qi5scnQ12IZAgtskANiUB1zkoKNc9i3Cn45SYojWCQ3/phNEgXC5dRa4e7bvpswn+AjG6o8FTSyhx+/JvvUdK2dY5rvZbrhfSPH+5PX6rg9wxrOfs5IjmxRC0Oc3q4sfGKCuqrZj8jId6+PBYT/oZXE99Rvd3+GoY7XSHhdMY9sl5mCSrLe4WQxwNmyZGIAgitwpMtSVSwdJ6hHvaggdyXtWcoKYs4Eg40/ev4dRR6+1ujjMPPUJrE0q5JOZ0une8niJmYmdr6VzgXZcJegDDp4O1Rxo/GHBRD X-Bogosity: Ham, tests=bogofilter, spamicity=0.244157, 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. 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.