Received: by 10.223.185.116 with SMTP id b49csp705760wrg; Tue, 20 Feb 2018 06:36:25 -0800 (PST) X-Google-Smtp-Source: AH8x227+q7XhrizRYM9jHlShjyj7VShuXhP9tDSHCv+qIaUdxEoa5Cw7RDDFNJVnt3wVISqWTAiW X-Received: by 10.98.86.151 with SMTP id h23mr8126229pfj.79.1519137384995; Tue, 20 Feb 2018 06:36:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519137384; cv=none; d=google.com; s=arc-20160816; b=RcJXlpT7GV+9XkaYnktyudJX64i0kSKYmpjmsXUjqx8QHWi6voDqv8TsffpfaWM/m9 5DRTt0fSG7e0xNzT2ywfXHbt2b/GJ2qGgKtWvaDjm/VHYpicd173iYlouHaN4UxDheT/ +Om3ZD7Wm4/t/mWkYOiMdL7xw3eF5Dq7amsSYpXbFNBhpC8qUAW23uJTpAfKmxUMzUJF 0slRM5+hyZSRHIvii8WBBNO+dErebd7QiHflHeh1SBEK/j0elz/n66mxP4NSYMNeaN27 7lblERJ4eKSiO8qqothT3T+X9ZC+9uZy+h5CoE3i81Bt6Hb5NXrZe9yGGXUzHysDjSEP 5ffQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature:arc-authentication-results; bh=DRL0rZI8BDnU46RD++7o+NePqCU9CP1nVNzjcRaEtoI=; b=py/dIEh1/0wKIN/bFUdLvkvKKoJmB3rN4RjPIK/cfhnW5Ku4TsOrVuFZOyZsGkoBts ntjg3754TtTT7cowb84pGBZzgHVZt/Oc1/5IOU36a6yiSXCh6c1hkWHqg/Aec1/sRalD KRxzRXrwnzVacbmrqZ8QAjN4xJ7mRkgnUe98wFKRHRm1/Tiqg3FAFUfJR0Xdf/o2cIHG xXKPXBwpXZJ4ASJxLGv0ByCcyzCiZgNO8MdxmZ18+gefkrLr2XoWlE3dMdk6uiazTe4F VT1jUiuDCTM874HWzXmT/p/5kDoOLT72Dyz7ugvsWm57tzrsqblKZ4+B40gbHcu54rnM 5CVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=pjSUxlRq; 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 c6si7752649pgt.111.2018.02.20.06.36.10; Tue, 20 Feb 2018 06:36:24 -0800 (PST) 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=@amdcloud.onmicrosoft.com header.s=selector1-amd-com header.b=pjSUxlRq; 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 S1751440AbeBTOfd (ORCPT + 99 others); Tue, 20 Feb 2018 09:35:33 -0500 Received: from mail-sn1nam02on0081.outbound.protection.outlook.com ([104.47.36.81]:29616 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750934AbeBTOfb (ORCPT ); Tue, 20 Feb 2018 09:35:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amdcloud.onmicrosoft.com; s=selector1-amd-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DRL0rZI8BDnU46RD++7o+NePqCU9CP1nVNzjcRaEtoI=; b=pjSUxlRqcoVzb7L9R61cJdN0cVn6edcmpVDRLodF3aPCiSoC+GK3yAgcF+nz+Vp6qTI+sANAO9hpQVyyH4ERiHt8sAJcFhnsklx0+qnWPC1OSa8JmIijLXfwh+TexRhpvTGVb4tmgvxjUYB9tRlPTzDlmeh7laEtJfb2MGVhZ50= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Christian.Koenig@amd.com; Received: from [IPv6:2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88] (2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88) by MWHPR12MB1309.namprd12.prod.outlook.com (2603:10b6:300:10::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Tue, 20 Feb 2018 14:35:27 +0000 Subject: Re: [PATCH 1/4] locking/ww_mutex: add ww_mutex_is_owned_by function v3 To: Peter Zijlstra Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org References: <20180220125829.27060-1-christian.koenig@amd.com> <20180220131253.GF25314@hirez.programming.kicks-ass.net> <8fd80334-4d0e-8ed0-8a09-02a7e36a0eae@gmail.com> <20180220135709.GD25201@hirez.programming.kicks-ass.net> From: =?UTF-8?Q?Christian_K=c3=b6nig?= Message-ID: Date: Tue, 20 Feb 2018 15:34:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180220135709.GD25201@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Originating-IP: [2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88] X-ClientProxiedBy: HE1PR06CA0146.eurprd06.prod.outlook.com (2603:10a6:7:16::33) To MWHPR12MB1309.namprd12.prod.outlook.com (2603:10b6:300:10::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: e79e2616-1fd5-4cfe-4e36-08d5786f3037 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(48565401081)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:MWHPR12MB1309; X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1309;3:T4Obs8ZINMa1r/PYdWw6hYos1eIVjV84A7gxNvLMAiBCuLeX5FkzcCnBe7JoXID+jmAG48w9Nls09y8R9E7FkO+eYyp6f/QFWbEdfTahm9TgDYbggcQZgdya34Vix9u7Dx2Yd3fJ3MVHx4Awump2UCw/A878OlGBIOEui0VfIiz1IQ9A3iDOGVk7pEN+LmMLaavf1SjqhM5BnmJ2YGIey8rMyUXjHrTai17LLWsnICO6RHpVYaOKxWbVSjZhIEFx;25:xkvA7IHB88XG/RucqtCuSjL9AycI/AKH2JIGnkVrjnvy6Fp/XaP3VZfa6ntpaee6b01C9pVOqoS7qNUAerWIEtUYh7Kh2Qb0mrpWfSQEhHuuWO+6ups0q15mxi3NVbyxJIanE6oaAd2fpxaaTqKAORv0ylgQWaMd78OWIXqipzFSVDpVRvI5RAUMDsWDer9qNb3lpyVGGLp0WnhfudlNegNldnTrAJcb64DTKiAgtTfAQdwzY6P0YTebT432KRrWrl4Nem/s6ThUw6RKNcbcQnVNExjwNkJ+Ff0sy3jcBWhhDOXhYVmneATYlsD2p3Vzg+DV5y2RDbJYSM0CpR/5dA==;31:c6F4RCxDw4p3StIMxorCDQb9+mpGuS8bpWxg10wL52bt79fHZuDBnVasCON+SgiJ7NlqUuJfPJ15TMW/vZ26IWT0BaGJDtu0jJj1ksOXnf2BxHcHgq+gn3XJLHkGvgtwvdQ8b8TAMQXEykdo4Xu4lAE5hFjgVXLljDz/60Dlb3S11fbbxEsvAMlFw4oaUgtH7dsYeIj4S9pf6ID/REw3o9CUUzy0294XJzVxCve8y7M= X-MS-TrafficTypeDiagnostic: MWHPR12MB1309: X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1309;20:y9O6MmjIXzV6kgcE/pRiveobpKLSSdbKK5YI0TD8j9AOFuz5dmTRJfB2IdSEcvoDk6eRxP5sxjfMEsmmIg4CmPihnGmJGZcpsud98e1sy0cWAbpiiCM9VHHPaZegf6rGtBq94BKMyhIinlU5wLLOP0NNSMqDZbkOfkAxTU5M9Nl6FbURsnGOF307g0YV5KnFSHr1tMd2KY8PfVFYwpUGtrBJ9cobCnD6IDmI0sHuLO+WqQKys6eYvBqQjaYM8hrIeXpc/UZE1U0sxtroKknCh1XAhY3doWZ5BegrqKK3hkVApuY6DOREffrS9bg5+Yl5QVJJFTJEuZtUiu8kGYNUAYkpT0ta5Qxzs1sWA98FK3MVpf6U4OxCx8rwIxsK+pVmrUqCiD+9iHZnI8fCW/+WtHL4Ux05qnPDDeIv68Wu8ieuyo3tzV8FtfSsIUwFwxKU34l1q4c/fn5gdTRpa8bwdIds3ZC2KNA8syCL0WcT9UxzWf9kHGPaE88Jiwy6b6fm;4:cZeZKo8zOamPcWQV51EeWmbLIeAsxayd6FdWO80wxzmCGeKvwErRKiVOFYd6DTCZJ6gTGbzcPeRtqBZ01tUXamKkG7NhKENf62DNk5Msp1/89hpLI0SOjkHUOI1z+2AMAmIAwSV13LF/4nnwU0w4LOaHIhgTcomVIFqOhq3nXIvRlyoxPDPsaq1PU58XCkyC2H8rpt1qfANIHEN9rzBOFDwlpuLpaS44iyh8I90GVuib5G7/w1bDj1aFPG2XGWqKMzATH/pp2hTL5A6amZJypg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040501)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231101)(944501161)(10201501046)(3002001)(6055026)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:MWHPR12MB1309;BCL:0;PCL:0;RULEID:;SRVR:MWHPR12MB1309; X-Forefront-PRVS: 05891FB07F X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(376002)(396003)(39860400002)(366004)(346002)(39380400002)(51914003)(189003)(199004)(6116002)(5660300001)(25786009)(53936002)(1706002)(2870700001)(31696002)(52116002)(6666003)(106356001)(52396003)(229853002)(23676004)(2486003)(52146003)(2950100002)(4326008)(47776003)(6916009)(64126003)(81166006)(81156014)(97736004)(65956001)(67846002)(72206003)(8936002)(7736002)(65806001)(83506002)(8676002)(6246003)(305945005)(93886005)(7520500002)(36756003)(86362001)(186003)(478600001)(6486002)(16526019)(59450400001)(50466002)(65826007)(386003)(76176011)(105586002)(58126008)(316002)(68736007)(2906002)(31686004);DIR:OUT;SFP:1101;SCL:1;SRVR:MWHPR12MB1309;H:[IPv6:2a02:908:1251:8fc0:4c6d:7233:b7e1:3b88];FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Received-SPF: None (protection.outlook.com: amd.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtNV0hQUjEyTUIxMzA5OzIzOlNqamxZemhrMHJtZmpwSTVoRTFlaEI5UEhN?= =?utf-8?B?ZkVZSEpGUXIzWUlYMEIyOFl5SlJUMnR2TkozNmpQSXF4bFUyTWUwVkJVT2lz?= =?utf-8?B?YytsSkI3bDhTbmVhRHU2cEJya1RYZFpyMzRsWkxobXVwemZ4a2UwM21hdjBz?= =?utf-8?B?UEVTZ0s5T3VUSTJGUHZTQWlnaTBRZVRWSjlVNDc5L1M2TWdnb3J4VytSSDhr?= =?utf-8?B?SC92NlFSZUlhTFY4SGkrUStmUW8xVjJRTUwrOWhlTFU1bk9vT3J2WXBEaXJ0?= =?utf-8?B?ZHM3d0xSYkRQZVc3Wmh6RjJQOUljSHVrU0JZdUhOOVJiamFnUGtMc1ZVdzY1?= =?utf-8?B?MjhFWE1Rd2hmN2l1bjlyN1RRYmRXclBHL0g3RWVoNk1XSmVpV1g0aXRqTHFn?= =?utf-8?B?a0lTbnhEZEh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iBlgRoG7vHuS7h8DaE44/4TJs=;5:egXrevchPjBFKy0b+Zc5thj3Cqz56GYl8gAOhWVIvlxs7PpU5u98TgeeGto5ScIzOKVdnngadgfrTd8aeuHPrFRQhoBaHhq8Q8MaKxzDXNh35wDW95BRo3bnh5s3puD85C3gnV1yd3PbtVsWvqI7t/PIK0RcufImB4uzqDL+V1w=;24:3sJHTsNCQhqIQtUPc6g8MHSVTuPF5370oB7/TRhcgHSsECNSi5PPPkVPmC94BG47zOR0xia86f/IUcb6RX78K7nA/2dC4VZUydEWKfNI9pw=;7:cxNb7aysnLtBUMPT5e1YkI0gN9Nsbp9mFmf2qH518c+1m10DMNEzdlSekH5fkDMZDcE0CQChlCAIZPG6mPpc6q24BfVTXoDffwsdoQOnKcmUOGHi5MmfZJx5JymOHUu8JyYZXOF4Au3fJVakUALYzFojqkwjXMAaxiASX0pbKK3DMLqd1N0fvtdwvZanmhAwvQHXsyAww7agVUFVu6PVE5zMb5L8FJ3iassp00R/OhTOj3x+iEhaxudcai7d17AE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;MWHPR12MB1309;20:GwH+B+VYMdIoF/qe2LHHRqohn4Z2QO4ea4rtv8rjzH7hmlRi4RWdFXZT9WRkONSDRpWIY9DA7xYXeAZPJTDoQKRB7ZGyrufhOL8wEBtE9cfEWYKlSlB5j3wzCH7IkpJt423/hCNxzSMGYBga37vm2sYwYWzNYLphpo681kF8no1wrS7h5y/AkDuLTi1h1imSoP0HD9zo3A8g3eb8lSnR6bankykLR+ysC+fWoq3OpMBajFpJoE/CAd+z5xfxNcbB X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Feb 2018 14:35:27.4520 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: e79e2616-1fd5-4cfe-4e36-08d5786f3037 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR12MB1309 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am 20.02.2018 um 14:57 schrieb Peter Zijlstra: > On Tue, Feb 20, 2018 at 02:26:55PM +0100, Christian König wrote: >>>> +static inline bool ww_mutex_is_owned_by(struct ww_mutex *lock, >>>> + struct ww_acquire_ctx *ctx) >>>> +{ >>>> + if (ctx) >>>> + return likely(READ_ONCE(lock->ctx) == ctx); >>>> + else >>>> + return likely(__mutex_owner(&lock->base) == current); >>>> +} >>> Much better than the previous version. If you want to bike-shed, you can >>> leave out the 'else' and unindent the last line. >> Thanks for the suggestion, going to do this. > You might also want likely(ctx), since ww_mutex without ctx is > a-typical I would think. > >>> I do worry about potential users of .ctx = NULL, though. It makes it far >>> too easy to do recursive locking, which is something we should strongly >>> discourage. >> Well, one of the addressed use cases is indeed checking for recursive >> locking. But recursive locking is something rather normal for ww_mutex and >> we are just exercising an existing code path. > But that would be the ctx case, right? I'm not sure there is a lot of > !ctx use out there, and in that case it really is rather like a normal > mutex. > >> E.g. the most common use case for the ww_mutex is in the graphics drivers >> where usespace sends us a list of buffer objects to work with. >> >> Now when userspace sends us duplicates in that buffer list the expectation >> is to get -EALREADY from ww_mutex_lock when we try to lock the same ww_mutex >> twice. > Right, I remember that much.. :-) > >> The intention behind this function is now to a) be able to extend those >> checks to make sure user space doesn't sends us potentially harmful nonsense >> and b) allow to check for recursion in TTM during buffer object eviction >> which uses ww_mutex_trylock instead of ww_mutex_lock. > OK, but neither case would in fact need the !ctx case right? That's just > there for completeness sake? Unfortunately not. TTM uses trylock to lock BOs which are about to be evicted to make room for all the BOs locked with a ctx. I need to be able to distinct between the BOs which are trylocked and those which are locked with a ctx. Writing this I actually noticed the current version is buggy, cause even when we check the mutex owner we still need to make sure that the ctx in the lock is NULL. Time for v4 of the patch, Christian. > > But yes, I cannot think of a better fallback there either. >