Saturday, February 2, 2013

32 versus 64 bit and measuring UEFI Secure Boot

This blog begins with a discussion of the execution mode of the pre-operating system (OS) and the operating system run time (RT).   This is a question that comes up often, so I wanted to given some overview and history.

32v64 - The OS view of the world
We'll being with the OS-visible portion of the pre-OS, or the UEFI boot services (BS) environment.  For today's 64-bit (aka x64) operating systems, you need a 64-bit kernel to be booted from 64-bit UEFI firmware.  Or BS and RT execution modes need to match the kernel execution mode.  Similarly, a 32-bit OS kernel needs a 32-bit RT and 32-bit BS.  For example, x64 (aka x86-64, EM64T, AMD64, Intel64....) Ubuntu or Windows8 need to have x64 UEFI.

On this point UEFI differs from 16-bit PC/AT BIOS where you can boot 16, 32 or 64-bit kernels.  In 1982, BIOS was 16-bit, as was Microsoft DOS.  The I/O subsystem of DOS was the BIOS, so the DOS run time calling into the 16-bit BIOS int-calls worked out well.   DOS was single-threaded, BIOS calls are blocking, and everyone was happy.  This worked through Windows3.1 where DOS was still effectively the kernel.  The tension in this model appeared with 32-bit OS's where the kernel would 'thunk' or make down-calls into BIOS when necessary, alongside the 32-bit native driver model with VxD's.   With NT and beyond, though, the kernel would have native drivers such that the BIOS was only used for booting.  Same story for Linux with its pure native drivers.

And on the point of booting, the first stage OS loader would typically stay in 16-bit mode in order to read the kernel from disk or network using 16-bit BIOS calls.  Then the kernel would trampoline into 32-bit mode in order to run the native OS kernel.  When x64 came on the scene in the mid-2000's, this trampoline process was extended to go from 16-to-32-to-64 bit mode.   

The notable point on PC/AT BIOS and OS run times today is that modern OS kernels do not invoke 16-bit services after the initial loader.   This is distinct from EFI/UEFI with its 'runtime' (RT) services which are by-design intended for OS kernel invocation.

Specifically, UEFI, on the other hand, took a different path.  The original EFI 1.02 specification in 1999 had an IA32 (aka x86) binding that was 32-bit only.  EFI antedated the relase of x64.  EFI1.02 continued having only the IA32 binding.  When x64 became public, it was still prior to 2006 and the standardization of EFI as UEFI.  Intel owned the EFI specification at the time and pondered how to address support of x64.  One side of the EFI house advocated today's behavior where the firmware Instruction Set Architecture (ISA) mode == kernel ISA mode, whereas a smaller group was in the camp of a modal solution.  

Enter the '2-headed firmware.'   The idea of the firmware having two modes or 'heads' was to forever keep EFI as 32-bit and having the ability for a 32-bit or 64-bit set of run time services to be published from the firmware for the kernel (32 or 64) to call.'  

The requirement for the kernel to match the firmware begins with the ISA mode of the EFI RT.  To support run time services, the kernel maps the EFI run time and directly calls into it from ring 0.  Since the EFI run time is defined to be the same as the EFI boot services in the EFI system table, RT and BS must be the same.  This leads to the model where if you want to boot a 64-bit OS, you need 64-bit firmware.   Modern OS eschew 'thunking' or down-calling into 32-bit mode from a 64-bit kernel, unlike the practice of doing this from user mode (e.g., WOW64 in Windows and capability binary support in Linux).

So back to the 2-headed BIOS versus the pure 64-bit firmware.  Both solutions were built, but it was quite tricky to implement the 64-bit RT.  We ended up with building a shim that invoked an SMI so that the bulk of code shared between 64-bit and 32-bit RT was handled by the Framework SMM DXE code (i.e., SMM driver model prior to the UEFI PI).  The 64-bit EFI was cleaner since the mode of EFI is also the mode of DXE, our EFI core.  And with the UEFI 2.0 specification in 2006, the 64-bit work was contributed and became one of the central features of the industry-owned specification.

