Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752630AbdI2QGw (ORCPT ); Fri, 29 Sep 2017 12:06:52 -0400 Received: from mail-he1eur01on0123.outbound.protection.outlook.com ([104.47.0.123]:42884 "EHLO EUR01-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752108AbdI2QGq (ORCPT ); Fri, 29 Sep 2017 12:06:46 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Subject: [PATCH REBASED 5/6] rwsem: Add down_read_killable() From: Kirill Tkhai To: linux-ia64@vger.kernel.org, avagin@virtuozzo.com, peterz@infradead.org, heiko.carstens@de.ibm.com, hpa@zytor.com, gorcunov@virtuozzo.com, linux-arch@vger.kernel.org, linux-s390@vger.kernel.org, x86@kernel.org, mingo@redhat.com, mattst88@gmail.com, fenghua.yu@intel.com, arnd@arndb.de, ktkhai@virtuozzo.com, ink@jurassic.park.msu.ru, tglx@linutronix.de, rth@twiddle.net, tony.luck@intel.com, linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org, schwidefsky@de.ibm.com, davem@davemloft.net, rientjes@google.com, viro@zeniv.linux.org.uk Date: Fri, 29 Sep 2017 19:06:38 +0300 Message-ID: <150670119884.23930.2585570605960763239.stgit@localhost.localdomain> In-Reply-To: <150670038738.23930.7190484711222807884.stgit@localhost.localdomain> References: <150670038738.23930.7190484711222807884.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0001.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::11) To DB6PR0801MB1333.eurprd08.prod.outlook.com (2603:10a6:4:a::27) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 52dbaf2c-fd23-44de-d2d4-08d507541373 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:DB6PR0801MB1333; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1333;3:mOLr6n2KXInXuAZkRS+MUlFWlDRs+Ue4VjYBL9dqQq6v8y0CLybITLR1Yp1cGiYNoXAJwv0Zdmu9j5BDXmeJMr2bpaVy1x+A625x1Pdrd2YlqEtTbvfQLt0NVTPt1fvDlYVm7F/DQp1+LNMgu6gcFAO14fCRWOmWswpdgBZpv/LqYA5/W4Tj36CS3VFHi1b4CS7KTPnX4NaE8JY2pc5043zqgTih0TjZl+rwx+Ipb94TsIC2myYrXqE0giinSGL2;25:2/hwCm0zV+TnJkt/X7Ap1GC0MIJ6K+OXJwF6tQwgny4G9NzmN/C4X0d1HxOVPL7ITfKV73oV5NRmGgvJWuPyk63CiaB56suqf4bU9FQqKIloZVogOd1qx57ah/PaNJWJCxunCa/oltp3ZYo67qCRxxwgmZzt6morN4m9LXhum9NS2Xe8sa6JlVDcl+nc//SCGVnRYJrt3gEwpw3tQGAKST6K/ePc+WAwcqnMR4lPOQr2y2fRilNOVxjKRXquFl0YjssYl+uFVeompsiTMHK/EBiRabjrzwOmCfDTJA0tPJ6ypV1+oGng7AVvsGVOHibjLEdIA4Lle+sH8360rOxT3w==;31:ebbrte6f+sY/k29B2dUgRsjEEu3fKV/qUREzZynVrLsTCmAR1JKi2414neUbsEVgFCeKkom5BiR8FHg6kMnuve95Ubzsxp9tJ16n9evgfoZVi5aQyKWp1qOhdwK9xCuL598l8/FaJBLXbN0aYeU8I9Kzt1unAPLcfdhDlsYNcMXgwwvs1zCvm7Jh0K+TevWBuqh48dn5NPWRATN8u+0s41w1SPWw0KTezITE1Duq9oo= X-MS-TrafficTypeDiagnostic: DB6PR0801MB1333: X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1333;20:80tKJNuZsPXlEA2t7A4rSdQKPiWvXj6ycOpcUEY/AUo6pV39TPHyyZfN3Jv2p1c+Q7fjMG4UUZCM9NRrBhaTMzk7CChoTDaMf6jHVGk9tMY3Jjh8oMYkksKcRK0WtkHNoA8pCqnJ4Iv/lv2O2qKMEw4YLLASxzK8c16ukyTj2Axa87PCoDob7JEf+Rl2ZdDz8fxTMzQAmqmTBgcbSDm/Ahm1HztNrmmf4E1qa3y8OR5yOeHmpuA9H8syoJ+z/iLPTcslZ+vvE8wEWreq5hpvLZRgjqQZJrzk1Tc+ODX+/c9mTfH0qeatEqe+b+OBR5c0yFsJVsS6zskrnO3u5CEU9b0eCGtXasUnSyx53Emzc8ejt4ufBzTnEWx0FzbvpBreLrZ1FgZnb5oDBbPzIymG42/aDFmDNbXZKtdFurhF+T4=;4:8HkzSsL5MQvQSn1l0HBAoJfVZ5lx1hnab0WpkL3Bt2PjODJ6WYtZwuoijzO5H7QofmGkupPwV9pgOpj3ystNJ+KtMdZyPlpxFMqocXrWBc5laF4MBvMGsWB0SGJ7fM097fierEUJtvQ6W5oGXG/Jgsedi+8kKxIF1Wl6tHtFb0LECrdYVfbVl+TnBVAhIkSfdVaVknY/g1GKJjf87Ken3FKW9bEzOCX3ZujI8E0T1vRwXIagSN2PqDFZ/zR4xffc X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3002001)(100000703101)(100105400095)(10201501046)(93006095)(93001095)(6041248)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123558100)(20161123555025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:DB6PR0801MB1333;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:DB6PR0801MB1333; X-Forefront-PRVS: 0445A82F82 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6009001)(6069001)(346002)(39830400002)(376002)(199003)(189002)(189998001)(7416002)(7736002)(66066001)(39060400002)(47776003)(25786009)(9686003)(50466002)(8676002)(81156014)(55016002)(81166006)(8936002)(3846002)(230700001)(6116002)(53936002)(305945005)(2906002)(478600001)(103116003)(23676002)(101416001)(68736007)(76176999)(54356999)(105586002)(58126008)(6506006)(50986999)(2950100002)(106356001)(61506002)(5660300001)(316002)(33646002)(16526017)(86362001)(83506001)(97736004)(921003)(217873001)(1121003);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0801MB1333;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtEQjZQUjA4MDFNQjEzMzM7MjM6cFBoMFhWMHhEazNFNkVTRnpwekYzSmw5?= =?utf-8?B?a2FaazljTjF2R1R4SEtNdVRvZ0RuZitzZDBzNk9CcnU1ckV0RU9LWHI5S3Jm?= =?utf-8?B?WWxLUnhmckVvNmttVzQ1QTdXNVR0ZnJ2NG5KKzZYakxPczgvY1lUbjkzaFc4?= =?utf-8?B?U0U0YVRYWjJ3SlQrUXMvaDB2NmtFR3FMK3o5ak82SFpuVnRLSGF0REw5Y0lC?= =?utf-8?B?S2YxRVY0c1RmVHpndjFqK3RjYjBMb3BUSXhCNzI0bmhlOVA2aFc2Y3oyU05T?= =?utf-8?B?NlRzYjIwazZMcm0yRENQd2pMeWdQR1pyY1hVZjJWdXYzTlB4cU53Sm9MZytE?= =?utf-8?B?QkQwd2laVWdaMXZWenVYWXBjMk5kZEpjbDIzVHQzWmZoeDF6cnhmQ0R2c3dJ?= =?utf-8?B?WnIvMEFiRXBkTTlkUkg5SU5PN1ZxNzZ0cWNtV2Q4UWVIdDM2anhiMGl0cHAz?= =?utf-8?B?Vk5oZ2h4elc4Qkg0a0xkb1l2cmY5OEhRaHRJdU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zyeIdyK2cmH1h/41AQhux6vdtRaXtdehxq3HSsFBqyHogZAyh5dwO7fOvGpGi7rBLEipB4lmP2ABeNy8RsZc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;DB6PR0801MB1333;20:SqguBU0rQ7CGfjcHP/j8OpJR0By1Pke9lhptuWQI/OAkDRc/lolrV7w0EqUFmvbiqr3TBAHtPSWpMJdmrAS7K0tmPgUgpB5Y81pxrxfu3VvWE4kqi3vt46FJC8/bM44lbt9M32uupr/+Nbi4Jh7Ak6F1qDEFTHlh/K7J1vQfuLM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2017 16:06:40.9360 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0801MB1333 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2142 Lines: 70 Similar to down_read() and down_write_killable(), add killable version of down_read(), based on __down_read_killable() function, added in previous patches. Signed-off-by: Kirill Tkhai --- include/asm-generic/rwsem.h | 8 ++++++++ include/linux/rwsem.h | 1 + kernel/locking/rwsem.c | 16 ++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/include/asm-generic/rwsem.h b/include/asm-generic/rwsem.h index 6c6a2141f271..2f71b913b555 100644 --- a/include/asm-generic/rwsem.h +++ b/include/asm-generic/rwsem.h @@ -37,6 +37,14 @@ static inline void __down_read(struct rw_semaphore *sem) rwsem_down_read_failed(sem); } +static inline int __down_read_killable(struct rw_semaphore *sem) +{ + if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0)) + if (IS_ERR(rwsem_down_read_failed_killable(sem))) + return -EINTR; + return 0; +} + static inline int __down_read_trylock(struct rw_semaphore *sem) { long tmp; diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 0ad7318ff299..6ac8ee5f15dd 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -111,6 +111,7 @@ static inline int rwsem_is_contended(struct rw_semaphore *sem) * lock for reading */ extern void down_read(struct rw_semaphore *sem); +extern int __must_check down_read_killable(struct rw_semaphore *sem); /* * trylock for reading -- returns 1 if successful, 0 if contention diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 4d48b1c4870d..e53f7746d9fd 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -28,6 +28,22 @@ void __sched down_read(struct rw_semaphore *sem) EXPORT_SYMBOL(down_read); +int __sched down_read_killable(struct rw_semaphore *sem) +{ + might_sleep(); + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_); + + if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) { + rwsem_release(&sem->dep_map, 1, _RET_IP_); + return -EINTR; + } + + rwsem_set_reader_owned(sem); + return 0; +} + +EXPORT_SYMBOL(down_read_killable); + /* * trylock for reading -- returns 1 if successful, 0 if contention */