Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1442965imc; Mon, 11 Mar 2019 13:59:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxs9LAeZfG29gRdVWqYGXwhwgkD3O4V85TBDsKRsh29ItvcQ012b7bTQ3HhctmJ2OBD39qC X-Received: by 2002:a62:b248:: with SMTP id x69mr34737961pfe.256.1552337996121; Mon, 11 Mar 2019 13:59:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552337996; cv=none; d=google.com; s=arc-20160816; b=o+/VQFrCebX1ieABfqiG2lfu4WrldMrY+wCZY+pKYcncoLlKX3Lieen1shvrOhZZoD +5Q0b/Azkx3jIArz1waQj6rOULm6X9SWBy/N83SC+yLo9pEvrG6Z8Rfe2Uy9exrwTGk9 XxFmUVnJAU5yOde0RSHuwQpVChqK7uE8MBW5hfVaO89wSlMU48pYiX0J20iyhg0ZmgRd R+/3w3pUEmuKxcZs4mSU09lSzpzf6XqYZLwVJZg59zBWZgPsgZTj7JSksc3PmcnIV+jh In85tSw73/PtO0E4r3TcpSPZMgZjEQMIbjjHfkBcuwObHlJAzOFTghYuz9rlTdnsTpVu WN0g== 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; bh=joFaR78DHCL1tgJBLek+bVJOh7TncAG/dejcR7SsEV8=; b=X1ATVN++qeYhI4xpjh9FCkMlZTGFu1UyOBGKS4huUjlgEUfxF8a/GPhJ2m83A96nAu O7XZaF/Sq0O5o9MEbX88J2yeEHbITSRTCgGO4OMqj8zidQUG8kjq+ignIKCjD5xTDpPZ RatpleOmwJ/+xzzBcZsjzu+b4TIeSsIn3PjgQcPGuVVfphC2OyErvhrPMuzqiwYLk+ZR O0AyparszKCv83Cf0dDklf3pmikLk4wrQGc3HKHg+UBYHtt9fikrgExt0oxNZuBrsa6D 0aTHdo2d3fBm0Dk/a3fwIs9Tq/dFAkh16LiejPSpDSSCrL06Lo+pPj7lCJql8hParQkm ovZQ== 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 h4si5531765pgc.354.2019.03.11.13.59.40; Mon, 11 Mar 2019 13:59:56 -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 S1728183AbfCKU7P (ORCPT + 99 others); Mon, 11 Mar 2019 16:59:15 -0400 Received: from mail-qt1-f196.google.com ([209.85.160.196]:36634 "EHLO mail-qt1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726675AbfCKU7O (ORCPT ); Mon, 11 Mar 2019 16:59:14 -0400 Received: by mail-qt1-f196.google.com with SMTP id b3so216514qtj.3 for ; Mon, 11 Mar 2019 13:59:14 -0700 (PDT) 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=joFaR78DHCL1tgJBLek+bVJOh7TncAG/dejcR7SsEV8=; b=KYiKOjMiKfJl8oyOc5AfRW2Q9QAc7wF1yfAYDk82JG/29xCDi4tkdzrOf4Wk3M15ap tCO0CgIG/arV2TG0Vut2dho8CwdT+2KUSuQ3FHKg7F34FdJf2jhe6W+0LSyyPYG04UtN vQpgjqJ/qvUnySM+XBztKfScFtd13AmnOYfPkcuevhXGKOedNHLE1Kx+LuHg4NKqN/oS n6lfijkQYrDvyYQMabgfPeIklKBr3b88BPGmYtUNVEIeMKu5VmNZXP3ErDbDI0kqicSB xpNK/55p/kZdfcmGEeUCBHkN5OTWURigW1yZzMLyziRoxBzFBn+vqgX5AR478EkW/py3 iVZQ== X-Gm-Message-State: APjAAAU6Ha4ND55JH7cROtKGuTncluT6n5okzkg0DJcnxhQcOTKw36Ve ttjDYDhbM0i3nw7PWt3j1GKz2T6KPYA4xvdS/is= X-Received: by 2002:ac8:2bcf:: with SMTP id n15mr26261515qtn.96.1552337953350; Mon, 11 Mar 2019 13:59:13 -0700 (PDT) MIME-Version: 1.0 References: <20190307091514.2489338-1-arnd@arndb.de> <20190307091514.2489338-2-arnd@arndb.de> <20190307234850.nsbpkfcit3lnmytu@shell.armlinux.org.uk> <20190308095308.hjjrzdp4fzbbtnnv@shell.armlinux.org.uk> <20190308103429.ycasmpt6tcpsoqps@shell.armlinux.org.uk> <20190308105835.tovswk5rwxusmxdu@shell.armlinux.org.uk> In-Reply-To: From: Arnd Bergmann Date: Mon, 11 Mar 2019 21:58:55 +0100 Message-ID: Subject: Re: [PATCH 2/2] ARM: futex: make futex_detect_cmpxchg more reliable To: Ard Biesheuvel Cc: Russell King - ARM Linux admin , Mikael Pettersson , Peter Zijlstra , Nick Desaulniers , LKML , Ingo Molnar , Darren Hart , Thomas Gleixner , Dave Martin , Linux ARM 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 Mon, Mar 11, 2019 at 5:36 PM Ard Biesheuvel wrote: > > On Mon, 11 Mar 2019 at 17:30, Arnd Bergmann wrote: > > > > On Mon, Mar 11, 2019 at 3:36 PM Ard Biesheuvel > > wrote: > > > On Mon, 11 Mar 2019 at 15:34, Arnd Bergmann wrote: > > > > On Fri, Mar 8, 2019 at 12:56 PM Ard Biesheuvel > > > > wrote: > > > > > On Fri, 8 Mar 2019 at 11:58, Russell King - ARM Linux admin wrote: > > > > > > On Fri, Mar 08, 2019 at 11:45:21AM +0100, Ard Biesheuvel wrote: > > > > > > > > My first attempt (before finding the original patch from Mikael Pettersson) > > > > was to change the probe to pass '1' as the value instead of '0', that > > > > worked fine. > > > > > > > > > > Which probe is that? > > > > diff --git a/kernel/futex.c b/kernel/futex.c > > index c3b73b0311bc..19615ad3c4f7 100644 > > --- a/kernel/futex.c > > +++ b/kernel/futex.c > > @@ -3864,7 +3864,7 @@ static void __init futex_detect_cmpxchg(void) > > * implementation, the non-functional ones will return > > * -ENOSYS. > > */ > > - if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT) > > + if (cmpxchg_futex_value_locked(&curval, NULL, 1, 1) == -EFAULT) > > futex_cmpxchg_enabled = 1; > > #endif > > } > > > > Ah ok. > > That explains a lot. > > Can't we just return -EFAULT if uaddr is NULL? Or does that defeat this check? I think that would work here, it would just create a tiny overhead for each call to futex_atomic_cmpxchg_inatomic(). Semi-related side note: After I looked at access_ok() for a bit too long, I tried replacing it with #define access_ok(addr, size) \ (((u64)(uintptr_t)addr + (u64)(size_t)size) >= current_thread_info()->addr_limit) which interestingly seemed to improve the output with clang (it lets it combine multiple access_ok() checks and schedule the instructions better, compared to our inline asm implementation), but it unfortunately creates horrible code with gcc. Arnd