From patchwork Thu Dec 15 16:55: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: 88200 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp907799qgi; Thu, 15 Dec 2016 08:59:23 -0800 (PST) X-Received: by 10.107.11.81 with SMTP id v78mr2227082ioi.20.1481821163439; Thu, 15 Dec 2016 08:59:23 -0800 (PST) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id o188si9656327itd.111.2016.12.15.08.59.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Dec 2016 08:59:23 -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 1cHZLe-0002C2-Lu; Thu, 15 Dec 2016 16:57:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cHZLd-0002Bv-Az for xen-devel@lists.xenproject.org; Thu, 15 Dec 2016 16:57:37 +0000 Received: from [85.158.143.35] by server-2.bemta-6.messagelabs.com id 1D/6D-22326-08BC2585; Thu, 15 Dec 2016 16:57:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42Lxqg3W0q0/HRR hcOuRmcX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmnFt222mgjmGFb8XbGFuYJyp1sXIxSEkMI1R YsLO9YwgDotAO7NEx74P7CCOhMA7FolVfU+BMpxATozEst41LF2MHEB2pcTj6w4gYSEBLYmjp 2azQkxqZpLobfvLDlLDJmAiMatDAqRGREBJ4t6qyUwgNrNAqMS/Z23sILawgJtEQ+8VsPEsAq oSx/omgdm8At4SG9+dYoVYKydx81wn8wRGvgWMDKsYNYpTi8pSi3QNLfWSijLTM0pyEzNzdA0 NzPRyU4uLE9NTcxKTivWS83M3MQIDhQEIdjD+WBZwiFGSg0lJlDd7eVCEEF9SfkplRmJxRnxR aU5q8SFGGQ4OJQne9FNAOcGi1PTUirTMHGDIwqQlOHiURHhXnwRK8xYXJOYWZ6ZDpE4xGnNMe 7b4KRPHjs41T5mEWPLy81KlxHn/gJQKgJRmlObBDYLF0iVGWSlhXkag04R4ClKLcjNLUOVfMY pzMCoJ87qB3MOTmVcCt+8V0ClMQKeILvEHOaUkESEl1cBY6sswXeHxmclJK14s+fR/854OLh+ T79aPi06WlHa3Rl4SmGScmhnwPvbGjPkV0gVGazZqP/9xS2PRovZXPnMPqHQlvJy+zPyLSmOS wT+LLsOMcpH9r+N3lO4vrEuZWCCza1XWwzs3HD4xS8c9y7vj9XjCHJX3S35fbAj8e8TPN9rfU vvdmj2TlViKMxINtZiLihMBVrnC6qACAAA= X-Env-Sender: bhupinder.thakur@linaro.org X-Msg-Ref: server-4.tower-21.messagelabs.com!1481821054!42330317!1 X-Originating-IP: [74.125.83.42] 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 60997 invoked from network); 15 Dec 2016 16:57:35 -0000 Received: from mail-pg0-f42.google.com (HELO mail-pg0-f42.google.com) (74.125.83.42) by server-4.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 15 Dec 2016 16:57:35 -0000 Received: by mail-pg0-f42.google.com with SMTP id 3so21846898pgd.0 for ; Thu, 15 Dec 2016 08:57:35 -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; bh=WTsUW+fbe3QUf08rbZgw9KdcuBqN5T8NbipbCe9AUm8=; b=c0koOY0NfXx3UpbOy5j+1djO98ulNbtHouqBLQ2GPOqKWWoEQLFSMo7Tsb3/JTmpas ojEBPYpPuF+NbFVbYatM6G6rfQ8rFOq0bZyRPHb6LpLx/Q228VYBEHQOI2KdTtYiD7As pAmWssMnRJSP6cvy/LqE4DLENkrSQzHkEgx5c= 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=WTsUW+fbe3QUf08rbZgw9KdcuBqN5T8NbipbCe9AUm8=; b=VK4oYEBDhuFna0iPr8Tsa6huXTYbmbmMxw0+iPFbve6vPQ2uy4SzzdjW60SW6CiikP dmBWkpXdx2/tb1r/naws0yKJII1C8UuFtIGBawU1IPZSiQtg96MG+Jicv9/5aD217lKe zu3KNnn4zcGNFzv73++Wqh9dZrYwKY3Miz3q58GicNemmwhtE29n++HB2Tjw5pwG4L36 wuWZoxjZWhCQozJzYFUJc9Q4yYaNGqdugb7bHv2eJNAq49/OygjW6frCzmLne24Uy82s Wdm32zNCcRjgTP2erj1ZRmt6RYjjqvYq93MNKO1qC0qylMLa2t6fTY1dDv2x5tyA/itx LW5w== X-Gm-Message-State: AKaTC00hPqXxgA5YXWYUS8m/3LIkK3SWOgLfcSOoZ2OLgnSqWhe1XSKbUuf8Ej2Oo2dOfXaE X-Received: by 10.84.170.195 with SMTP id j61mr4392716plb.13.1481821054126; Thu, 15 Dec 2016 08:57:34 -0800 (PST) Received: from blr-ubuntu-linaro.wlan.qualcomm.com ([103.5.19.19]) by smtp.gmail.com with ESMTPSA id c8sm5871951pfe.15.2016.12.15.08.57.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Dec 2016 08:57:33 -0800 (PST) From: Bhupinder Thakur To: xen-devel@lists.xenproject.org Date: Thu, 15 Dec 2016 22:25:28 +0530 Message-Id: <1481820928-27394-1-git-send-email-bhupinder.thakur@linaro.org> X-Mailer: git-send-email 2.7.4 Cc: Julien Grall , Stefano Stabellini Subject: [Xen-devel] [XEN VMID PATCH 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 --- 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..61b9e49 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 {