From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933000AbcBAOkk (ORCPT ); Mon, 1 Feb 2016 09:40:40 -0500 Received: from mail-wm0-f43.google.com ([74.125.82.43]:34119 "EHLO mail-wm0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932715AbcBAOki (ORCPT ); Mon, 1 Feb 2016 09:40:38 -0500 Date: Mon, 1 Feb 2016 15:41:03 +0100 From: Christoffer Dall To: Marc Zyngier Cc: Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH v2 18/21] arm64: KVM: Introduce hyp_alternate_value helper Message-ID: <20160201144103.GX1478@cbox> References: <1453737235-16522-1-git-send-email-marc.zyngier@arm.com> <1453737235-16522-19-git-send-email-marc.zyngier@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1453737235-16522-19-git-send-email-marc.zyngier@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 25, 2016 at 03:53:52PM +0000, Marc Zyngier wrote: > We already have hyp_alternate_select() to define a function pointer > that gets changed by a kernel feature or workaround. > > It would be useful to have a similar feature that resolves in a > direct value, without requiring a function call. For this purpose, > introduce hyp_alternate_value(), which returns one of two values > depending on the state of the alternative. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/kvm/hyp/hyp.h | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/arch/arm64/kvm/hyp/hyp.h b/arch/arm64/kvm/hyp/hyp.h > index 44eaff7..dc75fdb 100644 > --- a/arch/arm64/kvm/hyp/hyp.h > +++ b/arch/arm64/kvm/hyp/hyp.h > @@ -144,6 +144,17 @@ typeof(orig) * __hyp_text fname(void) \ > return val; \ > } > > +#define hyp_alternate_value(fname, orig, alt, cond) \ > +typeof(orig) __hyp_text fname(void) \ > +{ \ > + typeof(alt) val = orig; \ > + asm volatile(ALTERNATIVE("nop \n", \ > + "mov %0, %1 \n", \ > + cond) \ > + : "+r" (val) : "r" ((typeof(orig))alt)); \ > + return val; \ > +} > + > void __vgic_v2_save_state(struct kvm_vcpu *vcpu); > void __vgic_v2_restore_state(struct kvm_vcpu *vcpu); > > -- > 2.1.4 > I'm really not convinced that this is more readable than simply defining a function where needed. Perhaps the thing that needs a definition is the "asm volatile(ALTERNATIVE(...))" part? I also don't see why any of this is specific to KVM or Hyp ? -Christoffer