From patchwork Fri Dec 16 07:16:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bhupinder Thakur X-Patchwork-Id: 88265 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1247595qgi; Thu, 15 Dec 2016 23:18:56 -0800 (PST) X-Received: by 10.107.176.197 with SMTP id z188mr1651162ioe.7.1481872736136; Thu, 15 Dec 2016 23:18:56 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b188si1752923ite.76.2016.12.15.23.18.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2016 23:18:56 -0800 (PST) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHml0-0000Px-EU; Fri, 16 Dec 2016 07:16:42 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHmkz-0000Pq-QM for xen-devel@lists.xenproject.org; Fri, 16 Dec 2016 07:16:41 +0000 Received: from [85.158.139.211] by server-1.bemta-5.messagelabs.com id 6E/40-16850-8D493585; Fri, 16 Dec 2016 07:16:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrJIsWRWlGSWpSXmKPExsVyMfTAet0bU4I jDF5ckrL4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPaJn9iKlhgWLHl4SXWBsaZal2MXBxCAjMY JRas384K4rAIzGOWaJq4lBHEkRDoZ5U4unQXcxcjJ5ATIzHnSAM7hF0u8fLyO1YQW0hAS+Loq dlQdjOTRO+JiC5GDg42AROJWR0SIGERASWJe6smM4HYzAKhEv+etYGNERZwl1i2bjobSDmLgK rEpXt5IGFeAW+Jt+cXQG2Sk7h5rpMZpIRTwEei+1wOxCJvic//97NNYBRYwMiwilGjOLWoLLV I19BUL6koMz2jJDcxM0fX0MBULze1uDgxPTUnMalYLzk/dxMjMKgYgGAHY8N2z0OMkhxMSqK8 XrnBEUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeE9MBsoJFqWmp1akZeYAwxsmLcHBoyTCu3MCU Jq3uCAxtzgzHSJ1itGS49isxU+ZOKY9A5G7Otc8ZRJiycvPS5US52UFRpGQAEhDRmke3DhYDF 5ilJUS5mUEOlCIpyC1KDezBFX+FaM4B6OSMC8vyBSezLwSuK2vgA5iAjpIdIk/yEEliQgpqQZ GH9fAr06tLUtqJntHx7566vss6n3qvsZ9pXYHVz571DmvQdnDODjiU9af08F/px55yix/5vc/ 26I7P+dYtZhN8Qg0cXrietq+7O7/iYb606S1253qVorFv1sY9KWG5ZPCmlPmGyu9HvwMmjxDb i/7ip+vv7+dyOxV/s674Fga0wPhnOMfPDlUlFiKMxINtZiLihMBo8efLbwCAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-6.tower-206.messagelabs.com!1481872598!75547569!1 X-Originating-IP: [209.85.192.175] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 14939 invoked from network); 16 Dec 2016 07:16:39 -0000 Received: from mail-pf0-f175.google.com (HELO mail-pf0-f175.google.com) (209.85.192.175) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 16 Dec 2016 07:16:39 -0000 Received: by mail-pf0-f175.google.com with SMTP id d2so13118421pfd.0 for ; Thu, 15 Dec 2016 23:16:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TFQKHne7Xq7cIeU/rXQLJ4Ch9rxeZMJIxVjybb6KjgY=; b=agYtQFxWtrqB4yrycHH0LnFxaiOCY33GfGWc5mKEWVEJOn82eFk6NvIdV8ZeVLEcsT TcazamEGrbS3pbLkMNg7srtVEo7KlAWFNJ+dMITHs2lMyuSuvTjoy8zHoeXV3WjOeGEL 5bJnf7EQooIFUbxwLASBEqUNSN1be7VKAkQDs= 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:in-reply-to :references; bh=TFQKHne7Xq7cIeU/rXQLJ4Ch9rxeZMJIxVjybb6KjgY=; b=Nh6lhLF+nPTYafgJ0o7G7MoFxLAWXsHhAIaX1dif1rzpE+YIOfsMXB9WDAjUSfm0wT pITYJzKT0AsFMcay4oxehUO6AOf23l00E8BanK0bcalGzblKXV++3fHGxEBsqVPypa82 EOc5RuVm/5ZlS8bQBQebIO9HnC0cUokJ4m+/UdQTbvi6LxWP/wpVPKa1vaiMuGiZsOF9 glb0y7OR/P4FOtx3DCDrykuVBs7CfBFpZ08K56nN84MMZD7+0tCLowVy4dxW0o4OEb0Q wN4/Ut9MS76H/ndAvC84qI1V38cZEsqGs896a1jsBRtLYUbT8GZK2bE51ZGXRdQRsPcP LgIA== X-Gm-Message-State: AKaTC01R5oYBu/0DSBZJae5WzIGgwkNgkQUV2aVz+psYgWscV9a0bt3lcZPyX7ueefjx8HKs X-Received: by 10.84.171.1 with SMTP id k1mr3740086plb.169.1481872598236; Thu, 15 Dec 2016 23:16:38 -0800 (PST) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([202.46.23.54]) by smtp.gmail.com with ESMTPSA id 2sm9198699pgy.27.2016.12.15.23.16.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Dec 2016 23:16:37 -0800 (PST) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Fri, 16 Dec 2016 12:46:28 +0530 Message-Id: <1481872588-10876-2-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1481872588-10876-1-git-send-email-bhupinder.thakur@linaro.org> References: <1481872588-10876-1-git-send-email-bhupinder.thakur@linaro.org> Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [XEN VMID RESEND v5 2/2] xen/arm: Add support for 16 bit VMIDs X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" VMID space is increased to 16-bits from 8-bits in ARMv8 8.1 revision. This allows more than 256 VMs to be supported by Xen. This change adds support for 16-bit VMIDs in Xen based on whether the architecture supports it. Signed-off-by: Bhupinder Thakur Reviewed-by: Julien Grall --- xen/arch/arm/p2m.c | 52 ++++++++++++++++++++++++++++++++++------- xen/include/asm-arm/p2m.h | 2 +- xen/include/asm-arm/processor.h | 18 +++++++++++++- 3 files changed, 62 insertions(+), 10 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 6930f8c..09ceb37 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -14,15 +15,25 @@ #include #include +#define MAX_VMID_8_BIT (1UL << 8) +#define MAX_VMID_16_BIT (1UL << 16) + +#define INVALID_VMID 0 /* VMID 0 is reserved */ + #ifdef CONFIG_ARM_64 static unsigned int __read_mostly p2m_root_order; static unsigned int __read_mostly p2m_root_level; #define P2M_ROOT_ORDER p2m_root_order #define P2M_ROOT_LEVEL p2m_root_level +static unsigned int __read_mostly max_vmid = MAX_VMID_8_BIT; +/* VMID is by default 8 bit width on AArch64 */ +#define MAX_VMID max_vmid #else /* First level P2M is alway 2 consecutive pages */ #define P2M_ROOT_LEVEL 1 #define P2M_ROOT_ORDER 1 +/* VMID is always 8 bit width on AArch32 */ +#define MAX_VMID MAX_VMID_8_BIT #endif #define P2M_ROOT_PAGES (1<root = page; - p2m->vttbr = page_to_maddr(p2m->root) | ((uint64_t)p2m->vmid & 0xff) << 48; + p2m->vttbr = page_to_maddr(p2m->root) | ((uint64_t)p2m->vmid << 48); /* * Make sure that all TLBs corresponding to the new VMID are flushed @@ -1228,19 +1239,27 @@ static int p2m_alloc_table(struct domain *d) return 0; } -#define MAX_VMID 256 -#define INVALID_VMID 0 /* VMID 0 is reserved */ static spinlock_t vmid_alloc_lock = SPIN_LOCK_UNLOCKED; /* - * VTTBR_EL2 VMID field is 8 bits. Using a bitmap here limits us to - * 256 concurrent domains. + * VTTBR_EL2 VMID field is 8 or 16 bits. AArch64 may support 16-bit VMID. + * Using a bitmap here limits us to 256 or 65536 (for AArch64) concurrent + * domains. The bitmap space will be allocated dynamically based on + * whether 8 or 16 bit VMIDs are supported. */ -static DECLARE_BITMAP(vmid_mask, MAX_VMID); +static unsigned long *vmid_mask; static void p2m_vmid_allocator_init(void) { + /* + * allocate space for vmid_mask based on MAX_VMID + */ + vmid_mask = xzalloc_array(unsigned long, BITS_TO_LONGS(MAX_VMID)); + + if ( !vmid_mask ) + panic("Could not allocate VMID bitmap space"); + set_bit(INVALID_VMID, vmid_mask); } @@ -1630,20 +1649,36 @@ void __init setup_virt_paging(void) unsigned int cpu; unsigned int pa_range = 0x10; /* Larger than any possible value */ + bool vmid_8_bit = false; for_each_online_cpu ( cpu ) { const struct cpuinfo_arm *info = &cpu_data[cpu]; if ( info->mm64.pa_range < pa_range ) pa_range = info->mm64.pa_range; + + /* Set a flag if the current cpu does not support 16 bit VMIDs. */ + if ( info->mm64.vmid_bits != MM64_VMID_16_BITS_SUPPORT ) + vmid_8_bit = true; } + /* + * If the flag is not set then it means all CPUs support 16-bit + * VMIDs. + */ + if ( !vmid_8_bit ) + max_vmid = MAX_VMID_16_BIT; + /* pa_range is 4 bits, but the defined encodings are only 3 bits */ if ( pa_range >= ARRAY_SIZE(pa_range_info) || !pa_range_info[pa_range].pabits ) panic("Unknown encoding of ID_AA64MMFR0_EL1.PARange %x\n", pa_range); val |= VTCR_PS(pa_range); val |= VTCR_TG0_4K; + + /* Set the VS bit only if 16 bit VMID is supported. */ + if ( MAX_VMID == MAX_VMID_16_BIT ) + val |= VTCR_VS; val |= VTCR_SL0(pa_range_info[pa_range].sl0); val |= VTCR_T0SZ(pa_range_info[pa_range].t0sz); @@ -1651,9 +1686,10 @@ void __init setup_virt_paging(void) p2m_root_level = 2 - pa_range_info[pa_range].sl0; p2m_ipa_bits = 64 - pa_range_info[pa_range].t0sz; - printk("P2M: %d-bit IPA with %d-bit PA\n", + printk("P2M: %d-bit IPA with %d-bit PA and %d-bit VMID\n", p2m_ipa_bits, - pa_range_info[pa_range].pabits); + pa_range_info[pa_range].pabits, + ( MAX_VMID == MAX_VMID_16_BIT ) ? 16 : 8); #endif printk("P2M: %d levels with order-%d root, VTCR 0x%lx\n", 4 - P2M_ROOT_LEVEL, P2M_ROOT_ORDER, val); diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 0987be2..9de55fc 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -30,7 +30,7 @@ struct p2m_domain { struct page_info *root; /* Current VMID in use */ - uint8_t vmid; + uint16_t vmid; /* Current Translation Table Base Register for the p2m */ uint64_t vttbr; diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index 4163884..afc0e9a 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -215,6 +215,8 @@ #define VTCR_PS(x) ((x)<<16) +#define VTCR_VS (_AC(0x1,UL)<<19) + #endif #define VTCR_RES1 (_AC(1,UL)<<31) @@ -269,6 +271,11 @@ /* FSR long format */ #define FSRL_STATUS_DEBUG (_AC(0x22,UL)<<0) +#ifdef CONFIG_ARM_64 +#define MM64_VMID_8_BITS_SUPPORT 0x0 +#define MM64_VMID_16_BITS_SUPPORT 0x2 +#endif + #ifndef __ASSEMBLY__ struct cpuinfo_arm { @@ -337,7 +344,16 @@ struct cpuinfo_arm { unsigned long tgranule_64K:4; unsigned long tgranule_4K:4; unsigned long __res0:32; - }; + + unsigned long hafdbs:4; + unsigned long vmid_bits:4; + unsigned long vh:4; + unsigned long hpds:4; + unsigned long lo:4; + unsigned long pan:4; + unsigned long __res1:8; + unsigned long __res2:32; + }; } mm64; struct {