From patchwork Wed Apr 2 10:42:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 27613 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7786C20341 for ; Wed, 2 Apr 2014 11:13:27 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wn1sf156566obc.5 for ; Wed, 02 Apr 2014 04:13: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: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=OFGyx3d8D4FKja8Mb+ybARo5uGc45flSFbrb2qZ1rFc=; b=Kv4uxpzVB8rbeP0h70Su4PZNWvkUT+mIA5vhATTSZDrdAKSsLf57dZTQlhYE5cvBIB ghWL6C9jc7GhqOv2uSn6P5cfYsIKSTjCMUO5nJBtEEaG1pjP4odeFdgBtTxoIxfmVdWY 03BFod3nJWg7bYsBqs2VwLr44mUNyg4SuZ34zgdluUYz0cYW2vVXs8pH0oZcWVAAcggd AyRZV5nXgUVTKy3m56VdJMJu1jLNMIyAPqy3+deegB6+08IiMKEOXppRnMQLDQinI2dU UhyskJ7kg2s0ecaqIjAqHpJhq1dV1sF6/h9TTe7fyZ42A7nO3TDP/QsSLnqQauVwh1fE F9qA== X-Gm-Message-State: ALoCoQl73cCTI+7de5MNi3y4qcA7Bl7QfoVlu0jFn3gS+cqm1xKqIla9NeaVp/BbaCDqpvpMLdB9 X-Received: by 10.182.126.137 with SMTP id my9mr16655373obb.13.1396437206788; Wed, 02 Apr 2014 04:13:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.79 with SMTP id j73ls287686qge.45.gmail; Wed, 02 Apr 2014 04:13:26 -0700 (PDT) X-Received: by 10.52.3.42 with SMTP id 10mr2026vdz.78.1396437206575; Wed, 02 Apr 2014 04:13:26 -0700 (PDT) Received: from mail-vc0-f173.google.com (mail-vc0-f173.google.com [209.85.220.173]) by mx.google.com with ESMTPS id tq2si457963vdc.21.2014.04.02.04.13.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Apr 2014 04:13:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.173; Received: by mail-vc0-f173.google.com with SMTP id il7so41155vcb.18 for ; Wed, 02 Apr 2014 04:13:26 -0700 (PDT) X-Received: by 10.52.181.132 with SMTP id dw4mr1316vdc.86.1396437206417; Wed, 02 Apr 2014 04:13:26 -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.12.8 with SMTP id v8csp313641vcv; Wed, 2 Apr 2014 04:13:25 -0700 (PDT) X-Received: by 10.194.122.6 with SMTP id lo6mr29583488wjb.38.1396437205322; Wed, 02 Apr 2014 04:13:25 -0700 (PDT) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id fj6si8176638wic.105.2014.04.02.04.13.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Apr 2014 04:13:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WVIf5-0007z9-DP; Wed, 02 Apr 2014 10:44:53 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WVIeL-0007cP-6P; Wed, 02 Apr 2014 10:44:05 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WVIeD-0007Yn-QO for linux-arm-kernel@lists.infradead.org; Wed, 02 Apr 2014 10:43:58 +0000 Received: by mail-pa0-f46.google.com with SMTP id kx10so5793399pab.19 for ; Wed, 02 Apr 2014 03:43:37 -0700 (PDT) X-Received: by 10.68.34.225 with SMTP id c1mr20235809pbj.116.1396435416885; Wed, 02 Apr 2014 03:43:36 -0700 (PDT) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id tk5sm3573403pbc.63.2014.04.02.03.43.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Apr 2014 03:43:35 -0700 (PDT) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v7 08/12] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO Date: Wed, 2 Apr 2014 16:12:23 +0530 Message-Id: <1396435347-20056-9-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1396435347-20056-1-git-send-email-anup.patel@linaro.org> References: <1396435347-20056-1-git-send-email-anup.patel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140402_064357_964259_5864AD98 X-CRM114-Status: GOOD ( 15.29 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.46 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Mark Rutland , Rob Herring , linaro-kernel@lists.linaro.org, Anup Patel , 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: 209.85.220.173 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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 --- 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..5fccf0b 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 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 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;