All of lore.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: Borislav Petkov <bp@alien8.de>, X86 ML <x86@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Borislav Petkov <bp@suse.de>
Subject: Re: [RFC PATCH 1/3] x86: Add another set of MSR accessor functions
Date: Mon, 17 Feb 2014 08:21:47 -0800	[thread overview]
Message-ID: <5302371B.4090403@zytor.com> (raw)
In-Reply-To: <1391953709-15400-2-git-send-email-bp@alien8.de>

Good patch series overall, but I do have some issues with this one:

On 02/09/2014 05:48 AM, Borislav Petkov wrote:
> + */
> +int msr_read(u32 msr, struct msr *m)
> +{
> +	int err;
> +	u64 val;
> +
> +	val = native_read_msr_safe(msr, &err);

I don't think we should use the native_ function here.

> +	if (err)
> +		pr_warn("%s: Error reading MSR 0x%08x\n", __func__, msr);
> +	else
> +		m->q = val;

I also don't think we should print a message if the MSR doesn't exist.
This will be a normal occurrence in a number of flows.

> +static int __flip_bit(u32 msr, u8 bit, bool set)
> +{
> +	struct msr m;
> +
> +	if (bit > 63)
> +		return -1;

Feels a bit excessive, but I'd suggest returning -EINVAL instead.

I would suggest explicitly making this an inline function.

> +	if (msr_read(msr, &m))
> +		return -1;

Return -EIO?

How about:

	m1 = m;
	if (set)
		m1.q |= BIT_64(bit);
	else
		m1.q &= ~BIT_64(bit);

	if (m1.q != m.q) {
		if (msr_write(...))
			...
	}

> +
> +/**
> + * Set @bit in a MSR @msr.
> + *
> + * Retval:
> + * < 0: An error was encountered.
> + * = 0: Bit was already set.
> + * > 0: Hardware accepted the MSR write.
> + */
> +int msr_set_bit(u32 msr, u8 bit)
> +{
> +	int err = __flip_bit(msr, bit, true);
> +	if (err < 0)
> +		pr_err("%s: Error setting bit %d in MSR 0x%08x.\n",
> +			__func__, bit, msr);
> +
> +	return err;
> +}

Again, I'm not sure if printing a message here makes sense.  In fact,
this is the second message you print for the same thing.

	-hpa


  reply	other threads:[~2014-02-17 16:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-09 13:48 [RFC PATCH 0/3] MSR cleanups Borislav Petkov
2014-02-09 13:48 ` [RFC PATCH 1/3] x86: Add another set of MSR accessor functions Borislav Petkov
2014-02-17 16:21   ` H. Peter Anvin [this message]
2014-02-17 20:08     ` Borislav Petkov
2014-02-09 13:48 ` [RFC PATCH 2/3] x86, AMD: Convert to the new MSR accessors Borislav Petkov
2014-02-09 13:48 ` [RFC PATCH 3/3] x86, intel: " Borislav Petkov

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=5302371B.4090403@zytor.com \
    --to=hpa@zytor.com \
    --cc=bp@alien8.de \
    --cc=bp@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.