From patchwork Wed May 7 15:20:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 29801 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2BE03202E4 for ; Wed, 7 May 2014 15:24:25 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf5564375iec.0 for ; Wed, 07 May 2014 08:24:25 -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=wa7Y7z27kGWxSXW6yXtyhcYNPHZjo7zDEPfxw7/SBzg=; b=kUklc97EcEViCtII3RSIphGN5RRpMCE1qrMy62CmV8pujIfUoiKY2PRv8vVD/ExSV1 OlN7gfO3nFYAqR/ksIMFQG0DanTnRbpTvFTo2jyPD+1yuloCYKoL1HMwZeC38d+NZ1+V WLs6PabIL3Gl1PkUYB2jrKkFR2djlPK0lS9HX290Mot/FYmFGGmsFUMMFkFannQ86qOk feZWRkAUQtNCclBJEqXlFdzSXMW3ht2V4NjsNhRhGks9ikK6iSQrPD+bDEAEIPS6CKpU inOdAsSOuvJ6exsBSPOUsr6rh1NfPrBTW1FOzH+SirAKF2PyXQFwyD2jz1U1B5Z9j5L7 EmZQ== X-Gm-Message-State: ALoCoQmeSGUNFnchjuGIiuhj4lGh6xlTXjZ1Ad9k64CA9bSI+IpYWSa86hb57QjvaA/9DK/aXmLN X-Received: by 10.182.28.99 with SMTP id a3mr4738903obh.40.1399476265250; Wed, 07 May 2014 08:24:25 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.97.99 with SMTP id l90ls266238qge.13.gmail; Wed, 07 May 2014 08:24:25 -0700 (PDT) X-Received: by 10.58.105.105 with SMTP id gl9mr39146171veb.3.1399476265107; Wed, 07 May 2014 08:24:25 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id gq7si1798477vdc.158.2014.05.07.08.24.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 07 May 2014 08:24:25 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id hr9so1500924vcb.3 for ; Wed, 07 May 2014 08:24:25 -0700 (PDT) X-Received: by 10.52.227.138 with SMTP id sa10mr20604269vdc.25.1399476265041; Wed, 07 May 2014 08:24:25 -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.220.221.72 with SMTP id ib8csp318849vcb; Wed, 7 May 2014 08:24:23 -0700 (PDT) X-Received: by 10.140.30.99 with SMTP id c90mr60752916qgc.13.1399476262684; Wed, 07 May 2014 08:24:22 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id m6si6889103qay.149.2014.05.07.08.24.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 May 2014 08:24:22 -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 1Wi3gV-0000bN-Sr; Wed, 07 May 2014 15:23:03 +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 1Wi3fC-0007Cp-Ja for linux-arm-kernel@lists.infradead.org; Wed, 07 May 2014 15:21:43 +0000 Received: from e102391-lin.cambridge.arm.com (e102391-lin.cambridge.arm.com [10.1.209.166]) by collaborate-mta1.arm.com (Postfix) with ESMTP id 2D54513FAA0; Wed, 7 May 2014 10:21:03 -0500 (CDT) From: Marc Zyngier To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org Subject: [PATCH 6/9] arm64: KVM: check ordering of all system register tables Date: Wed, 7 May 2014 16:20:51 +0100 Message-Id: <1399476054-21571-7-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1399476054-21571-1-git-send-email-marc.zyngier@arm.com> References: <1399476054-21571-1-git-send-email-marc.zyngier@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140507_082142_716534_D0AA68A1 X-CRM114-Status: GOOD ( 12.46 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Catalin Marinas , Will Deacon , Ian Campbell , Christoffer Dall X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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...). 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 91ca0e4..c27a5cd 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -1280,14 +1280,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++)