Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp444361ybl; Thu, 23 Jan 2020 01:28:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxa2IHW00bJSsQCFGgzXn3WFH4671k6zoeNOqCk3UGl5/mKbaFvUmM4OtPLwJ9Zsly7CaPR X-Received: by 2002:a9d:3a66:: with SMTP id j93mr10952494otc.25.1579771707098; Thu, 23 Jan 2020 01:28:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579771707; cv=none; d=google.com; s=arc-20160816; b=GPxZG+8K+/zXH9/zlnYs/zQedld2pVBHsLImbR6W5G3y6KgaOm3AAZrvkww2ItoR6n DXSxgyQxAwbAxVu1SCTQj+i8b3VokydCZHOLOefNP+VRHh+1lU+o/iUppuZ633PzUJro NTv34X3LZoTONdvAWfKkIf8Lt2NiZm3pRyL7LMFc7j/OTutML47OReXZwLEIZAuQWbsA ZwYFHoziO6w7CRWnoIW9+rEyRUjqaS6zl7SP2J6LvyRTBzAo2HSVdCsq6PMxEA3WHq20 2G4k7mFyfODSKn5PCnlf1CN6hKIBwv56nBEylujUvOshJrExGFnNEA8KEO0pB6xaAkLq xtoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=yXt2e8+nL87kk6np60HZC4USlTrjp0fvuIINrNyQqC0=; b=IW32PYWl/l5XY2mjkvzB6wK/GHMN7qTnkDTLMSwBrK2MjGSve4MGetw/7kPNcFDNQ1 T/Got+PwFrEJZc5XIV5gSvN13Mdd7+GC1/2dfUtk3oDi92OlVPWbHp9Zwq9mRwYXT+fk jSQVt5uFa6xxWdWUaWFgQqN9LlVAuaSrXgk0cMb1YPOwLD8PO44f0djFmCa/kaTmcQ7M AIqC/75BnHyOAUXjqLksK+B4ejvPrtrqSBWqrzeViwh5ByGQIR0dIJttTMEsS+AAeUdO 9L08nKBe5YmYd38fI55E4bP3AAz6q4RAPZIDmb8D1Ihu4VveLeMgAvRhF524EPyf9U0O Py+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LwEOJEum; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a7si882284otp.284.2020.01.23.01.28.15; Thu, 23 Jan 2020 01:28:27 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=LwEOJEum; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726584AbgAWJ1R (ORCPT + 99 others); Thu, 23 Jan 2020 04:27:17 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:48758 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725785AbgAWJ1R (ORCPT ); Thu, 23 Jan 2020 04:27:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=yXt2e8+nL87kk6np60HZC4USlTrjp0fvuIINrNyQqC0=; b=LwEOJEumDlplZiem+kW6UY8o+ o4fASuFZarYZZSRRIT23Evkm73x8PyuTMXy/LyQpBhC4omCiPkvdAswM1WDx4yr1FVG00hntqSac/ Hwld7WW4oKbQmTH3NnLnnENDswejiBGxVRsW18sMqiVoEc9WCeA9wjztI3U0p1jaW9IRcGpFE9QVg ZOL7xGms0EUyBMlRgPml+hlRZcCx835gj9n+VRICM6l0U2j0jE0GboxXO48Z5HDAeCgyZFoi4Byiw b8Jp7C3noWpZk/LZxsaufi633nbnDQHobnjNuQbIasSlCXFeIUOB66NY8ud8ND8z65FwSFnEi5vyU akNTYWeYQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iuYlR-0007ow-GR; Thu, 23 Jan 2020 09:27:01 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 482F7304121; Thu, 23 Jan 2020 10:25:18 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1A8E82B6FD00E; Thu, 23 Jan 2020 10:26:58 +0100 (CET) Date: Thu, 23 Jan 2020 10:26:58 +0100 From: Peter Zijlstra To: Alex Kogan Cc: linux@armlinux.org.uk, mingo@redhat.com, will.deacon@arm.com, arnd@arndb.de, longman@redhat.com, linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, hpa@zytor.com, x86@kernel.org, guohanjun@huawei.com, jglauber@marvell.com, steven.sistare@oracle.com, daniel.m.jordan@oracle.com, dave.dice@oracle.com Subject: Re: [PATCH v9 3/5] locking/qspinlock: Introduce CNA into the slow path of qspinlock Message-ID: <20200123092658.GC14879@hirez.programming.kicks-ass.net> References: <20200115035920.54451-1-alex.kogan@oracle.com> <20200115035920.54451-4-alex.kogan@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200115035920.54451-4-alex.kogan@oracle.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 14, 2020 at 10:59:18PM -0500, Alex Kogan wrote: > +/* this function is called only when the primary queue is empty */ > +static inline bool cna_try_change_tail(struct qspinlock *lock, u32 val, > + struct mcs_spinlock *node) > +{ > + struct mcs_spinlock *head_2nd, *tail_2nd; > + u32 new; > + > + /* If the secondary queue is empty, do what MCS does. */ > + if (node->locked <= 1) > + return __try_clear_tail(lock, val, node); > + > + /* > + * Try to update the tail value to the last node in the secondary queue. > + * If successful, pass the lock to the first thread in the secondary > + * queue. Doing those two actions effectively moves all nodes from the > + * secondary queue into the main one. > + */ > + tail_2nd = decode_tail(node->locked); > + head_2nd = tail_2nd->next; > + new = ((struct cna_node *)tail_2nd)->encoded_tail + _Q_LOCKED_VAL; > + > + if (atomic_try_cmpxchg_relaxed(&lock->val, &val, new)) { > + /* > + * Try to reset @next in tail_2nd to NULL, but no need to check > + * the result - if failed, a new successor has updated it. > + */ I think you actually have an ordering bug here; the load of head_2nd *must* happen before the atomic_try_cmpxchg(), otherwise it might observe the new next and clear a valid next pointer. What would be the best fix for that; I'm thinking: head_2nd = smp_load_acquire(&tail_2nd->next); Will? > + cmpxchg_relaxed(&tail_2nd->next, head_2nd, NULL); > + arch_mcs_pass_lock(&head_2nd->locked, 1); > + return true; > + } > + > + return false; > +}