Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1328479

Re: [PATCH -v2] x86: Add an archinfo dumper module

From Borislav Petkov <bp@alien8.de>
Newsgroups linux.kernel
Subject Re: [PATCH -v2] x86: Add an archinfo dumper module
Date 2016-02-07 12:00 +0100
Message-ID <qZvep-4UN-5@gated-at.bofh.it> (permalink)
References (2 earlier) <qXFKW-BP-9@gated-at.bofh.it> <qY3ay-Nu-31@gated-at.bofh.it> <qY3tV-19p-37@gated-at.bofh.it> <qYu14-3JT-23@gated-at.bofh.it> <qYxrY-69y-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Oh wow,

I'm back and reading emails and I can see that Tony has had fun parsing
strings for a change!

:-)))

On Thu, Feb 04, 2016 at 11:07:57AM -0800, Luck, Tony wrote:
> On Thu, Feb 04, 2016 at 04:22:35PM +0100, Borislav Petkov wrote:
> > Here's v2 with the stuff we talked about, implemented. I've added
> > 'control_regs' file too so that you can do:
> > 
> > $ cat /sys/kernel/debug/x86/archinfo/control_regs
> > CR4: [-|-|SMEP|OSXSAVE|-|-|-|-|OSXMMEXCPT|OSFXSR|-|PGE|MCE|PAE|PSE|-|-|-|-]: 0x1406f0
> > 
> > for example. Yeah, only CR4 right now.
> > 
> > Off the top of my head, we would need "msrs" which dumps EFER and a
> > bunch of other interesting MSRs along with the names of the set bits.
> 
> It would be nce to have some helper function that makes it easier for
> people to add new registers to this that just uses one string
> to describe the format of a register. E.g. if we have a register
> like this:
> 
> 	 63 63 62  11 10  9 8    5 4   2 1   0
> 	+-----+------+-----+------+-----+-----+
> 	| VAL | rsvd | BAZ | rsvd | BAR | FOO |
> 	+-----+------+-----+------+-----+-----+
> 
> 	BAZ bits mean:
> 		00 - nope
> 		01 - low
> 		10 - mid
> 		11 - high
> 
> we could describe it with:
> 
> "1fVAL|52r|2[nope,low,mid,high]BAZ|4r|3xBAR|2dFOO"
> 
> syntax is <width><fmt><name>
> 
> where width is the number of bits. Format is one of:
> 
> f - flag - print the name if the field is non-zero, else print nothing
>     (or "-" to match the format you used above for CR4)
> r - reserved - skip this field
> d - print name=%d
> x - print name=0x%x
> [str0,str1,...str{2^width - 1}] - print NAME=str[val]

Right, this sounds real nice.

What I was going to propose, though, was to simplify the parsing by
doing this:

struct reg_range {
	const char * const names;
	unsigned flags;
	unsigned len;
};

which describes a bit slice of the register and then do this:

const struct reg_range reg_descriptor[] = {
	{ TYPE_FLAG,	  1,		{ "VAL" } },
	{ TYPE_RSVD,	  62 - 11 + 1,	{"rsvd" } },
	{ TYPE_ALTERNATE, 2,		{ "nope", "low", "mid", high" } },
	{ TYPE_HEX,	  3,		{ "BAR" } },
	{ TYPE_DEC,	  2,		{ "FOO" } },
};

Then, the parsing code would simply do:

	for (i = ARRAY_SIZE(reg_descriptor) - 1; i >= 0; i--)
		dump_range(reg_descriptor[i]);


with all the logic in dump_range().

The advantage is that you don't have to do any string parsing which
might be problematic in some cases and when typing the register
descriptor, you can be very easy exact on bit length and which bits by
typing the values directly from the manuals. And you can do lazy stuff
like "62-11+1" above in case you don't want to count reserved bits,
especially if they're trailing nybbles and such fun...



-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC] Dump interesting arch/platform info Borislav Petkov <bp@alien8.de> - 2016-02-01 13:00 +0100
  RE: [RFC] Dump interesting arch/platform info "Luck, Tony" <tony.luck@intel.com> - 2016-02-02 00:30 +0100
    Re: [RFC] Dump interesting arch/platform info Borislav Petkov <bp@alien8.de> - 2016-02-02 10:50 +0100
      Re: [RFC] Dump interesting arch/platform info Ingo Molnar <mingo@kernel.org> - 2016-02-03 11:50 +0100
        Re: [RFC] Dump interesting arch/platform info Borislav Petkov <bp@alien8.de> - 2016-02-03 12:10 +0100
          [PATCH -v2] x86: Add an archinfo dumper module Borislav Petkov <bp@alien8.de> - 2016-02-04 16:30 +0100
            Re: [PATCH -v2] x86: Add an archinfo dumper module "Luck, Tony" <tony.luck@intel.com> - 2016-02-04 20:10 +0100
              Re: [PATCH -v2] x86: Add an archinfo dumper module Borislav Petkov <bp@alien8.de> - 2016-02-07 12:00 +0100
            Re: [PATCH -v2] x86: Add an archinfo dumper module "Luck, Tony" <tony.luck@intel.com> - 2016-02-05 21:00 +0100
              RE: [PATCH -v2] x86: Add an archinfo dumper module "Luck, Tony" <tony.luck@intel.com> - 2016-02-05 23:30 +0100
            Re: [PATCH -v2] x86: Add an archinfo dumper module "H. Peter Anvin" <hpa@zytor.com> - 2016-02-08 01:10 +0100
              Re: [PATCH -v2] x86: Add an archinfo dumper module Boris Petkov <bp@alien8.de> - 2016-02-08 09:00 +0100

csiph-web