Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4862530ooa; Tue, 14 Aug 2018 11:35:37 -0700 (PDT) X-Google-Smtp-Source: AA+uWPw8f9uecx8dFDjfgVslxVc3SaflczYmrtzpom7AplMyS0eCl5axYLP0egwBSAl3D76Q6yVC X-Received: by 2002:a62:b0c:: with SMTP id t12-v6mr24574477pfi.36.1534271737585; Tue, 14 Aug 2018 11:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534271737; cv=none; d=google.com; s=arc-20160816; b=ob8oB+lW44sHXWr2A8VY0v5odUIDwb3RLjCwcgL8MExNOKI5dpnazzAQoOdQwSaCyN IE5rgf71h4WG/FpnCx61Ruy7Gg6UnC0Lahc9lXM9WijSqxMmcm0xnQ3Rzp7EWAvdbpT2 vdQVA6oU6XRBXzfPHnDqdRO9r1nVxTtl7dli9FoqLv0d0JVCeh9bNw/7N1sTOT4r2jRZ yyZa9ayfHoqQBsDbAEmjP0Wcrcg6fJHdflSkTW45/d8Vhf+o0qLoPa3uT3Xum2QrrCKu vZ3J69lHckbWqIDOdoTk1uKRerMR0cxGSB5riprDDw1Yj6NS8Km4Idmwihh+O2BR+fPi hxfA== 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=2JzaO4YaxfIJQPRJFexQauhTefoAUb9Tb4X41Uepf88=; b=MY4HgoTsM+2ZmMsuHThYyNEeUpQeOlzNl98KgY/zRP8YlXjYyubYoZni+DHt5fZlOX AukM7ZnfOzjFz8mQGiZ7S1JUtAm8YSAVjB31MdeG+JkflRRdmqY7xbS0+DGzCA44SYCW rsh0STwPEpwSMPb2Cr86yS8+BA7VxIHJRfyTrVEGS4bDRkX3082M+yZpChDxnB/2cj+B CqcDUXEPnGEHJ8nBjS6RJVTz3y75aSVFX4czMbGxA+ucEuxbSWxEvBJ80PINz+Rf3D4r mQr7t0vv5ckJ1jdNg1yahtf+2SFIS+aco8d+p+6CVAlN/r/naKMVnML6pjpRZx9Q38Bm zA9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=e5ee8ktc; 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 t128-v6si22644641pgt.614.2018.08.14.11.35.22; Tue, 14 Aug 2018 11:35:37 -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=@amarulasolutions.com header.s=google header.b=e5ee8ktc; 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 S1729695AbeHNVWE (ORCPT + 99 others); Tue, 14 Aug 2018 17:22:04 -0400 Received: from mail-wr1-f53.google.com ([209.85.221.53]:44719 "EHLO mail-wr1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbeHNVWD (ORCPT ); Tue, 14 Aug 2018 17:22:03 -0400 Received: by mail-wr1-f53.google.com with SMTP id r16-v6so18006980wrt.11 for ; Tue, 14 Aug 2018 11:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=2JzaO4YaxfIJQPRJFexQauhTefoAUb9Tb4X41Uepf88=; b=e5ee8ktcz8koxZspRZBdUR1n7UkzN1jQs7oSI8lNIFnAfDuCpuG8gvrBGr0xlvF8DW c96kb8IeeADl6HNbPGVJpksxdYpRZxVsiz2LSzvNgpTxZUObti2SraboLXYTZuztnDUX wh9P5eVcNtG49HM2hX0NZD10CeTMLtrltfhIE= 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=2JzaO4YaxfIJQPRJFexQauhTefoAUb9Tb4X41Uepf88=; b=KPe1FmdXBCy9S5q0TCmcNCpopuQ8xda45i1tgnIfCFt5wn78ZJsfRbAzt7sfGvH7Kf UAyIOb3m9Mr2yT3YobFl/A+KZkXX59jFJpAPL5WzdSdHyTnDDKePBGiIe7hVVBD0bVRl I5ZTVMDVg2u6HPO5LIeNxUMwXkI1CXVoYstySwsuUuQvN3ZqQ6Kh3Q78+iYvkmvKdRDR StoWqgJF/MdSBWKti24pdYKHLWWL+pDLcFM1Ig8+fqRVdBaj7lXYlQ/s2FR8GRQy8Hv1 a9pQxbG1q74nkkdkhqYx52G4CNlb+u50eqfW0kyOMCcoFRSlp/zY2C0V3qwhBfN69dQP +oTw== X-Gm-Message-State: AOUpUlHV1rNVSxiA+pYKbX/uYPPTugxxSywM19qa/kYG4CjoVEe898vF CrwSFGrPd6+OSj7JAmGaU3FRxA== X-Received: by 2002:adf:c554:: with SMTP id s20-v6mr14096335wrf.46.1534271615160; Tue, 14 Aug 2018 11:33:35 -0700 (PDT) Received: from andrea (host47-68-dynamic.36-79-r.retail.telecomitalia.it. [79.36.68.47]) by smtp.gmail.com with ESMTPSA id u14-v6sm21770815wrs.57.2018.08.14.11.33.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Aug 2018 11:33:34 -0700 (PDT) Date: Tue, 14 Aug 2018 20:33:28 +0200 From: Andrea Parri To: JeffyChen Cc: Brian Norris , Marcel Holtmann , Johan Hedberg , "David S. Miller" , linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Norris , AL Yu-Chen Cho Subject: Re: [Question] bluetooth/{bnep,cmtp,hidp}: memory barriers Message-ID: <20180814183328.GA8874@andrea> References: <20180730031030.GA9430@andrea> <20180813231854.GA173912@ban.mtv.corp.google.com> <5B725A12.8050409@rock-chips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5B725A12.8050409@rock-chips.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jeffy, Brian, On Tue, Aug 14, 2018 at 12:26:58PM +0800, JeffyChen wrote: > Hi guys, > > Thanks for your mails, and sorry for the late response.. > > On 08/14/2018 07:18 AM, Brian Norris wrote: > > > >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. > > right, i was trying to avoid losing memory-barriers when removing > set_current_state and changing wake_up_process to wake_up_interruptible. > > and checking these code again, it's true the smp_mb__before_atomic before > atomic_read is not needed, the smp_mb after atomic_inc(&session->terminate) > should be enough. > > and as Brian point out, there's already an smp_store_mb at the end of > wait_woken, i agree we can remove all the smp_mb__{before,after}_atomic() i > wrongly added :) Thank you for checking this once again. I'll send out a patch removing these barriers shortly. Andrea P.S. I'm out of office for the next two weeks, so my replies could come with some delay until ~ -rc1... > > > > >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). > >