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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC9EAC433F5 for ; Wed, 6 Oct 2021 14:49:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 B0608610EA for ; Wed, 6 Oct 2021 14:49:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B0608610EA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GqlIMRk9oIRwPCYrNcL6/JuBH2l2NCQD5Q8CSzpw9Og=; b=sausfasPskcWZ9 00yDwUOrbwgUY/mAK5QsUAhItxort+v4BWMH3eH80D+HIrwz5+WciEFSnacTkPGKbSid9msGGKpUb EA/AYi8BM3ocu9xd3aSNWc4EIkkqwLO4vvgfSgQicRdNWEfnsSXbOKc7Ul08HdSJMdQPis72JLTgn nHOuPXIKk7gwvrYA1O1S3BFx/qUTI/4Hk26GL9cEKTYQaQdh4csZG4Sbx/AViImkdzXjQHipE+4Ta YHraRQUcRgUwYchv0YKwWeCT3YV1OQK/R1rQZxbKnAXPf079XFd465bGXDItklHldsma3bxww4Isd tv15wxJTw100ZQYN8Dbw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mY8D0-00Ehl3-PT; Wed, 06 Oct 2021 14:47:50 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mY8Cw-00Ehjs-NC for linux-arm-kernel@lists.infradead.org; Wed, 06 Oct 2021 14:47:48 +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 EC6926D; Wed, 6 Oct 2021 07:47:41 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 109943F66F; Wed, 6 Oct 2021 07:47:40 -0700 (PDT) Date: Wed, 6 Oct 2021 15:49:19 +0100 From: Alexandru Elisei To: Andrew Jones Cc: maz@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: Re: [PATCH 2/2] KVM: arm64: Use get_raz_reg() for userspace reads of PMSWINC_EL0 Message-ID: References: <20210927124911.191729-1-alexandru.elisei@arm.com> <20210927124911.191729-3-alexandru.elisei@arm.com> <20210930132915.cpfzxdlws2zlou47@gator> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210930132915.cpfzxdlws2zlou47@gator> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211006_074746_905346_3CE24B65 X-CRM114-Status: GOOD ( 33.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Drew, Thank you for the review! On Thu, Sep 30, 2021 at 03:29:15PM +0200, Andrew Jones wrote: > On Mon, Sep 27, 2021 at 01:49:11PM +0100, Alexandru Elisei wrote: > > PMSWINC_EL0 is a write-only register and was initially part of the VCPU > > register state, but was later removed in commit 7a3ba3095a32 ("KVM: > > arm64: Remove PMSWINC_EL0 shadow register"). To prevent regressions, the > > register was kept accessible from userspace as Read-As-Zero (RAZ). > > > > The read function that is used to handle userspace reads of this > > register is get_raz_id_reg(), which, while technically correct, as it > > returns 0, it is not semantically correct, as PMSWINC_EL0 is not an ID > > register as the function name suggests. > > > > Add a new function, get_raz_reg(), to use it as the accessor for > > PMSWINC_EL0, as to not conflate get_raz_id_reg() to handle other types > > of registers. > > > > No functional change intended. > > > > Signed-off-by: Alexandru Elisei > > --- > > arch/arm64/kvm/sys_regs.c | 11 ++++++++++- > > 1 file changed, 10 insertions(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index 4adda8bf3168..1be827740f87 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -1285,6 +1285,15 @@ static int set_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > > return __set_id_reg(vcpu, rd, uaddr, true); > > } > > > > +static int get_raz_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > > + const struct kvm_one_reg *reg, void __user *uaddr) > > +{ > > + const u64 id = sys_reg_to_index(rd); > > + const u64 val = 0; > > + > > + return reg_to_user(uaddr, &val, id); > > +} > > + > > static int set_wi_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > > const struct kvm_one_reg *reg, void __user *uaddr) > > { > > @@ -1647,7 +1656,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { > > * previously (and pointlessly) advertised in the past... > > */ > > { PMU_SYS_REG(SYS_PMSWINC_EL0), > > - .get_user = get_raz_id_reg, .set_user = set_wi_reg, > > + .get_user = get_raz_reg, .set_user = set_wi_reg, > > .access = access_pmswinc, .reset = NULL }, > > { PMU_SYS_REG(SYS_PMSELR_EL0), > > .access = access_pmselr, .reset = reset_pmselr, .reg = PMSELR_EL0 }, > > -- > > 2.33.0 > > > > What about replacing get_raz_id_reg() with this new function? Do really need > both? I thought about that when writing this patch. I ultimately decided against it because changing the get_user accessor to be get_raz_reg() instead of get_raz_id_reg() would break the symmetry with set_user, which needs to stay set_raz_id_reg(), and cannot be substituted with set_wi_reg() because that would be a change in behaviour (set_raz_id_reg() checks that val == 0, set_wi_reg() doesn't). I do agree that get_raz_id_reg() does the exact same thing as get_raz_reg(), but in a more roundabout manner. So if you still feel that I should use get_raz_reg() instead, I'll do that for the next iteration of the series. What do you think? Thanks, Alex > > Thanks, > drew > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel