From patchwork Fri Aug 1 11:00:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 34695 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 C324920540 for ; Fri, 1 Aug 2014 11:02:33 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id et14sf26589730pad.2 for ; Fri, 01 Aug 2014 04:02:33 -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: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=m6IGmsjWQb8nsen7NrUo2Pn8z0lsH3+toSK7UQzGwa0=; b=G1COG0D0xqfz+E4JOgdaPXJbnPQsHEHE6E9Yu4F1HZQToYIe8C0QqRSxs8GTcBT+9P Ek9x9kmyiKYWe+d16uRVL+Cl9Fxu3bvdLxirdkd+1atv72HJcEzFpAAVBZMT505+7zjN b56nooYFF1LwvnWx6Je5sdgpysxV7ya02LwcCLWUplUPr+7NcivVPJUWqX7I9VVUPSLF XCagQSdqCLCl7lzIJYyxo81deZ/JVWOvFhqqlCwPuw/ZKMdqHziJuKAexV1pm4SePMTe wlKEVQjLxgYTOHZhwNm1flNHUopNNw36EGjx7GnshXXLOriy55s5X21x9NzSTvvmmreo EQ1g== X-Gm-Message-State: ALoCoQnyAr3G/QLrZAbrGGRdSfXJklRevm03MAh1ldv1cs9qgpJ1lKHYGnRK/QMKXk9sMOu7SURR X-Received: by 10.68.135.99 with SMTP id pr3mr41715pbb.9.1406890952861; Fri, 01 Aug 2014 04:02:32 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.85.213 with SMTP id n79ls1273160qgd.29.gmail; Fri, 01 Aug 2014 04:02:32 -0700 (PDT) X-Received: by 10.220.195.67 with SMTP id eb3mr4811432vcb.30.1406890952749; Fri, 01 Aug 2014 04:02:32 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id ts6si6868316vdc.84.2014.08.01.04.02.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 01 Aug 2014 04:02:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.174 as permitted sender) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id la4so6370553vcb.33 for ; Fri, 01 Aug 2014 04:02:32 -0700 (PDT) X-Received: by 10.52.129.165 with SMTP id nx5mr3963974vdb.25.1406890952595; Fri, 01 Aug 2014 04:02:32 -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 tc5csp101279vcb; Fri, 1 Aug 2014 04:02:32 -0700 (PDT) X-Received: by 10.68.137.98 with SMTP id qh2mr5071538pbb.26.1406890951614; Fri, 01 Aug 2014 04:02:31 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id ul9si9349797pbc.40.2014.08.01.04.02.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Aug 2014 04:02:31 -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 1XDAa8-0001BK-KY; Fri, 01 Aug 2014 11:01:04 +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 1XDAa4-00014L-Tw for linux-arm-kernel@lists.infradead.org; Fri, 01 Aug 2014 11:01:01 +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 5CB6113F717; Fri, 1 Aug 2014 06:00:37 -0500 (CDT) From: Marc Zyngier To: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH] arm64: KVM: fix 64bit CP15 VM access for 32bit guests Date: Fri, 1 Aug 2014 12:00:36 +0100 Message-Id: <1406890836-7294-1-git-send-email-marc.zyngier@arm.com> X-Mailer: git-send-email 2.0.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140801_040101_013247_89844385 X-CRM114-Status: GOOD ( 12.48 ) 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 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Christoffer Dall , Victor Kamensky 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.174 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 Commit f0a3eaff71b8 (ARM64: KVM: fix big endian issue in access_vm_reg for 32bit guest) changed the way we handle CP15 VM accesses, so that all 64bit accesses are done via vcpu_sys_reg. This looks like a good idea as it solves indianness issues in an elegant way, except for one small detail: the register index is doesn't refer to the same array! We end up corrupting some random data structure instead. Fix this by reverting to the original code, except for the introduction of a vcpu_cp15_64_high macro that deals with the endianness thing. Tested on Juno with 32bit SMP guests. Cc: Victor Kamensky Cc: Christoffer Dall Signed-off-by: Marc Zyngier Reviewed-by: Christoffer Dall --- Christoffer, can you please have a look at this one and and queue it if you find it acceptable? Thanks, M. arch/arm64/include/asm/kvm_host.h | 6 ++++-- arch/arm64/kvm/sys_regs.c | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 79812be..e10c45a 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -149,9 +149,11 @@ struct kvm_vcpu_arch { #define vcpu_cp15(v,r) ((v)->arch.ctxt.copro[(r)]) #ifdef CONFIG_CPU_BIG_ENDIAN -#define vcpu_cp15_64_low(v,r) ((v)->arch.ctxt.copro[((r) + 1)]) +#define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r)) +#define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r) + 1) #else -#define vcpu_cp15_64_low(v,r) ((v)->arch.ctxt.copro[((r) + 0)]) +#define vcpu_cp15_64_high(v,r) vcpu_cp15((v),(r) + 1) +#define vcpu_cp15_64_low(v,r) vcpu_cp15((v),(r)) #endif struct kvm_vm_stat { diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index a4fd526..5805e7c 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -135,10 +135,13 @@ static bool access_vm_reg(struct kvm_vcpu *vcpu, BUG_ON(!p->is_write); val = *vcpu_reg(vcpu, p->Rt); - if (!p->is_aarch32 || !p->is_32bit) + if (!p->is_aarch32) { vcpu_sys_reg(vcpu, r->reg) = val; - else + } else { + if (!p->is_32bit) + vcpu_cp15_64_high(vcpu, r->reg) = val >> 32; vcpu_cp15_64_low(vcpu, r->reg) = val & 0xffffffffUL; + } return true; }