Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753565AbbKLRrF (ORCPT ); Thu, 12 Nov 2015 12:47:05 -0500 Received: from mail-bn1on0099.outbound.protection.outlook.com ([157.56.110.99]:31185 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753118AbbKLRrD (ORCPT ); Thu, 12 Nov 2015 12:47:03 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=David.Daney@caviumnetworks.com; Message-ID: <5644D08D.4080206@caviumnetworks.com> Date: Thu, 12 Nov 2015 09:46:53 -0800 From: David Daney User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Peter Zijlstra CC: , , , Paul McKenney , Will Deacon , , Subject: Re: [RFC][PATCH] mips: Fix arch_spin_unlock() References: <20151112123123.GZ17308@twins.programming.kicks-ass.net> In-Reply-To: <20151112123123.GZ17308@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="ISO-8859-1"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [64.2.3.194] X-ClientProxiedBy: BLUPR07CA080.namprd07.prod.outlook.com (25.160.24.35) To CY1PR07MB2133.namprd07.prod.outlook.com (25.164.112.11) X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2133;2:x5XyGCL2jPPX34JHDWGjUFzcbuwD4opsFt2+It8kC37PEmETPKKUZS1pGyjRf7OdL2JdCBHxtAiETDzCqxhrxzTAAn2L8Qia5gF9CkMIbXZNKDcbEWL8jNmFrCzJBsRHOLL8+0imk9MdWSMt1oYYdkNgHVw5MK1cCnkAcFW+cDs=;3:Ahvdd4FYDAGxQp3npnh6cld6tXG/js3r5Y3EYx3jdOAfR+yutNDJ17tWxKdeDLeGfjC1fPCWWC6sChZMU1haYxq6ftfJjwwIeG2PnOy7JWc7VpWQK6fAeHSQGol/PpaBUYA1XuTYmJyVnvHB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am-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(2401047)(8121501046)(5005006)(520078)(3002001)(10201501046);SRVR:CY1PR07MB2133;BCL:0;PCL:0;RULEID:;SRVR:CY1PR07MB2133; X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2133;4:+fqqWACjKO0Tfqte54bu/QAI8XNFLwUnC9eGfs1zNPI275G7njuNs8jPvHTKFDt/Iz8/sLL4G4FLTQO92152/NxPHl2kRyNyoJSlSZdmkjhLsRaHTvbXqkEbI4VVXahXBz2YgyloCRDBQBnwtMEU+aLviVUefCTzZbFkmTL5PIq96H+rZDOwSG6G8Y/6320gSY3UoZC5HSpMbx7KMdvXhVqOt4cFfHBSc/MrtpC71Dvlj1YnMK/5Go/zfAq1bwk90DXGCYTgac57a1i55T9Eg7uwrw+3GXyXlfEgK5D3ao2Vkaq7UDCWbZeHoHUAbJbS0mbPcwN3E9RyFzJvtmpiOCjL+OGbo2nZJz9fgYHITnaTxxQsnniL+K4MDcgS/lA+ X-Forefront-PRVS: 07584EDBCD X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(6009001)(377454003)(24454002)(199003)(189002)(479174004)(59896002)(33656002)(80316001)(65806001)(40100003)(76176999)(105586002)(47776003)(122386002)(50986999)(106356001)(42186005)(83506001)(87266999)(64126003)(189998001)(92566002)(15975445007)(87976001)(101416001)(65816999)(54356999)(66066001)(50466002)(53416004)(69596002)(65956001)(23756003)(2950100001)(5001960100002)(5008740100001)(77096005)(110136002)(5007970100001)(97736004)(81156007)(19580395003)(4001350100001)(5004730100002)(36756003)(230700001)(19580405001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR07MB2133;H:dl.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?iso-8859-1?Q?1;CY1PR07MB2133;23:EYnNIT+MR/Zq+LhgQeXDS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?QdPQw8Z4thKgxGK9z3YeUNVTu6Mlw6qpVCO8z5DCEwaLNsIja+BKeT0JM4?= =?iso-8859-1?Q?8/vqtWS3gVECSfEYHIZHPhfy/AOnBW+eEluzLmK5hbZkGGZeLwpuzhLn2w?= =?iso-8859-1?Q?wXLNZVJYOa/WIiyvttKVnrwDe9smlrz1t5cPMf92bMoFUah+FiA561zfj9?= =?iso-8859-1?Q?zLnxaA/A2d85lDDYxpQLYUeXug01dcyL7G5HHKPvH9kF2n3k1QIvyJdc1R?= =?iso-8859-1?Q?ig+BE74qK5VR2OFIpqKsq/ziEgvZISl+W54HCDwJBoLi8sjv1NCHr4D+l2?= =?iso-8859-1?Q?mBWT5aaqeNlxZpjFOM4AQ8sqmXGBa1TS8fCVurPg36/dxjbtPF6VlrIIfd?= =?iso-8859-1?Q?2tVPZem3fUG61lLzBxIeTwU+KkxybnVHaGceL3il8UQc1/dbcMCHs/O17N?= =?iso-8859-1?Q?TXT1uQ5KXOrHtIhiHG1sW0m?= X-Microsoft-Exchange-Diagnostics: 1;CY1PR07MB2133;5:ql6Ls8VwmcW7s6kw2uu2rQteHbXBF7dZoZptbWP0MkIKzdrlp8kdqWw0Vjg032qWKPMc/tKETmNMLR5zR0be9QVQUL7fMXhpyLnzsDxed/YylD/6c2GWkjjz8h93XoIiqCbpifQ/wKiUzNr6ggw5iA==;24:9I6um59QLa3tJyLTumFzGkLRaHR3ps1BleeT2NiFlQ4cZ6Rpy9C2PkOvC0CBleMUpL2IdZ0/U8+evyvzh4TB7smMUcHf4u/GCK45jGhXX8s=;20:Dea0Gj1jzBBvFQlVc7NuB4VCerbelb/hZvTux3X8ZFStGqDlBPSnANCuluzmYXhQIJoFthgiM2YeB/GbxGUWtQ== SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2015 17:46:58.2539 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR07MB2133 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2821 Lines: 82 On 11/12/2015 04:31 AM, Peter Zijlstra wrote: > Hi > > I think the MIPS arch_spin_unlock() is borken. > > spin_unlock() must have RELEASE semantics, these require that no LOADs > nor STOREs leak out from the critical section. > > From what I know MIPS has a relaxed memory model which allows reads to > pass stores, and as implemented arch_spin_unlock() only issues a wmb > which doesn't order prior reads vs later stores. > > Therefore upgrade the wmb() to smp_mb(). > > (Also, why the unconditional wmb, as opposed to smp_wmb() ?) asm/spinlock.h is only used for !CONFIG_SMP. So, smp_wmb() would imply that special handling for non-SMP is needed, when this is already only used for the SMP build case. > > Maybe-Signed-off-by: Peter Zijlstra (Intel) > --- > diff --git a/arch/mips/include/asm/spinlock.h b/arch/mips/include/asm/spinlock.h > index 40196bebe849..b2ca13f06152 100644 > --- a/arch/mips/include/asm/spinlock.h > +++ b/arch/mips/include/asm/spinlock.h > @@ -140,7 +140,7 @@ static inline void arch_spin_lock(arch_spinlock_t *lock) > static inline void arch_spin_unlock(arch_spinlock_t *lock) > { > unsigned int serving_now = lock->h.serving_now + 1; > - wmb(); > + smp_mb(); That is too heavy. It implies a full MIPS "SYNC" operation which stalls execution until all previous writes are committed and globally visible. We really want just release semantics, and there is no standard named primitive that gives us that. For CONFIG_CPU_CAVIUM_OCTEON the proper thing would be: smp_wmb(); smp_rmb(); Which expands to exactly the same thing as wmb() because smp_rmb() expands to nothing. For CPUs that have out-of-order loads, smp_rmb() should expand to something lighter weight than "SYNC" Certainly we can load up the code with "SYNC" all over the place, but it will kill performance on SMP systems. So, my vote would be to make it as light weight as possible, but no lighter. That will mean inventing the proper barrier primitives. You yourself seem to have added smp_store_release(), so we could even do: smp_store_release(&lock->h.serving_now, lock->h.serving_now + 1); That would leave us to cook up a proper definition of smp_store_release(). David Daney > lock->h.serving_now = (u16)serving_now; > nudge_writes(); > } > -- > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/