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 8BD7CC00A8F for ; Tue, 24 Oct 2023 09:00:13 +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=3ZurrhSk7ec9TqjYoTdqtNO3tVx18VfoZJQV6sfLAQU=; b=yI/mzuQGFK7b4N vw7U/EgeNFbfC6Bip/ikEJOgTveVp/79GN1T4OdEZEL3iQjqFHza2+x8sH4U51YXsADi4gPixG8gI HLDICWRHaecIfuNL+4Az7GY7KBHm7fd0JhuXmdLBmaxDgHmbqMHwm4fVryP5CzSkd9mdCspSyO3R9 PQFkA5DpSJHInC5mCpKmbSz1k1tZ+88k5lR/SgyCGJUW6dPFXMCQxPSZXVUONDFbDHAk8E4fUkLHz 9Sx9DhVtjtTdSpo0u18ToXnkxI5piTn/28IQxdDctPfPKGQiIoLXhSh/PXODIj0mdWng/sPSJyDOW x5WQWPR9+xUCUwanJajw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qvDGQ-009Fp0-0O; Tue, 24 Oct 2023 08:59:50 +0000 Received: from out-202.mta1.migadu.com ([95.215.58.202]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qvDGG-009Fmt-1V for linux-arm-kernel@lists.infradead.org; Tue, 24 Oct 2023 08:59:42 +0000 Date: Tue, 24 Oct 2023 08:59:30 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1698137975; 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=D6TYYpqy8N97kO8tVC2Cc3XTS86qRouwgud2Yw4OPK4=; b=oFd6EYkL7idjhlxEaG6UTiY53c5RjtDdeG3QcRHlcOHPEzg95lcPHSAzMzHXNHO0bq+jwH S0AjNrrfYFkVGFRIKIhvXqcpVLF/ujPhdmZwVQbJY99KGSuW/VvDTLLF9tS9aslIs6AP4R wBfV8EFFpLCr8xGx0f3ThQAbDEldEms= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Raghavendra Rao Ananta Cc: Marc Zyngier , Alexandru Elisei , James Morse , Suzuki K Poulose , Paolo Bonzini , Zenghui Yu , Shaoqin Huang , Jing Zhang , Reiji Watanabe , Colton Lewis , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH v8 05/13] KVM: arm64: Add {get,set}_user for PM{C,I}NTEN{SET,CLR}, PMOVS{SET,CLR} Message-ID: References: <20231020214053.2144305-1-rananta@google.com> <20231020214053.2144305-6-rananta@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20231020214053.2144305-6-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231024_015940_913285_08C6D3A8 X-CRM114-Status: GOOD ( 19.24 ) 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 On Fri, Oct 20, 2023 at 09:40:45PM +0000, Raghavendra Rao Ananta wrote: > For unimplemented counters, the bits in PM{C,I}NTEN{SET,CLR} and > PMOVS{SET,CLR} registers are expected to RAZ. To honor this, > explicitly implement the {get,set}_user functions for these > registers to mask out unimplemented counters for userspace reads > and writes. > > Signed-off-by: Raghavendra Rao Ananta > --- > arch/arm64/kvm/sys_regs.c | 91 ++++++++++++++++++++++++++++++++++++--- > 1 file changed, 85 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index faf97878dfbbb..2e5d497596ef8 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -987,6 +987,45 @@ static bool access_pmu_evtyper(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > return true; > } > > +static void set_pmreg_for_valid_counters(struct kvm_vcpu *vcpu, > + u64 reg, u64 val, bool set) > +{ > + struct kvm *kvm = vcpu->kvm; > + > + mutex_lock(&kvm->arch.config_lock); > + > + /* Make the register immutable once the VM has started running */ This is a considerable change from the existing behavior and lacks justification. These registers, or rather the state that these aliases update, is mutable from the guest. I see no reason for excluding userspace from this behavior. > + if (kvm_vm_has_ran_once(kvm)) { > + mutex_unlock(&kvm->arch.config_lock); > + return; > + } > + > + val &= kvm_pmu_valid_counter_mask(vcpu); > + mutex_unlock(&kvm->arch.config_lock); I'm not entirely sold on taking the config_lock here. - If userspace is doing these ioctls in parallel then it cannot guarantee ordering in the first place, even w/ locking under the hood. Any garbage values will be discarded by KVM_REQ_RELOAD_PMU. - If the VM has already started PMCR.N is immutable, so there is no race. -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel