From patchwork Mon Jan 28 11:50:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156717 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333283jaa; Mon, 28 Jan 2019 03:52:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN7H9Fqt87+ueES+mpyIif8v/jd0h3fUj12J8557okImlWt68HQuYsHPEnmGhzjtfxeQQMOE X-Received: by 2002:a81:2e0b:: with SMTP id u11mr21109033ywu.412.1548676348716; Mon, 28 Jan 2019 03:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676348; cv=none; d=google.com; s=arc-20160816; b=Pg3NErNoKy+Q9pNMMPlQEVVQg3k7aCl+YjLnpLjuGn1TqJesALKifgNOLxSqWcfY6B 9TEv13aeqhost5O1GZgyY/MXjD8Od0TCVMZSXtvAkI1+9ZNu220/7yhKfDWrrpiCxwZR jjFyNL6Qw5gXYxBysoMu/CZPKDWM7Y7fFtSlJBGvj5op9zMHepVBVr8muU90DBKWygmB 7gOqh4YlSl5nR6XQljNNpEzOSIOZYVObISgSpuFR7O848882InAB3bBaHQ3RW9bZSug+ ziUKdMYJmsemG33vdOyzdtWjvZFgqmJdN47fxiST+guf4+x5V2WEgbJTTb33Mz0VbYPl OhLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=j/1p1O/yxvRLR5Jgk8tB+rLGOqGFv+Z67kk5IOVALkQ=; b=X43TDfRJof6Ru5QNsOKbJF/R10EoiuTrmm9dpiOtoTA7ZJ+EujH7vttX1VVbRMqwJq drP6VGBZ/JzwFsskfefKNkRp3m86wD532vAg7EZHU2HiZJ62EGeZLmPNhsA3cG+xVFsl Zl8i8vEQL39V4e9K6WeeGEqt4qckWF3ktPO4cAoFK0cXCdKDyqi3FwurfOt6qUy+umdC 2ClVHCL8YpjrkHYPsXHNBvmRp+cQ/wWhq/hIyMyOY/jDzXlPKWK8Udb7PXQWGzP5mkrL yV0TdUhM785J3gGuE7hhoE9ssYNrggm8zRDEI/bvfYwxl5J64zSXbnwR152Rsb5DirB7 iNgA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id q185si20317664ywf.50.2019.01.28.03.52.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qx-00034Y-MP; Mon, 28 Jan 2019 11:50:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qw-00034O-GN for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:34 +0000 X-Inumbo-ID: eb3606dc-22f2-11e9-bc5a-afb3584a4595 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id eb3606dc-22f2-11e9-bc5a-afb3584a4595; Mon, 28 Jan 2019 11:50:33 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5642015AD; Mon, 28 Jan 2019 03:50:33 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 695B53F59C; Mon, 28 Jan 2019 03:50:32 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:20 +0000 Message-Id: <20190128115026.3336-2-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 1/7] xen/arm: Only set necessary flags when initializing HCR_EL2 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: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Only {A,F,I}MO are necessary to receive interrupts until a guest vCPU is loaded. The rest have no effect on Xen and it is better to avoid setting them. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Fix typo - Add Andrii's and Stefano's reviewed-by --- xen/arch/arm/traps.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 221c762ada..64a78d83a5 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -157,8 +157,12 @@ void init_traps(void) WRITE_SYSREG((HCPTR_CP_MASK & ~(HCPTR_CP(10) | HCPTR_CP(11))) | HCPTR_TTA, CPTR_EL2); - /* Setup hypervisor traps */ - WRITE_SYSREG(get_default_hcr_flags(), HCR_EL2); + /* + * Configure HCR_EL2 with the bare minimum to run Xen until a guest + * is scheduled. {A,I,F}MO bits are set to allow EL2 receiving + * interrupts. + */ + WRITE_SYSREG(HCR_AMO | HCR_FMO | HCR_IMO, HCR_EL2); isb(); } From patchwork Mon Jan 28 11:50:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156714 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333243jaa; Mon, 28 Jan 2019 03:52:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN7mCQMdQ5sRGepGuWMeXZ+dkmDDDPE9bBjhEQZwCA9SUksBLV/24CLsfmvZf54vmgS+05Zi X-Received: by 2002:a25:2fd0:: with SMTP id v199mr19992222ybv.194.1548676345849; Mon, 28 Jan 2019 03:52:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676345; cv=none; d=google.com; s=arc-20160816; b=wFUdJAlZnVzyfc8PhXNgzl2CuMe+s0mLbp77Vc0MZYm4uk+TIbRVuNdCOyIVH/hHa1 MF5EZL/TPP+zcK7iFRv7UzgC1XGtBbM6CeTQig3/t/ogvXl9QPYnI7U3hxUQajC3/q10 7qs1eWQFn0ekpuDGtedOEErp4MRxQs0SmgLyMGd2JG0jBQ66MKoP0Awe9l9ocaHj8UK2 kPU9iPsuk+vi/f9Yyt1vXUbQKSt1R6wxKG0aZShR1SHeWj92CAYr+SiplIHH4CJrr4OH t41+RW5xV2jZRH3NrY2AOyKd1OS+gln0B/ZoGbdDy8yca8BlcqCfTCH0OtAvsrFX17Dc nQVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=tWQYAfjFw2fDTyceRNHUburZ+I14pa/6cXLkw1biBtQ=; b=WUunlhq/CRXTB6pX1QAyw0hLhWEAFWCGNJq6MhWlX307VWrox2Olx4GWxZew3CneDX TtN+SLFtp1jH7ecwmPbbcS/WEY4oCKDmBYYEjCvi9IqkE7/lUzNwdPdeRMxHF70/cD2o ZrqD70kdFaoeWMvcA4JD92/KW3cUuTxbsjyngA7SGwQqyrlHjhk2krW+y7H3CZHqb8Vv g8HQfYzd8SrsFLo7JjCRqMbyDj7AHWjDmFlwl095AcYxqO4IXteIv4MsqpZQl4BwnjL2 i9h5gBi4akTljTlSGeJp5wXGLM/FLFO9MQ0+Ba0l9kaKI4ex2WsVT9Iwq7Y2wBlAmM4c HZ5w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id h6si20480333ywf.363.2019.01.28.03.52.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qz-00034u-7K; Mon, 28 Jan 2019 11:50:37 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qx-00034b-Rb for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:35 +0000 X-Inumbo-ID: ebef88aa-22f2-11e9-b8be-b7a5f292b228 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id ebef88aa-22f2-11e9-b8be-b7a5f292b228; Mon, 28 Jan 2019 11:50:34 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 83BD9EBD; Mon, 28 Jan 2019 03:50:34 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9482E3F59C; Mon, 28 Jan 2019 03:50:33 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:21 +0000 Message-Id: <20190128115026.3336-3-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 2/7] xen/arm: p2m: Provide an helper to generate the VTTBR 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: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A follow-up patch will need to generate the VTTBR in a few places. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's and Stefano's reviewed-by --- xen/arch/arm/p2m.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 059a39157a..38bfa9964f 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -41,6 +41,11 @@ static const paddr_t level_masks[] = static const uint8_t level_orders[] = { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; +static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn) +{ + return (mfn_to_maddr(root_mfn) | ((uint64_t)vmid << 48)); +} + /* Unlock the flush and do a P2M TLB flush if necessary */ void p2m_write_unlock(struct p2m_domain *p2m) { @@ -1364,7 +1369,7 @@ static int p2m_alloc_table(struct domain *d) p2m->root = page; - p2m->vttbr = page_to_maddr(p2m->root) | ((uint64_t)p2m->vmid << 48); + p2m->vttbr = generate_vttbr(p2m->vmid, page_to_mfn(p2m->root)); /* * Make sure that all TLBs corresponding to the new VMID are flushed From patchwork Mon Jan 28 11:50:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156718 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333320jaa; Mon, 28 Jan 2019 03:52:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN7GgGGcFrMKnAEW38tmnKWrndM3gzUVKeyK1axftt9ALC833mpJfECO5B+YD9YECvx/vh8U X-Received: by 2002:a25:bb04:: with SMTP id z4mr21424534ybg.38.1548676350519; Mon, 28 Jan 2019 03:52:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676350; cv=none; d=google.com; s=arc-20160816; b=nfwcQmgOQFKPZrmacTRE2ljnk8DDF/idnKSFZehSs7f6HxcC81cMXfXHbu40lTdC2T xFNaDcE0numl9LoWX0Iw8gTCL3zBGlarFG1xrpUnBOHZYuTddzQ2xTC2pfX6yauf+whm 6UOZm4gr7IoSjES1TyKFmXZbfk06IqzZD5ZwjwbcL3h2hFm8AuQXd+TG9kEENjWSLevp icFBWQk8H6Fmz9qGBf7yFFoiu/dq1SsIEdInmZGBRJbKsvKoiAj+acZGFQ2Pi6mPibjt xoESUpThfnjZGTKFHBXPnYrGo9s/2a/fnnbNi+1HI7KvRItMxxRiaO/+hioNnqQdolpO UK5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Jezc4ZpQIXVvCSSWLXK1GmXcXGUrDir6qdKiidFuw8g=; b=BZ7rD+ETYJOI+8GnBMOYJIbEs594bH86nKPwF26SpP+Et5mrGasi/hSqiO0CRMb8ZJ MJooZkwicOjtXHVSr3FvLQES8uq3y8FknSR+DIZn7+rTMMbk+9Rcfhbo/D1zUdnxJ1TH suv4k+wu+SBTq+ylLptgrro8ZDdSaMNpxeYNirigBpnbis9OuZQ/HTnSoRbhHHM1wPCr 3njwjS167jdlwkTPM03HtA8ro92MPAXuYdERwmOMlRkHDYMY/h6glDQfYz/qFHv7jDj9 nlNqnxcQ7BI1a+x6+iTbUcmrqb7vrTPKyM7YxkU6pcXWksLpfShWMZ6Y+y42WRdZskTM WMtg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id i129si18659836yba.47.2019.01.28.03.52.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R0-00035F-L7; Mon, 28 Jan 2019 11:50:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qy-00034p-M8 for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:36 +0000 X-Inumbo-ID: eca345ba-22f2-11e9-aeee-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id eca345ba-22f2-11e9-aeee-bc764e045a96; Mon, 28 Jan 2019 11:50:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AD83315AD; Mon, 28 Jan 2019 03:50:35 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C13013F59C; Mon, 28 Jan 2019 03:50:34 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:22 +0000 Message-Id: <20190128115026.3336-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 3/7] xen/arm: p2m: Introduce an helper to allocate the root page-table 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: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" A follow-up patch will require to allocate the root page-table without having a domain in hand. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's and Stefano's reviewed-by --- xen/arch/arm/p2m.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 38bfa9964f..9844bfb936 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1353,21 +1353,29 @@ int guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn, return p2m_remove_mapping(d, gfn, (1 << page_order), mfn); } -static int p2m_alloc_table(struct domain *d) +static struct page_info *p2m_allocate_root(void) { - struct p2m_domain *p2m = p2m_get_hostp2m(d); struct page_info *page; unsigned int i; page = alloc_domheap_pages(NULL, P2M_ROOT_ORDER, 0); if ( page == NULL ) - return -ENOMEM; + return NULL; /* Clear both first level pages */ for ( i = 0; i < P2M_ROOT_PAGES; i++ ) clear_and_clean_page(page + i); - p2m->root = page; + return page; +} + +static int p2m_alloc_table(struct domain *d) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + + p2m->root = p2m_allocate_root(); + if ( !p2m->root ) + return -ENOMEM; p2m->vttbr = generate_vttbr(p2m->vmid, page_to_mfn(p2m->root)); From patchwork Mon Jan 28 11:50:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156713 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333239jaa; Mon, 28 Jan 2019 03:52:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN5EBLoILeBrt0ZFFM+t9D50e7cbASfckWonllQ1nTYWbSiCY0TB06JjQ/J0hIFmGLL47lcU X-Received: by 2002:a81:4ac6:: with SMTP id x189mr20761790ywa.249.1548676345584; Mon, 28 Jan 2019 03:52:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676345; cv=none; d=google.com; s=arc-20160816; b=iUaF6QI4kaclwqJwig/gYkh1Cfe3xHcjbRN+pDgkZq6/aTb815snYcTYeGEbXs+Yl9 HlwX6TpeOMsCWWA++q8cmFbTIp0ICTmq/kG9pdiLj03uJRNot9YIAWzF58SbnVWTuby1 1oZFhR7IgWdO9lt1oghjujcnrCbGyUWffHNxL7Ijo/pnzl/1T0+yGxxPlm8Ljqr6toX3 R3z2zKm9CtY9iWpU4ZmtoCwcMY6Hej+dTc8ogbIv11F/+NsvmZKzqTuUX8cJRUm8qBsj M3+hIc7LbhInOTPdLXquXmaPDVwKNO9B6Y8G8kWsRz4e78V+66VI2VBAUCBpeWQAaxWh wKsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=RNCcUnlWXdBb6E0ujhullIEVUGgG8lFiSP54bQbb3KA=; b=DVplhobDrMbqSwC4NXvmVX8H0scBYfzoZgqYj3cgo1LrEXi3xuGTLAO2CVwQp/KDsH 3KDoe4Q1mRORtJ+kOnM6e5xvUhc38TTt7QsVGkaJEIKSqe1RNRbNiraCIFjh+fHr15LN +KjThxYaQKwoDxOJyQFjBpILo5hBxuJndBPJgi8jl+pNl/e1uLeD7YIl88U4wGmHrihp UFgafbFXvqJKcIYWq7wri8LgvbjY8Jw9udoorgDP/xmVUw/Nelpiwys3r6nyCAo8Ku/B YZRN7wysv4XGdn5muwJKPloMGprT6uzyuBhq6ckAR1Yzfvo14pMAWUiCypogqke8Mya0 WmXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id k62si19699369ywd.392.2019.01.28.03.52.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R0-00035V-Ur; Mon, 28 Jan 2019 11:50:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5Qz-000350-Sd for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:37 +0000 X-Inumbo-ID: ed3a8998-22f2-11e9-aeee-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ed3a8998-22f2-11e9-aeee-bc764e045a96; Mon, 28 Jan 2019 11:50:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3965EBD; Mon, 28 Jan 2019 03:50:36 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EAD753F59C; Mon, 28 Jan 2019 03:50:35 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:23 +0000 Message-Id: <20190128115026.3336-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 4/7] xen/arm: domain_build: Don't switch to the guest P2M when copying data 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: Julien Grall , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Until recently, kernel/initrd/dtb were loaded using guest VA and therefore requiring to restore temporarily the P2M. This was reworked in a series of commits (up to 9292086 "xen/arm: domain_build: Use copy_to_guest_phys_flush_dcache in dtb_load") to use a guest PA. This will also help a follow-up patch which will require p2m_{save,restore}_state to work in pair to workaround an erratum. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Fix typo in commit message - Add Stefano's reviewed-by --- xen/arch/arm/domain_build.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d2c63a89ca..31af989e63 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1923,7 +1923,6 @@ static void __init find_gnttab_region(struct domain *d, static int __init construct_domain(struct domain *d, struct kernel_info *kinfo) { - struct vcpu *saved_current; int i, cpu; struct vcpu *v = d->vcpu[0]; struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs; @@ -1945,14 +1944,6 @@ static int __init construct_domain(struct domain *d, struct kernel_info *kinfo) #endif /* - * The following loads use the domain's p2m and require current to - * be a vcpu of the domain, temporarily switch - */ - saved_current = current; - p2m_restore_state(v); - set_current(v); - - /* * kernel_load will determine the placement of the kernel as well * as the initrd & fdt in RAM, so call it first. */ @@ -1961,10 +1952,6 @@ static int __init construct_domain(struct domain *d, struct kernel_info *kinfo) initrd_load(kinfo); dtb_load(kinfo); - /* Now that we are done restore the original p2m and current. */ - set_current(saved_current); - p2m_restore_state(saved_current); - memset(regs, 0, sizeof(*regs)); regs->pc = (register_t)kinfo->entry; From patchwork Mon Jan 28 11:50:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156716 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333285jaa; Mon, 28 Jan 2019 03:52:28 -0800 (PST) X-Google-Smtp-Source: ALg8bN5vgMt4zw7LN2jFm6eyDi+ykofxHNr588fRjnqdWxGcnnPINMEd97HJ60yldxqm2YUrQnEa X-Received: by 2002:a81:6a8a:: with SMTP id f132mr19424656ywc.212.1548676348735; Mon, 28 Jan 2019 03:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676348; cv=none; d=google.com; s=arc-20160816; b=h8MyaXpVdCi8eL2HIyB+wyIA5aqoqlTmBoMLt8005N6Hei2HzXlGakqZ48kvC541Tq 4JnDV1CwBsuhC6fSkGy695joi+DGJYZtVDD38WXxgs5VpBhkMFEbg6vIo9SRhHVebXlU TGsFpUNP/E+aPdF/p77glFynzbIxPU9lDWtYixnSwEZx5hZmCYjfiSKzsrBkZaEAofAc xH8xllwCNhTixVKEnJbSAToQLg2ANyRe2cR4g91IAoGjHqMEZcUAErwLRUcc9OGpRcOe rbe31us0CGwcEJ8do1lBQSGetwR+tZDvSmwnP6N6k9agrzOU7AlkradgG+5ahGZVRmRm HZbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=nmYWxgAvFTsq2ueUxcI2bQZt+Nc7ZiX6rS7MYQ/aM6o=; b=UFihULBtMnD+Pc0AZV8uFbvlei60F9HesNdtISV7IRn/TGaq0wkaZXKJXnd5lWBbuz n84ipvPkx9r13CD3oWg/OR2X7iCJnup26umHg/3XXJxqgTiLgENDI+0Th/8na5inJird uuXExJcPapKDixwfi2X9H+gmbIpW7WUPkkn4h7QpaJ+zA/bG32BJnv4YI8YVT+YoqVqQ zuP5rvBwoFUx9dbH5Ir8RVC33FHrJOrcG8VzaIecCXc0X2Nt928Q6azvahfzH1jHGsn3 O2AkMHjM3gWj1wXFK5g2d9QqcSsHKErkNBrJykTCBPCxZPIM2rm67t45Mbe5iRWZ/z/J BmLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a128si19855116ywf.375.2019.01.28.03.52.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R2-00035y-8P; Mon, 28 Jan 2019 11:50:40 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R1-00035Z-3i for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:39 +0000 X-Inumbo-ID: edf0be6b-22f2-11e9-aeee-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id edf0be6b-22f2-11e9-aeee-bc764e045a96; Mon, 28 Jan 2019 11:50:38 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DD28515AD; Mon, 28 Jan 2019 03:50:37 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F107C3F59C; Mon, 28 Jan 2019 03:50:36 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:24 +0000 Message-Id: <20190128115026.3336-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 5/7] xen/arm: p2m: Only use isb() when it is necessary 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: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The EL1 translation regime is out-of-context when running at EL2. This means the processor cannot speculate memory accesses using the registers associated to that regime. An isb() is only needed if Xen is going to use the translation regime before returning to the guest (exception returns will synchronize the context). Remove unnecessary isb() and document the ones left. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Remove pointless {} - Fix typoes - Add Andrii's reviewed-by --- xen/arch/arm/p2m.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 9844bfb936..44391a5f8c 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -106,17 +106,21 @@ void p2m_restore_state(struct vcpu *n) return; WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2); - isb(); - WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1); - isb(); - WRITE_SYSREG(n->arch.hcr_el2, HCR_EL2); - isb(); last_vcpu_ran = &p2m->last_vcpu_ran[smp_processor_id()]; /* + * While we are restoring an out-of-context translation regime + * we still need to ensure: + * - VTTBR_EL2 is synchronized before flushing the TLBs + * - All registers for EL1 are synchronized before executing an AT + * instructions targeting S1/S2. + */ + isb(); + + /* * Flush local TLB for the domain to prevent wrong TLB translation * when running multiple vCPU of the same domain on a single pCPU. */ @@ -147,6 +151,7 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) { local_irq_save(flags); WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2); + /* Ensure VTTBR_EL2 is synchronized before flushing the TLBs */ isb(); } @@ -155,6 +160,7 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) if ( ovttbr != READ_SYSREG64(VTTBR_EL2) ) { WRITE_SYSREG64(ovttbr, VTTBR_EL2); + /* Ensure VTTBR_EL2 is back in place before continuing. */ isb(); local_irq_restore(flags); } @@ -1907,7 +1913,6 @@ static uint32_t __read_mostly vtcr; static void setup_virt_paging_one(void *data) { WRITE_SYSREG32(vtcr, VTCR_EL2); - isb(); } void __init setup_virt_paging(void) From patchwork Mon Jan 28 11:50:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156720 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333351jaa; Mon, 28 Jan 2019 03:52:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN40wIu4XFCTH7sTIJp10tD437osVspYL+fjy0bEGOqejjKLRoodzxsfYaRyPF49OCIj+7Sz X-Received: by 2002:a25:7308:: with SMTP id o8mr20238370ybc.517.1548676352576; Mon, 28 Jan 2019 03:52:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676352; cv=none; d=google.com; s=arc-20160816; b=gMvrca60115+dNtKUQ3pWfsq2K6Wtrewc1MEi36Dg2Az7B7nUBD+Li8AGrFNzEdi4u DRron1Kdfctgmt4zotyZP0UP93OLlsTCvvOdHd7tpA5dK4+T6iCZBrcjlsujgzwpF71U CclL8+ilIAl9PWfz69CbZPteH1GYvu31bdonsiNkUanDNpQPeGPjWE9Bbl9f2TM072SZ TNlmk4YQJAZcwlwDIliWjds8uIOguUg3OR8SM/qqChT7d5/5dERDFP6N0ou1lAwmHbh7 jTC8cwJLt1xy3H+sKsdE6YLiEDx3O/yCDDnIcV3TG0RYmdkrxSP8XQgk/s4qHeKm39SE f7sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=ryWKBOolETSWduJrHH2rWe/D63aZ66WoB+lBgKTW090=; b=uTLF02yZE4ywWAIIceZiD4IVW5JADbGDdxEQ8Z2fgGKSKh83ZX+G7GarH8KOzU8/Yd l3EZQOkByz9YjNsvIjt8JPdC9SgJi7Nvhemj5Gz665PYIIrfZLlM8WkDOtIy9UIfQBoS xOhJi0dm6RqapuMGMmwEwapq07E//icRtYBZBPaq9NCxZC8G2OuM8HECjT2U5/XfrJV5 F2igT8Cw+w2F3AJnAeMOPda3e5b9jqahXrc8B+IbqShAgCzCfN5fcor96E+lcWZerfNf s5kEn/Io9b1CAntTWb8g0D/vfQKIC1U8ObSWnDvLF/HiJEdKLek1FZH3D8lC2GkiG6In uQMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id a188si19975535ywe.369.2019.01.28.03.52.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:32 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R4-00037g-H7; Mon, 28 Jan 2019 11:50:42 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R2-000369-MI for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:40 +0000 X-Inumbo-ID: eec673ae-22f2-11e9-a5d2-f7d37ba7b507 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id eec673ae-22f2-11e9-a5d2-f7d37ba7b507; Mon, 28 Jan 2019 11:50:39 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3FA81EBD; Mon, 28 Jan 2019 03:50:39 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 267203F59C; Mon, 28 Jan 2019 03:50:38 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:25 +0000 Message-Id: <20190128115026.3336-7-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 6/7] xen/arm: Implement workaround for Cortex-A76 erratum 1165522 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: Julien Grall , sstabellini@kernel.org, Andrii Anisov MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Early version of Cortex-A76 can end-up with corrupt TLBs if they speculate an AT instruction while the S1/S2 system registers are in an inconsistent state. This can happen during guest context switch and when invalidating the TLBs for other than the current VMID. The workaround implemented in Xen will: - Use an empty stage-2 with a reserved VMID while context switching between 2 guests - Use an empty stage-2 with the VMID where TLBs need to be flushed Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov --- Changes in v2: - Fix typo - Add Andrii's reviewed-by --- docs/misc/arm/silicon-errata.txt | 1 + xen/arch/arm/cpuerrata.c | 6 ++++ xen/arch/arm/domain.c | 8 +++-- xen/arch/arm/p2m.c | 78 ++++++++++++++++++++++++++++++++++++++-- xen/include/asm-arm/cpufeature.h | 3 +- xen/include/asm-arm/processor.h | 2 ++ 6 files changed, 93 insertions(+), 5 deletions(-) diff --git a/docs/misc/arm/silicon-errata.txt b/docs/misc/arm/silicon-errata.txt index 906bf5fd48..6cd1366f15 100644 --- a/docs/misc/arm/silicon-errata.txt +++ b/docs/misc/arm/silicon-errata.txt @@ -48,4 +48,5 @@ stable hypervisors. | ARM | Cortex-A57 | #852523 | N/A | | ARM | Cortex-A57 | #832075 | ARM64_ERRATUM_832075 | | ARM | Cortex-A57 | #834220 | ARM64_ERRATUM_834220 | +| ARM | Cortex-A76 | #1165522 | N/A | | ARM | MMU-500 | #842869 | N/A | diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c index f4815cafb4..4431b244fd 100644 --- a/xen/arch/arm/cpuerrata.c +++ b/xen/arch/arm/cpuerrata.c @@ -489,6 +489,12 @@ static const struct arm_cpu_capabilities arm_errata[] = { .matches = has_ssbd_mitigation, }, #endif + { + /* Cortex-A76 r0p0 - r2p0 */ + .desc = "ARM erratum 116522", + .capability = ARM64_WORKAROUND_AT_SPECULATE, + MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT), + }, {}, }; diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index 41f101746e..6dc633ed50 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -181,8 +181,6 @@ static void ctxt_switch_to(struct vcpu *n) if ( is_idle_vcpu(n) ) return; - p2m_restore_state(n); - vpidr = READ_SYSREG32(MIDR_EL1); WRITE_SYSREG32(vpidr, VPIDR_EL2); WRITE_SYSREG(n->arch.vmpidr, VMPIDR_EL2); @@ -235,6 +233,12 @@ static void ctxt_switch_to(struct vcpu *n) #endif isb(); + /* + * ARM64_WORKAROUND_AT_SPECULATE: The P2M should be restored after + * the stage-1 MMU sysregs have been restored. + */ + p2m_restore_state(n); + /* Control Registers */ WRITE_SYSREG(n->arch.cpacr, CPACR_EL1); diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 44391a5f8c..c38bd7e16e 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,8 @@ static const paddr_t level_masks[] = static const uint8_t level_orders[] = { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; +static mfn_t __read_mostly empty_root_mfn; + static uint64_t generate_vttbr(uint16_t vmid, mfn_t root_mfn) { return (mfn_to_maddr(root_mfn) | ((uint64_t)vmid << 48)); @@ -92,9 +95,25 @@ void dump_p2m_lookup(struct domain *d, paddr_t addr) P2M_ROOT_LEVEL, P2M_ROOT_PAGES); } +/* + * p2m_save_state and p2m_restore_state work in pair to workaround + * ARM64_WORKAROUND_AT_SPECULATE. p2m_save_state will set-up VTTBR to + * point to the empty page-tables to stop allocating TLB entries. + */ void p2m_save_state(struct vcpu *p) { p->arch.sctlr = READ_SYSREG(SCTLR_EL1); + + if ( cpus_have_const_cap(ARM64_WORKAROUND_AT_SPECULATE) ) + { + WRITE_SYSREG64(generate_vttbr(INVALID_VMID, empty_root_mfn), VTTBR_EL2); + /* + * Ensure VTTBR_EL2 is correctly synchronized so we can restore + * the next vCPU context without worrying about AT instruction + * speculation. + */ + isb(); + } } void p2m_restore_state(struct vcpu *n) @@ -105,10 +124,17 @@ void p2m_restore_state(struct vcpu *n) if ( is_idle_vcpu(n) ) return; - WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2); WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1); WRITE_SYSREG(n->arch.hcr_el2, HCR_EL2); + /* + * ARM64_WORKAROUND_AT_SPECULATE: VTTBR_EL2 should be restored after all + * registers associated to EL1/EL0 translations regime have been + * synchronized. + */ + asm volatile(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_AT_SPECULATE)); + WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2); + last_vcpu_ran = &p2m->last_vcpu_ran[smp_processor_id()]; /* @@ -149,8 +175,23 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) ovttbr = READ_SYSREG64(VTTBR_EL2); if ( ovttbr != p2m->vttbr ) { + uint64_t vttbr; + local_irq_save(flags); - WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2); + + /* + * ARM64_WORKAROUND_AT_SPECULATE: We need to stop AT to allocate + * TLBs entries because the context is partially modified. We + * only need the VMID for flushing the TLBs, so we can generate + * a new VTTBR with the VMID to flush and the empty root table. + */ + if ( !cpus_have_const_cap(ARM64_WORKAROUND_AT_SPECULATE) ) + vttbr = p2m->vttbr; + else + vttbr = generate_vttbr(p2m->vmid, empty_root_mfn); + + WRITE_SYSREG64(vttbr, VTTBR_EL2); + /* Ensure VTTBR_EL2 is synchronized before flushing the TLBs */ isb(); } @@ -1913,6 +1954,23 @@ static uint32_t __read_mostly vtcr; static void setup_virt_paging_one(void *data) { WRITE_SYSREG32(vtcr, VTCR_EL2); + + /* + * ARM64_WORKAROUND_AT_SPECULATE: We want to keep the TLBs free from + * entries related to EL1/EL0 translation regime until a guest vCPU + * is running. For that, we need to set-up VTTBR to point to an empty + * page-table and turn on stage-2 translation. The TLB entries + * associated with EL1/EL0 translation regime will also be flushed in case + * an AT instruction was speculated before hand. + */ + if ( cpus_have_cap(ARM64_WORKAROUND_AT_SPECULATE) ) + { + WRITE_SYSREG64(generate_vttbr(INVALID_VMID, empty_root_mfn), VTTBR_EL2); + WRITE_SYSREG(READ_SYSREG(HCR_EL2) | HCR_VM, HCR_EL2); + isb(); + + flush_tlb_all_local(); + } } void __init setup_virt_paging(void) @@ -1996,6 +2054,22 @@ void __init setup_virt_paging(void) /* It is not allowed to concatenate a level zero root */ BUG_ON( P2M_ROOT_LEVEL == 0 && P2M_ROOT_ORDER > 0 ); vtcr = val; + + /* + * ARM64_WORKAROUND_AT_SPECULATE requires to allocate root table + * with all entries zeroed. + */ + if ( cpus_have_cap(ARM64_WORKAROUND_AT_SPECULATE) ) + { + struct page_info *root; + + root = p2m_allocate_root(); + if ( !root ) + panic("Unable to allocate root table for ARM64_WORKAROUND_AT_SPECULATE\n"); + + empty_root_mfn = page_to_mfn(root); + } + setup_virt_paging_one(NULL); smp_call_function(setup_virt_paging_one, NULL, 1); } diff --git a/xen/include/asm-arm/cpufeature.h b/xen/include/asm-arm/cpufeature.h index 17de928467..c2c8f3417c 100644 --- a/xen/include/asm-arm/cpufeature.h +++ b/xen/include/asm-arm/cpufeature.h @@ -45,8 +45,9 @@ #define ARM_HARDEN_BRANCH_PREDICTOR 7 #define ARM_SSBD 8 #define ARM_SMCCC_1_1 9 +#define ARM64_WORKAROUND_AT_SPECULATE 10 -#define ARM_NCAPS 10 +#define ARM_NCAPS 11 #ifndef __ASSEMBLY__ diff --git a/xen/include/asm-arm/processor.h b/xen/include/asm-arm/processor.h index cb781751a6..b5f515805d 100644 --- a/xen/include/asm-arm/processor.h +++ b/xen/include/asm-arm/processor.h @@ -52,6 +52,7 @@ #define ARM_CPU_PART_CORTEX_A72 0xD08 #define ARM_CPU_PART_CORTEX_A73 0xD09 #define ARM_CPU_PART_CORTEX_A75 0xD0A +#define ARM_CPU_PART_CORTEX_A76 0xD0B #define MIDR_CORTEX_A12 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A12) #define MIDR_CORTEX_A17 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A17) @@ -61,6 +62,7 @@ #define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72) #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73) #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75) +#define MIDR_CORTEX_A76 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76) /* MPIDR Multiprocessor Affinity Register */ #define _MPIDR_UP (30) From patchwork Mon Jan 28 11:50:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 156715 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3333256jaa; Mon, 28 Jan 2019 03:52:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN7EAXNkfFuKiFirW3g0EwlSEKGvvnMospCno1jWtBRD/kgPvesieSKufdotArflRHO/yP8/ X-Received: by 2002:a81:6e43:: with SMTP id j64mr20790962ywc.171.1548676347074; Mon, 28 Jan 2019 03:52:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548676347; cv=none; d=google.com; s=arc-20160816; b=wOegvHln6PAdldzRvL5NquporHtvyg4QtBorYMHppLGfh1Ov4j3hLL/aRccAy4+7/b PbMnLEmOQ1eKWKowmLA80i5YpGdkTALZZI8rsHcp8KPdNiDZWVFzvo/nhrf3RqEepTHm 98vjk4LzrVfmZemY69fxef7KMtaecydKR4p+wnCukgSLvd1lD0unMwmgnyVAzN39Y1SE ASLDV6Y+iaVocTzOAIAZBmzVt2mWomFdP/27b7MAy3RTUDv7NfYzOFLRIMH3iw/zAT7Z TOagsppN+AFngjDbHKGfsJQr1FXvYooxrktn6raDVshwSL0NsLxvVl3zkN9Op9XcAYcU +25Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=KFRAL5qS8kNnsYO/ZVRTeHQF+qPF5nXDN8AjZFVWLNs=; b=lOOm1qO4wZvmCjQhdD0AYFVdM8RvZYyQo9jR+THkFcGojZHvHXjhnB2DesIsjhQm6z akQR4MsaEJ5+4i43aJcnAUn4emst84EthF9/ZGZFzb+rmkauzx3hTy1DDZzfh6neFoE2 ItNHjgfC9Z0PA24ve6KlaZQ5gzTyzt4rllVnq4xmrChtA3n9Ame5by5UgGVIOhYAlo17 GoAM3MUoVr17Ft4JHUsmEiSgQPq03vkRbdC5TFcjElfYC5os5iZnX+F9pcOooljiT/zA fwBNKCBSjPVVbFcBYkPrRJMDN9NLcYiJmLuC/SaTNHuECrQM+vZXKyYnUI7cg32UjEsa YU4w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id 63si10638830ybi.465.2019.01.28.03.52.26 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 28 Jan 2019 03:52:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R4-00038B-Sl; Mon, 28 Jan 2019 11:50:42 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1go5R3-00037B-C4 for xen-devel@lists.xenproject.org; Mon, 28 Jan 2019 11:50:41 +0000 X-Inumbo-ID: ef5b594a-22f2-11e9-aeee-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ef5b594a-22f2-11e9-aeee-bc764e045a96; Mon, 28 Jan 2019 11:50:40 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 45B4B15AD; Mon, 28 Jan 2019 03:50:40 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7CF203F59C; Mon, 28 Jan 2019 03:50:39 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 28 Jan 2019 11:50:26 +0000 Message-Id: <20190128115026.3336-8-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190128115026.3336-1-julien.grall@arm.com> References: <20190128115026.3336-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 7/7] DO NOT APPLY Allow testing the new AT speculate workaround code 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: Julien Grall , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Signed-off-by: Julien Grall --- xen/arch/arm/cpuerrata.c | 10 ++++++++++ xen/arch/arm/p2m.c | 2 ++ 2 files changed, 12 insertions(+) diff --git a/xen/arch/arm/cpuerrata.c b/xen/arch/arm/cpuerrata.c index 4431b244fd..727c67451d 100644 --- a/xen/arch/arm/cpuerrata.c +++ b/xen/arch/arm/cpuerrata.c @@ -381,6 +381,11 @@ static bool has_ssbd_mitigation(const struct arm_cpu_capabilities *entry) } #endif +static bool has_at_speculate(const struct arm_cpu_capabilities *entry) +{ + return true; +} + #define MIDR_RANGE(model, min, max) \ .matches = is_affected_midr_range, \ .midr_model = model, \ @@ -495,6 +500,11 @@ static const struct arm_cpu_capabilities arm_errata[] = { .capability = ARM64_WORKAROUND_AT_SPECULATE, MIDR_RANGE(MIDR_CORTEX_A76, 0, 2 << MIDR_VARIANT_SHIFT), }, + { + .desc = "AT speculate", + .capability = ARM64_WORKAROUND_AT_SPECULATE, + .matches = has_at_speculate, + }, {}, }; diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index c38bd7e16e..2b25706823 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -124,6 +124,8 @@ void p2m_restore_state(struct vcpu *n) if ( is_idle_vcpu(n) ) return; + ASSERT(READ_SYSREG64(VTTBR_EL2) == (generate_vttbr(INVALID_VMID, empty_root_mfn))); + WRITE_SYSREG(n->arch.sctlr, SCTLR_EL1); WRITE_SYSREG(n->arch.hcr_el2, HCR_EL2);