From patchwork Fri Jun 20 13:00:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 32276 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 12D1F203F4 for ; Fri, 20 Jun 2014 13:03:06 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id eu11sf13300881pac.6 for ; Fri, 20 Jun 2014 06:03:05 -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=ho1OmO4nkUhE0Rr/gDq5eSQHjMXo2BLk2EuM/KnO31E=; b=M9s84PuqZyhCEgdFC5WfXTpQMXwXBVMhEdr1pXzuqFVv+A6DH6jeydVvf9MxFm9S4f 1WskwCncSVJdNkTQrDwuhiyafuWDDNJy85ZnIqh4y8Raa5zxqEKwDO3mSuFaCTsx7bFH McaRx2IZU2arNH6Jkr9a80aKNLE+ZBKpf+qJb2zvq9k+tiE+QViz8/9t7BUAV3u8g8wL Y3x1H4t45Vi6ZZP9O+14qFeviQ1NXp/ZMFmG1hKvz2qRoHkZUOgJXfJe4aLRi9PUbiP8 CU7nYvQ94DP6NlpSP8KGHI2fa/DJpcZgkaMXH5m9UJnVImI3Z2DUqjGIuzE2vTYLzXdU APEQ== X-Gm-Message-State: ALoCoQk3jJ4wSFAHuLjeSiidfGjfPBdKlXzXAQVYD0Z7jY1gKV2ErzxRaJL6PVQnwDMklm8V0u/B X-Received: by 10.66.189.163 with SMTP id gj3mr1403171pac.32.1403269385365; Fri, 20 Jun 2014 06:03:05 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.36 with SMTP id o33ls971950qgo.76.gmail; Fri, 20 Jun 2014 06:03:05 -0700 (PDT) X-Received: by 10.52.101.168 with SMTP id fh8mr2360678vdb.34.1403269385262; Fri, 20 Jun 2014 06:03:05 -0700 (PDT) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by mx.google.com with ESMTPS id xn4si3950409veb.37.2014.06.20.06.03.05 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 06:03:05 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.181 as permitted sender) client-ip=209.85.220.181; Received: by mail-vc0-f181.google.com with SMTP id il7so3361621vcb.40 for ; Fri, 20 Jun 2014 06:03:05 -0700 (PDT) X-Received: by 10.220.105.136 with SMTP id t8mr2831934vco.13.1403269385196; Fri, 20 Jun 2014 06:03:05 -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 tc5csp20757vcb; Fri, 20 Jun 2014 06:03:04 -0700 (PDT) X-Received: by 10.224.66.70 with SMTP id m6mr4791961qai.55.1403269384678; Fri, 20 Jun 2014 06:03:04 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id i10si10667284qan.100.2014.06.20.06.03.04 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jun 2014 06:03:04 -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 1WxyRs-0002Zv-8K; Fri, 20 Jun 2014 13:01:44 +0000 Received: from fw-tnat.austin.arm.com ([217.140.110.23] helo=collaborate-mta1.arm.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxyR9-00029k-HT for linux-arm-kernel@lists.infradead.org; Fri, 20 Jun 2014 13:01:03 +0000 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.143]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 1782213FB3D; Fri, 20 Jun 2014 08:00:13 -0500 (CDT) From: Marc Zyngier To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v3 6/9] arm64: KVM: check ordering of all system register tables Date: Fri, 20 Jun 2014 14:00:04 +0100 Message-Id: <1403269207-1625-7-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1403269207-1625-1-git-send-email-marc.zyngier@arm.com> References: <1403269207-1625-1-git-send-email-marc.zyngier@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140620_060059_623235_291CA054 X-CRM114-Status: GOOD ( 12.27 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain Cc: Anup Patel , Christoffer Dall 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: marc.zyngier@arm.com 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.181 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 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 1fb1bff..9147b0c 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1299,14 +1299,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++)