Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7195643pxb; Thu, 18 Feb 2021 04:13:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJxGQrXou9ZF99oJ3BFqla+5/CaY3u165zcPUw1AHgKV4p+sZ1sXQnbwR14wZYg01FvnoTKR X-Received: by 2002:aa7:ce15:: with SMTP id d21mr3864849edv.206.1613650391626; Thu, 18 Feb 2021 04:13:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613650391; cv=none; d=google.com; s=arc-20160816; b=O/8z8SDo/TijpRHN+WnB43hH17jimmOONIjloxG6/iH5G3Qw/oBaTrtpn8qD8ZmjMn xCRrCfJRZXgpm4MOdPvwlfO5gt2TU704MvTBrUXuda6nM0qe820N/z8nJiO6ANXlLrf7 2Z1qscbIbc4y4M40zDSwpIUy6gNgvx2vGoQTT68kX139Tl6T8BhcpEZoqhO6/m2vPb0a slhsWOECGeL0F68tr8Wipe4o+tjMk0z6yWzWEoHJts0hwsgFxnD45DGgNR9WWWzDYQ7A pC2qt8sxxt0b/Ilog5o+y7sqlOsEPHnDeOM9jLaTgyvOCpLVHJdvDh/UVoFRNgyPuY+i BUMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=5YzZh5U+rbYbOtGMG9HlMExjvqqvM90VpKN3eXzL/+k=; b=MRzKoihnsUDROVSDP3tYCHhD8efVXKV3GRXCT7spOa44cmF/LrSVuEQY+inZ8xHqLN 9F6hhuR4nv0UFeRV3bdX8mlKpKyfsGvrDT86BKVKaRoJ0GfKhPavMQl1XJNPce1TV3JS BCcW0YRMPBYXy7Teemh+6/ioZ5aLvnDY1Kjixw+dBq4c4LKegT2TrZtyFiTocNcQnKW4 NjJWVLL0EDeWziJWCPMsXKyYuqXG9TJssMOpJvOTgsiHMJxgthHELsyy3f3yaiIJcZ+f dQBPkl7uDMjXieVnt9YdHULOqvNjoHJBYuE3+/Rbz47UlGMY8arqTfyJ33cIU9/hpDD0 4+UA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id jz7si3546212ejb.476.2021.02.18.04.12.47; Thu, 18 Feb 2021 04:13:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232470AbhBRMK1 convert rfc822-to-8bit (ORCPT + 99 others); Thu, 18 Feb 2021 07:10:27 -0500 Received: from szxga03-in.huawei.com ([45.249.212.189]:2903 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231194AbhBRKiE (ORCPT ); Thu, 18 Feb 2021 05:38:04 -0500 Received: from DGGEMM403-HUB.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4DhB0y0GwRz5Snm; Thu, 18 Feb 2021 18:34:58 +0800 (CST) Received: from dggema765-chm.china.huawei.com (10.1.198.207) by DGGEMM403-HUB.china.huawei.com (10.3.20.211) with Microsoft SMTP Server (TLS) id 14.3.498.0; Thu, 18 Feb 2021 18:36:52 +0800 Received: from lhreml710-chm.china.huawei.com (10.201.108.61) by dggema765-chm.china.huawei.com (10.1.198.207) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2106.2; Thu, 18 Feb 2021 18:36:52 +0800 Received: from lhreml710-chm.china.huawei.com ([169.254.81.184]) by lhreml710-chm.china.huawei.com ([169.254.81.184]) with mapi id 15.01.2106.006; Thu, 18 Feb 2021 10:36:49 +0000 From: Shameerali Kolothum Thodi To: Eric Auger , "eric.auger.pro@gmail.com" , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , "kvm@vger.kernel.org" , "kvmarm@lists.cs.columbia.edu" , "will@kernel.org" , "joro@8bytes.org" , "maz@kernel.org" , "robin.murphy@arm.com" , "alex.williamson@redhat.com" CC: "jean-philippe@linaro.org" , "zhangfei.gao@linaro.org" , "zhangfei.gao@gmail.com" , "vivek.gautam@arm.com" , "jacob.jun.pan@linux.intel.com" , "yi.l.liu@intel.com" , "tn@semihalf.com" , "nicoleotsuka@gmail.com" , yuzenghui , "Zengtao (B)" , "linuxarm@openeuler.org" Subject: RE: [PATCH v11 12/13] vfio/pci: Register a DMA fault response region Thread-Topic: [PATCH v11 12/13] vfio/pci: Register a DMA fault response region Thread-Index: AQHWvAgGhwjLBSYC0UyC6ARc2a6ugaoeJVMQgEAkCaA= Date: Thu, 18 Feb 2021 10:36:49 +0000 Message-ID: <6c00965615844f03954faecb6fcb9294@huawei.com> References: <20201116110030.32335-1-eric.auger@redhat.com> <20201116110030.32335-13-eric.auger@redhat.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.47.95.60] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Eric, > > -----Original Message----- > > From: Eric Auger [mailto:eric.auger@redhat.com] > > Sent: 16 November 2020 11:00 > > To: eric.auger.pro@gmail.com; eric.auger@redhat.com; > > iommu@lists.linux-foundation.org; linux-kernel@vger.kernel.org; > > kvm@vger.kernel.org; kvmarm@lists.cs.columbia.edu; will@kernel.org; > > joro@8bytes.org; maz@kernel.org; robin.murphy@arm.com; > > alex.williamson@redhat.com > > Cc: jean-philippe@linaro.org; zhangfei.gao@linaro.org; > > zhangfei.gao@gmail.com; vivek.gautam@arm.com; Shameerali Kolothum > > Thodi ; > > jacob.jun.pan@linux.intel.com; yi.l.liu@intel.com; tn@semihalf.com; > > nicoleotsuka@gmail.com; yuzenghui > > Subject: [PATCH v11 12/13] vfio/pci: Register a DMA fault response > > region > > > > In preparation for vSVA, let's register a DMA fault response region, > > where the userspace will push the page responses and increment the > > head of the buffer. The kernel will pop those responses and inject > > them on iommu side. > > > > Signed-off-by: Eric Auger > > --- > > drivers/vfio/pci/vfio_pci.c | 114 +++++++++++++++++++++++++--- > > drivers/vfio/pci/vfio_pci_private.h | 5 ++ > > drivers/vfio/pci/vfio_pci_rdwr.c | 39 ++++++++++ > > include/uapi/linux/vfio.h | 32 ++++++++ > > 4 files changed, 181 insertions(+), 9 deletions(-) > > > > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c > > index 65a83fd0e8c0..e9a904ce3f0d 100644 > > --- a/drivers/vfio/pci/vfio_pci.c > > +++ b/drivers/vfio/pci/vfio_pci.c > > @@ -318,9 +318,20 @@ static void vfio_pci_dma_fault_release(struct > > vfio_pci_device *vdev, > > kfree(vdev->fault_pages); > > } > > > > -static int vfio_pci_dma_fault_mmap(struct vfio_pci_device *vdev, > > - struct vfio_pci_region *region, > > - struct vm_area_struct *vma) > > +static void > > +vfio_pci_dma_fault_response_release(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region) { > > + if (vdev->dma_fault_response_wq) > > + destroy_workqueue(vdev->dma_fault_response_wq); > > + kfree(vdev->fault_response_pages); > > + vdev->fault_response_pages = NULL; > > +} > > + > > +static int __vfio_pci_dma_fault_mmap(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region, > > + struct vm_area_struct *vma, > > + u8 *pages) > > { > > u64 phys_len, req_len, pgoff, req_start; > > unsigned long long addr; > > @@ -333,14 +344,14 @@ static int vfio_pci_dma_fault_mmap(struct > > vfio_pci_device *vdev, > > ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1); > > req_start = pgoff << PAGE_SHIFT; > > > > - /* only the second page of the producer fault region is mmappable */ > > + /* only the second page of the fault region is mmappable */ > > if (req_start < PAGE_SIZE) > > return -EINVAL; > > > > if (req_start + req_len > phys_len) > > return -EINVAL; > > > > - addr = virt_to_phys(vdev->fault_pages); > > + addr = virt_to_phys(pages); > > vma->vm_private_data = vdev; > > vma->vm_pgoff = (addr >> PAGE_SHIFT) + pgoff; > > > > @@ -349,13 +360,29 @@ static int vfio_pci_dma_fault_mmap(struct > > vfio_pci_device *vdev, > > return ret; > > } > > > > -static int vfio_pci_dma_fault_add_capability(struct vfio_pci_device *vdev, > > - struct vfio_pci_region *region, > > - struct vfio_info_cap *caps) > > +static int vfio_pci_dma_fault_mmap(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region, > > + struct vm_area_struct *vma) > > +{ > > + return __vfio_pci_dma_fault_mmap(vdev, region, vma, > > vdev->fault_pages); > > +} > > + > > +static int > > +vfio_pci_dma_fault_response_mmap(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region, > > + struct vm_area_struct *vma) > > +{ > > + return __vfio_pci_dma_fault_mmap(vdev, region, vma, > > vdev->fault_response_pages); > > +} > > + > > +static int __vfio_pci_dma_fault_add_capability(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region, > > + struct vfio_info_cap *caps, > > + u32 cap_id) > > { > > struct vfio_region_info_cap_sparse_mmap *sparse = NULL; > > struct vfio_region_info_cap_fault cap = { > > - .header.id = VFIO_REGION_INFO_CAP_DMA_FAULT, > > + .header.id = cap_id, > > .header.version = 1, > > .version = 1, > > }; > > @@ -383,6 +410,14 @@ static int > > vfio_pci_dma_fault_add_capability(struct > > vfio_pci_device *vdev, > > return ret; > > } > > > > +static int vfio_pci_dma_fault_add_capability(struct vfio_pci_device *vdev, > > + struct vfio_pci_region *region, > > + struct vfio_info_cap *caps) { > > + return __vfio_pci_dma_fault_add_capability(vdev, region, caps, > > + VFIO_REGION_INFO_CAP_DMA_FAULT); } > > + > > static const struct vfio_pci_regops vfio_pci_dma_fault_regops = { > > .rw = vfio_pci_dma_fault_rw, > > .release = vfio_pci_dma_fault_release, > > @@ -390,6 +425,13 @@ static const struct vfio_pci_regops > > vfio_pci_dma_fault_regops = { > > .add_capability = vfio_pci_dma_fault_add_capability, > > }; > > > > +static const struct vfio_pci_regops vfio_pci_dma_fault_response_regops = { > > + .rw = vfio_pci_dma_fault_response_rw, > > + .release = vfio_pci_dma_fault_response_release, > > + .mmap = vfio_pci_dma_fault_response_mmap, > > + .add_capability = vfio_pci_dma_fault_add_capability, As I mentioned in the Qemu patch ([RFC v7 26/26] vfio/pci: Implement return_page_response page response callback), it looks like we are using the VFIO_REGION_INFO_CAP_DMA_FAULT cap id for the dma_fault_response here as well. Is that intentional? (Was wondering how it worked in the first place and noted this). Please check. Thanks, Shameer