Received: by 10.223.176.5 with SMTP id f5csp687241wra; Fri, 2 Feb 2018 04:35:21 -0800 (PST) X-Google-Smtp-Source: AH8x2253ZnI4rOdtdnlZTJRaf0l9RVxpmzsUeHb3RdDuOBHk7jKTrG0TKLd2IvXBV9rHIgH3O3Zh X-Received: by 2002:a17:902:f:: with SMTP id 15-v6mr34979663pla.419.1517574921563; Fri, 02 Feb 2018 04:35:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517574921; cv=none; d=google.com; s=arc-20160816; b=YZMs3ZAHXz3psxUfAmm4848qAZWtRnO7k8BCjGZtbyDKWUA7V+bzEQtko7raGFHEIV 2/nji6UC2k7R8tQjHa0zE0a7yG8KaPqHhwTRNOURRpQTkPrSW7lcZbiXa7l8RXFw7T3D Ohz3FOBkLuLnGqXQuhn+r+bhRpofO3WcTI9HrdFPN1MJdbFYfYPt7/++x0h6TjA8+8VT xqV9IJyu9RDewAVWQW6Tc16O/qrihuES/aw6rDuzKLLf5AcejhY85oRTZXQA9yJ06+GR W/5Kv8eYjHY0dl/oEdr/TQbNiQkS3sZCHwMsH0xQaqiRdQ7EGYtUWTBUVSgP31f+hAkK YpPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=tLvO4bihGDpztphxSN9C7GpcopbMqha6qWJ7Ujfd5WI=; b=SKLCsUzLY7aCzRjNjq/dyd0cNiK17oRjeqavzZNxJjKN8l6eoMXodsWyASm+NlVtDO WZvAbWvJ89ZLvxHoyFGzt4UpHLxYoH3Owov2wSMYItSHmLl/JVKjfFYbN8rCfCwxnF9L YFtwTXpnLK+u4jl72zT5kjoLAO39rQfCORpLweGPWw1lDnpNU1AmyQu7+bK/T/YXZsYG FUD3d4QN74fmq/qChg4/UQ3dv1BCifJHFCWLA7Uq3NFnKp0IonndKaMt8iDsc2T1sZy1 DaLL3ghL1WIr9blC6Uj3cnUoQD/c/64VaKyfq2kPtQnbOAiVnZJmmmT2LIPegrkEh0mJ xXEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eS2UD2EJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v127si1392607pgv.669.2018.02.02.04.35.06; Fri, 02 Feb 2018 04:35:21 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eS2UD2EJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752000AbeBBMd4 (ORCPT + 99 others); Fri, 2 Feb 2018 07:33:56 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:39150 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751897AbeBBMdX (ORCPT ); Fri, 2 Feb 2018 07:33:23 -0500 Received: by mail-wm0-f67.google.com with SMTP id b21so12051532wme.4 for ; Fri, 02 Feb 2018 04:33:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=tLvO4bihGDpztphxSN9C7GpcopbMqha6qWJ7Ujfd5WI=; b=eS2UD2EJCvJ6fx/lWZMarZwbKlhlU2clE+4tnuxb1v5NhOjlaUYj0TxgpuTEXM218K H64jYla4rBS2yvkqbATiZ/qRMU/AsLtMeypimPab0V/ZdmozGIW4b9MlqC6Ebmlm9vjJ xaM7LOLYSEui3zRIqgNvPaI1q6D0kIB9ptK/A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=tLvO4bihGDpztphxSN9C7GpcopbMqha6qWJ7Ujfd5WI=; b=WU2t5oOOF1SP/dUNEf7zmF7WoUp+8uxGDXopJt5l9WRn95dqmTyAfDpsMw1mHd8khi qYTvE7m1EgODmO5EA5Fh58Fx7FrnRj56yK/7zf1AQoxFHJoW89el600L8bwH2zjXzyfV OwZGpCBHKT3P7ssZMwrOdlPzLobtTmah0f9mebYmsP5ywn+f+PEp915DkiA8btW0Rjn2 wJBvuXiKDsn+6q4fUcuOX0FpWdOn9wKyaU6MNSyisWNQjGsgvp+laTns3V/yrcrV96AH D2tYOPlOFa37cEhh6HH7KOmYgcJIXHdXBbOmTKIWPgReAoSYUUBHwfLEgGEV3mlfEIC3 hkOA== X-Gm-Message-State: AKwxytfZj9YxMGq7qyOHBaHyHo8WM1oAZAfvz7WQaTaaY4iFHWBBqvoW M110/xhjd1CXjF6YQLZLUkunog== X-Received: by 10.80.225.3 with SMTP id h3mr65614035edl.194.1517574801591; Fri, 02 Feb 2018 04:33:21 -0800 (PST) Received: from localhost (x50d2404e.cust.hiper.dk. [80.210.64.78]) by smtp.gmail.com with ESMTPSA id c16sm1672336eda.67.2018.02.02.04.33.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Feb 2018 04:33:20 -0800 (PST) Date: Fri, 2 Feb 2018 13:33:19 +0100 From: Christoffer Dall To: Marc Zyngier Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, Catalin Marinas , Will Deacon , Peter Maydell , Lorenzo Pieralisi , Mark Rutland , Robin Murphy , Ard Biesheuvel , Andrew Jones , Hanjun Guo , Jayachandran C , Jon Masters , Russell King - ARM Linux Subject: Re: [PATCH v3 06/18] arm/arm64: KVM: Add smccc accessors to PSCI code Message-ID: <20180202123319.GI21802@cbox> References: <20180201114657.7323-1-marc.zyngier@arm.com> <20180201114657.7323-7-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180201114657.7323-7-marc.zyngier@arm.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 01, 2018 at 11:46:45AM +0000, Marc Zyngier wrote: > Instead of open coding the accesses to the various registers, > let's add explicit SMCCC accessors. > Reviewed-by: Christoffer Dall > Signed-off-by: Marc Zyngier > --- > virt/kvm/arm/psci.c | 52 ++++++++++++++++++++++++++++++++++++++++++---------- > 1 file changed, 42 insertions(+), 10 deletions(-) > > diff --git a/virt/kvm/arm/psci.c b/virt/kvm/arm/psci.c > index 999f94d6bb98..c41553d35110 100644 > --- a/virt/kvm/arm/psci.c > +++ b/virt/kvm/arm/psci.c > @@ -32,6 +32,38 @@ > > #define AFFINITY_MASK(level) ~((0x1UL << ((level) * MPIDR_LEVEL_BITS)) - 1) > > +static u32 smccc_get_function(struct kvm_vcpu *vcpu) > +{ > + return vcpu_get_reg(vcpu, 0); > +} > + > +static unsigned long smccc_get_arg1(struct kvm_vcpu *vcpu) > +{ > + return vcpu_get_reg(vcpu, 1); > +} > + > +static unsigned long smccc_get_arg2(struct kvm_vcpu *vcpu) > +{ > + return vcpu_get_reg(vcpu, 2); > +} > + > +static unsigned long smccc_get_arg3(struct kvm_vcpu *vcpu) > +{ > + return vcpu_get_reg(vcpu, 3); > +} > + > +static void smccc_set_retval(struct kvm_vcpu *vcpu, > + unsigned long a0, > + unsigned long a1, > + unsigned long a2, > + unsigned long a3) > +{ > + vcpu_set_reg(vcpu, 0, a0); > + vcpu_set_reg(vcpu, 1, a1); > + vcpu_set_reg(vcpu, 2, a2); > + vcpu_set_reg(vcpu, 3, a3); > +} > + > static unsigned long psci_affinity_mask(unsigned long affinity_level) > { > if (affinity_level <= 3) > @@ -77,7 +109,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) > unsigned long context_id; > phys_addr_t target_pc; > > - cpu_id = vcpu_get_reg(source_vcpu, 1) & MPIDR_HWID_BITMASK; > + cpu_id = smccc_get_arg1(source_vcpu) & MPIDR_HWID_BITMASK; > if (vcpu_mode_is_32bit(source_vcpu)) > cpu_id &= ~((u32) 0); > > @@ -96,8 +128,8 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) > return PSCI_RET_INVALID_PARAMS; > } > > - target_pc = vcpu_get_reg(source_vcpu, 2); > - context_id = vcpu_get_reg(source_vcpu, 3); > + target_pc = smccc_get_arg2(source_vcpu); > + context_id = smccc_get_arg3(source_vcpu); > > kvm_reset_vcpu(vcpu); > > @@ -116,7 +148,7 @@ static unsigned long kvm_psci_vcpu_on(struct kvm_vcpu *source_vcpu) > * NOTE: We always update r0 (or x0) because for PSCI v0.1 > * the general puspose registers are undefined upon CPU_ON. > */ > - vcpu_set_reg(vcpu, 0, context_id); > + smccc_set_retval(vcpu, context_id, 0, 0, 0); > vcpu->arch.power_off = false; > smp_mb(); /* Make sure the above is visible */ > > @@ -136,8 +168,8 @@ static unsigned long kvm_psci_vcpu_affinity_info(struct kvm_vcpu *vcpu) > struct kvm *kvm = vcpu->kvm; > struct kvm_vcpu *tmp; > > - target_affinity = vcpu_get_reg(vcpu, 1); > - lowest_affinity_level = vcpu_get_reg(vcpu, 2); > + target_affinity = smccc_get_arg1(vcpu); > + lowest_affinity_level = smccc_get_arg2(vcpu); > > /* Determine target affinity mask */ > target_affinity_mask = psci_affinity_mask(lowest_affinity_level); > @@ -210,7 +242,7 @@ int kvm_psci_version(struct kvm_vcpu *vcpu) > static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) > { > struct kvm *kvm = vcpu->kvm; > - unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); > + u32 psci_fn = smccc_get_function(vcpu); > unsigned long val; > int ret = 1; > > @@ -277,14 +309,14 @@ static int kvm_psci_0_2_call(struct kvm_vcpu *vcpu) > break; > } > > - vcpu_set_reg(vcpu, 0, val); > + smccc_set_retval(vcpu, val, 0, 0, 0); > return ret; > } > > static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) > { > struct kvm *kvm = vcpu->kvm; > - unsigned long psci_fn = vcpu_get_reg(vcpu, 0) & ~((u32) 0); > + u32 psci_fn = smccc_get_function(vcpu); > unsigned long val; > > switch (psci_fn) { > @@ -302,7 +334,7 @@ static int kvm_psci_0_1_call(struct kvm_vcpu *vcpu) > break; > } > > - vcpu_set_reg(vcpu, 0, val); > + smccc_set_retval(vcpu, val, 0, 0, 0); > return 1; > } > > -- > 2.14.2 >