Skip to content

Conversation

@i2h2
Copy link
Contributor

@i2h2 i2h2 commented Jun 6, 2025

Boots SMP Linux as kvm guest with VS IMSIC interrupts. Dependent on riscv/riscv-opcodes#354

@binno @glg-rv

@aswaterman
Copy link
Collaborator

@binno @arrv-sc @chihminchao can y'all lend a hand reviewing this large but useful PR?

Copy link
Collaborator

@arromanoff arromanoff left a comment

Choose a reason for hiding this comment

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

I would appreciate if someone else would also take a look at this. As I am not very familiar with APLIC

Comment on lines +119 to +120
if (!eiid || it == procs.end())
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be an internal error/assert instead of a NOP?

val = target[idx];
}

memcpy(bytes, (uint8_t *)&val, len);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] uint8_t * cast inside memcpy is unnecessary as both source and destination accept void * and any pointer implicitly casts to void *

sourcecfg[idx] = val;
}
} else if (addr >= SETIP_BASE && addr < SETIPNUM) {
auto idx = (addr - SETIP_BASE) / 4;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This 4 keeps appearing throughout this function. Can we name it somehow? constexpr variable or define would be nice.

Comment on lines +208 to +214
if (proc->extension_enabled_const(EXT_SSAIA)) {
add_hypervisor_csr(CSR_HGEIE, hgeie = std::make_shared<hgeie_csr_t>(proc, CSR_HGEIE, proc->geilen));
add_hypervisor_csr(CSR_HGEIP, hgeip = std::make_shared<hgeip_csr_t>(proc, CSR_HGEIP));
} else {
add_hypervisor_csr(CSR_HGEIE, std::make_shared<const_csr_t>(proc, CSR_HGEIE, 0));
add_hypervisor_csr(CSR_HGEIP, std::make_shared<const_csr_t>(proc, CSR_HGEIP, 0));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Why don't we set hgeie/hgeip members under else branch?

typedef std::shared_ptr<imsic_file_t> imsic_file_t_p;
class topei_csr_t: public csr_t {
public:
topei_csr_t(processor_t* const proc, const reg_t addr, imsic_file_t_p const imsic);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit][here and around] I am not a fan of moving trivial constructors to the .cc files. It does not reduce number of dependencies but negatively affects readability and prevents this function from being inlined. I don't think it's critical, however, as we already do that a lot.

uint32_t deleg_mask[APLIC_MAX_DEVICES / 32];

bool interrupt_enabled(uint32_t id);
bool accessible(uint32_t id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
bool accessible(uint32_t id);
bool accessible(uint32_t id) const;

// deleg_mask can be directly applied to other packed registers
uint32_t deleg_mask[APLIC_MAX_DEVICES / 32];

bool interrupt_enabled(uint32_t id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
bool interrupt_enabled(uint32_t id);
bool interrupt_enabled(uint32_t id) const;

const fdt32_t *p;
int val;

for (int i = 0; i < 2; i++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does this 2 represent? It is hard to read/maintain this code without knowing every part of APLIC spec. Please add a constexpr variable/define. Such constants deserve to be named.

m = std::make_shared<imsic_file_t>(proc, MIP_MEIP, IMSIC_M_FILE_REGS);
if (proc->extension_enabled_const(EXT_SSAIA)) {
s = std::make_shared<imsic_file_t>(proc, MIP_SEIP, IMSIC_S_FILE_REGS);
assert(geilen <= 63);
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nitpick] This would be much more readable:

Suggested change
assert(geilen <= 63);
assert(geilen < 64);

Comment on lines +304 to +307
if (dynamic_cast<aplic_m_t*>(&*dev_ptr)) {
assert(!aplic_m);
aplic_m = std::static_pointer_cast<aplic_m_t>(dev_ptr);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (dynamic_cast<aplic_m_t*>(&*dev_ptr)) {
assert(!aplic_m);
aplic_m = std::static_pointer_cast<aplic_m_t>(dev_ptr);
}
if (auto *aplic_m_new = dynamic_cast<aplic_m_t*>(&*dev_ptr)) {
assert(!aplic_m);
aplic_m = aplic_m_new;
}

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.

3 participants