Re: [PATCH v2 1/1] x86: Add Isolated Memory Regions for Quark X1000

From: Bryan O'Donoghue
Date: Sat Jan 24 2015 - 14:53:27 EST


On 24/01/15 01:48, Ong, Boon Leong wrote:

Skipping stuff I agree with.

From V1 comment:
Suggest to add a statement on 3 different types of IMR: General IMR, Host Memory
I/O Boundary IMR & System Management Mode IMR. Then, call out that this patch
is meant to support general IMR type only.

Hmm - There's no mention of grouping like that in the documentation, nor in released silicon - to my knowledge.

Also why do you want a statement added saying that it supports CPU only mode ?

This patch will support adding IMRs for SMM mode - if calling code wants do do that - it's just imr_add_range(base, size, SMM, SMM);

Same thing with virtual-channels, RMU, etc.


+ ret = imr_check_range(base, size);
+ if (ret)
+ return ret;
+
+ if (size < IMR_ALIGN)
+ return -EINVAL;
I believe this is redundant because imr_check_range() has test for (size & IMR_MASK)
which means if the size is indeed smaller than 0x400, the test will caught it anyway.

Nope.

(0 & 0x3FF) == 0

We need to bounds check for a zero size.

I'll change it to

if (size == 0)
return -EINVAL;

to avoid confusion.

+
+ /* Tweak the size value */
+ size = imr_fixup_size(size);
+ pr_debug("IMR %d phys 0x%08lx-0x%08lx rmask 0x%08x wmask
0x%08x\n",
+ reg, base, end, rmask, wmask);
Do we want to account for the 'size fixup' above on 'end'
+
+ /* Allocate IMR */
+ imr.addr_lo = phys_to_imr(base);
+ imr.addr_hi = phys_to_imr(end);

The fix-up size above is never factored here ...
'end-size' should be the correct one

hmmm.

The correct fix is

size = imr_fixup_size(size);
end = base + size;

+ } else {
+ /* Search for match based on address range */
+ for (i = 0; i < imr_dev.max_imr; i++) {
+ ret = imr_read(reg, &imr);
A serious bug here.... 'reg' should be 'i' . We enter this branch if reg=-1
Is there a miss in your test case?

Hmm you're right.

Turns out there's only the one test case for imr_del_range();

Good catch.

--
BOD

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/