Skip to content

Commit

Permalink
Merge pull request #271 from ved-rivos/1110
Browse files Browse the repository at this point in the history
Fix return values
  • Loading branch information
ved-rivos authored Nov 10, 2023
2 parents 42c778f + 15f41b0 commit 1ab2219
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions iommu_ref_model/libtables/src/build_ddt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ add_dev_context(
i = LEVELS - 1;
while ( i > 0 ) {
ddte.raw = 0;
read_memory((a + (DDI[i] * 8)), 8, (char *)&ddte.raw);
if ( read_memory((a + (DDI[i] * 8)), 8, (char *)&ddte.raw) ) return -1;
if ( ddte.V == 0 ) {
ddte.V = 1;
ddte.PPN = get_free_ppn(1);
write_memory((char *)&ddte.raw, (a + (DDI[i] * 8)), 8);
if ( write_memory((char *)&ddte.raw, (a + (DDI[i] * 8)), 8) ) return -1;
}
i = i - 1;
a = ddte.PPN * PAGESIZE;
}
write_memory((char *)DC, (a + (DDI[0] * DC_SIZE)), DC_SIZE);
if ( write_memory((char *)DC, (a + (DDI[0] * DC_SIZE)), DC_SIZE) ) return -1;
return (a + (DDI[0] * DC_SIZE));
}
8 changes: 4 additions & 4 deletions iommu_ref_model/libtables/src/build_g_stage_pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ add_g_stage_pte (
a = iohgatp.PPN * PAGESIZE;
while ( i > add_level ) {
nl_gpte.raw = 0;
read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_gpte.raw);
if ( read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_gpte.raw) ) return -1;
if ( nl_gpte.V == 0 ) {
nl_gpte.V = 1;
nl_gpte.PPN = get_free_ppn(1);
write_memory((char *)&nl_gpte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( write_memory((char *)&nl_gpte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
}
i = i - 1;
if ( i < 0 ) return 1;
if ( i < 0 ) return -1;
a = nl_gpte.PPN * PAGESIZE;
}
write_memory((char *)&gpte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( write_memory((char *)&gpte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
return (a | (vpn[i] * PTESIZE));
}
12 changes: 6 additions & 6 deletions iommu_ref_model/libtables/src/build_pdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ add_process_context(
a = DC->fsc.pdtp.PPN * PAGESIZE;
i = LEVELS - 1;
while ( i > 0 ) {
if ( translate_gpa(DC->iohgatp, a, &a) == -1 ) return 1;
if ( translate_gpa(DC->iohgatp, a, &a) == -1 ) return -1;
pdte.raw = 0;
read_memory((a + (PDI[i] * 8)), 8, (char *)&pdte.raw);
if ( read_memory((a + (PDI[i] * 8)), 8, (char *)&pdte.raw) ) return -1;
if ( pdte.V == 0 ) {
pdte.V = 1;
pdte.reserved0 = pdte.reserved1 = 0;
Expand All @@ -47,16 +47,16 @@ add_process_context(
gpte.PBMT = PMA;
gpte.PPN = get_free_ppn(1);

add_g_stage_pte(DC->iohgatp, (PAGESIZE * pdte.PPN), gpte, 0);
if ( add_g_stage_pte(DC->iohgatp, (PAGESIZE * pdte.PPN), gpte, 0) == -1 ) return -1;
} else {
pdte.PPN = get_free_ppn(1);
}
write_memory((char *)&pdte.raw, (a + (PDI[i] * 8)), 8);
if ( write_memory((char *)&pdte.raw, (a + (PDI[i] * 8)), 8) ) return -1;
}
i = i - 1;
a = pdte.PPN * PAGESIZE;
}
if ( translate_gpa(DC->iohgatp, a, &a) == -1 ) return 1;
write_memory((char *)PC, (a + (PDI[0] * 16)), 16);
if ( translate_gpa(DC->iohgatp, a, &a) == -1 ) return -1;
if ( write_memory((char *)PC, (a + (PDI[0] * 16)), 16) ) return -1;
return (a + (PDI[0] * 16));
}
8 changes: 4 additions & 4 deletions iommu_ref_model/libtables/src/build_s_stage_pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ add_s_stage_pte (
a = satp.PPN * PAGESIZE;
while ( i > add_level ) {
nl_pte.raw = 0;
read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_pte.raw);
if ( read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_pte.raw)) return -1;
if ( nl_pte.V == 0 ) {
nl_pte.V = 1;
nl_pte.PPN = get_free_ppn(1);
write_memory((char *)&nl_pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( write_memory((char *)&nl_pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
}
i = i - 1;
if ( i < 0 ) return 1;
if ( i < 0 ) return -1;
a = nl_pte.PPN * PAGESIZE;
}
write_memory((char *)&pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( write_memory((char *)&pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
return (a | (vpn[i] * PTESIZE));
}
12 changes: 6 additions & 6 deletions iommu_ref_model/libtables/src/build_vs_stage_pt.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ add_vs_stage_pte (
i = LEVELS - 1;
a = satp.PPN * PAGESIZE;
while ( i > add_level ) {
if ( translate_gpa(iohgatp, a, &a) == -1) return 1;
if ( translate_gpa(iohgatp, a, &a) == -1) return -1;
nl_pte.raw = 0;
read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_pte.raw);
if ( read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_pte.raw)) return -1;
if ( nl_pte.V == 0 ) {
gpte_t gpte;

Expand All @@ -66,15 +66,15 @@ add_vs_stage_pte (
gpte.PBMT = PMA;
gpte.PPN = get_free_ppn(1);

add_g_stage_pte(iohgatp, (PAGESIZE * nl_pte.PPN), gpte, 0);
if ( add_g_stage_pte(iohgatp, (PAGESIZE * nl_pte.PPN), gpte, 0) == -1) return -1;

write_memory((char *)&nl_pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( write_memory((char *)&nl_pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
}
i = i - 1;
if ( i < 0 ) return 1;
a = nl_pte.PPN * PAGESIZE;
}
if ( translate_gpa(iohgatp, a, &a) == -1) return 1;
write_memory((char *)&pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE);
if ( translate_gpa(iohgatp, a, &a) == -1) return -1;
if ( write_memory((char *)&pte.raw, (a | (vpn[i] * PTESIZE)), PTESIZE) ) return -1;
return (a | (vpn[i] * PTESIZE));
}
8 changes: 4 additions & 4 deletions iommu_ref_model/libtables/src/translate_gpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ translate_gpa (
PTESIZE = 8;
if ( iohgatp.MODE == IOHGATP_Bare ) {
*spa = gpa;
return 0;
return -1;
}
if ( iohgatp.MODE == IOHGATP_Sv32x4 ) {
vpn[0] = get_bits(21, 12, gpa);
Expand Down Expand Up @@ -53,8 +53,8 @@ translate_gpa (
a = iohgatp.PPN * PAGESIZE;
while ( 1 ) {
nl_gpte.raw = 0;
read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_gpte.raw);
if ( nl_gpte.V == 0 ) return 1;
if ( read_memory((a | (vpn[i] * PTESIZE)), PTESIZE, (char *)&nl_gpte.raw) ) return -1;
if ( nl_gpte.V == 0 ) return -1;
if ( nl_gpte.R != 0 || nl_gpte.X != 0 ) {
*spa = nl_gpte.PPN;
*spa = *spa * PAGESIZE;
Expand All @@ -63,7 +63,7 @@ translate_gpa (
return (a | (vpn[i] * PTESIZE));
}
i = i - 1;
if ( i < 0 ) return -11;
if ( i < 0 ) return -1;
gst_page_sz = ( i == 0 ) ? PAGESIZE : (gst_page_sz / 512);
a = nl_gpte.PPN * PAGESIZE;
}
Expand Down
8 changes: 5 additions & 3 deletions iommu_ref_model/test/test_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ main(void) {
fail_if( ( check_rsp_and_faults(&req, &rsp, UNSUPPORTED_REQUEST, 266, 0) < 0 ) );

// Access viol on non-leaf PDTE
translate_gpa(DC.iohgatp, DC.fsc.pdtp.PPN * PAGESIZE, &temp);
fail_if( (translate_gpa(DC.iohgatp, DC.fsc.pdtp.PPN * PAGESIZE, &temp) == -1) );
access_viol_addr = (temp) | (get_bits(19, 17, 0xBABEC) * 8);
send_translation_request(0x112233, 1, 0xBABEC, 0,
0, 1, 0, ADDR_TYPE_UNTRANSLATED, 0xdeadbeef,
Expand Down Expand Up @@ -2117,10 +2117,10 @@ main(void) {
PC.ta.ENS = 1;
PC.ta.SUM = 1;
PC_addr = add_process_context(&DC, &PC, 0xBABEC);
read_memory(PC_addr, 16, (char *)&PC);
fail_if( (read_memory(PC_addr, 16, (char *)&PC) != 0) );

// misconfigured NL PTE
translate_gpa(DC.iohgatp, DC.fsc.pdtp.PPN * PAGESIZE, &temp);
fail_if( (translate_gpa(DC.iohgatp, DC.fsc.pdtp.PPN * PAGESIZE, &temp) == -1) );
temp = (temp) | (get_bits(19, 17, 0xBABEC) * 8);
read_memory(temp, 8, (char *)&pdte);
pdte.reserved0 = 1;
Expand Down Expand Up @@ -2207,6 +2207,7 @@ main(void) {
// guest page fault on PC walk
gpa = (DC.fsc.pdtp.PPN * PAGESIZE) | (get_bits(19, 17, 0xBABEC) * 8);
temp = translate_gpa(DC.iohgatp, gpa, &temp);
fail_if( (temp == -1) );
read_memory(temp, 8, (char *)&gpte);
gpte.V = 0;
write_memory((char *)&gpte, temp, 8);
Expand Down Expand Up @@ -2476,6 +2477,7 @@ main(void) {

// Guest-Page fault on NL S-stage PTE
gpte_addr = translate_gpa(DC.iohgatp, (PC.fsc.iosatp.PPN * PAGESIZE), &temp);
fail_if( (gpte_addr == -1) );
read_memory(gpte_addr, 8, (char *)&gpte);
gpte.V = 0;
write_memory((char *)&gpte.raw, gpte_addr, 8);
Expand Down

0 comments on commit 1ab2219

Please sign in to comment.