From: Stephen Boyd <sboyd@codeaurora.org> To: David Brown <davidb@codeaurora.org>, Kumar Gala <galak@codeaurora.org> Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Lina Iyer <lina.iyer@linaro.org> Subject: [PATCH 1/8] msm: scm: Fix incorrect cache invalidation Date: Mon, 4 Aug 2014 18:31:43 -0700 [thread overview] Message-ID: <1407202310-3359-2-git-send-email-sboyd@codeaurora.org> (raw) In-Reply-To: <1407202310-3359-1-git-send-email-sboyd@codeaurora.org> The cache invalidation in scm_call() correctly rounds down the start address to invalidate the beginning of the cacheline but doesn't properly round up the 'end' address to make it aligned. The last chunk of the buffer won't be invalidated when 'end' is not cacheline size aligned so make sure to invalidate the last few bytes in such situations. It also doesn't do anything about outer caches so make sure to invalidate and flush those as well. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> --- arch/arm/mach-qcom/scm.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-qcom/scm.c b/arch/arm/mach-qcom/scm.c index c536fd6bf827..820c72165e19 100644 --- a/arch/arm/mach-qcom/scm.c +++ b/arch/arm/mach-qcom/scm.c @@ -22,6 +22,7 @@ #include <linux/errno.h> #include <linux/err.h> +#include <asm/outercache.h> #include <asm/cacheflush.h> #include "scm.h" @@ -203,6 +204,7 @@ static int __scm_call(const struct scm_command *cmd) * side in the buffer. */ flush_cache_all(); + outer_flush_all(); ret = smc(cmd_addr); if (ret < 0) ret = scm_remap_error(ret); @@ -210,6 +212,20 @@ static int __scm_call(const struct scm_command *cmd) return ret; } +static void scm_inv_range(unsigned long start, unsigned long end) +{ + start = round_down(start, CACHELINESIZE); + end = round_up(end, CACHELINESIZE); + outer_inv_range(start, end); + while (start < end) { + asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) + : "memory"); + start += CACHELINESIZE; + } + dsb(); + isb(); +} + /** * scm_call() - Send an SCM command * @svc_id: service identifier @@ -227,6 +243,7 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len, int ret; struct scm_command *cmd; struct scm_response *rsp; + unsigned long start, end; cmd = alloc_scm_command(cmd_len, resp_len); if (!cmd) @@ -243,17 +260,15 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len, goto out; rsp = scm_command_to_response(cmd); + start = (unsigned long)rsp; + do { - u32 start = (u32)rsp; - u32 end = (u32)scm_get_response_buffer(rsp) + resp_len; - start &= ~(CACHELINESIZE - 1); - while (start < end) { - asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) - : "memory"); - start += CACHELINESIZE; - } + scm_inv_range(start, start + sizeof(*rsp)); } while (!rsp->is_complete); + end = (unsigned long)scm_get_response_buffer(rsp) + resp_len; + scm_inv_range(start, end); + if (resp_buf) memcpy(resp_buf, scm_get_response_buffer(rsp), resp_len); out: -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
WARNING: multiple messages have this Message-ID (diff)
From: sboyd@codeaurora.org (Stephen Boyd) To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/8] msm: scm: Fix incorrect cache invalidation Date: Mon, 4 Aug 2014 18:31:43 -0700 [thread overview] Message-ID: <1407202310-3359-2-git-send-email-sboyd@codeaurora.org> (raw) In-Reply-To: <1407202310-3359-1-git-send-email-sboyd@codeaurora.org> The cache invalidation in scm_call() correctly rounds down the start address to invalidate the beginning of the cacheline but doesn't properly round up the 'end' address to make it aligned. The last chunk of the buffer won't be invalidated when 'end' is not cacheline size aligned so make sure to invalidate the last few bytes in such situations. It also doesn't do anything about outer caches so make sure to invalidate and flush those as well. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> --- arch/arm/mach-qcom/scm.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/arch/arm/mach-qcom/scm.c b/arch/arm/mach-qcom/scm.c index c536fd6bf827..820c72165e19 100644 --- a/arch/arm/mach-qcom/scm.c +++ b/arch/arm/mach-qcom/scm.c @@ -22,6 +22,7 @@ #include <linux/errno.h> #include <linux/err.h> +#include <asm/outercache.h> #include <asm/cacheflush.h> #include "scm.h" @@ -203,6 +204,7 @@ static int __scm_call(const struct scm_command *cmd) * side in the buffer. */ flush_cache_all(); + outer_flush_all(); ret = smc(cmd_addr); if (ret < 0) ret = scm_remap_error(ret); @@ -210,6 +212,20 @@ static int __scm_call(const struct scm_command *cmd) return ret; } +static void scm_inv_range(unsigned long start, unsigned long end) +{ + start = round_down(start, CACHELINESIZE); + end = round_up(end, CACHELINESIZE); + outer_inv_range(start, end); + while (start < end) { + asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) + : "memory"); + start += CACHELINESIZE; + } + dsb(); + isb(); +} + /** * scm_call() - Send an SCM command * @svc_id: service identifier @@ -227,6 +243,7 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len, int ret; struct scm_command *cmd; struct scm_response *rsp; + unsigned long start, end; cmd = alloc_scm_command(cmd_len, resp_len); if (!cmd) @@ -243,17 +260,15 @@ int scm_call(u32 svc_id, u32 cmd_id, const void *cmd_buf, size_t cmd_len, goto out; rsp = scm_command_to_response(cmd); + start = (unsigned long)rsp; + do { - u32 start = (u32)rsp; - u32 end = (u32)scm_get_response_buffer(rsp) + resp_len; - start &= ~(CACHELINESIZE - 1); - while (start < end) { - asm ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start) - : "memory"); - start += CACHELINESIZE; - } + scm_inv_range(start, start + sizeof(*rsp)); } while (!rsp->is_complete); + end = (unsigned long)scm_get_response_buffer(rsp) + resp_len; + scm_inv_range(start, end); + if (resp_buf) memcpy(resp_buf, scm_get_response_buffer(rsp), resp_len); out: -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
next prev parent reply other threads:[~2014-08-05 1:31 UTC|newest] Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top 2014-08-05 1:31 [PATCH 0/8] qcom SCM updates Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd [this message] 2014-08-05 1:31 ` [PATCH 1/8] msm: scm: Fix incorrect cache invalidation Stephen Boyd 2014-08-05 1:31 ` [PATCH 2/8] msm: scm: Get cacheline size from CTR Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 3/8] msm: scm: Flush the command buffer only instead of the entire cache Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 4/8] msm: scm: Add atomic SCM APIs Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 5/8] msm: scm: Add API to query for service/command availability Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 6/8] msm: scm: Add a feat version query API Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 7/8] msm: scm: Add logging of actual return code from scm call Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 1:31 ` [PATCH 8/8] msm: scm: Move the scm driver to drivers/soc/qcom Stephen Boyd 2014-08-05 1:31 ` Stephen Boyd 2014-08-05 4:07 ` Lina Iyer 2014-08-05 4:07 ` Lina Iyer 2014-08-05 20:12 ` Bjorn Andersson 2014-08-05 20:12 ` Bjorn Andersson 2014-08-05 20:12 ` Bjorn Andersson 2014-08-05 20:17 ` Lina Iyer 2014-08-05 20:17 ` Lina Iyer 2014-08-05 20:17 ` Lina Iyer 2015-01-22 1:13 ` Olof Johansson 2015-01-22 1:13 ` Olof Johansson 2015-01-22 1:13 ` Olof Johansson 2015-01-22 1:53 ` Bjorn Andersson 2015-01-22 1:53 ` Bjorn Andersson 2015-01-22 1:53 ` Bjorn Andersson 2015-01-22 16:49 ` Kumar Gala 2015-01-22 16:49 ` Kumar Gala 2015-01-22 16:49 ` Kumar Gala 2015-01-23 1:19 ` Rob Clark 2015-01-23 1:19 ` Rob Clark 2015-01-23 1:19 ` Rob Clark 2014-09-17 22:08 ` [PATCH 0/8] qcom SCM updates Kumar Gala 2014-09-17 22:08 ` Kumar Gala
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1407202310-3359-2-git-send-email-sboyd@codeaurora.org \ --to=sboyd@codeaurora.org \ --cc=davidb@codeaurora.org \ --cc=galak@codeaurora.org \ --cc=lina.iyer@linaro.org \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-arm-msm@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.