Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932134AbbGCVrA (ORCPT ); Fri, 3 Jul 2015 17:47:00 -0400 Received: from mail-la0-f43.google.com ([209.85.215.43]:34432 "EHLO mail-la0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755546AbbGCVqu (ORCPT ); Fri, 3 Jul 2015 17:46:50 -0400 Date: Fri, 3 Jul 2015 23:46:47 +0200 From: Christoffer Dall To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, peter.maydell@linaro.org, agraf@suse.de, drjones@redhat.com, pbonzini@redhat.com, zhichao.huang@linaro.org, jan.kiszka@siemens.com, dahi@linux.vnet.ibm.com, r65777@freescale.com, bp@suse.de, Gleb Natapov , Russell King , Catalin Marinas , Will Deacon , Ard Biesheuvel , Lorenzo Pieralisi , Richard Weinberger , Andre Przywara , open list Subject: Re: [PATCH v7 08/11] KVM: arm64: introduce vcpu->arch.debug_ptr Message-ID: <20150703214647.GD10878@cbox> References: <1435775343-20034-1-git-send-email-alex.bennee@linaro.org> <1435775343-20034-9-git-send-email-alex.bennee@linaro.org> <20150702183440.GK11332@cbox> <87mvzdsoer.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87mvzdsoer.fsf@linaro.org> 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 Content-Length: 4411 Lines: 125 On Fri, Jul 03, 2015 at 08:14:52AM +0100, Alex Benn?e wrote: > > Christoffer Dall writes: > > > On Wed, Jul 01, 2015 at 07:29:00PM +0100, Alex Benn?e wrote: > >> This introduces a level of indirection for the debug registers. Instead > >> of using the sys_regs[] directly we store registers in a structure in > >> the vcpu. The new kvm_arm_reset_debug_ptr() sets the debug ptr to the > >> guest context. > >> > >> This also entails updating the sys_regs code to access this new > >> structure. New access function have been added for each set of debug > >> registers. The generic functions are still used for the few registers > >> stored in the main context. > >> > >> New access function pointers have been added to the sys_reg_desc > >> structure to support the GET/SET_ONE_REG ioctl operations. > > > > Why is this needed? > > Previously I had a hacky: > > if (r->access == trap_debug64) > return debug_get64(vcpu, r, reg, uaddr); > > Which used the same offset information. Now we have a cleaner: > > if (r->set) > return (r->set)(vcpu, r, reg, uaddr); > > Which accesses the structure directly, as the trap functions do: > > __u64 *r = &vcpu->arch.vcpu_debug_state.dbg_bvr[rd->reg]; > if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) > return -EFAULT; > return 0; I get it now, had to take another look at sys_regs.c. I think this commit message needs a littel tweaking saying "Because we no longer give the sys_regs offset for the sys_reg_desc->reg field, but instead the index into a debug-specific struct, the generic user-space access code no longer works, and we are therefore forced to add specific user_set/get functions for these registers." At least it was hard for me to understand the rationale without this, and I think it would be good to have for someone doing git blame later. > > > >> +#if 0 > >> +static int debug_set64(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > >> + const struct kvm_one_reg *reg, void __user *uaddr) > >> +{ > >> + __u64 *r = (__u64 *) ((void * )&vcpu->arch.vcpu_debug_state + rd->reg); > >> + if (copy_from_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) > >> + return -EFAULT; > >> + return 0; > >> +} > >> + > >> +static int debug_get64(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > >> + const struct kvm_one_reg *reg, void __user *uaddr) > >> +{ > >> + __u64 *r = (__u64 *) ((void * )&vcpu->arch.vcpu_debug_state + rd->reg); > >> + if (copy_to_user(uaddr, r, KVM_REG_SIZE(reg->id)) != 0) > >> + return -EFAULT; > >> + return 0; > >> +} > >> +#endif > >> + > > > > what is this ifdef'ed block of code doing here? > > Oops. Yeah looks like I missed removing that after I finished the > re-factor. These where the old get/set functions I used. > > > > >> int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) > >> { > >> const struct sys_reg_desc *r; > >> @@ -1303,6 +1530,9 @@ int kvm_arm_sys_reg_get_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg > >> if (!r) > >> return get_invariant_sys_reg(reg->id, uaddr); > >> > >> + if (r->get) > >> + return (r->get)(vcpu, r, reg, uaddr); > >> + > >> return reg_to_user(uaddr, &vcpu_sys_reg(vcpu, r->reg), reg->id); > >> } > >> > >> @@ -1321,6 +1551,9 @@ int kvm_arm_sys_reg_set_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg > >> if (!r) > >> return set_invariant_sys_reg(reg->id, uaddr); > >> > >> + if (r->set) > >> + return (r->set)(vcpu, r, reg, uaddr); > >> + > >> return reg_from_user(&vcpu_sys_reg(vcpu, r->reg), uaddr, reg->id); > >> } > >> > >> diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h > >> index d411e25..9265e7d 100644 > >> --- a/arch/arm64/kvm/sys_regs.h > >> +++ b/arch/arm64/kvm/sys_regs.h > >> @@ -55,6 +55,12 @@ struct sys_reg_desc { > >> > >> /* Value (usually reset value) */ > >> u64 val; > >> + > >> + /* Get/Set functions, fallback if NULL */ > > > > Is this only meant for usersapce access or when should one use these? > > Yes for GET/SET > ok, see other mail for potential rename to get_user / set_user if you like the idea. Thanks, -Christoffer -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/