Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1750706rda; Tue, 24 Oct 2023 01:59:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCb/64jktUR0dSQUu5f61jfeJI8MYDjsjWzRHwoixZ+lUOKMISO/KD4HCri6MUBfilVITD X-Received: by 2002:a05:6a00:10c4:b0:6b8:780:94e5 with SMTP id d4-20020a056a0010c400b006b8078094e5mr10522510pfu.18.1698137994200; Tue, 24 Oct 2023 01:59:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698137994; cv=none; d=google.com; s=arc-20160816; b=xM4w/oV0xPcVsKAU/x0jAWyUCDiecH22l24mlMc9Jolovmzpa2PlZZIR5I0i12NV7l Y8YCCk+KRZ3rM4AQDPHFuv/9dL/jCGo2o74we6nW2m3T/1kdmGzm9GDgIlcUfovig9xl eG1Ar4DCCdsrHwYJVcp/9YMBroPz6MgSAxV9fwPDG4Ri3kQnQfSytrP9C/+fcCXF58ml nUv8dcYxthNvSvoiW5bBHiknVQzF4rbr4IpTPFGvgweKmnrYUbhFdo52FcU0z6bW2Ce8 63BqryN7c6o3T/x7hIKfUt7ZMMnARYwOScbAMLuq8zL0g9U7GFV4CL/dFeOGYyDQvaRd jHhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:dkim-signature:date; bh=D6TYYpqy8N97kO8tVC2Cc3XTS86qRouwgud2Yw4OPK4=; fh=4I6BNv7iobpZrRcbueKA7r9RD02xPQmynyU/PeDFguM=; b=XYbd90eOVDhoo4Yde5SXepshrPI+IfB6TY6k3qdON0PauCklmJ9kVPlUof4Utu/vAz bGR8FsE/95ygCeEEDCOtDlwL5AP44dsCnH/+SfrzJsoPjCwwag5z08NuxMuno6ZbYAdx j3vOUPagYxqbYkae0FuytWJSFvHXG9dllFHog0TqqrA/GsBrt+SGoJrWmsqxzxgM/410 wDZ2QWnXoGN08NKlNvO0uJEYHyOv8WHUZoSNnATpqtMlPvxWDpiL79XQg2KDNvjBq2fJ 7r2hRu1ZLgIeRiGXEIu+Epzw8INS1jfQkYF9Hwq4MUZ2onKBqpPdBPTwJx3vABP+o0Bz SNrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oFd6EYkL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id d17-20020a056a00245100b006be0b34a99fsi8045131pfj.402.2023.10.24.01.59.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 01:59:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oFd6EYkL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D8D598077521; Tue, 24 Oct 2023 01:59:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233988AbjJXI7o (ORCPT + 99 others); Tue, 24 Oct 2023 04:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233946AbjJXI7l (ORCPT ); Tue, 24 Oct 2023 04:59:41 -0400 Received: from out-190.mta1.migadu.com (out-190.mta1.migadu.com [IPv6:2001:41d0:203:375::be]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A203FAC for ; Tue, 24 Oct 2023 01:59:38 -0700 (PDT) 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231020214053.2144305-6-rananta@google.com> X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Tue, 24 Oct 2023 01:59:51 -0700 (PDT) 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