From patchwork Mon Aug 4 08:47:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 34813 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f72.google.com (mail-yh0-f72.google.com [209.85.213.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8DD2D20F2E for ; Mon, 4 Aug 2014 09:00:58 +0000 (UTC) Received: by mail-yh0-f72.google.com with SMTP id f73sf25489076yha.3 for ; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=flTtfredaNLtIsL+W5YuN+QAJs6s8NcwTVoS/hjWK38=; b=QIz1agjH7jtJcmfJxYIm0napp/Bu1dBvQQcUImNVeJZNMClfNRWjJkd7Pjo62V7DDW y/srgxDqDgqpPyD6T74o951obPQqoAi3hJtJYpKqTJosLD6nK0ogh34+qtzqx3Z8gJNV BJTeKibR6EXQJXMCjLvDcZjGvtTSgYdDxNfyExfbGP1mMQjZS5+pCRJ982/3RqmFroWD 15JPlPnhuIxX3HdyIWt3MQGMgwXtDJOWlOw8EjGm7x8MtTW9jsqq7iquYgkbbmY+LuoV 547zkfQ4a7IbqaJ3alwqO4E+G26JOd/LWAaL9Qsot2YnEH8UIdLrFotogbRP1c5mxTBS qUbQ== X-Gm-Message-State: ALoCoQn3a1kkRQAS2IYsEW+UVPfPLXGo3K4KzlR8zIJXoSIktlmtoS3k04rMYGz20a92FvJbJipD X-Received: by 10.224.169.20 with SMTP id w20mr6358500qay.4.1407142858395; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.34.44 with SMTP id k41ls2203494qgk.78.gmail; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) X-Received: by 10.220.3.79 with SMTP id 15mr403203vcm.63.1407142858298; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) Received: from mail-vc0-f169.google.com (mail-vc0-f169.google.com [209.85.220.169]) by mx.google.com with ESMTPS id fw8si11525993vdc.60.2014.08.04.02.00.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 04 Aug 2014 02:00:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) client-ip=209.85.220.169; Received: by mail-vc0-f169.google.com with SMTP id le20so10422462vcb.14 for ; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) X-Received: by 10.221.25.210 with SMTP id rj18mr21918991vcb.5.1407142858201; Mon, 04 Aug 2014 02:00:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp288783vcb; Mon, 4 Aug 2014 02:00:57 -0700 (PDT) X-Received: by 10.68.201.68 with SMTP id jy4mr22664440pbc.64.1407142857322; Mon, 04 Aug 2014 02:00:57 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id gk1si16909340pbd.79.2014.08.04.02.00.56 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Aug 2014 02:00:57 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XEE7A-0007Ai-H8; Mon, 04 Aug 2014 08:59:32 +0000 Received: from mail-la0-f50.google.com ([209.85.215.50]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XEDx4-0002e2-AM for linux-arm-kernel@lists.infradead.org; Mon, 04 Aug 2014 08:49:06 +0000 Received: by mail-la0-f50.google.com with SMTP id gf5so5085565lab.23 for ; Mon, 04 Aug 2014 01:48:44 -0700 (PDT) X-Received: by 10.112.5.170 with SMTP id t10mr21376492lbt.54.1407142124001; Mon, 04 Aug 2014 01:48:44 -0700 (PDT) Received: from localhost.localdomain (188-178-240-98-static.dk.customer.tdc.net. [188.178.240.98]) by mx.google.com with ESMTPSA id px1sm26731207lbb.46.2014.08.04.01.48.35 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 Aug 2014 01:48:39 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , Gleb Natapov Subject: [GIT PULL 45/51] arm64: KVM: check ordering of all system register tables Date: Mon, 4 Aug 2014 10:47:02 +0200 Message-Id: <1407142028-31105-46-git-send-email-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1407142028-31105-1-git-send-email-christoffer.dall@linaro.org> References: <1407142028-31105-1-git-send-email-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140804_014906_563512_1208358B X-CRM114-Status: GOOD ( 14.45 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.50 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.215.50 listed in wl.mailspike.net] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: christoffer.dall@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.169 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Marc Zyngier 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...). Reviewed-by: Anup Patel Reviewed-by: Christoffer Dall Signed-off-by: Marc Zyngier --- arch/arm64/kvm/sys_regs.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 499a351..8ab47c7 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1308,14 +1308,32 @@ int kvm_arm_copy_sys_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) return write_demux_regids(uindices); } +static int check_sysreg_table(const struct sys_reg_desc *table, unsigned int n) +{ + unsigned int i; + + for (i = 1; i < n; i++) { + if (cmp_sys_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_sys_reg_table_init(void) { unsigned int i; struct sys_reg_desc clidr; /* Make sure tables are unique and in order. */ - for (i = 1; i < ARRAY_SIZE(sys_reg_descs); i++) - BUG_ON(cmp_sys_reg(&sys_reg_descs[i-1], &sys_reg_descs[i]) >= 0); + BUG_ON(check_sysreg_table(sys_reg_descs, ARRAY_SIZE(sys_reg_descs))); + BUG_ON(check_sysreg_table(cp14_regs, ARRAY_SIZE(cp14_regs))); + BUG_ON(check_sysreg_table(cp14_64_regs, ARRAY_SIZE(cp14_64_regs))); + BUG_ON(check_sysreg_table(cp15_regs, ARRAY_SIZE(cp15_regs))); + BUG_ON(check_sysreg_table(cp15_64_regs, ARRAY_SIZE(cp15_64_regs))); + BUG_ON(check_sysreg_table(invariant_sys_regs, ARRAY_SIZE(invariant_sys_regs))); /* We abuse the reset function to overwrite the table itself. */ for (i = 0; i < ARRAY_SIZE(invariant_sys_regs); i++)