For a refresher on UEFI versus PI, check out Beyond BIOS http://www.amazon.com/Beyond-BIOS-Developing-Extensible-Interface/dp/1934053295/ or chapter 3 of Hardware Dependent Software http://www.amazon.com/Hardware-dependent-Software-Principles-Wolfgang-Ecker/dp/9048181283/.

After all of the that, you can see why ACPI and its static tables and interpreted AML byte-codes are the preferred run time interface to the platform for PC/AT BIOS and UEFI systems today.  The co-location of the UEFI RT with the kernel in ring 0 and some of the vagaries listed above in implementation argue for not growing the corpus of UEFI RT capabilities.

32v64 - The platform construction view of the world
You will note above some discussion of DXE along with the EFI ISA mode work.  Just as the UEFI RT dictates the UEFI BS mode of operation, the UEFI BS mode dictates the Driver Execution Environment (DXE) mode of operation since the Framework and UEFI Platform Initialization (PI) DXE forms the core of the EFI and UEFI interface sets, respectively.   The same holds true for Framework and PI SMM in the DXE is the SMM loader, so the ISA mode of DXE boot service-time became the mode of the SMM DXE.   Once the die was cast for 64-bits, almost everything in the pre-OS became 64-bit.

"Almost everything" was the case because there are a couple of modes of operation prior to DXE, namely the SEC and PEI phases.  These two phases commence after a processor reset.  Even with the advent of x64, Intel Architecture CPU's still commence operation in 16-bit mode.  As such, the SEC phase mode switches to the PEI mode of operation.  PEI can execute in 32-bit or 64-bit mode.  Some of the complexities of 64-bit long mode entail larger binaries and having to run with paging enabled.  These can be covered by budgeting for the flash space for larger code images and setting up ROM'd page tables with the AD bits pre-set so that page fault walkers don't panic trying to update read-only PTE's.  The advantages of having the ISA mode of PEI and DXE match also include having codes from PEI that can be passed into DXE and re-used, such as the PE/COFF loader and the report status code logic.  The latter is especially important in that prior to loading the DXE architectural protocols, a HOB proxied report status code pointer can be used to update the boot progress during the grey period between PEI hand-off and DXE start up.  32-bit mode, on the other hand, can run in physical mode without paging.  Since such PEI execute in place (XIP) codes rarely need greater than 32-bit addressing and need to be penurious on code size and data usage because of cache-as-RAM size limitations, today PEI implementations are typically 32-bit and the final PEI, or the DXE IPL PEIM, will mode switch to 64-bit as part of invoking DXE Main.

So in summary, the ISA mode of the firmware and the OS kernel is not so simple of a story, and the story is again distinct from the ISA mode of the early PI phases of execution.

So enough on 32-bit and 64-bit.   

Note (3/4/14):  Matt Fleming has an experimental patch treating booting a 64-bit Linux kernel on a 32-bit UEFI platform https://lkml.org/lkml/2014/3/4/242 

UEFI Secure Boot - Measuring Policy
The other thing I wanted to mention was a recent publication on MSDN, namely the Trusted Execution Environment (TrEE)  EFI Protocol and measurement updates, which can be found at http://msdn.microsoft.com/en-us/library/windows/hardware/jj923068.aspx.  This publication is important because the language toward the end around PCR[7] logging of the UEFI 2.3.1c PK, KEK, and DB/DBX addresses one of the architectural gaps of scenarios that employ both measured and secure boot.  Recall that the paper "UEFI Networking and Pre-OS Security" at https://noggin.intel.com/content/uefi-networking-and-pre-os-security-0  describes the relationship of measured and secure boot.  Specifically, on page 94 of the same, "...Measured Boot must include the Allowed, Forbidden, KEK, and PK variables (databases) in its measurements of a Secure Boot-configured platform."  As a result, the measurement language in the TrEE protocol provides a solution for recording the state of the UEFI Secure Boot enforcement policy.   

Tuesday, January 8, 2013

Leveraging UEFI Secure Boot beyond the loader

