From patchwork Sat May 16 04:45:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhichao Huang X-Patchwork-Id: 6419001 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 82CB2C0432 for ; Sat, 16 May 2015 04:46:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EA0E203AA for ; Sat, 16 May 2015 04:46:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9B73020204 for ; Sat, 16 May 2015 04:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934413AbbEPEqj (ORCPT ); Sat, 16 May 2015 00:46:39 -0400 Received: from mail-pa0-f42.google.com ([209.85.220.42]:35484 "EHLO mail-pa0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934372AbbEPEqi (ORCPT ); Sat, 16 May 2015 00:46:38 -0400 Received: by pacwv17 with SMTP id wv17so47573244pac.2 for ; Fri, 15 May 2015 21:46:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/2aARMFIpdthtlXXYqM/n1X15ob4eOfryxWsxwWUnJo=; b=TlstkZiq31KsfenaQbXvzroiHFOQiAeB1r3Gp/daF2VxjJy8mGx3WSHyg/Qw1t96xM eGt3c73s7fbcpPHIe8lc/9vdmoGAgMjrbayS5SQLCAwiEGIho0nLskO+x29jgGUu6YaG vPXVCk8ZOwCkxCPQ/HmvqigUCqy/yEN0joc5hEXgh7/i6z2U+SdJjNxhH+u6FsyfHDvI W351dIY53OkNVHVOD50D+G3M64hizmrsTkbSF/kiuM6En6f0lzWIeLblmdlJcMrfZEWJ pQ13IlNi142Mw6CGgonU4uvQxVYEs7BTp+AOo0SQknskhbdDH6zL8HHSxa39MEkQrjmb enpw== X-Gm-Message-State: ALoCoQndeE7JuMtJvZ1G6tHD1pGnIgkucpE8qzGp2cUmUylKksrRV82eoPcOJZbf4jtaPLs79aLZ X-Received: by 10.66.177.238 with SMTP id ct14mr24341487pac.121.1431751598466; Fri, 15 May 2015 21:46:38 -0700 (PDT) Received: from localhost ([167.160.116.91]) by mx.google.com with ESMTPSA id ms7sm3384279pdb.11.2015.05.15.21.46.35 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 15 May 2015 21:46:37 -0700 (PDT) From: Zhichao Huang To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, alex.bennee@linaro.org Cc: huangzhichao@huawei.com, Zhichao Huang Subject: [PATCH 05/10] KVM: arm: check ordering of all system register tables Date: Sat, 16 May 2015 12:45:46 +0800 Message-Id: <1431751551-4788-6-git-send-email-zhichao.huang@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> References: <1431751551-4788-1-git-send-email-zhichao.huang@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We now have multiple tables for the various system registers we trap. Make sure we check the order of all of them, as it is critical that we get the order right (been there, done that...). Signed-off-by: Zhichao Huang --- arch/arm/kvm/coproc.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index d23395b..16d5f69 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -737,6 +737,9 @@ static struct coproc_reg invariant_cp15[] = { { CRn( 0), CRm( 0), Op1( 0), Op2( 3), is32, NULL, get_TLBTR }, { CRn( 0), CRm( 0), Op1( 0), Op2( 6), is32, NULL, get_REVIDR }, + { CRn( 0), CRm( 0), Op1( 1), Op2( 1), is32, NULL, get_CLIDR }, + { CRn( 0), CRm( 0), Op1( 1), Op2( 7), is32, NULL, get_AIDR }, + { CRn( 0), CRm( 1), Op1( 0), Op2( 0), is32, NULL, get_ID_PFR0 }, { CRn( 0), CRm( 1), Op1( 0), Op2( 1), is32, NULL, get_ID_PFR1 }, { CRn( 0), CRm( 1), Op1( 0), Op2( 2), is32, NULL, get_ID_DFR0 }, @@ -752,9 +755,6 @@ static struct coproc_reg invariant_cp15[] = { { CRn( 0), CRm( 2), Op1( 0), Op2( 3), is32, NULL, get_ID_ISAR3 }, { CRn( 0), CRm( 2), Op1( 0), Op2( 4), is32, NULL, get_ID_ISAR4 }, { CRn( 0), CRm( 2), Op1( 0), Op2( 5), is32, NULL, get_ID_ISAR5 }, - - { CRn( 0), CRm( 0), Op1( 1), Op2( 1), is32, NULL, get_CLIDR }, - { CRn( 0), CRm( 0), Op1( 1), Op2( 7), is32, NULL, get_AIDR }, }; /* @@ -1297,13 +1297,29 @@ int kvm_arm_copy_coproc_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +static int check_sysreg_table(const struct coproc_reg *table, unsigned int n) +{ + unsigned int i; + + for (i = 1; i < n; i++) { + if (cmp_reg(&table[i-1], &table[i]) >= 0) { + kvm_err("sys_reg table %p out of order (%d)\n", + table, i - 1); + return 1; + } + } + + return 0; +} + void kvm_coproc_table_init(void) { unsigned int i; /* Make sure tables are unique and in order. */ - for (i = 1; i < ARRAY_SIZE(cp15_regs); i++) - BUG_ON(cmp_reg(&cp15_regs[i-1], &cp15_regs[i]) >= 0); + BUG_ON(check_sysreg_table(cp14_regs, ARRAY_SIZE(cp14_regs))); + BUG_ON(check_sysreg_table(cp15_regs, ARRAY_SIZE(cp15_regs))); + BUG_ON(check_sysreg_table(invariant_cp15, ARRAY_SIZE(invariant_cp15))); /* We abuse the reset function to overwrite the table itself. */ for (i = 0; i < ARRAY_SIZE(invariant_cp15); i++)