From patchwork Wed Mar 11 18:34:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433541 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1F6714B4 for ; Thu, 12 Mar 2020 08:11:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82D9220650 for ; Thu, 12 Mar 2020 08:11:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="VUmp9gXg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 82D9220650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2EF3D6EAA4; Thu, 12 Mar 2020 08:09:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE03A6E9E1 for ; Wed, 11 Mar 2020 18:35:16 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id c145so3070456qke.12 for ; Wed, 11 Mar 2020 11:35:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uADmryRzUppwT0DoGC+vBgxjUH6ONtG4PbQCGFnnObM=; b=VUmp9gXg3gFFyzdp3BYqvtlRiDQuHpwTyPbJtafqR5nqzevoh+CJyh9Tmk0l1rtePV BQbOyou6HXXPi0MIBkFBd/nDlZ7zW6oaWhgYkg1746g6vTjLUc4zchtLbTk5u6rlJFcH OqI/UsNrU0c1qnzSRe+90EsTnAep6Cxv9sDTgutpePZ2ftbb4+r2vBajlqvQ/FtfH2WQ tcRgrS0PSKtpdfnaJFY1e10PVH+8BMdvSdmZ03GeCrZjItWXejdM+25Q9PumbjfaRSBO Tl6c+VS+Z2ou82HkY5RIOvzff/ouDGE/WNAnF+hBwzsCmqGcMlKT5IZzkHUBtySUT505 m+6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uADmryRzUppwT0DoGC+vBgxjUH6ONtG4PbQCGFnnObM=; b=bTK8UsaBbe5IP4n9oSBm0LqsC7/g9BadIzuf+V2eLEZFNPJgXTpBXZpq9vHq5m6T/C YSLwixmLyklB7tsZDIfGE3UNGDrDFJrSDhmNbbukqJBXUg+kG2UvAF/Vv0KSRt7ZtG4C k57t63T9a4EcHV7qkkXxWwtz3JJCI+8i+mHn48utOcP8IY7OFITsrVkUoqx4dd10Zr4Q c4nylPZxeBuFmUZIkmWppRowWQiScFIg9IjFQY/t7DkdbzD+Ns6/x6jDMzNDfSDYxfiS GcNgDtDzORaw64BOtFbM/3aNEfY926QGsc6RyQmJQOW92z97bocvF3rVbXxsB8C2h0X6 tDEA== X-Gm-Message-State: ANhLgQ2ZhcTYSWPX5m8f0KJwigCnN/wBkCDblpvZmXb7eI/Omd71aJBH KxvcFWZAygERXysEt78k8DmVjg== X-Google-Smtp-Source: ADFU+vu4pkafRt7ZpiQA2Qo9TSkli2LPgyls9Ykw3IxuaySmx8qfnahDqH8g+HMF46wNbf60JV5d8Q== X-Received: by 2002:a05:620a:11b3:: with SMTP id c19mr4218673qkk.296.1583951715965; Wed, 11 Mar 2020 11:35:15 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id c40sm5273938qtk.18.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:15 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-000168-0X; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 1/8] mm/hmm: add missing unmaps of the ptep during hmm_vma_handle_pte() Date: Wed, 11 Mar 2020 15:34:59 -0300 Message-Id: <20200311183506.3997-2-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe Many of the direct returns of error skipped doing the pte_unmap(). All non zero exit paths must unmap the pte. The pte_unmap() is split unnaturally like this because some of the error exit paths trigger a sleep and must release the lock before sleeping. Fixes: 992de9a8b751 ("mm/hmm: allow to mirror vma of a file on a DAX backed filesystem") Fixes: 53f5c3f489ec ("mm/hmm: factor out pte and pmd handling to simplify hmm_vma_walk_pmd()") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 72e5a6d9a41756..35f85424176d14 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -325,6 +325,7 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, } /* Report error for everything else */ + pte_unmap(ptep); *pfn = range->values[HMM_PFN_ERROR]; return -EFAULT; } else { @@ -339,10 +340,13 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, if (pte_devmap(pte)) { hmm_vma_walk->pgmap = get_dev_pagemap(pte_pfn(pte), hmm_vma_walk->pgmap); - if (unlikely(!hmm_vma_walk->pgmap)) + if (unlikely(!hmm_vma_walk->pgmap)) { + pte_unmap(ptep); return -EBUSY; + } } else if (IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL) && pte_special(pte)) { if (!is_zero_pfn(pte_pfn(pte))) { + pte_unmap(ptep); *pfn = range->values[HMM_PFN_SPECIAL]; return -EFAULT; } @@ -437,7 +441,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, r = hmm_vma_handle_pte(walk, addr, end, pmdp, ptep, &pfns[i]); if (r) { - /* hmm_vma_handle_pte() did unmap pte directory */ + /* hmm_vma_handle_pte() did pte_unmap() */ hmm_vma_walk->last = addr; return r; } From patchwork Wed Mar 11 18:35:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433457 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E816114B4 for ; Thu, 12 Mar 2020 08:09:15 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C987B20650 for ; Thu, 12 Mar 2020 08:09:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="W2QcOA29" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C987B20650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69B046EA4F; Thu, 12 Mar 2020 08:08:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4F1996E9E5 for ; Wed, 11 Mar 2020 18:35:20 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id e16so3097559qkl.6 for ; Wed, 11 Mar 2020 11:35:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8lEcVZbpC6FaqZy+Eys87JwANFXrjLZWV2hXSwo7DsY=; b=W2QcOA29+2hWCo5dDy/jbUb7GhqQlmsnMJZk/cECcBgqjRYGVtdV2RyzDV9agkzEDY kdGVL25lhvr2y1TCNOvtamw6p7HliGBbQOlw5wyKr5k01cZPcqO3bX8bYmGwGbdVbjzZ Qw2Q7wpYrxD4X6zOi2KLFKH5EiBC1WW9a0e7B7cX60TfFbRpaDvpECRZsYahA2FgOPcC l8evX/8XNukV9x7I9e6WmEE8SxUhCDwQ8vktxGPhdfd+O1KaOqLDUEEevOUGpLT1R1G+ iwi43ZEr6GqkZtDpl7jhMmGOTb/j9MRuywyNP2Pf72IzWStQ2oSvqU+oCwVTGUwoilMP KaFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8lEcVZbpC6FaqZy+Eys87JwANFXrjLZWV2hXSwo7DsY=; b=uIcSVZwfioRJUiEYngM4mo+WfkQlq/UhprOzl03HpoccQw5atkXzMGfEhMiOAqvFrn DgPA+SJ7AQiEq/NXrnFRycKcXS28FIz0QzP/4LgzoGuBc+dWJ1D+OGOpHnq09G6jD3ju A6DRz+F91ptBRgdOfTSio7ryUvDyDyd0VxWS82+sQA0eqkbCsSIBYZvn5/952UpI/wT4 iKriS0oJyaDR5bg1v5VZ8qWu00acGLdwoZVwXnhmNV1oUC5krPFXl402O0yqvaCf4/Mo BBNmycqnvkvNqmI6Kb0Ttvw1jATP5E6J+hbrqYr9cBzr58z6btGgE2LZRAakJh0lZOCe 1ptQ== X-Gm-Message-State: ANhLgQ3FqRGiv+0R+X2N8P75g6zy/NEJafFLJOoqmSEUnYcO8AtCkgSm 75sND9RjqPMpy1/i34G8JmJ8yg== X-Google-Smtp-Source: ADFU+vv42iIVOVgQYb8TOc186/XWa+snYITfoBWnXSMFRcjaqugUYatuGxkE3I0VXu08rjERKTHgkg== X-Received: by 2002:a05:620a:134a:: with SMTP id c10mr4076890qkl.188.1583951719448; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id d73sm7995274qkg.113.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016F-3B; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 2/8] mm/hmm: don't free the cached pgmap while scanning Date: Wed, 11 Mar 2020 15:35:00 -0300 Message-Id: <20200311183506.3997-3-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe The pgmap is held in the hmm_vma_walk variable in hope of speeding up future get_dev_pagemap() calls by hitting the same pointer. The algorithm doesn't actually care about how long the pgmap is held for. Move the put of the cached pgmap to after the walk is completed and delete all the other now redundant puts. This solves a possible leak of the reference in hmm_vma_walk_pmd() if a hmm_vma_handle_pte() fails while looping. Fixes: 992de9a8b751 ("mm/hmm: allow to mirror vma of a file on a DAX backed filesystem") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) We talked about just deleting this stuff, but I think it makes alot sense for hmm_range_fault() to trigger fault on devmap pages that are not compatible with the caller - so lets just fix the leak on error path for now. diff --git a/mm/hmm.c b/mm/hmm.c index 35f85424176d14..9e8f68eb83287a 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -239,10 +239,6 @@ static int hmm_vma_handle_pmd(struct mm_walk *walk, unsigned long addr, } pfns[i] = hmm_device_entry_from_pfn(range, pfn) | cpu_flags; } - if (hmm_vma_walk->pgmap) { - put_dev_pagemap(hmm_vma_walk->pgmap); - hmm_vma_walk->pgmap = NULL; - } hmm_vma_walk->last = end; return 0; } @@ -360,10 +356,6 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, return 0; fault: - if (hmm_vma_walk->pgmap) { - put_dev_pagemap(hmm_vma_walk->pgmap); - hmm_vma_walk->pgmap = NULL; - } pte_unmap(ptep); /* Fault any virtual address we were asked to fault */ return hmm_vma_walk_hole_(addr, end, fault, write_fault, walk); @@ -446,16 +438,6 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, return r; } } - if (hmm_vma_walk->pgmap) { - /* - * We do put_dev_pagemap() here and not in hmm_vma_handle_pte() - * so that we can leverage get_dev_pagemap() optimization which - * will not re-take a reference on a pgmap if we already have - * one. - */ - put_dev_pagemap(hmm_vma_walk->pgmap); - hmm_vma_walk->pgmap = NULL; - } pte_unmap(ptep - 1); hmm_vma_walk->last = addr; @@ -529,10 +511,6 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, pfns[i] = hmm_device_entry_from_pfn(range, pfn) | cpu_flags; } - if (hmm_vma_walk->pgmap) { - put_dev_pagemap(hmm_vma_walk->pgmap); - hmm_vma_walk->pgmap = NULL; - } hmm_vma_walk->last = end; goto out_unlock; } @@ -694,6 +672,15 @@ long hmm_range_fault(struct hmm_range *range, unsigned int flags) return -EBUSY; ret = walk_page_range(mm, hmm_vma_walk.last, range->end, &hmm_walk_ops, &hmm_vma_walk); + /* + * A pgmap is kept cached in the hmm_vma_walk to avoid expensive + * searching in the probably common case that the pgmap is the + * same for the entire requested range. + */ + if (hmm_vma_walk.pgmap) { + put_dev_pagemap(hmm_vma_walk.pgmap); + hmm_vma_walk.pgmap = NULL; + } } while (ret == -EBUSY); if (ret) From patchwork Wed Mar 11 18:35:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433489 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CC0B90 for ; Thu, 12 Mar 2020 08:09:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0DA3420650 for ; Thu, 12 Mar 2020 08:09:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="nU/438MJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0DA3420650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8704C6EA70; Thu, 12 Mar 2020 08:08:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by gabe.freedesktop.org (Postfix) with ESMTPS id 20D2B6E9E6 for ; Wed, 11 Mar 2020 18:35:19 +0000 (UTC) Received: by mail-qt1-x843.google.com with SMTP id l21so2336259qtr.8 for ; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7tlzdKvmVhZXurBBb+bDdPz4NTtXbLSAXRRPdzQxqMg=; b=nU/438MJuKpkChqrzGp1uQGe8kdR+9FMZNnY3eJEh1/fEkuAylxu/p3vRpF+STOTTc 1aZg6sghnmz+a1b1hofgPaLUEiSjYs6mnou5cSAQpAbusouHhmCshZJn5Y+BpFibMFws sS75VycDsMUXbQ5eG56z8VC2S20c63fEttL1RiDnUqJDg+27ki6Luzb2lDKvYEm/m63H 6AZ3S+ZudbR9EAgzdlmCv8l453QIr6/K4xP1Yxid64YED9TXkLOxfIreGtEKC+JHYDou mhQgU7/y1uYgxw3hMkdkxrzX6Tt8Qzhinu+oRAIaElTPL8qH6WmoiY+PgLkYkfRfEjMh 7g9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7tlzdKvmVhZXurBBb+bDdPz4NTtXbLSAXRRPdzQxqMg=; b=JqgtNB3x4thsL/xiSIDL3wGMzkmf0rbfUpTyl6tq3BSoNrlDHE/5MFjESaS/3NyRsd tKYWQKqI0+Kr4uPnEze3mY869Qf/dS88NWoe+TW1JxctE43PjIg9CKXbeiqM/HXVXdzP L+TbTOsZBLNlXqUv2cY8fInjpifIUZdei6vXa1xeE9nqAE+FyEsI9dQO/p79FXO6KVYC rtZM8DQ6CZd61Ed6/8E7BSUZdQDRLGWqXv5ejbr7PnztyWyXi5t9Z4/cAz1R2mo/Gxo2 8AT3B0Fjk7GvlxMYBP2S+5KNEua7dlRntcU7fJ410Ia63ItevUTXrU+NB7tw6TRD3ipV DwAA== X-Gm-Message-State: ANhLgQ3xKRJU32T4MclIZEVQGoY+GDew6LVhLhy2dW0SG4Zk6cO5t1Kw Uxlz3hS6XF3JzMUJr7RCAxBWyQ== X-Google-Smtp-Source: ADFU+vvx8+qty+5T7X6/CVYANONypWbzRUqA+9Oqg9yC8JsorlJ4ocR7hpiWYgd7bDnMLWyAZmGiVQ== X-Received: by 2002:ac8:6f4c:: with SMTP id n12mr4002527qtv.367.1583951717799; Wed, 11 Mar 2020 11:35:17 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id 3sm26733708qte.59.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016L-4h; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 3/8] mm/hmm: do not call hmm_vma_walk_hole() while holding a spinlock Date: Wed, 11 Mar 2020 15:35:01 -0300 Message-Id: <20200311183506.3997-4-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, Steven Price , linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe This eventually calls into handle_mm_fault() which is a sleeping function. Release the lock first. hmm_vma_walk_hole() does not touch the contents of the PUD, so it does not need the lock. Fixes: 3afc423632a1 ("mm: pagewalk: add p4d_entry() and pgd_entry()") Cc: Steven Price Signed-off-by: Jason Gunthorpe Reviewed-by: Steven Price --- mm/hmm.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 9e8f68eb83287a..32dcbfd3908315 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -473,8 +473,8 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, pud = READ_ONCE(*pudp); if (pud_none(pud)) { - ret = hmm_vma_walk_hole(start, end, -1, walk); - goto out_unlock; + spin_unlock(ptl); + return hmm_vma_walk_hole(start, end, -1, walk); } if (pud_huge(pud) && pud_devmap(pud)) { @@ -483,8 +483,8 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, bool fault, write_fault; if (!pud_present(pud)) { - ret = hmm_vma_walk_hole(start, end, -1, walk); - goto out_unlock; + spin_unlock(ptl); + return hmm_vma_walk_hole(start, end, -1, walk); } i = (addr - range->start) >> PAGE_SHIFT; @@ -495,9 +495,9 @@ static int hmm_vma_walk_pud(pud_t *pudp, unsigned long start, unsigned long end, hmm_range_need_fault(hmm_vma_walk, pfns, npages, cpu_flags, &fault, &write_fault); if (fault || write_fault) { - ret = hmm_vma_walk_hole_(addr, end, fault, - write_fault, walk); - goto out_unlock; + spin_unlock(ptl); + return hmm_vma_walk_hole_(addr, end, fault, write_fault, + walk); } pfn = pud_pfn(pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT); From patchwork Wed Mar 11 18:35:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433473 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B64BC14B4 for ; Thu, 12 Mar 2020 08:09:35 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 973F320650 for ; Thu, 12 Mar 2020 08:09:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Oj2+9cL+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 973F320650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 69DD66EA48; Thu, 12 Mar 2020 08:08:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by gabe.freedesktop.org (Postfix) with ESMTPS id 848836E9E3 for ; Wed, 11 Mar 2020 18:35:18 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id t13so2312875qtn.13 for ; Wed, 11 Mar 2020 11:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eYOHMjSMYAiqyn3S+V97OaKejU5YnzW7DlF+2YMOcF0=; b=Oj2+9cL+KscU9a9zK4Suzl5t1bo3inZGbyVIq9f/zeCmxkVp6hpJxKiilnqnMZQ/FY 88384yWaxGdO7AK2SvS4w/5ttmUJ1QwwiIIQkIru3m4YEvr6DVRfcc2LZX2b+WisWs3x Q9/ZJPxajspOeqvaygRv/+e66+A+86ngTjF2dHCc+iW767kCXhfOPdAWbvM9qhpvmh52 a1hdeiAzVdj1EC+964oWge4gJ1EvDWASPw6bKneNMxHD5zeTPMdbLleLYVkd/wi+PWZ9 2CJq/Ge+3bDYLHuaBaG8pI2c5Dwhg7JguuNwrBTyac857oUPLrhjtOnYkU9jB4pEhySk Wr0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eYOHMjSMYAiqyn3S+V97OaKejU5YnzW7DlF+2YMOcF0=; b=gF1NlFluiMm5f9J1bHbRmnt4QintKO+usxH2x4SxO6eQ5OFCG45n9GBAD5jvM9galH ukmvXxKzCc8r9FKly02+nhh2mKlaFsYPjVtBlN5Ww1HhIhaRPnINSoy0c7L0LOLK2MsC QoS67ZZ86Uj0W9jR3XgKaova9q2s84LR0NcrAA0DACqvyfnKvPGiPyQp4r518iPKZFXF PxJTO61dIx11d+/TfqxPDOWWpaJQO4ix0MY5H8mliQKLETNgKoGmycQLML70gcfgkcn4 7yUmVWILv9MSyM7owOGfox4xMB4dGGraFUZiEup3Rv3DXqFhLQM39XratIJP3HecgX1v kVIQ== X-Gm-Message-State: ANhLgQ2TufL5qhhRJartNaMzhBOrXGtIv7nLEmy1OgltKJuTo+/awtPo eiDbNWX1iIoxL919eihZ//RhEw== X-Google-Smtp-Source: ADFU+vvtZI7GOONaM2bhtDz46uIiycc1D5Nn8U4YJ8Luo17HKLeSzNTw8qbnVEqbl89i5RN+bVZ38Q== X-Received: by 2002:ac8:1758:: with SMTP id u24mr4036108qtk.148.1583951716868; Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id u26sm948048qku.97.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016R-6m; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 4/8] mm/hmm: add missing pfns set to hmm_vma_walk_pmd() Date: Wed, 11 Mar 2020 15:35:02 -0300 Message-Id: <20200311183506.3997-5-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe All success exit paths from the walker functions must set the pfns array. A migration entry with no required fault is a HMM_PFN_NONE return, just like the pte case. Fixes: d08faca018c4 ("mm/hmm: properly handle migration pmd") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/hmm.c b/mm/hmm.c index 32dcbfd3908315..5f5ccf13dd1e85 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -394,7 +394,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, pmd_migration_entry_wait(walk->mm, pmdp); return -EBUSY; } - return 0; + return hmm_pfns_fill(start, end, range, HMM_PFN_NONE); } else if (!pmd_present(pmd)) return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR); From patchwork Wed Mar 11 18:35:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433503 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F1FF90 for ; Thu, 12 Mar 2020 08:10:14 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F91F20650 for ; Thu, 12 Mar 2020 08:10:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="DwTEKicl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F91F20650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 795EE6EA4D; Thu, 12 Mar 2020 08:08:47 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2FC736E9E3 for ; Wed, 11 Mar 2020 18:35:18 +0000 (UTC) Received: by mail-qv1-xf44.google.com with SMTP id ca9so1353016qvb.9 for ; Wed, 11 Mar 2020 11:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=V4LlS7crloThbv9GsTKnTI10IpHCEC6Nex/YosncVz8=; b=DwTEKiclhpQg0fNTYvqAuNy+heFBVQDSfpsXeRVFu0jDES6R+ZMeTr35f2e5N625FK NToJ+Fd3YnorvJ5CX+rlPDiHjGYo/nKZi9O2f3e7L+49kPt+8lcENKJ5g82DzDMVzbYQ B/OsMP99QPyNZ+fbnmeMkVwjuffPVwRi1xkGV4I8FGJpZH/UT89BW6LfgfUKESMIZV87 ohDZTTRJdm5qYEKozQzdCvJ3Z7x2V6OG3XC9TNpEnREYKTtGMwA3lKn4rC7QZ+C7mL4/ gwlfxffBMiHJVWrMbkz21Qx/6pE+4seQ24ZP6qSJckOZ3It/iBMOQoLOFMdzzsJV/PgL DFEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=V4LlS7crloThbv9GsTKnTI10IpHCEC6Nex/YosncVz8=; b=DjcbRS4pvq59ZSWXQZJaxbXJrLz0ZGOtlEQwxlXpVRPFQ4JWksqNjUgOHDxMvpdPN3 BN6Wive/39GFbUe6MyWQ8aHctfQqmqHsVj+Apnqy+YHdLGCNgfac4hKcT9UJmZ3Wvavg b/sgOQnX4T6P4auB1Rub1Co9dhWDIjvTnET+ZtGqt0qGM24IdEbbTJbq4+7iMaOlhsCp W5jrb9cVwdquQbzVbK3F0HHggFbiVgIeDqynOipp7vaP/wLWdZwex2/0Ct10DHPxvL7J saeSwC7H0E8x+/GIhyIAzOeAk3+uUdHFLkqcCgKyjdPKlUZ50/iyGLdatR1PgkIyAILv GiVQ== X-Gm-Message-State: ANhLgQ2JxGcBUUoiUPupMoa/x4lybptN2sH2efrOQcbNDW/1EReHk5fA hm+XsFkvrlyw8QgJodqQwfHbrg== X-Google-Smtp-Source: ADFU+vtiAnVo6RkgaCWxmSuBgPMtecLVlfoeqm0VtiCXRstC1SIEdwxVoTIzwmkXm1mF22wmi1C85w== X-Received: by 2002:ad4:4e73:: with SMTP id ec19mr3920755qvb.78.1583951717237; Wed, 11 Mar 2020 11:35:17 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id p16sm4656758qkj.5.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016X-8Y; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 5/8] mm/hmm: add missing call to hmm_range_need_fault() before returning EFAULT Date: Wed, 11 Mar 2020 15:35:03 -0300 Message-Id: <20200311183506.3997-6-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe All return paths that do EFAULT must call hmm_range_need_fault() to determine if the user requires this page to be valid. If the page cannot be made valid if the user later requires it, due to vma flags in this case, then the return should be HMM_PFN_ERROR. Fixes: a3e0d41c2b1f ("mm/hmm: improve driver API to work and wait over a range") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index 5f5ccf13dd1e85..e10cd0adba7b37 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -582,18 +582,15 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end, struct vm_area_struct *vma = walk->vma; /* - * Skip vma ranges that don't have struct page backing them or - * map I/O devices directly. - */ - if (vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP)) - return -EFAULT; - - /* + * Skip vma ranges that don't have struct page backing them or map I/O + * devices directly. + * * If the vma does not allow read access, then assume that it does not - * allow write access either. HMM does not support architectures - * that allow write without read. + * allow write access either. HMM does not support architectures that + * allow write without read. */ - if (!(vma->vm_flags & VM_READ)) { + if ((vma->vm_flags & (VM_IO | VM_PFNMAP | VM_MIXEDMAP)) || + !(vma->vm_flags & VM_READ)) { bool fault, write_fault; /* @@ -607,7 +604,7 @@ static int hmm_vma_walk_test(unsigned long start, unsigned long end, if (fault || write_fault) return -EFAULT; - hmm_pfns_fill(start, end, range, HMM_PFN_NONE); + hmm_pfns_fill(start, end, range, HMM_PFN_ERROR); hmm_vma_walk->last = end; /* Skip this vma and continue processing the next vma. */ From patchwork Wed Mar 11 18:35:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433497 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF38914B4 for ; Thu, 12 Mar 2020 08:10:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C04E320650 for ; Thu, 12 Mar 2020 08:10:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="T5u4wkGo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C04E320650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0BDD66EA6B; Thu, 12 Mar 2020 08:08:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id 122F76E9E4 for ; Wed, 11 Mar 2020 18:35:19 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id l13so2329768qtv.10 for ; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Yd+xe0QbNmktoZjpJg43C/41KpLoxm/0aQKS2FSaS3E=; b=T5u4wkGorRMsF6nNncNqo4u2AxsrIUqlN8mcICipRt8jE73vdIfF+GtJaU/nwQTASH 8wS+b8zMD796R57juosBaEBb8H9hMJVyml4x+uTHb+BCypffHOEfwYvE/nrlai0Jegv6 FxYC7LXInWuPmKKE66pgeEaK0xiROZGQqzjplU9JF00xyUqrLGiz5jSK5YigiieXcTgu 2MhdCfLjfpUneRGX+PKVLQAfE0z1/Y0bTUreYkirHtkb4PSp/LyoQgl7ymheDmm5a08a Gz9PK60Dko2CPILX0MePkRl7styVd1ZNKQhzvOkSgrmoFOwybxNI7y/d+HBSQ1EVHt0N K+UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Yd+xe0QbNmktoZjpJg43C/41KpLoxm/0aQKS2FSaS3E=; b=c51V3eHvRZ3p3amSR0SZMVNT2ri9KS1vGQbk34f+9t//g6WYb5b8xelZztQnpXFAeg mocHPVvQAXWKWVmkRY5df+BZQVG4nFn3KJuiAK/9xNUvDWyiid5RB0AScAQFDkVW07UK mi0dAJYKEEBVrfXo9Pu9K/x7StoXseVvPzz5tZ9Z14b9NIrWPiu0Gxl86Zf2GBIlynv+ sP7MeFCblvtVIzJEYXsEIrRJscoJV5CRVbzovd2xo9NeKaImUfkKM+lEmea5C2l3l6+i eggTBuFCjMBeEVlxo9jYAP8VtGrYOPtLs6OHGSaatkh6cKpc54H/+gRkvcKe7g5DJpGc omiA== X-Gm-Message-State: ANhLgQ3BB4kWbvWUV9SSif9nCUCrEPNXcF1PEqTeGku34WqZGJty/fN+ yECL4mBMMeHwcoDNm6q1VCtRdQ== X-Google-Smtp-Source: ADFU+vtkDL7Acp/VH19W18vm5b/9WqeC+awgKyc75q+9sf3VgvOE3gOX0YH3WoWVFdlaKA6kLiYpzg== X-Received: by 2002:aed:2266:: with SMTP id o35mr3965179qtc.392.1583951718149; Wed, 11 Mar 2020 11:35:18 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id o7sm8052457qtg.63.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016d-Aq; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 6/8] mm/hmm: reorganize how !pte_present is handled in hmm_vma_handle_pte() Date: Wed, 11 Mar 2020 15:35:04 -0300 Message-Id: <20200311183506.3997-7-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe The intention with this code is to determine if the caller required the pages to be valid, and if so, then take some action to make them valid. The action varies depending on the page type. In all cases, if the caller doesn't ask for the page, then hmm_range_fault() should not return an error. Revise the implementation to be clearer, and fix some bugs: - hmm_pte_need_fault() must always be called before testing fault or write_fault otherwise the defaults of false apply and the if()'s don't work. This was missed on the is_migration_entry() branch - -EFAULT should not be returned unless hmm_pte_need_fault() indicates fault is required - ie snapshotting should not fail. - For !pte_present() the cpu_flags are always 0, except in the special case of is_device_private_entry(), calling pte_to_hmm_pfn_flags() is confusing. Reorganize the flow so that it always follows the pattern of calling hmm_pte_need_fault() and then checking fault || write_fault. Fixes: 2aee09d8c116 ("mm/hmm: change hmm_vma_fault() to allow write fault on page basis") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index e10cd0adba7b37..bf676cfef3e8ee 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -282,15 +282,6 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, if (!pte_present(pte)) { swp_entry_t entry = pte_to_swp_entry(pte); - if (!non_swap_entry(entry)) { - cpu_flags = pte_to_hmm_pfn_flags(range, pte); - hmm_pte_need_fault(hmm_vma_walk, orig_pfn, cpu_flags, - &fault, &write_fault); - if (fault || write_fault) - goto fault; - return 0; - } - /* * This is a special swap entry, ignore migration, use * device and report anything else as error. @@ -310,26 +301,30 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, return 0; } - if (is_migration_entry(entry)) { - if (fault || write_fault) { - pte_unmap(ptep); - hmm_vma_walk->last = addr; - migration_entry_wait(walk->mm, pmdp, addr); - return -EBUSY; - } + hmm_pte_need_fault(hmm_vma_walk, orig_pfn, 0, &fault, + &write_fault); + if (!fault && !write_fault) return 0; + + if (!non_swap_entry(entry)) + goto fault; + + if (is_migration_entry(entry)) { + pte_unmap(ptep); + hmm_vma_walk->last = addr; + migration_entry_wait(walk->mm, pmdp, addr); + return -EBUSY; } /* Report error for everything else */ pte_unmap(ptep); *pfn = range->values[HMM_PFN_ERROR]; return -EFAULT; - } else { - cpu_flags = pte_to_hmm_pfn_flags(range, pte); - hmm_pte_need_fault(hmm_vma_walk, orig_pfn, cpu_flags, - &fault, &write_fault); } + cpu_flags = pte_to_hmm_pfn_flags(range, pte); + hmm_pte_need_fault(hmm_vma_walk, orig_pfn, cpu_flags, &fault, + &write_fault); if (fault || write_fault) goto fault; From patchwork Wed Mar 11 18:35:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433535 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A487A90 for ; Thu, 12 Mar 2020 08:11:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 858F320650 for ; Thu, 12 Mar 2020 08:11:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="Obbz1qB+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 858F320650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9FE526EA8E; Thu, 12 Mar 2020 08:08:59 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x841.google.com (mail-qt1-x841.google.com [IPv6:2607:f8b0:4864:20::841]) by gabe.freedesktop.org (Postfix) with ESMTPS id AECD36E9E6 for ; Wed, 11 Mar 2020 18:35:19 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id f17so1058238qtq.6 for ; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uygKHmkoF/XJeHmET22wDgQZ4IaJVIkBqpHNgU4CsJM=; b=Obbz1qB+tB3LW2qPkKBSaSvBXS0QAxokU4EYzwIOqtm8mh2BUcwkjBK401WkLDG3qN maRWjYJWBrWo0yx7uPmbBEL9/OzQfBwoxFIjDiIZ4OOTuIIkTb0vfXIeIFlufr44gvy8 ozDGUwJ+AScwhg3khplp06oZj8CIkNUNOOOSsNf9UpdHapwBkULUpPjYH90BGR4d5ybZ l2D7tGyYQL+lxEibzC81pQq/n5FVYiBCvnO3s8o0YZ74E2FigGT6Ku4BH3nFtHmoRzsv Y1UQAMgsdkUeEyDQRU6R2V+PqPmV9Io8KFSEaRkCEdGoEN79gzAbDpSPiBBGoLfSwi6k 0GSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uygKHmkoF/XJeHmET22wDgQZ4IaJVIkBqpHNgU4CsJM=; b=R8+N75xdLLSANHV4EfJcczsB4KI3VpAG4waSzuOlPYHHHW6vY4dEH/yPavnoi9QM3z JOAJJHbX8pjeIZS+ZtI8Uu0XxV79AMLcdMId1edWqtgRguG6M00ggr7iQM4FGqq0RgaF en2m0vfuyoDdrlaHtHr/4d+3+BtfzzjT5c9zwbPsdwBiKh9zP8ge9K3bfDV+Q9vHYpiH 7JH2DZJZwvoiCQ+0Gc404oPZPSJR2DCfCPlSCZkOsK6Y+mx20TJsreqgPdDcUgvurd8N /mAiTolcYs0NmncdqJM/FGqNKEDCWafiiYe1HITqVJk1KHueGj39fnQBPc1EgipqUJC3 49MQ== X-Gm-Message-State: ANhLgQ2fGn1XKzyBKtClNYCdTcHKsahuQ7hSVBW8uRq+vb/MJPWQK3i6 dbaYCBGeMkiEZWFJxzYQwBRuRw== X-Google-Smtp-Source: ADFU+vuxi2jwTZNWP7BbaHt9jLf2pO1O8MStIxhR8zwOb6icVa77ppaQhtJcOJ1hj7G1PBtoZXjjag== X-Received: by 2002:ac8:b43:: with SMTP id m3mr3894888qti.191.1583951718521; Wed, 11 Mar 2020 11:35:18 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id g22sm11074847qtp.8.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016j-CP; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 7/8] mm/hmm: return -EFAULT when setting HMM_PFN_ERROR on requested valid pages Date: Wed, 11 Mar 2020 15:35:05 -0300 Message-Id: <20200311183506.3997-8-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe hmm_range_fault() should never return 0 if the caller requested a valid page, but the pfns output for that page would be HMM_PFN_ERROR. hmm_pte_need_fault() must always be called before setting HMM_PFN_ERROR to detect if the page is in faulting mode or not. Fix two cases in hmm_vma_walk_pmd() and reorganize some of the duplicated code. Fixes: d08faca018c4 ("mm/hmm: properly handle migration pmd") Fixes: da4c3c735ea4 ("mm/hmm/mirror: helper to snapshot CPU page table") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index bf676cfef3e8ee..f61fddf2ef6505 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -363,8 +363,10 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, { struct hmm_vma_walk *hmm_vma_walk = walk->private; struct hmm_range *range = hmm_vma_walk->range; - uint64_t *pfns = range->pfns; - unsigned long addr = start, i; + uint64_t *pfns = &range->pfns[(start - range->start) >> PAGE_SHIFT]; + unsigned long npages = (end - start) >> PAGE_SHIFT; + unsigned long addr = start; + bool fault, write_fault; pte_t *ptep; pmd_t pmd; @@ -374,14 +376,6 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, return hmm_vma_walk_hole(start, end, -1, walk); if (thp_migration_supported() && is_pmd_migration_entry(pmd)) { - bool fault, write_fault; - unsigned long npages; - uint64_t *pfns; - - i = (addr - range->start) >> PAGE_SHIFT; - npages = (end - addr) >> PAGE_SHIFT; - pfns = &range->pfns[i]; - hmm_range_need_fault(hmm_vma_walk, pfns, npages, 0, &fault, &write_fault); if (fault || write_fault) { @@ -390,8 +384,15 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, return -EBUSY; } return hmm_pfns_fill(start, end, range, HMM_PFN_NONE); - } else if (!pmd_present(pmd)) + } + + if (!pmd_present(pmd)) { + hmm_range_need_fault(hmm_vma_walk, pfns, npages, 0, &fault, + &write_fault); + if (fault || write_fault) + return -EFAULT; return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR); + } if (pmd_devmap(pmd) || pmd_trans_huge(pmd)) { /* @@ -408,8 +409,7 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, if (!pmd_devmap(pmd) && !pmd_trans_huge(pmd)) goto again; - i = (addr - range->start) >> PAGE_SHIFT; - return hmm_vma_handle_pmd(walk, addr, end, &pfns[i], pmd); + return hmm_vma_handle_pmd(walk, addr, end, pfns, pmd); } /* @@ -418,15 +418,19 @@ static int hmm_vma_walk_pmd(pmd_t *pmdp, * entry pointing to pte directory or it is a bad pmd that will not * recover. */ - if (pmd_bad(pmd)) + if (pmd_bad(pmd)) { + hmm_range_need_fault(hmm_vma_walk, pfns, npages, 0, &fault, + &write_fault); + if (fault || write_fault) + return -EFAULT; return hmm_pfns_fill(start, end, range, HMM_PFN_ERROR); + } ptep = pte_offset_map(pmdp, addr); - i = (addr - range->start) >> PAGE_SHIFT; - for (; addr < end; addr += PAGE_SIZE, ptep++, i++) { + for (; addr < end; addr += PAGE_SIZE, ptep++, pfns++) { int r; - r = hmm_vma_handle_pte(walk, addr, end, pmdp, ptep, &pfns[i]); + r = hmm_vma_handle_pte(walk, addr, end, pmdp, ptep, pfns); if (r) { /* hmm_vma_handle_pte() did pte_unmap() */ hmm_vma_walk->last = addr; From patchwork Wed Mar 11 18:35:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Gunthorpe X-Patchwork-Id: 11433527 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B86F90 for ; Thu, 12 Mar 2020 08:10:52 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3C6B220650 for ; Thu, 12 Mar 2020 08:10:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="My+Tr5ob" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3C6B220650 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D8ED76EAA7; Thu, 12 Mar 2020 08:08:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by gabe.freedesktop.org (Postfix) with ESMTPS id E28036E9E4 for ; Wed, 11 Mar 2020 18:35:19 +0000 (UTC) Received: by mail-qv1-xf43.google.com with SMTP id du17so1337969qvb.12 for ; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QKMl+66IkY5RJBc0Lj1AmzrrF9o7Pt2qhF3I7u882Ls=; b=My+Tr5obADx21Hw+/1ZHcQU2g7c3b+OTd5/wmC6UjpMNkjW0hIDHzK8ddjx9NxansQ xMX4Aj/BzOraQiOZJMCoAJ8BCbWpA76TeDQJpSF1cBs17/ZSUbEOp4oTniYhhkumK6D7 KPLipNTzlsr1LrvMhvbr+cT/iJpfFUGKIEcWYdHQmJuix/X8M9v34cDlqNcvcZb93gg/ qmECXi4N7kLooQrxoej2u3Z7KgVr5NUCbBqtvxqBvM21srVWLIok/zC+S/xT+e22qQba ye/unTNuQ58XryNUiO+MHYbpZFny3E4SK95zolNONBnkBWCTXSu4FmHMN6+0AqoaxvaT c/tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QKMl+66IkY5RJBc0Lj1AmzrrF9o7Pt2qhF3I7u882Ls=; b=Q3hLdEX08wTyhjV5Pr4lECbDoDciE3i7kztqD9HB0FIk5VJ7aTvkvttSq9b0qfd99t u2gDvjQVKkiUulfJ4HbGNPrQvDiV+vNXkgtD+8nbHfF9rnU4MH+NNHWBPITBMOwyKcPh ycYSI2kdrnp10kX4hCUwxw/VPoGaLj1v+XiY/CzXLoxsemasG5H1tIUuOh2Qt4II1Q8a zCvYBVelfhlWyQY+AjlFnwpb9K99YujtZYDQkvKV5zTyxtNt54qh5txTij3/jf1Ovi2D PFtvJSDQ6YxFVOoQlg3Ix2StP9vC1NAPgcyfQ7NZ8WXK2rnuN+KIcEjRerpgj1VyoK4S JKZQ== X-Gm-Message-State: ANhLgQ0zYquPrZGLU8mcrMpGVz677ULJGnqE8z8KRZW6RFeEzSsRQSlw md5aXReIpnY48PzAU4EA90wd1w== X-Google-Smtp-Source: ADFU+vtfPiOC5zRwhZ8OGnDckKKD8dKwbpO/uXMgStKCVg9GMeRPWKdwyL8T6AA5IGkEm62LONCB8g== X-Received: by 2002:ad4:4a89:: with SMTP id h9mr4082034qvx.168.1583951719048; Wed, 11 Mar 2020 11:35:19 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-57-212.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.57.212]) by smtp.gmail.com with ESMTPSA id 17sm9154803qkm.105.2020.03.11.11.35.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Mar 2020 11:35:16 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1jC6CJ-00016p-Dt; Wed, 11 Mar 2020 15:35:15 -0300 From: Jason Gunthorpe To: Jerome Glisse , Ralph Campbell , Felix.Kuehling@amd.com Subject: [PATCH hmm 8/8] mm/hmm: add missing call to hmm_pte_need_fault in HMM_PFN_SPECIAL handling Date: Wed, 11 Mar 2020 15:35:06 -0300 Message-Id: <20200311183506.3997-9-jgg@ziepe.ca> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200311183506.3997-1-jgg@ziepe.ca> References: <20200311183506.3997-1-jgg@ziepe.ca> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 12 Mar 2020 08:08:13 +0000 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Philip Yang , John Hubbard , amd-gfx@lists.freedesktop.org, linux-mm@kvack.org, Jason Gunthorpe , dri-devel@lists.freedesktop.org, Christoph Hellwig Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Jason Gunthorpe Currently if a special PTE is encountered hmm_range_fault() immediately returns EFAULT and sets the HMM_PFN_SPECIAL error output (which nothing uses). EFAULT should only be returned after testing with hmm_pte_need_fault(). Also pte_devmap() and pte_special() are exclusive, and there is no need to check IS_ENABLED, pte_special() is stubbed out to return false on unsupported architectures. Fixes: 992de9a8b751 ("mm/hmm: allow to mirror vma of a file on a DAX backed filesystem") Signed-off-by: Jason Gunthorpe --- mm/hmm.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mm/hmm.c b/mm/hmm.c index f61fddf2ef6505..ca33d086bdc190 100644 --- a/mm/hmm.c +++ b/mm/hmm.c @@ -335,16 +335,21 @@ static int hmm_vma_handle_pte(struct mm_walk *walk, unsigned long addr, pte_unmap(ptep); return -EBUSY; } - } else if (IS_ENABLED(CONFIG_ARCH_HAS_PTE_SPECIAL) && pte_special(pte)) { - if (!is_zero_pfn(pte_pfn(pte))) { + } + + /* + * Since each architecture defines a struct page for the zero page, just + * fall through and treat it like a normal page. + */ + if (pte_special(pte) && !is_zero_pfn(pte_pfn(pte))) { + hmm_pte_need_fault(hmm_vma_walk, orig_pfn, 0, &fault, + &write_fault); + if (fault || write_fault) { pte_unmap(ptep); - *pfn = range->values[HMM_PFN_SPECIAL]; return -EFAULT; } - /* - * Since each architecture defines a struct page for the zero - * page, just fall through and treat it like a normal page. - */ + *pfn = range->values[HMM_PFN_SPECIAL]; + return 0; } *pfn = hmm_device_entry_from_pfn(range, pte_pfn(pte)) | cpu_flags;