From patchwork Fri Apr 23 09:51:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Kumar Gautam X-Patchwork-Id: 12220015 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3473C433ED for ; Fri, 23 Apr 2021 09:54:34 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BCF4613C3 for ; Fri, 23 Apr 2021 09:54:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3BCF4613C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:Cc:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TTLo10nb0WbrbYggaO+LnBy+JXAlo/GVgESOuzIidYo=; b=g1+DgoT15GqG1LFIvb09O9GYWn t9zm/APty4mlE8mtCkNt79l8EwLnN2ogtdsFpIg5Qi1ZYS4BKnvkc9RBAhdlMFBHiy/YcYjjUjeRo +pR8WvseN00vJXSRPYK1SDG7YIl/v1Z0SFLhHI0y1GfmZgKwFlpxwbZmdHRDFsgRPB8SKL7B/28HK /hML2FetNTRz4YyrCairi+ocLnm9bOIQrb4CygGBXEz8c4X5oyjGXiswn+CRMdWZMJcZ4itA4gkJF 8pqx20hNjh7O/X+nZtJv4HLwWeyMOv32uD80W5IkxrWNrIkMA8Rkl7IkAJ/bC+yvUD/uqlmUsjeio bXLk1pAw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZsUO-001DHc-Mu; Fri, 23 Apr 2021 09:52:44 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lZsTx-001DF2-8q for linux-arm-kernel@desiato.infradead.org; Fri, 23 Apr 2021 09:52:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=NNPPPqB2c/dEC57x6zUAiv6Ja2LQ/amPOhojqqQaohs=; b=R66NxxKfhuCggoHPrWJTd6OgOh mFGwQ40u4mg5Ap4Z0E2cxAhr6xEKU+YZW0YqXTbMmucYsQ2DPmb0FSXGcsxyNoF/mwUpo9+HpG2Px vZqaSCLpBknXgdWowkCyW2ugfklYw2cSXTIgN4cufN3Osg8ECNo5eu4QdpcpBKYbLhROB+SZ3EXZm yQH4ubWFRKPTeRqsbYxYMRecrkV0lqKmMkuL5w88iCThZ8IVpRRB8atqTuVs6KYWdrfHNqScu+bmY PopYBrjtFbc9m+ejO5fjax3xGFgMUjsQTRt658ZxexF6xaQDt+S5w3i8UJsyUIDk/0smyeQa0HAYy 95XoxouQ==; Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lZsTu-00EIfT-Ek for linux-arm-kernel@lists.infradead.org; Fri, 23 Apr 2021 09:52:16 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3D45152B; Fri, 23 Apr 2021 02:52:12 -0700 (PDT) Received: from usa.arm.com (a074945.blr.arm.com [10.162.16.71]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8C3533F774; Fri, 23 Apr 2021 02:52:08 -0700 (PDT) From: Vivek Gautam To: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org Cc: joro@8bytes.org, will.deacon@arm.com, mst@redhat.com, robin.murphy@arm.com, jean-philippe@linaro.org, eric.auger@redhat.com, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, yi.l.liu@intel.com, Lorenzo.Pieralisi@arm.com, shameerali.kolothum.thodi@huawei.com, Vivek Gautam Subject: [PATCH RFC v1 03/11] iommu/virtio: Handle incoming page faults Date: Fri, 23 Apr 2021 15:21:39 +0530 Message-Id: <20210423095147.27922-4-vivek.gautam@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210423095147.27922-1-vivek.gautam@arm.com> References: <20210423095147.27922-1-vivek.gautam@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210423_025214_608031_814F2F67 X-CRM114-Status: GOOD ( 15.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Redirect the incoming page faults to the registered fault handler that can take the fault information such as, pasid, page request group-id, address and pasid flags. Signed-off-by: Vivek Gautam --- drivers/iommu/virtio-iommu.c | 80 ++++++++++++++++++++++++++++++- include/uapi/linux/virtio_iommu.h | 1 + 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index c970f386f031..fd237cad1ce5 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -37,6 +37,13 @@ /* Some architectures need an Address Space ID for each page table */ DEFINE_XARRAY_ALLOC1(viommu_asid_xa); +struct viommu_dev_pri_work { + struct work_struct work; + struct viommu_dev *dev; + struct virtio_iommu_fault *vfault; + u32 endpoint; +}; + struct viommu_dev { struct iommu_device iommu; struct device *dev; @@ -49,6 +56,8 @@ struct viommu_dev { struct list_head requests; void *evts; struct list_head endpoints; + struct workqueue_struct *pri_wq; + struct viommu_dev_pri_work *pri_work; /* Device configuration */ struct iommu_domain_geometry geometry; @@ -666,6 +675,58 @@ static int viommu_probe_endpoint(struct viommu_dev *viommu, struct device *dev) return ret; } +static void viommu_handle_ppr(struct work_struct *work) +{ + struct viommu_dev_pri_work *pwork = + container_of(work, struct viommu_dev_pri_work, work); + struct viommu_dev *viommu = pwork->dev; + struct virtio_iommu_fault *vfault = pwork->vfault; + struct viommu_endpoint *vdev; + struct viommu_ep_entry *ep; + struct iommu_fault_event fault_evt = { + .fault.type = IOMMU_FAULT_PAGE_REQ, + }; + struct iommu_fault_page_request *prq = &fault_evt.fault.prm; + + u32 flags = le32_to_cpu(vfault->flags); + u32 prq_flags = le32_to_cpu(vfault->pr_evt_flags); + u32 endpoint = pwork->endpoint; + + memset(prq, 0, sizeof(struct iommu_fault_page_request)); + prq->addr = le64_to_cpu(vfault->address); + + if (prq_flags & VIRTIO_IOMMU_FAULT_PRQ_F_LAST_PAGE) + prq->flags |= IOMMU_FAULT_PAGE_REQUEST_LAST_PAGE; + if (prq_flags & VIRTIO_IOMMU_FAULT_PRQ_F_PASID_VALID) { + prq->flags |= IOMMU_FAULT_PAGE_REQUEST_PASID_VALID; + prq->pasid = le32_to_cpu(vfault->pasid); + prq->grpid = le32_to_cpu(vfault->grpid); + } + + if (flags & VIRTIO_IOMMU_FAULT_F_READ) + prq->perm |= IOMMU_FAULT_PERM_READ; + if (flags & VIRTIO_IOMMU_FAULT_F_WRITE) + prq->perm |= IOMMU_FAULT_PERM_WRITE; + if (flags & VIRTIO_IOMMU_FAULT_F_EXEC) + prq->perm |= IOMMU_FAULT_PERM_EXEC; + if (flags & VIRTIO_IOMMU_FAULT_F_PRIV) + prq->perm |= IOMMU_FAULT_PERM_PRIV; + + list_for_each_entry(ep, &viommu->endpoints, list) { + if (ep->eid == endpoint) { + vdev = ep->vdev; + break; + } + } + + if ((prq_flags & VIRTIO_IOMMU_FAULT_PRQ_F_PASID_VALID) && + (prq_flags & VIRTIO_IOMMU_FAULT_PRQ_F_NEEDS_PASID)) + prq->flags |= IOMMU_FAULT_PAGE_RESPONSE_NEEDS_PASID; + + if (iommu_report_device_fault(vdev->dev, &fault_evt)) + dev_err(vdev->dev, "Couldn't handle page request\n"); +} + static int viommu_fault_handler(struct viommu_dev *viommu, struct virtio_iommu_fault *fault) { @@ -679,7 +740,13 @@ static int viommu_fault_handler(struct viommu_dev *viommu, u32 pasid = le32_to_cpu(fault->pasid); if (type == VIRTIO_IOMMU_FAULT_F_PAGE_REQ) { - dev_info(viommu->dev, "Page request fault - unhandled\n"); + dev_info_ratelimited(viommu->dev, + "Page request fault from EP %u\n", + endpoint); + + viommu->pri_work->vfault = fault; + viommu->pri_work->endpoint = endpoint; + queue_work(viommu->pri_wq, &viommu->pri_work->work); return 0; } @@ -1683,6 +1750,17 @@ static int viommu_probe(struct virtio_device *vdev) goto err_free_vqs; } + viommu->pri_work = kzalloc(sizeof(*viommu->pri_work), GFP_KERNEL); + if (!viommu->pri_work) + return -ENOMEM; + + viommu->pri_work->dev = viommu; + + INIT_WORK(&viommu->pri_work->work, viommu_handle_ppr); + viommu->pri_wq = create_singlethread_workqueue("viommu-pri-wq"); + if (!viommu->pri_wq) + return -ENOMEM; + viommu->map_flags = VIRTIO_IOMMU_MAP_F_READ | VIRTIO_IOMMU_MAP_F_WRITE; viommu->last_domain = ~0U; diff --git a/include/uapi/linux/virtio_iommu.h b/include/uapi/linux/virtio_iommu.h index accc3318ce46..53aa88e6b077 100644 --- a/include/uapi/linux/virtio_iommu.h +++ b/include/uapi/linux/virtio_iommu.h @@ -302,6 +302,7 @@ struct virtio_iommu_req_invalidate { #define VIRTIO_IOMMU_FAULT_F_READ (1 << 0) #define VIRTIO_IOMMU_FAULT_F_WRITE (1 << 1) #define VIRTIO_IOMMU_FAULT_F_EXEC (1 << 2) +#define VIRTIO_IOMMU_FAULT_F_PRIV (1 << 3) #define VIRTIO_IOMMU_FAULT_F_ADDRESS (1 << 8) #define VIRTIO_IOMMU_FAULT_F_DMA_UNRECOV 1