Skip to content

libsel4vm: fix number of GIC active_clr registers - #29

Merged
kent-mcleod merged 1 commit into
seL4:masterfrom
Ivan-Velickovic:vgic_fixes
Jun 15, 2022
Merged

kent-mcleod merged 1 commit into
seL4:masterfrom
Ivan-Velickovic:vgic_fixes

Conversation

@Ivan-Velickovic

@Ivan-Velickovic Ivan-Velickovic commented Mar 8, 2022

Copy link
Copy Markdown
Contributor

active_clr has 31 registers that aren't banked, rather than 32.

uint32_t active[31]; /* [0x300, 0x380) */
uint32_t active_clr0[CONFIG_MAX_NUM_NODES]; /* [0x380, 0x384) */
uint32_t active_clr[32]; /* [0x384, 0x400) */
uint32_t active_clr[31]; /* [0x384, 0x400) */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems this has always been a bug then and the comments about the offsets were never right from this place on? Are we just lucky the code every worked because nobody uses this correctly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a bug since the only access to that field is in the distributor fault handling code, and those accesses are dependent on the offsets defined in vgicv2_defs.h, which are correct. I don't think it was ever possible to access the last element when it was length 32.

@axel-h axel-h Mar 8, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a bug, because if we have 32 words here, this uses offset 0x384 - 0x404 actually, so everything after this is 4 byte off.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are we depending on these offsets?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something here. Is this describing some actual hardware or is this is virtual peripheral where the actual memory layout does not matter because it only ever accesses via the filed names, so the compiler handles this properly and any memory layout could be used?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is virtual, all the "resX" could also be dropped, because nobody needs them and they don't guarantee anything when CONFIG_MAX_NUM_NODES changes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm implementing GICv3 right now, and was planning on adding a comment explaining why the register map is dependent on CONFIG_MAX_NUM_NODES and so the offsets aren't always correct. I think that they still have value, it's easier for me to go to the spec based on an offset commented rather than the name of the field.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment here explaining it anyways.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is virtual, all the "resX" could also be dropped

Sure, I'll do that too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offsets [...] still have value, it's easier for me to go to the spec based on an offset commented rather than the name of the field.

Well, I'd argue here, that the specs [1][2] also use names, and these might be easier to search for than the number.

[1] https://developer.arm.com/documentation/ddi0471/b/programmers-model/distributor-register-summary
[2] https://developer.arm.com/documentation/ddi0516/e/programmers-model/distributor-register-summary

Comment thread libsel4vm/src/arch/arm/vgic/vgic.c Outdated
assert(!"Unable to calloc memory for VGIC");
return -1;
}
assert(vgic);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure is you can do that, there is no global guarantee calloc() will be successful and asserts are removed in release code. Now one could argue that it never fails in release code because this is well tested - but still, you don't know the context this is used in. So I'd prefer to keep this and have an error path here that the caller must deal with.
Another option would be making all this static, so the compiler/linker can ensure this. How much dynamism do we need there in the end?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @axel-h, the error checking should stay as this is library and needs to allow applications to make policy choices about whether to abort on errors or do something else.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was my mistake, I wrongly assumed that asserts were enabled in release mode. I'll make these changes once #28 goes through.

Comment thread libsel4vm/src/arch/arm/vgic/vgic.c Outdated
free(vgic_dist->priv);
return -1;
}
assert(!err);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep the cleanup and just accept that thing might fail. It's the caller problem then to handle this.

@axel-h

axel-h commented Mar 8, 2022

Copy link
Copy Markdown
Member

I'm not sure about removing the error checking - why remove this?

@axel-h

axel-h commented Mar 8, 2022

Copy link
Copy Markdown
Member

I'm implementing GICv3 right now

The PR #8 also works towards this, could you check if you can take over this one?

@axel-h
axel-h requested a review from yyshen March 8, 2022 17:48
@Ivan-Velickovic

Copy link
Copy Markdown
Contributor Author

The PR #8 also works towards this, could you check if you can take over this one?

I am using #8 as a reference but was planning on making a separate PR. Is that okay or should I be trying to resurrect #8?

@axel-h

axel-h commented Mar 9, 2022

Copy link
Copy Markdown
Member

I am using #8 as a reference but was planning on making a separate PR. Is that okay or should I be trying to resurrect #8?

if you already had a look there and concluded there's not much in it, then we can also close it as outdated and reference this PR as the new approach to add GICv3 support eventually.

@Ivan-Velickovic

Ivan-Velickovic commented Mar 9, 2022

Copy link
Copy Markdown
Contributor Author

if you already had a look there and concluded there's not much in it, then we can also close it as outdated and reference this PR as the new approach to add GICv3 support eventually.

It's not that there's not much in it, it's that due to the code changing over time since the PR, I would rather selectively take what I need rather than take over the existing one. But if you think it's better to take over it, I can do that.

@axel-h

axel-h commented Mar 9, 2022

Copy link
Copy Markdown
Member

But if you think it's better to take over it, I can do that.

I have not really opinion there. Cherry-picking what's useful sound like a good plan. And once there's a new PR from you we close #8 one as obsolete.

@lsf37

lsf37 commented Mar 9, 2022

Copy link
Copy Markdown
Member

Yes, I'm also happy with that approach.

@kent-mcleod

Copy link
Copy Markdown
Member

I think this should be put on hold until after #28 is resolved as it looks to be refactoring the same code.

@axel-h

axel-h commented Mar 28, 2022

Copy link
Copy Markdown
Member

#28 is merged now, can you rebase this? Would be good to have the trivial: fix number of active_clr registers merged then also.

@axel-h

axel-h commented Apr 22, 2022

Copy link
Copy Markdown
Member

@Ivan-Velickovic: could you rebase this an resolve the conflicts, so we can merge it?

@axel-h

axel-h commented Jun 13, 2022

Copy link
Copy Markdown
Member

@Ivan-Velickovic: could you rebase this and resolve the conflicts, so we can merge it?

Signed-off-by: Ivan Velickovic <i.velickovic@unsw.edu.au>
@Ivan-Velickovic Ivan-Velickovic changed the title Various VGIC fixes/clean up libsel4vm: fix number of GIC active_clr registers Jun 14, 2022
@Ivan-Velickovic

Copy link
Copy Markdown
Contributor Author

Done. Apologies for forgetting about this.

@axel-h axel-h mentioned this pull request Jun 14, 2022
@kent-mcleod
kent-mcleod merged commit 44cf596 into seL4:master Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants