Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7200301pxb; Thu, 18 Feb 2021 04:20:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBQKywftLaBBLWK0jc+ZWuKhQJ3AYfdoQDERLvyTP6gErLJQGz1lBCM74xrasG2pQqRmT7 X-Received: by 2002:a05:6402:296:: with SMTP id l22mr3802518edv.225.1613650811743; Thu, 18 Feb 2021 04:20:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613650811; cv=none; d=google.com; s=arc-20160816; b=stekx/gykJKetskEYR0sye5bi48DyvwxPgaPj4utuSKHjSxLo7DViYO3D0CR1thrhA onXQUcsblCeQXDF5rO9w/ldJ9HZG3+mucHh2PDGk2ViTcPvW34SElJtO56A1EenVcjQr ygQVYE0zQ5BovJAw0zeu7DG0SiIZnSXiZXBrD0nhNHlyTyVicbkMNgD8/lXMKF7Q8NV0 alzq0Jxi8iDQ2IQJ5uM06QruDCE7ok8Y2SwBksYqEnp8fYrEI6/pwt7k7i1+RRsbxlKm Ep6m1b08gol0fjhkGMz8Npgi8PeEL/3DFcxoIzS2jUPCf/6W11PWljQYWbVmifmOHAuH Ctgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=xrLVPyhrv8/F8fL5Wp8KW8EGwEwKdeCoRYS/Gw5ZWiY=; b=FJCOlvTNQFuHx01UdGpYmBb7DnVP6Iy2vQ4/ws2iCUiGRshvDuk8NDW9pHkdmukELG ou1K47ZQ8Um7Z9wjM80lC/8UeJ0n5VBWGkUGFsUk3dPRGqCb1tj+qqAwvfvolBrlX6tM MH53LM1Y089kjglPF23q+r0PeW4m+P/cXzvLZ3eoeO+GmIb/+V3awLVk6ttv1SRxW7DM ochabVyfhHXcpYDqZOB7M5DP2t9YjWf6WPGSvBHmZl2/8snn7bLUODQB95cd5Ei7KZDV dAzrZlEIlla50mvAi0COeZlZAuY+v3SKYEwMpbkYZtpsxmogVQTtbSgTaVcQSrGsmR8h WlzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c2fSORLX; 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 x5si3805746edi.139.2021.02.18.04.19.46; Thu, 18 Feb 2021 04:20: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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=c2fSORLX; 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 S232457AbhBRMSA (ORCPT + 99 others); Thu, 18 Feb 2021 07:18:00 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:56907 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230357AbhBRKuQ (ORCPT ); Thu, 18 Feb 2021 05:50:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613645327; 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: in-reply-to:in-reply-to:references:references; bh=xrLVPyhrv8/F8fL5Wp8KW8EGwEwKdeCoRYS/Gw5ZWiY=; b=c2fSORLXEXocuTzPImYrz49ErfgjCheHv48a45VKWLR+LgqX/v4sC1Xgd6KSjNV4v/EUKy dNMZuk4PAncd0Y+d9BvLadvSgZpgPxqMi8GZ0eRNb3kpXzL6Y04A6tXATbGqgBexRA8NhZ Qo2goSNjy7A1V52Owv3bX65QL6Rg2pc= 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-220-zLEF85eQO1Sv2WJwOi_wrA-1; Thu, 18 Feb 2021 05:48:43 -0500 X-MC-Unique: zLEF85eQO1Sv2WJwOi_wrA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EC3E2192CC42; Thu, 18 Feb 2021 10:48:40 +0000 (UTC) Received: from [10.36.114.34] (ovpn-114-34.ams2.redhat.com [10.36.114.34]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EB6762679; Thu, 18 Feb 2021 10:48:32 +0000 (UTC) Subject: Re: [PATCH v11 12/13] vfio/pci: Register a DMA fault response region To: Shameerali Kolothum Thodi , "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" References: <20201116110030.32335-1-eric.auger@redhat.com> <20201116110030.32335-13-eric.auger@redhat.com> <6c00965615844f03954faecb6fcb9294@huawei.com> From: Auger Eric Message-ID: <13efbf21-90cc-9b52-a6cd-68280ea73db2@redhat.com> Date: Thu, 18 Feb 2021 11:48:30 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <6c00965615844f03954faecb6fcb9294@huawei.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Shameer, On 2/18/21 11:36 AM, Shameerali Kolothum Thodi wrote: > 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). yep, copy paste error :-( Thanks Eric > > Please check. > > Thanks, > Shameer >