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=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 303B9C433DF for ; Mon, 20 Jul 2020 19:58:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id E62222080D for ; Mon, 20 Jul 2020 19:58:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=nvidia.com header.i=@nvidia.com header.b="J/HjJ/a4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E62222080D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3AA098D0002; Mon, 20 Jul 2020 15:58:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35BE98D0001; Mon, 20 Jul 2020 15:58:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 249398D0002; Mon, 20 Jul 2020 15:58:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0140.hostedemail.com [216.40.44.140]) by kanga.kvack.org (Postfix) with ESMTP id 0DC688D0001 for ; Mon, 20 Jul 2020 15:58:08 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 56A978248047 for ; Mon, 20 Jul 2020 19:58:07 +0000 (UTC) X-FDA: 77059515414.27.fact19_230dae726f27 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin27.hostedemail.com (Postfix) with ESMTP id E5D1B17EF7D for ; Mon, 20 Jul 2020 19:56:41 +0000 (UTC) X-HE-Tag: fact19_230dae726f27 X-Filterd-Recvd-Size: 6922 Received: from hqnvemgate24.nvidia.com (hqnvemgate24.nvidia.com [216.228.121.143]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Mon, 20 Jul 2020 19:56:41 +0000 (UTC) Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Mon, 20 Jul 2020 12:54:40 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Mon, 20 Jul 2020 12:56:39 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Mon, 20 Jul 2020 12:56:39 -0700 Received: from rcampbell-dev.nvidia.com (172.20.13.39) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Mon, 20 Jul 2020 19:56:31 +0000 Subject: Re: [PATCH v2 3/5] mm/notifier: add migration invalidation type To: Jason Gunthorpe CC: , , , , , , "Jerome Glisse" , John Hubbard , "Christoph Hellwig" , Andrew Morton , Shuah Khan , Ben Skeggs , Bharata B Rao References: <20200713172149.2310-1-rcampbell@nvidia.com> <20200713172149.2310-4-rcampbell@nvidia.com> <20200720184020.GS2021248@mellanox.com> X-Nvconfidentiality: public From: Ralph Campbell Message-ID: <86e3730a-bdf9-8d93-6dec-f658a8684f6e@nvidia.com> Date: Mon, 20 Jul 2020 12:56:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <20200720184020.GS2021248@mellanox.com> X-Originating-IP: [172.20.13.39] X-ClientProxiedBy: HQMAIL107.nvidia.com (172.20.187.13) To HQMAIL107.nvidia.com (172.20.187.13) Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1595274880; bh=5GRiSBs3RDOMk08dKGgpct0rWCZMLTR1JrSTRec7I5Q=; h=X-PGP-Universal:Subject:To:CC:References:X-Nvconfidentiality:From: Message-ID:Date:User-Agent:MIME-Version:In-Reply-To: X-Originating-IP:X-ClientProxiedBy:Content-Type:Content-Language: Content-Transfer-Encoding; b=J/HjJ/a4Z1TyqdDeMi/trUuxwre2mngbZuk4MS7bh5bh0WX1m3ugS3ZC6r1Sr63hL jxw0u1znD+p4jaGRMJFIKV5Nv7U4UndgsV5nVoGqRzw8Z1I1HyohTbwpCiEPt9Iju+ Pp2jtt8Qtbed/25hYEqaHZPDxIkFLq561hpNsdRSyAhv8KXIyPKMwAAyb6Wplsu3wY uHfsi35PrgZ6A1el4uTZPEg2VVA31PS0U8sKjKnUMWFsBXWzPDEwnM8LTJ1rNCkdyD wZHst3Xm3c+A3P/AuVFwuj1gEglhhLMDcUvCAxRi59G7lZpg39UF6hJxTeZvfmajnt Jgp9CMjMTEugA== X-Rspamd-Queue-Id: E5D1B17EF7D X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam04 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 7/20/20 11:40 AM, Jason Gunthorpe wrote: > On Mon, Jul 13, 2020 at 10:21:47AM -0700, Ralph Campbell wrote: >> Currently migrate_vma_setup() calls mmu_notifier_invalidate_range_start() >> which flushes all device private page mappings whether or not a page >> is being migrated to/from device private memory. In order to not disrupt >> device mappings that are not being migrated, shift the responsibility >> for clearing device private mappings to the device driver and leave >> CPU page table unmapping handled by migrate_vma_setup(). To support >> this, the caller of migrate_vma_setup() should always set struct >> migrate_vma::src_owner to a non NULL value that matches the device >> private page->pgmap->owner. This value is then passed to the struct >> mmu_notifier_range with a new event type which the driver's invalidation >> function can use to avoid device MMU invalidations. >> >> Signed-off-by: Ralph Campbell >> include/linux/mmu_notifier.h | 7 +++++++ >> mm/migrate.c | 8 +++++++- >> 2 files changed, 14 insertions(+), 1 deletion(-) >> >> diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h >> index fc68f3570e19..1921fcf6be5b 100644 >> +++ b/include/linux/mmu_notifier.h >> @@ -38,6 +38,10 @@ struct mmu_interval_notifier; >> * >> * @MMU_NOTIFY_RELEASE: used during mmu_interval_notifier invalidate to signal >> * that the mm refcount is zero and the range is no longer accessible. >> + * >> + * @MMU_NOTIFY_MIGRATE: used during migrate_vma_collect() invalidate to signal >> + * a device driver to possibly ignore the invalidation if the >> + * migrate_pgmap_owner field matches the driver's device private pgmap owner. >> */ >> enum mmu_notifier_event { >> MMU_NOTIFY_UNMAP = 0, >> @@ -46,6 +50,7 @@ enum mmu_notifier_event { >> MMU_NOTIFY_PROTECTION_PAGE, >> MMU_NOTIFY_SOFT_DIRTY, >> MMU_NOTIFY_RELEASE, >> + MMU_NOTIFY_MIGRATE, >> }; >> >> #define MMU_NOTIFIER_RANGE_BLOCKABLE (1 << 0) >> @@ -264,6 +269,7 @@ struct mmu_notifier_range { >> unsigned long end; >> unsigned flags; >> enum mmu_notifier_event event; >> + void *migrate_pgmap_owner; >> }; >> >> static inline int mm_has_notifiers(struct mm_struct *mm) >> @@ -513,6 +519,7 @@ static inline void mmu_notifier_range_init(struct mmu_notifier_range *range, >> range->start = start; >> range->end = end; >> range->flags = flags; >> + range->migrate_pgmap_owner = NULL; >> } >> >> #define ptep_clear_flush_young_notify(__vma, __address, __ptep) \ >> diff --git a/mm/migrate.c b/mm/migrate.c >> index 2bbc5c4c672e..9b3dcb81be5f 100644 >> +++ b/mm/migrate.c >> @@ -2391,8 +2391,14 @@ static void migrate_vma_collect(struct migrate_vma *migrate) >> { >> struct mmu_notifier_range range; >> >> - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, NULL, >> + /* >> + * Note that the src_owner is passed to the mmu notifier callback so >> + * that the registered device driver can skip invalidating device >> + * private page mappings that won't be migrated. >> + */ >> + mmu_notifier_range_init(&range, MMU_NOTIFY_MIGRATE, 0, migrate->vma, >> migrate->vma->vm_mm, migrate->start, migrate->end); > > So the idea is that src_owner is always set to the pgmap owner when > working with DEVICE_PRIVATE? > > But then the comment in the prior patch should be fixed: > > @@ -199,11 +204,12 @@ struct migrate_vma { > > /* > * Set to the owner value also stored in page->pgmap->owner for > + * migrating device private memory. The direction also needs to > + * be set to MIGRATE_VMA_FROM_DEVICE_PRIVATE. > > To say the caller must always provide src_owner. > > And that field should probably be renamed at this point, as there is > nothing "src" about it. It is just the pgmap_owner of the > DEVICE_PRIVATE pages the TO/FROM DEVICE migration is working on. > > Jason Good point. I'll send a v3 with your suggested changes.