Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp3695474ooa; Mon, 13 Aug 2018 16:37:07 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw2/CcV3AcM2FVo9CE5Mrfb161grNxpRKm6ynVVvFyvLjymAO/sFo9wucwp6z5kzrzZWJ4k X-Received: by 2002:a17:902:59da:: with SMTP id d26-v6mr18326805plj.42.1534203426945; Mon, 13 Aug 2018 16:37:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534203426; cv=none; d=google.com; s=arc-20160816; b=JiRCPhPMS2U5ztQ/4L/TrDEcObloQxRAgXnPmmcfknHpZW/woM1xtPU+7dK09RRyIY Z5iwmOIVsHGiclKHasipUe100FrslQPBGdZdBTe2SjDWLTeuIbZpGtz3XRJpa9EEpTEh KwjqOIhUe1bfyGWMbfldMwBCmOj2uYq5QQC063ggaI2uwxtTgH4WcONT0CcCDG4rvqm1 2q4mWKVLEZT/C71JP/I2PEIjkft4dSy6RqowoiiSmye6xCaJRzHfS57vbXYNSZVFAgcL rLq0G48WDbM4U611yv5MHCrJ1yR7/AhujPOBEIQy8hQcoHJmv/LyQoxVsoTg/84s/BQN PJ0g== 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:arc-authentication-results; bh=RM563o6Hx84A95xvuO+qAsVrNZfo0NVHUPDxOl7TDcU=; b=PdisSjNtTcr9xlXwVVer/SkrK59gC5ujzKe9KLTiczKUsy7+Mfa/SAThnd5iLFmMok 7Rz3KoAKWbl1wM3p6kaJ8axOrqaNuOTESNVHSMu6LmBVqfB0o333YZ92HwQoEaO8oWNZ 0Q4fMayOEpWUe9RCUwcPwR5HzVen4wMdlFgCSMhZE5ur9vx/jh9b2eWDQwmLqfs+7kqK KX5ocqh9AVX3LSWeW2sOJxrQ2s+WUviVGmuWd6xihtxX2uLBTEqyua0cFW40z8Upq2LM y6cjGrWTIybTcw9otemzFDV8GzCSGSshgbMt4XegT0m9YuvUGd6NYfzL5nt74XWCPV5Y rrwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=sqdXZViJ; 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 c83-v6si21422952pfk.361.2018.08.13.16.36.46; Mon, 13 Aug 2018 16:37:06 -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=sqdXZViJ; 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 S1732190AbeHNCDW (ORCPT + 99 others); Mon, 13 Aug 2018 22:03:22 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:34242 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730203AbeHNCDW (ORCPT ); Mon, 13 Aug 2018 22:03:22 -0400 Received: by mail-pg1-f194.google.com with SMTP id y5-v6so8230561pgv.1; Mon, 13 Aug 2018 16:18:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=RM563o6Hx84A95xvuO+qAsVrNZfo0NVHUPDxOl7TDcU=; b=sqdXZViJJtPIOR2ey1IAe/I65LtlNlif7397bxvukw5fLDLS0dilZ13XyTHufvid72 9NOY+K/9plC4cNUEfRYSB0KDVX5iWn/QOFo7gjyTKhsYEHaQUxTeqTiYQV0Es+0iYXCG fmsMap4cdL9BU+wzz2e5MlKxBlYzcKltXn5VHZvyiMAsWXX7Gmv6TiGumbqqxIEUsgdF XtGgSqLGyRxfBAnywa//dkQ53ZUPwiaCUMB4/bgqPAYlr573buKX8TB0riNTb39gG+Gj SFLPDu9hsAXnZ+arX0Y6cR/wDaXwM0NkMxi7W02U7O5wydM3euCUQE0tUB7qsbMHyrQL 3vcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=RM563o6Hx84A95xvuO+qAsVrNZfo0NVHUPDxOl7TDcU=; b=lEJNOjHEelQUS+FdhUBr2TSE4UXrvmU0vj+U7u7R9X9ESTdHnJiKnvWXXQ4qiMeu1B lzq/eeKHAGGuctn0QLV1n5VC8UaXkU1KC5Ywh5CW3N9/TQpBGKPo/FUCL9xBz7jnS5YY GKWybrvHcuvdoUOJdY4ItMj+B3hg9kbrv8f7ehrSv3zYhjKImRANxg2YYWfRaRwrK6UR SSPy9VqLikKF6IQedPtnUUMfHGGO3XLOUh5VUUAEllR1IBG5AHAcNO4IqUo2ZLREZlGE D/p68AWEI7YAS586lE0/2ZaIykggyZAiPnux1aGs47/JBWei355ATtaD/w0VhXZiPT7K X8fA== X-Gm-Message-State: AOUpUlG5q3vzSpu8Xj6iacTay+k35o1xsmTww9PW5TBXqP1dgNiNln8Q P3ksMPZEoCFZSI3vZTHohVE= X-Received: by 2002:a63:144b:: with SMTP id 11-v6mr19195348pgu.219.1534202338509; Mon, 13 Aug 2018 16:18:58 -0700 (PDT) Received: from ban.mtv.corp.google.com ([2620:15c:202:1:299d:6b87:5478:d28a]) by smtp.gmail.com with ESMTPSA id 1-v6sm42142159pfm.145.2018.08.13.16.18.56 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 13 Aug 2018 16:18:57 -0700 (PDT) Date: Mon, 13 Aug 2018 16:18:54 -0700 From: Brian Norris To: Andrea Parri Cc: Marcel Holtmann , Johan Hedberg , "David S. Miller" , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jeffy Chen , Brian Norris , AL Yu-Chen Cho Subject: Re: [Question] bluetooth/{bnep,cmtp,hidp}: memory barriers Message-ID: <20180813231854.GA173912@ban.mtv.corp.google.com> References: <20180730031030.GA9430@andrea> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180730031030.GA9430@andrea> User-Agent: Mutt/1.10.1+48 (1f3a9df87d11) (2018-07-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 30, 2018 at 05:10:30AM +0200, Andrea Parri wrote: > Hi, Hi! > I'm currently puzzled by the the three calls to smp_mb__before_atomic() > in bnep_session(), cmtp_session() and hidp_session_run() respectively: For the curious: I believe Jeffy Chen added all of those. > On the one hand, these barriers provide no guarantee on the subsequent > atomic_read(s->terminate) (as the comments preceding the barriers seem > to suggest), because atomic_read() is not a read-modify-write. I'll admit, I didn't notice that piece of the documentation when reviewing this the first time: Documentation/atomic_t.txt The barriers: smp_mb__{before,after}_atomic() only apply to the RMW ops and can be used to augment/upgrade the ordering inherent to the used atomic op. > On the other hand, I'm currently unable to say *why such an "mb" would > be required: not being too familiar with this code, I figured I should > ask before sending a patch. ;-) I can't fully speak for Jeffy, but I expect based on the initial development of his patches like this one commit 5da8e47d849d3d37b14129f038782a095b9ad049 Author: Jeffy Chen Date: Tue Jun 27 17:34:44 2017 +0800 Bluetooth: hidp: fix possible might sleep error in hidp_session_thread that *some* kind of barrier was stuck in there simply as a response to comments like this, that were going away: - * - * Note: set_current_state() performs any necessary - * memory-barriers for us. */ - set_current_state(TASK_INTERRUPTIBLE); + /* Ensure session->terminate is updated */ + smp_mb__before_atomic(); It was probably an attempt to fill in the gap for the set_current_state() (and comment) which was being removed. I believe Jeffy originally added more barriers in other places, but I convinced him not to. I have to say, I'm not really up-to-speed on the use of manual barriers in Linux (it's much preferable when they're wrapped into higher-level data structures already), but I believe the main intention here is to ensure that any change to 'terminate' that happened during the previous "wait_woken()" would be visible to our atomic_read(). Looking into wait_woken(), I'm feeling like none of these additional barriers are necessary at all. I believe wait_woken() handles the visibility issues we care about (that if we were woken for termination, we'll see the terminating condition). That's my two cents, even if it's only worth about two cents. HTH, Brian