public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <graf@amazon.com>
To: yqwfh <amdeniulari@protonmail.com>, <kvm@vger.kernel.org>
Cc: Daniele Ahmed <ahmeddan@amazon.com>,
	Thomas Huth <thuth@redhat.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	Sean Christopherson <sean.j.christopherson@intel.com>,
	Andrew Jones <drjones@redhat.com>
Subject: Re: [kvm-unit-tests PATCH] x86/msr.c generalize to any input msr
Date: Thu, 23 Sep 2021 11:11:57 +0200	[thread overview]
Message-ID: <08d356da-17ce-d380-1fc9-18ba7ec67020@amazon.com> (raw)
In-Reply-To: <20210810143029.2522-1-amdeniulari@protonmail.com>

Hi Daniele!

On 10.08.21 16:31, yqwfh wrote:
> If an MSR description is provided as input by the user,
> run the test against that MSR. This allows the user to
> run tests on custom MSR's.
> 
> Otherwise run all default tests.

This patch description is missing the rationale. It comes through 
lightly where you say "This allows the user to run tests on custom 
MSRs", but that still doesn't explain why you would need that functionality.

The most important piece to transmit in the patch description is always 
the "Why". Only after that it sorted, you move on to a quick "How".

> 
> Signed-off-by: Daniele Ahmed <ahmeddan@amazon.com>

Please send the email from the same account that your SoB line quotes :)

It usually also helps to CC people that worked on the same file before. 
Usually, get_maintainers.pl should extract that list automatically for 
you but I realized that there is no such file in the kvm-unit-tests tree 
even though we have a MAINTAINERS one.

Paolo, what is the method you'd prefer to determine who to CC on 
kvm-unit-tests submissions?

> ---
>   x86/msr.c | 48 ++++++++++++++++++++++++++++++++++--------------
>   1 file changed, 34 insertions(+), 14 deletions(-)
> 
> diff --git a/x86/msr.c b/x86/msr.c
> index 7a551c4..554014e 100644
> --- a/x86/msr.c
> +++ b/x86/msr.c
> @@ -3,6 +3,7 @@
>   #include "libcflat.h"
>   #include "processor.h"
>   #include "msr.h"
> +#include <stdlib.h>
>   
>   struct msr_info {
>   	int index;
> @@ -77,25 +78,44 @@ static void test_rdmsr_fault(struct msr_info *msr)
>   	       "Expected #GP on RDSMR(%s), got vector %d", msr->name, vector);
>   }
>   
> +static void test_msr(struct msr_info *msr, bool is_64bit_host)
> +{
> +	if (is_64bit_host || !msr->is_64bit_only) {
> +		test_msr_rw(msr, msr->value);
> +
> +		/*
> +		 * The 64-bit only MSRs that take an address always perform
> +		 * canonical checks on both Intel and AMD.
> +		 */
> +		if (msr->is_64bit_only &&
> +		    msr->value == addr_64)
> +			test_wrmsr_fault(msr, NONCANONICAL);
> +	} else {
> +		test_wrmsr_fault(msr, msr->value);
> +		test_rdmsr_fault(msr);
> +	}
> +}
> +

I would prefer if you separate the "extract individual MSR logic into 
function" part from the "Add a new mode of operation to test a 
particular MSR" part into two separate patches. That way it's easier to 
review.

>   int main(int ac, char **av)
>   {
>   	bool is_64bit_host = this_cpu_has(X86_FEATURE_LM);
>   	int i;
>   
> -	for (i = 0 ; i < ARRAY_SIZE(msr_info); i++) {
> -		if (is_64bit_host || !msr_info[i].is_64bit_only) {
> -			test_msr_rw(&msr_info[i], msr_info[i].value);
> -
> -			/*
> -			 * The 64-bit only MSRs that take an address always perform
> -			 * canonical checks on both Intel and AMD.
> -			 */
> -			if (msr_info[i].is_64bit_only &&
> -			    msr_info[i].value == addr_64)
> -				test_wrmsr_fault(&msr_info[i], NONCANONICAL);
> -		} else {
> -			test_wrmsr_fault(&msr_info[i], msr_info[i].value);
> -			test_rdmsr_fault(&msr_info[i]);
> +	if (ac == 4) {

This means you require 3 completely undocumented command line arguments, 
no? I'm sure even you as the author of this patch will forget what they 
are in 2 years :).

Shouldn't there be some documentation that explains users that and how 
they can use this special mode of operation somewhere?

> +		char msr_name[16];
> +		int index = strtoul(av[1], NULL, 0x10);
> +		snprintf(msr_name, sizeof(msr_name), "MSR:0x%x", index);
> +
> +		struct msr_info msr = {
> +			.index = index,
> +			.name = msr_name,
> +			.is_64bit_only = !strcmp(av[3], "0"),

Why do you need to pass this when you invoke the test manually?

> +			.value = strtoul(av[2], NULL, 0x10)

Overall, the command line parsing is pretty ad hoc and wouldn't scale 
well with updates. Paolo, is there any common theme on command line 
argument passing? Do we do things like command line options? Help texts? 
Do we have something even remotely similar to getopt?


Thanks,

Alex

> +		};
> +		test_msr(&msr, is_64bit_host);
> +	} else {
> +		for (i = 0 ; i < ARRAY_SIZE(msr_info); i++) {
> +			test_msr(&msr_info[i], is_64bit_host);
>   		}
>   	}
>   
> 




Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss
Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B
Sitz: Berlin
Ust-ID: DE 289 237 879



  reply	other threads:[~2021-09-23  9:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-10 14:31 [kvm-unit-tests PATCH] x86/msr.c generalize to any input msr yqwfh
2021-09-23  9:11 ` Alexander Graf [this message]
2021-09-23  9:32   ` Paolo Bonzini
2021-09-27 15:30   ` [kvm-unit-tests PATCH v2 1/3] lib/string: Add stroull and strtoll ahmeddan
2021-09-27 15:30     ` [kvm-unit-tests PATCH v2 2/3] [kvm-unit-tests PATCH] x86/msr.c refactor out generic test logic ahmeddan
2021-09-27 15:38       ` Alexander Graf
2021-09-27 15:30     ` [kvm-unit-tests PATCH v2 3/3] x86/msr.c generalize to any input msr ahmeddan
2021-09-28 15:36       ` Paolo Bonzini
2021-10-01 14:14         ` Ahmed, Daniele
2021-10-15 15:57       ` Paolo Bonzini
2021-10-13 16:44     ` [kvm-unit-tests PATCH v2 1/3] lib/string: Add stroull and strtoll Andrew Jones

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=08d356da-17ce-d380-1fc9-18ba7ec67020@amazon.com \
    --to=graf@amazon.com \
    --cc=ahmeddan@amazon.com \
    --cc=amdeniulari@protonmail.com \
    --cc=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=sean.j.christopherson@intel.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox