From mboxrd@z Thu Jan 1 00:00:00 1970 From: Will Deacon Subject: Re: [PATCH 1/1] iommu/arm-smmu-v3: replace writel with writel_relaxed in queue_inc_prod Date: Wed, 21 Jun 2017 10:08:03 +0100 Message-ID: <20170621090803.GB3768@arm.com> References: <1497956694-11784-1-git-send-email-thunder.leizhen@huawei.com> <5949CBB7.1030908@huawei.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <5949CBB7.1030908-hv44wF8Li93QT0dZR+AlfA@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: iommu-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: "Leizhen (ThunderTown)" Cc: Hanjun Guo , linux-kernel , Xinwei Hu , iommu , Zefan Li , Tianhong Ding , linux-arm-kernel List-Id: iommu@lists.linux-foundation.org On Wed, Jun 21, 2017 at 09:28:23AM +0800, Leizhen (ThunderTown) wrote: > On 2017/6/20 19:35, Robin Murphy wrote: > > On 20/06/17 12:04, Zhen Lei wrote: > >> This function is protected by spinlock, and the latter will do memory > >> barrier implicitly. So that we can safely use writel_relaxed. In fact, the > >> dmb operation will lengthen the time protected by lock, which indirectly > >> increase the locking confliction in the stress scene. > > > > If you remove the DSB between writing the commands (to Normal memory) > > and writing the pointer (to Device memory), how can you guarantee that > > the complete command is visible to the SMMU and it isn't going to try to > > consume stale memory contents? The spinlock is irrelevant since it's > > taken *before* the command is written. > OK, I see, thanks. Let's me see if there are any other methods. And I think > that this may should be done well by hardware. FWIW, I did use the _relaxed variants wherever I could when I wrote the driver. There might, of course, be bugs, but it's not like the normal case for drivers where the author didn't consider the _relaxed accessors initially. Will From mboxrd@z Thu Jan 1 00:00:00 1970 From: will.deacon@arm.com (Will Deacon) Date: Wed, 21 Jun 2017 10:08:03 +0100 Subject: [PATCH 1/1] iommu/arm-smmu-v3: replace writel with writel_relaxed in queue_inc_prod In-Reply-To: <5949CBB7.1030908@huawei.com> References: <1497956694-11784-1-git-send-email-thunder.leizhen@huawei.com> <5949CBB7.1030908@huawei.com> Message-ID: <20170621090803.GB3768@arm.com> To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On Wed, Jun 21, 2017 at 09:28:23AM +0800, Leizhen (ThunderTown) wrote: > On 2017/6/20 19:35, Robin Murphy wrote: > > On 20/06/17 12:04, Zhen Lei wrote: > >> This function is protected by spinlock, and the latter will do memory > >> barrier implicitly. So that we can safely use writel_relaxed. In fact, the > >> dmb operation will lengthen the time protected by lock, which indirectly > >> increase the locking confliction in the stress scene. > > > > If you remove the DSB between writing the commands (to Normal memory) > > and writing the pointer (to Device memory), how can you guarantee that > > the complete command is visible to the SMMU and it isn't going to try to > > consume stale memory contents? The spinlock is irrelevant since it's > > taken *before* the command is written. > OK, I see, thanks. Let's me see if there are any other methods. And I think > that this may should be done well by hardware. FWIW, I did use the _relaxed variants wherever I could when I wrote the driver. There might, of course, be bugs, but it's not like the normal case for drivers where the author didn't consider the _relaxed accessors initially. Will From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752149AbdFUJHy (ORCPT ); Wed, 21 Jun 2017 05:07:54 -0400 Received: from foss.arm.com ([217.140.101.70]:48976 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750927AbdFUJHw (ORCPT ); Wed, 21 Jun 2017 05:07:52 -0400 Date: Wed, 21 Jun 2017 10:08:03 +0100 From: Will Deacon To: "Leizhen (ThunderTown)" Cc: Robin Murphy , Joerg Roedel , linux-arm-kernel , iommu , linux-kernel , Zefan Li , Xinwei Hu , Tianhong Ding , Hanjun Guo Subject: Re: [PATCH 1/1] iommu/arm-smmu-v3: replace writel with writel_relaxed in queue_inc_prod Message-ID: <20170621090803.GB3768@arm.com> References: <1497956694-11784-1-git-send-email-thunder.leizhen@huawei.com> <5949CBB7.1030908@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5949CBB7.1030908@huawei.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 21, 2017 at 09:28:23AM +0800, Leizhen (ThunderTown) wrote: > On 2017/6/20 19:35, Robin Murphy wrote: > > On 20/06/17 12:04, Zhen Lei wrote: > >> This function is protected by spinlock, and the latter will do memory > >> barrier implicitly. So that we can safely use writel_relaxed. In fact, the > >> dmb operation will lengthen the time protected by lock, which indirectly > >> increase the locking confliction in the stress scene. > > > > If you remove the DSB between writing the commands (to Normal memory) > > and writing the pointer (to Device memory), how can you guarantee that > > the complete command is visible to the SMMU and it isn't going to try to > > consume stale memory contents? The spinlock is irrelevant since it's > > taken *before* the command is written. > OK, I see, thanks. Let's me see if there are any other methods. And I think > that this may should be done well by hardware. FWIW, I did use the _relaxed variants wherever I could when I wrote the driver. There might, of course, be bugs, but it's not like the normal case for drivers where the author didn't consider the _relaxed accessors initially. Will