From patchwork Fri Jan 20 10:50:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 92051 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1650obz; Fri, 20 Jan 2017 02:50:55 -0800 (PST) X-Received: by 10.55.22.97 with SMTP id g94mr11367296qkh.287.1484909455926; Fri, 20 Jan 2017 02:50:55 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id a19si4640120qtc.79.2017.01.20.02.50.55 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jan 2017 02:50:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cUWmT-0000RN-Ht; Fri, 20 Jan 2017 10:50:53 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cUWmD-0008Jr-H7 for linux-arm-kernel@lists.infradead.org; Fri, 20 Jan 2017 10:50:39 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 532DEF; Fri, 20 Jan 2017 02:50:17 -0800 (PST) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2E23C3F24D; Fri, 20 Jan 2017 02:50:16 -0800 (PST) From: Sudeep Holla To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/2] arm64: kvm: reuse existing cache type/info related macros Date: Fri, 20 Jan 2017 10:50:09 +0000 Message-Id: <1484909410-11673-1-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170120_025037_594824_BDE98FEE X-CRM114-Status: UNSURE ( 9.94 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -10.1 (----------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-10.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.101.70 listed in list.dnswl.org] -3.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Catalin Marinas , Will Deacon , Christoffer Dall , Sudeep Holla MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org We already have various macros related to cache type and bitfields in CLIDR system register. We can replace some of the hardcoded values here using those existing macros. This patch reuses those existing cache type/info related macros and replaces the hardcorded values. It also removes some of the comments that become trivial with the macro names. Cc: Catalin Marinas Cc: Will Deacon Cc: Christoffer Dall Cc: Marc Zyngier Signed-off-by: Sudeep Holla --- arch/arm64/include/asm/cachetype.h | 7 +++++++ arch/arm64/kernel/cacheinfo.c | 7 ------- arch/arm64/kvm/sys_regs.c | 27 +++++++++++++-------------- 3 files changed, 20 insertions(+), 21 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/include/asm/cachetype.h b/arch/arm64/include/asm/cachetype.h index f5588692f1d4..f58b5e3df6b8 100644 --- a/arch/arm64/include/asm/cachetype.h +++ b/arch/arm64/include/asm/cachetype.h @@ -39,6 +39,13 @@ extern unsigned long __icache_flags; +#define MAX_CACHE_LEVEL 7 /* Max 7 level supported */ +/* Ctypen, bits[3(n - 1) + 2 : 3(n - 1)], for n = 1 to 7 */ +#define CLIDR_CTYPE_SHIFT(level) (3 * (level - 1)) +#define CLIDR_CTYPE_MASK(level) (7 << CLIDR_CTYPE_SHIFT(level)) +#define CLIDR_CTYPE(clidr, level) \ + (((clidr) & CLIDR_CTYPE_MASK(level)) >> CLIDR_CTYPE_SHIFT(level)) + /* * NumSets, bits[27:13] - (Number of sets in cache) - 1 * Associativity, bits[12:3] - (Associativity of cache) - 1 diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c index 3f2250fc391b..a460208b08cf 100644 --- a/arch/arm64/kernel/cacheinfo.c +++ b/arch/arm64/kernel/cacheinfo.c @@ -26,13 +26,6 @@ #include #include -#define MAX_CACHE_LEVEL 7 /* Max 7 level supported */ -/* Ctypen, bits[3(n - 1) + 2 : 3(n - 1)], for n = 1 to 7 */ -#define CLIDR_CTYPE_SHIFT(level) (3 * (level - 1)) -#define CLIDR_CTYPE_MASK(level) (7 << CLIDR_CTYPE_SHIFT(level)) -#define CLIDR_CTYPE(clidr, level) \ - (((clidr) & CLIDR_CTYPE_MASK(level)) >> CLIDR_CTYPE_SHIFT(level)) - static inline enum cache_type get_cache_type(int level) { u64 clidr; diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 87e7e6608cd8..5dca1f10340f 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -21,11 +21,13 @@ */ #include +#include #include #include #include #include +#include #include #include #include @@ -59,7 +61,7 @@ static u32 cache_levels; /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ -#define CSSELR_MAX 12 +#define CSSELR_MAX ((MAX_CACHE_LEVEL - 1) >> 1) /* Which cache CCSIDR represents depends on CSSELR value. */ static u32 get_ccsidr(u32 csselr) @@ -68,9 +70,7 @@ static u32 get_ccsidr(u32 csselr) /* Make sure noone else changes CSSELR during this! */ local_irq_disable(); - write_sysreg(csselr, csselr_el1); - isb(); - ccsidr = read_sysreg(ccsidr_el1); + ccsidr = cache_get_ccsidr(csselr); local_irq_enable(); return ccsidr; @@ -1960,19 +1960,18 @@ static bool is_valid_cache(u32 val) return false; /* Bottom bit is Instruction or Data bit. Next 3 bits are level. */ - level = (val >> 1); - ctype = (cache_levels >> (level * 3)) & 7; + level = (val >> 1) + 1; + ctype = CLIDR_CTYPE(cache_levels, level); switch (ctype) { - case 0: /* No cache */ - return false; - case 1: /* Instruction cache only */ - return (val & 1); - case 2: /* Data cache only */ - case 4: /* Unified cache */ - return !(val & 1); - case 3: /* Separate instruction and data caches */ + case CACHE_TYPE_INST: + return (val & CACHE_TYPE_INST); + case CACHE_TYPE_DATA: + case CACHE_TYPE_UNIFIED: + return !(val & CACHE_TYPE_INST); + case CACHE_TYPE_SEPARATE: return true; + case CACHE_TYPE_NOCACHE: default: /* Reserved: we can't know instruction or data. */ return false; } From patchwork Fri Jan 20 10:50:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudeep Holla X-Patchwork-Id: 92050 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp1581obz; Fri, 20 Jan 2017 02:50:44 -0800 (PST) X-Received: by 10.55.192.196 with SMTP id v65mr11698465qkv.40.1484909444580; Fri, 20 Jan 2017 02:50:44 -0800 (PST) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id m28si4621980qtm.165.2017.01.20.02.50.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jan 2017 02:50:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cUWmI-000069-Va; Fri, 20 Jan 2017 10:50:42 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cUWmD-0008Ko-H7 for linux-arm-kernel@lists.infradead.org; Fri, 20 Jan 2017 10:50:39 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6AF81516; Fri, 20 Jan 2017 02:50:18 -0800 (PST) Received: from e107155-lin.cambridge.arm.com (unknown [10.1.210.28]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8F5893F24D; Fri, 20 Jan 2017 02:50:17 -0800 (PST) From: Sudeep Holla To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/2] arm64: kvm: upgrade csselr and ccsidr to 64-bit values Date: Fri, 20 Jan 2017 10:50:10 +0000 Message-Id: <1484909410-11673-2-git-send-email-sudeep.holla@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1484909410-11673-1-git-send-email-sudeep.holla@arm.com> References: <1484909410-11673-1-git-send-email-sudeep.holla@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170120_025037_595876_CAE83B70 X-CRM114-Status: GOOD ( 10.01 ) X-Spam-Score: -10.1 (----------) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-10.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [217.140.101.70 listed in list.dnswl.org] -3.2 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Catalin Marinas , Will Deacon , Christoffer Dall , Sudeep Holla MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org csselr and ccsidr are treated as 64-bit values already elsewhere in the kernel. It also aligns well with the architecture extensions that allow 64-bit format for ccsidr. This patch upgrades the existing accesses to csselr and ccsidr from 32-bit to 64-bit in preparation to add support to those extensions. Cc: Christoffer Dall Cc: Marc Zyngier Signed-off-by: Sudeep Holla --- arch/arm64/kvm/sys_regs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 5dca1f10340f..a3559a8a2b0c 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -58,15 +58,15 @@ */ /* 3 bits per cache level, as per CLIDR, but non-existent caches always 0 */ -static u32 cache_levels; +static u64 cache_levels; /* CSSELR values; used to index KVM_REG_ARM_DEMUX_ID_CCSIDR */ #define CSSELR_MAX ((MAX_CACHE_LEVEL - 1) >> 1) /* Which cache CCSIDR represents depends on CSSELR value. */ -static u32 get_ccsidr(u32 csselr) +static u64 get_ccsidr(u64 csselr) { - u32 ccsidr; + u64 ccsidr; /* Make sure noone else changes CSSELR during this! */ local_irq_disable(); @@ -1952,9 +1952,9 @@ static int set_invariant_sys_reg(u64 id, void __user *uaddr) return 0; } -static bool is_valid_cache(u32 val) +static bool is_valid_cache(u64 val) { - u32 level, ctype; + u64 level, ctype; if (val >= CSSELR_MAX) return false; @@ -1979,8 +1979,8 @@ static bool is_valid_cache(u32 val) static int demux_c15_get(u64 id, void __user *uaddr) { - u32 val; - u32 __user *uval = uaddr; + u64 val; + 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 @@ -2004,8 +2004,8 @@ 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; + u64 val, 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