Messages in this thread | ![/](/images/icornerl.gif) | | Date | Sat, 29 Oct 2022 02:59:51 +0300 | From | "Kirill A. Shutemov" <> | Subject | Re: [PATCH 1/2] x86/tdx: Extract GET_INFO call from get_cc_mask() |
| |
On Fri, Oct 28, 2022 at 04:27:10PM -0700, Dave Hansen wrote: > 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.
I agree. Sorry about that.
We have more code in our tree that want to check attributes. And it is after initialization, so the code structure derived from there.
But, yes, I should have rework it before sending upstream.
> 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.
Looks good and works fine:
Acked-and-Tested-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
-- Kiryl Shutsemau / Kirill A. Shutemov
| ![\](/images/icornerr.gif) |