From patchwork Thu Feb 10 07:28:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 12741510 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C9D76C433FE for ; Thu, 10 Feb 2022 07:29:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1A6CD6B0074; Thu, 10 Feb 2022 02:29:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 156D36B009D; Thu, 10 Feb 2022 02:29:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E25D96B009E; Thu, 10 Feb 2022 02:29:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0190.hostedemail.com [216.40.44.190]) by kanga.kvack.org (Postfix) with ESMTP id CE0F26B0074 for ; Thu, 10 Feb 2022 02:29:51 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 8CC9A1813120E for ; Thu, 10 Feb 2022 07:29:51 +0000 (UTC) X-FDA: 79126045782.18.81FC6D6 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf27.hostedemail.com (Postfix) with ESMTP id 3EF5140008 for ; Thu, 10 Feb 2022 07:29:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=cT0lgQLRNyTNcmoanfoLYEuqgQBo6jG7fWqTaM2xsVI=; b=WtXnyR0/9o8Ve39JA/IAs6kxRj +T3DdMelNYqpGXzKygkC4Y4CtpCWN/6tcAC/dBsxIY5S2HAa1ONMU3A3VdEBKd8Qvvk6phUj9gw8s qf0oxMsyITvf3j0B1ovCKTLGKdB+48mCGSFd+7ATgssvTFB5v08ay/qd+SAOe1JHFUn44Io2RZMAQ oEZyC2tZhuIyk5ylZU9lCNPDL3mYOudZ6I6bFj6addurE4AP+dLanx1P0RKhpQBRIRt+KUAbiP8q6 8ffUhMXi1H/nvzHVwM+Lag8Uit/c5OfAwt6VydD4rL2duWM1tbopsEdfKuBA6Pqa7qLP0gPbcPAIJ NAo1KASw==; Received: from [2001:4bb8:188:3efc:8014:b2f2:fdfd:57ea] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nI3te-002sOv-8Y; Thu, 10 Feb 2022 07:29:42 +0000 From: Christoph Hellwig To: Andrew Morton , Dan Williams Cc: Felix Kuehling , Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" , Ben Skeggs , Karol Herbst , Lyude Paul , Jason Gunthorpe , Alistair Popple , Logan Gunthorpe , Ralph Campbell , linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org, nvdimm@lists.linux.dev, linux-mm@kvack.org Subject: [PATCH 25/27] mm: remove the vma check in migrate_vma_setup() Date: Thu, 10 Feb 2022 08:28:26 +0100 Message-Id: <20220210072828.2930359-26-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220210072828.2930359-1-hch@lst.de> References: <20220210072828.2930359-1-hch@lst.de> MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Rspamd-Queue-Id: 3EF5140008 X-Rspam-User: Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=bombadil.20210309 header.b="WtXnyR0/"; spf=none (imf27.hostedemail.com: domain of BATV+4801fb5fa93fa27e8109+6745+infradead.org+hch@bombadil.srs.infradead.org has no SPF policy when checking 198.137.202.133) smtp.mailfrom=BATV+4801fb5fa93fa27e8109+6745+infradead.org+hch@bombadil.srs.infradead.org; dmarc=none X-Stat-Signature: 7h93ege7qhzrbpkz5p54bjtk4o6asb3x X-Rspamd-Server: rspam04 X-HE-Tag: 1644478191-215265 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: Alistair Popple migrate_vma_setup() checks that a valid vma is passed so that the page tables can be walked to find the pfns associated with a given address range. However in some cases the pfns are already known, such as when migrating device coherent pages during pin_user_pages() meaning a valid vma isn't required. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling Signed-off-by: Christoph Hellwig --- mm/migrate_device.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 0b295594e7626d..03e182f9fc7865 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -462,24 +462,24 @@ int migrate_vma_setup(struct migrate_vma *args) args->start &= PAGE_MASK; args->end &= PAGE_MASK; - if (!args->vma || is_vm_hugetlb_page(args->vma) || - (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) - return -EINVAL; - if (nr_pages <= 0) - return -EINVAL; - if (args->start < args->vma->vm_start || - args->start >= args->vma->vm_end) - return -EINVAL; - if (args->end <= args->vma->vm_start || args->end > args->vma->vm_end) - return -EINVAL; if (!args->src || !args->dst) return -EINVAL; - - memset(args->src, 0, sizeof(*args->src) * nr_pages); - args->cpages = 0; - args->npages = 0; - - migrate_vma_collect(args); + if (args->vma) { + if (is_vm_hugetlb_page(args->vma) || + (args->vma->vm_flags & VM_SPECIAL) || vma_is_dax(args->vma)) + return -EINVAL; + if (args->start < args->vma->vm_start || + args->start >= args->vma->vm_end) + return -EINVAL; + if (args->end <= args->vma->vm_start || + args->end > args->vma->vm_end) + return -EINVAL; + memset(args->src, 0, sizeof(*args->src) * nr_pages); + args->cpages = 0; + args->npages = 0; + + migrate_vma_collect(args); + } if (args->cpages) migrate_vma_unmap(args); @@ -661,7 +661,7 @@ void migrate_vma_pages(struct migrate_vma *migrate) continue; } - if (!page) { + if (!page && migrate->vma) { if (!(migrate->src[i] & MIGRATE_PFN_MIGRATE)) continue; if (!notified) {