Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1465604rbb; Mon, 26 Feb 2024 10:04:07 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXti/ksQ2avUZwIkURDwjXx8tPoPstq/7w+KVzgeOWU7DnNfn19edNgtIKJsyz1MBlG6VA++qKGzkcFFs/oS2kvrXm4CQunyPDcmTFb4g== X-Google-Smtp-Source: AGHT+IHegPuFT/TF5WJH1aQuHBsxqVoMxa5E4VQM3D2IXcZWJOAtz4DnG92xMHxnHCpv9mDSG9QE X-Received: by 2002:a9d:7381:0:b0:6e4:957f:f67c with SMTP id j1-20020a9d7381000000b006e4957ff67cmr4196955otk.32.1708970647314; Mon, 26 Feb 2024 10:04:07 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708970647; cv=pass; d=google.com; s=arc-20160816; b=nQbehZoYvocwGHbRI8kfihCWK/oc1VO382k8qY68je0wj+4YtSl6YL8K70/0tgvnzM vx36IelbQxS/IDsVdZyu/YJDabNOizhVZA/xra9CuDDAGNkPq7ZZxo5kNFbalPQtHLB+ UG8IRimcI71c4Hv9EdrCLp/5L/4OyEHR8oKPetAv8I4T8rHGRqt802lIE3vp8n7uGiJL Gw9i+IHlnxfHp/EX7NVdScG9qbBDrUkdshKUKE3WXH9C7U2aXjlsAnorMzRGTAaqvHUi ez9cRN9ptGrK8AlnVT/0ADxQ0ifL7y5wrSejo36byWfe+W/SjRbNAqMda68DTvtHo0z7 jnoQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=MQJjnfcQzNf6paqfbFzzh2wlwenEXxcMPOZL6VYYYb4=; fh=ZPzPmdAM9g5edCtkUA6nA+gDIZh5e3C6PTYlFr5sZcw=; b=S1PfkKnM86roK/6lKudoOKIGJ2Zji7iEiePHFeXrWLSD2DUcGiCLN5/F9x4x4CXVZQ zmFRF/Di3XooVibmWL14C9uIaYqzxqvPRLZaoYrXNLonoQKzcGhw7wIlOTBOFj5dpTgq lTq1yQDBY8rrcjohzml4TopbJJj01YOAl1uSP3UBKJpWQjjfiW+geycQmMq2zEk7PbM+ BRhLh28ltXxu8n1sofyq2lqxzzO8B+pZQFkpA9DE3sl7DJqj6jDG7FO03LmJKvzA7OOa dh6QpovRwXgo4LreKs7OcT4j03lifDlVJqcVnPiQBcygI/pYyIluPssMI16VER+8BNtY n9TA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMUpxrMa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x16-20020ac87310000000b0042c74f61419si5320911qto.634.2024.02.26.10.04.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 10:04:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-82118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tMUpxrMa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-82118-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-82118-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 048A71C2B945 for ; Mon, 26 Feb 2024 18:04:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B7DB612EBDE; Mon, 26 Feb 2024 18:04:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="tMUpxrMa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD60E80058; Mon, 26 Feb 2024 18:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708970640; cv=none; b=uH2Pk9zd/DHXBKamNGhEQS5EqYJuz7lRHfp7NGuRMFcMIXnXiLjPyXkUldVnlb+3WRM/9PtRQIKqGIh9fk+RLVeJfwwSCxeFK/tLc5j+unp+kR2EtdaJX6+QU51i4PMXIaDiexm1G81EpZk48DQuIlZL8W/P1j0KNiz7eicSm/A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708970640; c=relaxed/simple; bh=mhTJjZKQrDShxZufuClbdZ2NvX4xFGOaNZAk1lyMMes=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=sh96a6Tq8B+KbX49LaG2Ua4IzKftmYNRmeVSRPWZgi5esdwQPNKta+opHGl/TgQH8AbMYe0OaO7phLfOhtsvz9YneEpDc1xaQvJ21ihqRpSDwlcquE0S5mv00VhkSq8Zp0jqasqHZMRc+ME8FzbPR88kIcr/uA+5NKP1aXk28X8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tMUpxrMa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4638EC433C7; Mon, 26 Feb 2024 18:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708970640; bh=mhTJjZKQrDShxZufuClbdZ2NvX4xFGOaNZAk1lyMMes=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=tMUpxrMaTOOrwNIHmAC9slZG/+uzyxb0RcBrBMKwFGkY31+YqR6DW30ZuA0g3Koi0 6ShU2OWvj9006LcsGxGyzWza4USkwgnm+LvF8hvLEzHcFaWXxpGvV2cm4b6K9ECRxI B0UfrNRjHUpy7qvZAvFIHmAJMXf9nZFmD74/0iXVw2S8t96fu+i0aNM0ZL4QzvG8te PN7uaQQ/lX5bY+QZoDfECo5Z/yBUC1VBPNvpCbJ+5C7awfFV5bRr/PCk2qeHpfqidq NrQJtByZc4XL7IykOv2zJI7fQkBZ1BF/KMHrIUFZcY7s6GZ62H8N1JDDik3Yx7K33e IxAdup/oYbGaA== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1refKX-006z6g-Rp; Mon, 26 Feb 2024 18:03:57 +0000 Date: Mon, 26 Feb 2024 18:03:57 +0000 Message-ID: <86a5nn2jci.wl-maz@kernel.org> From: Marc Zyngier To: James Clark Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, suzuki.poulose@arm.com, acme@kernel.org, oliver.upton@linux.dev, broonie@kernel.org, James Morse , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Alexander Shishkin , Anshuman Khandual , Miguel Luis , Joey Gouly , Ard Biesheuvel , Quentin Perret , Javier Martinez Canillas , Mark Rutland , Arnd Bergmann , Vincent Donnefort , Ryan Roberts , Fuad Tabba , Jing Zhang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v6 5/8] arm64: KVM: Add iflag for FEAT_TRF In-Reply-To: <8b9c1cce-401c-5084-ee2f-68beb03ad7a0@arm.com> References: <20240226113044.228403-1-james.clark@arm.com> <20240226113044.228403-6-james.clark@arm.com> <86edcz2vrz.wl-maz@kernel.org> <8b9c1cce-401c-5084-ee2f-68beb03ad7a0@arm.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.1 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: james.clark@arm.com, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, suzuki.poulose@arm.com, acme@kernel.org, oliver.upton@linux.dev, broonie@kernel.org, james.morse@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, mike.leach@linaro.org, alexander.shishkin@linux.intel.com, anshuman.khandual@arm.com, miguel.luis@oracle.com, joey.gouly@arm.com, ardb@kernel.org, qperret@google.com, javierm@redhat.com, mark.rutland@arm.com, arnd@arndb.de, vdonnefort@google.com, ryan.roberts@arm.com, tabba@google.com, jingzhangos@google.com, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 26 Feb 2024 15:41:02 +0000, James Clark wrote: > > > > On 26/02/2024 13:35, Marc Zyngier wrote: > > On Mon, 26 Feb 2024 11:30:33 +0000, > > James Clark wrote: [...] > >> diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c > >> index ce8886122ed3..49a13e72ddd2 100644 > >> --- a/arch/arm64/kvm/debug.c > >> +++ b/arch/arm64/kvm/debug.c > >> @@ -332,14 +332,30 @@ void kvm_arch_vcpu_load_debug_state_flags(struct kvm_vcpu *vcpu) > >> !(read_sysreg_s(SYS_PMBIDR_EL1) & BIT(PMBIDR_EL1_P_SHIFT))) > >> vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_SPE); > >> > >> - /* Check if we have TRBE implemented and available at the host */ > >> - if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_TraceBuffer_SHIFT) && > >> - !(read_sysreg_s(SYS_TRBIDR_EL1) & TRBIDR_EL1_P)) > >> - vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRBE); > >> + /* > >> + * Set SAVE_TRFCR flag if FEAT_TRF (TraceFilt) exists. This flag > >> + * signifies that the exclude_host/exclude_guest settings of any active > >> + * host Perf session on a core running a VCPU can be written into > >> + * TRFCR_EL1 on guest switch. > >> + */ > >> + if (cpuid_feature_extract_unsigned_field(dfr0, ID_AA64DFR0_EL1_TraceFilt_SHIFT)) { > >> + vcpu_set_flag(vcpu, DEBUG_STATE_SAVE_TRFCR); > > > > Can we avoid doing this unconditionally? It only makes sense to save > > the trace crud if it is going to be changed, right? > > > > Do you mean to see if kvm_guest_trfcr was non-zero (and would have to be > changed) at VCPU load? I assumed that it could be modified between load > and switch. That would mean there is no way to do it conditionally. What's the problem? If you change the value behind the vcpu's back, you get what you deserve: garbage. I'm baffled that you consider that randomly changing a value without proper synchronisation (such as with an IPI) is a valid approach. Please look at what is being done for the PMU in the same context. > I also assumed that's the reason SPE and TRBE were implemented like > this, with the feat check at load and the enabled check at switch. It > doesn't feel like TRFCR is any different to those two. Well, that' doesn't make it right. Having just looked at the debug stuff, I'm ashamed to have let that stuff in. > Or do you mean to only set DEBUG_STATE_SAVE_TRFCR on switch if tracing > was enabled? I don't think there should be any flag. The discriminant should be: - does the HW support TRF? - is the in-guest tracing enabled? If both are true, and that this requires a change of configuration, *then* you perform the change. Same thing on exit. No flag. And a static key for TRF support, which should really be valid on all CPUs. M. -- Without deviation from the norm, progress is not possible.