From patchwork Fri Apr 24 05:27:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 47492 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 20C3320553 for ; Fri, 24 Apr 2015 05:30:03 +0000 (UTC) Received: by labgx2 with SMTP id gx2sf9444014lab.1 for ; Thu, 23 Apr 2015 22:30:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=xjFeihws0h2nPJOMg0ZV1Th5h5Wl6jGSxwbrYxjz5rU=; b=H+Hi3/lsm5P1/fTxLOxCov6Dk8E00aUXXFr1KvbN+bMhNCpv2E3yQxIlGnzIAbVkB8 9ustQ6C6tfN30D+tnesjHX/T7lECthmgx/at1Yw30O4hVGb3gwq25qekqX5+z3KeugR1 IQZI9GPIvi23C9+dA9Lnpt/hN1YVMRgWbS+//faDDHQJ8t0IF82lkBnLucFE+av02rbI x3TfKDyZXTyG6U2S02KIPk/P5UerXLS2rvvzvTX4Wa5qcyu78vvnbX4RYlDzMZwawwaT Bi9jhXSnVtL7vVcj8adpPXLzfSXsvAw8AVAJlzRHX0oHGCuCTuFwacupMfHV8xzW+PRl xvPg== X-Gm-Message-State: ALoCoQlmH33bH6kJ/xIvborY907fHqn9SKZCtsMxWFRSPSaFuJLzCHzsTp1aUuFvT1ypVuZzrDi/ X-Received: by 10.112.162.228 with SMTP id yd4mr3158783lbb.8.1429853402070; Thu, 23 Apr 2015 22:30:02 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.38 with SMTP id p6ls372197lap.17.gmail; Thu, 23 Apr 2015 22:30:01 -0700 (PDT) X-Received: by 10.152.207.41 with SMTP id lt9mr5380053lac.52.1429853401789; Thu, 23 Apr 2015 22:30:01 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id aw7si7468539lbc.80.2015.04.23.22.30.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Apr 2015 22:30:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbuc2 with SMTP id uc2so28517569lbb.2 for ; Thu, 23 Apr 2015 22:30:01 -0700 (PDT) X-Received: by 10.152.87.204 with SMTP id ba12mr5543537lab.35.1429853401364; Thu, 23 Apr 2015 22:30:01 -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.112.67.65 with SMTP id l1csp977014lbt; Thu, 23 Apr 2015 22:30:00 -0700 (PDT) X-Received: by 10.68.246.38 with SMTP id xt6mr11574619pbc.20.1429853398660; Thu, 23 Apr 2015 22:29:58 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gw3si15799508pac.117.2015.04.23.22.29.57; Thu, 23 Apr 2015 22:29:58 -0700 (PDT) Received-SPF: none (google.com: stable-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752880AbbDXF35 (ORCPT + 2 others); Fri, 24 Apr 2015 01:29:57 -0400 Received: from mail-ob0-f171.google.com ([209.85.214.171]:34777 "EHLO mail-ob0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750877AbbDXF34 (ORCPT ); Fri, 24 Apr 2015 01:29:56 -0400 Received: by obfe9 with SMTP id e9so30170378obf.1 for ; Thu, 23 Apr 2015 22:29:56 -0700 (PDT) X-Received: by 10.60.70.140 with SMTP id m12mr1034874oeu.32.1429853396027; Thu, 23 Apr 2015 22:29:56 -0700 (PDT) Received: from localhost ([167.160.116.36]) by mx.google.com with ESMTPSA id cd3sm6012798oec.2.2015.04.23.22.29.53 (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 23 Apr 2015 22:29:55 -0700 (PDT) From: shannon.zhao@linaro.org To: stable@vger.kernel.org Cc: jslaby@suse.cz, christoffer.dall@linaro.org, shannon.zhao@linaro.org, Marc Zyngier Subject: [PATCH for 3.12.y stable 07/63] arm/arm64: KVM: PSCI: use MPIDR to identify a target CPU Date: Fri, 24 Apr 2015 13:27:05 +0800 Message-Id: <1429853281-6136-8-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> References: <1429853281-6136-1-git-send-email-shannon.zhao@linaro.org> Sender: stable-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: stable@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: shannon.zhao@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.217.173 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Marc Zyngier commit 79c648806f9034abf54332b78043bb242189d953 upstream. The KVM PSCI code blindly assumes that vcpu_id and MPIDR are the same thing. This is true when vcpus are organized as a flat topology, but is wrong when trying to emulate any other topology (such as A15 clusters). Change the KVM PSCI CPU_ON code to look at the MPIDR instead of the vcpu_id to pick a target CPU. Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall Signed-off-by: Shannon Zhao --- arch/arm/include/asm/kvm_emulate.h | 5 +++++ arch/arm/kvm/psci.c | 18 ++++++++++++++---- arch/arm64/include/asm/kvm_emulate.h | 5 +++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/kvm_emulate.h b/arch/arm/include/asm/kvm_emulate.h index a464e8d..708e4d8 100644 --- a/arch/arm/include/asm/kvm_emulate.h +++ b/arch/arm/include/asm/kvm_emulate.h @@ -157,4 +157,9 @@ static inline u32 kvm_vcpu_hvc_get_imm(struct kvm_vcpu *vcpu) return kvm_vcpu_get_hsr(vcpu) & HSR_HVC_IMM_MASK; } +static inline unsigned long kvm_vcpu_get_mpidr(struct kvm_vcpu *vcpu) +{ + return vcpu->arch.cp15[c0_MPIDR]; +} + #endif /* __ARM_KVM_EMULATE_H__ */ diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 86a693a..881c9fc 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -34,22 +35,31 @@ static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu) static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) { struct kvm *kvm = source_vcpu->kvm; - struct kvm_vcpu *vcpu; + struct kvm_vcpu *vcpu = NULL, *tmp; wait_queue_head_t *wq; unsigned long cpu_id; + unsigned long mpidr; phys_addr_t target_pc; + int i; cpu_id = *vcpu_reg(source_vcpu, 1); if (vcpu_mode_is_32bit(source_vcpu)) cpu_id &= ~((u32) 0); - if (cpu_id >= atomic_read(&kvm->online_vcpus)) + kvm_for_each_vcpu(i, tmp, kvm) { + mpidr = kvm_vcpu_get_mpidr(tmp); + if ((mpidr & MPIDR_HWID_BITMASK) + == (cpu_id & MPIDR_HWID_BITMASK)) { + vcpu = tmp; + break; + } + } + + if (!vcpu) return KVM_PSCI_RET_INVAL; target_pc = *vcpu_reg(source_vcpu, 2); - vcpu = kvm_get_vcpu(kvm, cpu_id); - wq = kvm_arch_vcpu_wq(vcpu); if (!waitqueue_active(wq)) return KVM_PSCI_RET_INVAL; diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index eec0738..6df93cd 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -177,4 +177,9 @@ static inline u8 kvm_vcpu_trap_get_fault(const struct kvm_vcpu *vcpu) return kvm_vcpu_get_hsr(vcpu) & ESR_EL2_FSC_TYPE; } +static inline unsigned long kvm_vcpu_get_mpidr(struct kvm_vcpu *vcpu) +{ + return vcpu_sys_reg(vcpu, MPIDR_EL1); +} + #endif /* __ARM64_KVM_EMULATE_H__ */