Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp558268pxb; Wed, 25 Aug 2021 09:24:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXWHvsl+JkpOEIqicR0Sq1ZHFIkoheqFa68wTA0ukNO2A5SMFaHd6izHujT3nIxjoT8biK X-Received: by 2002:aa7:c408:: with SMTP id j8mr13182574edq.280.1629908668992; Wed, 25 Aug 2021 09:24:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629908668; cv=none; d=google.com; s=arc-20160816; b=yx7uJz5DZqDNDrsMO8H+6jB+yiKyIx2wd7AlLWlkoLckb5mAzWt2aFIuuI4vtoquH/ kmB9lZYfqBPrxW6ACI9r+GDPPCcBaq3ec6SXy5Z1OnZULRzWCTQPq4D+qNvV9IQmLHxy uWjcVArZoIz9bsr98FgXa6gjH3aEjXl5bjQmEalHVpZ0QgHIkG/94yNZD7/gCcTqEL95 UTUd2b6lIWIhlVukkAArmy0zrBWBgeNf/fF2e9dRHTwoRtFDOHiWuSBwQ4kL0iPVKp4I NDFD6QW/WmARpuO0veY2w32sjavTp8xV9tvfbSKm0NYnM+JIqi3p5yOP4vqSKaAfrYjR GJ/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from; bh=FnT7Mtb+UAUHIlhw+czaqqhBvTQo2H56x4fRsjdSQos=; b=kPR2zQ7sozGgAbLJUXumvO4TKBOBuU8X0H4ZTanNf6i14yYx7ktpupBjjeAphlU5LD oA2B0pxYy3AeZ4y3RPhCWdumq8DSWBGzTY8qlZGuHkQhuVULEuGUpulnFlcEX2zReQYd /WhZ8poxMtrCHK3xsSWiFl92J0kd/ipRQKDRljZ9e/nXBvjE3PRfwqIkwYM9DXE57Uv0 qApOqPduG0HqxVfNZ7yAGffP48fpQi47l89LVMH0FZkuAT3llT8r1E+AaZfm3msPRzVA sW7MmYy4B3QF/cHhQVSh65N3GErjcHCUcoi56SsoIM+orB/vWjZuTVUtzS5h4UOEA0c6 fA/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq40si191338ejc.619.2021.08.25.09.24.01; Wed, 25 Aug 2021 09:24:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242102AbhHYQUE (ORCPT + 99 others); Wed, 25 Aug 2021 12:20:04 -0400 Received: from foss.arm.com ([217.140.110.172]:54768 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241987AbhHYQS6 (ORCPT ); Wed, 25 Aug 2021 12:18:58 -0400 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 183DC14BF; Wed, 25 Aug 2021 09:18:12 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BDAE53F66F; Wed, 25 Aug 2021 09:18:10 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, will@kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v4 37/39] KVM: arm64: Add PMSIDR_EL1 to the SPE register context Date: Wed, 25 Aug 2021 17:18:13 +0100 Message-Id: <20210825161815.266051-38-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210825161815.266051-1-alexandru.elisei@arm.com> References: <20210825161815.266051-1-alexandru.elisei@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PMSIDR_EL1 is not part of the VCPU register context because the profiling control registers were not trapped and the register is read-only. With the introduction of the KVM_ARM_VCPU_SPE_STOP API, KVM will start trapping accesses to the profiling control registers, add PMSIDR_EL1 to the VCPU register context to prevent undefined exceptions in the guest. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/sys_regs.c | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index cc46f1406196..f866c4556ff9 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -247,6 +247,7 @@ enum vcpu_sysreg { PMSFCR_EL1, /* Sampling Filter Control Register */ PMSEVFR_EL1, /* Sampling Event Filter Register */ PMSLATFR_EL1, /* Sampling Latency Filter Register */ + PMSIDR_EL1, /* Sampling Profiling ID Register */ PMBLIMITR_EL1, /* Profiling Buffer Limit Address Register */ PMBPTR_EL1, /* Profiling Buffer Write Pointer Register */ PMBSR_EL1, /* Profiling Buffer Status/syndrome Register */ diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index cc711b081f31..1a85a0cedbec 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -603,6 +603,18 @@ static unsigned int spe_visibility(const struct kvm_vcpu *vcpu, return REG_HIDDEN; } +static void reset_pmsidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) +{ + /* + * When SPE is stopped by userspace, the guest reads the in-memory value + * of the register. When SPE is resumed, accesses to the control + * registers are not trapped and the guest reads the hardware + * value. Reset PMSIDR_EL1 to the hardware value to avoid mistmatches + * between the two. + */ + vcpu_write_sys_reg(vcpu, read_sysreg_s(SYS_PMSIDR_EL1), PMSIDR_EL1); +} + static bool access_spe_reg(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { int reg = r->reg; @@ -613,10 +625,14 @@ static bool access_spe_reg(struct kvm_vcpu *vcpu, struct sys_reg_params *p, *vcpu_pc(vcpu), *vcpu_cpsr(vcpu)); } - if (p->is_write) + if (p->is_write) { + if (reg == PMSIDR_EL1) + return write_to_read_only(vcpu, p, r); + kvm_spe_write_sysreg(vcpu, reg, val); - else + } else { p->regval = kvm_spe_read_sysreg(vcpu, reg); + } return true; } @@ -1568,7 +1584,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { { SPE_SYS_REG(SYS_PMSFCR_EL1), .reg = PMSFCR_EL1 }, { SPE_SYS_REG(SYS_PMSEVFR_EL1), .reg = PMSEVFR_EL1 }, { SPE_SYS_REG(SYS_PMSLATFR_EL1), .reg = PMSLATFR_EL1 }, - { SPE_SYS_REG(SYS_PMSIDR_EL1), .reset = NULL }, + { SPE_SYS_REG(SYS_PMSIDR_EL1), .reset = reset_pmsidr, .reg = PMSIDR_EL1 }, { SPE_SYS_REG(SYS_PMBLIMITR_EL1), .reg = PMBLIMITR_EL1 }, { SPE_SYS_REG(SYS_PMBPTR_EL1), .reg = PMBPTR_EL1 }, { SPE_SYS_REG(SYS_PMBSR_EL1), .reg = PMBSR_EL1 }, -- 2.33.0