Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1243480rbb; Mon, 26 Feb 2024 03:33:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqPOZ6uePqDY0tH06RAgWxV1NQEjufvCK/V/lHtjnsGjwL7PXcBj1Gf6sbufrUT7qh+qL7fn46+WuaGVZiJskzSvVNw550m2m9VShpJg== X-Google-Smtp-Source: AGHT+IG8CCE/kYIsrHn0pS7j07oFJ92FGQqLpDcBiyB4XThu8S50buyELrllrFHgr7PBHHorzwiX X-Received: by 2002:a05:6359:458d:b0:176:d46c:e704 with SMTP id no13-20020a056359458d00b00176d46ce704mr8006262rwb.16.1708947192777; Mon, 26 Feb 2024 03:33:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708947192; cv=pass; d=google.com; s=arc-20160816; b=P5mweO5RNDx5oKShU8l+VgAWxk/EFaaap83qdKFOzuks1njLXMHFHIKHeiGkQsj0Le xx9+4TTtIxGEq3f8iTHHd+EAyafed1Ftt1KbDSciuhfERv6kEAaF2OuT9qoLMMrlvyuz okDf4biPUbO+uV3j1Zn1nd0MzA1y/O1LRLK6NlPLMzs6fukq2g2QEnIgS+fqas/aCd4/ TJBphKUg4YsLz5on2+FScTfMJNiLgIJHJmT8xP+p4AsLC+ZS6RbtaQ5v3m+ryNxRMJDP l6p3UufbB5ItlAhkS0MMnAj9VToTLzEdqMO3G9EbZNB1zPWIdizEL13WFKddusXRA0FK kDuA== ARC-Message-Signature: i=2; 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:message-id:date:subject:cc:to :from; bh=6PX9yGB7fJHZZqdFUZ9KCI2aYD1mgfj9VAlcHPGqMQw=; fh=8YtgjMY+/alDUnU/OpPmql9C83bKlyIOQbg8EB569x8=; b=HfGHR9dCTtGg7wM3xlZHDRTFPqiPC4uSkFB1YXtWS7n1chCwP5DYWODpc8dtNpz9og blPGvgthNBvhxV9zAbeXdKUITLISJPhoBR9miAMUQOr29uAZ4M8tBlgA7pmBUjkZ4AeZ qmBhOAF/eO88S5gQcmj2IWr9LEASyD51X3yXscrRfbTbzmxn9ZZ294vBSytVN1OpIn0+ 4WF/kh77SSL5uX55O9vggywoKk/Dlfm8qIudBqI02ud6ORoKtttwmZjKgu5Mf/0DP1DZ muQe6c/zpgkzcpeA39ueXlqCtghhl9taoOCBWr4DLVDd6OS1Tl098spAdfWkGbeKO6II iEXQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-81265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81265-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h66-20020a636c45000000b005dc6576d8adsi3561919pgc.386.2024.02.26.03.33.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 03:33:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-81265-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81265-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 6D2352892F8 for ; Mon, 26 Feb 2024 11:33:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9C9CE1DA23; Mon, 26 Feb 2024 11:33:07 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC7C61D546 for ; Mon, 26 Feb 2024 11:33:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708947187; cv=none; b=QlwfgSiieuEIcjzyij9Bfk6ntlNEGm1RvchiwhB77dLWvLh9EiBmYXEI7R0P/eL4iMfjdvIF4Fu8u4jMrsPzl7whtrk6yXnPuK9sFl9bxd128UWn50fAJdazjMa4s3PNAXN1oic/NO82MfgPWm2ky6MNHw1eyp42Q+DhS3WUwfM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708947187; c=relaxed/simple; bh=dVvusUqZUQYYyXGU6LPv5l7YLKfrSCfBWtzkuyf2pnI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=MFhGD5tXTwPJp0fmg5hpGcefQwxhTAb8rgC38PUx++6AV7fftTm4MRR3aup6CUmxV81t2m7XZ/GLjdUPrP1VdxMlnxSnb68/d9CMTRhdu+0gHgic8gTEAvW/dvSqfKmOLkmzGiZIbFj5gfZBRwdBOSE80pD3Chl1kcfEk3Q4gI0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 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 B2B18DA7; Mon, 26 Feb 2024 03:33:41 -0800 (PST) Received: from e127643.broadband (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 923DD3F6C4; Mon, 26 Feb 2024 03:32:59 -0800 (PST) From: James Clark To: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, maz@kernel.org, suzuki.poulose@arm.com, acme@kernel.org, oliver.upton@linux.dev, broonie@kernel.org Cc: James Clark , James Morse , Zenghui Yu , Catalin Marinas , Will Deacon , Mike Leach , Alexander Shishkin , Anshuman Khandual , Miguel Luis , Joey Gouly , Ard Biesheuvel , Arnd Bergmann , Mark Rutland , Helge Deller , Quentin Perret , Vincent Donnefort , Ryan Roberts , Fuad Tabba , Jing Zhang , linux-kernel@vger.kernel.org Subject: [PATCH v6 0/8] kvm/coresight: Support exclude guest and exclude host Date: Mon, 26 Feb 2024 11:30:28 +0000 Message-Id: <20240226113044.228403-1-james.clark@arm.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This is a combination of the RFC for nVHE here [1] and v3 of VHE version here [2]. After a few of the review comments it seemed much simpler for both versions to use the same interface and be in the same patchset. FEAT_TRF is a Coresight feature that allows trace capture to be completely filtered at different exception levels, unlike the existing TRCVICTLR controls which may still emit target addresses of branches, even if the following trace is filtered. Without FEAT_TRF, it was possible to start a trace session on a host and also collect trace from the guest as TRCVICTLR was never programmed to exclude guests (and it could still emit target addresses even if it was). With FEAT_TRF, the current behavior of trace in guests exists depends on whether nVHE or VHE are being used. Both of the examples below are from the host's point of view, as Coresight isn't accessible from guests. This patchset is only relevant to when FEAT_TRF exists, otherwise there is no change. nVHE/pKVM: Because the host and the guest are both using TRFCR_EL1, trace will be generated in guests depending on the same filter rules the host is using. For example if the host is tracing userspace only, then guest userspace trace will also be collected. (This is further limited by whether TRBE is used because an issue with TRBE means that it's completely disabled in nVHE guests, but it's possible to have other tracing components.) VHE: With VHE, the host filters will be in TRFCR_EL2, but the filters in TRFCR_EL1 will be active when the guest is running. Because we don't write to TRFCR_EL1, guest trace will be completely disabled. With this change, the guest filtering rules from the Perf session are now honored for both nVHE and VHE modes. This is done by either writing to TRFCR_EL12 at the start of the Perf session and doing nothing else further, or caching the guest value and writing it at guest switch for nVHE. In pKVM, trace is now be disabled for both protected and unprotected guests. --- Changes since V5 [4]: * Sort new sysreg entries by encoding * Add a comment about sorting arch/arm64/tools/sysreg * Warn on preemptible() before calling smp_processor_id() * Pickup tags * Change TRFCR_EL2 from SysregFields to Sysreg because it was only used once Changes since V4 [3]: * Remove all V3 changes that made it work in pKVM and just disable trace there instead * Restore PMU host/hyp state sharing back to how it was (kvm_pmu_update_vcpu_events()) * Simplify some of the duplication in the comments and function docs * Add a WARN_ON_ONCE() if kvm_etm_set_guest_trfcr() is called when the trace filtering feature doesn't exist. * Split sysreg change into a tools update followed by the new register addition Changes since V3: * Create a new shared area to store the host state instead of copying it before each VCPU run * Drop commit that moved SPE and trace registers from host_debug_state into the kvm sysregs array because the guest values were never used * Document kvm_etm_set_guest_trfcr() * Guard kvm_etm_set_guest_trfcr() with a feature check * Drop Mark B and Suzuki's review tags on the sysreg patch because it turned out that broke the Perf build and needed some unconventional changes to fix it (as in: to update the tools copy of the headers in the same commit as the kernel changes) Changes since V2: * Add a new iflag to signify presence of FEAT_TRF and keep the existing TRBE iflag. This fixes the issue where TRBLIMITR_EL1 was being accessed even if TRBE didn't exist * Reword a commit message Changes since V1: * Squashed all the arm64/tools/sysreg changes into the first commit * Add a new commit to move SPE and TRBE regs into the kvm sysreg array * Add a comment above the TRFCR global that it's per host CPU rather than vcpu Changes since nVHE RFC [1]: * Re-write just in terms of the register value to be written for the host and the guest. This removes some logic from the hyp code and a value of kvm_vcpu_arch:trfcr_el1 = 0 no longer means "don't restore". * Remove all the conditional compilation and new files. * Change the kvm_etm_update_vcpu_events macro to a function. * Re-use DEBUG_STATE_SAVE_TRFCR so iflags don't need to be expanded anymore. * Expand the cover letter. Changes since VHE v3 [2]: * Use the same interface as nVHE mode so TRFCR_EL12 is now written by kvm. [1]: https://lore.kernel.org/kvmarm/20230804101317.460697-1-james.clark@arm.com/ [2]: https://lore.kernel.org/kvmarm/20230905102117.2011094-1-james.clark@arm.com/ [3]: https://lore.kernel.org/linux-arm-kernel/20240104162714.1062610-1-james.clark@arm.com/ [4]: https://lore.kernel.org/all/20240220100924.2761706-1-james.clark@arm.com/ James Clark (8): arm64: KVM: Fix renamed function in comment arm64/sysreg: Add a comment that the sysreg file should be sorted tools: arm64: Update sysreg.h header files arm64/sysreg/tools: Move TRFCR definitions to sysreg arm64: KVM: Add iflag for FEAT_TRF arm64: KVM: Add interface to set guest value for TRFCR register arm64: KVM: Write TRFCR value on guest switch with nVHE coresight: Pass guest TRFCR value to KVM arch/arm64/include/asm/kvm_host.h | 7 +- arch/arm64/include/asm/sysreg.h | 12 - arch/arm64/kernel/image-vars.h | 1 + arch/arm64/kvm/debug.c | 53 ++- arch/arm64/kvm/hyp/nvhe/debug-sr.c | 53 ++- arch/arm64/kvm/hyp/nvhe/setup.c | 2 +- arch/arm64/tools/sysreg | 38 ++ .../coresight/coresight-etm4x-core.c | 42 +- drivers/hwtracing/coresight/coresight-etm4x.h | 2 +- drivers/hwtracing/coresight/coresight-priv.h | 3 + tools/arch/arm64/include/asm/sysreg.h | 375 +++++++++++++++++- tools/include/linux/kasan-tags.h | 15 + 12 files changed, 541 insertions(+), 62 deletions(-) create mode 100644 tools/include/linux/kasan-tags.h -- 2.34.1