Re: sparc64: normalize prom mappings

2023-01-07 Thread Ted Bullock
On 2023-01-05 12:59 p.m., Miod Vallat wrote:
> tl;dr: if you have a sparc64 machine, please try this diff and report if
>your system no longer works with it.

Tried it on a sunblade 100; machine still boots.

-- 
Ted Bullock 



sparc64: normalize prom mappings

2023-01-05 Thread Miod Vallat
tl;dr: if you have a sparc64 machine, please try this diff and report if
   your system no longer works with it.



On sparc64, the kernel keeps the existing OpenFirmware memory mappings
into the kernel pmap, so as to be able to use ofw routines and walk the
device tree.

However, these translation table entries have a few, software-defined,
bits, which matter to the OpenBSD kernel and may or may not matter to
the PROM.

Recent experiments have shown that, on at least one sparc64 system,
one of these software bits is set in the translations inherited from
OpenFirmware, and this could be misleading.

A quick examination of property dumps (eeprom -p, "translations"
property) collected from various sparc64 systems shows that apparently
most, if not all, systems with UltraSPARC I/II/IIi/IIe processors have
TTE values with unwanted bits set.

The following diff normalizes these values by clearing all
software-defined bits, when adding them to the kernel pmap. It needs to
be tested on as many systems as possible - if they still boot multiuser,
and can reboot without problems, then everything's fine. I'd like to
hear about systems no longer working correctly with this diff, should
there be any.

Miod

Index: sys/arch/sparc64/sparc64/pmap.c
===
RCS file: /OpenBSD/src/sys/arch/sparc64/sparc64/pmap.c,v
retrieving revision 1.106
diff -u -p -r1.106 pmap.c
--- sys/arch/sparc64/sparc64/pmap.c 10 Sep 2022 20:35:29 -  1.106
+++ sys/arch/sparc64/sparc64/pmap.c 5 Jan 2023 19:48:09 -
@@ -1074,6 +1074,7 @@ remap_data:
if (prom_map[i].vstart && ((prom_map[i].vstart>>32) == 0)) {
for (j = 0; j < prom_map[i].vsize; j += NBPG) {
int k;
+   uint64_t tte;

for (k = 0; page_size_map[k].mask; k++) {
if (((prom_map[i].vstart |
@@ -1084,9 +1085,14 @@ remap_data:
break;
}
/* Enter PROM map into pmap_kernel() */
+   tte = prom_map[i].tte;
+   if (CPU_ISSUN4V)
+   tte &= ~SUN4V_TLB_SOFT_MASK;
+   else
+   tte &= ~(SUN4U_TLB_SOFT2_MASK |
+   SUN4U_TLB_SOFT_MASK);
pmap_enter_kpage(prom_map[i].vstart + j,
-   (prom_map[i].tte + j)|data|
-   page_size_map[k].code);
+   (tte + j) | data | page_size_map[k].code);
}
}
}