Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp7814111rdb; Thu, 4 Jan 2024 08:28:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IEWqzjH4+Q6Wrzpo8So0mS/EYJNUNCMt0Pbbu9kk1YaFOF7LafDnrLIG57w2okRLrUnyKot X-Received: by 2002:a05:6359:3184:b0:170:3ef2:de12 with SMTP id ri4-20020a056359318400b001703ef2de12mr576325rwb.46.1704385702676; Thu, 04 Jan 2024 08:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704385702; cv=none; d=google.com; s=arc-20160816; b=A1/l9z8CfoQBTPIdv43f5E8lqWf9QzpuFtiZcWGDFtXO9DvwkDSljOtR+OfYIkeLaJ L0ehNyz6jJ9nvrMrtrTQz3YGDGIGBk/hLOlIAfSqSMJ2olmS9J0rexCJuRmOYY04gg6L gaOg4CKN5/2jDZUZ5XwyJVpdEkRcMFf9ARPnTLaoJZ/BXikpNb4Qpim4ggIjchOrzhGI wi4OtkCciNYxBEv3KOajjAXZsmQ9wWCzczdbNdew0Kx35Kblz1pxho00GBhBRqpzOGJj 2XVukxZmbjvQQ2knt/SsY3rGe2XK0mXx8/sBJnkWREUioO47m5c3Q9tEdQyWNTEe5bh6 o5Sg== 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:message-id:date:subject:cc:to :from; bh=jdjRFoVCD5khtbl2rbVBCeUkKlZT1dFD+2NTPvCgiPI=; fh=DVCW9AaHIbCyGv21yfYB0wpSRzXIHYaaosVnshlVF1g=; b=PjRuiEFkakm0hIj93HEZLA4r6JtCi+H9XfGQxtPS3ieXrvzu7pSSmQhJ/ISWjxtdt7 /umOt7JHzo2APeNR+dZuWLCg7PB/UK8H/l2uWQuY4jDmMIJGE3VGm16q3CSqGKGKdggh d/pR6W961PL3hXooWZymaJNFldmLsQC+1DDgYyeRn5A2PKAWkAgBuH+svQC/KA5GCXBS NCqoyK/gc1QTXRX7wWjca769ySJj09qM4APGtWOrxFbCpDwQzOCJthq3pc770quM4UQa TqdhjDYDeLsSfXjgYTm8SiVd2ikFWnKATOoh+zWYmCua6CuzJuuT3/rFbIk3AF7YEQLG SaTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16924-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id s62-20020a635e41000000b005ce018f4293si20630650pgb.701.2024.01.04.08.28.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 08:28:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-16924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-16924-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-16924-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 6CC03B24CBC for ; Thu, 4 Jan 2024 16:27:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CF09C24B3D; Thu, 4 Jan 2024 16:27:33 +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 61A6424B29 for ; Thu, 4 Jan 2024 16:27:31 +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 A39FEC15; Thu, 4 Jan 2024 08:28:16 -0800 (PST) Received: from e127643.. (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 968433F5A1; Thu, 4 Jan 2024 08:27: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 , Helge Deller , Arnd Bergmann , Quentin Perret , Vincent Donnefort , Akihiko Odaki , Fuad Tabba , Kristina Martsenko , Joey Gouly , Jing Zhang , linux-kernel@vger.kernel.org Subject: [PATCH v4 0/7] kvm/coresight: Support exclude guest and exclude host Date: Thu, 4 Jan 2024 16:27:00 +0000 Message-Id: <20240104162714.1062610-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: 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 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. --- 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/ James Clark (7): arm64: KVM: Fix renamed function in comment arm64: KVM: Use shared area to pass PMU event state to hypervisor 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 | 15 +- arch/arm64/include/asm/sysreg.h | 12 - arch/arm64/kernel/image-vars.h | 1 + arch/arm64/kvm/arm.c | 16 +- arch/arm64/kvm/debug.c | 48 ++- arch/arm64/kvm/hyp/nvhe/debug-sr.c | 55 +-- arch/arm64/kvm/hyp/nvhe/setup.c | 13 +- arch/arm64/kvm/hyp/nvhe/switch.c | 9 +- arch/arm64/kvm/pmu.c | 4 +- arch/arm64/tools/sysreg | 41 +++ .../coresight/coresight-etm4x-core.c | 42 ++- drivers/hwtracing/coresight/coresight-etm4x.h | 2 +- drivers/hwtracing/coresight/coresight-priv.h | 3 + include/kvm/arm_pmu.h | 17 - tools/arch/arm64/include/asm/sysreg.h | 345 +++++++++++++++++- tools/include/linux/kasan-tags.h | 15 + 16 files changed, 554 insertions(+), 84 deletions(-) create mode 100644 tools/include/linux/kasan-tags.h -- 2.34.1