From patchwork Thu Feb 6 11:31:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 24248 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f200.google.com (mail-ve0-f200.google.com [209.85.128.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7B9A020445 for ; Thu, 6 Feb 2014 11:32:58 +0000 (UTC) Received: by mail-ve0-f200.google.com with SMTP id c14sf4257817vea.11 for ; Thu, 06 Feb 2014 03:32:57 -0800 (PST) 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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=DfLjwlvQIHkJwPZZPx5AfJrKU96nSys2v8zvrC4NTNo=; b=PsozAkX4FqSk7TJY1P/iPeY3yAp8+o6VGk+m3w1sAkxqknZyYh+OkRRq0wDB345U0t T8DFk5rwmjAIIAgNymVHm0KEvJxz/xGUViByQwJdbwYVnfm2br80ltT9t4rHFypKIA+F Tcm3VTCv3J83l72BTlefdItnEBaFENH5zB5atoLObdHVXng287TR7/hTHYiRwywOG+4W zSVTeHbVs4KpTkrf8GUElonwh2dj/R2NIttQNo4DkjZoI2nsA2gzzLKHqOcWomPEP4zo uqUyheqXKQlXYG1SgxaWtkzOSy6rGp66G8fl/2YT9zt0RK+oowtP2dfpNWcxkQAIjxUv cSKA== X-Gm-Message-State: ALoCoQmgJ8+ifedj+NoBHyaDqIC6qu7SQL86G8NOfA5zZ9ABrV+/CoTsih/6tRnsiNnWjmPbMyZM X-Received: by 10.224.4.202 with SMTP id 10mr3169859qas.7.1391686377596; Thu, 06 Feb 2014 03:32:57 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.80.98 with SMTP id b89ls539889qgd.9.gmail; Thu, 06 Feb 2014 03:32:57 -0800 (PST) X-Received: by 10.52.106.107 with SMTP id gt11mr4588680vdb.7.1391686377528; Thu, 06 Feb 2014 03:32:57 -0800 (PST) Received: from mail-ve0-f176.google.com (mail-ve0-f176.google.com [209.85.128.176]) by mx.google.com with ESMTPS id uc1si157575vcb.128.2014.02.06.03.32.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Feb 2014 03:32:57 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.176 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.176; Received: by mail-ve0-f176.google.com with SMTP id oz11so1349318veb.21 for ; Thu, 06 Feb 2014 03:32:57 -0800 (PST) X-Received: by 10.220.159.4 with SMTP id h4mr5469396vcx.1.1391686377450; Thu, 06 Feb 2014 03:32:57 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp5273vcz; Thu, 6 Feb 2014 03:32:56 -0800 (PST) X-Received: by 10.66.149.37 with SMTP id tx5mr73843pab.81.1391686376523; Thu, 06 Feb 2014 03:32:56 -0800 (PST) Received: from mail-pb0-f52.google.com (mail-pb0-f52.google.com [209.85.160.52]) by mx.google.com with ESMTPS id to9si846783pbc.5.2014.02.06.03.32.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Feb 2014 03:32:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.160.52 is neither permitted nor denied by best guess record for domain of anup.patel@linaro.org) client-ip=209.85.160.52; Received: by mail-pb0-f52.google.com with SMTP id jt11so1639316pbb.11 for ; Thu, 06 Feb 2014 03:32:56 -0800 (PST) X-Received: by 10.69.0.168 with SMTP id az8mr11701396pbd.51.1391686376063; Thu, 06 Feb 2014 03:32:56 -0800 (PST) Received: from pnqlab006.amcc.com ([182.73.239.130]) by mx.google.com with ESMTPSA id yd4sm2594758pbc.13.2014.02.06.03.32.51 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Feb 2014 03:32:55 -0800 (PST) From: Anup Patel To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, patches@apm.com, Marc Zyngier , Christoffer Dall , Mark Rutland , Pranavkumar Sawargaonkar , Anup Patel Subject: [PATCH v4 07/10] ARM/ARM64: KVM: Emulate PSCI v0.2 AFFINITY_INFO Date: Thu, 6 Feb 2014 17:01:39 +0530 Message-Id: <1391686302-19451-8-git-send-email-anup.patel@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1391686302-19451-1-git-send-email-anup.patel@linaro.org> References: <1391686302-19451-1-git-send-email-anup.patel@linaro.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.128.176 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 Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/arch/arm/kvm/psci.c b/arch/arm/kvm/psci.c index 1f1720a..9890710 100644 --- a/arch/arm/kvm/psci.c +++ b/arch/arm/kvm/psci.c @@ -85,6 +85,55 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) return KVM_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 = MPIDR_HWID_BITMASK; + switch (lowest_affinity_level) { + case 0: /* All affinity levels are valid */ + target_affinity_mask &= ~0x0UL; + break; + case 1: /* Aff0 ignored */ + target_affinity_mask &= ~0xFFUL; + break; + case 2: /* Aff0 and Aff1 ignored */ + target_affinity_mask &= ~0xFFFFUL; + break; + case 3: /* Aff0, Aff1, and Aff2 ignored */ + target_affinity_mask &= ~0xFFFFFFUL; + break; + default: + 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 +181,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) case KVM_PSCI_0_2_FN64_CPU_ON: val = kvm_psci_vcpu_on(vcpu); break; + case KVM_PSCI_0_2_FN_AFFINITY_INFO: + case KVM_PSCI_0_2_FN64_AFFINITY_INFO: + val = kvm_psci_vcpu_affinity_info(vcpu); + break; case KVM_PSCI_0_2_FN_SYSTEM_OFF: kvm_psci_system_off(vcpu); val = KVM_PSCI_RET_SUCCESS; @@ -143,12 +196,10 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) ret = 0; break; case KVM_PSCI_0_2_FN_CPU_SUSPEND: - case KVM_PSCI_0_2_FN_AFFINITY_INFO: case KVM_PSCI_0_2_FN_MIGRATE: case KVM_PSCI_0_2_FN_MIGRATE_INFO_TYPE: case KVM_PSCI_0_2_FN_MIGRATE_INFO_UP_CPU: case KVM_PSCI_0_2_FN64_CPU_SUSPEND: - case KVM_PSCI_0_2_FN64_AFFINITY_INFO: case KVM_PSCI_0_2_FN64_MIGRATE: case KVM_PSCI_0_2_FN64_MIGRATE_INFO_UP_CPU: val = KVM_PSCI_RET_NI;