Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2418267ybi; Mon, 17 Jun 2019 04:35:22 -0700 (PDT) X-Google-Smtp-Source: APXvYqxpeQCDvUl+0MabxZ6qqG5Jd4cQpNe3kWR+E2DKMqKulWEXCTdkFOtxE5QF0iowizcNtV5L X-Received: by 2002:a63:d705:: with SMTP id d5mr5296307pgg.167.1560771322332; Mon, 17 Jun 2019 04:35:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560771322; cv=none; d=google.com; s=arc-20160816; b=RjEQvytzTixjd8kQaEmRSZWxhjCVL4wsNcdaEuO5HYNydq0fdfeBCrC+f9zbzzkSk/ 2T/FAnHPVDnIo7MoL3HWOE/1lhxLhbk+enuGNBV/neoo3L/ECzFH2d8JCr+Y6mscgfr3 nTzxlTgNJOdQFnAudp4CJuqomx+P2qtcI4RmHcdHpD4Mi5qfBkuk27WHLg03GGPRcBAS /BUV71c7VGMnrhznqOrd0AsllXgJvyfpDnqgLCII0oFgtkKMKSbsN1o579Hy5hwIbZYp H9Ri+HELT7ZsUSDwinl4WMGeIepQQCwuZjBNOai/dJpBa0cuKVbAuDY6wPj78jN/k4HU 4jnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=uTaQurjF4DAEz2YA58sq1itwNB0DAFLlJ/DDxkRjQXs=; b=mP4ISZrnvR4oaM7Iu7jY0HTM0M1n4R+6NtQ8cgham0NgEm/dQ1YPlU9rOSLWd7XvyQ jirXH6X4YNKdbz4m6cRItGaCNPLb/d6mlHKc20V8AqsRQTPhSTIwjBbDnFUURxoO1XYJ sBwzTeR6DEof29CR0lf4HNftQPC030LVecArcq0IcBtl3ZqhF916Doq/RMhEJUuM/Uwv 9XtLWhS+wANQSqY1UaEC8f18iMZqO+RXSVM2CIpOT+u2WOxgDEfN8Tvt53JO2EAVDnGa xbr5eBDkhxlonJOsMH6dTDFjCBSUMLCW1UHRSgIVpSVAoPqlz1GZk6PeD9arH8glKwLD I1bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YlBxHyck; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i62si10805690pfe.2.2019.06.17.04.35.06; Mon, 17 Jun 2019 04:35:22 -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; dkim=pass header.i=@linaro.org header.s=google header.b=YlBxHyck; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727873AbfFQLdc (ORCPT + 99 others); Mon, 17 Jun 2019 07:33:32 -0400 Received: from mail-io1-f54.google.com ([209.85.166.54]:43566 "EHLO mail-io1-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725681AbfFQLdc (ORCPT ); Mon, 17 Jun 2019 07:33:32 -0400 Received: by mail-io1-f54.google.com with SMTP id k20so20256527ios.10 for ; Mon, 17 Jun 2019 04:33:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uTaQurjF4DAEz2YA58sq1itwNB0DAFLlJ/DDxkRjQXs=; b=YlBxHyckiHCNw4pcv1L+3aipakmvWHdfu1oxzwefcQcVWnyNIn5NGlNqYIN/7QC0ey ioGaBXAv5AJACbpMWAaAsdLvLID96zO5uFRnyIa/tNH4W41NImVSVkxrQ0LVv/5lBHZz iEw6edvCS3C/y6wdXkjdsW3dJBbRBA4SU1vFKgiJzgFxZZEW6e1ELjhVW+MpsfItpE7h ZcLT9Ml5vwbXxOJ18xbKM2fo2/VHFZmbasZ2ki93QAjNEpwdH9E6TdwQqBrr5CEXoFeL rxMZ9NE4l66LJ1eS2LKTv6F9j1x+5ianNQxSP60RRxrfI+gX25JRg2p+ejEoCSKNrw9Y sWuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uTaQurjF4DAEz2YA58sq1itwNB0DAFLlJ/DDxkRjQXs=; b=pY8dOOseAWtCf8nAEldZoRCIGFlcVZ1j+kM9ejd4ME7irUI+z9IUoc/imHxSUqnK99 MZHC7I6A0U915ohDzGa3X6PAsZM8gmav0htYF1+1iyN3BOpRT1KiybCa2EIQQvRuqSCI UKkzIB/Nxt6CZqxN+M0txlfsOBrD7Zq+NMNzN4rqWv0IF15RCmUB2mSH/AIPJ3RbN/7P XlzOLgXMK04bMHoRbuCMeiea7igaJlHWeZOf52uiQX8YZCYCxFBZSekEbW4NAidP2JC/ Ml+jRk0KLGFJlFlV2w2PrW1JNCIv5ShA0HW0ibvtS042nuvSG11lJUfk8AMVdSo0879d mZsw== X-Gm-Message-State: APjAAAWGPMihrrM1/5/TfNF0t8NBaK40gfU2NdcpOsatCvOxYbaySSRn 1qN9ypqHrO+KujldJZgEGYhQQVhWDE4AXcTz6uMjEA== X-Received: by 2002:a02:3308:: with SMTP id c8mr15420974jae.103.1560771211244; Mon, 17 Jun 2019 04:33:31 -0700 (PDT) MIME-Version: 1.0 References: <20190612040933.GA18848@dc5-eodlnx05.marvell.com> <20190612093151.GA11554@brain-police> <20190614070914.GA21961@dc5-eodlnx05.marvell.com> <20190614095846.GC10506@fuggles.cambridge.arm.com> <20190614103850.GG10659@fuggles.cambridge.arm.com> <201906142026.1BC27EDB1E@keescook> <201906150654.FF4400F7C8@keescook> <201906161429.BCE1083@keescook> In-Reply-To: <201906161429.BCE1083@keescook> From: Ard Biesheuvel Date: Mon, 17 Jun 2019 13:33:19 +0200 Message-ID: Subject: Re: [RFC] Disable lockref on arm64 To: Kees Cook Cc: Will Deacon , Jayachandran Chandrasekharan Nair , "catalin.marinas@arm.com" , Jan Glauber , Linus Torvalds , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, 16 Jun 2019 at 23:31, Kees Cook wrote: > > On Sat, Jun 15, 2019 at 04:18:21PM +0200, Ard Biesheuvel wrote: > > Yes, I am using the same saturation point as x86. In this example, I > > am not entirely sure I understand why it matters, though: the atomics > > guarantee that the write by CPU2 fails if CPU1 changed the value in > > the mean time, regardless of which value it wrote. > > > > I think the concern is more related to the likelihood of another CPU > > doing something nasty between the moment that the refcount overflows > > and the moment that the handler pins it at INT_MIN/2, e.g., > > > > > CPU 1 CPU 2 > > > inc() > > > load INT_MAX > > > about to overflow? > > > yes > > > > > > set to 0 > > > > > > set to INT_MIN/2 > > Ah, gotcha, but the "set to 0" is really "set to INT_MAX+1" (not zero) > if you're using the same saturation. > Of course. So there is no issue here: whatever manipulations are racing with the overflow handler can never result in the counter to unsaturate. And actually, moving the checks before the stores is not as trivial as I thought, E.g., for the LSE refcount_add case, we have " ldadd %w[i], w30, %[cval]\n" \ " adds %w[i], %w[i], w30\n" \ REFCOUNT_PRE_CHECK_ ## pre (w30)) \ REFCOUNT_POST_CHECK_ ## post \ and changing this into load/test/store defeats the purpose of using the LSE atomics in the first place. On my single core TX2, the comparative performance is as follows Baseline: REFCOUNT_TIMING test using REFCOUNT_FULL (LSE cmpxchg) 191057942484 cycles # 2.207 GHz 148447589402 instructions # 0.78 insn per cycle 86.568269904 seconds time elapsed Upper bound: ATOMIC_TIMING 116252672661 cycles # 2.207 GHz 28089216452 instructions # 0.24 insn per cycle 52.689793525 seconds time elapsed REFCOUNT_TIMING test using LSE atomics 127060259162 cycles # 2.207 GHz 0 instructions # 0.00 insn per cycle 57.243690077 seconds time elapsed