I've earlier noted some of the exciting work that the community has been doing with platforms around Microsoft(R) Windows8, including UEFI Secure Boot.  Some details are at http://channel9.msdn.com/Events/Windows-Ecosystem-Summit/2011Taipei/SYS-457T, for example.

In addition to the Windows roll-out, Brian Richardson noted the work of Peter Jones of the Fedora Project around "Package Signature Checking During Installation" @ http://fedoraproject.org/wiki/Features/PackageSignatureCheckingDuringInstall.  This work extends UEFI Secure Boot into the OS provisioning. Details include "Following the implementation of Features/SecureBoot, we can extend the Secure Boot keys as a root of trust provided by the hardware against which we can verify a signature on our key files, thus guaranteeing that they're from the same source as the boot media".  

This Fedora work, alongside the Microsoft release, further reinforces the tenet that boot firmware is by design OS-neutral. The plurality of hardware specifications like PCI & USB, firmware-oriented specifications like SMBIOS, UEFI, and ACPI, and finally, implementations like edk2, help to form the bridge between platforms and OS usages.

On a personal note, Peter is a great guy and continues to make valuable contributions into the OS usage of UEFI. This includes some of his work on multiple signatures we mentioned in chapter 4 of http://iweb.dl.sourceforge.net/project/edk2/General%20Documentation/A_Tour_Beyond_BIOS_into_UEFI_Secure_Boot_White_Paper.pdf, too.

The Fedora usages, along with efforts like Matt Flemming & Co. on UEFI loader development https://github.com/mfleming/efilinux, continue to strengthen open source infrastructure for these emergent UEFI platform firmware capabilities.

Thursday, January 3, 2013

A new year, a new blog entry and a couple of white papers

It looks like the Mayan predictions for the end of the world didn't come to pass, although the jury is still out on the Fiscal Cliff correlative of the Mayan-predicted apocalypse. 

That being said, I wanted to highlight a couple of white papers. The first white paper is "Open Platforms and the impacts of security technologies, initiatives, and deployment practices," a joint Cisco and Intel white paper.   Bill Jacobs, my Cisco co-author, and I came up with idea for this paper when we met at the September 2012 Intel Developer Forum. After discussing the large set of security technologies in the industry, we agreed on the need for some higher level review of a subset of these technologies and how they were related. Thus was born the white paper which can be found on the sharing page of http://uefidk.com/share, namely

The next white paper was posted in the last twenty-four hours.  This paper was written with my Intel colleague Palsamy Sakthikumar.  The paper "A Tour beyond BIOS Implementing the ACPI Platform Error Interface with the Unified Extensible Firmware" can be found on the same website at the location http://uefidk.com/sites/default/files/resources/A_Tour_beyond_BIOS_Implementing_APEI_with_UEFI_White_Paper.pdf. The paper demonstrates the usage of firmware standards like UEFI and ACPI to deploy a significant platform capability for the enterprise. Palsamy and I talked about creating the paper for a couple of years so I am happy to see it finally come to fruition.

Regrettably, today is Palsamy's last day at Intel. I wish him the best in his travels.


Tuesday, December 18, 2012

Accessing UEFI from the operating system runtime


Sometimes the question arises about accessing UEFI services during the operating system runtime.   Recall that UEFI demarcates its core services into boot services and runtime services.   The former are only available prior to the invocation of ExitBootServices(), whereas the latter are available during the life of the platform for a UEFI-aware operating system.   This is the design intent.   Other boot services components can expose content during runtime if said content is allocated in runtime services memory and exposes itself through infrastructure like an installable GUIDed table.

In practice today, these services are not necessarily exposed 1:1 between an operating system services and the corresponding UEFI runtime service.

For Windows, the only API that I know of for accessing UEFI entail the UEFI variable services.   Check out Get/Set firmware environment variables services http://msdn.microsoft.com/en-us/library/windows/desktop/ms724934(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/ms724325(v=vs.85).aspx, respectively.

Linux provides access to the UEFI variable services through sysfs, too.  Some detail can be found at 

