From nobody Sat Apr 27 16:47:50 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1580309781679294.98647658910215; Wed, 29 Jan 2020 06:56:21 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwokZ-0000LQ-HO; Wed, 29 Jan 2020 14:55:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iwokY-0000Kt-Fo for xen-devel@lists.xenproject.org; Wed, 29 Jan 2020 14:55:26 +0000 Received: from mail-lf1-x143.google.com (unknown [2a00:1450:4864:20::143]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6164dd7c-42a7-11ea-b211-bc764e2007e4; Wed, 29 Jan 2020 14:55:25 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id t23so12055630lfk.6 for ; Wed, 29 Jan 2020 06:55:25 -0800 (PST) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id k24sm1358605ljj.27.2020.01.29.06.55.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Jan 2020 06:55:23 -0800 (PST) X-Inumbo-ID: 6164dd7c-42a7-11ea-b211-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=ZW9+Wg3q/4l9pYMVcV8YdGyoyYfomvr0275Ia3YZK6E=; b=VWqkjMAqKqsPzyQZmtXOTKbHWqAfFlPjz3aEQ0PmSczqCrwVYLSpCXm3OTe7KvLrAG qSEYpqoMpvkPxUlkgQQFXgbU+HVtOcm53pq37UhmRKSzWsAC2Uy2GGja2oGz4t0zSq2R fUCShSiRkGcinaeOfcahl4UZRjGk3YyDigVudV3d3CrltoxmvS18oPopZAtPR9IufI4k eHqlzzL+2at8UVRf68VwHKmKvgW2+8yCWFp0kSkqCGtKUfZt//O9svvmM/3dRn5hOx1Q kyUuxmniWdqCVOgURTeo9K1wa04EdDOw7eVlGqpB9n+RFzToVyOE032spzL4ZJLVhlxc lqBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=ZW9+Wg3q/4l9pYMVcV8YdGyoyYfomvr0275Ia3YZK6E=; b=azri75AUQO6EVk/2EK1oAS6RHRnVg3KQ/t+a+vlIah4F54aLZ40KTLo0M3yWCaFzzI aZBkJGLPvJx7rU7Ma9dfTTPR98B8BNKc8meL6JZeP2uXd28+Z9W2J63K3UdtlQ3ucGs9 wkBGkem66KTxMcDOELyyY9TPJHebRliUH/iJ7/NPAK9ts24XchEF7EeB72/5oDkTTU1z HzEsuTD/PiGm0sj5ws1qsLs+UqrXE0Vj4gR0WwPMgHFSyI7jY23Pw+e7ZFts87TybZ2w S3d6LaQ2M/XlxM0Vsi3aHYsXk62kwUqHvn5w0PhXx5ScmsS20yfonjJuy+/nPUIIrLUW gN/w== X-Gm-Message-State: APjAAAW+sYRfUI5JNXABHQw1hlBq/P/pgm1E2o5V7kuWkn5Ly9USxVSU waIUxKaoU02CiKjiDhTXDmcImWgMYJw= X-Google-Smtp-Source: APXvYqzSmmZbz/o2JGngqjGECL0eKGvEb/MeDavdj+NRTZ6D4QpyzxFTBV2dU0FxZRcLVgWxs2AJdQ== X-Received: by 2002:a19:c210:: with SMTP id l16mr5846701lfc.35.1580309724283; Wed, 29 Jan 2020 06:55:24 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Wed, 29 Jan 2020 16:55:14 +0200 Message-Id: <1580309714-21912-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Xen-devel] [PATCH] iommu/arm: Don't allow the same micro-TLB to be shared between domains X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Oleksandr Tyshchenko , Yoshihiro Shimoda , Stefano Stabellini , Julien Grall , Volodymyr Babchuk MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Oleksandr Tyshchenko For the IPMMU-VMSA we need to prevent the use cases where devices which use the same micro-TLB are assigned to different Xen domains (micro-TLB cannot be shared between multiple Xen domains, since it points to the context bank to use for the page walk). As each Xen domain uses individual context bank pointed by context_id, we can potentially recognize that use case by comparing current and new context_id for the already enabled micro-TLB and prevent different context bank from being set. Signed-off-by: Oleksandr Tyshchenko --- CC: Julien Grall CC: Stefano Stabellini CC: Volodymyr Babchuk CC: Yoshihiro Shimoda --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 44 +++++++++++++++++++++++++++-= ---- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index 9cfae7e..c21d2d7 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -257,6 +257,7 @@ static DEFINE_SPINLOCK(ipmmu_devices_lock); #define IMUCTR_TTSEL_MMU(n) ((n) << 4) #define IMUCTR_TTSEL_PMB (8 << 4) #define IMUCTR_TTSEL_MASK (15 << 4) +#define IMUCTR_TTSEL_SHIFT 4 #define IMUCTR_FLUSH (1 << 1) #define IMUCTR_MMUEN (1 << 0) =20 @@ -434,19 +435,45 @@ static void ipmmu_tlb_invalidate(struct ipmmu_vmsa_do= main *domain) } =20 /* Enable MMU translation for the micro-TLB. */ -static void ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, - unsigned int utlb) +static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *domain, + unsigned int utlb) { struct ipmmu_vmsa_device *mmu =3D domain->mmu; + uint32_t data; + + /* + * We need to prevent the use cases where devices which use the same + * micro-TLB are assigned to different Xen domains (micro-TLB cannot be + * shared between multiple Xen domains, since it points to the context= bank + * to use for the page walk). + * As each Xen domain uses individual context bank pointed by context_= id, + * we can potentially recognize that use case by comparing current and= new + * context_id for already enabled micro-TLB and prevent different cont= ext + * bank from being set. + */ + data =3D ipmmu_read(mmu, IMUCTR(utlb)); + if ( data & IMUCTR_MMUEN ) + { + unsigned int context_id; + + context_id =3D (data & IMUCTR_TTSEL_MASK) >> IMUCTR_TTSEL_SHIFT; + if ( domain->context_id !=3D context_id ) + { + dev_err(mmu->dev, "Micro-TLB %u already assigned to IPMMU cont= ext %u\n", + utlb, context_id); + return -EINVAL; + } + } =20 /* * TODO: Reference-count the micro-TLB as several bus masters can be - * connected to the same micro-TLB. Prevent the use cases where - * the same micro-TLB could be shared between multiple Xen domains. + * connected to the same micro-TLB. */ ipmmu_write(mmu, IMUASID(utlb), 0); - ipmmu_write(mmu, IMUCTR(utlb), ipmmu_read(mmu, IMUCTR(utlb)) | + ipmmu_write(mmu, IMUCTR(utlb), data | IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); + + return 0; } =20 /* Disable MMU translation for the micro-TLB. */ @@ -671,7 +698,12 @@ static int ipmmu_attach_device(struct ipmmu_vmsa_domai= n *domain, dev_info(dev, "Reusing IPMMU context %u\n", domain->context_id); =20 for ( i =3D 0; i < fwspec->num_ids; ++i ) - ipmmu_utlb_enable(domain, fwspec->ids[i]); + { + int ret =3D ipmmu_utlb_enable(domain, fwspec->ids[i]); + + if ( ret ) + return ret; + } =20 return 0; } --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel