git: 9front

Download patch

ref: 4af50fee6567842abb2bc91607b9fd74583337ac
parent: a9105c84d1134fcf47d1fe05b7bdeb62192a3538
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Dec 11 10:21:44 EST 2020

pc, pc64: ignore MTRR's when MTRRCap.vcnt and MTRRCap.fix are zero

Bhyve returns 0 in MTRRCap register, so we
can use that instead on relying on cpuid only
to see if MTRR's are supported.

That way we can get rid of the sanity check
in memory.c.

--- a/sys/src/9/pc/memory.c
+++ b/sys/src/9/pc/memory.c
@@ -383,16 +383,8 @@
 		}
 	}
 
-	/*
-	 * Make sure RAM is set to writeback,
-	 * but do a sanity check first checking
-	 * that the kernel text is writeback.
-	 * This is needed as some emulators (bhyve)
-	 * set everything to uncached.
-	 */
-	s = mtrrattr(PADDR(KTZERO), nil);
-	if(s != nil && strcmp(s, "wb") == 0)
-		mtrrexclude(MemRAM, "wb");
+	/* RAM needs to be writeback */
+	mtrrexclude(MemRAM, "wb");
 
 	for(base = memmapnext(-1, MemRAM); base != -1; base = memmapnext(base, MemRAM)){
 		size = memmapsize(base, BY2PG) & ~(BY2PG-1);
--- a/sys/src/9/pc/mtrr.c
+++ b/sys/src/9/pc/mtrr.c
@@ -305,12 +305,14 @@
 	vlong v;
 	int i;
 
-	s->mask = physmask();
+	if(rdmsr(MTRRCap, &s->cap) < 0)
+		return -1;
 
+	if((s->cap & (Capfix|Capvcnt)) == 0)
+		return -1;
+
 	if(rdmsr(MTRRDefaultType, &s->def) < 0)
 		return -1;
-	if(rdmsr(MTRRCap, &s->cap) < 0)
-		return -1;
 
 	if(s->cap & Capfix){
 		for(i = 0; i < nelem(fixreg); i++){
@@ -331,6 +333,8 @@
 		if(rdmsr(MTRRPhysMask0 + 2*i, &s->varreg[i].mask) < 0)
 			return -1;
 	}
+
+	s->mask = physmask();
 
 	if(strcmp(m->cpuidid, "AuthenticAMD") != 0
 	|| m->cpuidfamily < 15
--