Beyond variables, though, UEFI interfaces are opaque at OS runtime for Windows.   For Linux the UEFI system table is a kernel global object for Linux drivers.

The net result is that you cannot get to the UEFI RT or the system table at OS runtime, I'm afraid.   The Linux sysfs is the closest but even there it doesn't expose each UEFI RT call point.  The reason that the UEFI variable services are exposed in the fashion they are via Win32 calls is that OS installer programs have needed them since EFI1.02 back in 1999.   Writing UEFI RT code is pretty tricky because of things like the OS owning the hardware, the virtual mapping of the firmware, etc.(i.e., tough for firmware folks).  Also, the OS guys don't necessarily trust firmware and the UEFI RT code/data isn't hardware isolated from the other OS kernel components and drivers.

As such, the preferred industry approach to having a runtime interface to the platform is ACPI since ACPI runs in a sandbox with an interpreted bytecode AML.  There is some interesting open source implementations of ACPI at http://www.acpica.org/, for example.   UEFI is great for pre-OS applications and usages, of course.  And one model observed today is to stage activities from the OS, such as writing a file to the UEFI system partition, and then rebooting so that an associated UEFI application can act upon the file or directive from the OS agent.

Of course, UEFI runtime services are always available in the pre-OS, namely during the boot services (BS) phase.

3/10/14 update-
Windows now has kernel-mode variants of its access API's http://msdn.microsoft.com/en-us/library/windows/hardware/jj151553(v=vs.85).aspx and there is a nice description of variable access from Linux at firmware.intel.com/blog/accessing-uefi-variables-linux

5/22/14 update-
Regarding the protection of the platform resources by the OS, you need to have administrative privileges in Windows and Linux in order to access the OS API's that abstract the UEFI variable interface from user-land code.

11/5/14 update -
if you boot via Int19h PC/AT BIOS process, the UEFI runtime memory is given back to the OS and is reported as available via the memory map call in E820h Int15h call. As such, there is no way to invoke Get/Set Variable from a PC/AT "Legacy" BIOS boot.

Tuesday, December 4, 2012

Errata, PI1.2.1a and all that

Recall that the UEFI Forum (www.uefi.org) governs several specifications.   The first is the main UEFI specification which serves as the contract between the platform firmware and several pre-OS components.  The latter components include pre-OS applications, drivers, OS runtimes.   The other specification under the aegis of the UEFI Forum is the platform initialization, or "PI" specifications.   These five volumes describe interoperability between components that comprise the construction of the platform firmware, including the Pre-EFI Initiation (PEI) phase and the Driver Execution Environment (DXE).   For both the UEFI and PI specifications, major specification releases entail updates to functionality and capabilities.  A fortiori, such changes entail updates to the version fields in the various services tables, such as the UEFI System Table for UEFI and the PEI, DXE, and SMM services tables for PI, respectively.   These service table revisions allow for software to detect the variant of a given platform firmware in case a certain service has evolved modal behavior or to ascertain if a certain capability exists.

With all that in mind, evolution of the UEFI and PI specifications can also occur via the errata process.  If you think of the major specification updates to be a forward direction evolving process, the errata process is more lateral in that it clarifies issues within a given set of specifications without introducing interoperability issues.   This interop issue is important in that there is no software discernible difference between various implementations of errata for a given UEFI or PI major version, so such changes cannot be probed by software via the version number conceit listed earlier.

Finally we get to the point of this blog posting and the PI 1.2.1a specification.   The 'a' suffix means that this revision of the specification consists of the first errata against the PI 1.2.1a specification.   Recall that the PI 1.2.1 specification was released on May 2, 2012.   The PI 1.2.1a specification, in turn, was released on October 26, 2012.   This five month cadence is not unreasonable, with the most frequent errata cycle being once per quarter if there are sufficient bugs to address.

For PI 1.2.1a specification, the errata includes the following:

- Adding a 'boot with manufacturing mode'
- Addition of a simple signed firmware volume and file
- Clarification of memory usage across the S3 boot path
- Root handler processing clarification in SMI

