From patchwork Fri Apr 5 12:01:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ott X-Patchwork-Id: 13618965 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 25640CD11C2 for ; Fri, 5 Apr 2024 12:03:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Vw9qwA+CSQAOKy51gJy6K4WfDgh4BWKnJPvHIvOe/ks=; b=cNA2vLTFkcMagF 36eJKU/vbY3SZ9/Hd+TaQmhj+8LQ+dCIjzk4P7+1RpwB0QS+L9w1BZvQYqHQtzaOOQUbJKeHZDIpL uihY/VQo/UJd1D7CgEQomNYCeXscwO/BSBzd+uc3CAwtfoujp9NyobD76MHVMrXSuk+/vcIE+bTi5 2xXIf17/6QY2gm0QWn47l2/7pxAlalEXq/m+t4XgKvEmSzTR2STOO8OVuITsiZ16FQ8Jb/J586ktU trCiGO4ipHpBqrHrQXYb5F2rVSANqpraEgPp7KG1YrxTWItBv/SadEp0gbYybkFOXFA4XbXvpqL7M 2esySi1hydqrFPqDJCiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsiHh-00000006o6u-1Bia; Fri, 05 Apr 2024 12:03:05 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rsiHe-00000006o5d-0XRZ for linux-arm-kernel@lists.infradead.org; Fri, 05 Apr 2024 12:03:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712318581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rsSFcUbsThM5IkqFm5UZmPp81ZNMKoAIhMlsT6uF7yg=; b=CJL2A4WSyyT5c/jQJ6KHasiEK/5eyOFqPPYzCKs305RIZsCu/v0xktNPgKT1AS16DmZRoJ yBvocAQB9NmngNFR7VEipidixh7fvZ8eMb56nM0k3RUGGeVkFEXGImFy5J0pPgpGudT65n N+3DrEqUPwUY3K2kWvqodcyr+9x9Mcc= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-34-P_IDlGY8NAulByTc7edwPQ-1; Fri, 05 Apr 2024 08:01:22 -0400 X-MC-Unique: P_IDlGY8NAulByTc7edwPQ-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-430ac211fbbso21535681cf.1 for ; Fri, 05 Apr 2024 05:01:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712318482; x=1712923282; 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=rsSFcUbsThM5IkqFm5UZmPp81ZNMKoAIhMlsT6uF7yg=; b=RAN3IBLcMC82orXdBowIJ8Fvkywomc1xuQyAgK5USvQ6wYulWW0Zy61WnWdvZvavEX +DSQrRacelyIJw5/LYQMhxeNa4FK/qKwCpzTmDgC7lIZEJdJfAZMepQWvFPx3HUwxon4 xf6/X0amgGnKSHDGQjKOARhc0QOUfHDiMWwh3ycmfGh+SkjsM5HeFzzSvACvygOZzw3a 3bUskQizd+S5BmFQI7QFc67w/eaFly8s7horIJkBM3kbG56k9THnccAGiipTly2S22Q8 Ii/jzd7Zt5NrYL/Eu/kcI3mWTo7cTw6xtnBEsHZLniNBsB6VtXZdl4oL2KuYXLaaa3A4 XH+Q== X-Gm-Message-State: AOJu0YwrMb6eHKKdffdkPZmGIKwjb8jLhRIZ33OzVdTrB8dkkgaoBkHs R0xQWWi8hfRytMnI+QwOUnIZCqo3oogeEOwlLjKO+3tKz37WZGM9kXr+Wnnw193QLxiEtNizmyy mdvAtHnJrHG2rej9d69zcItjPW4IOc0CPm1M66sYsLxezKP5ktnIJugIR0Vm5r1eAyys74MSIo+ 214lPOYXXHvakqeYIw/ZCNwIgvbvDUTor8X+gWZcx6QXAuEW5X/Shnog== X-Received: by 2002:a05:622a:298f:b0:434:6094:beaa with SMTP id hd15-20020a05622a298f00b004346094beaamr1267274qtb.39.1712318480615; Fri, 05 Apr 2024 05:01:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnpiinNv2C2T+YikhgYDSg8DJI+6kCRzyHodV6nkO8b80TJOicClVWNFFNXPLtsSMcu3AVIQ== X-Received: by 2002:a05:622a:298f:b0:434:6094:beaa with SMTP id hd15-20020a05622a298f00b004346094beaamr1267234qtb.39.1712318480054; Fri, 05 Apr 2024 05:01:20 -0700 (PDT) Received: from rh.redhat.com (p200300c93f4c24001316a1e598258370.dip0.t-ipconnect.de. [2003:c9:3f4c:2400:1316:a1e5:9825:8370]) by smtp.gmail.com with ESMTPSA id fb17-20020a05622a481100b00434383f2518sm679808qtb.87.2024.04.05.05.01.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 05:01:19 -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 2/4] KVM: arm64: maintain per VM value for CTR_EL0 Date: Fri, 5 Apr 2024 14:01:06 +0200 Message-ID: <20240405120108.11844-3-sebott@redhat.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240405120108.11844-1-sebott@redhat.com> References: <20240405120108.11844-1-sebott@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240405_050302_256916_0203ECB3 X-CRM114-Status: GOOD ( 16.07 ) 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 In preparation for CTR_EL0 emulation maintain a per VM for this register and use it where appropriate. Signed-off-by: Sebastian Ott --- arch/arm64/include/asm/kvm_host.h | 1 + arch/arm64/kvm/sys_regs.c | 22 +++++++++++++++------- 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 9e8a496fb284..481216febb46 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -318,6 +318,7 @@ struct kvm_arch { /* PMCR_EL0.N value for the guest */ u8 pmcr_n; + u64 ctr_el0; /* Iterator for idreg debugfs */ u8 idreg_debugfs_iter; diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 131f5b0ca2b9..4d29b1a0842d 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -215,13 +215,21 @@ 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 +static u64 kvm_get_ctr_el0(struct kvm *kvm) +{ + if (kvm->arch.ctr_el0) + return kvm->arch.ctr_el0; + + return read_sanitised_ftr_reg(SYS_CTR_EL0); +} + /* * 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 = read_sanitised_ftr_reg(SYS_CTR_EL0); + u64 ctr = kvm_get_ctr_el0(kvm); u8 field; if (icache) @@ -248,7 +256,7 @@ static u32 get_ccsidr(struct kvm_vcpu *vcpu, u32 csselr) if (vcpu->arch.ccsidr) return vcpu->arch.ccsidr[csselr]; - line_size = get_min_cache_line_size(csselr & CSSELR_EL1_InD); + line_size = get_min_cache_line_size(vcpu->kvm, csselr & CSSELR_EL1_InD); /* * Fabricate a CCSIDR value as the overriding value does not exist. @@ -283,7 +291,7 @@ static int set_ccsidr(struct kvm_vcpu *vcpu, u32 csselr, u32 val) u32 i; 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_InD)) return -EINVAL; if (!ccsidr) { @@ -1862,7 +1870,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); - p->regval = read_sanitised_ftr_reg(SYS_CTR_EL0); + p->regval = kvm_get_ctr_el0(vcpu->kvm); return true; } @@ -1882,7 +1890,7 @@ static bool access_clidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, */ static u64 reset_clidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) { - u64 ctr_el0 = read_sanitised_ftr_reg(SYS_CTR_EL0); + u64 ctr_el0 = kvm_get_ctr_el0(vcpu->kvm); u64 clidr; u8 loc; @@ -1935,7 +1943,7 @@ 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 ctr_el0 = read_sanitised_ftr_reg(SYS_CTR_EL0); + u64 ctr_el0 = kvm_get_ctr_el0(vcpu->kvm); u64 idc = !CLIDR_LOC(val) || (!CLIDR_LOUIS(val) && !CLIDR_LOUU(val)); if ((val & CLIDR_EL1_RES0) || (!(ctr_el0 & CTR_EL0_IDC) && idc))