From patchwork Mon Mar 29 22:18:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12171057 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B71BC433E0 for ; Mon, 29 Mar 2021 22:18:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A3B476196E for ; Mon, 29 Mar 2021 22:18:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A3B476196E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id AB1D76B0082; Mon, 29 Mar 2021 18:18:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A64326B0083; Mon, 29 Mar 2021 18:18:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 867666B0085; Mon, 29 Mar 2021 18:18:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0186.hostedemail.com [216.40.44.186]) by kanga.kvack.org (Postfix) with ESMTP id 666E66B0082 for ; Mon, 29 Mar 2021 18:18:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2B6466C1D for ; Mon, 29 Mar 2021 22:18:47 +0000 (UTC) X-FDA: 77974327494.25.2E78E7B Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 5904C40002CF for ; Mon, 29 Mar 2021 22:18:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617056326; h=from:from: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; bh=WUaW949Sngo6yyC4xTwj+erWp36FebBIUp15Ep+mJGo=; b=ZgDigZbT954pQN0tnLVBlztOcP8cpz47yNXt/3p/zmSAB1I+CFdy23XyjPvS4Ep5o8fwxw H0DlVHzWG77uar0ebmhZa7aFf2xl5BX+3PNzpGZYnEvqTI9wSXLiyQFc/yltbRKZUh4uzM d5cENoKq61GKFrGBOonehKAf/8fUOyA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-0yfw0oaMM-Oj3kADc1dL5w-1; Mon, 29 Mar 2021 18:18:44 -0400 X-MC-Unique: 0yfw0oaMM-Oj3kADc1dL5w-1 Received: by mail-qv1-f72.google.com with SMTP id im11so1859742qvb.23 for ; Mon, 29 Mar 2021 15:18:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WUaW949Sngo6yyC4xTwj+erWp36FebBIUp15Ep+mJGo=; b=YOr6cH/FLMUl0wS0xDbjlOs/PX4K9iofokDsTngKXEFuoDrKvTv2fsq5+Rb5auaX/Q eOduwCFGX0Ve5bCufep/hi0uR0XsAcTEm7b0vJfRh8Pil90/2PX5Sq83nzSD2GU9ixyC Yx6pIPN+GM0YRT+WGLQEHwmIAj18Y/hEm1slhKUHky5qfnu7MfAQBfGtVwvnb1GZph2r v9kFmOZiIGAKb7kIFU7IeB4yeHMVwIgxLb+2mfUSrB9jTI/Nbzznb4czvNrtxcHNS/L8 0YHVRwma+LufLJbOdlL9Mw+ahKe/eHLy9o5q/eaJ/0mYs4eiwc7ZgvMfyJwiyQ8+jGY3 nthQ== X-Gm-Message-State: AOAM530GYwqrRxHiY0cAqDCzXiCwOSs+okTSKoHoADYz13FLVLhM+CTQ JNXOf3ife2ClT6Dy3dT4k6nAyZSdFzPoDbZH4MGYlTWq60SHOlXEJI8QBNesbOEJcGgPhUUcp/3 iC8KopXZdnlJIRHK+8QNKWwCv2vTFEhtWv59ouVb8ADsHTNQCnG5eQgY/0UHp X-Received: by 2002:ac8:1009:: with SMTP id z9mr24461437qti.128.1617056323732; Mon, 29 Mar 2021 15:18:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyxdKP9FUZ/PE3P0cEW+pqhOmx0ng44ycgosjq2R17bSMGFeko3E8KREiwoyB8K2f+jnIt6NQ== X-Received: by 2002:ac8:1009:: with SMTP id z9mr24461400qti.128.1617056323323; Mon, 29 Mar 2021 15:18:43 -0700 (PDT) Received: from xz-x1.redhat.com (bras-base-toroon474qw-grc-82-174-91-135-175.dsl.bell.ca. [174.91.135.175]) by smtp.gmail.com with ESMTPSA id i17sm12255215qtr.33.2021.03.29.15.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Mar 2021 15:18:42 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-man@vger.kernel.org Cc: Axel Rasmussen , peterx@redhat.com, Nadav Amit , Mike Rapoport , Alejandro Colomar , Andrea Arcangeli , Michael Kerrisk , Andrew Morton Subject: [PATCH v5 4/4] ioctl_userfaultfd.2: Add write-protect mode docs Date: Mon, 29 Mar 2021 18:18:33 -0400 Message-Id: <20210329221833.517923-5-peterx@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210329221833.517923-1-peterx@redhat.com> References: <20210329221833.517923-1-peterx@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=peterx@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 5904C40002CF X-Stat-Signature: fkekk8xd36yjbcc8tgtksrtzrgpuui6z Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf26; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617056324-803846 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: Userfaultfd write-protect mode is supported starting from Linux 5.7. Acked-by: Mike Rapoport Signed-off-by: Peter Xu --- man2/ioctl_userfaultfd.2 | 84 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/man2/ioctl_userfaultfd.2 b/man2/ioctl_userfaultfd.2 index d4a8375b8..ca533a383 100644 --- a/man2/ioctl_userfaultfd.2 +++ b/man2/ioctl_userfaultfd.2 @@ -234,6 +234,11 @@ operation is supported. The .B UFFDIO_UNREGISTER operation is supported. +.TP +.B 1 << _UFFDIO_WRITEPROTECT +The +.B UFFDIO_WRITEPROTECT +operation is supported. .PP This .BR ioctl (2) @@ -322,9 +327,6 @@ Track page faults on missing pages. .B UFFDIO_REGISTER_MODE_WP Track page faults on write-protected pages. .PP -Currently, the only supported mode is -.BR UFFDIO_REGISTER_MODE_MISSING . -.PP If the operation is successful, the kernel modifies the .I ioctls bit-mask field to indicate which @@ -443,6 +445,16 @@ operation: .TP .B UFFDIO_COPY_MODE_DONTWAKE Do not wake up the thread that waits for page-fault resolution +.TP +.B UFFDIO_COPY_MODE_WP +Copy the page with read-only permission. +This allows the user to trap the next write to the page, +which will block and generate another write-protect userfault message. +This is only used when both +.B UFFDIO_REGISTER_MODE_MISSING +and +.B UFFDIO_REGISTER_MODE_WP +modes are enabled for the registered range. .PP The .I copy @@ -654,6 +666,72 @@ field of the structure was not a multiple of the system page size; or .I len was zero; or the specified range was otherwise invalid. +.SS UFFDIO_WRITEPROTECT (Since Linux 5.7) +Write-protect or write-unprotect an userfaultfd registered memory range +registered with mode +.BR UFFDIO_REGISTER_MODE_WP . +.PP +The +.I argp +argument is a pointer to a +.I uffdio_range +structure as shown below: +.PP +.in +4n +.EX +struct uffdio_writeprotect { + struct uffdio_range range; /* Range to change write permission */ + __u64 mode; /* Mode to change write permission */ +}; +.EE +.in +There're two mode bits that are supported in this structure: +.TP +.B UFFDIO_WRITEPROTECT_MODE_WP +When this mode bit is set, the ioctl will be a write-protect operation upon the +memory range specified by +.IR range . +Otherwise it'll be a write-unprotect operation upon the specified range, +which can be used to resolve an userfaultfd write-protect page fault. +.TP +.B UFFDIO_WRITEPROTECT_MODE_DONTWAKE +When this mode bit is set, +do not wake up any thread that waits for page-fault resolution after the operation. +This could only be specified if +.B UFFDIO_WRITEPROTECT_MODE_WP +is not specified. +.PP +This +.BR ioctl (2) +operation returns 0 on success. +On error, \-1 is returned and +.I errno +is set to indicate the error. +Possible errors include: +.TP +.B EINVAL +The +.I start +or the +.I len +field of the +.I ufdio_range +structure was not a multiple of the system page size; or +.I len +was zero; or the specified range was otherwise invalid. +.TP +.B EAGAIN +The process was interrupted; retry this call. +.TP +.B ENOENT +The range specified in +.I range +is not valid. +For example, the virtual address does not exist, +or not registered with userfaultfd write-protect mode. +.TP +.B EFAULT +Encountered a generic fault during processing. .SH RETURN VALUE See descriptions of the individual operations, above. .SH ERRORS