and other clean-up.

The creation of errata allow for consistency in the software definitions.  This, along with conformant implementations of the UEFI and PI specifications at http://sourceforge.net/apps/mediawiki/tianocore/index.php?title=EDK2, provides an evolution of the platform firmware between the addition of new features and capabilities in major specification revision updates.

Tuesday, October 23, 2012

250


This Tuesday I received my 250th US Patent.   

Vincent Zimmer, Scott H. Robinson, “Methods and Systems for Microcode Patching,”, Issued 10/23/2012, US Patent #8,296,528

Hat's off to Scott.  Like all of my IP adventures, I enjoy the human, collaborative aspect most of all with my co-inventors.  And what a list of co-inventors, from recent-college graduates to Intel Senior Fellows, from North America to the near East and the far East.  

I won't opine on the alternate perspectives regarding the need or value of patents promulgated by the various voices spanning the meat space to cyberspace.   To me patents are a business fact in the modern, knowledge-driven economy of the 21st century, and I am a small cog in this economy.   

When confronted by patents, like other phenomena in life, I first try to understand the item prior to making a value judgement.  As such, putting intellectual property law in a historical perspective provides one vantage for achieving additional insight. And to that end, I'm 1/3 of the way through Robert Merges Justifying Intellectual Property http://www.amazon.com/Justifying-Intellectual-Property-Robert-Merges/dp/0674049489/ref=sr_1_1?ie=UTF8&qid=1351049499&sr=8-1&keywords=robert+merges.   I'm in the thick of the Kantian versus Lockean view of property rights, but I am finding it increasingly difficult to find the time and focus to wade through the tome.  

So how to make sense of the morass of patents.  For international patents, Espanet and the query 
provides a compendium of my activities in the US and overseas.  I find it difficult to wade through the results given the amount of output and the query options.

The calculus is a bit easier in the United States, with the US Patent and Trademark Office (USPTO) having a couple of useful interfaces for applications that were published at least 18 months ago http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.html&r=0&p=1&f=S&l=50&Query=in%2F%22Zimmer%2C+Vincent%22&d=PG01 and issued cases http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&Sect2=HITOFF&u=%2Fnetahtml%2FPTO%2Fsearch-adv.htm&r=0&p=1&f=S&l=50&Query=in%2F%22Zimmer%2C+Vincent%22&d=PTXT.

Luckily the name "Vincent Zimmer" is unique enough in the patent realm to allow direct hits on the USPTO queries.  This is especially important since a few cases omit the assignee company and other data that would allow for a more specific query string.

So how does this activity relate to the rest of the US patent-filing population?

According to Michael Orlando, an economist for the Federal Reserve Bank of Kansas City“40 patents per year are developed within a population of 200,000. In 2006, the patent office received 443,652 patent applications, but only 183,187 were issued that year.”

From Orlando's figures, one can see a 183,187/443,652 or 41% approval rate.


From the queries above to the USPTO, I'm at 251 issued and 453 abandoned, issued or active cases.  This gives a rough metric of 251 / 453 = 55% approval rate, which is slightly better than the 2006 average of 41%.   Given the number of cases in play on my list, including cases in that 18 month window of filed but not public, this isn't an exact number.  But it's probably in the neighborhood of where the metric will converge over time.

The size of the applications can range from eight to 20+ pages.  Assuming an average size of 10 pp., that makes 4500 pages of application data alone.  What a formidable number for my troubled memory.  

The law is definitely fluid. This month there was an interesting update on IP law and what it means for technologists.  You can find the slides for the Tuesday Oct 16,2012 IEEE Seattle Communications Chapter presentation "Evolving Standards of Patent Eligible Subject Matter" at https://skydrive.live.com/?cid=b47e69a64974ad21&id=B47E69A64974AD21%21123#cid=B47E69A64974AD21&id=B47E69A64974AD21%21168

