From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.120]) by mx.groups.io with SMTP id smtpd.web10.23644.1594148941623519251 for ; Tue, 07 Jul 2020 12:09:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HmSyOHL/; spf=pass (domain: redhat.com, ip: 207.211.31.120, mailfrom: lersek@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594148940; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5T2PwJDqm8BAm0GhqSrTfFmYLHwrCXHVSygZsYgF3eE=; b=HmSyOHL/X+xKpdr7wlSDJ4rEOGHBCBB57CsrE725yZxv5LJenFZL2OuC59MOksnVni9tT9 MRLSWp0jkXw13R63n6cpL9smljbqyWMf0laAIYTaersh1nA1EUQ7udHrjEP19n8v+Hx529 O65VNmDq63i5UCT+2NjHa6YAdUyT6d8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-433-By5Ud720Oxe6HemzTuN5Qg-1; Tue, 07 Jul 2020 15:08:54 -0400 X-MC-Unique: By5Ud720Oxe6HemzTuN5Qg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9BFE10059B4; Tue, 7 Jul 2020 19:08:53 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-90.ams2.redhat.com [10.36.114.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B5DA5C1D0; Tue, 7 Jul 2020 19:08:52 +0000 (UTC) Subject: Re: [edk2-devel] Question about the OVMF and MTRRs? To: devel@edk2.groups.io, afish@apple.com References: <369C9B43-A02C-4AEB-8F02-735E1042ABB2@apple.com> From: "Laszlo Ersek" Message-ID: <236d9a8e-7c7c-90a5-ca79-849ba6e7f4fb@redhat.com> Date: Tue, 7 Jul 2020 21:08:52 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <369C9B43-A02C-4AEB-8F02-735E1042ABB2@apple.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi Andrew, On 07/03/20 19:22, Andrew Fish via groups.io wrote: > I noticed for my version of QEMU that MTRR registers are not supported. Is that expected? Or is it something if you get wrong it does not break in QEMU? > > Due to no MTRR support the CPU Protocol SetMemoeryAttributes() call is falling [1] and non of the GCD ranges have EFI_MEMORY_UC Attribute. > > I’m not sure but I think the no MTRR case should attempt to set the attributes via page tables via: > > return AssignMemoryPageAttributes (NULL, BaseAddress, Length, MemoryAttributes, NULL); > > Vs > > return EFI_UNSUPPORTED; > > [1] https://github.com/tianocore/edk2/blob/master/UefiCpuPkg/CpuDxe/CpuDxe.c#L429 sorry, reaching this email only now. I wouldn't really expect IsMtrrSupported() to return FALSE. BOOLEAN EFIAPI IsMtrrSupported ( VOID ) { CPUID_VERSION_INFO_EDX Edx; MSR_IA32_MTRRCAP_REGISTER MtrrCap; // // Check CPUID(1).EDX[12] for MTRR capability // AsmCpuid (CPUID_VERSION_INFO, NULL, NULL, NULL, &Edx.Uint32); if (Edx.Bits.MTRR == 0) { return FALSE; } // // Check number of variable MTRRs and fixed MTRRs existence. // If number of variable MTRRs is zero, or fixed MTRRs do not // exist, return false. // MtrrCap.Uint64 = AsmReadMsr64 (MSR_IA32_MTRRCAP); if ((MtrrCap.Bits.VCNT == 0) || (MtrrCap.Bits.FIX == 0)) { return FALSE; } return TRUE; } In QEMU, the rdmsr is handled in "target/i386/misc_helper.c", function helper_rdmsr(): case MSR_MTRRcap: if (env->features[FEAT_1_EDX] & CPUID_MTRR) { val = MSR_MTRRcap_VCNT | MSR_MTRRcap_FIXRANGE_SUPPORT | MSR_MTRRcap_WC_SUPPORTED; } else { /* XXX: exception? */ val = 0; } break; thus the second "FALSE" branch in IsMtrrSupported() can never be reached. (Either the first "FALSE" branch is taken, or the "TRUE" branch is taken.) MSR_MTRRcap_VCNT is 8. Regarding the first "FALSE" branch, whether that is taken depends on the QEMU CPU model (or the QEMU command line). Check "target/i386/cpu.c" for "CPUID_MTRR". Unfortunately I can't think of an easy way to list the CPU models that do *not* have CPUID_MTRR. What is your CPU model? Thanks Laszlo