From patchwork Tue Feb 2 20:19:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Hocko X-Patchwork-Id: 8195351 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 641699FBE9 for ; Tue, 2 Feb 2016 20:21:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8E861202B8 for ; Tue, 2 Feb 2016 20:21:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C5312202F0 for ; Tue, 2 Feb 2016 20:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933960AbcBBUUr (ORCPT ); Tue, 2 Feb 2016 15:20:47 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35875 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933675AbcBBUTw (ORCPT ); Tue, 2 Feb 2016 15:19:52 -0500 Received: by mail-wm0-f68.google.com with SMTP id 128so4050356wmz.3; Tue, 02 Feb 2016 12:19:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=j1vDpfYIwj5kDeMUX8OXTS1ExSvAr8HXazedc6WtAKs=; b=PokMLGJzkb2K0pcna8zvZHtnjdxTVBk8ASXWTxpERfSqH9zROTQiNBdLbulS0iEX9N kP0YAwB1FHcrDBT5l+kV1eSq/OKpXWPKtjr5yqQ5GxMHcq7tOT99AQUHR9Y11S/3JdMI Pr1zkH1OndXzLQdWjrDFhQ6I6cJ7yQYV2xY/pOmkasvh7XYIwW7VsWTYJ2Rj5xTd1AR0 7Z4RM5g9S1uPdySVK5l6gF4lMmj3errbirfIWoQ2fjg4j/wWVstv1Bn4/Tfz/Wsb0fdk pqWsOaCA6lxj2uvogFT7pb9CY/BRP5eoG70D3TQSO4VnN47dOHF8sJHgk/ZLoxF86YMO Tg1A== X-Gm-Message-State: AG10YOTFbh2uRScnWwpUXL5k/n0BzOuQBH7FzL+KWEu62JtYgheUOpCWUO8Zpa5COEDF0Q== X-Received: by 10.28.47.23 with SMTP id v23mr20669966wmv.7.1454444390747; Tue, 02 Feb 2016 12:19:50 -0800 (PST) Received: from tiehlicka.suse.cz (ip-86-49-65-8.net.upcbroadband.cz. [86.49.65.8]) by smtp.gmail.com with ESMTPSA id l7sm3099511wjx.14.2016.02.02.12.19.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Feb 2016 12:19:50 -0800 (PST) From: Michal Hocko To: LKML Cc: Peter Zijlstra , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , "David S. Miller" , Tony Luck , Andrew Morton , Chris Zankel , Max Filippov , x86@kernel.org, linux-alpha@vger.kernel.org, linux-ia64@vger.kernel.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-xtensa@linux-xtensa.org, linux-arch@vger.kernel.org, Michal Hocko Subject: [RFC 11/12] x86, rwsem: provide __down_write_killable Date: Tue, 2 Feb 2016 21:19:28 +0100 Message-Id: <1454444369-2146-12-git-send-email-mhocko@kernel.org> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1454444369-2146-1-git-send-email-mhocko@kernel.org> References: <1454444369-2146-1-git-send-email-mhocko@kernel.org> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Michal Hocko which is uses the same fast path as __down_write except it falls back to rwsem_down_write_failed_killable slow path and return -EINTR if killed. Signed-off-by: Michal Hocko --- arch/x86/include/asm/rwsem.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h index 1b5e89b3643d..64899daa51e2 100644 --- a/arch/x86/include/asm/rwsem.h +++ b/arch/x86/include/asm/rwsem.h @@ -109,6 +109,19 @@ static inline void __down_write(struct rw_semaphore *sem) rwsem_down_write_failed(sem); } +static inline int __down_write_killable(struct rw_semaphore *sem) +{ + long tmp; + + tmp = atomic_long_add_return(RWSEM_ACTIVE_WRITE_BIAS, + (atomic_long_t *)&sem->count); + if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS)) + if (IS_ERR(rwsem_down_write_failed_killable(sem))) + return -EINTR; + + return 0; +} + /* * trylock for writing -- returns 1 if successful, 0 if contention */