From patchwork Tue Apr 29 05:54:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 29290 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f197.google.com (mail-qc0-f197.google.com [209.85.216.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 29BD220553 for ; Tue, 29 Apr 2014 05:57:42 +0000 (UTC) Received: by mail-qc0-f197.google.com with SMTP id i8sf27832189qcq.8 for ; Mon, 28 Apr 2014 22:57:41 -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=iUEQp6anveBctSUZwfRT0MrrmCodSapl3RL6QaHA0II=; b=dPs+GtPMgs7cOdKj0ycuni6/HFqitJ6DxrY9DKAt1P6FJc50YMcM0rfkOd4WYixCsC YhTJpmSbU74HyVdHlgj3sxbCot83DatGFtReKT4aHKnHzv/YoTb+o6jux4hGfGkpOUB5 BuKLoKsHVa5B3KVNCKw6i1QmvNeIV7xUs824OOBK163tZNhAAI5BFwjPLW3ieAoAOcpz geJ74pYxWlQ0Ps7/iZUdTCsrfalcpIdlAV8A5Irj48aKbsS4c+OuDVtFAj3arwTMgBiv Zt1M4PUp/ah8M9kPfLgNnJjqcB6y2beppW+wAZShjc65x8pg3/bp/p/0orq9SoFu3AAX Hezw== X-Gm-Message-State: ALoCoQmclzaIYib7bet8T5LoShM7MlBk5vx4taSYwoLA3v/0TlD13XM+ngjR0VZ731HfZ6LW2TFO X-Received: by 10.236.69.74 with SMTP id m50mr13490506yhd.0.1398751061968; Mon, 28 Apr 2014 22:57:41 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.49.231 with SMTP id q94ls1315835qga.28.gmail; Mon, 28 Apr 2014 22:57:41 -0700 (PDT) X-Received: by 10.58.23.6 with SMTP id i6mr27325823vef.12.1398751061868; Mon, 28 Apr 2014 22:57:41 -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 j5si4267965veb.183.2014.04.28.22.57.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 22:57:41 -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 id10so1596844vcb.17 for ; Mon, 28 Apr 2014 22:57:41 -0700 (PDT) X-Received: by 10.52.51.197 with SMTP id m5mr23645000vdo.9.1398751061778; Mon, 28 Apr 2014 22:57:41 -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 ib8csp170788vcb; Mon, 28 Apr 2014 22:57:41 -0700 (PDT) X-Received: by 10.224.112.74 with SMTP id v10mr39422135qap.28.1398751061172; Mon, 28 Apr 2014 22:57:41 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id d5si8987201qad.86.2014.04.28.22.57.41 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Apr 2014 22:57:41 -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 1Wf11j-000398-8D; Tue, 29 Apr 2014 05:56:23 +0000 Received: from mail-pb0-f43.google.com ([209.85.160.43]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wf11L-0002iw-F4 for linux-arm-kernel@lists.infradead.org; Tue, 29 Apr 2014 05:55:59 +0000 Received: by mail-pb0-f43.google.com with SMTP id um1so6703780pbc.16 for ; Mon, 28 Apr 2014 22:55:41 -0700 (PDT) X-Received: by 10.66.231.105 with SMTP id tf9mr30493527pac.84.1398750941718; Mon, 28 Apr 2014 22:55:41 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id xg4sm39106507pbb.47.2014.04.28.22.55.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 28 Apr 2014 22:55:40 -0700 (PDT) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v11 08/12] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO Date: Tue, 29 Apr 2014 11:24:21 +0530 Message-Id: <1398750865-10892-9-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398750865-10892-1-git-send-email-anup.patel@linaro.org> References: <1398750865-10892-1-git-send-email-anup.patel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140428_225559_534209_C1FE4508 X-CRM114-Status: GOOD ( 16.38 ) 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 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.43 listed in list.dnswl.org] Cc: Rob Herring , linaro-kernel@lists.linaro.org, Anup Patel , kvm@vger.kernel.org, Marc Zyngier , patches@apm.com, Ashwin Chaugule , linux-arm-kernel@lists.infradead.org, Christoffer Dall , Pranavkumar Sawargaonkar 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: anup.patel@linaro.org 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 This patch adds emulation of PSCI v0.2 AFFINITY_INFO function call for KVM ARM/ARM64. This is a VCPU-level function call which will be used to determine current state of given affinity level. Signed-off-by: Anup Patel Signed-off-by: Pranavkumar Sawargaonkar Reviewed-by: Christoffer Dall Acked-by: Marc Zyngier --- arch/arm/kvm/psci.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 5936213..3b6a0cf 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -27,6 +27,16 @@ * as described in ARM document number ARM DEN 0022A. */ +#define AFFINITY_MASK(level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1) + +static unsigned long psci_affinity_mask(unsigned long affinity_level) +{ + if (affinity_level <= 3) + return MPIDR_HWID_BITMASK & AFFINITY_MASK(affinity_level); + + return 0; +} + static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu) { vcpu->arch.pause = true; @@ -85,6 +95,42 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) return PSCI_RET_SUCCESS; } +static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu) +{ + int i; + unsigned long mpidr; + unsigned long target_affinity; + unsigned long target_affinity_mask; + unsigned long lowest_affinity_level; + struct kvm *kvm = vcpu->kvm; + struct kvm_vcpu *tmp; + + target_affinity = *vcpu_reg(vcpu, 1); + lowest_affinity_level = *vcpu_reg(vcpu, 2); + + /* Determine target affinity mask */ + target_affinity_mask = psci_affinity_mask(lowest_affinity_level); + if (!target_affinity_mask) + return PSCI_RET_INVALID_PARAMS; + + /* Ignore other bits of target affinity */ + target_affinity &= target_affinity_mask; + + /* + * If one or more VCPU matching target affinity are running + * then ON else OFF + */ + kvm_for_each_vcpu(i, tmp, kvm) { + mpidr = kvm_vcpu_get_mpidr(tmp); + if (((mpidr & target_affinity_mask) == target_affinity) && + !tmp->arch.pause) { + return PSCI_0_2_AFFINITY_LEVEL_ON; + } + } + + return PSCI_0_2_AFFINITY_LEVEL_OFF; +} + static void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type) { memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); @@ -132,6 +178,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) case PSCI_0_2_FN64_CPU_ON: val = kvm_psci_vcpu_on(vcpu); break; + case PSCI_0_2_FN_AFFINITY_INFO: + case PSCI_0_2_FN64_AFFINITY_INFO: + val = kvm_psci_vcpu_affinity_info(vcpu); + break; case PSCI_0_2_FN_SYSTEM_OFF: kvm_psci_system_off(vcpu); /* @@ -157,12 +207,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) ret = 0; break; case PSCI_0_2_FN_CPU_SUSPEND: - case PSCI_0_2_FN_AFFINITY_INFO: case PSCI_0_2_FN_MIGRATE: case PSCI_0_2_FN_MIGRATE_INFO_TYPE: case PSCI_0_2_FN_MIGRATE_INFO_UP_CPU: case PSCI_0_2_FN64_CPU_SUSPEND: - case PSCI_0_2_FN64_AFFINITY_INFO: case PSCI_0_2_FN64_MIGRATE: case PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: val = PSCI_RET_NOT_SUPPORTED;