From patchwork Tue Feb 1 07:05:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12731427 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A197DC4332F for ; Tue, 1 Feb 2022 07:06:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 010D610EC97; Tue, 1 Feb 2022 07:06:51 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2044.outbound.protection.outlook.com [40.107.236.44]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6DFB810EC96; Tue, 1 Feb 2022 07:06:49 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JV3aoDHinm4UTEceHtn5xpHA0ZWjUKLDIX+M4mrokSECL+uKBEK+7DH4of/YhFPWTkKoaVgBp+YHmGDfN/QPzZAWfqC6+c+55cKYfqdFpgSOrEFksvH7+voKCM74PLG2jftcRKiszzde2UsX2p2zysL3mceg0ADjITQ3Y0uGxY76/DB73Dz9qxVkSs2ppNePiFqfbNM2eYsKBQD8KgzU03vNKoPDyix+hAVQfI1JSaW+0oHoqxtTR79cwWdfTV42Ik5qTjPcoZJdbQ11W+FHGDhxLc10uebVR78WJDyWUKS4i6qsVc9YntHxMkIXL6nyvemdO8i3BTaDexCuFo9RiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=b51ocJMBk4G9G+uPxYS2c6YPUjtxQDBMQdZVtZ1jMWg=; b=jQCUrNbXvBUXj6iJ4P+4Oi5hv5WRX/eAC4p87sXfEygyA99jD6I3t24MJf1FzU0LiPvvz6KUGGlN5eO7dhFyk9eM+AwMDGYXkUWahnlVYa6JEVGSh6lE24pfWz3Xr/Heftsn7ahcNzNxMEgL8AniUwQ+5OYfBZbIFBf6VXW9urcWE9jpzRJ83EEeewenRDOQplDU50F/O724+SQJ+C0A36FmDeqN7tnv0FLO3sM2QSjX2bNfTz167U12AJRQUZHFwILXXGj+9k7jip6HUWvWUK5F8qOXbW8ygKgN+w1JsCKoEtq0uGjHBfzhV/jjaYT/6hvH+PMzJwfapEr/sP8KMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=b51ocJMBk4G9G+uPxYS2c6YPUjtxQDBMQdZVtZ1jMWg=; b=gGBeBuqoct8oeL77wirmELX91j2ntlxFt0bgIzDFUeOXRTULSrJQdE1V7FV6IN7DE1UxwV8dFMQQTVICucvoGgy0iwj1GmQAUsJsAE6bShY0jfoFyFVFHDfybZTkTd57V53fioyF2pAzepFw2P2Fc1+wLC61aawnKI7xuIHeil6F859RGA+Dos7Ds63TYaSniz5YDTxvLNAojUqIpl68NM2zwhTI6a/kkLSZjapkTQ8+wzo533A5YtK4Bs34mTLJrGQFdUGyq4GpAFnl0mu3w/hfjI9qPmKQhjG/iRysDw/QpcXxIqXkliES/9ONHsOz4VVLs1Uz203bhG9rFeX5fg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by CH2PR12MB3991.namprd12.prod.outlook.com (2603:10b6:610:2f::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.15; Tue, 1 Feb 2022 07:06:47 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd%4]) with mapi id 15.20.4930.022; Tue, 1 Feb 2022 07:06:47 +0000 From: Alistair Popple To: akpm@linux-foundation.org, linux-mm@kvack.org Subject: [PATCH 1/3] migrate.c: Remove vma check in migrate_vma_setup() Date: Tue, 1 Feb 2022 18:05:55 +1100 Message-Id: <02339ee87f428688336960d0403059b7af5834fe.1643698773.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0012.namprd13.prod.outlook.com (2603:10b6:a03:2c0::17) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 273833b0-db72-497e-fd5f-08d9e5516982 X-MS-TrafficTypeDiagnostic: CH2PR12MB3991:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rsBkYo9DX1SiQYRskbiXpG41ptiwVSg7PEBH5boMEiI5RlkF4Oc4KkKziHPSmGA/x1+OMhaYnvwKLYhol19GbUC/AYdhh3B/RIWa0omKhiwcKQ+JHGsbVqvrQe3Ss1KVaDJOZotXEAeK5L11kULFGAeysjLUWCW5qQfilt5nihLHCFfcUyTKmP4/BuQUJhuA1V+YUuI24BPJHz39nTEkiyVLWpcpg87x9VAgaXlgfHdLXMcGblZcvAyQs6+nSjRDMAoDAiy6dkH0el2pagBL+inIuXCGE6z6UCUSrPAXVcBi5UtXpLI9eP4XoKoEvLN5FYX66Q8nf8RFZpeZUQ5jwYr+zd6+/7vsCVX/454xA4vknx1QTJFP9hifwoYKMSqSgztlonkWpS/rfI9dgpMrKbQKYEZO5RGEUhpf1Dr4Hwx6rtZgk6wEz3IM9uIjTgSBwB4ZcufB1/UNXxHB+YA4FTcP0/gGLZ3TD+utzHGcDG2BmM9Xwyj3dSJRbTtTcfCWdPn+4cGGeQnuHTT4sS6fhcofQ+5jtRCk1qhI7Yh3+4gtdaChbmpeio6tnUtZ7g9VGI2XcYvfX779tWDVD9YSXEaqWcU1dFQD4PXSVu87QxdhUv175k4VVvN7spG/FIMGF4d5timu9xtv3A/ojDzoYQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR12MB3176.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(508600001)(86362001)(6486002)(7416002)(2906002)(5660300002)(66556008)(8936002)(83380400001)(66946007)(6512007)(4326008)(66476007)(36756003)(8676002)(186003)(2616005)(26005)(107886003)(6506007)(316002)(38100700002)(6666004)(20210929001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: x18ZnB0Ni1bjxp8kuBxH+E6d9IJ8vlnftoSyjSs0By5M3fpl9HnFsubM61yBfaigWydnmrqP3ZGVBkRgjlFK7q4AewlhNYapwSc4AOpCVFNs1I7w9rPi0wnUz7yTUN3mpiB95wgj1+ZNHtbHM66nmFU3cdt0voYKu/ym6yaqbDT33THbl1CCCP3QnW/P0Ge9a7ZEfNRyhJTVDt64J0KVF68LJu2fc86/c24mciX1oLgFv5HznsxY/zfxst7UM9zCDsgnxEFPyA6A4qEpCNubhydk9j7merDJLOdd7swqQdpUHM9JWDgMTI5kT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+zuiprmL0MlEyQZu+1itvBigMXPegUYk0MTAjJSdJXRGSZ3ZVVttCFkp4ZM10UA3kAevywWHKWDaMcBap/LpFYbC7c9nqdc0bQIn0RSbdovLZvsoX0dJXQrIKXAWb1HC444v3Itgpqa3YHpBv6hg4++KgkE2/6OAzTAqeK2tZ8/MS/yuUdHQQbyJ2RYYPuzGktPS0FEx3M1hgypZXg5tT6KUa+p7jvW/YWgQnILiOUgUQOPjcyKgD0Be/f4= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 273833b0-db72-497e-fd5f-08d9e5516982 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 07:06:47.6658 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 9zS38548/NKGbLWh86kc/aXLfM+yb2E7n34p9uOoP7BxIK+EK3WJEd5qxJT0D4DnLanfazwsR3gM6Vvo+cATdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB3991 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: alex.sierra@amd.com, rcampbell@nvidia.com, willy@infradead.org, jhubbard@nvidia.com, Felix.Kuehling@amd.com, Alistair Popple , dri-devel@lists.freedesktop.org, linux-xfs@vger.kernel.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, linux-ext4@vger.kernel.org, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 --- mm/migrate.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index d3cc358..31ba8ca 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2581,24 +2581,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); @@ -2783,7 +2783,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) { From patchwork Tue Feb 1 07:05:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12731428 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id A0E31C43219 for ; Tue, 1 Feb 2022 07:06:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8FE9310EC9D; Tue, 1 Feb 2022 07:06:55 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2053.outbound.protection.outlook.com [40.107.236.53]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F7F710EC9C; Tue, 1 Feb 2022 07:06:54 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KHX3SMvbPuVMti9xoOgA+Rz43fzQM3s898ViucsmU7GvH/Q1lxUlbSmH/kefqbK/AJfTMo4vsNtT66K3wyjs9sUV2HG1VFBjyVHD8rD6Kv4+BFC13c1D3ZnaoydtuHHBRjfnXvpEBGYmiik3NLaVTuBcSTFEbe+r0cpusIw24wlOrDLNfTorLQfsqCmZ0QFr3y5aIMk3mY8kRqfov0Svm3r5wXnEJ6j/GG3UJYHpo2eLEt3POdZq4o2XthZFJ6HAnm7D6sLuqBW/FUNwjIWOEFaWAgC/NsNM+MgR/UHlQaQJ4LZHrOB4RDfcrqR2QdEZIXslUvbK9SVKJPDOhNX48Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ekn26LWSwUBLEq5u14kTznh4j631tJTxixy+Ed+Jnb4=; b=CxW+M2qQpzt4Hsp5psC4I4hgpEX0egySPQQ51HXvHcA8xlLYgHRIGM9tY0yP3G4L3tMJsOZCqWRuHIKfLVPBvAuVLdPtFIFXhkO+YCJ6qEYBL6hvR49OX4VB261zp2MmKB8HMWYQt9ADvT/Vd3YGB7i3/eq3U3z5un56YrFV8oiQyWBc7Aese/tN7OL77FdwNbNbh/MZNUfrjn8dms0Hp/ytZqsz1+U7Q0/1R8ZvSfAeZatXzB2dyHjJwcQeLYv/738mHkBk76t3HxrWAXpZl3Dp2ZAmY67KBSt5r8SBr/LUAWYf9LmcsfKgozS3LEqrjds+/W9Na3x+6PcSWe7N8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ekn26LWSwUBLEq5u14kTznh4j631tJTxixy+Ed+Jnb4=; b=bmdxcVo3OApJ1hxieNxaZcbZCZ+gLH2Qp/ECRzsUmZgoNiLaaXgpn4uRLO2zmAtuzQakFxcpKbwgycoqtz6/zP+TXZrr4E/zugPffQHFTAn5mYsKV+kWQDhLOIQTrxcBNGPaAvYRiq5lvRIVccMoj6HoN3myeOhPye/iVZLIUnNKOOqr9oGVhUsckibSzUm/td/3BrdlK2WSwWjgW25ktEklrHt721qkHH+Gcm72jGFeYx/HPUEqh/iBxWj8Fu0Jexr3ixGQCYKXizHtl2sv4WBxsjz07xqxa5+ni3cmpiCmlKL1gPeKLm3UsNxlojc59TVVBqePKHl6j+D+n+DjEg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by CY4PR1201MB0214.namprd12.prod.outlook.com (2603:10b6:910:25::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Tue, 1 Feb 2022 07:06:51 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd%4]) with mapi id 15.20.4930.022; Tue, 1 Feb 2022 07:06:51 +0000 From: Alistair Popple To: akpm@linux-foundation.org, linux-mm@kvack.org Subject: [PATCH 2/3] mm/gup.c: Migrate device coherent pages when pinning instead of failing Date: Tue, 1 Feb 2022 18:05:56 +1100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR05CA0126.namprd05.prod.outlook.com (2603:10b6:a03:33d::11) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 426a86f4-d077-4df3-9f0c-08d9e5516b96 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0214:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r+DLAS/dnni9a1m9PRrZjrA3j/zSJEJ67AKDvqhZRPqJ3zuhU3/nNu9EHVj/l+Y0Ed4wUeKT02RXX/0qywVST4YjUCwKmdBo1FZA9P4OOR5t46PpjTKZe/b5E4y3lIKDZBAV7UrqexBADcSNSMcv8/j90BvEvz6BCB4tpxbFb6W3LQEAUcp7qXr0jA3ebObAihiPdWHPX7fukRpvfpMlasnorqyGLpIO0/gk+zEVsP/R7Hn4KX/kaIqkRUSmVFc9KH4nldOLt4BdK2v7Nh1uSfWeYuvTvoLAmwaSmeqCykRlwWW0VBSwxEQdD5gOpWUNWFmDyT5Kt57IGzO/dQHq6eyDcDCwHPkQ7o/xT+OmUCclmUqq5pQQhYvfhRO1XoCwbt48w0cS52uMQLXtLSLsEhst+yrvmCSUpwPD5rD7TXi9O1/jaVSp/I95MrXtPMTfEqgHs0PCyrRhRH9XlUVLTB4z1yYkbKZIpnbUQvEcXhQE2IGVH9wv/IrwzKqdA7gefN0VkmcWTSjMJ1eyskAHhjdWarZytj5DI+7WSebokrgfkDJwS1qeMoO7vwEd0P0czAtQX27IhybPSYYRE1me8l2eouAzf+llHKyvMR4QvhWTsQlMInrqGSZpjmKN2ybfs1QXO0hnQTvicCq2+EXV+A== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR12MB3176.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(107886003)(38100700002)(5660300002)(4326008)(7416002)(316002)(186003)(508600001)(83380400001)(8676002)(2616005)(66946007)(36756003)(2906002)(66476007)(66556008)(86362001)(6486002)(6512007)(6506007)(26005)(8936002)(20210929001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5bbQWU4v+bp0Y9FGw3+0RVlsjFNdUdKVtl9Sq95J5kaHlImgmUEPl1JjbleUMW0AiuiXhHkRbjB8YtSDv8Xh+MFWLC8Th3SJ9rYqS10zy/YvTWBNMjNSZc44jOLQrnfypXh9xOnxHcAMZmKT9Psld+1mRypXNqH7XCk7qMCaUsDvbpfk85jW/7S/MeYeXRPy5ui6QJW8aUrXN3huGf8PE9GAmT3oErb4XuiYYdhlY3iwfm8tZClmPbQNJFuqjzO6e4CXPvHUfbQHZ6e8Puszcr3TyHdFh/XvFRVXJ2Xsb2Wdq6j6S+0F+XRoyQ3/bHxPXykHRO84K5Q2J5IYCVUXz39YxQ9GuGmKk43H2azG80gQpjGKV7QQhXTmhCd2rynM0kauJVNL30x2a8aGAeIri2aCtX403mgRpYZS+vucfB89NBU7bz0mrijScBMJmrVKvaA33UFHcsaqbtqUX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FlahkRWArbjTmVNNErYsYpnAYApqR+SthKv7NvFAJ8IBqey7pmOOyeIW9x/Xnm1c0jEY1cNBiHM5hCQmBqXmdiyA= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 426a86f4-d077-4df3-9f0c-08d9e5516b96 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 07:06:51.1343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bwh8FDLklPOkM5ILv884vBjY10zS4MvIAr2QHuwaLZYVsKh006IZiEeNDlhXCYnXZoBvDxb3ipKcGmoF6ZDDfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0214 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: alex.sierra@amd.com, rcampbell@nvidia.com, willy@infradead.org, jhubbard@nvidia.com, Felix.Kuehling@amd.com, Alistair Popple , dri-devel@lists.freedesktop.org, linux-xfs@vger.kernel.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, linux-ext4@vger.kernel.org, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Currently any attempts to pin a device coherent page will fail. This is because device coherent pages need to be managed by a device driver, and pinning them would prevent a driver from migrating them off the device. However this is no reason to fail pinning of these pages. These are coherent and accessible from the CPU so can be migrated just like pinning ZONE_MOVABLE pages. So instead of failing all attempts to pin them first try migrating them out of ZONE_DEVICE. Signed-off-by: Alistair Popple Acked-by: Felix Kuehling --- mm/gup.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 10 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index f596b93..2cbef54 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1834,6 +1834,60 @@ struct page *get_dump_page(unsigned long addr) #ifdef CONFIG_MIGRATION /* + * Migrates a device coherent page back to normal memory. Caller should have a + * reference on page which will be copied to the new page if migration is + * successful or dropped on failure. + */ +static struct page *migrate_device_page(struct page *page, + unsigned int gup_flags) +{ + struct page *dpage; + struct migrate_vma args; + unsigned long src_pfn, dst_pfn = 0; + + lock_page(page); + src_pfn = migrate_pfn(page_to_pfn(page)) | MIGRATE_PFN_MIGRATE; + args.src = &src_pfn; + args.dst = &dst_pfn; + args.cpages = 1; + args.npages = 1; + args.vma = NULL; + migrate_vma_setup(&args); + if (!(src_pfn & MIGRATE_PFN_MIGRATE)) + return NULL; + + dpage = alloc_pages(GFP_USER | __GFP_NOWARN, 0); + + /* + * get/pin the new page now so we don't have to retry gup after + * migrating. We already have a reference so this should never fail. + */ + if (WARN_ON_ONCE(!try_grab_page(dpage, gup_flags))) { + __free_pages(dpage, 0); + dpage = NULL; + } + + if (dpage) { + lock_page(dpage); + dst_pfn = migrate_pfn(page_to_pfn(dpage)); + } + + migrate_vma_pages(&args); + if (src_pfn & MIGRATE_PFN_MIGRATE) + copy_highpage(dpage, page); + migrate_vma_finalize(&args); + if (dpage && !(src_pfn & MIGRATE_PFN_MIGRATE)) { + if (gup_flags & FOLL_PIN) + unpin_user_page(dpage); + else + put_page(dpage); + dpage = NULL; + } + + return dpage; +} + +/* * Check whether all pages are pinnable, if so return number of pages. If some * pages are not pinnable, migrate them, and unpin all pages. Return zero if * pages were migrated, or if some pages were not successfully isolated. @@ -1861,15 +1915,40 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, continue; prev_head = head; /* - * If we get a movable page, since we are going to be pinning - * these entries, try to move them out if possible. + * Device coherent pages are managed by a driver and should not + * be pinned indefinitely as it prevents the driver moving the + * page. So when trying to pin with FOLL_LONGTERM instead try + * migrating page out of device memory. */ if (is_dev_private_or_coherent_page(head)) { + /* + * device private pages will get faulted in during gup + * so it shouldn't be possible to see one here. + */ WARN_ON_ONCE(is_device_private_page(head)); - ret = -EFAULT; - goto unpin_pages; + WARN_ON_ONCE(PageCompound(head)); + + /* + * migration will fail if the page is pinned, so convert + * the pin on the source page to a normal reference. + */ + if (gup_flags & FOLL_PIN) { + get_page(head); + unpin_user_page(head); + } + + pages[i] = migrate_device_page(head, gup_flags); + if (!pages[i]) { + ret = -EBUSY; + break; + } + continue; } + /* + * If we get a movable page, since we are going to be pinning + * these entries, try to move them out if possible. + */ if (!is_pinnable_page(head)) { if (PageHuge(head)) { if (!isolate_huge_page(head, &movable_page_list)) @@ -1897,16 +1976,22 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, * If list is empty, and no isolation errors, means that all pages are * in the correct zone. */ - if (list_empty(&movable_page_list) && !isolation_error_count) + if (!ret && list_empty(&movable_page_list) && !isolation_error_count) return nr_pages; -unpin_pages: - if (gup_flags & FOLL_PIN) { - unpin_user_pages(pages, nr_pages); - } else { - for (i = 0; i < nr_pages; i++) + for (i = 0; i < nr_pages; i++) + if (!pages[i]) + continue; + else if (gup_flags & FOLL_PIN) + unpin_user_page(pages[i]); + else put_page(pages[i]); + + if (ret && !list_empty(&movable_page_list)) { + putback_movable_pages(&movable_page_list); + return ret; } + if (!list_empty(&movable_page_list)) { ret = migrate_pages(&movable_page_list, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, From patchwork Tue Feb 1 07:05:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 12731429 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E7B73C433F5 for ; Tue, 1 Feb 2022 07:07:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 722CB10ECA2; Tue, 1 Feb 2022 07:06:57 +0000 (UTC) Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2063.outbound.protection.outlook.com [40.107.236.63]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5759C10ECA0; Tue, 1 Feb 2022 07:06:56 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LVqnM6q4UGMyG3mVm2JVV+uKvfDsW+vfItdZq1dkjrNB0OUOfLFNM3n79QtsQooxPXMHbd3P6+Vl2MpISWHQ1mYqaqSKhlLhIyr4cpTySbWaTyl07+JVpNtbFCi1AsFJgMSNotBK710Y9N4kZxkeQWPvofDSJ1MGAbv8otXHHNLGj1wpD0nXgzgrLiEmH0Xq3bR30Hig+QGmaVyAT4SnymzDjxmOsqTZ5+2coM3rmsCGd1aBmc+2sLcSyvxco3PRwGWw2ZMuoTB+3lc8mLBg/9KK0hq72s8zYMPn7yRvfT43WaRFrx1Ab+yuJfHOMfPe05TMEaG5CN4JbPCmGWtmtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dd81HyG71D8pTfKOZda6N8+bA8ij9IGX6lSZqZkGGWE=; b=U4L4OPtRoiD3DYILyM6ilJGFzYcBBX2+DXA6KwMBaSE8Z31X+phJWroZp2jW/7+cCBtxzhgXbcDq84CVZ13lSS5jIpXkRcFt8bVhFzJdKKJrjN8B3xiehu9mAucwgY6J6ORSTjawoHPeM/IJkq8r6MZhn3GgVCptAzOo65KxFnkUehwhRzqEwHpiWFhncf2ggivqNQXZuvXqn7aGhx5kYIpNb8msxOnGv63xYFSxMbA47KNqgp84UxOrr6yw++X4XvHoX65UhjgEXyETM8kaF4rbGTqa9SdGMsMgvKdMUy8UERBkmpQ+DCXajcpqYD46/rBgn3+kPIJDf5oLL/GmIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dd81HyG71D8pTfKOZda6N8+bA8ij9IGX6lSZqZkGGWE=; b=EaEn71y7itik3sADmPHrxXRcXBVI2U0kM0YneFfYqI9CQ2MyIguUPCZtEZkfu7+3VR/38Jrzd8W6hAjh4xIZy00p8gvWrMUKmElEVy9wt9jCaIhl2VAViM4YfHaRbFgNAgmY6mk4Zn8X4s7FAniWQfHU0+Lp4WQoMqf0EdYLPvYcjXTDvU8C+qlRWpIWLIyH1hCAIeyumaCEX1yT//WWzsPN/zkQOjLKgViYcY8BkfzZ7FrCb9sDsg2cH44JRqDsK4UCXij6KMjEDo3VvfvhgsXu2n2bBpjdoQn4QK6gjBAjISvQ0i5RkmzsbPgTWPZ6HMkPaur1LSet19Xknz8lkQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) by CY4PR1201MB0214.namprd12.prod.outlook.com (2603:10b6:910:25::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Tue, 1 Feb 2022 07:06:54 +0000 Received: from BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd]) by BYAPR12MB3176.namprd12.prod.outlook.com ([fe80::48bc:2cb6:45e3:41fd%4]) with mapi id 15.20.4930.022; Tue, 1 Feb 2022 07:06:54 +0000 From: Alistair Popple To: akpm@linux-foundation.org, linux-mm@kvack.org Subject: [PATCH 3/3] tools: add hmm gup test for long term pinned device pages Date: Tue, 1 Feb 2022 18:05:57 +1100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-ClientProxiedBy: SJ0PR13CA0012.namprd13.prod.outlook.com (2603:10b6:a03:2c0::17) To BYAPR12MB3176.namprd12.prod.outlook.com (2603:10b6:a03:134::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d5b6f9a-73d4-40f4-1dea-08d9e5516d65 X-MS-TrafficTypeDiagnostic: CY4PR1201MB0214:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S/QGslVbU7mnyw/nbcWMaIf/h4SxF9AGNdH+dGhwA/nsOtn+ksQTlX0IVAsEJSs0F5bQb9TxEqAq4CRL2+DjWZa47LdG4aELRi31oXVPsa5+X7qaubIDUFydAGthsTi9BCqbqaPFwvxYu2Yt1u2lnUVh5AV+LMPQuQhWWHUGQVGBYq3pGKALcpVn4Ttota8Z93MdMcySMJsKaywNPqSLpGesWlahne3d2NNMH4F0vV+YreGzlxJyEoJeafRWNL4MGEbiR7LngbWkoHVRI5bam8kQ1tCnzx464oEBtHxXPghfbQZP7WYFsau9UmQtiG2ISLuPL7XalSgBemrqbmjQE/GOtCoofmUeDwWtay2AjrMG+/486g2Mm1u2iXQwoZWcZcFJA9+MmH+sWBk3BggOM6nEB2eLfPLqm3Uj7VVhOz5j2+OnuM0m6hryap5mu0HYIkeL9rKMyDnhnzYSnnhX1nG5yC+LuoGa5X3DOWn1ejXyHCtxrgZDCbXlu+MNpnuI+0BQxeS9v3yzJC1LtRMc8T7Z6rJGihAcUjzgfd94jg41nHR1n4JsipuZhDlszrBT+s5ZOOrSeYHrL0rYA4or1il09Xb+SXK+RyzuQXpD0AEoHvPT01nLSeExknhpZTovlJgLrrSTE2khHaCaK22u1g== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR12MB3176.namprd12.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(107886003)(38100700002)(5660300002)(4326008)(7416002)(316002)(186003)(508600001)(83380400001)(8676002)(2616005)(66946007)(36756003)(2906002)(66476007)(66556008)(86362001)(6486002)(6512007)(6506007)(26005)(8936002)(20210929001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fUfoR9CFruCVMAD/8Z27S6d6haot7/ItGPYj4CKRVx1/qtqalbbNA73FuvDe8YOqtrQjfcrvDrh1OgSKAFNZD/afvuPfST/R04vraKIUVApGdGuZ/Ffhpc+SqJJ+mn6ND/WvdoOE11b2NpdrHim7Fc3j49Am3Y+ypSgMT7/2uMHwZuMFwFZ588QUOUMntXrFWyW/0HV2sggtOY/7wCpoh6c2g1BklViDS6iE3w7JWJjZb3biBkpBvDpRXytEldBU3OoKRGxq8Bk3UmD+rhiN/5ZpD8B4oeHbZfBTNDSLw8eiWzjBiqN3AmLCrNUex9KfquR4mR2BkQkc7Q34WFHzS+NB/ltq3X/zlCzb48NsQfrInPUwpiRXyS9mG0rt9IOEVZIF47KiqeTL67RGZpBa5dSuvbG20FmWg2go5N9J5Y3SE34plXM31gUJVGqM0rtIjo0NxhVIbXSMfEYoFTyPQh077agVtIog6Mc4tQigQgHWfFSBBcd0wVsrZlj530C78qIoEC1NOq4JsFlBfjQMd82EWylpXN7nCHcfvYZ8l+RdIcZNfPY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YrRUEgkM= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4d5b6f9a-73d4-40f4-1dea-08d9e5516d65 X-MS-Exchange-CrossTenant-AuthSource: BYAPR12MB3176.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 07:06:54.1653 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0CUfUNUf2GXl32hjY+aoYxSxNYL6wq6WtUSlhYMTkt3EJMtjMgT1CPLZEpNkE8mru7QNzyq9AjcT1hX1UVPByA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR1201MB0214 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: alex.sierra@amd.com, rcampbell@nvidia.com, willy@infradead.org, jhubbard@nvidia.com, Felix.Kuehling@amd.com, Alistair Popple , dri-devel@lists.freedesktop.org, linux-xfs@vger.kernel.org, jglisse@redhat.com, amd-gfx@lists.freedesktop.org, jgg@nvidia.com, linux-ext4@vger.kernel.org, hch@lst.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Alex Sierra The intention is to test device coherent type pages that have been called through get user pages with PIN_LONGTERM flag set. These pages should get migrated back to normal system memory. Signed-off-by: Alex Sierra Signed-off-by: Alistair Popple Reviewed-by: Felix Kuehling --- tools/testing/selftests/vm/Makefile | 2 +- tools/testing/selftests/vm/hmm-tests.c | 81 +++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vm/Makefile b/tools/testing/selftests/vm/Makefile index 1607322..58c8427 100644 --- a/tools/testing/selftests/vm/Makefile +++ b/tools/testing/selftests/vm/Makefile @@ -142,7 +142,7 @@ $(OUTPUT)/mlock-random-test $(OUTPUT)/memfd_secret: LDLIBS += -lcap $(OUTPUT)/gup_test: ../../../../mm/gup_test.h -$(OUTPUT)/hmm-tests: local_config.h +$(OUTPUT)/hmm-tests: local_config.h ../../../../mm/gup_test.h # HMM_EXTRA_LIBS may get set in local_config.mk, or it may be left empty. $(OUTPUT)/hmm-tests: LDLIBS += $(HMM_EXTRA_LIBS) diff --git a/tools/testing/selftests/vm/hmm-tests.c b/tools/testing/selftests/vm/hmm-tests.c index 84ec8c4..11b83a8 100644 --- a/tools/testing/selftests/vm/hmm-tests.c +++ b/tools/testing/selftests/vm/hmm-tests.c @@ -36,6 +36,7 @@ * in the usual include/uapi/... directory. */ #include "../../../../lib/test_hmm_uapi.h" +#include "../../../../mm/gup_test.h" struct hmm_buffer { void *ptr; @@ -60,6 +61,8 @@ enum { #define NTIMES 10 #define ALIGN(x, a) (((x) + (a - 1)) & (~((a) - 1))) +/* Just the flags we need, copied from mm.h: */ +#define FOLL_WRITE 0x01 /* check pte is writable */ FIXTURE(hmm) { @@ -1766,4 +1769,82 @@ TEST_F(hmm, exclusive_cow) hmm_buffer_free(buffer); } +/* + * Test get user device pages through gup_test. Setting PIN_LONGTERM flag. + * This should trigger a migration back to system memory for both, private + * and coherent type pages. + * This test makes use of gup_test module. Make sure GUP_TEST_CONFIG is added + * to your configuration before you run it. + */ +TEST_F(hmm, hmm_gup_test) +{ + struct hmm_buffer *buffer; + struct gup_test gup; + int gup_fd; + unsigned long npages; + unsigned long size; + unsigned long i; + int *ptr; + int ret; + unsigned char *m; + + gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (gup_fd == -1) + SKIP(return, "Skipping test, could not find gup_test driver"); + + npages = 4; + ASSERT_NE(npages, 0); + size = npages << self->page_shift; + + buffer = malloc(sizeof(*buffer)); + ASSERT_NE(buffer, NULL); + + buffer->fd = -1; + buffer->size = size; + buffer->mirror = malloc(size); + ASSERT_NE(buffer->mirror, NULL); + + buffer->ptr = mmap(NULL, size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, + buffer->fd, 0); + ASSERT_NE(buffer->ptr, MAP_FAILED); + + /* Initialize buffer in system memory. */ + for (i = 0, ptr = buffer->ptr; i < size / sizeof(*ptr); ++i) + ptr[i] = i; + + /* Migrate memory to device. */ + ret = hmm_migrate_sys_to_dev(self->fd, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + /* Check what the device read. */ + for (i = 0, ptr = buffer->mirror; i < size / sizeof(*ptr); ++i) + ASSERT_EQ(ptr[i], i); + + gup.nr_pages_per_call = npages; + gup.addr = (unsigned long)buffer->ptr; + gup.gup_flags = FOLL_WRITE; + gup.size = size; + /* + * Calling gup_test ioctl. It will try to PIN_LONGTERM these device pages + * causing a migration back to system memory for both, private and coherent + * type pages. + */ + if (ioctl(gup_fd, PIN_LONGTERM_BENCHMARK, &gup)) { + perror("ioctl on PIN_LONGTERM_BENCHMARK\n"); + goto out_test; + } + + /* Take snapshot to make sure pages have been migrated to sys memory */ + ret = hmm_dmirror_cmd(self->fd, HMM_DMIRROR_SNAPSHOT, buffer, npages); + ASSERT_EQ(ret, 0); + ASSERT_EQ(buffer->cpages, npages); + m = buffer->mirror; + for (i = 0; i < npages; i++) + ASSERT_EQ(m[i], HMM_DMIRROR_PROT_WRITE); +out_test: + close(gup_fd); + hmm_buffer_free(buffer); +} TEST_HARNESS_MAIN