From patchwork Sat Apr 10 08:16:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shaokun Zhang X-Patchwork-Id: 12195459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 08C56C433ED for ; Sat, 10 Apr 2021 08:19:22 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 88A4761184 for ; Sat, 10 Apr 2021 08:19:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 88A4761184 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=hisilicon.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version: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:In-Reply-To:References:List-Owner; bh=9sPc3wBOkQsp8eKHMQhD+Zb9nIidSH6BtozIcfeIMqo=; b=JYLdIUoK1XbE7c7c2DpAAoU2f+ n6byxHBNNu/hi8I8K8jncNUyb6Wpg2qon5GtPD9m7Q8CFthZxsJDlHWteBaw0uUsJobpevnkqmwqW 66zKu9ojxd2wtA2HKL6pB9aGi2UYsKxFvHpAAwfFxiVjCQyPEcFqJa3wsr6xCC7j0NefibeRi2Kx7 WymvXWnCB+f6sQ3YTr0pnlV769y2+6P4/qQ4BExgsKVpbNaRIEkxz/NrzejmCV+5DUPM0ONi4oWbX PkizRuRLgyzRe7WQKiQUqqTgQgU9eWctgAdMSHp0Cbhbf5FoEQoqNnOOanOUH/TNB8dnNHQOQB8r2 e1vkUjRw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lV8o2-002P1t-5P; Sat, 10 Apr 2021 08:17:26 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lV8ny-002P1o-6S for linux-arm-kernel@desiato.infradead.org; Sat, 10 Apr 2021 08:17:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Type:MIME-Version:Message-ID: Date:Subject:CC:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=lMsPYxCRIfCDflQ/Ujh+NzM0dHEaLp49sZc2wgMC4Qk=; b=2pbYbg7bvq7yt6tvX1Sa7wSmLA 8sx2LwO6EjTcQG7eQre0y47//glQ3frze8+sc9Qp1alKt1/9AoMFhJf90KNELjA9U6m877bxNR2t/ +AiZacLfjjfrwNoQLmTmhzSmK43MnjydttLTBKmB+5RbRVCefGcr0++jHZzFRt/hoEXV5+L4zD8z+ la/KgRWmAZw4mI1QzmlN0EXvDYOUJxbd+2pkaxh/lQagTHWTGa+bAv2wvVvUCEvIQRZF4LoPUPf26 7mgRQnN1xQrpddPqtK0IpWzPfGTbwdu3teBUQIPAOHSPqSQa7hpluFXx9fSC1/3loqSPUFyxydQIs e7cvnYFg==; Received: from szxga07-in.huawei.com ([45.249.212.35]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lV8nt-004z76-Ph for linux-arm-kernel@lists.infradead.org; Sat, 10 Apr 2021 08:17:19 +0000 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4FHSTm4d6tz9xYS; Sat, 10 Apr 2021 16:14:52 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.498.0; Sat, 10 Apr 2021 16:16:58 +0800 From: Shaokun Zhang To: , CC: Shaokun Zhang , Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose Subject: [RFC] KVM: arm64: Support FEAT_CCIDX Date: Sat, 10 Apr 2021 16:16:37 +0800 Message-ID: <1618042597-59294-1-git-send-email-zhangshaokun@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210410_011718_042673_B2C6512E X-CRM114-Status: GOOD ( 13.50 ) 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 CCSIDR_EL1 can be implemented as 64-bit format inferred by CCIDX field in ID_AA64MMFR2_EL1. The bits of Numsets and Associativity are different from the 32-bit format. Let's support this feature. Cc: Marc Zyngier Cc: James Morse Cc: Alexandru Elisei Cc: Suzuki K Poulose Signed-off-by: Shaokun Zhang --- arch/arm64/kvm/sys_regs.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 52fdb9a015a4..0dc822cef20b 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -95,9 +96,9 @@ static u32 cache_levels; #define CSSELR_MAX 14 /* Which cache CCSIDR represents depends on CSSELR value. */ -static u32 get_ccsidr(u32 csselr) +static u64 get_ccsidr(u32 csselr) { - u32 ccsidr; + u64 ccsidr; /* Make sure noone else changes CSSELR during this! */ local_irq_disable(); @@ -1275,12 +1276,16 @@ static bool access_csselr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, const struct sys_reg_desc *r) { - u32 csselr; + u32 csselr, ccidx; + u64 mmfr2; if (p->is_write) return write_to_read_only(vcpu, p, r); csselr = vcpu_read_sys_reg(vcpu, CSSELR_EL1); + mmfr2 = read_sysreg_s(SYS_ID_AA64MMFR2_EL1); + ccidx = cpuid_feature_extract_unsigned_field(mmfr2, + ID_AA64MMFR2_CCIDX_SHIFT); p->regval = get_ccsidr(csselr); /* @@ -1295,8 +1300,13 @@ static bool access_ccsidr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, * geometry (which is not permitted by the architecture), they would * only do so for virtually indexed caches.] */ - if (!(csselr & 1)) // data or unified cache - p->regval &= ~GENMASK(27, 3); + if (!(csselr & 1)) { // data or unified cache + if (ccidx) + p->regval &= ~(GENMASK(23, 3) | GENMASK(55, 32)); + else + p->regval &= ~GENMASK(27, 3); + } + return true; } @@ -2521,7 +2531,7 @@ static bool is_valid_cache(u32 val) static int demux_c15_get(u64 id, void __user *uaddr) { u32 val; - u32 __user *uval = uaddr; + u64 __user *uval = uaddr; /* Fail if we have unknown bits set. */ if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK @@ -2545,8 +2555,9 @@ static int demux_c15_get(u64 id, void __user *uaddr) static int demux_c15_set(u64 id, void __user *uaddr) { - u32 val, newval; - u32 __user *uval = uaddr; + u32 val; + u64 newval; + u64 __user *uval = uaddr; /* Fail if we have unknown bits set. */ if (id & ~(KVM_REG_ARCH_MASK|KVM_REG_SIZE_MASK|KVM_REG_ARM_COPROC_MASK