Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938933AbcKXMTX (ORCPT ); Thu, 24 Nov 2016 07:19:23 -0500 Received: from mail-sn1nam01on0067.outbound.protection.outlook.com ([104.47.32.67]:25376 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934732AbcKXMTV (ORCPT ); Thu, 24 Nov 2016 07:19:21 -0500 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Nicolai.Haehnle@amd.com; Subject: Re: [PATCH 1/4] locking/ww_mutex: Fix a deadlock affecting ww_mutexes To: Peter Zijlstra , Daniel Vetter References: <1479900325-28358-1-git-send-email-nhaehnle@gmail.com> <20161123140336.GU3092@twins.programming.kicks-ass.net> <20161123142525.ns2pkyp4bo2sa5z2@phenom.ffwll.local> <20161124114007.GE3092@twins.programming.kicks-ass.net> <20161124115601.GR3207@twins.programming.kicks-ass.net> CC: =?UTF-8?Q?Nicolai_H=c3=a4hnle?= , Linux Kernel Mailing List , stable , Ingo Molnar , dri-devel , Maarten Lankhorst From: =?UTF-8?Q?Nicolai_H=c3=a4hnle?= Message-ID: <6ab13a2e-fea0-55b0-8828-150d99ae6fef@amd.com> Date: Thu, 24 Nov 2016 13:05:01 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161124115601.GR3207@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2001:a61:11f3:a101:1c57:b5ac:d8d1:6bf] X-ClientProxiedBy: AM4PR0701CA0038.eurprd07.prod.outlook.com (10.165.102.48) To BN6PR12MB1187.namprd12.prod.outlook.com (10.168.227.9) X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;2:6xDLjs8okG0VkyAwN/6n98exMdXNP5Poce8SgjZHZgf7UtKVal7G9nvIaCLfO/y3GJuYu5S3l3PlqUF3qeTv/16CoF+VCjH6LcBP0rgwinvVAYiwBPay5/STSK1ddpIRTmn+XojJexTsNUSs3M/jxnArS3m236/NvvwEQNmtpnk=;3:Emq+PIfqbbZjEiQKAjFr4myBjlpx2fZQC/imqfW0phbdQaZau0wUrizwEi9ajAj56bXqNu36LBS9iVZLnAWGJJeiBsIH+S17p2dO3aSaBMPHhWqA9X+HvyGI1oOgVzPwsnEw8pOG7z3I32rilMi2okP4bHI+cNoyNrL/z/esTLA= X-MS-Office365-Filtering-Correlation-Id: 5afb469f-5991-4a31-2fdb-08d4146226b7 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:BN6PR12MB1187; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;25:icKfAnpvxFsN2qHV/o1saVC2hUxZhOD9Ogw8hb5UhVGW6q87/IUp2CYtcKHh9A385os5XqUxRrNSU5DoqabYmQC3/1rx1M4EANVlE4kYAI2ifM0J71zf3tpFcUicNvhaRBKzoGKc2ZuqZQXFlNtMM870JvGmPbKzl5iIbvT0+vX/eGhIyIq0+kxXb0G3vmQ2nDwLOtX32Exh1sAM4zU33h5Pn/1gCv9ptX9LxLu95wgGMVG01LpjmgcNjWMgFLKrgt58z4l3Ssh8ByfVkM6Kn1aL+mvTU470qUXkW1WR/S0v4ZyhZqECov6qreldhelrpclVcODg7766DRtZUdIeEwaGHENnY1Tm/y1auv8sFo9jEeHpwk0Awq3n9yg7kNWQdBXOAr9erTVLeIYvWTIEXYu4SoCAn0BGStwj8/SBUPUYCXh+hx3Njp7Q1qDx2K7MxdFt7TTiJ0NgLlFXn36chs54PrCDf0+JlBndLJWmXjzV808uTPdVla5EUwCIudrs2dR0pEREQVjOSOjUWUw0pfC1wyk4DTBBKaZUzEEdp1QhnYWexD+rjtF2Vd+/9YQVyin/cJjxykQV7JuOFDpsgcJs4SqQ3/H3gDc2VqfNjnEOMfumW+o+njot5g2h4Qu50Lc1uywjpTt9/FdJz4lG/RAVxC/m+ab0tpZX0YyIRIH+o3UtJ8LXffBRqWTBVu42IU3eiyJLRhNTGcK4BVGMRF9tJAVpOTrD8t3mYnDDVsN898KdeKdhmslt+UZI+rvmJ6JVlgfCY+1JFA6TFIYiVigYP4lhZaUeTQmf0LdtNh0= X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;31:HWbKR3+p/5uHhQ1mzB3jHCkORdKp9hMr1phx8Lm6G7+o+Slk1alC0ClDtEHyOzDbyWS58aTflpqXWKJDsV9FoMDwPi4liZHEFoMNeP4wYaJqW9LRg8qk5Wt2XeIhOgELIoDBP8QF3T6qpbZh7W3uyI7gNSl3bl/GmQo6qqaZ27lAplpQ4GUt0qQ239JyptfM4eOQMH+tfRLc5bkUjXvnvf8X07mx+DoijbAtXGDhMB6EZ3rGe3UOSiVLc8DiYsendiAVKa1pH80FWK2TuXnqzA==;20:j3tEjrthrUK0+XhhIq4Vc7178CA99h/XVPZUfpryAQC5lmLWXg/nWXxhiM893DAyDpZkDR8dHrcJZokD/919sNIf9kzwgIwb6dhHmsDF3UDwJeQCmBoXygyhZEObJDZ4+S/KBJ9GT59eq4qUF4j4Mx2tu2Xpw/GCU8uxeGCj18Gr8zCjTk2NRqZgmgesgiJUttse4u0vcHny0r5Z7Y5sQw0xmZ4raQX25BuYCGwRb3V9hGOtcNU2DM4awsxF2hrDOlaeaQfkfpr223BaiBUV7uflIpiP3rvAX8TV895Q3XDq497IaBvLV9a0o6vE8xg8bE5YFe3ce1lcuwObGxTovYql5SeIPrXV6cyW5q/S4X9aR0MHe//qqKWaraLySCozR194vVfvL25AcaPGLZui4cq88DICu7+1A6taq5SqMM/OD0EjEvdrAPQwP6kKKcoFF4tx8pxUREbMr97RVpkwxvXLvoA7KysFgCbA+UbDl04um8eC3rbxa5MIgKd71kk/ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6060326)(6045199)(6040361)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001)(6055026)(6061324)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123558021)(20161123560025)(6072148);SRVR:BN6PR12MB1187;BCL:0;PCL:0;RULEID:;SRVR:BN6PR12MB1187; X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;4:CQQojzyeGfjsHacMeYAN3d2BJ2iPL0DZnsc1dkNw27d2ssv04VNiQwC39uukP5sHxH3t5sgY8aC8nIFT8JYDeJbFByNCMD/1TUiol9Pp2UuBWSsxEQXCtduE2mBUeUw3AHkEI06jmF7O9+NEvGJHH1/SIScyw2qVNWIDlheyqjcaVsXUrxiJoepd6lnEfxQticD4A9+z/uhHOpGP/crt5dlOZd5QO7QjlTSAO9/CFE1g02IzedYDXEG0lnnBBxnXvSg1gf4B25o/Boy3z+NTxyyWQ5PUMRwLKMBU7+oXns8tDQqMDKJk8Bs2QGfqcogncAZoyEVJ9NjC/tzn6wSmTDXRO1SWAKvvbggcIoZK1+I9AICTgpUzYJKD2GII2JtPe//mr4boHhL126KG9J39LGC1+XpkJTCwzkjWPbYoRLZyWc2Ez68p+tpSL9j+IVcALfRQxxqdzT+jQ+qZaIAfYfJ7ovDKcYgGrj/vT6LuBDvILj9cKI/roIcjKhaq/GACgKV3pqftUmQeR9P0AwBRgPTZ7ijeYwezZu+SxpVi2HkHIRBvdwoQHQp34Vi6RbsqNCG4cbKiC4R8R2NXK0dS2hVlEuP9ic8Pc9T7s9um8V8UtWb3jhiEE5rvTqLNTQZ/4Yzj5A9ndfBMeQaWgEDlZ7i7lml4FisYwTNrmZPUMQCVo9/7EvYekwnkmcbT8UT6 X-Forefront-PRVS: 0136C1DDA4 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4630300001)(979002)(6009001)(7916002)(189002)(52314003)(199003)(24454002)(377454003)(31696002)(65956001)(97736004)(189998001)(23746002)(5660300001)(4001350100001)(5001770100001)(68736007)(33646002)(47776003)(65806001)(36756003)(77096005)(229853002)(93886004)(39060400001)(39400400001)(86362001)(39390400001)(64126003)(92566002)(6116002)(81156014)(1706002)(81166006)(4326007)(305945005)(7846002)(38730400001)(2906002)(39410400001)(39380400001)(54356999)(50986999)(101416001)(76176999)(50466002)(42186005)(83506001)(7736002)(230700001)(65826007)(6666003)(2950100002)(8676002)(31686004)(106356001)(105586002)(969003)(989001)(999001)(1009001)(1019001);DIR:OUT;SFP:1101;SCL:1;SRVR:BN6PR12MB1187;H:[IPv6:2001:a61:11f3:a101:1c57:b5ac:d8d1:6bf];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;BN6PR12MB1187;23:gtB6s0/kUS2UWQrkiQ1MXjGumTWUFxCUhPjy0?= =?Windows-1252?Q?AvzaBgh4jNY6salMT9UYYd0pxhHYYLnl39zMHBQiseknEHEUtpTGDvSd?= =?Windows-1252?Q?9toQ9W28Tnt7aeOtQljsvNjJYJfdx8wGj10R3LsMZM3vhX2zQwNdLFzR?= =?Windows-1252?Q?1bM+JukAoEB2pctNFD0PRPBnJnAX52RDfi8G+1FznG/F2u7u64SJrPxs?= =?Windows-1252?Q?1rxrg1uiAcB8e4X43KLrI+poJBWbSEAbliSm5T6YKoL5UKKlTxpVlwqk?= =?Windows-1252?Q?YKGnNURa96UFLxXPaQ9UV1ZjIolCSbeHt8ORd82E5JpDgBY8mpUHZiNG?= =?Windows-1252?Q?xSTqDVY84owrBwmbr4g6G/+l0WzSxtGWH275uhH1vbAp6Hqfjf9jaqpq?= =?Windows-1252?Q?3ebtQiV2uheZJzrpVZjLYIX7bhynZTFLks/MX0qSgbp7KP4gwgAJdihu?= =?Windows-1252?Q?CkZ/K5gneiT0Is5VISBdBtTl1CQ/+/6W3FM4qRHXk27ha2B+XinDBN0i?= =?Windows-1252?Q?YhCshRSnsBXLcZrnWC7ZsSJVrMofNz3RjEw3XzNCTmC11ADzuzS0rsiP?= =?Windows-1252?Q?6/4dPIkREDWPY74xQEVc6rhXQeVZUp5BT5sj5JWo8dDWdDatenmhy/WJ?= =?Windows-1252?Q?r+6vPHUIutjpTjX/6vr19nU1SmvEAOgB5VciHSwyifpGYlmybyfT5eu7?= =?Windows-1252?Q?Bdb7KiJ21jEQLQukC8LptRRkUE2IpJyeA23oPybgVH8wifZyhD6HNwjW?= =?Windows-1252?Q?WpFZUSeer+0JJixHNaa8KmRvUwG8Pj79/mnIAuKsr5qPfQtMgG7AxwK2?= =?Windows-1252?Q?KyfCmu33hvqLAQqWYPzrJECPYBcXViS9x6om6mRK94rcfQxMDdOj8Ft6?= =?Windows-1252?Q?F9asHHnWaqaU032KOguabbBXhhW/bxJl4sxzUZ9YlF7tVKLsLDNCG9Se?= =?Windows-1252?Q?sCc9GhQpkLGc/aCHpTxVaKeu2Jw+Ru1UK4oKe8p+6ycqINwZoJ37vg3u?= =?Windows-1252?Q?6SnsAkl8NSrWA2/hK7OrYau/u1kwUWLZFGrShqS1jvHGwDb545NaNMe/?= =?Windows-1252?Q?XBCrtR405uoBNCE6SF9LVjH+2u6n7TLnBmfueKorh7kFWHKDEno02T4c?= =?Windows-1252?Q?8tbrn7h3V4aaby5c+YoR2kgeuC6E7ogRCxZ9/dMQ3IOR2chqwkS6K0Ya?= =?Windows-1252?Q?/3w7qJxX6Sh2XRhnyZTIGyqUun3qgZlivXmp2DGu8JNMoXHuHSCSiuBp?= =?Windows-1252?Q?ecKJbJqj6iUVV6QSgp8uIQ6L+rzq9FwQJzmbY6SZ1ewF04Je+Eo4sy7N?= =?Windows-1252?Q?pKEvqUq99lRYRLXUpWP5QHu623PeXFOngHtnoYtcT+5pfF8EZpzEj/rX?= =?Windows-1252?Q?m7RPKf9NKK9VzEAMs9TUvhLz/hGz0phASdY4Krs5nDLtZtX2VjFQr0My?= =?Windows-1252?Q?zp5ZR71euEH/18ScY2256hJGHh8Ef4kNwJy7AbGyQklrfZk6f2vXEeF7?= =?Windows-1252?Q?U15LomLHu5CHyzUbbmTOXFEm0uWahQ6INs4JGanb31GQhNw14ARtB8za?= =?Windows-1252?Q?cs/tp52ROToB9rasq0UlutcHmKBnMCIHFuXaIox+xw4RE5Ta7nlmWB15?= =?Windows-1252?Q?lhk78sd21KOvb+IUPyKPdcBPOxUM2AN9So+epDDVRKb?= X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;6:sEvx545zidIFi8AlWBclNFiz7oOguzzovz+UQc8fVMoSWDIRUcAIpZLJ1nhK04f7jHPk9X1wGAEyNprHM6+DOkT2Gu9en4UzimgKYz0Y0o8tAAgitpmRZZua9iS5evAYTAsSMIY2rBIr7z0qsVSm+xuw7em3Dp8ndRs1BLXnJO46hz2v9geq/HORGeA/55i8aB9M0Eh8OdoGrhmnTl18kFFN6KA+GbysIdkqr29TK1vY8Kn37WbPVInFANbxb1dUr3hB9zNwjcRb88qtzjwoT/ZGC3RNQvljH4qqt33cpZO6BZG/jLIcdLyaG/3ZvlsCNEhTacBf+qTVpbF8KlesHF32riMkGpULT1eLNACk/BDLlGEKhDAEISGYCO75WnSy;5:5WAlDS0UaHL59EtVdl5Mx84XafY0+y74NHwdfrwAteCbo9EOiG2Koy9NUjW+J4gFPcLflkGMUkzluoH1DsVpJkibN/iHtiCHKcdm/Z/fce05BKgffY+BO/c8GDDeTZRbUNfn3kJMUtMdrRrm58lICA==;24:5ACuDAgyW2M3qu8HCLtHo/nv1uHXnLYwyxEwUuP7tQ1v29lFXy39IRIMsiRNz7pr7qvk+h8sPmLMXYZrIwKN+Gd5MWb4voG/DUQ3SV4cjCQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BN6PR12MB1187;7:aKc2NuO+8X3sWk6egZ6uKadFFuqbeSR9dD0pp3wk5tW/aJSpj3m52mqTbf9tkBOWCPZuwOd61jCphWbgtBclFT5YWXZU/GA3YKG2uQOmUVHb5h5sh9t5UhAsDT8E4GDqCgfypmlDJPvB+K6onaFqPtFSr8s/dfgwMUHsT0cHBBlh2KjNMcNBe4oIuiDmN13BBVVkFQiM95edZEGPyQGWrb6xxbtfvRLn2BNNv7hDPTaUsdNvnm654//j6NM4Dfx5cpCj/JeOuhj54eq88YlfdzwvITjpWN4zCPRmwp5UPdSWBdKALUEWZQ8+cJUMFkZ7zdb/RZQ9uqHl0ggu7jhVotv5wMoY86z52FWp3HZ7wis=;20:zLnRnWYHFJntsV0yyWY5WIIK1cwiS93GeD701RXgx030XoyxXf/2e8FoVXXAY3z4dJaA6OS+a+fadLSknUgI5g0R8mVqG+RV4hxiQODSo2v+gPQi42/YznS36OoOnaWN6PtHQ2hTpoYaP2/ZftL+7a7IMTrM73Ywos5pmNHboPXQA3JUVXTFNbC/clbSeUvz0sPDA6yHqK3XoDgdzXLKie2bx5UFgJREoaL/bi/Nc02Boti6Hd5rHh2ZL6a0MW/v X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Nov 2016 12:05:13.7928 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1187 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1666 Lines: 35 On 24.11.2016 12:56, Peter Zijlstra wrote: > On Thu, Nov 24, 2016 at 12:52:25PM +0100, Daniel Vetter wrote: >> On Thu, Nov 24, 2016 at 12:40 PM, Peter Zijlstra wrote: >>> >>>> I do believe we can win a bit by keeping the wait list sorted, if we also >>>> make sure that waiters don't add themselves in the first place if they see >>>> that a deadlock situation cannot be avoided. >>>> >>>> I will probably want to extend struct mutex_waiter with ww_mutex-specific >>>> fields to facilitate this (i.e. ctx pointer, perhaps stamp as well to reduce >>>> pointer-chasing). That should be fine since it lives on the stack. >>> >>> Right, shouldn't be a problem I think. >>> >>> The only 'problem' I can see with using that is that its possible to mix >>> ww and !ww waiters through ww_mutex_lock(.ctx = NULL). This makes the >>> list order somewhat tricky. >>> >>> Ideally we'd remove that feature, although I see its actually used quite >>> a bit :/ >> >> I guess we could create a small fake acquire_ctx for single-lock >> paths. That way callers still don't need to deal with having an >> explicit ctx, but we can assume the timestamp (for ensuring fairness) >> is available for all cases. Otherwise there's indeed a problem with >> correctly (well fairly) interleaving ctx and non-ctx lockers I think. > > Actually tried that, but we need a ww_class to get a stamp from, and > ww_mutex_lock() doesn't have one of those.. The acquire context needs to be live until the unlock anyway, so this is something that requires modifying the callers of ww_mutex_lock. Those should all have a ww_class available, or something is very wrong :) Nicolai