Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp521327imu; Thu, 20 Dec 2018 00:31:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/Wkb1NuGLKH2fKZzLpELSFXl3e5oFQRBV0FczZT8O7KRaMCpQxEEoO2SM0M0NW+jdi3JEEf X-Received: by 2002:a17:902:2e01:: with SMTP id q1mr22560728plb.97.1545294693026; Thu, 20 Dec 2018 00:31:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545294692; cv=none; d=google.com; s=arc-20160816; b=DJLXUjvR2HAnOBntTalfxarpctkiGVVhWVTXTTTzTSRWJNTr6/WhCVApiZsoGtjVSK 7ifJUGPRcAPlGI42jHdLxHb4i6OzFmaKGlzVQHrB9aM1GtXDXuDcW0dwu91tYGS71OMx QCMSWpOZ1KK5aJJNdPTgoye8W0KfuHO9fR5+Byx1vtQMTeSAy6903SnUS5AjYhsee1NV tIwyFWxJnQPwSqwZjdUVYDx0RP6332YGK9NPRsfpPiL0HWVOd0nEMderlPMfc46i63f+ GiiN3z0uht1KZHnUPTo8+UYEG5dVcTsIFHtSKbXsMIJuRmKK3vahcHQBQNmA7vkzvqxf f3UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=qASZMLJNzwJn1o9jfxOPB9obKhqFsswON/UkTzYvgZk=; b=XGMdHi2PPbNuHuhYG8gJU4lHfN88Qp/x9VDkRYU+dbHDbhX7fENV8pOOhVHwK+uGFV bVCiO7yYuSeQr5LyP6rpFcIJiFWMlGZ675Dg/DJQlgZS6TTWz1ic9M1QFj6ZN8byde4K PHiZL6vbyV0OnfDAWuwXPZPRw8tCOb4tetbZF9bMS/8N3K42gSu6huHOjB0cYSPGulmx qt+47EkfWAlNg4anz+Lub76XDCjqvY/iVG7krdI2kxzTY8CVOsexM0lM5+8xl1vK6ZIB 3i9Qj0rC3k0o9Xh9WHZRLDRyFig/MLWm29ZHpJJRkBFULpP7pf+ssnsjTSZOKiQesp6F fKfw== ARC-Authentication-Results: i=1; mx.google.com; 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 e189si4846296pfc.202.2018.12.20.00.31.17; Thu, 20 Dec 2018 00:31:32 -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; 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 S1731115AbeLTIZG (ORCPT + 99 others); Thu, 20 Dec 2018 03:25:06 -0500 Received: from ozlabs.ru ([107.173.13.209]:54908 "EHLO ozlabs.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731097AbeLTIZD (ORCPT ); Thu, 20 Dec 2018 03:25:03 -0500 Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 40C26AE80490; Thu, 20 Dec 2018 03:24:58 -0500 (EST) From: Alexey Kardashevskiy To: linuxppc-dev@lists.ozlabs.org Cc: Alexey Kardashevskiy , David Gibson , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, Alistair Popple , Reza Arbab , Sam Bobroff , Piotr Jaroszynski , =?UTF-8?q?Leonardo=20Augusto=20Guimar=C3=A3es=20Garcia?= , Jose Ricardo Ziviani , Daniel Henrique Barboza , Alex Williamson , Paul Mackerras , linux-kernel@vger.kernel.org, Christoph Hellwig Subject: [PATCH kernel v7 18/20] vfio_pci: Allow mapping extra regions Date: Thu, 20 Dec 2018 19:23:48 +1100 Message-Id: <20181220082350.58113-19-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181220082350.58113-1-aik@ozlabs.ru> References: <20181220082350.58113-1-aik@ozlabs.ru> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So far we only allowed mapping of MMIO BARs to the userspace. However there are GPUs with on-board coherent RAM accessible via side channels which we also want to map to the userspace. The first client for this is NVIDIA V100 GPU with NVLink2 direct links to a POWER9 NPU-enabled CPU; such GPUs have 16GB RAM which is coherently mapped to the system address space, we are going to export these as an extra PCI region. We already support extra PCI regions and this adds support for mapping them to the userspace. Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson Acked-by: Alex Williamson --- Changes: v2: * reverted one of mistakenly removed error checks --- drivers/vfio/pci/vfio_pci_private.h | 3 +++ drivers/vfio/pci/vfio_pci.c | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_private.h b/drivers/vfio/pci/vfio_pci_private.h index cde3b5d..86aab05 100644 --- a/drivers/vfio/pci/vfio_pci_private.h +++ b/drivers/vfio/pci/vfio_pci_private.h @@ -59,6 +59,9 @@ struct vfio_pci_regops { size_t count, loff_t *ppos, bool iswrite); void (*release)(struct vfio_pci_device *vdev, struct vfio_pci_region *region); + int (*mmap)(struct vfio_pci_device *vdev, + struct vfio_pci_region *region, + struct vm_area_struct *vma); }; struct vfio_pci_region { diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index fef5002..4a6f7c0 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c @@ -1130,6 +1130,15 @@ static int vfio_pci_mmap(void *device_data, struct vm_area_struct *vma) return -EINVAL; if ((vma->vm_flags & VM_SHARED) == 0) return -EINVAL; + if (index >= VFIO_PCI_NUM_REGIONS) { + int regnum = index - VFIO_PCI_NUM_REGIONS; + struct vfio_pci_region *region = vdev->region + regnum; + + if (region && region->ops && region->ops->mmap && + (region->flags & VFIO_REGION_INFO_FLAG_MMAP)) + return region->ops->mmap(vdev, region, vma); + return -EINVAL; + } if (index >= VFIO_PCI_ROM_REGION_INDEX) return -EINVAL; if (!vdev->bar_mmap_supported[index]) -- 2.17.1