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 X-Spam-Level: X-Spam-Status: No, score=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 8CDB7C11D05 for ; Thu, 20 Feb 2020 16:32:03 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B070206F4 for ; Thu, 20 Feb 2020 16:32:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UsrIoiWG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B070206F4 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 CA3A46B0074; Thu, 20 Feb 2020 11:31:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C03C36B0075; Thu, 20 Feb 2020 11:31:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9943F6B0078; Thu, 20 Feb 2020 11:31:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 73E876B0074 for ; Thu, 20 Feb 2020 11:31:49 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 2BAEE281F for ; Thu, 20 Feb 2020 16:31:49 +0000 (UTC) X-FDA: 76511046738.23.cook63_2cebca4b6d31b X-HE-Tag: cook63_2cebca4b6d31b X-Filterd-Recvd-Size: 7570 Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Thu, 20 Feb 2020 16:31:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582216308; 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=roK4fSL01gtUBJEYDZG6I36/g2kCOboQcgi8qGt4HbQ=; b=UsrIoiWGSZ1WZZokjGS5+2lGeYl0n/PpxHxNDHg9TuIPcZOMgPUcttYG+fSj2tKVON4Oj7 mlovVZLuOxYSDq4ttdtLarwYhFmz5qeQXvEAJAYDPDabkvNopotRNfP90UAX9kRyg2p141 7Q5AzFXT4Yny/ILJ8WDL/iFAAAhUOGM= 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-292-noPrkm1jN-uY7_BPLsqm2Q-1; Thu, 20 Feb 2020 11:31:45 -0500 Received: by mail-qv1-f72.google.com with SMTP id z9so2728035qvo.10 for ; Thu, 20 Feb 2020 08:31:45 -0800 (PST) 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=klS12EpOfCO+92N1kPohJ72pmA2dZr16cCtOmkqqQu0=; b=a9EQvBjHYvZILdKLBRIXrMml8kFf1kanVhEwCQNrJyPMZdkpIN//QFUHhXvJOd0eE+ N6tvQGxdTEui99FaO4KuprcJ1GjCibiDUt3+YqMAjFIOlUZu9SLwh5hRlG1WR22aGavg TqRgnQ+MxBcBkGBLAXl3jgjL3od03vWLzvMexrjAcCbCKI63pRKWT9CsKubW9zwy/cc8 x9amCzuBynLFQmBuCEh4nQkv4b03DMkQw9FF1Wllc6YkK1QfiIDBGYSLEYOelTRrkt4g FrMRwlGEnh/aEn32hM3iaWQucsNjjg/fDs70UeqmNtYZnjwOakQRXX1uzYnN/9suuOYP 6E7g== X-Gm-Message-State: APjAAAU1tGvCGC7VUZX1Gzq52dmHSxtiPKNSr4HBwn3mZZ3Iua4Kae62 GXcEA1PvzF95Skdr/RZyvhn4mXcrqNb7whhLMp1KkRdrFIDBjs1I6RcjkKbR64nA9dvrUIxuxir V8H2e26X3uwM= X-Received: by 2002:a05:6214:6aa:: with SMTP id s10mr26736226qvz.138.1582216304939; Thu, 20 Feb 2020 08:31:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzYGpukdNxdfXYm0WZoUSCZUP5BJRRurBSVxU3kXV0jc2iuspd6kbmXRu4C8oT1RGdmpXxezg== X-Received: by 2002:a05:6214:6aa:: with SMTP id s10mr26736189qvz.138.1582216304590; Thu, 20 Feb 2020 08:31:44 -0800 (PST) Received: from xz-x1.redhat.com ([104.156.64.75]) by smtp.gmail.com with ESMTPSA id l19sm42366qkl.3.2020.02.20.08.31.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Feb 2020 08:31:43 -0800 (PST) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Brian Geffon , Pavel Emelyanov , Mike Kravetz , David Hildenbrand , peterx@redhat.com, Martin Cracauer , Andrea Arcangeli , Mel Gorman , Bobby Powers , Mike Rapoport , "Kirill A . Shutemov" , Maya Gokhale , Johannes Weiner , Marty McFadden , Denis Plotnikov , Hugh Dickins , "Dr . David Alan Gilbert" , Jerome Glisse Subject: [PATCH v6 16/19] userfaultfd: wp: UFFDIO_REGISTER_MODE_WP documentation update Date: Thu, 20 Feb 2020 11:31:09 -0500 Message-Id: <20200220163112.11409-17-peterx@redhat.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200220163112.11409-1-peterx@redhat.com> References: <20200220163112.11409-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: noPrkm1jN-uY7_BPLsqm2Q-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable 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: From: Martin Cracauer Adds documentation about the write protection support. Signed-off-by: Martin Cracauer Signed-off-by: Andrea Arcangeli [peterx: rewrite in rst format; fixups here and there] Reviewed-by: Jerome Glisse Reviewed-by: Mike Rapoport Signed-off-by: Peter Xu --- Documentation/admin-guide/mm/userfaultfd.rst | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Documentation/admin-guide/mm/userfaultfd.rst b/Documentation/a= dmin-guide/mm/userfaultfd.rst index 5048cf661a8a..c30176e67900 100644 --- a/Documentation/admin-guide/mm/userfaultfd.rst +++ b/Documentation/admin-guide/mm/userfaultfd.rst @@ -108,6 +108,57 @@ UFFDIO_COPY. They're atomic as in guaranteeing that no= thing can see an half copied page since it'll keep userfaulting until the copy has finished. =20 +Notes: + +- If you requested UFFDIO_REGISTER_MODE_MISSING when registering then + you must provide some kind of page in your thread after reading from + the uffd. You must provide either UFFDIO_COPY or UFFDIO_ZEROPAGE. + The normal behavior of the OS automatically providing a zero page on + an annonymous mmaping is not in place. + +- None of the page-delivering ioctls default to the range that you + registered with. You must fill in all fields for the appropriate + ioctl struct including the range. + +- You get the address of the access that triggered the missing page + event out of a struct uffd_msg that you read in the thread from the + uffd. You can supply as many pages as you want with UFFDIO_COPY or + UFFDIO_ZEROPAGE. Keep in mind that unless you used DONTWAKE then + the first of any of those IOCTLs wakes up the faulting thread. + +- Be sure to test for all errors including (pollfd[0].revents & + POLLERR). This can happen, e.g. when ranges supplied were + incorrect. + +Write Protect Notifications +--------------------------- + +This is equivalent to (but faster than) using mprotect and a SIGSEGV +signal handler. + +Firstly you need to register a range with UFFDIO_REGISTER_MODE_WP. +Instead of using mprotect(2) you use ioctl(uffd, UFFDIO_WRITEPROTECT, +struct *uffdio_writeprotect) while mode =3D UFFDIO_WRITEPROTECT_MODE_WP +in the struct passed in. The range does not default to and does not +have to be identical to the range you registered with. You can write +protect as many ranges as you like (inside the registered range). +Then, in the thread reading from uffd the struct will have +msg.arg.pagefault.flags & UFFD_PAGEFAULT_FLAG_WP set. Now you send +ioctl(uffd, UFFDIO_WRITEPROTECT, struct *uffdio_writeprotect) again +while pagefault.mode does not have UFFDIO_WRITEPROTECT_MODE_WP set. +This wakes up the thread which will continue to run with writes. This +allows you to do the bookkeeping about the write in the uffd reading +thread before the ioctl. + +If you registered with both UFFDIO_REGISTER_MODE_MISSING and +UFFDIO_REGISTER_MODE_WP then you need to think about the sequence in +which you supply a page and undo write protect. Note that there is a +difference between writes into a WP area and into a !WP area. The +former will have UFFD_PAGEFAULT_FLAG_WP set, the latter +UFFD_PAGEFAULT_FLAG_WRITE. The latter did not fail on protection but +you still need to supply a page when UFFDIO_REGISTER_MODE_MISSING was +used. + QEMU/KVM =3D=3D=3D=3D=3D=3D=3D=3D =20 --=20 2.24.1