Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7814468rdb; Thu, 4 Jan 2024 08:29:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6h3rNklOANESAJLXBfbsgEYyQFLRxuxD9I+35MXTPUG/cykZQJIvB54QS3bgBRFpq+j+8 X-Received: by 2002:a05:6214:dc1:b0:67f:2d13:a58d with SMTP id 1-20020a0562140dc100b0067f2d13a58dmr878612qvt.53.1704385744222; Thu, 04 Jan 2024 08:29:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385744; cv=none; d=google.com; s=arc-20160816; b=h0QAq8YEkwVg5wUZ28QVajt1lvDo4Qe07FxI9rKqjxInLLW9ZWduhz5Otzq0GylTnw qV6ltnJh3YwAiwL2M84GKNpQpE8Y9TAXFOA7CCB9ZbQh+z/Rbu5z1vQFoOS5Y7U2VFyF rX25Tr4/3kMIIolcmMuYX6Ew+ZjP/KXMrUONz1DtZenhWwuRNVEGRMEnDwCNWtbdrwfW m2mpeZ+hRp+RVuRvEvbopgbstqnUvHpjm02yjKWVISHEYyto9QLfNW3Op/B1+gVDNkVU ba9aZvLpOrk69DE20sxBFbLA7DNt1L3XEoNugsb4TR8fF6k5bNXj7bPUXIOFX87kYVQ9 O4Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=4Lwq2z5CG5ww+UxS+rK2r8/4DYeXCxgx6IZcpSvNn9M=; fh=oGudNpsvhOK0OvNzVfeEyv1pDli8cEVuU7V81EJhEJI=; b=Jhf2k6NiC2soTQr6sgIBivM9cmvC9BsdaZSnYCC8epF2yDPbkKLjeUcsJ+yMXKGUbl zQ6rBDn5eLD9F8qsLPot8mXUXom3v3FCqkGaGaen8IRVwMHQt0NkISLWjKOTvtAmZ30T bD0g+hyr6/cnPqZKcoNEPqUSJizquUxT0ElbFUaxT1ltfDNQ2o/wTSpHk2EjUjATrDFT pVfRgovUzMOcPvSR0LVTpO7Qbch8FRb0OIbmOD0jah0kP88de28TtWi+jJFytX1OUgkH MwlpvD5Un/75cXKg8r72hK4aKNK9230ZIv8cELGmNrsa2bylGk48q1hCqCk0Dr2/M3OS qgzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id x7-20020a0ce247000000b0067f38efba32si31836697qvl.583.2024.01.04.08.29.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:29:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16929-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; spf=pass (google.com: domain of linux-kernel+bounces-16929-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16929-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 F25DD1C22317 for ; Thu, 4 Jan 2024 16:29:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2E81B25114; Thu, 4 Jan 2024 16:28:34 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 56B5425102 for ; Thu, 4 Jan 2024 16:28:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A8AFFC15; Thu, 4 Jan 2024 08:29:17 -0800 (PST) Received: from e127643.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2A9BD3F5A1; Thu, 4 Jan 2024 08:28:23 -0800 (PST) From: James Clark To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, broonie@kernel.org, maz@kernel.org, suzuki.poulose@arm.com, acme@kernel.org Cc: James Clark , Oliver Upton , James Morse , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Leo Yan , Alexander Shishkin , Anshuman Khandual , Rob Herring , Miguel Luis , Jintack Lim , Ard Biesheuvel , Mark Rutland , Javier Martinez Canillas , Arnd Bergmann , Kalesh Singh , Vincent Donnefort , Kristina Martsenko , Akihiko Odaki , Fuad Tabba , Joey Gouly , Jing Zhang , linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] arm64: KVM: Add iflag for FEAT_TRF Date: Thu, 4 Jan 2024 16:27:04 +0000 Message-Id: <20240104162714.1062610-5-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240104162714.1062610-1-james.clark@arm.com> References: <20240104162714.1062610-1-james.clark@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add an extra iflag to signify if the TRFCR register is accessible. Because TRBE requires FEAT_TRF, DEBUG_STATE_SAVE_TRBE still has the same behavior even though it's only set when FEAT_TRF is present. The following holes are left in struct kvm_vcpu_arch, but there aren't enough other 8 bit fields to rearrange it to leave any hole smaller than 7 bytes: u8 cflags; /* 2292 1 */ /* XXX 1 byte hole, try to pack */ u16 iflags; /* 2294 2 */ u8 sflags; /* 2296 1 */ bool pause; /* 2297 1 */ /* XXX 6 bytes hole, try to pack */ Reviewed-by: Suzuki K Poulose Signed-off-by: James Clark --- arch/arm64/include/asm/kvm_host.h | 4 +++- arch/arm64/kvm/debug.c | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 93d38ad257ed..4864a1fcdf89 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -551,7 +551,7 @@ struct kvm_vcpu_arch { u8 cflags; /* Input flags to the hypervisor code, potentially cleared after use */ - u8 iflags; + u16 iflags; /* State flags for kernel bookkeeping, unused by the hypervisor code */ u8 sflags; @@ -761,6 +761,8 @@ struct kvm_vcpu_arch { #define DEBUG_STATE_SAVE_TRBE __vcpu_single_flag(iflags, BIT(6)) /* vcpu running in HYP context */ #define VCPU_HYP_CONTEXT __vcpu_single_flag(iflags, BIT(7)) +/* Save trace filter controls */ +#define DEBUG_STATE_SAVE_TRFCR __vcpu_single_flag(iflags, BIT(8)) /* SVE enabled for host EL0 */ #define HOST_SVE_ENABLED __vcpu_single_flag(sflags, BIT(0)) diff --git a/arch/arm64/kvm/debug.c b/arch/arm64/kvm/debug.c index 8725291cb00a..f86cbfae60f3 100644 --- a/arch/arm64/kvm/debug.c +++ b/arch/arm64/kvm/debug.c @@ -331,14 +331,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); + /* + * Check if we have TRBE implemented and available at the host. + * If it's in use at the time of guest switch then trace will + * need to be completely disabled. The architecture mandates + * FEAT_TRF with TRBE, so we only need to check for TRBE after + * TRF. + */ + 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); + } } void kvm_arch_vcpu_put_debug_state_flags(struct kvm_vcpu *vcpu) { vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_SPE); vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRBE); + vcpu_clear_flag(vcpu, DEBUG_STATE_SAVE_TRFCR); } -- 2.34.1