Message ID | 20191217123851.8854-2-david@redhat.com (mailing list archive) |
---|---|
State | RFC |
Headers | show |
Series | [RFC,v1,1/3] powerpc/memtrace: Enforce power of 2 for memory buffer size | expand |
Context | Check | Description |
---|---|---|
snowpatch_ozlabs/apply_patch | success | Successfully applied on branch powerpc/merge (270c0c3e491684893e7250f6c32f4f2eb2e4c3b2) |
snowpatch_ozlabs/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 20 lines checked |
diff --git a/arch/powerpc/platforms/powernv/memtrace.c b/arch/powerpc/platforms/powernv/memtrace.c index eb2e75dac369..0c4c54d2e3c4 100644 --- a/arch/powerpc/platforms/powernv/memtrace.c +++ b/arch/powerpc/platforms/powernv/memtrace.c @@ -268,15 +268,11 @@ static int memtrace_online(void) static int memtrace_enable_set(void *data, u64 val) { - u64 bytes; - - /* - * Don't attempt to do anything if size isn't aligned to a memory - * block or equal to zero. - */ - bytes = memory_block_size_bytes(); - if (val & (bytes - 1)) { - pr_err("Value must be aligned with 0x%llx\n", bytes); + const unsigned long bytes = memory_block_size_bytes(); + + if (val && (!is_power_of_2(val) || val < bytes)) { + pr_err("Value must be 0 or a power of 2 (at least 0x%lx)\n", + bytes); return -EINVAL; }
The code mentions "Trace memory needs to be aligned to the size", and e.g., round_up() is documented to work on power of 2 only. Also, the whole search is not optimized e.g., for being aligned to memory block size only while allocating multiple memory blocks. Let's just limit to powers of 2 that are at least the size of memory blocks - the granularity we are using for alloc/offline/unplug. Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: David Hildenbrand <david@redhat.com> Cc: Allison Randal <allison@lohutok.net> Cc: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Balbir Singh <bsingharora@gmail.com> Cc: Rashmica Gupta <rashmica.g@gmail.com> Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: David Hildenbrand <david@redhat.com> --- arch/powerpc/platforms/powernv/memtrace.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)