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=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham 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 2FDE1C55178 for ; Sat, 31 Oct 2020 18:23:09 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 9435F206F9 for ; Sat, 31 Oct 2020 18:23:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="fZ/2XHBq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9435F206F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 022894B6EC; Sat, 31 Oct 2020 14:23:08 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@kernel.org Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JFBn1FQWiC0i; Sat, 31 Oct 2020 14:23:06 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id CAE684B6E9; Sat, 31 Oct 2020 14:23:06 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 57E624B6E7 for ; Sat, 31 Oct 2020 14:23:05 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qISc7qBWOIup for ; Sat, 31 Oct 2020 14:23:04 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 2545E4B6E5 for ; Sat, 31 Oct 2020 14:23:04 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 039E5206DB; Sat, 31 Oct 2020 18:23:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604168583; bh=axiUj+6HBuU8jdmBWJCN+O6t+9LSFrhnx8QFpdCZ4sc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=fZ/2XHBqI3GMvqInLrowpfOeRe+6gjMBJz0WscemrC427oWigz+3iCZBVtOH6nzZw xHJn/+II1WMZvESzv2gpF1nu9xEnW4p/FYbOciqfljXtcI/vcMxOYU84d2pCqPUXw9 KGPCOCZaocRp3RS65zUPzVKmLD/H0y7z0J9IWZnE= Received: from 78.163-31-62.static.virginmediabusiness.co.uk ([62.31.163.78] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1kYvWm-0068z0-OE; Sat, 31 Oct 2020 18:23:00 +0000 Date: Sat, 31 Oct 2020 18:23:00 +0000 Message-ID: <878sbmdzln.wl-maz@kernel.org> From: Marc Zyngier To: Andrew Jones Subject: Re: [PATCH 2/3] KVM: arm64: Check RAZ visibility in ID register accessors In-Reply-To: <20201029201105.101910-3-drjones@redhat.com> References: <20201029201105.101910-1-drjones@redhat.com> <20201029201105.101910-3-drjones@redhat.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 EasyPG/1.0.0 Emacs/26.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 62.31.163.78 X-SA-Exim-Rcpt-To: drjones@redhat.com, kvmarm@lists.cs.columbia.edu, Dave.Martin@arm.com, xu910121@sina.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: xu910121@sina.com, kvmarm@lists.cs.columbia.edu, Dave.Martin@arm.com X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Thu, 29 Oct 2020 20:11:04 +0000, Andrew Jones wrote: > > The instruction encodings of ID registers are preallocated. Until an > encoding is assigned a purpose the register is RAZ. KVM's general ID > register accessor functions already support both paths, RAZ or not. > If for each ID register we can determine if it's RAZ or not, then all > ID registers can build on the general functions. The register visibility > function allows us to check whether a register should be completely > hidden or not, extending it to also report when the register should > be RAZ or not allows us to use it for ID registers as well. > > No functional change intended. > > Signed-off-by: Andrew Jones > --- > arch/arm64/kvm/sys_regs.c | 19 ++++++++++++++++--- > arch/arm64/kvm/sys_regs.h | 20 ++++++++++++++++++++ > 2 files changed, 36 insertions(+), 3 deletions(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index d24e66ee59b3..9f6151589460 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -1171,7 +1171,9 @@ static bool access_id_reg(struct kvm_vcpu *vcpu, > struct sys_reg_params *p, > const struct sys_reg_desc *r) > { > - return __access_id_reg(vcpu, p, r, false); > + bool raz = sysreg_raz_from_guest(vcpu, r); > + > + return __access_id_reg(vcpu, p, r, raz); > } > > static bool access_raz_id_reg(struct kvm_vcpu *vcpu, > @@ -1283,13 +1285,17 @@ static int __set_id_reg(const struct kvm_vcpu *vcpu, > static int get_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > const struct kvm_one_reg *reg, void __user *uaddr) > { > - return __get_id_reg(vcpu, rd, uaddr, false); > + bool raz = sysreg_raz_from_user(vcpu, rd); > + > + return __get_id_reg(vcpu, rd, uaddr, raz); > } > > static int set_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > const struct kvm_one_reg *reg, void __user *uaddr) > { > - return __set_id_reg(vcpu, rd, uaddr, false); > + bool raz = sysreg_raz_from_user(vcpu, rd); > + > + return __set_id_reg(vcpu, rd, uaddr, raz); > } > > static int get_raz_id_reg(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, > @@ -1375,12 +1381,19 @@ static bool access_mte_regs(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > return false; > } > > +static unsigned int id_visibility(const struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *r) > +{ > + return 0; > +} > + > /* sys_reg_desc initialiser for known cpufeature ID registers */ > #define ID_SANITISED(name) { \ > SYS_DESC(SYS_##name), \ > .access = access_id_reg, \ > .get_user = get_id_reg, \ > .set_user = set_id_reg, \ > + .visibility = id_visibility, \ > } > > /* > diff --git a/arch/arm64/kvm/sys_regs.h b/arch/arm64/kvm/sys_regs.h > index 5a6fc30f5989..d5add36c130a 100644 > --- a/arch/arm64/kvm/sys_regs.h > +++ b/arch/arm64/kvm/sys_regs.h > @@ -61,6 +61,8 @@ struct sys_reg_desc { > > #define REG_HIDDEN_USER (1 << 0) /* hidden from userspace ioctls */ > #define REG_HIDDEN_GUEST (1 << 1) /* hidden from guest */ > +#define REG_RAZ_USER (1 << 2) /* RAZ from userspace ioctls */ > +#define REG_RAZ_GUEST (1 << 3) /* RAZ from guest */ > > static __printf(2, 3) > inline void print_sys_reg_msg(const struct sys_reg_params *p, > @@ -129,6 +131,24 @@ static inline bool sysreg_hidden_from_user(const struct kvm_vcpu *vcpu, > return r->visibility(vcpu, r) & REG_HIDDEN_USER; > } > > +static inline bool sysreg_raz_from_guest(const struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *r) > +{ > + if (likely(!r->visibility)) > + return false; > + > + return r->visibility(vcpu, r) & REG_RAZ_GUEST; > +} > + > +static inline bool sysreg_raz_from_user(const struct kvm_vcpu *vcpu, > + const struct sys_reg_desc *r) > +{ > + if (likely(!r->visibility)) > + return false; > + > + return r->visibility(vcpu, r) & REG_RAZ_USER; > +} > + > static inline int cmp_sys_reg(const struct sys_reg_desc *i1, > const struct sys_reg_desc *i2) > { Is there actually a case for any ID register to have different RAZ semantics between guest and userspace? I have the feeling that we'd want them to be consistent at all times. Or did you have any particular (and future) use case in mind? Otherwise, looks good. M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm