Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp6640409imm; Wed, 27 Jun 2018 10:43:53 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLwQ/ZrAUQ5V4m6aTsGOrlrkyxF4j1RbMGhUDxctxlr9X9x/TuzMJy1L5Hzlj4C6AWsAeFu X-Received: by 2002:a63:91c8:: with SMTP id l191-v6mr5903253pge.180.1530121432935; Wed, 27 Jun 2018 10:43:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530121432; cv=none; d=google.com; s=arc-20160816; b=G0FLHcINDMR2jguo897k2GlHi5IkhvbWewgiNR7Gg7fxVA8Y8Q0kOoYQcpLWWXj6j/ D4BVz+htPCB0bbboPK/BQzIEf+s8Jjt+61G/sSasrGETmPS/t4meqQDeseWd/zs9qeL6 UlS+AoWBG7fsJ/n2NcjunTaEH09t8yj6+nok6AzohUJo6t/IyhH9TEQe8pwJ+yRqh0Mg 9HF2TPxV9dvwSGkHXRv7igt0d1OY6DPswvwIPw6AXDWTl11l8vA1uOprjfvM6YQFcKo0 mUJqwgjgP2z04CA028zP2Y2swAZtOseECkhCKP6bBECtzYiWZ2ZDNwus2Bjp7SoWIvMI 8i4Q== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=9EaVJyNOM2Blcaa/tm2TGOUCWmXDP+G1pKMt9UlwkPo=; b=O3yc0mRf9MCQIZhulUNm13x5hLdc2WPGZEUPXUjFAV3cV83Xzze3OEq7ZiuN3Yh2tN 7/V5GjtGJieMPCXAaGAbTaqyJDVz/Gz7VpY6KjLqGbwMhj3pupzlPw79pmvGlaP5SQ3l /Enk5U8tbpXTRyZ9d1AgF6H4rxwQTrpS6THZheM3GhA0/HVx4Q559raCvf6j5nKi030j SWqlvefD2iFcJ6fwJhX5M0+qLSaoxpFjQFlsvDR3594TnYiOSoZjWbsF9qurLzO902DF vQ3UQ+dinkybUpffKdIQiFtCAClAIwH+mrPHR4nCPHpx44Sm8BJN3AzuhWrdOiwDP3Nk mV6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=P8nL5kyi; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12-v6si4423851plg.154.2018.06.27.10.43.38; Wed, 27 Jun 2018 10:43:52 -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=@gmail.com header.s=20161025 header.b=P8nL5kyi; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965487AbeF0RdI (ORCPT + 99 others); Wed, 27 Jun 2018 13:33:08 -0400 Received: from mail-vk0-f67.google.com ([209.85.213.67]:46526 "EHLO mail-vk0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965055AbeF0RdG (ORCPT ); Wed, 27 Jun 2018 13:33:06 -0400 Received: by mail-vk0-f67.google.com with SMTP id b134-v6so1650567vke.13 for ; Wed, 27 Jun 2018 10:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9EaVJyNOM2Blcaa/tm2TGOUCWmXDP+G1pKMt9UlwkPo=; b=P8nL5kyiKuZqi34L3TZbAiwmace3QMx2YmecQKguER/kQI58EIWWGSjAS/7jWb54a2 kisXj+rn5avbuKzPxh9bNb4MYAp8wZzbSa+zopTAi8lYE34SJBF0TqHXFB0yYLsJBYwI m6ULLcfJK/IImwXaiKT+BRfuzMCOCx5pUyJU3jB13BPnIknWCUKkWUNHYkM1X3fxLi2M UO8Z43Bhcmdj4L1mdKtrEgRUv8hJjVBNbYTla8ap4YqifidPjJp4XV90Y7dS+ZL/NjsH PMmYp+Z9zeNeCyiWUoYRiuTlRZ9borpoqqwxL+293gCgs4VeC8f3NWVLilAZlLm+jNmn UPOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9EaVJyNOM2Blcaa/tm2TGOUCWmXDP+G1pKMt9UlwkPo=; b=pghb5gZ+kYXMtauHDsl1jcTkIcANEb0xVRcsvAlY3TzzjPgwyrN3wowWXePBnQvdLQ umjRckdvkBWcUQH5yd7BwsjwTg1dQjO4M2V08x0TO+ST1BdoLStNpR9uWgmBwxgkfMxl 8hdBA93rTQdHsIkcCUtQCxWjXd6oBvGcnYOkNWjV+HIs1ejILy1Pjf/TN8Wit8gr7Dp9 4qDfoSdsEtNb2mlQGVaAf+CDWVlSqhVHn50yPT1psnBIPfCaNy9eXbhq/txL1mNfampM idF9HPpaQv59VcTw1zHY/GajlDVDocuAjh3Cn54JsZN0xXt6deL2fPQK17e1e4EJM/rS Ut3w== X-Gm-Message-State: APt69E0/ZX2xmYBKPow+zRsGO810JNa1mC0fVrmyHYpbhfYVeenqv0hx GeQc+Ud324psA/A6ErUPBCFhS3BfujNCb2LudRE= X-Received: by 2002:a1f:20d4:: with SMTP id g203-v6mr3203567vkg.176.1530120786071; Wed, 27 Jun 2018 10:33:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a67:8b02:0:0:0:0:0 with HTTP; Wed, 27 Jun 2018 10:33:05 -0700 (PDT) In-Reply-To: <20180626193040.GO2494@hirez.programming.kicks-ass.net> References: <20180625105952.3756-1-mark.rutland@arm.com> <20180625105952.3756-2-mark.rutland@arm.com> <20180626193040.GO2494@hirez.programming.kicks-ass.net> From: Andy Shevchenko Date: Wed, 27 Jun 2018 20:33:05 +0300 Message-ID: Subject: Re: [PATCHv2 01/11] atomic/tty: Fix up atomic abuse in ldsem To: Peter Zijlstra Cc: Mark Rutland , Linux Kernel Mailing List , Will Deacon , Boqun Feng , Peter Hurley 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 Tue, Jun 26, 2018 at 10:30 PM, Peter Zijlstra wrote: > On Tue, Jun 26, 2018 at 09:53:18PM +0300, Andy Shevchenko wrote: >> On Mon, Jun 25, 2018 at 1:59 PM, Mark Rutland wrote: >> > From: Peter Zijlstra >> > >> > Mark found ldsem_cmpxchg() needed an (atomic_long_t *) cast to keep >> > working after making the atomic_long interface type safe. >> > >> > Needing casts is bad form, which made me look at the code. There are no >> > ld_semaphore::count users outside of these functions so there is no >> > reason why it can not be an atomic_long_t in the first place, obviating >> > the need for this cast. >> > >> > That also ensures the loads use atomic_long_read(), which implies (at >> > least) READ_ONCE() in order to guarantee single-copy-atomic loads. >> > >> > When using atomic_long_try_cmpxchg() the ldsem_cmpxchg() wrapper gets >> > very thin (the only difference is not changing *old on success, which >> > most callers don't seem to care about). >> > >> > So rework the whole thing to use atomic_long_t and its accessors >> > directly. >> > >> > While there, fixup all the horrible comment styles. >> >> >> > - ldsem_atomic_update(-LDSEM_WAIT_BIAS, sem); >> > + atomic_long_add_return(-LDSEM_WAIT_BIAS, &sem->count); >> >> I suppose it's simple atomic_long_add() here? > > Different ordering rules for those two. I didn't look hard enough to see > if that mattered here. Indeed. So, to follow semantics it would be something like smp_mb__before_atomic(); atomic_long_add_relaxed(); smp_mb__after_atomic(); though I do not dare to convert that way (as I understood the simple atomic_long_add_return() variant might be implemented better). -- With Best Regards, Andy Shevchenko