Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752611AbdI2QGl (ORCPT ); Fri, 29 Sep 2017 12:06:41 -0400 Received: from mail-eopbgr00128.outbound.protection.outlook.com ([40.107.0.128]:14051 "EHLO EUR02-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752108AbdI2QGh (ORCPT ); Fri, 29 Sep 2017 12:06:37 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Subject: [PATCH REBASED 4/6] x86: 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:28 +0300 Message-ID: <150670118802.23930.1316107715255410256.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: HE1PR0102CA0028.eurprd01.prod.exchangelabs.com (2603:10a6:7:14::41) To AM5PR0801MB1330.eurprd08.prod.outlook.com (2603:10a6:203:1f::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 38ec50a4-a89d-4249-ef5b-08d507540dde X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075);SRVR:AM5PR0801MB1330; X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1330;3:u4I3Kq6TzwlO1hRHcXtFqm37tuYY0yEc+kvRwELWDCMIHdEERrBY1f7V1RbNB9ht+piuiBqwop/VeoT6F16gEn+v2hNEA1g1klmOSyzDg6aBKAuig2BL00D5oIL1oWOwfC9E9NxjSbLCTfHQoFZLQvi4uOVzS3TrfW6veUzjWZxeq875k6Q/GlpDh2cc4OkbBCthxspkVAIoi+DQ+t5qmgMeEWJjR4+4RgcfHnqwmFmZ+R9EiT3Fx3UmgpAh9tAv;25:yv0znI4rkTSg0G/U/YDzYjh/jWVZQcxNYqECDhsz+zAG2+cv+SlQvL6ahLxfMREqcTsBftRRFIFiC3TgrtBETsV+0yhYzLeKFyskCRh2jHVQPIV/hne8NjIMnzQdcm9Ktdgj3bDgL5eOuqmq8qrUj+qacgO+1B8LdmpiTdQk3VWJLOsjxtJJ4Ws2fqssG9CIaLbt6B8ZdaE3ci7oS0heSKhYBoOJHsHFuSk5fwJwAhSy56XgbEehHdFz+i2LfY9B2JuTiC6Q7CIrUSw21M91sG1TB9gVpr5z9Mf0eWXuquUnHmJJoyYSwhoVM5rqs0JU854/mxIJpyMcfPKTcJ2kJw==;31:AojyLJbr+d5TBs1tofOdORaExTBjdydmKDPUs01Vj5TA2rIDXsMw7jltwSFonK0GHYMmGxlAfVfQxu+uZv/PLLdcSiQ46iXyeORj3pC13dc6qqI3L7Q6pKqH1BmkBYxElQIxQgDWyt6C7yg83dox8Z2oYbzLcFbdirbwxWfZMBwygvYVx1PxzGtRr1LRSdqWSAYrl5VMzePwJuVNlxk3uwkjGwgrb9sw/cAiZv9NfIo= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1330: X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1330;20:ulUykQq7kf6Es7p2BxJd3KP3BEM8xXTA8f3wSxIs+wSl/v4ZVAbxFEjqbyunDQTUPee791uZvbwq/y2aXXDwQaYgr8pIx84YJBoBdoiljHdPrGK8JC2ZzAuEoaMtz3hDMCgcIJ1m4SqM5Odl3jLSt4yVuIZq/1lWNtLl54/i65nq4P7px5pRinWee/8Yjf13D9cGpk5QOHpCgk1N36S9MzZ1ZvMw6OSNN5QjFm/iA2Lw160YiMcKPmm9jzk3YuGWgyhkT665xOX192ciAgD3FH9jK1/k8C1rpJE1OlDEDUNXuSoaYKX5cN4HZtVjKVeY1Bz2nhK5hBz3SaifTpRr8ZxlJvqW7w8utLbFy6YMIAEKSkF9yxaea7/WPMGxl4jCOOjGX7CyCQjkNhvjaxXKqICLqHtnevTfa8PGKfGq4y4=;4:dFL5W1nV2x3ZiJapGRTiHbHqYPdLwZkeSTidAwgRNcA3DSxjbOS69vYNjmOfsF7cakfZz49Y93mXHvIToxUu5GWNydrPL84/YQ9B8IsJES+zRRhOqLWVPocgl/BRrxBND6rA23C2fGlJ7hf/+T1T5YgozOHQ0k2qz73n1JVK9C/SYMGfUwfUvrkwIQZFC2H6s+SEZsIv5aWYOtR8qhPHEbTy0kDNAonvAn3qgYU/zSPQrPR7NTpE8zkVzsWJJ56+ 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)(5005006)(8121501046)(100000703101)(100105400095)(3002001)(10201501046)(93006095)(93001095)(6041248)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(20161123555025)(20161123560025)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:AM5PR0801MB1330;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:AM5PR0801MB1330; X-Forefront-PRVS: 0445A82F82 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(6009001)(346002)(39830400002)(376002)(189002)(199003)(68736007)(83506001)(8676002)(101416001)(2906002)(106356001)(105586002)(103116003)(81166006)(478600001)(81156014)(7416002)(9686003)(33646002)(316002)(25786009)(6506006)(230700001)(305945005)(86362001)(47776003)(2950100002)(39060400002)(23676002)(16526017)(575784001)(76176999)(54356999)(189998001)(50466002)(50986999)(5660300001)(53936002)(3846002)(6666003)(8936002)(55016002)(66066001)(97736004)(7736002)(6116002)(58126008)(61506002)(921003)(1121003)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:AM5PR0801MB1330;H:localhost.localdomain;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtBTTVQUjA4MDFNQjEzMzA7MjM6ZHFyRWhpcWNUMHBUb2E3T1dzM3JQUFd0?= =?utf-8?B?RE1pakR6OTVXRlEySlMxcFlYUkUxcDNqQ3h3bjVSNWU5SmhVeldSdFNvcUlT?= =?utf-8?B?YUlydFRIK2JqaXlVY3NPTFgrOVpMdkZYN0dyV1JqVW5oWm9qRGRoUkYyNFds?= =?utf-8?B?czcranFhVm1xb045Z0Y5WGJDTUtoUWZ0Qnc3Uko2ZEhMNXhnbE9oY1RGbVpG?= =?utf-8?B?TzN3MGY5QkFiWHEvV1c0MHIxSmVIK0pqM3hjaHpETU91Z21oRHdWbldZTHRt?= =?utf-8?B?NDQxMloxSGVJUHQxWjh1Um5FWnRhUWlBS1V5aWlSU2lDZUlncWp6c1MzUEMz?= =?utf-8?B?UUpUZlhhbjRUZ0Ftejl2UW41TjlodjFtZWRxWEY4bEFJRGx6NEdGOWhCU0dI?= =?utf-8?B?WXFobVh5L3hqYTJDQ01YaUJFck9Kd0VKT1h4WnllU0lXb0l4VGNkclBveDBI?= =?utf-8?B?ZTR5OVBuVGJnQ1RjUCtCTDZzUGdlYkM1N0Ri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fJsFd4l950ChQ363YUs6kG6zQmlgehVWIqzXkVz3xKYH0VXJ6yy06IEa0iuRruvc2GqkVMtVvNAEyIIi1LcpquW9JKlTq8mTIOzU3vQBiEpIEXfb+oZ2ObfGyWe1zLOCUGa6Klvf0QNJfFO9OvwHJhpDck= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;AM5PR0801MB1330;20:Wz1bTj0YXAYOAuxD6J4t3kczlbigPtMPMvZnvHuL1NJFqs5FQFHIVHGO/tp40snjYByhZw6Bd8+A6FEbJv3Jp1Vtrl/Z6etY9QUKh2AOeXq4GYgmeiKxDUkEzCTDzS42xvoxMUpKVieQLiSd+/6Z5G3pm/ulpRUjhqoEjoE5xQk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Sep 2017 16:06:31.3528 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1330 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2680 Lines: 87 Similar to __down_write_killable(), add read killable primitive: extract current __down_read() code to macros and teach it to get different functions as slow_path argument: store ax register to ret, and add sp register and preserve its value. Add call_rwsem_down_read_failed_killable() assembly entry similar to call_rwsem_down_read_failed(): push dx register to stack in additional to common registers, as it's not declarated as modifiable in ____down_read(). Signed-off-by: Kirill Tkhai --- arch/x86/include/asm/rwsem.h | 35 +++++++++++++++++++++++++---------- arch/x86/lib/rwsem.S | 12 ++++++++++++ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h index a8f486e7a124..1e51195c0b63 100644 --- a/arch/x86/include/asm/rwsem.h +++ b/arch/x86/include/asm/rwsem.h @@ -60,18 +60,33 @@ /* * lock for reading */ +#define ____down_read(sem, slow_path) \ +({ \ + struct rw_semaphore* ret; \ + asm volatile("# beginning down_read\n\t" \ + LOCK_PREFIX _ASM_INC "(%[sem])\n\t" \ + /* adds 0x00000001 */ \ + " jns 1f\n" \ + " call " slow_path "\n" \ + "1:\n\t" \ + "# ending down_read\n\t" \ + : "+m" (sem->count), "=a" (ret), \ + ASM_CALL_CONSTRAINT \ + : [sem] "a" (sem) \ + : "memory", "cc"); \ + ret; \ +}) + static inline void __down_read(struct rw_semaphore *sem) { - asm volatile("# beginning down_read\n\t" - LOCK_PREFIX _ASM_INC "(%[sem])\n\t" - /* adds 0x00000001 */ - " jns 1f\n" - " call call_rwsem_down_read_failed\n" - "1:\n\t" - "# ending down_read\n\t" - : "+m" (sem->count) - : [sem] "a" (sem) - : "memory", "cc"); + ____down_read(sem, "call_rwsem_down_read_failed"); +} + +static inline int __down_read_killable(struct rw_semaphore *sem) +{ + if (IS_ERR(____down_read(sem, "call_rwsem_down_read_failed_killable"))) + return -EINTR; + return 0; } /* diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S index bf2c6074efd2..dc2ab6ea6768 100644 --- a/arch/x86/lib/rwsem.S +++ b/arch/x86/lib/rwsem.S @@ -98,6 +98,18 @@ ENTRY(call_rwsem_down_read_failed) ret ENDPROC(call_rwsem_down_read_failed) +ENTRY(call_rwsem_down_read_failed_killable) + FRAME_BEGIN + save_common_regs + __ASM_SIZE(push,) %__ASM_REG(dx) + movq %rax,%rdi + call rwsem_down_read_failed_killable + __ASM_SIZE(pop,) %__ASM_REG(dx) + restore_common_regs + FRAME_END + ret +ENDPROC(call_rwsem_down_read_failed_killable) + ENTRY(call_rwsem_down_write_failed) FRAME_BEGIN save_common_regs