From patchwork Wed Oct 11 08:16:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13416853 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1CEA7CD98FD for ; Wed, 11 Oct 2023 08:17:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230134AbjJKIRS (ORCPT ); Wed, 11 Oct 2023 04:17:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbjJKIRR (ORCPT ); Wed, 11 Oct 2023 04:17:17 -0400 Received: from out-190.mta1.migadu.com (out-190.mta1.migadu.com [95.215.58.190]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61EDA93 for ; Wed, 11 Oct 2023 01:17:16 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1697012234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=l4MtoeUio+QJkGABxRH9TB9eJMl3DOp+ol2TBjjaaNk=; b=nOGAlB2DnGpg6RE7lLGfaR1M3Nm4Ta5kiffzTkiJebyxxBPn3bjs2t1G96WeuBR6P6Zc12 0hPCeExtmT53kw8V0DyaHUn++UpeP7zwQ/UcnAfIz8h0exp8vsdwqpQ7JLipFuUIiyw57A 4VXFa+kMs4QF4EJzbi4jYzJe5P01Qi8= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Raghavendra Rao Ananta , Mark Rutland , Will Deacon , James Clark , Oliver Upton Subject: [PATCH 1/2] KVM: arm64: Disallow vPMU for NV guests Date: Wed, 11 Oct 2023 08:16:47 +0000 Message-ID: <20231011081649.3226792-2-oliver.upton@linux.dev> In-Reply-To: <20231011081649.3226792-1-oliver.upton@linux.dev> References: <20231011081649.3226792-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The existing PMU emulation code is inadequate for use with nested virt. Disable the feature altogether with NV until the hypervisor controls are handled correctly. Signed-off-by: Oliver Upton --- arch/arm64/kvm/arm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 1bfdd583b261..356b7eec3c93 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1238,9 +1238,10 @@ static int kvm_vcpu_init_check_features(struct kvm_vcpu *vcpu, test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, &features)) return -EINVAL; - /* Disallow NV+SVE for the time being */ + /* Disallow PMU and SVE with NV for the time being */ if (test_bit(KVM_ARM_VCPU_HAS_EL2, &features) && - test_bit(KVM_ARM_VCPU_SVE, &features)) + (test_bit(KVM_ARM_VCPU_SVE, &features) || + test_bit(KVM_ARM_VCPU_PMU_V3, &features))) return -EINVAL; if (!test_bit(KVM_ARM_VCPU_EL1_32BIT, &features)) From patchwork Wed Oct 11 08:16:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 13416855 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E8D39CD98FD for ; Wed, 11 Oct 2023 08:17:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344742AbjJKIRV (ORCPT ); Wed, 11 Oct 2023 04:17:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230179AbjJKIRU (ORCPT ); Wed, 11 Oct 2023 04:17:20 -0400 Received: from out-199.mta1.migadu.com (out-199.mta1.migadu.com [95.215.58.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9F35C93 for ; Wed, 11 Oct 2023 01:17:18 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1697012236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m/P2cXWXKHxiKIrHs6BVDT2TzNGuicu3kg1x643elmo=; b=fI2e3O2CpjLkohDlSCvitB3OpjTRFNOfdJtfu703Z85lVSCv4t3gBkVUM4Vfg6v7GgaBy5 LzI0tIPRPDT1AnFQpb/3fWRPTdK7PrTLkeNSGZzrhEF/VsFuumyY7qbPoLmidASbJOKYJq 1TzqA43oxEmdbQoeO1rov+LAVtBNWCs= From: Oliver Upton To: kvmarm@lists.linux.dev Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Suzuki K Poulose , Zenghui Yu , Raghavendra Rao Ananta , Mark Rutland , Will Deacon , James Clark , Oliver Upton Subject: [PATCH 2/2] KVM: arm64: Treat PMEVTYPER_EL0.NSH as RES0 Date: Wed, 11 Oct 2023 08:16:48 +0000 Message-ID: <20231011081649.3226792-3-oliver.upton@linux.dev> In-Reply-To: <20231011081649.3226792-1-oliver.upton@linux.dev> References: <20231011081649.3226792-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Prevent the guest from setting the NSH bit, which enables event counting while the PE is in EL2. kvm_pmu_create_perf_event() never wired up the bit, nor does it make any sense in the context of a guest without NV. While at it, build the event type mask using explicit field definitions instead of relying on ARMV8_PMU_EVTYPE_MASK. KVM probably should've been doing this in the first place, as it avoids changes to the aforementioned mask affecting sysreg emulation. Signed-off-by: Oliver Upton Reviewed-by: Suzuki K Poulose kvm); reg = counter_index_to_evtreg(pmc->idx);