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=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 7333BC63798 for ; Fri, 27 Nov 2020 13:31:15 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id D538D2224D for ; Fri, 27 Nov 2020 13:31:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RNIs5Qbu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D538D2224D 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 E7B706B0036; Fri, 27 Nov 2020 08:31:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E2AFB6B005C; Fri, 27 Nov 2020 08:31:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A276B006C; Fri, 27 Nov 2020 08:31:13 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0195.hostedemail.com [216.40.44.195]) by kanga.kvack.org (Postfix) with ESMTP id B93F26B0036 for ; Fri, 27 Nov 2020 08:31:13 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 854448249980 for ; Fri, 27 Nov 2020 13:31:13 +0000 (UTC) X-FDA: 77530284426.22.soda16_480f95627388 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 5C87618038E72 for ; Fri, 27 Nov 2020 13:31:13 +0000 (UTC) X-HE-Tag: soda16_480f95627388 X-Filterd-Recvd-Size: 5931 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf24.hostedemail.com (Postfix) with ESMTP for ; Fri, 27 Nov 2020 13:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606483871; 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: in-reply-to:in-reply-to:references:references; bh=ED8t4Qy7PTQ/kC+YjFAEVvZVdG/aRP0VblcEzp2WkKo=; b=RNIs5QbuVYNJQQOoj0IrSav2hbqN2E8+blTaIT74FwEsCwyjyqt4oyj87bjRsQGxTB9ijn nqN8f1TjpirKCXTDwPSLU2GjqZU/YVN/hoQ5IyqSlpalTYGPmnDQ53kM2yf1zyusIcbB5r Sp8+wwVe+P9yD6yzadlbnsopWSMwmm0= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-350-pOkDm-eINH6HaAOlKAZZEQ-1; Fri, 27 Nov 2020 08:31:09 -0500 X-MC-Unique: pOkDm-eINH6HaAOlKAZZEQ-1 Received: by mail-qv1-f70.google.com with SMTP id e11so3084704qvu.18 for ; Fri, 27 Nov 2020 05:31:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ED8t4Qy7PTQ/kC+YjFAEVvZVdG/aRP0VblcEzp2WkKo=; b=L+PeXKRQzPt9wHmS/8PvAQ6MuhjCYDmjY8zANCuQH9w2wg+Ffrg2g43m4PaLboa8Uz hLk2qSDeDxpe0ghutrJx2HW99PDuXWH1gQLL5nnxb6bUoDpn727nD4HGM2yy1Cg/3qMG M80G/kPWmhWWrEz54u/w2vezBDgZkcoGu2EJ9BUzr8s74SQryNEE3IeiQktYA1PNguht cfcE5GqALaBvVE52dskDs3fw8lTZMFfU6ovKgeIZ0K9k4Y/c8Zuz/PHEjMxP+8uFq8WC XodIzkFwwq1ZmMX69l7K4REMJnrNqtlaU53hVcxTryE6nQp4S8mN489u2ZxLFG9vk2db sHgQ== X-Gm-Message-State: AOAM532mPGUAOI258fVUQ8mxK0M5Ch3ATXRPd3RPFsEz+bMhWhKiaTKo R3l1lU9PfGBkmbMuCcOFeCyuNlE4B0Y8sj2dimPeLpHq8rhfn8UoffamHebPhpntB8XOWCoVigv Ea2d22R68wXU= X-Received: by 2002:ad4:4b01:: with SMTP id r1mr8236591qvw.51.1606483869219; Fri, 27 Nov 2020 05:31:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuuEfzOgED8+Mw/pa0JP/ReXJap7o04I6TP6rj+aZvawEET+ECQspMmP3qAsjMZTSiGhLhSw== X-Received: by 2002:ad4:4b01:: with SMTP id r1mr8236566qvw.51.1606483868918; Fri, 27 Nov 2020 05:31:08 -0800 (PST) Received: from xz-x1 ([142.126.81.247]) by smtp.gmail.com with ESMTPSA id p62sm6006251qkf.50.2020.11.27.05.31.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 05:31:08 -0800 (PST) Date: Fri, 27 Nov 2020 08:31:06 -0500 From: Peter Xu To: Mike Rapoport Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Morton , Hugh Dickins , Andrea Arcangeli , Mike Rapoport Subject: Re: [PATCH] mm: Don't fault around userfaultfd-registered regions on reads Message-ID: <20201127133106.GA6573@xz-x1> References: <20201126222359.8120-1-peterx@redhat.com> <20201127081605.GX123287@linux.ibm.com> MIME-Version: 1.0 In-Reply-To: <20201127081605.GX123287@linux.ibm.com> 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 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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: On Fri, Nov 27, 2020 at 10:16:05AM +0200, Mike Rapoport wrote: > On Thu, Nov 26, 2020 at 05:23:59PM -0500, Peter Xu wrote: > > Faulting around for reads are in most cases helpful for the performance so that > > continuous memory accesses may avoid another trip of page fault. However it > > may not always work as expected. > > > > For example, userfaultfd registered regions may not be the best candidate for > > pre-faults around the reads. > > > > For missing mode uffds, fault around does not help because if the page cache > > existed, then the page should be there already. If the page cache is not > > there, nothing else we can do, either. If the fault-around code is destined to > > be helpless for userfault-missing vmas, then ideally we can skip it. > > > > For wr-protected mode uffds, errornously fault in those pages around could lead > > to threads accessing the pages without uffd server's awareness. For example, > > when punching holes on uffd-wp registered shmem regions, we'll first try to > > unmap all the pages before evicting the page cache but without locking the > > page (please refer to shmem_fallocate(), where unmap_mapping_range() is called > > before shmem_truncate_range()). When fault-around happens near a hole being > > punched, we might errornously fault in the "holes" right before it will be > > punched. Then there's a small window before the page cache was finally > > dropped, and after the page will be writable again (NOTE: the uffd-wp protect > > information is totally lost due to the pre-unmap in shmem_fallocate(), so the > > page can be writable within the small window). That's severe data loss. > > > > Let's grant the userspace full control of the uffd-registered ranges, rather > > than trying to do the tricks. > > > > Cc: Hugh Dickins > > Cc: Andrea Arcangeli > > Cc: Andrew Morton > > Cc: Mike Rapoport > > Signed-off-by: Peter Xu > > One nit below, except that > > Reviewed-by: Mike Rapoport Thanks! > > +static inline bool vma_registered_userfaultfd(struct vm_area_struct *vma) > > +{ > > + return userfaultfd_missing(vma) || userfaultfd_wp(vma); > > +} > > We have userfaultfd_armed() that does exectly this, don't we? Yes, will fix that up. -- Peter Xu