public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	Alexander Graf <agraf@suse.de>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] KVM: SVM: Move msrpm offset calculation to seperate function
Date: Fri, 26 Feb 2010 11:25:07 +0100	[thread overview]
Message-ID: <20100226102506.GB12689@amd.com> (raw)
In-Reply-To: <4B87A05A.3010600@redhat.com>

On Fri, Feb 26, 2010 at 12:20:10PM +0200, Avi Kivity wrote:
> On 02/25/2010 07:15 PM, Joerg Roedel wrote:
> >The algorithm to find the offset in the msrpm for a given
> >msr is needed at other places too. Move that logic to its
> >own function.
> >
> >  #define MAX_INST_SIZE 15
> >
> >@@ -417,23 +439,22 @@ err_1:
> >  static void set_msr_interception(u32 *msrpm, unsigned msr,
> >  				 int read, int write)
> >  {
> >-	int i;
> >+	u8 bit_read, bit_write;
> >+	unsigned long tmp;
> >+	u32 offset;
> >
> >-	for (i = 0; i<  NUM_MSR_MAPS; i++) {
> >-		if (msr>= msrpm_ranges[i]&&
> >-		    msr<  msrpm_ranges[i] + MSRS_IN_RANGE) {
> >-			u32 msr_offset = (i * MSRS_IN_RANGE + msr -
> >-					  msrpm_ranges[i]) * 2;
> >-
> >-			u32 *base = msrpm + (msr_offset / 32);
> >-			u32 msr_shift = msr_offset % 32;
> >-			u32 mask = ((write) ? 0 : 2) | ((read) ? 0 : 1);
> >-			*base = (*base&  ~(0x3<<  msr_shift)) |
> >-				(mask<<  msr_shift);
> >-			return;
> >-		}
> >-	}
> >-	BUG();
> >+	offset    = svm_msrpm_offset(msr);
> >+	bit_read  = 2 * (msr&  0x0f);
> >+	bit_write = 2 * (msr&  0x0f) + 1;
> >+
> >+	BUG_ON(offset == MSR_INVALID);
> >+
> >+	tmp = msrpm[offset];
> >+
> >+	read  ? clear_bit(bit_read,&tmp) : set_bit(bit_read,&tmp);
> >+	write ? clear_bit(bit_write,&tmp) : set_bit(bit_write,&tmp);
> >+
> >+	msrpm[offset] = tmp;
> >  }
> 
> This can fault - set_bit() accesses an unsigned long, which can be 8
> bytes, while offset can point into the last u32 of msrpm.  So this
> needs either to revert to u32 shift/mask ops or msrpm be changed to
> a ulong array (actually better, since bitmaps in general are defined
> as arrays of ulongs).

Ah true, I will fix that. Thanks.

> btw, the op-level ternary expression is terrible, relying solely on
> *_bit()'s side effects.  Please convert to an ordinary if.
> 
> btw2, use __set_bit() which atomic operation is not needed.

Right, will switch to __set_bit and __clear_bit.

	Joerg



  reply	other threads:[~2010-02-26 10:25 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-25 17:15 [PATCH 0/5] Rework of msrpm optimization and additional fixes for nested svm Joerg Roedel
2010-02-25 17:15 ` [PATCH 1/5] KVM: SVM: Move msrpm offset calculation to seperate function Joerg Roedel
2010-02-26 10:20   ` Avi Kivity
2010-02-26 10:25     ` Joerg Roedel [this message]
2010-02-25 17:15 ` [PATCH 2/5] KVM: SVM: Optimize nested svm msrpm merging Joerg Roedel
2010-02-26 10:28   ` Avi Kivity
2010-02-26 12:25     ` Joerg Roedel
2010-02-26 12:28       ` Alexander Graf
2010-02-26 13:04         ` Joerg Roedel
2010-02-26 13:08           ` Alexander Graf
2010-02-26 13:19             ` Joerg Roedel
2010-02-26 13:10           ` Avi Kivity
2010-02-26 13:21             ` Joerg Roedel
2010-02-26 13:26               ` Alexander Graf
2010-02-26 13:30                 ` Joerg Roedel
2010-02-26 13:59                   ` Avi Kivity
2010-02-26 12:42       ` Avi Kivity
2010-02-25 17:15 ` [PATCH 3/5] KVM: SVM: Use svm_msrpm_offset in nested_svm_exit_handled_msr Joerg Roedel
2010-02-26 10:30   ` Avi Kivity
2010-03-01 13:33     ` Joerg Roedel
2010-02-25 17:15 ` [PATCH 4/5] KVM: SVM: Add correct handling of nested iopm Joerg Roedel
2010-02-26 10:33   ` Avi Kivity
2010-02-25 17:15 ` [PATCH 5/5] KVM: SVM: Ignore lower 12 bit of nested msrpm_pa Joerg Roedel

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=20100226102506.GB12689@amd.com \
    --to=joerg.roedel@amd.com \
    --cc=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mtosatti@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