Messages in this thread | ![/](/images/icornerl.gif) | | Date | Fri, 28 Oct 2022 16:27:10 -0700 | Subject | Re: [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask() | From | Dave Hansen <> |
| |
I looked at this a bit more closely. The code is just bonkers now. It can't go in like this.
tdx_parse_tdinfo() stashes two global variables. Then, about three lines later in the function, it calls get_cc_mask() which just returns one of those variables, modulo a little masking.
Ditto for the td_attr. It's stashed in a global variable and then read one time.
There is *ZERO* reason to store 'td_attr'. There's also zero reason to have 'gpa_width' as a global variable. It's only used *ONE* *TIME* from the scope of *ONE* *FUNCTION*.
Even the comment is bonkers:
/* * Initializes gpa_width and td_attr. Must be called before * get_cc_mask() or attribute checks. */ tdx_parse_tdinfo();
Comments are great. But comments that are only there because the code is obtuse are not. I changed it to:
tdx_parse_tdinfo(&cc_mask);
It doesn't even need a comment now. Why? Because it's obvious from the naming and calling convention that it initializes cc_mask and what the ordering dependency is. Plus, even *if* I missed the call, or screwed up the order, the compiler would tell me that I'm a dolt.
The whole global variable thing actually makes the code objectively worse in almost every possible way.
Can you please take a look through this and make sure I didn't botch anything:
> https://git.kernel.org/pub/scm/linux/kernel/git/daveh/devel.git/log/?h=tdxbadve
The end result is about 50 lines less than what was there before. Most of it is comment removal but the code is simpler too.
Acks and Tested-by's would be appreciated.
| ![\](/images/icornerr.gif) |