From patchwork Mon Mar 31 10:46:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 3913521 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 18E8B9F357 for ; Mon, 31 Mar 2014 11:37:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28BE1203AC for ; Mon, 31 Mar 2014 11:37:40 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B0C720386 for ; Mon, 31 Mar 2014 11:37:39 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUZnI-0007D2-Cd; Mon, 31 Mar 2014 10:50:21 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUZmP-0004r3-Ll; Mon, 31 Mar 2014 10:49:25 +0000 Received: from mail-pb0-f54.google.com ([209.85.160.54]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WUZkp-0004fN-Ae for linux-arm-kernel@lists.infradead.org; Mon, 31 Mar 2014 10:47:49 +0000 Received: by mail-pb0-f54.google.com with SMTP id ma3so7987470pbc.41 for ; Mon, 31 Mar 2014 03:47:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jcNS+qwiIcHok0ZvmEZ2BCnuvhXfTBEqF4J42xeCW9U=; b=U5759HCbwk3PlgEqmOKXqsp0b6BgFpvkpZeR5eyYT+NrOW9ZKQHfgxMyBt7a+Rou7j CxzBsa8/IC4IUPSy5KvzrzU41kdRcnxqqy6xLhXHHHkLCVRAfQkKtpb+idRWTrq2euaS bt4nERuWzPetT5nShpNLCfkfJ8HXCDEFmOPqOWV2J4kPW30FRKqIk9TSNocLkoqsVUR1 GOjOWWyYB2Wc0zwiR5pU1As8/0XSqTh6hzEYOZ0deXQN1HGgnU8NiA0t5kgPWdlayFlE su1DyWqKz58TdXKBLsbLQ6LCIQL8bdowhX31vkMwcoL0lnTJ3YQN2vYLT8UpeYpb/K9V 24GA== X-Gm-Message-State: ALoCoQkTsYT49hFFOv/eIYgGTwBdDDp/uMf+A70iECj6Y3ugB6jMmfTblPgU7FDzDOXRg9RgMgU+ X-Received: by 10.66.141.12 with SMTP id rk12mr2706449pab.152.1396262846013; Mon, 31 Mar 2014 03:47:26 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id oa3sm42582874pbb.15.2014.03.31.03.47.20 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 31 Mar 2014 03:47:24 -0700 (PDT) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v6 08/12] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO Date: Mon, 31 Mar 2014 16:16:09 +0530 Message-Id: <1396262773-7723-9-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1396262773-7723-1-git-send-email-anup.patel@linaro.org> References: <1396262773-7723-1-git-send-email-anup.patel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140331_064747_509528_0A3689D3 X-CRM114-Status: GOOD ( 14.49 ) X-Spam-Score: -2.6 (--) Cc: Mark Rutland , Rob Herring , linaro-kernel@lists.linaro.org, Anup Patel , Marc Zyngier , patches@apm.com, 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- arch/arm/kvm/psci.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index b964aa4..c80bd45 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -27,6 +27,31 @@ * as described in ARM document number ARM DEN 0022A. */ +static unsigned long psci_affinity_mask(unsigned long affinity_level) +{ + unsigned long affinity_mask = MPIDR_HWID_BITMASK; + + switch (affinity_level) { + case 0: /* All affinity levels are valid */ + affinity_mask &= ~0x0UL; + break; + case 1: /* Aff0 ignored */ + affinity_mask &= ~0xFFUL; + break; + case 2: /* Aff0 and Aff1 ignored */ + affinity_mask &= ~0xFFFFUL; + break; + case 3: /* Aff0, Aff1, and Aff2 ignored */ + affinity_mask &= ~0xFFFFFFUL; + break; + default: + affinity_mask = 0; + break; + }; + + return affinity_mask; +} + static void kvm_psci_vcpu_off(struct kvm_vcpu *vcpu) { vcpu->arch.pause = true; @@ -85,6 +110,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 KVM_PSCI_RET_INVAL; + + /* Ignore other bits of target affinity */ + target_affinity &= target_affinity_mask; + + /* + * If one or more VCPU matching target affinity are running + * then return 0 (ON) else return 1 (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 0; + } + } + + return 1; +} + static inline void kvm_prepare_system_event(struct kvm_vcpu *vcpu, u32 type) { memset(&vcpu->run->system_event, 0, sizeof(vcpu->run->system_event)); @@ -132,6 +193,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); val = PSCI_RET_SUCCESS; @@ -143,12 +208,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;