lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <52EBE875.3070107@hp.com>
Date:	Fri, 31 Jan 2014 13:16:21 -0500
From:	Waiman Long <waiman.long@...com>
To:	Tim Chen <tim.c.chen@...ux.intel.com>
CC:	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	"H. Peter Anvin" <hpa@...or.com>, Arnd Bergmann <arnd@...db.de>,
	linux-arch@...r.kernel.org, x86@...nel.org,
	linux-kernel@...r.kernel.org,
	Peter Zijlstra <peterz@...radead.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Michel Lespinasse <walken@...gle.com>,
	Andi Kleen <andi@...stfloor.org>,
	Rik van Riel <riel@...hat.com>,
	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	Linus Torvalds <torvalds@...ux-foundation.org>,
	Raghavendra K T <raghavendra.kt@...ux.vnet.ibm.com>,
	George Spelvin <linux@...izon.com>,
	Daniel J Blueman <daniel@...ascale.com>,
	Alexander Fyodorov <halcy@...dex.ru>,
	Aswin Chandramouleeswaran <aswin@...com>,
	Scott J Norton <scott.norton@...com>,
	Thavatchai Makphaibulchoke <thavatchai.makpahibulchoke@...com>
Subject: Re: [PATCH v3 1/2] qspinlock: Introducing a 4-byte queue spinlock
 implementation

On 01/30/2014 02:00 PM, Tim Chen wrote:
> On Tue, 2014-01-28 at 13:19 -0500, Waiman Long wrote:
>
>> +/**
>> + * queue_spin_lock_slowpath - acquire the queue spinlock
>> + * @lock: Pointer to queue spinlock structure
>> + */
>> +void queue_spin_lock_slowpath(struct qspinlock *lock)
>> +{
>> +	unsigned int cpu_nr, qn_idx;
>> +	struct qnode *node, *next = NULL;
>> +	u32 prev_qcode, my_qcode;
>> +
>> +	/*
>> +	 * Get the queue node
>> +	 */
>> +	cpu_nr = smp_processor_id();
>> +	node   = this_cpu_ptr(&qnodes[0]);
>> +	qn_idx = 0;
>> +
>> +	if (unlikely(node->used)) {
>> +		/*
>> +		 * This node has been used, try to find an empty queue
>> +		 * node entry.
>> +		 */
>> +		for (qn_idx = 1; qn_idx<  MAX_QNODES; qn_idx++)
>> +			if (!node[qn_idx].used)
>> +				break;
>> +		if (unlikely(qn_idx == MAX_QNODES)) {
>> +			/*
>> +			 * This shouldn't happen, print a warning message
>> +			 *&  busy spinning on the lock.
>> +			 */
>> +			printk_sched(
>> +			  "qspinlock: queue node table exhausted at cpu %d!\n",
>> +			  cpu_nr);
>> +			while (!unfair_trylock(lock))
>> +				arch_mutex_cpu_relax();
>> +			return;
>> +		}
>> +		/* Adjust node pointer */
>> +		node += qn_idx;
>> +	}
>> +
>> +	/*
>> +	 * Set up the new cpu code to be exchanged
>> +	 */
>> +	my_qcode = SET_QCODE(cpu_nr, qn_idx);
>> +
> If we get interrupted here before we have a chance to set the used flag,
> the interrupt handler could pick up the same qnode if it tries to
> acquire queued spin lock.  Then we could overwrite the qcode we have set
> here.
>
> Perhaps an exchange operation for the used flag to prevent this race
> condition?
>
> Tim

That actually is fine. I am assuming that whenever an interrupt handler 
needs to acquire a spinlock, it can use the same queue node as the 
interrupted function as long as it can finish the lock acquisition and 
release queue node back to the pool before returning to the interrupted 
function. The only case where an interrupt handler cannot use the queue 
node is when useful data were already there indicated by the setting of 
the used flag.

I will add comment to clarify this possible scenario.

-Longman
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