From nobody Sun May 5 14:35:03 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 1581951979554325.3517454749714; Mon, 17 Feb 2020 07:06:19 -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 1j3hxv-0004dD-TN; Mon, 17 Feb 2020 15:05:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j3hxu-0004d5-7h for xen-devel@lists.xenproject.org; Mon, 17 Feb 2020 15:05:42 +0000 Received: from mail-lj1-x242.google.com (unknown [2a00:1450:4864:20::242]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f653774c-5196-11ea-ade5-bc764e2007e4; Mon, 17 Feb 2020 15:05:41 +0000 (UTC) Received: by mail-lj1-x242.google.com with SMTP id y6so19252935lji.0 for ; Mon, 17 Feb 2020 07:05:41 -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 d24sm565627lja.82.2020.02.17.07.05.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Feb 2020 07:05:39 -0800 (PST) X-Inumbo-ID: f653774c-5196-11ea-ade5-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=NDVEH24r0tl+f20FJv4g2GPHj4AgtO8yaBQy/pa/XPo=; b=cbBjrsgd5H5lDB67KY6+SanN2nA7B99hrtZNp2TKOjvYa35ib7CgZju0c9rMQsC13O o5YH+gJx867SN6iuRYSbbvV13NGV1lgd/Yht2Y44K8T3OpYWU4KDnzzmvt5zoPeiTf5R 6j6jEoKNmEn5J+kGeuYkpB93U28RRVm5KKdabS3K28B6L6rWLrhNidSm/isbJjteUqbh xHVbIo4B+o7Oeh92eHL6SdVt9qtrrEVa/tzkWGOxpMhkpkJ9ymemSLBXriKH8jVwoB75 fkaykHw8eb3iHbukoazX3UP9P/X9iVmk4rSI6weOgHovrwQN4yOoGW2NxeHWofKPrIBY +1/Q== 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=NDVEH24r0tl+f20FJv4g2GPHj4AgtO8yaBQy/pa/XPo=; b=LZ8QvyaLeDJqvOpCJr4rc98+n5Kt09ijgwn9aYw8GUOyonoyY4tHFnQCOTC/uAKULE eGz1mrCzAWXGDl/wVFQFtr1AIYwlucm9e++oMeA2YzqTDx84tAvVRSZX8XKhU/uc1+h6 CmNpp5vQ8fXI98sv796Cy/cvSrQ6NXFEXX6dHMNA21m8i3yozNnzc4DX5Zt8YJwVd+A7 W/gVUobjOjc5ow7lUzkJoeofbgTQHtA6TLVNMFpwMF1vAVF2x3nikRwOyxMumWHKRwQk gtGG2fN57otdUz71043wKGWSo/44x/I+aBImPWjP7ZwUBKVOUbbZTaz0i1zLa+o1G4H+ lthg== X-Gm-Message-State: APjAAAUqT8UdvRA3ea07EaDXYxm6mNiRdtkPN74Udd6UuRsGRhLjdH05 x1zyYRIgR7npI810Lip6BGhamnbax5I= X-Google-Smtp-Source: APXvYqxyzvZMioqp2AzwR4TxZeFhLCHPPFb6DmxbtMkVpenhAqfgB2oLTVpPbRsoQqRUUQz0Rgu9Rg== X-Received: by 2002:a05:651c:1049:: with SMTP id x9mr10372770ljm.233.1581951940119; Mon, 17 Feb 2020 07:05:40 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Mon, 17 Feb 2020 17:05:35 +0200 Message-Id: <1581951935-5279-1-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 Subject: [Xen-devel] [PATCH V2] 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 Acked-by: Julien Grall Reviewed-by: Yoshihiro Shimoda --- CC: Julien Grall CC: Stefano Stabellini CC: Volodymyr Babchuk CC: Yoshihiro Shimoda Changes V1 [1] -> V2: - Rename "data" to "imuctr" in ipmmu_utlb_enable() - Disable already enabled uTLBs in ipmmu_attach_device() in case of error [1] https://patchwork.kernel.org/patch/11356303/ --- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 49 ++++++++++++++++++++++++++++= ---- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index 9cfae7e..b2a65df 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 imuctr; + + /* + * 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. + */ + imuctr =3D ipmmu_read(mmu, IMUCTR(utlb)); + if ( imuctr & IMUCTR_MMUEN ) + { + unsigned int context_id; + + context_id =3D (imuctr & 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), imuctr | IMUCTR_TTSEL_MMU(domain->context_id) | IMUCTR_MMUEN); + + return 0; } =20 /* Disable MMU translation for the micro-TLB. */ @@ -671,7 +698,17 @@ 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 ) + { + while ( i-- ) + ipmmu_utlb_disable(domain, fwspec->ids[i]); + + 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