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=-6.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 9174DC43460 for ; Wed, 19 May 2021 12:24:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 462D861353 for ; Wed, 19 May 2021 12:24:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 462D861353 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 890A66B0036; Wed, 19 May 2021 08:24:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8412B6B006C; Wed, 19 May 2021 08:24:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BAAF6B006E; Wed, 19 May 2021 08:24:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0207.hostedemail.com [216.40.44.207]) by kanga.kvack.org (Postfix) with ESMTP id 3CAE06B0036 for ; Wed, 19 May 2021 08:24:32 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id D0146B792 for ; Wed, 19 May 2021 12:24:31 +0000 (UTC) X-FDA: 78157898742.31.2D43A72 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 9CFD0A0003B8 for ; Wed, 19 May 2021 12:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621427070; 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=B6+GMlwrRYCIhKlucQm0d4pBq6rNn427lZR0x1Dlm1U=; b=EbYoSluzMNhbEpOumzUwtHyuMIzBpVC//0qSDZmlKC8tYpvcrH6roPskLn/KRzJGCBaWY3 K/Dv6yOpLAOFtwJI3xqxGOxK/4y8UCIUr1uqg+zZpPAmjdK8ZaJdr2QPqEFxtzIFVYnfBY IfTWUQIxVulS/Vqinxa6HFQ1CaFMg4A= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-59-6fAzzPetN2SuBHcTY1vpBQ-1; Wed, 19 May 2021 08:24:29 -0400 X-MC-Unique: 6fAzzPetN2SuBHcTY1vpBQ-1 Received: by mail-qk1-f197.google.com with SMTP id u9-20020a05620a4549b02902e956c2a3c8so9611803qkp.20 for ; Wed, 19 May 2021 05:24:29 -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=B6+GMlwrRYCIhKlucQm0d4pBq6rNn427lZR0x1Dlm1U=; b=gDe0kwsDa5JCF/aQIpKRweIDBIig62thboKSjdgfR6Z0pKgukfqSKMBN8Q/+KmUIeF RaM1UimYxLRa/1Tmbr0p9a8wjfCZ+rXQPzYaz824DsLSrIkgLwgN/8h66kLbnt8rUYWS OHv1Y3aoYFbjqkD5eFfagCV2WjGCOc8yWq4tSQCyuvbhv36Y3hdxWrNLKVL2GJXnYkVI 0Tu38oqj/n6/bvcWO4wdbV/qZPcydtmpynvwyjZbWV2BvuA3B7yPb+/tvJxvFry4Ffhk GXB4Ki9lD21WS1ihq/Em2x/Fm1uVk/cSefe2QRE04g6Z/UGnWtvRpNNq+7askgYAZROE GkbA== X-Gm-Message-State: AOAM531ACcdSm9zwKoCwCWTSDnJK3TTcTUfUWU2jFrqJYwIMJMsnNAaq bUV6sNoExRoo/b0XpkX7whW4iX/M4LPI/5kLnEvhJjL+Bi6/9yXM5jadUndwHfjdc7AED0SGyRd Dafchl/sD1xs= X-Received: by 2002:ac8:4b74:: with SMTP id g20mr11134582qts.196.1621427068813; Wed, 19 May 2021 05:24:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfYWS/dsuPCr9XZO07LTE6R21Hbq/UdkcASCcx2KQMguWwavSEob3mks8rwF1tmkFnKYSzdA== X-Received: by 2002:ac8:4b74:: with SMTP id g20mr11134560qts.196.1621427068562; Wed, 19 May 2021 05:24:28 -0700 (PDT) Received: from t490s (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id m4sm15981169qtg.21.2021.05.19.05.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 May 2021 05:24:28 -0700 (PDT) Date: Wed, 19 May 2021 08:24:27 -0400 From: Peter Xu To: Alistair Popple Cc: linux-mm@kvack.org, nouveau@lists.freedesktop.org, bskeggs@redhat.com, akpm@linux-foundation.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, jhubbard@nvidia.com, rcampbell@nvidia.com, jglisse@redhat.com, jgg@nvidia.com, hch@infradead.org, daniel@ffwll.ch, willy@infradead.org, bsingharora@gmail.com, Christoph Hellwig Subject: Re: [PATCH v8 5/8] mm: Device exclusive memory access Message-ID: References: <20210407084238.20443-1-apopple@nvidia.com> <20210407084238.20443-6-apopple@nvidia.com> <3859486.fHISG1RMxY@nvdebian> MIME-Version: 1.0 In-Reply-To: <3859486.fHISG1RMxY@nvdebian> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Rspamd-Queue-Id: 9CFD0A0003B8 Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EbYoSluz; spf=none (imf15.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam04 X-Stat-Signature: jos111uw79hz4pceinnxrhhkynju384a X-HE-Tag: 1621427070-214401 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 Wed, May 19, 2021 at 08:49:01PM +1000, Alistair Popple wrote: > On Wednesday, 19 May 2021 7:16:38 AM AEST Peter Xu wrote: > > External email: Use caution opening links or attachments > > > > > > On Wed, Apr 07, 2021 at 06:42:35PM +1000, Alistair Popple wrote: > > > > [...] > > > > > +static bool try_to_protect(struct page *page, struct mm_struct *mm, > > > + unsigned long address, void *arg) > > > +{ > > > + struct ttp_args ttp = { > > > + .mm = mm, > > > + .address = address, > > > + .arg = arg, > > > + .valid = false, > > > + }; > > > + struct rmap_walk_control rwc = { > > > + .rmap_one = try_to_protect_one, > > > + .done = page_not_mapped, > > > + .anon_lock = page_lock_anon_vma_read, > > > + .arg = &ttp, > > > + }; > > > + > > > + /* > > > + * Restrict to anonymous pages for now to avoid potential writeback > > > + * issues. > > > + */ > > > + if (!PageAnon(page)) > > > + return false; > > > + > > > + /* > > > + * During exec, a temporary VMA is setup and later moved. > > > + * The VMA is moved under the anon_vma lock but not the > > > + * page tables leading to a race where migration cannot > > > + * find the migration ptes. Rather than increasing the > > > + * locking requirements of exec(), migration skips > > > + * temporary VMAs until after exec() completes. > > > + */ > > > + if (!PageKsm(page) && PageAnon(page)) > > > + rwc.invalid_vma = invalid_migration_vma; > > > + > > > + rmap_walk(page, &rwc); > > > + > > > + return ttp.valid && !page_mapcount(page); > > > +} > > > > I raised a question in the other thread regarding fork(): > > > > https://lore.kernel.org/lkml/YKQjmtMo+YQGx%2FwZ@t490s/ > > > > While I suddenly noticed that we may have similar issues even if we fork() > > before creating the ptes. > > > > In that case, we may see multiple read-only ptes pointing to the same page. > > We will convert all of them into device exclusive read ptes in rmap_walk() > > above, however how do we guarantee after all COW done in the parent and all > > the childs processes, the device owned page will be returned to the parent? > > I assume you are talking about a fork() followed by a call to > make_device_exclusive()? I think this should be ok because > make_device_exclusive() always calls GUP with FOLL_WRITE both to break COW and > because a device performing atomic operations needs to write to the page. I > suppose a comment here highlighting the need to break COW to avoid this > scenario would be useful though. Indeed, sorry for the false alarm! Yes it would be great to mention that too. -- Peter Xu