T8132 smp#536
Conversation
a7d0ac2 to
40e2963
Compare
|
@abrender would you mind testing it again? |
|
Hello, I tried your PR on my M4 MacbookAir but I'm hitting the exception you introduced when trying to use the chainload. According to your initial comment on the PR, it seems you have a similar state (wrong value + locked), making me think you should also raise this exception when trying to chainload. Note: Not changing the secondary CPUs RVBARs allows me to complete the "chainload" (e.g. loading a patched m1n1), thus I'm wondering if this script should do it at all? |
Signed-off-by: Yureka <[email protected]>
|
I tested the following on my M4 Mac Mini:
IMO this PR is ready to be merged, as it solves the problem of causing the SError in smp init (for example when chainloading). |
Signed-off-by: Yureka <[email protected]>
Signed-off-by: Yureka <[email protected]>
|
Tested on my M4 Macbook Air, chainloading works properly and I don't hit the Python Exception anymore. |
Sorry for the delayed response - I no longer have access to the M4 to test :( |
jannau
left a comment
There was a problem hiding this comment.
functionally ok now, sorry for the nitpicking
|
|
||
| u64 rvbar_value = read64(impl); | ||
| bool rvbar_locked = rvbar_value & 1; | ||
| bool write_rvbar = (rvbar_value & 0xfffffffff000) != (u64)_vectors_start; |
There was a problem hiding this comment.
please use ~0xfffUL.
update_rvbar sounds to me clearer than write_rvbar
There was a problem hiding this comment.
~0xfffUL would not work. According to the notes in the PR description, the value I read from the register was 0x100100034f4001 for E-cores and 0x1100100034f4001 for P-Cores, while the m1n1 base is 0x100034f4000.
So, we want to skip if the last 48 bits (except the last 12 bits) are already set to the expected value, since the first 16 bits may contain some other information and are not used for the actual jump address.
There was a problem hiding this comment.
ok, please use defines then
#define RVBAR_LOCK BIT(0)
#define RVBAR_ADDR GENMASK(47, 12)
I don't think we need rvbar_locked then since FIELD_GET(RVBAR_LOCK, val) is as descriptive.
|
|
||
| val = p.read64(addr) | ||
| locked = val & 1 | ||
| do_write = val & 0xfffffffff000 != rvbar |
There was a problem hiding this comment.
I think
if val & ~0xfff != rvbar:
if val & 1:
raise Exception(f"RVBAR for {cpu.name} is locked but differs from entry point")
p.write64(addr, rvbar)
is easier to follow than the ifs with two booleans. print(f" {cpu.name}: [0x{addr:x}] = 0x{rvbar:x}") should stay directly above the write.
Not sure if we shouldn't just drop this. I think this is a leftover from old times before we updated in-place
|
|
||
| val = p.read64(addr) | ||
| locked = val & 1 | ||
| do_write = val & 0xfffffffff000 != rvbar |
| bool rvbar_locked = rvbar_value & 1; | ||
| bool write_rvbar = (rvbar_value & 0xfffffffff000) != (u64)_vectors_start; | ||
| if (rvbar_locked && write_rvbar) { | ||
| printf("RVBAR is locked and does not already contain start address:\n 0x%lx != 0x%lx\n", |
There was a problem hiding this comment.
Please prefix it with Failed! \n to make it clear that starting the secondary CPU failed.
"and differs from entry point" sound imo nicer. Printing the values could make clear which one is which
According to the discussion here, the RVBAR at cpu_impl_reg+0x00 is already set to the m1n1 entrypoint and locked by iBoot for all cores on M4.
Indeed, I can see the following values:
m1n1 base:
0x100034f4000E-Cores cpu_impl_reg at
0x210X50000:0x100100034f4001P-Cores cpu_impl_reg at
0x211X50000:0x1100100034f4001And voila, when skipping the writes when the value is already correct (which previously produced SErrors when writing to the P-Core cpu_impl_reg),
smp_start_secondaries()now works as expected.