From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26B9FC433E0 for ; Fri, 26 Jun 2020 15:41:46 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA1AD207D8 for ; Fri, 26 Jun 2020 15:41:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ezTZX7/i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA1AD207D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=XDQmDdqCRgniNjqmx0JkLIGP5FhapuZw8no4iKGtz+s=; b=ezTZX7/iHYOgo6LuZlGYNEpYp n7JrhOEQ+ZF/O3OJ4wXBxy0LqeTTqWeDSIl7S9fdV+Zpw5KUpzYD5PxZkZd+jYzI01gUSTK1uNR7V 8X0Ysdm1eD2vdJHxtjeBq7FTYP45v5MM8u6Q/zdPGikwFJGfzbMKZU7so0DqXsgBRgkBnCn4ilGi2 aateSG4kyQ8XKIbe28eFXMBsaefc+75Fo34eBpBiaatsJhE2HJJl6TDG0WsZ8Oj+CTCH+en1e2YS+ CQpZgVFROO2qyWWCs9wcATshdtmWHX8siEyWQZcLANJ2TvHd7wfThehmhk7YB2haCsXMMMDmrJBlc wVwbmEfIg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joqRj-00013d-NY; Fri, 26 Jun 2020 15:39:19 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1joqRg-00012s-6y for linux-arm-kernel@lists.infradead.org; Fri, 26 Jun 2020 15:39:17 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53F771042; Fri, 26 Jun 2020 08:39:14 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 2F1E33F6CF; Fri, 26 Jun 2020 08:39:12 -0700 (PDT) Subject: Re: [PATCH v2 06/17] KVM: arm64: Introduce accessor for ctxt->sys_reg To: Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org References: <20200615132719.1932408-1-maz@kernel.org> <20200615132719.1932408-7-maz@kernel.org> From: Alexandru Elisei Message-ID: Date: Fri, 26 Jun 2020 16:39:52 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <20200615132719.1932408-7-maz@kernel.org> Content-Language: en-US X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , kernel-team@android.com, Suzuki K Poulose , Andre Przywara , Christoffer Dall , Dave Martin , George Cherian , James Morse , Andrew Scull , "Zengtao \(B\)" , Catalin Marinas , Will Deacon , Jintack Lim , Julien Thierry Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, On 6/15/20 2:27 PM, Marc Zyngier wrote: > In order to allow the disintegration of the per-vcpu sysreg array, > let's introduce a new helper (ctxt_sys_reg()) that returns the > in-memory copy of a system register, picked from a given context. > > __vcpu_sys_reg() is rewritten to use this helper. > > Signed-off-by: Marc Zyngier > --- > arch/arm64/include/asm/kvm_host.h | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index e7fd03271e52..5314399944e7 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -405,12 +405,17 @@ struct kvm_vcpu_arch { > #define vcpu_gp_regs(v) (&(v)->arch.ctxt.gp_regs) > > /* > - * Only use __vcpu_sys_reg if you know you want the memory backed version of a > - * register, and not the one most recently accessed by a running VCPU. For > - * example, for userspace access or for system registers that are never context > - * switched, but only emulated. > + * Only use __vcpu_sys_reg/ctxt_sys_reg if you know you want the > + * memory backed version of a register, and not the one most recently > + * accessed by a running VCPU. For example, for userspace access or > + * for system registers that are never context switched, but only > + * emulated. > */ > -#define __vcpu_sys_reg(v,r) ((v)->arch.ctxt.sys_regs[(r)]) > +#define __ctxt_sys_reg(c,r) (&(c)->sys_regs[(r)]) > + > +#define ctxt_sys_reg(c,r) (*__ctxt_sys_reg(c,r)) > + > +#define __vcpu_sys_reg(v,r) (ctxt_sys_reg(&(v)->arch.ctxt, (r))) This is confusing - __vcpu_sys_reg() returns the value, but __ctxt_sys_reg() return a pointer to the value. Because of that, I made the mistake of thinking that __vcpu_sys_reg() returns a pointer when reviewing the next patch in the series, and I got really worried that stuff was seriously broken (it was not). I'm not sure what the reasonable solution is, or even if there is one. Some thoughts: we could have just one macro, ctxt_sys_reg() and dereference that when we want the value; we could keep both and swap the macro definitions; or we could encode the fact that a macro returns a pointer in the macro name (so we would end up with __ctxt_sys_reg() -> __ctxt_sys_regp() and ctxt_sys_reg -> __ctxt_sys_reg()). What do you think? Thanks, Alex > > u64 vcpu_read_sys_reg(const struct kvm_vcpu *vcpu, int reg); > void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg); _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel