From patchwork Sat Feb 8 02:01:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13966228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1DA98C02199 for ; Sat, 8 Feb 2025 02:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:Mime-Version:Date:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=h057a6wBvbw/h7/thrY5CNdcIWE5bhRIXwUHBVJJdVc=; b=KUflwrSEqGSoWCKSHyAv1MuiNu TX2XBGqqOkkNhJ/1BugNJCUbJ7sRnCO7krhjGFOnT8+d2GkAImyD9Z60APC2GvcPyoo8+pU+YYb4O vevWbP7lrDwPbEjg4w5DAZCGtSwMoDE2cf6pggZ6q9IqbOm/bD7KC2IcLP+5/N/sWK5hEU89BpMCh naAi6a/O0W5m1qtNbk+wtwQ+ovsy/mCOKceAgY2JL5x3G5B6jeOTAV6iLAlZ5DSmwFRL4MwCh6BGE aZGQmWIZ1mxoEZbWipnxSF0NSSz0JESSY64m40II3F8wwdFalY78gKKRIIIpxb719VEMevYpQSOV8 2ePRNrsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tgaDc-0000000BsBX-1NcT; Sat, 08 Feb 2025 02:05:16 +0000 Received: from mail-ot1-x349.google.com ([2607:f8b0:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tga9s-0000000BrLy-12wY for linux-arm-kernel@lists.infradead.org; Sat, 08 Feb 2025 02:01:25 +0000 Received: by mail-ot1-x349.google.com with SMTP id 46e09a7af769-71e24087e47so947986a34.3 for ; Fri, 07 Feb 2025 18:01:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738980082; x=1739584882; darn=lists.infradead.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h057a6wBvbw/h7/thrY5CNdcIWE5bhRIXwUHBVJJdVc=; b=iKHsVoJ00UOV8XvskHXC//MOpOuE+Txg98D2YUQ92M/8qDgJWyNgqZiekReivsAYQq aGwXfrPjiOLjf0rgjd25gduGaqNocHIeLLk9sG8N2036oMCCoOQzzi4j/RbEcCcsqDxL tlbY+H9rAWLISoQWUcPAxkRWNrjZRghD1zJ1vDZrwFNOZ+oHoqQEIbMrb45v0K+KYDhq +8admbrpzfpMk2O4o+MxCS1CjQLE2yMmOOoEfNsJtgkzxReEVlDScdrk+H5HRepTa5ZY JKt/qE3HIaE5d2wm1ST4NSPu0eb+dG0BAjIhabux+rdcqpKS4+RQjtRmbpWFqRyWo+Ab n0Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738980082; x=1739584882; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h057a6wBvbw/h7/thrY5CNdcIWE5bhRIXwUHBVJJdVc=; b=O/vyr0DC9rWzQ7GivO/MJK+qdrWjaNT3+L3FQLugvRkQ30S0xPW8hy10KvSr1qkNFo OkJLUk7Q/kXk1+ajPtcnD9YlCE41IPxiB/SAG0AD9A/o0OyUhMrm8D4SeeWZWuIbF79V ZnMOIVYjjRaJw6IyKZdx6gvNuvwOabBoIjLT/KlzbWPfEnWl5xpDcNb8g5Q5AuUMCn80 35D4+I0/bMtq11bWpl2t4CvW/3laHGqJiBuVEK3EyQL2/L8biiK6H7F/NcZhxRkqpO6t pX0EoAWAFVWyKs/IslUbNLiw4nb5K5c5EoyedwYN+Yab/LTiEEYlDwCFLAW9qtL4Xzzx tgmQ== X-Forwarded-Encrypted: i=1; AJvYcCWWgo2LcmhnMHx4oSHPBW07Jw+WNxcZ+ZrgGtdzk0Y6De6xyuAfPUFcVBNjl6dFZ9ny0zPy1j4tFZb1cQOGOI7o@lists.infradead.org X-Gm-Message-State: AOJu0Yx+rvtGOASG5hJT9wIVTF8K6tHFcWNl+uN78TFotRmekvPSFexO i+SHWewyBxOsBzQehpzogh/x+qe0KDRfqfspNY3JhORC+anjpIeeOhww7JyFcwO3y6zYzrhF5nt 3IpO2qdMKb4x+6C/fIMOfwg== X-Google-Smtp-Source: AGHT+IEeIQl7ICG4+Tc/ss00exHzkJsS1m2K/kNfEhqSBG/Hd5ytT4t77wwZci5K7lAYgGA5tByy2i89yzSGB3II1A== X-Received: from otbel32.prod.google.com ([2002:a05:6830:71a0:b0:71d:e05c:915b]) (user=coltonlewis job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6830:4989:b0:71d:62bc:85ec with SMTP id 46e09a7af769-726b87f4aecmr3709624a34.13.1738980082581; Fri, 07 Feb 2025 18:01:22 -0800 (PST) Date: Sat, 8 Feb 2025 02:01:07 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.48.1.502.g6dc24dfdaf-goog Message-ID: <20250208020111.2068239-1-coltonlewis@google.com> Subject: [RFC PATCH v2 0/4] PMU partitioning driver support From: Colton Lewis To: kvm@vger.kernel.org Cc: Russell King , Catalin Marinas , Will Deacon , Marc Zyngier , Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Mark Rutland , Paolo Bonzini , Shuah Khan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-perf-users@vger.kernel.org, linux-kselftest@vger.kernel.org, Colton Lewis X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250207_180124_298070_61960B7F X-CRM114-Status: GOOD ( 20.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This series introduces support in the ARM PMUv3 driver for partitioning PMU counters into two separate ranges by taking advantage of the MDCR_EL2.HPMN register field. The advantage of a partitioned PMU would be to allow KVM guests direct access to a subset of PMU functionality, greatly reducing the overhead of performance monitoring in guests. While this feature could be accepted on its own merits, practically there is a lot more to be done before it will be fully useful, so I'm sending as an RFC for now. v2: * Rebase to v6.14-rc1, and take into account Oliver's debug cleanup changing some KVM handling of MDCR_EL2. * Reorder patches to put related things closer together for easier reading. * Ensure driver compiles for 32-bit ARM by defining 32-bit access to MDCR_EL2 correctly, which is called HDCR there. These will not be called due to the below requirement for VHE mode but a functionally correct definition seemed preferable to making it a no op. * Rename parameter to reserved_host_counters to better reflect underlying hardware semantics and ensure host counters are easier to preserve. * Document parameter with MODULE_PARM_DESC * Restrict partitioning to VHE mode only. Using HPMN restricts the host counters to EL2 access only. Trying to make this work for the driver running at EL1 would require hypercalls for every access of those registers and a lot of additional handling at the KVM level. This would defeat the whole purpose of having the feature at all. Define has_vhe() on 32-bit arm to always return false. * While Rob asked about making the parameter configurable at run time rather than boot time through sysfs, that is potentially very tricky because it is only safe to reprogram HPMN when we are certain no one, host or guest, is using any counters that might change ownership. If this is determined to be worthwhile, it should come after getting the core infrastructure right. * While Marc asked about reusing the sysreg masks instead of redefining them for MDCR_EL2, that doesn't work because sysreg masks are only defined for arm64. I'm not sure how to avoid the duplication. * Wrap code for determining if a counter index belongs to the host or guest partition in functions * Typo fixes and additional testing v1: https://lore.kernel.org/kvm/20250127222031.3078945-1-coltonlewis@google.com/ Colton Lewis (4): perf: arm_pmuv3: Generalize counter bitmasks perf: arm_pmuv3: Introduce module param to partition the PMU perf: arm_pmuv3: Keep out of guest counter partition KVM: arm64: Make guests see only counters they can access arch/arm/include/asm/arm_pmuv3.h | 13 ++ arch/arm64/include/asm/arm_pmuv3.h | 10 ++ arch/arm64/kvm/debug.c | 3 +- arch/arm64/kvm/pmu-emul.c | 8 +- drivers/perf/arm_pmuv3.c | 117 ++++++++++++++++-- include/linux/perf/arm_pmu.h | 2 + include/linux/perf/arm_pmuv3.h | 34 ++++- .../selftests/kvm/arm64/vpmu_counter_access.c | 2 +- 8 files changed, 168 insertions(+), 21 deletions(-) base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b --- 2.48.1.502.g6dc24dfdaf-goog