Seattle definitely has more public technical talks than the South Puget Sound area.   The day after the IP talk, the same venue, namely the Bellevue Court House, hosted the October Seattle Meet-up on Cloud Computing.  I was the third speaker, after the Citrix and Microsoft talk.  As you can read from http://joewlarson.com/blog/2012/10/20/cases-of-network-tech-stf/  this eastside crowd was a bit higher in the software stack than I'm used to dealing.  The blogger captured my angst, with the associated Rodney Dangerfield foil 4 https://docs.google.com/file/d/0BxgB4JDywk3McWhfX0ZlSk03bkE/edit with his observation "Zimmer explained that the BIOS had an awkward place in technology, because hardware guys tend to think of BIOS as software, and software guys think of it as hardware."   

As such, I sometimes wonder if the complaints over software patents even apply to my vocation in the land of firmware.

Going forward.   

I'm getting old.   I filed my first patent at 20 when I was an intern at Texaco.   I never followed up on the office action and USPTO application records are not available prior to 2001, so this item is lost in the sands of time.   My IP activity picked up in the late 90's, with the following run of issued US cases:

1999 - 1
2002 - 1
2003 - 1
2004 - 2
2005 - 2
2006 - 22
2007 - 46
2008 - 40
2009 - 36
2010 - 44
2011 - 34
2012 - 22

This is less interesting since the latency from filing to issue can span from four to nearly ten years.  The more interesting data is number of filings per year.

To that end, the application publications per year have progressed as follows:

2002 - 4
2003 - 6
2004 - 60
2005 - 86
2006 - 63
2007 - 55
2008 - 57
2009 - 59
2010 - 21
2011 - 20
2012 - 22

Definitely not Gaussian.  More of a long-tail Pareto style distribution.   

Well, enough on this topic.  250 is a strange number.  Not sure if I'll reach 300, more less a 4-digit number.  Nevertheless, it has been an interesting run.

I'll close with a quotation from Ralph Waldo Emerson, “Life is a journey, not a destination.” 

Sunday, October 7, 2012

Did a book inspire your choice of a profession?

At the last Intel Developer Forum in San Francisco, Intel's futurist David Brian Johnson talked about the Tomorrow Projects http://www.tomorrow-projects.com/.  I downloaded one of the related texts from David's works, namely Science Fiction Prototyping.  The book talks about Science Fiction and how it contributes the the "future casting" efforts.  The quote that I took away from the book that inspired this blog entry, though, was how many of the pioneers in aeronautics were inspired by the science fiction of Jules Verne.  For me, the book that inspired my pursuit into electrical engineering, and then the computing sciences, wasn't from the genre of science fiction so much as science fact.  Specifically, I recall Norbert Wiener's Cybernetics as the text which fused an information theoretic view of the world, including control theory, as an inspiration.
I would be curious whether others had a specific book or author that inspired their professional pursuits.

Starting with a scientific degree doesn't necessarily guarantee a successful engineering career, either.  In fact, one of the best programmers with whom I've had the pleasure to work during my early career didn't even have a degree in computer science or engineering.  Instead, he was an ex-Marine who afterward joined the Trappist order in Gethsemani http://www.monks.org/ for ten years, studying Heidegger's Being and Time while observing the silence and working in the fields. After leaving the order he returned to Houston and picked up a bachelors degree in philosophy.

What does philosophy mean for tech?  Consider the fact that most smart phones of 2012 can hold the equivalent of the Library of Alexandria.  But what do most most people use their devices for? Cat watching, such as http://www.youtube.com/watch?v=jI-kpVh6e1U&feature=relmfu and http://www.lolcats.com/.  Why not download from http://www.gutenberg.org/? As such, studying the philosophy and the meaning of existence doesn't sound like such a bad idea.

Now go back to work and/or read a good book.

PS
From the earlier blogs, here's a quick update.  The SF IDF presentation has an audio link at http://intelstudios.edgesuite.net/idf/2012/sf/aep/EFIS003/EFIS003.html.   And for the http://pdxlinux.org/ talk, the presentation is posted to https://docs.google.com/open?id=0BxgB4JDywk3MbENUTVdqZkZaUmM   and watch the pdx website for the video to be posted.