Received: by 10.192.165.156 with SMTP id m28csp539729imm; Wed, 11 Apr 2018 03:26:11 -0700 (PDT) X-Google-Smtp-Source: AIpwx498WGMwFloqWg0WasUXx0I4slS7vxT9kcU9lbQf/0f5vhYn19HNl9bXDRt/HiRkHUVXPaE/ X-Received: by 10.99.55.1 with SMTP id e1mr3000170pga.237.1523442371914; Wed, 11 Apr 2018 03:26:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523442371; cv=none; d=google.com; s=arc-20160816; b=Uo0KmoCs19+s5zi4lhLUHnnN/ORIh5FbXdqGNecTvCyQ1hVnOqIlPleV4T+VLGmU5u cUhYjnVfmbiMtvrfMB8YOfrY1m7/PBV1c1+BTczCzyctC+/M3PmjUjQR3UO/YnaUXVWE fXsK6q2eiGvOVe4pqnGnmnFkyTqjpkQQdJ7wUGQVcIGuFr7PSESrFDc9hmFyjSYxiwPq PHMnFvpY1/jbIvucTLFSnz9m+8nRpdYAf3ZpNHgsUKrxgs7eKYo7usRITnK94OP5tFh3 JYOkoKLJm2IXo3/f6Hi9ST8Cj6zetVF/IYLgcXby5u/FVdT7+p7P2p0lBetd5q1ZSc9e gQpw== 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:arc-authentication-results; bh=RWYIZ30y27qvSaANLcnPwP+Eys3DUnB31hSBK6iw5TM=; b=qIw6ImttSpBwpIRP3CV0W8wnpN+b7tvj46E11+x3t4HArwI19CHaTiFgSrKwIbNhlD A5U0ubwq1ZD3y+M4DY5DNqF3G96ZpoMKoFVV4qVTmcoZJVwCuSZGSfeKzN0QD2tR6Oyf 1phEPgJgC2H2yUepUmFzGZzYAouHymHrQVLT02dWBqd9IxZ1wzuFjay7VE27VDZstk4U O8g2AkOVglHU1r/3FbEoeRPmpRQj0Sj/+eM511Jz+UQNqJD3RexXBpcGQ3N9rhpKATnZ Nlml3y2ejBtIJ0SMuGUQhLy1DXv+/f5wLCfxoOMq/XbQVL47u0TbWHkxK9UECbdLcsAQ vV8g== ARC-Authentication-Results: i=1; mx.google.com; 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 y101-v6si818272plh.188.2018.04.11.03.25.34; Wed, 11 Apr 2018 03:26:11 -0700 (PDT) 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; 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 S1752810AbeDKKUK (ORCPT + 99 others); Wed, 11 Apr 2018 06:20:10 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:47636 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750819AbeDKKUI (ORCPT ); Wed, 11 Apr 2018 06:20:08 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B370880D; Wed, 11 Apr 2018 03:20:08 -0700 (PDT) Received: from armageddon.cambridge.arm.com (armageddon.cambridge.arm.com [10.1.206.84]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C92F93F587; Wed, 11 Apr 2018 03:20:06 -0700 (PDT) Date: Wed, 11 Apr 2018 11:20:04 +0100 From: Catalin Marinas To: Andrea Parri Cc: Will Deacon , peterz@infradead.org, boqun.feng@gmail.com, linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com, mingo@kernel.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 00/10] kernel/locking: qspinlock improvements Message-ID: <20180411102003.rjfrcmc4fjukehst@armageddon.cambridge.arm.com> References: <1522947547-24081-1-git-send-email-will.deacon@arm.com> <20180406132249.GA7071@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180406132249.GA7071@andrea> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 06, 2018 at 03:22:49PM +0200, Andrea Parri wrote: > On Thu, Apr 05, 2018 at 05:58:57PM +0100, Will Deacon wrote: > > I've been kicking the tyres further on qspinlock and with this set of patches > > I'm happy with the performance and fairness properties. In particular, the > > locking algorithm now guarantees forward progress whereas the implementation > > in mainline can starve threads indefinitely in cmpxchg loops. > > > > Catalin has also implemented a model of this using TLA to prove that the > > lock is fair, although this doesn't take the memory model into account: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/cmarinas/kernel-tla.git/commit/ > > Nice! I'll dig into this formalization, but my guess is that our model > (and axiomatic models "a-la-herd", in general) are not well-suited when > it comes to study properties such as fairness, liveness... Maybe someone with a background in formal methods could give a better answer. How TLA+ works is closer to rmem [1] (operational model, exhaustive memoised state search) than herd. Liveness verification requires checking that, under certain fairness properties, some state is eventually reached. IOW, it tries to show that either all state change graphs lead to (go through) such state or that there are cycles in the graph and the state is never reached. I don't know whether herd could be modified to check liveness. I'm not sure it can handle infinite loops either (the above model checks an infinite lock/unlock loop on each CPU and that's easier to implement in a tool with memoised states). The TLA+ model above assumes sequential consistency, so no memory ordering taken into account. One could build an operational model in TLA+ that's equivalent to the axiomatic one (e.g. following the Flat model equivalence as in [2]), however, liveness checking (at least with TLA+) is orders of magnitude slower than safety. Any small variation has an exponential impact on the state space, so likely to be impractical. For specific parts of the algorithm, you may be able to use a poor man's ordering by e.g. writing two accesses in two different orders so the model checks both combinations. There are papers (e.g. [3]) on how to convert liveness checking to safety checking but I haven't dug further. I think it's easier/faster if you do liveness checking with a simplified model and separately check the safety with respect to memory ordering on tools like herd. [1] http://www.cl.cam.ac.uk/~sf502/regressions/rmem/ [2] http://www.cl.cam.ac.uk/~pes20/armv8-mca/armv8-mca-draft.pdf [3] https://www.sciencedirect.com/science/article/pii/S1571066104804109 -- Catalin