kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nadav Amit <nadav.amit@gmail.com>
To: Sean Christopherson <sean.j.christopherson@intel.com>
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [kvm-unit-tests PATCH] x86: Fix breakage of fw_cfg for 32-bit unit tests
Date: Thu, 22 Aug 2019 16:55:14 -0700	[thread overview]
Message-ID: <DCA6E594-72DC-43AD-A490-BAEC1DE85F7E@gmail.com> (raw)
In-Reply-To: <20190822235052.3703-1-sean.j.christopherson@intel.com>

> On Aug 22, 2019, at 4:50 PM, Sean Christopherson <sean.j.christopherson@intel.com> wrote:
> 
> Ensure the fw_cfg overrides are parsed prior consuming any of said
> overrides.  fwcfg_get_u() treats zero as a valid overide value, which
> is slightly problematic since the overrides are in the .bss and thus
> initialized to zero.
> 
> Add a limit check when indexing fw_override so that future code doesn't
> spontaneously explode.
> 
> Cc: Nadav Amit <nadav.amit@gmail.com>
> Fixes: 03b1e4570f967 ("x86: Support environments without test-devices")
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
> lib/x86/fwcfg.c | 10 ++++++++--
> lib/x86/fwcfg.h |  2 --
> x86/cstart64.S  |  2 --
> 3 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/x86/fwcfg.c b/lib/x86/fwcfg.c
> index d8d797f..06ef62c 100644
> --- a/lib/x86/fwcfg.c
> +++ b/lib/x86/fwcfg.c
> @@ -5,10 +5,11 @@
> static struct spinlock lock;
> 
> static long fw_override[FW_CFG_MAX_ENTRY];
> +static bool fw_override_done;
> 
> bool no_test_device;
> 
> -void read_cfg_override(void)
> +static void read_cfg_override(void)
> {
> 	const char *str;
> 	int i;
> @@ -26,6 +27,8 @@ void read_cfg_override(void)
> 
> 	if ((str = getenv("TEST_DEVICE")))
> 		no_test_device = !atol(str);
> +
> +    fw_override_done = true;
> }
> 
> static uint64_t fwcfg_get_u(uint16_t index, int bytes)
> @@ -34,7 +37,10 @@ static uint64_t fwcfg_get_u(uint16_t index, int bytes)
>     uint8_t b;
>     int i;
> 
> -    if (fw_override[index] >= 0)
> +    if (!fw_override_done)
> +        read_cfg_override();
> +
> +    if (index < FW_CFG_MAX_ENTRY && fw_override[index] >= 0)
> 	    return fw_override[index];

How did that happen? I remember I tested this code with KVM..

Anyhow,

Reviewed-by: Nadav Amit <nadav.amit@gmail.com>

Thanks for fixing it.


  reply	other threads:[~2019-08-22 23:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-22 23:50 [kvm-unit-tests PATCH] x86: Fix breakage of fw_cfg for 32-bit unit tests Sean Christopherson
2019-08-22 23:55 ` Nadav Amit [this message]
2019-08-22 23:56   ` Sean Christopherson

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=DCA6E594-72DC-43AD-A490-BAEC1DE85F7E@gmail.com \
    --to=nadav.amit@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=sean.j.christopherson@intel.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;
as well as URLs for NNTP newsgroup(s).