Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp347192pxu; Thu, 7 Jan 2021 06:38:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0mGoV4qt8sPpQxh9tP2lgq9RYD5l65u3ox3AoUQzZ1Eorpq71L9uJYrXqdFVdwznvRcqM X-Received: by 2002:a17:906:174f:: with SMTP id d15mr6540723eje.52.1610030293909; Thu, 07 Jan 2021 06:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610030293; cv=none; d=google.com; s=arc-20160816; b=xuo2QDTItUNBNYcNL2zGwJ5OlMMRBdPoS7jscUSALd6zRjySu/IbaEUYsjrxbi4vnU TeWqsKOn/7fvqBYDQCvGk5j1Z+IqgezZePCDuF9jtSprOpsSArEHoXutc/UeuIwCVISE n1gYAfcsvBXxY1U9ViYrGElWFdm5boJFbb6Enu0ixCyT3+STn42vMggtQPDspvnTND1u iuBvVMEZs7YIsLYMQ5bewqTedNL8J2FGUBeJmxSqWvDcQhMGPWPukusguUlOF7BIxaGv D1bEASA81nIyY3gXiedFw/FGekYE2y6zsjvZPvtZR62Ubuhv6g4WQywDrDeI+EWrRisg 28Rg== 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=vnDKilmuAHZfHddi6vdVVocT4Oduc/HjWTM0SIIExkg=; b=hrgXCGi3Yj5AF+MEOs1nG4+ukWfJg26J8Rn1OihjMIwhd6C61/TBSSJUdAFammQePc KhVmLXztEqO+IUE3g9UwGrhyzUprnSe4Uf905ywQCvLh5t2e7PfIfpugYcFVP8U0zJNH KLX1Mb6vkURJu+wl+L+gkXiymPzhdwf4xUInmykH6F9l3KK+bOSS1Drbmu2Il8EVA/2h JzRge1s1I84WkAplJfR1Ycws7CUuy3khG16ovDmlsZifvaDHaY6K50o1oYjah7czRx/M f36Oex+Py/JiKEuJCZrmt3VH+L6zRf+I8WBYkE2HrHimkxOIAdi7Q74IX8pWUdtlmDFA rrMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jTRVVoai; 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 m15si2363366edp.363.2021.01.07.06.37.49; Thu, 07 Jan 2021 06:38:13 -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=jTRVVoai; 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 S1729240AbhAGOff (ORCPT + 99 others); Thu, 7 Jan 2021 09:35:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:47262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729565AbhAGOdV (ORCPT ); Thu, 7 Jan 2021 09:33:21 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45D322311E; Thu, 7 Jan 2021 14:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610029960; bh=07H55USeSn93ZqRjF/TaBFzUhTUO066N9IvQn5RjYao=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jTRVVoaiFbNhyWwYigNla7sBicVY9pO/uxaiqojZkhvLGBaFxgNkppaVHoPm20BPR NLH5U+svwdderIE/Zzas1Vvq4mtGFrnUU+kDicXArL0HtB0zcSt2qNGdzoeyK9vxem NlH2i1gOZX0Vt9CT2Cx8gCgdZODY6B9q9+7NVZFA= 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 11/13] rwsem: Implement down_read_interruptible Date: Thu, 7 Jan 2021 15:33:30 +0100 Message-Id: <20210107143051.459159924@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 31784cff7ee073b34d6eddabb95e3be2880a425c ] In preparation for converting exec_update_mutex to a rwsem so that multiple readers can execute in parallel and not deadlock, add down_read_interruptible. This is needed for perf_event_open to be converted (with no semantic changes) from working on a mutex to wroking on a rwsem. Signed-off-by: Eric W. Biederman Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/87k0tybqfy.fsf@x220.int.ebiederm.org Signed-off-by: Sasha Levin --- include/linux/rwsem.h | 1 + kernel/locking/rwsem.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index c91ac00d1ff8c..8a3606372abc8 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -125,6 +125,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_interruptible(struct rw_semaphore *sem); extern int __must_check down_read_killable(struct rw_semaphore *sem); /* diff --git a/kernel/locking/rwsem.c b/kernel/locking/rwsem.c index 2ce13f9585779..a5eb87f2c5816 100644 --- a/kernel/locking/rwsem.c +++ b/kernel/locking/rwsem.c @@ -1348,6 +1348,18 @@ inline void __down_read(struct rw_semaphore *sem) } } +static inline int __down_read_interruptible(struct rw_semaphore *sem) +{ + if (!rwsem_read_trylock(sem)) { + if (IS_ERR(rwsem_down_read_slowpath(sem, TASK_INTERRUPTIBLE))) + return -EINTR; + DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem); + } else { + rwsem_set_reader_owned(sem); + } + return 0; +} + static inline int __down_read_killable(struct rw_semaphore *sem) { if (!rwsem_read_trylock(sem)) { @@ -1498,6 +1510,20 @@ void __sched down_read(struct rw_semaphore *sem) } EXPORT_SYMBOL(down_read); +int __sched down_read_interruptible(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_interruptible)) { + rwsem_release(&sem->dep_map, _RET_IP_); + return -EINTR; + } + + return 0; +} +EXPORT_SYMBOL(down_read_interruptible); + int __sched down_read_killable(struct rw_semaphore *sem) { might_sleep(); -- 2.27.0