historical-speck.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pawan Gupta <pawan.kumar.gupta@linux.intel.com>
To: speck@linutronix.de
Subject: [MODERATED] Re: [PATCH v6 9/9] TAAv6 9
Date: Fri, 11 Oct 2019 18:41:02 -0700	[thread overview]
Message-ID: <20191012014102.GA22297@guptapadev.amr> (raw)
In-Reply-To: <20191010065412.GD256999@kroah.com>

On Thu, Oct 10, 2019 at 08:54:12AM +0200, speck for Greg KH wrote:
> > +static DEFINE_MUTEX(tsx_mutex);
> 
> I still don't know what this is trying to "protect".  Please at least
> document it so I have a chance to review it...

I will add these comments to the code:

	/*
	 * Protect tsx_ctrl_state and TSX update on_each_cpu() from concurrent
	 * writers.
	 *
	 *  - Serialize TSX_CTRL MSR writes across all CPUs when there are
	 *    concurrent sysfs requests. on_each_cpu() callback execution
	 *    order on other CPUs can be different for multiple calls to
	 *    on_each_cpu(). For conflicting concurrent sysfs requests the
	 *    lock ensures all CPUs have updated the TSX_CTRL MSR before the
	 *    next call to on_each_cpu().
	 *  - Serialize tsx_ctrl_state update so that it doesn't get out of
	 *    sync with TSX_CTRL MSR.
	 *  - Serialize update to taa_mitigation.
	 */

> > +/* Take tsx_mutex lock and update tsx_ctrl_state when calling this function */
> > +static void tsx_update_on_each_cpu(bool val)
> > +{
> > +	get_online_cpus();
> > +	on_each_cpu(tsx_update_this_cpu, (void *)val, 1);
> > +	put_online_cpus();
> > +}
> 
> Why take the lock?  This is only called in one place.

So that TSX_CTRL MSR state stays consistent across all CPUs between
multiple on_each_cpu() calls. Otherwise overlapping conflicting TSX_CTRL MSR
writes could end up in some CPUs with TSX enabled and others with TSX
disabled.

> > +ssize_t hw_tx_mem_show(struct device *dev, struct device_attribute *attr,
> > +		       char *buf)
> > +{
> > +	return sprintf(buf, "%d\n", tsx_ctrl_state == TSX_CTRL_ENABLE ? 1 : 0);
> > +}
> > +
> > +ssize_t hw_tx_mem_store(struct device *dev, struct device_attribute *attr,
> > +			const char *buf, size_t count)
> > +{
> > +	enum tsx_ctrl_states requested_state;
> > +	ssize_t ret;
> > +	bool val;
> > +
> > +	ret = kstrtobool(buf, &val);
> > +	if (ret)
> > +		return ret;
> > +
> > +	mutex_lock(&tsx_mutex);
> > +
> > +	if (val)
> > +		requested_state = TSX_CTRL_ENABLE;
> > +	else
> > +		requested_state = TSX_CTRL_DISABLE;
> 
> Why is lock grabbed above and not here?

Yes, can be moved here.

Thanks,
Pawan

  reply	other threads:[~2019-10-12  1:47 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-09 23:21 [MODERATED] [PATCH v6 0/9] TAAv6 0 Pawan Gupta
2019-10-09 23:22 ` [MODERATED] [PATCH v6 1/9] TAAv6 1 Pawan Gupta
2019-10-09 23:23 ` [MODERATED] [PATCH v6 2/9] TAAv6 2 Pawan Gupta
2019-10-09 23:24 ` [MODERATED] [PATCH v6 3/9] TAAv6 3 Pawan Gupta
2019-10-09 23:25 ` [MODERATED] [PATCH v6 4/9] TAAv6 4 Pawan Gupta
2019-10-09 23:26 ` [MODERATED] [PATCH v6 5/9] TAAv6 5 Pawan Gupta
2019-10-09 23:27 ` [MODERATED] [PATCH v6 6/9] TAAv6 6 Pawan Gupta
2019-10-09 23:28 ` [MODERATED] [PATCH v6 7/9] TAAv6 7 Pawan Gupta
2019-10-09 23:29 ` [MODERATED] [PATCH v6 8/9] TAAv6 8 Pawan Gupta
2019-10-09 23:30 ` [MODERATED] [PATCH v6 9/9] TAAv6 9 Pawan Gupta
2019-10-09 23:34 ` [MODERATED] Re: [PATCH v6 1/9] TAAv6 1 Pawan Gupta
2019-10-10  1:23   ` Pawan Gupta
2019-10-15 12:54     ` Thomas Gleixner
2019-10-21 20:35       ` [MODERATED] " Pawan Gupta
2019-10-09 23:38 ` Andrew Cooper
2019-10-09 23:40   ` Andrew Cooper
2019-10-09 23:53     ` Luck, Tony
2019-10-10  0:01       ` Andrew Cooper
2019-10-10 16:51         ` Luck, Tony
     [not found] ` <5d9e6daa.1c69fb81.f84ad.88ceSMTPIN_ADDED_BROKEN@mx.google.com>
2019-10-10  6:47   ` [MODERATED] Re: [PATCH v6 3/9] TAAv6 3 Greg KH
2019-10-10 23:44     ` Pawan Gupta
     [not found] ` <5d9e6e22.1c69fb81.6df19.ff55SMTPIN_ADDED_BROKEN@mx.google.com>
2019-10-10  6:50   ` [MODERATED] Re: [PATCH v6 5/9] TAAv6 5 Greg KH
2019-10-10 21:18     ` Pawan Gupta
2019-10-10  6:50   ` Greg KH
     [not found] ` <5d9e6f13.1c69fb81.d7036.be99SMTPIN_ADDED_BROKEN@mx.google.com>
2019-10-10  6:54   ` [MODERATED] Re: [PATCH v6 9/9] TAAv6 9 Greg KH
2019-10-12  1:41     ` Pawan Gupta [this message]
2019-10-13 20:05       ` Ben Hutchings
2019-10-13 21:00         ` Ben Hutchings
     [not found] ` <4b15283c29b75be3177eb7c4b8601be5644f630e.157065=?utf-8?q?8889?= .git.pawan.kumar.gupta@linux.intel.com>
2019-10-18  1:21   ` [MODERATED] Re: [PATCH v6 8/9] TAAv6 8 Ben Hutchings
2019-10-21 20:04 ` [MODERATED] Re: [PATCH v6 0/9] TAAv6 0 Josh Poimboeuf
2019-10-21 20:09   ` Pawan Gupta

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=20191012014102.GA22297@guptapadev.amr \
    --to=pawan.kumar.gupta@linux.intel.com \
    --cc=speck@linutronix.de \
    /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).