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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9E990C77B7C for ; Fri, 26 May 2023 21:37:44 +0000 (UTC) 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=fxjJEmkj+aC2QsUPL3mCfW8Ywbud6NvGbI3MFaAhE9I=; b=rMBFAyIa9AXUka VwACISW8oSZb/5aFGuh4bNb2p9pk14szxXIGOvpji0JuRSlCE8Zk6fsHiIjPtOeFFWRipS6DYcVsQ os5w3xieYOtcG8eldpTou9VYWnAWaJRNcFIPAIvP+LCJ3wyIRE54uErv6nToHhLeAhcy0Ud25VRlp FaBeA5/qTIFHp5E1av8BI8Ilv8Xb6Nv35IXoCFTPPhaLBScDLsBxAfVHG4cBndnc7YGnI3Z+j6Woi Qv1/zXehzjXQUu8+1NW3vt/fZS/7hp4M8YqPvSwnD2nvwsfX+cGHVoYNU8BLgOR1iWpF5RM7rLqwZ NzRh7+D1Nd4EFBX50yRQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2f7c-00404L-19; Fri, 26 May 2023 21:37:16 +0000 Received: from out-22.mta1.migadu.com ([95.215.58.22]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2f7Z-00403M-0D for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:37:14 +0000 Date: Fri, 26 May 2023 21:37:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1685137029; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NFmfZJ9XSBvihraEvyzSKBtHQpCcMvW1SpatpSEYiEE=; b=mAQWhVuBWTZ2vUp9QXlpaQmgvIpPn7WZKHBChPEYdJXqisi9FB5bGReorOWP3/umm0nQgh wpQH14L8SKVxqsuP3iyV7hBqWuSQBglt0VRFRwsGr17PN/YnZH5MVM09zmdKOvND3xyqnF qAM4htNt1/pFWDuDRChhDvZDdJZSaHM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Jing Zhang Cc: KVM , KVMARM , ARMLinux , Marc Zyngier , Oliver Upton , Will Deacon , Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Fuad Tabba , Reiji Watanabe , Raghavendra Rao Ananta Subject: Re: [PATCH v10 4/5] KVM: arm64: Reuse fields of sys_reg_desc for idreg Message-ID: References: <20230522221835.957419-1-jingzhangos@google.com> <20230522221835.957419-5-jingzhangos@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230522221835.957419-5-jingzhangos@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230526_143713_520193_415DA42C X-CRM114-Status: GOOD ( 22.17 ) 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 Jing, On Mon, May 22, 2023 at 10:18:34PM +0000, Jing Zhang wrote: > Since reset() and val are not used for idreg in sys_reg_desc, they would > be used with other purposes for idregs. > The callback reset() would be used to return KVM sanitised id register > values. The u64 val would be used as mask for writable fields in idregs. > Only bits with 1 in val are writable from userspace. The tense of the changelog is wrong (should be in an imperative mood). Maybe something like: sys_reg_desc::{reset, val} are presently unused for ID register descriptors. Repurpose these fields to support user-configurable ID registers. Use the ::reset() function pointer to return the sanitised value of a given ID register, optionally with KVM-specific feature sanitisation. Additionally, keep a mask of writable register fields in ::val. > Signed-off-by: Jing Zhang > --- > arch/arm64/kvm/sys_regs.c | 101 +++++++++++++++++++++++++++----------- > arch/arm64/kvm/sys_regs.h | 15 ++++-- > 2 files changed, 82 insertions(+), 34 deletions(-) > [...] > +/* > + * Since reset() callback and field val are not used for idregs, they will be > + * used for specific purposes for idregs. > + * The reset() would return KVM sanitised register value. The value would be the > + * same as the host kernel sanitised value if there is no KVM sanitisation. > + * The val would be used as a mask indicating writable fields for the idreg. > + * Only bits with 1 are writable from userspace. This mask might not be > + * necessary in the future whenever all ID registers are enabled as writable > + * from userspace. > + */ > + > /* sys_reg_desc initialiser for known cpufeature ID registers */ > #define ID_SANITISED(name) { \ > SYS_DESC(SYS_##name), \ > @@ -1751,6 +1788,8 @@ static unsigned int elx2_visibility(const struct kvm_vcpu *vcpu, > .get_user = get_id_reg, \ > .set_user = set_id_reg, \ > .visibility = id_visibility, \ > + .reset = general_read_kvm_sanitised_reg,\ > + .val = 0, \ I generally think unions are more trouble than they're worth, but it might make sense to throw the fields with dual meaning into one, like struct sys_reg_desc { [...] union { struct { void (*reset)(struct kvm_vcpu *, const struct sys_reg_desc *); u64 val; }; struct { u64 (*read_sanitised)(struct kvm_vcpu *vcpu, const struct sys_reg_desc *); u64 mask; }; }; } You could then avoid repainting the world to handle ->reset() returning a value and usage of the fields in an id register context become a bit more self-documenting. And you get to play with fire while you do it! Let's see if the other side of the pond agrees with my bikeshedding... -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel