Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp348359pxu; Thu, 7 Jan 2021 06:39:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJxgnuQk4+7RrRQz5RXEIvoY1cwfc3xg7w5IOXu2gkn8e7287EUpxYz8OmRLy4LthOXZE4Kx X-Received: by 2002:a17:906:168f:: with SMTP id s15mr6393950ejd.180.1610030386533; Thu, 07 Jan 2021 06:39:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030386; cv=none; d=google.com; s=arc-20160816; b=qUfsP107BrB5+Ghr6bgOuZoObRnxLwYyjlgO8E8ldgmmO8aZSIQ7U/+iCFNMhqgZel muS//a1OIF/EF6oA3u3+kSBqxGEiziVd99dBgkFB9D0M5AqdbYvinHax4ILJCVe0zl4+ Mp2bBIU+q5YPSXcjxTi4k5QG1A6/YFMutqqBSZPI7dBi6DduELgpc86qQIa4MJiyVfU2 YGqbjmOTYQx42IH7M23aSS+LyNrYSfkfo9vrDsqd3MEkkVvPR6nJgCDlDiZ3eWUALuuG q34lb3N9JHJJscLCcz00IhJnWjG3JiCO3cP4oN1Xl4RLXu+2v7kTQR25gdkrhob+F/fl YF+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7/U2vOXBnMfjE2IQOoRsYHLvp/yp5+ns967Z2MGJmGI=; b=MPUMfGqHhrc3hBLdl2gN1CvdUYM7EHoRUy835bwqQvuBHs9x31VQw5A9fkgfuMv2yP ym1RcO2Xiqpex8mNBnXuBZGlsqJMgxEW0DNQNPEALxvALXJy/yUS2GxU03qHzcdbpdoa G5QFyCUdYX+mpaEsESXB5Xhm/aBM7kkuoWfO2oojJjwWO2cJ7LOt4WLT65F3UXrfzbc2 5WTrtZ1dnJLTNgIj34AVektaTrKKIGTYe/lsj4Iu2GiUZmy80a61KJrO60KVMH+b7kyn WsRzhRNuK9t5CBRabfNcBnFfHfhPbGIccLdsAlQkgug4ziHzKmcaus9kF2zF+KVfbKas 8Few== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PhHO972q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si2650809edv.392.2021.01.07.06.39.23; Thu, 07 Jan 2021 06:39:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PhHO972q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729569AbhAGOdV (ORCPT + 99 others); Thu, 7 Jan 2021 09:33:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:47240 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729532AbhAGOdS (ORCPT ); Thu, 7 Jan 2021 09:33:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 168E12336D; Thu, 7 Jan 2021 14:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029958; bh=Kga/4gP3btIfsllJyQ5qKksgwH9GjlUV7ZHTymD/SgY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhHO972qlXaazF1kmOZjEgcO5AKxPyrx/MlVDdTeZcRdUCQeoSux0zawXNQ7ybS3A Y2v2DiT1tJ3tswEbI5KP39SXZTNOSYeCzeTC2UWxtLynyMgsM3e+DrkG03ln/eWA26 xrvWs086gToFIzg4tyC1wvHxk/uhZENDAI4ogkRs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Eric W. Biederman" , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.4 10/13] rwsem: Implement down_read_killable_nested Date: Thu, 7 Jan 2021 15:33:29 +0100 Message-Id: <20210107143051.339142973@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210107143049.929352526@linuxfoundation.org> References: <20210107143049.929352526@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric W. Biederman [ Upstream commit 0f9368b5bf6db0c04afc5454b1be79022a681615 ] In preparation for converting exec_update_mutex to a rwsem so that multiple readers can execute in parallel and not deadlock, add down_read_killable_nested. This is needed so that kcmp_lock can be converted from working on a mutexes to working on rw_semaphores. Signed-off-by: Eric W. Biederman Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/87o8jabqh3.fsf@x220.int.ebiederm.org Signed-off-by: Sasha Levin --- include/linux/rwsem.h | 2 ++ kernel/locking/rwsem.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 00d6054687dd2..c91ac00d1ff8c 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -173,6 +173,7 @@ extern void downgrade_write(struct rw_semaphore *sem); * See Documentation/locking/lockdep-design.rst for more details.) */ extern void down_read_nested(struct rw_semaphore *sem, int subclass); +extern int __must_check down_read_killable_nested(struct rw_semaphore *sem, int subclass); extern void down_write_nested(struct rw_semaphore *sem, int subclass); extern int down_write_killable_nested(struct rw_semaphore *sem, int subclass); extern void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest_lock); @@ -193,6 +194,7 @@ extern void down_read_non_owner(struct rw_semaphore *sem); extern void up_read_non_owner(struct rw_semaphore *sem); #else # define down_read_nested(sem, subclass) down_read(sem) +# define down_read_killable_nested(sem, subclass) down_read_killable(sem) # define down_write_nest_lock(sem, nest_lock) down_write(sem) # define down_write_nested(sem, subclass) down_write(sem) # define down_write_killable_nested(sem, subclass) down_write_killable(sem) diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index baafa1dd9fcc4..2ce13f9585779 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1608,6 +1608,20 @@ void down_read_nested(struct rw_semaphore *sem, int subclass) } EXPORT_SYMBOL(down_read_nested); +int down_read_killable_nested(struct rw_semaphore *sem, int subclass) +{ + might_sleep(); + rwsem_acquire_read(&sem->dep_map, subclass, 0, _RET_IP_); + + if (LOCK_CONTENDED_RETURN(sem, __down_read_trylock, __down_read_killable)) { + rwsem_release(&sem->dep_map, _RET_IP_); + return -EINTR; + } + + return 0; +} +EXPORT_SYMBOL(down_read_killable_nested); + void _down_write_nest_lock(struct rw_semaphore *sem, struct lockdep_map *nest) { might_sleep(); -- 2.27.0