From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F151E134A5 for ; Tue, 14 May 2024 07:29:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671746; cv=none; b=YlxUEyiX1jJcBxNwX7mOaWyyN8nTg/Dr/ZEhhVs6nVGXJgwX4uK3/q4XswTKQ+e2b4q6Nb3dCy7Nm5YM2z+8oyMhXfNZAs8/Z0UM9mjGG67P6rtNZWHJj1EsmyvdcIN7hNiB8ySe5FTdYGug/RaM92mXegTzvS2YMP8N76ABoB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671746; c=relaxed/simple; bh=SplUyiceO33acZVUSNIv+R1LEcFl7TGSw9aJpGoYgm4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=br++bR5R/s+FElXAfBUccXEvc2av1QVeiWUgLj/9D/0hlshweIgeVlTz6QYYnJzr6E67ffqL2bR+NxL+Ah2ZIiyBqKdmDWxDQFD8/qoHw7nf04iknxLi+Xm5wY57eeONh9pTPUcfxVp9qvfQV6BxIOfKsUhKAyb/+0QiIqR6rFs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ZwVDpqbN; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZwVDpqbN" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671744; 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=Rb7KafJV7I3Bq8cEiRTMNitbrzaJJX9E0+TIJqM8O5c=; b=ZwVDpqbNRM42gMwolQ4bN0d8K6TI6ddKG8GqFDzhofQN9RZ8v4Y/LTU0DXrXk4VTdQ8MrK 7wA8Zf6R1iCmAw8gHOIFDOx7khb+BiVifeCH6unNcKxX2Lv0lM1uUuQw6QJeZMObQXLOlG s/L74ObpKDo6fqSr2jb+skY0f0Eox6Y= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-I5w7gbb1MDiaYX_RaI3T1Q-1; Tue, 14 May 2024 03:23:00 -0400 X-MC-Unique: I5w7gbb1MDiaYX_RaI3T1Q-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-69b6fe789e9so45448796d6.0 for ; Tue, 14 May 2024 00:23:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671380; x=1716276180; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Rb7KafJV7I3Bq8cEiRTMNitbrzaJJX9E0+TIJqM8O5c=; b=YQKsziiGvo7Eg4Rph6aKQqkTjMtP1vBbLTrbtiHdL12BV8kMk60SKRq9VRMM0SpM6D nnEDvb9P+mi4/bEislmxgHiMhWXH60s2LSO3hX0wFiMH0EOR9c7YGVdlTIW+zTWx8QrL LwglEkDkhVxCMtZd9M3FoaCflpINqdSUQeBdxc9jB0mAEGB6jYCphladWhTMTsQesRM8 D8e3X5KzEUfTyk3RjIAsvuk1bJ0xzEiQQBZU4rXhRpnTz8FGhaA9iLTD69fOyUZOHEkP zGd5PVeS9D7DzyIoNRe4bNtRdUydRzk6hJNw9jltTSP3wsKuJTeS8CuBrnmTGRPliOYe h2Ew== X-Forwarded-Encrypted: i=1; AJvYcCUIqSaDTg4fwkvQPoOXC5VrlWnWYc+E6PPVbo/QudN1t/HRLnBi2R8FqA7g3P13C6GbSJ7IAn0sG/CTEP7Wn703qKuxA31MrZAbeSKs X-Gm-Message-State: AOJu0YzcdA/L+j1gW50P0TC7U2IAkadWAerYihzow0VBWK59mWqDndFB BamjK8GnjE/6qoX5KIqH8783glGCNlrELucbklej/ET0femGH1CVFmMZFFgxXF5dDKiU/1UJP3t m9JAma09yzSUdTtVr1LFe1zHEs06aYSykIk6hx0PzNGbBXfP8lRts+O0b8Yv+1w== X-Received: by 2002:a05:6214:5b81:b0:6a0:c151:6283 with SMTP id 6a1803df08f44-6a16838986fmr165997566d6.56.1715671379854; Tue, 14 May 2024 00:22:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFdX4p3qfLGGnIV/WfSKOJPR1Byzbb/+g2h6nrg91L5/ZNPPFTPTSZHsAztlmX12uE60Uj70Q== X-Received: by 2002:a05:6214:5b81:b0:6a0:c151:6283 with SMTP id 6a1803df08f44-6a16838986fmr165997406d6.56.1715671379502; Tue, 14 May 2024 00:22:59 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.22.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:22:58 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 1/6] KVM: arm64: unify code to prepare traps Date: Tue, 14 May 2024 09:22:47 +0200 Message-ID: <20240514072252.5657-2-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are 2 functions to calculate traps via HCR_EL2: * kvm_init_sysreg() called via KVM_RUN (before the 1st run or when the pid changes) * vcpu_reset_hcr() called via KVM_ARM_VCPU_INIT To unify these 2 and to support traps that are dependent on the ID register configuration, move the code from vcpu_reset_hcr() to sys_regs.c and call it via kvm_init_sysreg(). We still have to keep the non-FWB handling stuff in vcpu_reset_hcr(). Also the initialization with HCR_GUEST_FLAGS is kept there but guarded by !vcpu_has_run_once() to ensure that previous calculated values don't get overwritten. While at it rename kvm_init_sysreg() to kvm_calculate_traps() to better reflect what it's doing. Signed-off-by: Sebastian Ott Reviewed-by: Eric Auger --- arch/arm64/include/asm/kvm_emulate.h | 40 +++++++--------------------- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/kvm/arm.c | 2 +- arch/arm64/kvm/sys_regs.c | 34 +++++++++++++++++++++-- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/= kvm_emulate.h index 501e3e019c93..84dc3fac9711 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -69,39 +69,17 @@ static __always_inline bool vcpu_el1_is_32bit(struct kv= m_vcpu *vcpu) =20 static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) { - vcpu->arch.hcr_el2 =3D HCR_GUEST_FLAGS; - if (has_vhe() || has_hvhe()) - vcpu->arch.hcr_el2 |=3D HCR_E2H; - if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN)) { - /* route synchronous external abort exceptions to EL2 */ - vcpu->arch.hcr_el2 |=3D HCR_TEA; - /* trap error record accesses */ - vcpu->arch.hcr_el2 |=3D HCR_TERR; - } + if (!vcpu_has_run_once(vcpu)) + vcpu->arch.hcr_el2 =3D HCR_GUEST_FLAGS; =20 - if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) { - vcpu->arch.hcr_el2 |=3D HCR_FWB; - } else { - /* - * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C - * get set in SCTLR_EL1 such that we can detect when the guest - * MMU gets turned on and do the necessary cache maintenance - * then. - */ + /* + * For non-FWB CPUs, we trap VM ops (HCR_EL2.TVM) until M+C + * get set in SCTLR_EL1 such that we can detect when the guest + * MMU gets turned on and do the necessary cache maintenance + * then. + */ + if (!cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) vcpu->arch.hcr_el2 |=3D HCR_TVM; - } - - if (cpus_have_final_cap(ARM64_HAS_EVT) && - !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE)) - vcpu->arch.hcr_el2 |=3D HCR_TID4; - else - vcpu->arch.hcr_el2 |=3D HCR_TID2; - - if (vcpu_el1_is_32bit(vcpu)) - vcpu->arch.hcr_el2 &=3D ~HCR_RW; - - if (kvm_has_mte(vcpu->kvm)) - vcpu->arch.hcr_el2 |=3D HCR_ATA; } =20 static inline unsigned long *vcpu_hcr(struct kvm_vcpu *vcpu) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 8170c04fde91..212ae77eefaf 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -1122,7 +1122,7 @@ int __init populate_nv_trap_config(void); bool lock_all_vcpus(struct kvm *kvm); void unlock_all_vcpus(struct kvm *kvm); =20 -void kvm_init_sysreg(struct kvm_vcpu *); +void kvm_calculate_traps(struct kvm_vcpu *); =20 /* MMIO helpers */ void kvm_mmio_write_buf(void *buf, unsigned int len, unsigned long data); diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 9996a989b52e..6b217afb4e8e 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -797,7 +797,7 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) * This needs to happen after NV has imposed its own restrictions on * the feature set */ - kvm_init_sysreg(vcpu); + kvm_calculate_traps(vcpu); =20 ret =3D kvm_timer_enable(vcpu); if (ret) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 22b45a15d068..41741bf4d2b2 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -4041,11 +4041,33 @@ int kvm_vm_ioctl_get_reg_writable_masks(struct kvm = *kvm, struct reg_mask_range * return 0; } =20 -void kvm_init_sysreg(struct kvm_vcpu *vcpu) +static void vcpu_set_hcr(struct kvm_vcpu *vcpu) { struct kvm *kvm =3D vcpu->kvm; =20 - mutex_lock(&kvm->arch.config_lock); + if (has_vhe() || has_hvhe()) + vcpu->arch.hcr_el2 |=3D HCR_E2H; + if (cpus_have_final_cap(ARM64_HAS_RAS_EXTN)) { + /* route synchronous external abort exceptions to EL2 */ + vcpu->arch.hcr_el2 |=3D HCR_TEA; + /* trap error record accesses */ + vcpu->arch.hcr_el2 |=3D HCR_TERR; + } + + if (cpus_have_final_cap(ARM64_HAS_STAGE2_FWB)) + vcpu->arch.hcr_el2 |=3D HCR_FWB; + + if (cpus_have_final_cap(ARM64_HAS_EVT) && + !cpus_have_final_cap(ARM64_MISMATCHED_CACHE_TYPE)) + vcpu->arch.hcr_el2 |=3D HCR_TID4; + else + vcpu->arch.hcr_el2 |=3D HCR_TID2; + + if (vcpu_el1_is_32bit(vcpu)) + vcpu->arch.hcr_el2 &=3D ~HCR_RW; + + if (kvm_has_mte(vcpu->kvm)) + vcpu->arch.hcr_el2 |=3D HCR_ATA; =20 /* * In the absence of FGT, we cannot independently trap TLBI @@ -4054,6 +4076,14 @@ void kvm_init_sysreg(struct kvm_vcpu *vcpu) */ if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, OS)) vcpu->arch.hcr_el2 |=3D HCR_TTLBOS; +} + +void kvm_calculate_traps(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm =3D vcpu->kvm; + + mutex_lock(&kvm->arch.config_lock); + vcpu_set_hcr(vcpu); =20 if (cpus_have_final_cap(ARM64_HAS_HCX)) { vcpu->arch.hcrx_el2 =3D HCRX_GUEST_FLAGS; --=20 2.42.0 From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 228091DA2F for ; Tue, 14 May 2024 07:23:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671386; cv=none; b=Ny63u6gwmPeTCJIwvGbzM4mCHDQB8FxdpUjK8PbmgnuTc08DJQrX1clI1bzjdrc1YGTcQIQEPSrQN1vQDDZ6e9Se7KSmlAecJQ/uZFCS3njRZkiEqcD4i0KK/hsScN1aopMzhL48LKMhCclCc/EQ0rE3kKPLa3Vj0ApmENuM0DE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671386; c=relaxed/simple; bh=dLdaCow7P2Xib4OcE/09HYpSkp4Gr7+ElTge/KPtjtg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lew1AloBmzNt92005lpJB+DkvvxN7utSL71kjKdtMBUJtCCm0EnjqNKBF2jXtAnNoL6kvEPEaK7vTaICkVr28X22lBjLi4FXRpb79YvC6hyNxLQkYi7/NniCpkGtJkMtxXdEHVBWAg6tcIfamDssDt7Ui5FIUa+NCaeHuJe5qkM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=SGyU4jV5; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SGyU4jV5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671384; 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=4wO7UP5uZ9GbYlk7RUrHboh34vCyWLtZOIaQcDBJ5dg=; b=SGyU4jV5c+l3E88dldqILC7h5HdXU6lHb/7hcsr5kNB8pcBs89pbAJzc1E/yvAeSzJ/5Dr P+ezDXoaG7STtxpqSwG++HQ0HgQoC9te8R3Dr/j5ah+kpMIKMxfDuE2IdXzsPTySnAaX7m iwa2sVvDK+jM4uxOMKunzSy2NxSJneI= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-489-rL4hHq40NwKgNbe-w82gdA-1; Tue, 14 May 2024 03:23:02 -0400 X-MC-Unique: rL4hHq40NwKgNbe-w82gdA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6a1530209deso123552706d6.1 for ; Tue, 14 May 2024 00:23:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671382; x=1716276182; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4wO7UP5uZ9GbYlk7RUrHboh34vCyWLtZOIaQcDBJ5dg=; b=Et4H7vKmJYCTUa5/Ytr95E1Bx8RJ8cTHUvPveUEbNro9sG3w5MzgdnbmLtNJMVy14N l3//Beq6ehtzDXDW7bAK43zjWd2KJYNJHMHqPcBlcniHFq7059PXQXs67a0zdVInXXzm yZle+EkKQqWNuurrrWBFSA1ux0dv5WWm3Kg4mj4QqVHOxl5PCCDaUEwqSmwEybAYkY8k zZW6vITpfPE5H1724g6Zfw2lQH6fbymOrSBpz2wB4eKnoePKLxN0qblbIFfwsCbklkJE cJr7JG4wKMzWOJaSjJCO/JHehwgMER/fgeIq/WgVLce5W1W+1XdPv4JBqW5puseyBYv+ tAhw== X-Forwarded-Encrypted: i=1; AJvYcCW/mEeq7vrRblqeBid1byJZNXZ0n0+F7rDlACa0wJOviOR7yjo2vcZQ9CIEp5BNDdmtvSGXV6hJ6tk1XKJvI07PS+yMjzDsljR9Uof1 X-Gm-Message-State: AOJu0YwsZQ0AgyBicWdrCkCeTvIBjlD77g18X9l7PWZs9+ejtMpWcpTd xTQbpwmCskSzGN/cq7BjQWhFHaKz9DaMSD3326qa+aRvABOF/cr3CFOY6hOL5LGjRVohZXbH0Vs 59hm43DK/33gA790E0atJowBZRfZ/WgrVZNfXIvUuArYOjW0RzKJbphM91lFIOQ== X-Received: by 2002:a0c:eec6:0:b0:6a0:e8ed:49a6 with SMTP id 6a1803df08f44-6a15cc96cedmr264843776d6.27.1715671381819; Tue, 14 May 2024 00:23:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHL+IuDEP1OeSc3CrfYuG8GF7qjHL+o2EAfKbDGMN9FevsDKBoeIuPMJwzJc0jicKEcMQt2kw== X-Received: by 2002:a0c:eec6:0:b0:6a0:e8ed:49a6 with SMTP id 6a1803df08f44-6a15cc96cedmr264843506d6.27.1715671381475; Tue, 14 May 2024 00:23:01 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:23:01 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 2/6] KVM: arm64: maintain per VM value for CTR_EL0 Date: Tue, 14 May 2024 09:22:48 +0200 Message-ID: <20240514072252.5657-3-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In preparation for CTR_EL0 emulation maintain a per VM for this register and use it where appropriate. Signed-off-by: Sebastian Ott Reviewed-by: Shaoqin Huang --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/sys_regs.c | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm= _host.h index 212ae77eefaf..1259be5e2f3e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -331,6 +331,8 @@ struct kvm_arch { #define KVM_ARM_ID_REG_NUM (IDREG_IDX(sys_reg(3, 0, 0, 7, 7)) + 1) u64 id_regs[KVM_ARM_ID_REG_NUM]; =20 + u64 ctr_el0; + /* Masks for VNCR-baked sysregs */ struct kvm_sysreg_masks *sysreg_masks; =20 diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 41741bf4d2b2..0213c96f73f2 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -219,9 +219,9 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val,= int reg) * Returns the minimum line size for the selected cache, expressed as * Log2(bytes). */ -static u8 get_min_cache_line_size(bool icache) +static u8 get_min_cache_line_size(struct kvm *kvm, bool icache) { - u64 ctr =3D read_sanitised_ftr_reg(SYS_CTR_EL0); + u64 ctr =3D kvm->arch.ctr_el0; u8 field; =20 if (icache) @@ -248,7 +248,7 @@ static u32 get_ccsidr(struct kvm_vcpu *vcpu, u32 csselr) if (vcpu->arch.ccsidr) return vcpu->arch.ccsidr[csselr]; =20 - line_size =3D get_min_cache_line_size(csselr & CSSELR_EL1_InD); + line_size =3D get_min_cache_line_size(vcpu->kvm, csselr & CSSELR_EL1_InD); =20 /* * Fabricate a CCSIDR value as the overriding value does not exist. @@ -283,7 +283,7 @@ static int set_ccsidr(struct kvm_vcpu *vcpu, u32 csselr= , u32 val) u32 i; =20 if ((val & CCSIDR_EL1_RES0) || - line_size < get_min_cache_line_size(csselr & CSSELR_EL1_InD)) + line_size < get_min_cache_line_size(vcpu->kvm, csselr & CSSELR_EL1_In= D)) return -EINVAL; =20 if (!ccsidr) { @@ -1886,7 +1886,7 @@ static bool access_ctr(struct kvm_vcpu *vcpu, struct = sys_reg_params *p, if (p->is_write) return write_to_read_only(vcpu, p, r); =20 - p->regval =3D read_sanitised_ftr_reg(SYS_CTR_EL0); + p->regval =3D vcpu->kvm->arch.ctr_el0; return true; } =20 @@ -1906,7 +1906,7 @@ static bool access_clidr(struct kvm_vcpu *vcpu, struc= t sys_reg_params *p, */ static u64 reset_clidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { - u64 ctr_el0 =3D read_sanitised_ftr_reg(SYS_CTR_EL0); + u64 ctr_el0 =3D vcpu->kvm->arch.ctr_el0; u64 clidr; u8 loc; =20 @@ -1959,8 +1959,8 @@ static u64 reset_clidr(struct kvm_vcpu *vcpu, const s= truct sys_reg_desc *r) static int set_clidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val) { - u64 ctr_el0 =3D read_sanitised_ftr_reg(SYS_CTR_EL0); u64 idc =3D !CLIDR_LOC(val) || (!CLIDR_LOUIS(val) && !CLIDR_LOUU(val)); + u64 ctr_el0 =3D vcpu->kvm->arch.ctr_el0; =20 if ((val & CLIDR_EL1_RES0) || (!(ctr_el0 & CTR_EL0_IDC) && idc)) return -EINVAL; @@ -3557,6 +3557,13 @@ void kvm_reset_sys_regs(struct kvm_vcpu *vcpu) struct kvm *kvm =3D vcpu->kvm; unsigned long i; =20 + if (!kvm_vcpu_initialized(vcpu)) + /* + * Make sure CTR_EL0 is initialized before registers + * that depend on it are reset. + */ + kvm->arch.ctr_el0 =3D read_sanitised_ftr_reg(SYS_CTR_EL0); + for (i =3D 0; i < ARRAY_SIZE(sys_reg_descs); i++) { const struct sys_reg_desc *r =3D &sys_reg_descs[i]; =20 --=20 2.42.0 From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F2B3117BD2 for ; Tue, 14 May 2024 07:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671688; cv=none; b=MBqoa1Qc28RHHl8NKmJYUx1YcgR/kgIgNJu6h7cFc2CNduhjY/3TpefSq6oUZTln5WIWwjU0s24zIwn3IwIerX5aOGmEvzT/Wie95Al3AHRDeuJKRsVGy84fT66YHxbZjG8ThCT9XhCRN1Lze+KutW8/zw3J6/Kes6LosDavl4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671688; c=relaxed/simple; bh=pdBP/poxNQkLoCpZlP6M+ozK0xi+66h+bhcdCKIIlcE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WmE0Put4QKrtMeq8QWqTG4gmUxidm7MkOkC2lB6SAwu7uL0+QKnEH1jZISlXroFl9o/EZUKphnKqFXwYgVTzJKXN8fOlYZ3Xs1YHDgCNF4Iqa41xDS856+b4q79BZXP0tqS1+dXe8hc74TbzA9QCNMHQk3mqzCxGhWtKfNN6dyY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HsnkgtWf; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HsnkgtWf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671685; 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=G/gMpEmtI+IAI1lEUeLeMcm+4WhBEW2fmE2xkm8KyS0=; b=HsnkgtWfLaJUiuvaDbosuUK1q1zk7LT1kchu6i+xOiKtlPCre073qV6ujsUMScTDisRHrR RGs8P51z9UUyx5YlcxRlTxdQwnt0/RrfmHG39/fQAI3TvIOpi6cIkMHLDMzt4Uz1RxQsgH USNCWLKLL3HdZvzeEGueKmyCRCPMunQ= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-YCjYwyIZNeKtW8ejBJzPow-1; Tue, 14 May 2024 03:23:04 -0400 X-MC-Unique: YCjYwyIZNeKtW8ejBJzPow-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6a1530209deso123553006d6.1 for ; Tue, 14 May 2024 00:23:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671384; x=1716276184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=G/gMpEmtI+IAI1lEUeLeMcm+4WhBEW2fmE2xkm8KyS0=; b=TwzJAk+6KkHKSLj0M3ucrIpuCWVpOvebltuGNcbzCx/GCKEXGG0YB/x9gS1xUSFMVQ CpnoO9DCyIJCQC8c/DZKOAK4txJDGv07Vq1RcVXk+0VLsNR4iitTbYWtRuqNXJn6Nwye jgOUJ313aSWUeXJC1jEHFKHcq/KOH8s5gA81+3K6Xd8KLNf3wDk2dVo1SbKgDNm4alds arbHl609pj0QWzdg0rF3v+eZ74sj/wZ8CzoiyrPbIkeeK4jfU21m5gy8gdpkzk9QV/DY h2gI9s/3rzXxg3GLx5696a8C3qKru3eoScNLVZ62rB7l8OW0PnYDeGrmiAPv95b9tLW+ rkSQ== X-Forwarded-Encrypted: i=1; AJvYcCUsbB5mCQT+IqQQHOIcekvDZiBl0td53Ne1QKw3zt2RQ9U3MmzYUd0ENovGGesIt7gnoEIf5Jn14DvEdy0CoNOYZs84fSMHRvb4PvdN X-Gm-Message-State: AOJu0Yxlw0J6tRLe3ButjDx7pbboHIrxFckqq/FLTYqlYRDFnspWZX1z ySvGmsyLcmikweXgBzbOvwlMJPNdmt2cKOWYr3z08KOSnXqC/tvGMa6lmIE1sgVeXPL+9hDON4u Jb/ztdBnBBqP52Tm2gzCIT93R3exZirtx3yB3LHzAWjTicdeJd1GskMexHTJ0ZA== X-Received: by 2002:a05:6214:4903:b0:6a0:e5cd:a66a with SMTP id 6a1803df08f44-6a16798b72cmr206212086d6.24.1715671383844; Tue, 14 May 2024 00:23:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEJGrKm6swz5CxYuqHAR7YAvfD3qZgiXFXmXmEN+UZo19xxwFL5nUJkieiEsNX+PH4OW99qRg== X-Received: by 2002:a05:6214:4903:b0:6a0:e5cd:a66a with SMTP id 6a1803df08f44-6a16798b72cmr206211936d6.24.1715671383475; Tue, 14 May 2024 00:23:03 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:23:03 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 3/6] KVM: arm64: add emulation for CTR_EL0 register Date: Tue, 14 May 2024 09:22:49 +0200 Message-ID: <20240514072252.5657-4-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CTR_EL0 is currently handled as an invariant register, thus guests will be presented with the host value of that register. Add emulation for CTR_EL0 based on a per VM value. Userspace can switch off DIC and IDC bits and reduce DminLine and IminLine sizes. When CTR_EL0 is changed validate that against CLIDR_EL1 and CCSIDR_EL1 to make sure we present the guest with consistent register values. Changes that affect the generated cache topology values are allowed if they don't clash with previous register writes. Signed-off-by: Sebastian Ott --- arch/arm64/kvm/sys_regs.c | 130 +++++++++++++++++++++++++++++++++----- 1 file changed, 114 insertions(+), 16 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0213c96f73f2..8e8acf3dd9bd 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -215,13 +215,8 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val= , int reg) /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ #define CSSELR_MAX 14 =20 -/* - * Returns the minimum line size for the selected cache, expressed as - * Log2(bytes). - */ -static u8 get_min_cache_line_size(struct kvm *kvm, bool icache) +static u8 __get_min_cache_line_size(u64 ctr, bool icache) { - u64 ctr =3D kvm->arch.ctr_el0; u8 field; =20 if (icache) @@ -240,6 +235,15 @@ static u8 get_min_cache_line_size(struct kvm *kvm, boo= l icache) return field + 2; } =20 +/* + * Returns the minimum line size for the selected cache, expressed as + * Log2(bytes). + */ +static u8 get_min_cache_line_size(struct kvm *kvm, bool icache) +{ + return __get_min_cache_line_size(kvm->arch.ctr_el0, icache); +} + /* Which cache CCSIDR represents depends on CSSELR value. */ static u32 get_ccsidr(struct kvm_vcpu *vcpu, u32 csselr) { @@ -1880,6 +1884,45 @@ static int set_wi_reg(struct kvm_vcpu *vcpu, const s= truct sys_reg_desc *rd, return 0; } =20 +static const struct sys_reg_desc *get_sys_reg_desc(u32 encoding); + +static int validate_clidr_el1(u64 clidr_el1, u64 ctr_el0) +{ + u64 idc =3D !CLIDR_LOC(clidr_el1) || + (!CLIDR_LOUIS(clidr_el1) && !CLIDR_LOUU(clidr_el1)); + + if ((clidr_el1 & CLIDR_EL1_RES0) || (!(ctr_el0 & CTR_EL0_IDC) && idc)) + return -EINVAL; + + return 0; +} + +static int validate_cache_top(struct kvm_vcpu *vcpu, u64 ctr_el0) +{ + const struct sys_reg_desc *clidr_el1; + unsigned int i; + int ret; + + clidr_el1 =3D get_sys_reg_desc(SYS_CLIDR_EL1); + if (!clidr_el1) + return -ENOENT; + + ret =3D validate_clidr_el1(__vcpu_sys_reg(vcpu, clidr_el1->reg), ctr_el0); + if (ret) + return ret; + + if (!vcpu->arch.ccsidr) + return 0; + + for (i =3D 0; i < CSSELR_MAX; i++) { + if ((FIELD_GET(CCSIDR_EL1_LineSize, get_ccsidr(vcpu, i)) + 4) + < __get_min_cache_line_size(ctr_el0, i & CSSELR_EL1_InD)) + return -EINVAL; + } + + return 0; +} + static bool access_ctr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { @@ -1890,6 +1933,55 @@ static bool access_ctr(struct kvm_vcpu *vcpu, struct= sys_reg_params *p, return true; } =20 +static u64 reset_ctr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd) +{ + vcpu->kvm->arch.ctr_el0 =3D read_sanitised_ftr_reg(SYS_CTR_EL0); + return vcpu->kvm->arch.ctr_el0; +} + +static int get_ctr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, + u64 *val) +{ + *val =3D vcpu->kvm->arch.ctr_el0; + return 0; +} + +static int set_ctr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, + u64 val) +{ + u64 ctr =3D vcpu->kvm->arch.ctr_el0; + u64 writable_mask =3D rd->val; + int ret; + + if (val =3D=3D ctr) + return 0; + + if (kvm_vm_has_ran_once(vcpu->kvm)) + return -EBUSY; + + if ((ctr & ~writable_mask) !=3D (val & ~writable_mask)) + return -EINVAL; + + if (((ctr & CTR_EL0_DIC_MASK) < (val & CTR_EL0_DIC_MASK)) || + ((ctr & CTR_EL0_IDC_MASK) < (val & CTR_EL0_IDC_MASK)) || + ((ctr & CTR_EL0_DminLine_MASK) < (val & CTR_EL0_DminLine_MASK)) || + ((ctr & CTR_EL0_IminLine_MASK) < (val & CTR_EL0_IminLine_MASK))) { + return -EINVAL; + } + + mutex_lock(&vcpu->kvm->arch.config_lock); + ret =3D validate_cache_top(vcpu, val); + if (ret) { + mutex_unlock(&vcpu->kvm->arch.config_lock); + return ret; + } + + vcpu->kvm->arch.ctr_el0 =3D val; + mutex_unlock(&vcpu->kvm->arch.config_lock); + + return 0; +} + static bool access_clidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { @@ -1959,10 +2051,9 @@ static u64 reset_clidr(struct kvm_vcpu *vcpu, const = struct sys_reg_desc *r) static int set_clidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *rd, u64 val) { - u64 idc =3D !CLIDR_LOC(val) || (!CLIDR_LOUIS(val) && !CLIDR_LOUU(val)); u64 ctr_el0 =3D vcpu->kvm->arch.ctr_el0; =20 - if ((val & CLIDR_EL1_RES0) || (!(ctr_el0 & CTR_EL0_IDC) && idc)) + if (validate_clidr_el1(val, ctr_el0)) return -EINVAL; =20 __vcpu_sys_reg(vcpu, rd->reg) =3D val; @@ -2475,7 +2566,11 @@ static const struct sys_reg_desc sys_reg_descs[] =3D= { { SYS_DESC(SYS_CCSIDR2_EL1), undef_access }, { SYS_DESC(SYS_SMIDR_EL1), undef_access }, { SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 }, - { SYS_DESC(SYS_CTR_EL0), access_ctr }, + { SYS_DESC(SYS_CTR_EL0), access_ctr, .reset =3D reset_ctr, + .get_user =3D get_ctr, .set_user =3D set_ctr, .val =3D (CTR_EL0_DIC_MAS= K | + CTR_EL0_IDC_MASK | + CTR_EL0_DminLine_MASK | + CTR_EL0_IminLine_MASK)}, { SYS_DESC(SYS_SVCR), undef_access }, =20 { PMU_SYS_REG(PMCR_EL0), .access =3D access_pmcr, .reset =3D reset_pmcr, @@ -3651,6 +3746,13 @@ static bool index_to_params(u64 id, struct sys_reg_p= arams *params) } } =20 +static const struct sys_reg_desc *get_sys_reg_desc(u32 encoding) +{ + struct sys_reg_params params =3D encoding_to_params(encoding); + + return find_reg(¶ms, sys_reg_descs, ARRAY_SIZE(sys_reg_descs)); +} + const struct sys_reg_desc *get_reg_by_id(u64 id, const struct sys_reg_desc table[], unsigned int num) @@ -3704,18 +3806,11 @@ FUNCTION_INVARIANT(midr_el1) FUNCTION_INVARIANT(revidr_el1) FUNCTION_INVARIANT(aidr_el1) =20 -static u64 get_ctr_el0(struct kvm_vcpu *v, const struct sys_reg_desc *r) -{ - ((struct sys_reg_desc *)r)->val =3D read_sanitised_ftr_reg(SYS_CTR_EL0); - return ((struct sys_reg_desc *)r)->val; -} - /* ->val is filled in by kvm_sys_reg_table_init() */ static struct sys_reg_desc invariant_sys_regs[] __ro_after_init =3D { { SYS_DESC(SYS_MIDR_EL1), NULL, get_midr_el1 }, { SYS_DESC(SYS_REVIDR_EL1), NULL, get_revidr_el1 }, { SYS_DESC(SYS_AIDR_EL1), NULL, get_aidr_el1 }, - { SYS_DESC(SYS_CTR_EL0), NULL, get_ctr_el0 }, }; =20 static int get_invariant_sys_reg(u64 id, u64 __user *uaddr) @@ -4083,6 +4178,9 @@ static void vcpu_set_hcr(struct kvm_vcpu *vcpu) */ if (!kvm_has_feat(kvm, ID_AA64ISAR0_EL1, TLB, OS)) vcpu->arch.hcr_el2 |=3D HCR_TTLBOS; + + if (kvm->arch.ctr_el0 !=3D read_sanitised_ftr_reg(SYS_CTR_EL0)) + vcpu->arch.hcr_el2 |=3D HCR_TID2; } =20 void kvm_calculate_traps(struct kvm_vcpu *vcpu) --=20 2.42.0 From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15EAA15E81 for ; Tue, 14 May 2024 07:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671395; cv=none; b=gPeFShFbY14BSLc742ZeNTCf0Nbo7ob4+Po0a6faX0W/QjaL7GwXuDSEK8mGN+qmTa7OHSTlXhG/JFOr3/olX8losZfalP2jLo3rGRmTNz2S+Bd8fuMbkarYudkVkKXPzMUrALRh/VfC2BCuEtVmaAVeD3gHfO1hkolAo3J5p9M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671395; c=relaxed/simple; bh=t7E4Xq+CwDIyBlgpDlmVyy3gj5a/gnFSGaWMtzUgsUw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kFcHaSOThtAe1CFz+n+D6jgBxh0aM/bH1mbh075SZxU0sEJ+iAhTFzsCcvIqP2YBpXF1HJzWa1snkjOkih6jzp2tFAzgExaPcDoENeYgTk3DSZtlrM1NO5DiJFoOUsh3VH3iaJxLD5+RKx7KgTQmUvK8Fobiuv0bSY77NvR2hwY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=RsG0saWk; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RsG0saWk" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671393; 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=edf79jeIcR6SIIHgF1L+nP6ohGfiMC191SZcpJswp0Q=; b=RsG0saWk7RiqOrzG/o3OYywJ6M+BhRbKRm5HLs4PLD0dBjd6oO2MIHcziPspulEc0F1fYi jiccuQEeLE7LRFV7lCNeiozpIhDTWHCVThKsM8KF90H8acDBXary00AbpSMBtz59TZaqhi LUpGJq/PBV2c4WrDxT051E0mMCo0Oig= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-106-Mh4UboGvORaMFkv6M4Hrhw-1; Tue, 14 May 2024 03:23:06 -0400 X-MC-Unique: Mh4UboGvORaMFkv6M4Hrhw-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6a0eca15156so59793436d6.3 for ; Tue, 14 May 2024 00:23:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671386; x=1716276186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=edf79jeIcR6SIIHgF1L+nP6ohGfiMC191SZcpJswp0Q=; b=VkVBx/kfOSrpWLsSrzLWNUOpUpFsDuPE3zNS1D8YIhPAfddjdHWjTuqoOsqdHCK4rM sp6hUpnDwF4FpKAzjkIzBev/kpKwy3BCUSQYhbUpxlc7v3txBZPxXp7U3nGfF8pNeeBG CfvQsj5bymwtKbBl1QdV/gmaK5GSogPMhnI/lyRGMp6H+g2KlqSaHAJcYPNFFUim43mj zI5ELvTVyUpGraoxJ52qPPPuA4lAt7LghpZ8fCLU9d0IzssNzB7s3YUxcqyhyvrbr2VD UXFdx6J9lnpllxen9jWqHii22l4mHb8pcwhG6bjhY7VncI8/ohCW3ap6PF/ffohDFOPX T0Hw== X-Forwarded-Encrypted: i=1; AJvYcCVbPvz7p92JFhsiVWZ+v19TWUktR0kQFEDWdo3RlWJJliAC0uVOl4TqMnBiGX4bvBllq0Z/hoJqIGDDYOj7XoVvxWWB/r9VzxwXC4UP X-Gm-Message-State: AOJu0YyHsiFppvMDxARFCIFdWMBVMHmKes2RWSEov29WKjaHZA31KwOq y1zXCCYoIAsxeLlBcZAnKqC6IVfGUUpMhUb5YAO9T7Eayjdi6oi4PN3c49vfliaKxJO9FmT2xlW 3ok3LLxz7bhIWQi0sKmN1+oI+BRVUJXqoqstUFAuxi2PhzRSFzXFrb+yk8lBbRA== X-Received: by 2002:a0c:fe8b:0:b0:6a3:27b4:9b72 with SMTP id 6a1803df08f44-6a327b49baemr101393816d6.5.1715671386214; Tue, 14 May 2024 00:23:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHH89ioZLBSNiqjRiyo8fWL2ZJPx4atue/rPXREABDqOjqAEr1TFGlquEEfDdLQbtkO/SiRlw== X-Received: by 2002:a0c:fe8b:0:b0:6a3:27b4:9b72 with SMTP id 6a1803df08f44-6a327b49baemr101393586d6.5.1715671385677; Tue, 14 May 2024 00:23:05 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.23.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:23:05 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 4/6] KVM: arm64: show writable masks for feature registers Date: Tue, 14 May 2024 09:22:50 +0200 Message-ID: <20240514072252.5657-5-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of using ~0UL provide the actual writable mask for non-id feature registers in the output of the KVM_ARM_GET_REG_WRITABLE_MASKS ioctl. This changes the mask for the CTR_EL0 and CLIDR_EL1 registers. Signed-off-by: Sebastian Ott Reviewed-by: Eric Auger --- arch/arm64/kvm/sys_regs.c | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 8e8acf3dd9bd..1b6ab483e21e 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -2562,7 +2562,7 @@ static const struct sys_reg_desc sys_reg_descs[] =3D { =20 { SYS_DESC(SYS_CCSIDR_EL1), access_ccsidr }, { SYS_DESC(SYS_CLIDR_EL1), access_clidr, reset_clidr, CLIDR_EL1, - .set_user =3D set_clidr }, + .set_user =3D set_clidr, .val =3D ~CLIDR_EL1_RES0 }, { SYS_DESC(SYS_CCSIDR2_EL1), undef_access }, { SYS_DESC(SYS_SMIDR_EL1), undef_access }, { SYS_DESC(SYS_CSSELR_EL1), access_csselr, reset_unknown, CSSELR_EL1 }, @@ -4121,20 +4121,11 @@ int kvm_vm_ioctl_get_reg_writable_masks(struct kvm = *kvm, struct reg_mask_range * if (!is_feature_id_reg(encoding) || !reg->set_user) continue; =20 - /* - * For ID registers, we return the writable mask. Other feature - * registers return a full 64bit mask. That's not necessary - * compliant with a given revision of the architecture, but the - * RES0/RES1 definitions allow us to do that. - */ - if (is_vm_ftr_id_reg(encoding)) { - if (!reg->val || - (is_aa32_id_reg(encoding) && !kvm_supports_32bit_el0())) - continue; - val =3D reg->val; - } else { - val =3D ~0UL; + if (!reg->val || + (is_aa32_id_reg(encoding) && !kvm_supports_32bit_el0())) { + continue; } + val =3D reg->val; =20 if (put_user(val, (masks + KVM_ARM_FEATURE_ID_RANGE_INDEX(encoding)))) return -EFAULT; --=20 2.42.0 From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 28F742230C for ; Tue, 14 May 2024 07:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671493; cv=none; b=cySTKO2+T+KNkFT0jLoEJCgw5lL/3HED2VLJ0gCKvUL4XBZ1xxXVjBx0RbO7F6Z5vClFxAcHN4/uG/pYRl/Sn01tlrgmaBbTqUgN8Tj3NkoCKpKrh0VnJX6V3whkP7eiam39XG5Clg9ucd58PzRXRF9ldet1a0pHedn+zWpsf/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671493; c=relaxed/simple; bh=GKU8aDad++UHg7ULCq5a+WASZrV1XSR5fQTRpdyDPAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KF3G36yS5r8c0ZNINJJ98lorR3TV++5iIVUsqcWmdG6bg33LJnoRWurgyTle9l7u0o3gPDsnSwLX2rqT60xvRDsk+nBs8DNYZE0vvz2kfReopZ7q3MtZ2XvBEw7p0YjCEFMqiyWS4EZpMvO2U1+UXdnhr8RBCihhIGGu7WVeC6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EZis6710; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EZis6710" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671491; 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=Ir9ch9TLrkkINczF+u09rhfqVntFlPUGfW92ABaqtP4=; b=EZis6710d7TwB/U+iI/xTIyVzSBfB6ekYsEJtMQcVNNitFREeRr5G1S1gzmcMyCmsYy4gj n73ZLJSNwltLMX8MApGm6pw3BCNikT7gBz37Y14RNslbtWyusLMy2QqUJYPF+eyncTPi0e /qbPyFKw+OLq4txZ0in2PEU21bn1c6I= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-142-svXIcDRKNtyf-ftbWYgYUg-1; Tue, 14 May 2024 03:23:08 -0400 X-MC-Unique: svXIcDRKNtyf-ftbWYgYUg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-792c365cb16so603582685a.3 for ; Tue, 14 May 2024 00:23:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671388; x=1716276188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ir9ch9TLrkkINczF+u09rhfqVntFlPUGfW92ABaqtP4=; b=Wek9PnpBDcnrKpRrXlEX9cJqUxANFGS921BqGh6hdzwwfsl2SsehxZcV6/Af3nHV0D n1KWYcXwbc7SlGHr3q/qZX7YrrxV+gLJDvj6yI1SvR4ATlHfvCAxvfzdKDaHmJGr29HR +qBJGuwQ2XDoYFh9AkiLjEVNsvhPoqKE67SQakynesL3sDCpjUQAXwq75IsdcSrVCOla JsQvsdr9ohhrzGHa2O7PZzbL7knmWM0RGlBKy8K6S9ROO0Rb12sOeB8nuX/X2Al/1aSd potAuPZN20C4cERfoOAXwbV+Qj2HSwPtKRB3+abdRMMPxCDI1DDhSPyiVVUPylWFA/dg n5sA== X-Forwarded-Encrypted: i=1; AJvYcCW3QpCX2Wv5vQla5an4h7JIThqdTUdXcOAscMG2D4esQx0b7WFuAiqsl9EzNkCIO1CABdRaYmuP55lc1sXtlgkEUfYsvh8Sata2QfLo X-Gm-Message-State: AOJu0Yw315mzXGUQChfr3U6qWz1XUUnxUw1FuZRU8FQwSZ9cxL+wlqsi w+hWrkbPEVse291OsscOytcsnZZ00Y6SDCbIqSAIrFSle71nWF6/l9zJHrXrNqnYYJYWomQuMZE ETirlcsjvXYEJkWpu3/oUkjEChQAZ3H6jb9h9drESmq8aSWZNOP8oYiUCIYG6LA== X-Received: by 2002:a05:6214:4309:b0:6a0:d21b:c914 with SMTP id 6a1803df08f44-6a168217e82mr153404496d6.51.1715671387989; Tue, 14 May 2024 00:23:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHIbQ2Xnzp0GccgqjWLFujOwJhCg38lH8DFppsuBR5FMZevyxek/6u2nIsapmQtCwGG2EXSrA== X-Received: by 2002:a05:6214:4309:b0:6a0:d21b:c914 with SMTP id 6a1803df08f44-6a168217e82mr153404396d6.51.1715671387689; Tue, 14 May 2024 00:23:07 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:23:07 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 5/6] KVM: arm64: rename functions for invariant sys regs Date: Tue, 14 May 2024 09:22:51 +0200 Message-ID: <20240514072252.5657-6-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Invariant system id registers are populated with host values at initialization time using their .reset function cb. These are currently called get_* which is usually used by the functions implementing the .get_user callback. Change their function names to reset_* to reflect what they are used for. Signed-off-by: Sebastian Ott Reviewed-by: Eric Auger --- arch/arm64/kvm/sys_regs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 1b6ab483e21e..bae72a4ce72b 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -3795,8 +3795,8 @@ id_to_sys_reg_desc(struct kvm_vcpu *vcpu, u64 id, */ =20 #define FUNCTION_INVARIANT(reg) \ - static u64 get_##reg(struct kvm_vcpu *v, \ - const struct sys_reg_desc *r) \ + static u64 reset_##reg(struct kvm_vcpu *v, \ + const struct sys_reg_desc *r) \ { \ ((struct sys_reg_desc *)r)->val =3D read_sysreg(reg); \ return ((struct sys_reg_desc *)r)->val; \ @@ -3808,9 +3808,9 @@ FUNCTION_INVARIANT(aidr_el1) =20 /* ->val is filled in by kvm_sys_reg_table_init() */ static struct sys_reg_desc invariant_sys_regs[] __ro_after_init =3D { - { SYS_DESC(SYS_MIDR_EL1), NULL, get_midr_el1 }, - { SYS_DESC(SYS_REVIDR_EL1), NULL, get_revidr_el1 }, - { SYS_DESC(SYS_AIDR_EL1), NULL, get_aidr_el1 }, + { SYS_DESC(SYS_MIDR_EL1), NULL, reset_midr_el1 }, + { SYS_DESC(SYS_REVIDR_EL1), NULL, reset_revidr_el1 }, + { SYS_DESC(SYS_AIDR_EL1), NULL, reset_aidr_el1 }, }; =20 static int get_invariant_sys_reg(u64 id, u64 __user *uaddr) --=20 2.42.0 From nobody Tue Feb 10 22:15:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2E1C515EA6 for ; Tue, 14 May 2024 07:23:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671395; cv=none; b=gq9rMZdG8+WKdxYJTp0+fqBHB1fvpU+kamXcYSW0HloAvJbzl52Z/+SE8hFo2m3AiObTF1CXCxX4Fs5O6M+VM/i40bA0kMl5xivjSHXsNGqvceDK9tsvGwp545QPvdUjEKUuc8TFDbdGnjL/M+3/QktrPjk3+HRJh7mWA7ZkH6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715671395; c=relaxed/simple; bh=wY+GRzCRFH5gnq+ih1QfRxaZi4OYPpugBgelwQ2YeW4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SJJGFECm4zJVjyU4qDygTFYCZ/W+uf9uz9CgXFCZGMq9ahDVWsX0e0f0xLu8r/6GG0ptO6jZeNgD/cGCNABO/M4sN5yPVKwOkMJzGmdW+nPeL0t8ib5oUamwiOaEDoD2QI0QpNIJ9tTZYQFXhAsw/v02BdbcgURjJuEjgzoO4qg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BqvWTVEZ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BqvWTVEZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1715671393; 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=qmTJtxNzwCydsCweSeZKkzPt91K1xWWXybaXzLbEATg=; b=BqvWTVEZamN6OO+g9CpoFWHLO8RZxz6jAyYvHYI02r7pf9lBiEQuBj1gfG+RzLyMlBFtVS SBcWQZOGG4+rnsqOqJezauoQdW/5i1bx9s3PPJHJxGGVqmKHSsmp91yvfhDOH0WFC6bkC5 emtcCsF6vt1jifgfa8aaKgHjcbM+8r0= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-615-7-ECFLzTMqqfLicpe3mnIQ-1; Tue, 14 May 2024 03:23:11 -0400 X-MC-Unique: 7-ECFLzTMqqfLicpe3mnIQ-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-43de2f59d09so65725751cf.0 for ; Tue, 14 May 2024 00:23:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715671390; x=1716276190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qmTJtxNzwCydsCweSeZKkzPt91K1xWWXybaXzLbEATg=; b=V7IJZypS48FXYoOTDr7cFGiaSuVkwe8RLvzKvqiui8zD+1Zo/QwKggIqhJkVoYZdJb Qyby7T4XLQ7PMeLhvUubWCqQ4qFJpbhdgwY9Op/ifDDSdKJKFWSfnK0PmVUyjJfqHNpb SbfaXMkL5VgLglV7vuOrlkaVIgdHpdGNt0WzXXCmAbq8kPtDKrAqxocLzIJQo0CqWgDX eeks95itvHlNvBSrqSwHF7W5nLx5mtZzcJSp3Cl1Ls73h1NCpNc/D5y2svXuojxLqR83 dgU7lO+jDja45OAVdncZIhTGSzAmfnHAxortZ83Z9yfvmiVCki2mZ1OrgegeqHP8hdf3 b3KA== X-Forwarded-Encrypted: i=1; AJvYcCWRPgxDc99/pnlixkntMp2vcGT+CqUGjUbEL22irBfjq7sm2m/gI/q1vx0GylLKtp2oCpSrimY5q9MYtSl/qV2JUR7O3bO5EgJ7wLib X-Gm-Message-State: AOJu0Yxe5+rNk1tehJR0/vBaOBW+ej6krlGeSuSJIN9OKHzTKRXAo+aX bas2L4kC2FE7QXUFIupSRBzGHVqsXO2+h26lhnfJvqzgnpD4Ri5alDfZCjVMFJ51doGgUlk1PpU FvZLL/v0GFBFw+F2rCiwyjqGSWUWt1PzlFSmCSpBQ/jau3tH6UIE4lQTwfyYLpQ== X-Received: by 2002:a05:6214:5b87:b0:6a0:cd69:374d with SMTP id 6a1803df08f44-6a16824151fmr150030376d6.50.1715671390420; Tue, 14 May 2024 00:23:10 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ2R7/7LcuNEr1pVh3mkLXVqAI7slnKMsvoAq1Lye2TXziw5bgVSkgrOVRGpraSzpR7RDmOA== X-Received: by 2002:a05:6214:5b87:b0:6a0:cd69:374d with SMTP id 6a1803df08f44-6a16824151fmr150030156d6.50.1715671389920; Tue, 14 May 2024 00:23:09 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4cc600a5cdf10de606b5e2.dip0.t-ipconnect.de. [2003:c9:3f4c:c600:a5cd:f10d:e606:b5e2]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6a15f1ccd4esm50917516d6.97.2024.05.14.00.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 May 2024 00:23:09 -0700 (PDT) From: Sebastian Ott To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Catalin Marinas , Will Deacon Subject: [PATCH v3 6/6] KVM: selftests: arm64: Test writes to CTR_EL0 Date: Tue, 14 May 2024 09:22:52 +0200 Message-ID: <20240514072252.5657-7-sebott@redhat.com> X-Mailer: git-send-email 2.45.0 In-Reply-To: <20240514072252.5657-1-sebott@redhat.com> References: <20240514072252.5657-1-sebott@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Test that CTR_EL0 is modifiable from userspace, that changes are visible to guests, and that they are preserved across a vCPU reset. Signed-off-by: Sebastian Ott Reviewed-by: Eric Auger --- .../testing/selftests/kvm/aarch64/set_id_regs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/set_id_regs.c b/tools/test= ing/selftests/kvm/aarch64/set_id_regs.c index a7de39fa2a0a..9583c04f1228 100644 --- a/tools/testing/selftests/kvm/aarch64/set_id_regs.c +++ b/tools/testing/selftests/kvm/aarch64/set_id_regs.c @@ -219,6 +219,7 @@ static void guest_code(void) GUEST_REG_SYNC(SYS_ID_AA64MMFR1_EL1); GUEST_REG_SYNC(SYS_ID_AA64MMFR2_EL1); GUEST_REG_SYNC(SYS_ID_AA64ZFR0_EL1); + GUEST_REG_SYNC(SYS_CTR_EL0); =20 GUEST_DONE(); } @@ -490,11 +491,25 @@ static void test_clidr(struct kvm_vcpu *vcpu) test_reg_vals[encoding_to_range_idx(SYS_CLIDR_EL1)] =3D clidr; } =20 +static void test_ctr(struct kvm_vcpu *vcpu) +{ + u64 ctr; + + vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0), &ctr); + ctr &=3D ~CTR_EL0_DIC_MASK; + if (ctr & CTR_EL0_IminLine_MASK) + ctr--; + + vcpu_set_reg(vcpu, KVM_ARM64_SYS_REG(SYS_CTR_EL0), ctr); + test_reg_vals[encoding_to_range_idx(SYS_CTR_EL0)] =3D ctr; +} + static void test_vcpu_ftr_id_regs(struct kvm_vcpu *vcpu) { u64 val; =20 test_clidr(vcpu); + test_ctr(vcpu); =20 vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &val); val++; @@ -525,6 +540,7 @@ static void test_reset_preserves_id_regs(struct kvm_vcp= u *vcpu) test_assert_id_reg_unchanged(vcpu, test_regs[i].reg); =20 test_assert_id_reg_unchanged(vcpu, SYS_CLIDR_EL1); + test_assert_id_reg_unchanged(vcpu, SYS_CTR_EL0); =20 ksft_test_result_pass("%s\n", __func__); } --=20 2.42.0