Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2084900pxb; Mon, 8 Mar 2021 13:49:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxTocAGMkLdzTJjCRmbvLeASET6vZDqyfiPdsdKxs8+UZE79rxT4c52hapm21F5f5LKTyV X-Received: by 2002:a05:6402:50c8:: with SMTP id h8mr622102edb.360.1615240176167; Mon, 08 Mar 2021 13:49:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615240176; cv=none; d=google.com; s=arc-20160816; b=SMwlW5awIwri7jMETjowE65zx3/azbolhf057LgpnxHueSSMpT10vYFpJHObNlIAgE 3g6KaPHNd58cQUgUOByM8GtYAYjiVUB1JX2AadreGZpyMiut58Z3a7znxk5WbbawjeM3 5WPNtk1qR0i9n1Yr6/50fYGNdH1r0jN3fsuAPo3LzrBaTAHJ0fR0kwyWXQQ142/nvlWK vPwAnB51cLg5O8gZmuRehxDA4FAObSF3yKqsUfZVBXHlI9iETjx6GEtle8B/3MnOg+Vc XchohIaMKr9ijSm+cQzAK8QBk6IUU2CBfIIk+K171JrgRO8qxly8KXAs12FR7c5e/fpp t7Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:message-id:date:cc:to:from:subject:dkim-signature; bh=D+es/eWhmxxz29JK+WvmP/Ck2/6vYOLc/3sWGVtLCbc=; b=ZheS1jttpyLsDJRMkFpQpfBdAdah1VajUxvT8bC/WD13TfTbu2BjlLSccspOZ00WCB +XSdM6QmKlBcmVXMvFydiKAHfwcdir0RNve85pliJyT/mvyB45KIIuPBZiDHIwJzf2Dw 0+ug82RlnnA/jz4FMp8UPccxd0ZmOpmpyydY1mffJ+xnliE7hg7DwkrmuLKCb9vpKo89 bx+MH/dTkh8F5kbOBo1IC+Cd7YLOrZLxzxQSVbTCYSJBV8ruBittOlsM3E6INmwuWkKg Ks4zcckIoJt5GWW7dtNFQxYMQCoGtW6Q3kkI1xBqUtkxt7wGnozh5awhf1NwsVPuvf/S izog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RFgXid9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x21si7773210eju.471.2021.03.08.13.49.12; Mon, 08 Mar 2021 13:49:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RFgXid9+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231334AbhCHVsS (ORCPT + 99 others); Mon, 8 Mar 2021 16:48:18 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56975 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230343AbhCHVrx (ORCPT ); Mon, 8 Mar 2021 16:47:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615240072; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=D+es/eWhmxxz29JK+WvmP/Ck2/6vYOLc/3sWGVtLCbc=; b=RFgXid9+IxNYras43sTW+ZLPZD7AskI0UkHzUclZIRk9RuxgTNb6oIQ+vGwMHTm3qsfGrK tW7D+cKcvSb/fhZESF6K80UW68sNiWWBEwZ8T/gCSBfsJX+S9m7dwmBAJXg/H5tZhmppdw 1NjhZfe65sYslA30mZlvFe+Rx68n+Pg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-242-5e4ZJSszOj6VeyxB2DsjeQ-1; Mon, 08 Mar 2021 16:47:24 -0500 X-MC-Unique: 5e4ZJSszOj6VeyxB2DsjeQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 35A241005D45; Mon, 8 Mar 2021 21:47:23 +0000 (UTC) Received: from gimli.home (ovpn-112-255.phx2.redhat.com [10.3.112.255]) by smtp.corp.redhat.com (Postfix) with ESMTP id C66601037E80; Mon, 8 Mar 2021 21:47:16 +0000 (UTC) Subject: [PATCH v1 00/14] vfio: Device memory DMA mapping improvements From: Alex Williamson To: alex.williamson@redhat.com Cc: cohuck@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jgg@nvidia.com, peterx@redhat.com Date: Mon, 08 Mar 2021 14:47:16 -0700 Message-ID: <161523878883.3480.12103845207889888280.stgit@gimli.home> User-Agent: StGit/0.21-2-g8ef5 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The primary goal of this series is to better manage device memory mappings, both with a much simplified scheme to zap CPU mappings of device memory using unmap_mapping_range() and also to restrict IOMMU mappings of PFNMAPs to vfio device memory and drop those mappings on device release. This series updates vfio-pci to include the necessary vma-to-pfn interface, allowing the type1 IOMMU backend to recognize vfio device memory. If other bus drivers support peer-to-peer DMA, they should be updated with a similar callback and trigger the device notifier on release. RFC->v1: - Fix some incorrect ERR handling - Fix use of vm_pgoff to be compatible with unmap_mapping_range() - Add vma-to-pfn interfaces - Generic device-from-vma handling - pfnmap obj directly maps back to vfio_dma obj - No bypass for strict MMIO handling - Batch PFNMAP handling - Follow-on patches to cleanup "extern" usage and bare unsigned Works in my environment, further testing always appreciated. This will need to be merged with a solution for concurrent fault handling. Thanks especially to Jason Gunthorpe for previous reviews and suggestions. Thanks, Alex RFC:https://lore.kernel.org/kvm/161401167013.16443.8389863523766611711.stgit@gimli.home/ --- Alex Williamson (14): vfio: Create vfio_fs_type with inode per device vfio: Update vfio_add_group_dev() API vfio: Export unmap_mapping_range() wrapper vfio/pci: Use vfio_device_unmap_mapping_range() vfio: Create a vfio_device from vma lookup vfio: Add vma to pfn callback vfio: Add a device notifier interface vfio/pci: Notify on device release vfio/type1: Refactor pfn_list clearing vfio/type1: Pass iommu and dma objects through to vaddr_get_pfn vfio/type1: Register device notifier vfio/type1: Support batching of device mappings vfio: Remove extern from declarations across vfio vfio: Cleanup use of bare unsigned Documentation/driver-api/vfio-mediated-device.rst | 19 +- Documentation/driver-api/vfio.rst | 8 - drivers/s390/cio/vfio_ccw_cp.h | 13 + drivers/s390/cio/vfio_ccw_private.h | 14 + drivers/s390/crypto/vfio_ap_private.h | 2 drivers/vfio/Kconfig | 1 drivers/vfio/fsl-mc/vfio_fsl_mc.c | 6 - drivers/vfio/fsl-mc/vfio_fsl_mc_private.h | 7 - drivers/vfio/mdev/vfio_mdev.c | 5 drivers/vfio/pci/vfio_pci.c | 229 ++++----------------- drivers/vfio/pci/vfio_pci_intrs.c | 42 ++-- drivers/vfio/pci/vfio_pci_private.h | 69 +++--- drivers/vfio/platform/vfio_platform_common.c | 7 - drivers/vfio/platform/vfio_platform_irq.c | 21 +- drivers/vfio/platform/vfio_platform_private.h | 31 +-- drivers/vfio/vfio.c | 154 ++++++++++++-- drivers/vfio/vfio_iommu_type1.c | 234 +++++++++++++++------ include/linux/vfio.h | 129 ++++++------ 18 files changed, 543 insertions(+), 448 deletions(-)