Received: by 10.223.185.116 with SMTP id b49csp1009641wrg; Fri, 16 Feb 2018 10:44:51 -0800 (PST) X-Google-Smtp-Source: AH8x227GfTz5xvXF/I9ldVuPiI/BOT3q5VWXtcjnEAkyXYlN2+nEvmpxDnBXMnGq92sFglGXMpHJ X-Received: by 10.98.46.70 with SMTP id u67mr6956069pfu.16.1518806691570; Fri, 16 Feb 2018 10:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518806691; cv=none; d=google.com; s=arc-20160816; b=issxa50qSw392VxV3WJRkn2KU1HP0kq3RraWrquu+ir4SvOqPa7ylUO/RVxQW8jWnE AcBNznre8yiovwbFG+NhqdZ/exS8fNd8+EOoqQWTIK+5W9q9XgGshJVKvJ/Tm7v3g/nS DUyKUAP10gzMaC9lly1aSuDmzIGElsFhjvcM/kALD9Nb/3InhmVnfNkcr+AGpdgm33wL v0eq4TZQP85uE0UcbAx3buM053W0S48ae6tK4NjXXQIr5ckovWz7b5x2i/T8BAj6r7RN cJCg1WaYJbt1yxSClnG839P9fs6dFExF44fdW6e7vnwj3ExH/2AsNvXG9kvYEF0rEJuR sYjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=XctQ1Ly/OtZ8AEe4CvEt5RTjeDxc/RE6ncOwixBIXfI=; b=Yc47+ufQYw46by393S+0Qeoqhy3iTrS6CGi31QfkHbHWUTQVqDP7rtfrfG5fJTl8xf v8adZ+Y6Mt5Jp1MoVoDVF5O+REggv2+yxKMfk9vtaVy/VegZl+U9pfIW+JLvHvG5B4L8 b4Ur0n6xsYhiisHUEMcQjZaJqbo07UAt/C+XC9ogOAAH97kxDQQhAC/NhZjnNCpEzQ9b WVpT3EmKCpHapbDM7keBNqMmPQPw2thqUnuK4kroghd31R6U3eeCFbHP8vcTk8bo/fNM FcgoigyARsZw+8W5GYGTvy8NVllueAJGJN7mfDUT4z0afYKmpiq7HkXvxA1MY3kYt/PW sQkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=JdE/s8NE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l59-v6si1818722plb.391.2018.02.16.10.44.36; Fri, 16 Feb 2018 10:44:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=JdE/s8NE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751380AbeBPEE3 (ORCPT + 99 others); Thu, 15 Feb 2018 23:04:29 -0500 Received: from mail-by2nam03on0057.outbound.protection.outlook.com ([104.47.42.57]:34940 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751342AbeBPEE1 (ORCPT ); Thu, 15 Feb 2018 23:04:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=XctQ1Ly/OtZ8AEe4CvEt5RTjeDxc/RE6ncOwixBIXfI=; b=JdE/s8NEtHbWY/4qu0owECuH1ZlVfbDW6S52UNbxRHwG6pCauOMxLHPO8LJY6lBA1OnJGfPDiibZ5X+ZlnkFKKDtDqj883yop+qwnIooW/PeCJwHk6nwP89jJ+njwwZeX2lKFxoASM7GCbgoTjSVA4DaKQwtB/qiDjHo6gBXvwI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Linu.Cherian@cavium.com; Received: from localhost (111.93.218.67) by DM5PR07MB3435.namprd07.prod.outlook.com (10.164.153.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.506.18; Fri, 16 Feb 2018 04:04:22 +0000 Received: by localhost (sSMTP sendmail emulation); Fri, 16 Feb 2018 09:34:04 +0530 Date: Fri, 16 Feb 2018 09:34:04 +0530 From: Linu Cherian To: Alex Williamson Cc: Linu Cherian , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sunil.Goutham@cavium.com Subject: Re: Handling active DMA during a VFIO application crash Message-ID: <20180216040404.GA12253@virtx40> References: <20180215110406.GA15219@virtx40> <20180215092109.51dc7a1a@w520.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180215092109.51dc7a1a@w520.home> User-Agent: Mutt/1.5.21 (2010-09-15) X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0083.INDPRD01.PROD.OUTLOOK.COM (10.174.208.151) To DM5PR07MB3435.namprd07.prod.outlook.com (10.164.153.14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: eb05fded-7bb3-492a-4230-08d574f25d78 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:DM5PR07MB3435; X-Microsoft-Exchange-Diagnostics: 1;DM5PR07MB3435;3:U9cefFhZsRUUkmNbF8tbisDJYf5K+z81vnHmIlpbcya3f3G1yJ0WGFHGgQLfbYto5GQaDSLS99LRvoXLUJ7bQs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B1IATMVnzdDZJjw1UZPCjEH9X0eE56d4f2FioqTMqhl5W5uMNt1V+gasDwxrlOQCBcqYYK2wuB7Fcyg3pyFn9Og3HSA1M2crI+qDa2Edq5h1I3IXqT++RUz4ysc4cxz8VRyiZBPTw6JkmHPwxnrm5rLfILQXlM6ueFAcnXRiwYm+Xd0Y740kLqYFNUDY1aDMNWEGwlLlpBIIX79jBHslTK8bSuCB3SmqL3m3hpAPi/yOWZEFsqdu+n;4:nOkH3AGMhMoVkCo6D0TtLbuNvrOjnfuML6mL4x7couEEdhrzT6bmQfLbc4mlE5xwIhhCvA4/5HWs4+H7Ng7lXujaZAkgDcs+796Mo5U0e084RYFMi76ZoW1P5w9NemGwHFPzV5QVLg6hhq9ctGfOR/EBvpKw3Ckg/9pY+93YP/9qeVdAquQPVghUBxVetgPHS4dV2shYBvpqoGxQUAJYxDdCV3S9bE1n5lUWm/uR4mQBUiUmzBuTkyeJpHJJIh0RuYLQJ79SY5mOqfR53VheeBF5lcvfOiyuRmNsJPeL3jPWocJO41VUM+46VVDlqLFu X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(85827821059158); X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(944501161)(93006095)(93001095)(6041288)(20161123560045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(6072148)(201708071742011);SRVR:DM5PR07MB3435;BCL:0;PCL:0;RULEID:;SRVR:DM5PR07MB3435; X-Forefront-PRVS: 0585417D7B X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6069001)(39860400002)(39380400002)(366004)(376002)(346002)(396003)(189003)(199004)(51914003)(2906002)(107886003)(4326008)(39060400002)(33656002)(81166006)(81156014)(8936002)(106356001)(105586002)(50466002)(68736007)(6916009)(33716001)(47776003)(83506002)(5660300001)(8676002)(52116002)(66066001)(2950100002)(6246003)(16586007)(316002)(42186006)(58126008)(186003)(23726003)(72206003)(478600001)(229853002)(86362001)(575784001)(26005)(305945005)(7736002)(76176011)(33896004)(386003)(1076002)(9686003)(97736004)(59450400001)(53936002)(3846002)(6116002)(122856001)(18370500001);DIR:OUT;SFP:1101;SCL:1;SRVR:DM5PR07MB3435;H:localhost;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;DM5PR07MB3435;23:JgdJCjpYBlLBSVGfjNamdK9q7aKrv+udptZuYrADB?= =?us-ascii?Q?m0IZ4n32ayFo060MGZ9i9V896esexVYSajjxk8amFvGnUM3U9VzB4PnzCMz1?= =?us-ascii?Q?m+SpXU9nHl6PAOtG4zMZw7wkga/ashJrb++BbBeEnH4p0R5g3oV9gVVpT+6/?= =?us-ascii?Q?yGwBoFa1uw21c81JkZ8+eSNP0Uqm3T0GKl7LCKzMwpVqt5/MPum0x/92C5RY?= =?us-ascii?Q?q076wHSeljJF9e0xuAcgI/bgranAwA3aig/mw7JcQiiMjy6YBRWbBPWNezBD?= =?us-ascii?Q?ccxZu01yBr/k7n6b9YLDYKWXS25sxfE5RIwL+EOm1+W4p3qX4lL9ugc4L/cF?= =?us-ascii?Q?u7AKuRm6RpFKf9yCEunPHYRBptXuwxZn4Q4tTZm20C8ceGOuYfFwO3KDOvym?= =?us-ascii?Q?xVcuX3h1kIgZslFMjGXor2OnaPTkl26awWjbL490yiFIHnDFzhc6spSqnIvd?= =?us-ascii?Q?K0se6wAdNHlgYNI8hbySypCLxFwKf3jx8S6w6KXvRjbAb5VCozPf+6wgHLY8?= =?us-ascii?Q?rc4zDjwUX/kI48mAlTkZK3uAFAZW5y4ekUDJiuZjBAtE2Xhr26WY/+2ksMzg?= =?us-ascii?Q?H6+tWBBaxP+qBAgE/H3YHj5Fjm0NOhKNkkpFm/Zb6lBvfOxrk8udYm3BdI+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pc0V5Sr7CS60dAJ9xdoAQhPdYsgVwiAhpuPS67xdpvMXOTSMTAgqbNnNNGVsgTL8b36cLbeBhY8yurvMIQ303r/lVRqeD3neOpxpr8RUgEATj3DEePmF4sNGwqyT7iLZAQPj6Hc6KLIr+AD+dqU07cBjOnNFGh+gDJ8zsJ3IjxtjZcMlndjgWqRYG/x6qQiE6adk=;5:ZYBoIknpoCc6b922Qn0wrRz+juUG9zebxbjoArQzqMO2Q+HZxv1RdnpuewiGENy/NrDpydm/gUdVTEMq6YcvA3xWCs2jGdVyxV0/i7Herqwlv5+F1QLcrSWVHRbZcXb6QMRSYDjfcPg3co3Ufxd8PdbDU8qWt14ixFyu/6qn294=;24:0rCr5cioMSRrCnepV3xItwsvZid2xsLCrljcEzv7B9vsHoOeRkxYv9sgUHtGjSSuG4oVqYeuaebrs8YJeDzawO0Y/hTgTY+LSZzDEZOk9Hk=;7:wqhyKX3V+ixJBXY1GCUmCGpSO2VOL0CZLY4turSq7bRiqfQmhIDnjXvcZEoXjle+f+uka0VtayoiAwSZGSp0b7u6QUZgH4PDKaggnAzAbzxxti6RChGkzoCM91VW1wUj/0GG2rLoYG/ygf6Gd/lqE6hDYu35KdNshttBDR7ZKhqjSrISRNFqw47Bvwg7BHKPpllYhEDz+BA0t/U6aEMVeVntyJikD/s5l0238SdeeeJPptVrjui2UUJf8Ec37tvG SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Feb 2018 04:04:22.4987 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eb05fded-7bb3-492a-4230-08d574f25d78 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR07MB3435 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Alex, On Thu Feb 15, 2018 at 09:21:09AM -0700, Alex Williamson wrote: > On Thu, 15 Feb 2018 16:34:06 +0530 > Linu Cherian wrote: > > > Hi, > > > > Was exploring the implications of an application crash while DMA > > is active from a vfio PCI device; the DMA being configured and > > started by the application using vfio APIs. > > > > The expectation is that, DMA is stopped/reset before we tear down the IOMMU mappings > > and finally free the mmapped pages(on which DMA is happening). > > > > From the below stack trace(with dump_stack in vfio_pci_release), > > [ 201.564273] [] vfio_pci_release+0x80/0x458 > > [ 201.564276] [] vfio_device_fops_release+0x2c/0x50 > > [ 201.564279] [] __fput+0x9c/0x218 > > [ 201.564283] [] ____fput+0x20/0x30 > > [ 201.564286] [] task_work_run+0xa0/0xc8 > > [ 201.564289] [] do_exit+0x2bc/0x9c8 > > [ 201.564293] [] do_group_exit+0x3c/0xa8 > > [ 201.564296] [] get_signal+0x3e4/0x538 > > [ 201.564299] [] do_signal+0x70/0x660 > > [ 201.564302] [] do_notify_resume+0xe0/0x120 > > > > > > PCI device is disabled/reset from vfio_pci_release invoked as part of > > device fd release. The fd releases are in turn invoked from exit_files > > and exit_task_work. > > > > But exit_mm, gets called before exit_files/exit_task_work in do_exit. > > > > Assuming all pages allocated/mmaped to a process gets freed in exit_mm, > > is there is a possibility that user pages configured for DMA can get freed > > to kernel before the vfio device is stopped/reset ? > > Pages mapped through the IOMMU are still pinned, so they have an > elevated reference count and I believe therefore cannot "get freed to > kernel". Nothing should therefore be able to allocate those pages > until the container is released, which happens even after the device is > released. Thanks, > > Alex Thanks for the clarification. I will dig through the code on this. -- Linu cherian