Skip to content

Commit dfbf8c9

Browse files
wildea01gregkh
authored andcommitted
arm64: Fix minor issues with the dcache_by_line_op macro
[ Upstream commit 33309ec ] The dcache_by_line_op macro suffers from a couple of small problems: First, the GAS directives that are currently being used rely on assembler behavior that is not documented, and probably not guaranteed to produce the correct behavior going forward. As a result, we end up with some undefined symbols in cache.o: $ nm arch/arm64/mm/cache.o ... U civac ... U cvac U cvap U cvau This is due to the fact that the comparisons used to select the operation type in the dcache_by_line_op macro are comparing symbols not strings, and even though it seems that GAS is doing the right thing here (undefined symbols by the same name are equal to each other), it seems unwise to rely on this. Second, when patching in a DC CVAP instruction on CPUs that support it, the fallback path consists of a DC CVAU instruction which may be affected by CPU errata that require ARM64_WORKAROUND_CLEAN_CACHE. Solve these issues by unrolling the various maintenance routines and using the conditional directives that are documented as operating on strings. To avoid the complexity of nested alternatives, we move the DC CVAP patching to __clean_dcache_area_pop, falling back to a branch to __clean_dcache_area_poc if DCPOP is not supported by the CPU. Reported-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Suggested-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 73f0b2e commit dfbf8c9

2 files changed

Lines changed: 21 additions & 12 deletions

File tree

‎arch/arm64/include/asm/assembler.h‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -378,27 +378,33 @@ alternative_endif
378378
* size: size of the region
379379
* Corrupts: kaddr, size, tmp1, tmp2
380380
*/
381+
.macro __dcache_op_workaround_clean_cache, op, kaddr
382+
alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
383+
dc \op, \kaddr
384+
alternative_else
385+
dc civac, \kaddr
386+
alternative_endif
387+
.endm
388+
381389
.macro dcache_by_line_op op, domain, kaddr, size, tmp1, tmp2
382390
dcache_line_size \tmp1, \tmp2
383391
add \size, \kaddr, \size
384392
sub \tmp2, \tmp1, #1
385393
bic \kaddr, \kaddr, \tmp2
386394
9998:
387-
.if (\op == cvau || \op == cvac)
388-
alternative_if_not ARM64_WORKAROUND_CLEAN_CACHE
389-
dc \op, \kaddr
390-
alternative_else
391-
dc civac, \kaddr
392-
alternative_endif
393-
.elseif (\op == cvap)
394-
alternative_if ARM64_HAS_DCPOP
395-
sys 3, c7, c12, 1, \kaddr // dc cvap
396-
alternative_else
397-
dc cvac, \kaddr
398-
alternative_endif
395+
.ifc \op, cvau
396+
__dcache_op_workaround_clean_cache \op, \kaddr
397+
.else
398+
.ifc \op, cvac
399+
__dcache_op_workaround_clean_cache \op, \kaddr
400+
.else
401+
.ifc \op, cvap
402+
sys 3, c7, c12, 1, \kaddr // dc cvap
399403
.else
400404
dc \op, \kaddr
401405
.endif
406+
.endif
407+
.endif
402408
add \kaddr, \kaddr, \tmp1
403409
cmp \kaddr, \size
404410
b.lo 9998b

‎arch/arm64/mm/cache.S‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ ENDPROC(__dma_clean_area)
212212
* - size - size in question
213213
*/
214214
ENTRY(__clean_dcache_area_pop)
215+
alternative_if_not ARM64_HAS_DCPOP
216+
b __clean_dcache_area_poc
217+
alternative_else_nop_endif
215218
dcache_by_line_op cvap, sy, x0, x1, x2, x3
216219
ret
217220
ENDPIPROC(__clean_dcache_area_pop)

0 commit comments

Comments
 (0)