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=-5.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 D42ABC4727E for ; Thu, 24 Sep 2020 18:34:25 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4136B23600 for ; Thu, 24 Sep 2020 18:34:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Htrz0GAy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4136B23600 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 89AEF6B0062; Thu, 24 Sep 2020 14:34:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84C7C8E0001; Thu, 24 Sep 2020 14:34:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 713266B006C; Thu, 24 Sep 2020 14:34:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0009.hostedemail.com [216.40.44.9]) by kanga.kvack.org (Postfix) with ESMTP id 5B8D56B0062 for ; Thu, 24 Sep 2020 14:34:24 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 22964181AE865 for ; Thu, 24 Sep 2020 18:34:24 +0000 (UTC) X-FDA: 77298805248.20.snow82_460783627161 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id F2CA2180C07AB for ; Thu, 24 Sep 2020 18:34:23 +0000 (UTC) X-HE-Tag: snow82_460783627161 X-Filterd-Recvd-Size: 6122 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 18:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600972462; 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=8K7ULO9gOYr1TfXMbCWrHocAusNVWavCoisSi1BnpHw=; b=Htrz0GAyohAW2O0YD3C17YdUa1cLes9dLNhht/a4HM5/22Pb6ukAGSq/1b1/3thcc+sodB aE7caex3Hb6XNBld21xW2SJYf0wx8k3NVz+e7FDDa8SnNPYzTvGENBkcue9hEiI1tBP50o uVyvcEWVlRI47q/7CuCfcXHawWgiZww= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-373CrXqbMry5lS98kgQMKg-1; Thu, 24 Sep 2020 14:34:21 -0400 X-MC-Unique: 373CrXqbMry5lS98kgQMKg-1 Received: by mail-qt1-f199.google.com with SMTP id a14so13023qtp.15 for ; Thu, 24 Sep 2020 11:34:21 -0700 (PDT) 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=8K7ULO9gOYr1TfXMbCWrHocAusNVWavCoisSi1BnpHw=; b=g9NusKh7gcwAkwVcd4ubiATPa+vGNGgbnda3S9+B+O961Y3NGFGVGXRg7DtDM7ayEr WIpv7qPq8woV7TqpkpPnBHfI92exSPhvAssM09cR3cSxBb4fEwfK0XmUFkKM4f6jauX4 tA6hlrHx6YhZsbGYPEnSnNnarSsEhdnzCmh9gxuf84zrl9hCmyUv8UjvZPaww7/XQz3z 0RJqQhRa/XtY0JxaiaqOId42qXivSe1eQtG/GwVeoT9T2ZG8Ms5xhDEn4N7ujOeuAfnQ xMoxCVnOpue7ChfJzgY14leVscI4WzAi9GoiGeGrNHJkWh1MAk0yMYqT++ISpIVsnLaO R6wg== X-Gm-Message-State: AOAM533o4yucQa/P4ZKiiwHlfoLhQwRnAxoKrRHRJ2wobUXGUNU2IYZL Vr3zaEeSC3bkUZ6NaXHk/GQtYpkEkqxAUR7S88n3rFN4IsTCusRS4MFmc5Q2B0gmMBhfeTu/olY MdlWzPsbhvfY= X-Received: by 2002:a37:a0cf:: with SMTP id j198mr464627qke.408.1600972460559; Thu, 24 Sep 2020 11:34:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz189qd83FsBU+Y1WUPx1hxxa2IHQ66Cfq7DuTjUWqlGX5heqwtD0IdF9ou967Lsr72f6+HHw== X-Received: by 2002:a37:a0cf:: with SMTP id j198mr464597qke.408.1600972460310; Thu, 24 Sep 2020 11:34:20 -0700 (PDT) Received: from xz-x1 (bras-vprn-toroon474qw-lp130-11-70-53-122-15.dsl.bell.ca. [70.53.122.15]) by smtp.gmail.com with ESMTPSA id z3sm211216qkj.0.2020.09.24.11.34.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Sep 2020 11:34:19 -0700 (PDT) Date: Thu, 24 Sep 2020 14:34:18 -0400 From: Peter Xu To: Jason Gunthorpe Cc: John Hubbard , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Jan Kara , Michal Hocko , Kirill Tkhai , Kirill Shutemov , Hugh Dickins , Christoph Hellwig , Andrea Arcangeli , Oleg Nesterov , Leon Romanovsky , Linus Torvalds , Jann Horn Subject: Re: [PATCH 1/5] mm: Introduce mm_struct.has_pinned Message-ID: <20200924183418.GJ79898@xz-x1> References: <20200922151736.GD19098@xz-x1> <20200922161046.GB731578@ziepe.ca> <20200922175415.GI19098@xz-x1> <20200922191116.GK8409@ziepe.ca> <20200923002735.GN19098@xz-x1> <20200923170759.GA9916@ziepe.ca> <20200924143517.GD79898@xz-x1> <20200924165152.GE9916@ziepe.ca> <20200924175531.GH79898@xz-x1> <20200924181501.GF9916@ziepe.ca> MIME-Version: 1.0 In-Reply-To: <20200924181501.GF9916@ziepe.ca> 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 Thu, Sep 24, 2020 at 03:15:01PM -0300, Jason Gunthorpe wrote: > On Thu, Sep 24, 2020 at 01:55:31PM -0400, Peter Xu wrote: > > On Thu, Sep 24, 2020 at 01:51:52PM -0300, Jason Gunthorpe wrote: > > > > Regarding the solution here, I think we can also cover read-only fast-gup too > > > > in the future - IIUC what we need to do is to make it pte_protnone() instead of > > > > pte_wrprotect(), then in the fault handler we should identify this special > > > > pte_protnone() against numa balancing (change_prot_numa()). I think it should > > > > work fine too, iiuc, because I don't think we should migrate a page at all if > > > > it's pinned for any reason... > > > > [1] > > > > > > > > With your COW breaking patch the read only fast-gup should break the > > > COW because of the write protect, just like for the write side. Not > > > seeing why we need to do something more? > > > > Consider this sequence of a parent process managed to fork() a child: > > > > buf = malloc(); Sorry! I think I missed something like: mprotect(buf, !WRITE); Here. > > // RDONLY gup > > pin_user_pages(buf, !WRITE); > > // pte of buf duplicated on both sides > > fork(); > > mprotect(buf, WRITE); > > *buf = 1; > > // buf page replaced as cow triggered > > > > Currently when fork() we'll happily share a pinned read-only page with the > > child by copying the pte directly. > > Why? This series prevents that, the page will be maybe_dma_pinned, so > fork() will copy it. With the extra mprotect(!WRITE), I think we'll see a !pte_write() entry. Then it'll not go into maybe_dma_pinned() at all since cow==false. > > > As a summary: imho the important thing is we should not allow any kind of > > sharing of any dma page, even it's pinned for read. > > Any sharing that results in COW. MAP_SHARED is fine, for instance Oh right, MAP_SHARED is definitely special. Thanks, -- Peter Xu