From mboxrd@z Thu Jan 1 00:00:00 1970 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=-12.5 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, UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_SANE_2 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 427A8C433E9 for ; Thu, 4 Mar 2021 00:29: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 3382A6023B for ; Thu, 4 Mar 2021 00:29:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3382A6023B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.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:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=M3nw219e4gPTz8eqyLDB9cZzenxfCgWh+m6/JjJzohg=; b=Ju1KS9FFrHcy5TkLeOKk8fPxt f1EAe8hj9EnbEq2nN0KSdsCCuW10w4v1lFTwgMoNlRcoMW0jVMbxZkiLu7BSZD4gIkPnJIj9QPcNv /cmjReyZQr0h8F7ubJaiYIYXnWtIJYommLQZxzU/HgNdwzDaNvD9YD4siYbf1YW0uJPK+tTtB9hsi EH0o5NMqLBJclDg/w24DBt8KbQlm/JqTqrcuy7fWpNYw6V8MCJwv0c/XO+haXM6NObX01nVymklO3 BHlb1N6jsv2jucEeTTuBY+TZBnW6pOSpq5adB/pNUPjNY3i+cjtZUU+j2gdbCbuRVoyaO9O3QyyJl VpvrYtdww==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHbmo-0078wa-Tl; Thu, 04 Mar 2021 00:24:15 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHWDk-00613W-N1 for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 18:27:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date:Sender :Reply-To:Content-ID:Content-Description; bh=Ay2gNkUN+BxutwHd3kaYRMbaJ0zhbPkIdfvTnG9Pg98=; b=cSe6urq0EE+mDOTOx+RhacYYVy ICbrAVLTJSGhZkL9QgOdgdPyH5jRG/MTVWJXp7bO51n48aQvQbdJpUHvarpKdy5X4KEs03GC5kqiQ 3rfoswvd7QCMNP7it+8a3DFiJZChaIp59EEd186XLbwUkTzBA1PWq2ZzezfinoQMk/qlz6kTGujh+ KcfrZ3mPwldZ6j8cGTgjVRQmfJWtK46k61el3Ve5cUkOJdjWGeqiivtyPJdFAg0/nD0ddkiTfNaMO A0aXSuRK+6Jhm09lZ479afSnBdJG8o7va3AKJIItA8HVytGKHH/JXXe8U6KvKMNo2NX+HrlYUeG3N yTPuQzEg==; Received: from mga06.intel.com ([134.134.136.31]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHWDg-003igI-E6 for linux-arm-kernel@lists.infradead.org; Wed, 03 Mar 2021 18:27:39 +0000 IronPort-SDR: ntJ7d/dJqTs+Iq7aBURzqFvvSTV1BJLVf2wUXz0tmNYS5+TUHE4ofGhjTGfJaY7meCgWixJDkW hgNt+7BSaRnQ== X-IronPort-AV: E=McAfee;i="6000,8403,9912"; a="248655699" X-IronPort-AV: E=Sophos;i="5.81,220,1610438400"; d="scan'208";a="248655699" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 10:26:33 -0800 IronPort-SDR: flZ7ydHew/uLhmA0gDtrMwbn8pEMwFG07GAmfz4SHyILz2W2OCSJgnBR1uJ6kAa/Ww7OBC5TmT S3ny2ZIn3+Ww== X-IronPort-AV: E=Sophos;i="5.81,220,1610438400"; d="scan'208";a="428367968" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Mar 2021 10:26:33 -0800 Date: Wed, 3 Mar 2021 10:28:48 -0800 From: Jacob Pan To: Vivek Gautam Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org, joro@8bytes.org, will.deacon@arm.com, mst@redhat.com, robin.murphy@arm.com, jean-philippe@linaro.org, eric.auger@redhat.com, alex.williamson@redhat.com, kevin.tian@intel.com, yi.l.liu@intel.com, lorenzo.pieralisi@arm.com, shameerali.kolothum.thodi@huawei.com, jacob.jun.pan@linux.intel.com Subject: Re: [PATCH RFC v1 12/15] iommu/virtio: Add support for INVALIDATE request Message-ID: <20210303102848.5d879f0e@jacob-builder> In-Reply-To: <20210115121342.15093-13-vivek.gautam@arm.com> References: <20210115121342.15093-1-vivek.gautam@arm.com> <20210115121342.15093-13-vivek.gautam@arm.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210303_182739_207490_DCBC17B3 X-CRM114-Status: GOOD ( 23.77 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Vivek, On Fri, 15 Jan 2021 17:43:39 +0530, Vivek Gautam wrote: > From: Jean-Philippe Brucker > > Add support for tlb invalidation ops that can send invalidation > requests to back-end virtio-iommu when stage-1 page tables are > supported. > Just curious if it possible to reuse the iommu uapi for invalidation and others. When we started out designing the iommu uapi, the intention was to support both emulated and virtio iommu. > Signed-off-by: Jean-Philippe Brucker > [Vivek: Refactoring the iommu_flush_ops, and adding only one pasid sync > op that's needed with current iommu-pasid-table infrastructure. > Also updating uapi defines as required by latest changes] > Signed-off-by: Vivek Gautam > Cc: Joerg Roedel > Cc: Will Deacon > Cc: Michael S. Tsirkin > Cc: Robin Murphy > Cc: Jean-Philippe Brucker > Cc: Eric Auger > Cc: Alex Williamson > Cc: Kevin Tian > Cc: Jacob Pan > Cc: Liu Yi L > Cc: Lorenzo Pieralisi > Cc: Shameerali Kolothum Thodi > --- > drivers/iommu/virtio-iommu.c | 95 ++++++++++++++++++++++++++++++++++++ > 1 file changed, 95 insertions(+) > > diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c > index ae5dfd3f8269..004ea94e3731 100644 > --- a/drivers/iommu/virtio-iommu.c > +++ b/drivers/iommu/virtio-iommu.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -63,6 +64,8 @@ struct viommu_mapping { > }; > > struct viommu_mm { > + int pasid; > + u64 archid; > struct io_pgtable_ops *ops; > struct viommu_domain *domain; > }; > @@ -692,6 +695,98 @@ static void viommu_event_handler(struct virtqueue > *vq) virtqueue_kick(vq); > } > > +/* PASID and pgtable APIs */ > + > +static void __viommu_flush_pasid_tlb_all(struct viommu_domain *vdomain, > + int pasid, u64 arch_id, int > type) +{ > + struct virtio_iommu_req_invalidate req = { > + .head.type = VIRTIO_IOMMU_T_INVALIDATE, > + .inv_gran = > cpu_to_le32(VIRTIO_IOMMU_INVAL_G_PASID), > + .flags = > cpu_to_le32(VIRTIO_IOMMU_INVAL_F_PASID), > + .inv_type = cpu_to_le32(type), > + > + .domain = cpu_to_le32(vdomain->id), > + .pasid = cpu_to_le32(pasid), > + .archid = cpu_to_le64(arch_id), > + }; > + > + if (viommu_send_req_sync(vdomain->viommu, &req, sizeof(req))) > + pr_debug("could not send invalidate request\n"); > +} > + > +static void viommu_flush_tlb_add(struct iommu_iotlb_gather *gather, > + unsigned long iova, size_t granule, > + void *cookie) > +{ > + struct viommu_mm *viommu_mm = cookie; > + struct viommu_domain *vdomain = viommu_mm->domain; > + struct iommu_domain *domain = &vdomain->domain; > + > + iommu_iotlb_gather_add_page(domain, gather, iova, granule); > +} > + > +static void viommu_flush_tlb_walk(unsigned long iova, size_t size, > + size_t granule, void *cookie) > +{ > + struct viommu_mm *viommu_mm = cookie; > + struct viommu_domain *vdomain = viommu_mm->domain; > + struct virtio_iommu_req_invalidate req = { > + .head.type = VIRTIO_IOMMU_T_INVALIDATE, > + .inv_gran = cpu_to_le32(VIRTIO_IOMMU_INVAL_G_VA), > + .inv_type = cpu_to_le32(VIRTIO_IOMMU_INV_T_IOTLB), > + .flags = > cpu_to_le32(VIRTIO_IOMMU_INVAL_F_ARCHID), + > + .domain = cpu_to_le32(vdomain->id), > + .pasid = cpu_to_le32(viommu_mm->pasid), > + .archid = cpu_to_le64(viommu_mm->archid), > + .virt_start = cpu_to_le64(iova), > + .nr_pages = cpu_to_le64(size / granule), > + .granule = ilog2(granule), > + }; > + > + if (viommu_add_req(vdomain->viommu, &req, sizeof(req))) > + pr_debug("could not add invalidate request\n"); > +} > + > +static void viommu_flush_tlb_all(void *cookie) > +{ > + struct viommu_mm *viommu_mm = cookie; > + > + if (!viommu_mm->archid) > + return; > + > + __viommu_flush_pasid_tlb_all(viommu_mm->domain, viommu_mm->pasid, > + viommu_mm->archid, > + VIRTIO_IOMMU_INV_T_IOTLB); > +} > + > +static struct iommu_flush_ops viommu_flush_ops = { > + .tlb_flush_all = viommu_flush_tlb_all, > + .tlb_flush_walk = viommu_flush_tlb_walk, > + .tlb_add_page = viommu_flush_tlb_add, > +}; > + > +static void viommu_flush_pasid(void *cookie, int pasid, bool leaf) > +{ > + struct viommu_domain *vdomain = cookie; > + struct virtio_iommu_req_invalidate req = { > + .head.type = VIRTIO_IOMMU_T_INVALIDATE, > + .inv_gran = > cpu_to_le32(VIRTIO_IOMMU_INVAL_G_PASID), > + .inv_type = cpu_to_le32(VIRTIO_IOMMU_INV_T_PASID), > + .flags = > cpu_to_le32(VIRTIO_IOMMU_INVAL_F_PASID), + > + .domain = cpu_to_le32(vdomain->id), > + .pasid = cpu_to_le32(pasid), > + }; > + > + if (leaf) > + req.flags |= > cpu_to_le32(VIRTIO_IOMMU_INVAL_F_LEAF); + > + if (viommu_send_req_sync(vdomain->viommu, &req, sizeof(req))) > + pr_debug("could not send invalidate request\n"); > +} > + > /* IOMMU API */ > > static struct iommu_domain *viommu_domain_alloc(unsigned type) Thanks, Jacob _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel