Page MenuHomeFreeBSD

x86: tsc: more resilient cpuid parsing
AcceptedPublic

Authored by kevans on Mon, Jan 6, 4:42 AM.

Details

Reviewers
jkim
kib
markj
imp
Summary

It seems unlikely, but we might as well defend against garbage in the
lower bytes -- better to return false more directly than to act on
elements outside of the brand array.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 61532
Build 58416: arc lint + arc unit

Event Timeline

kevans requested review of this revision.Mon, Jan 6, 4:42 AM

Why 5, but regardless of why, this is correct

This revision is now accepted and ready to land.Mon, Jan 6, 4:46 AM
In D48331#1102183, @imp wrote:

Why 5, but regardless of why, this is correct

A bit further down there's an assignment p -= 5.

In D48331#1102183, @imp wrote:

Why 5, but regardless of why, this is correct

A bit further down there's an assignment p -= 5.

Yeah, I was trying to explain this with the comment. and don't seem to have quite worded it well enough.. we expect four digits + (M, G, or T) before we see 'Hz', so logically it makes sense to start the search there since we won't be able to parse a valid frequency in-bounds before that.

sys/x86/x86/tsc.c
217
220

The mention of "potential garbage" perhaps distracts from the explanation of where 5 comes from. Maybe explain that in a separate paragraph? What kind of garbage might come up?

In D48331#1102183, @imp wrote:

Why 5, but regardless of why, this is correct

A bit further down there's an assignment p -= 5.

Where does that 5 come from was my real question. What spec says we know this format

In D48331#1102324, @imp wrote:
In D48331#1102183, @imp wrote:

Why 5, but regardless of why, this is correct

A bit further down there's an assignment p -= 5.

Where does that 5 come from was my real question. What spec says we know this format

In the document referenced earlier: http://www.intel.com/assets/pdf/appnote/241618.pdf -- figure 3-10

Drop the garbage reference entirely, expand on the description to note the
figure used. Also note some possible future work to rewrite the later part of
this to more closely follow the algorithm described, as they don't seem to want
to commit to D.DD[MGT]Hz or DDDD[MGT]Hz -- they specifically recommend scanning
for a prior space. This would also offer us an opportunity to validate that
all of the involved digits are actually [0-9] or '.'.

This revision now requires review to proceed.Tue, Jan 7, 2:19 AM
This revision is now accepted and ready to land.Tue, Jan 7, 2:39 PM

Note that appnote is deprecated. Intel incorporated its content into SDM and always references CPUID description in SDM now.

Also when doing 'hard' references like page numbers/picture numbers, please specify the document revision.