Received: by 2002:a05:7412:9c07:b0:fa:6e18:a558 with SMTP id lr7csp51351rdb; Fri, 26 Jan 2024 18:31:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IGZTGkDjM11V/Vo0B12cbmZ4LtEBYWlYSsRMLDk9/fREFxb8MephDhYGK2n0PdecdgFxmRd X-Received: by 2002:a17:90b:11d5:b0:28b:dc7d:5250 with SMTP id gv21-20020a17090b11d500b0028bdc7d5250mr720453pjb.85.1706322679033; Fri, 26 Jan 2024 18:31:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706322679; cv=pass; d=google.com; s=arc-20160816; b=WhdfCfedk1CP2ih/QxNDdUD/MwS+DMjwCXdpDX/gdgspWTXLyk0wNYn7kWM+Cvvcgj MC+iZihEi8qPQZ3LpW02D5oP7F7GFKiqyO2Byyn8BoC0AKfTmeQR6JRNLEnoQu3wPYwB vjCnVMM7thVmc30W5qejH3ynrvXa0YxMDKOQ/yh53JGqIEOg+AO8VgzuL9OLC48vojby 1v3zBornTyCnoVImIovpjeHgSdWH6UZOdZeLXSWQu1dDP22XfSSz2YKfgv6fFst1gK0k 2J5hr6YuOWoklPRuLbu0AZzqAoWJcauxO+wFrd03uli84pHbGtSAfgut3AxUDdyad3Ee JejA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dhcmLJc/KPpam9Xa9GT9+fmxCdezLGqepV5bOxUHdOE=; fh=2sjOP59XGR4r99n5itLmxyAfoh46FGs/2pzyLP9EdQ4=; b=avP5HL93+cC2xdeul8LDjQlunhSbMJ62WQNQzjvw8OMmKY+iykHHmGlY5Wxf7i02Oj okX8UY039mA5I7QB+JjNMPURX0vUEyi8j4JZD1DhqyBV00ESpW/bZZ/ShV2XiIcf1FU+ YRkHU2lWFGEAM+eeJ4vTPfe+Al/gq+oSzJucivLMrxFqnNMbuUX1+H1Hd7HgtjFtxaK2 CNU9+A92tcA+J0E8VhZdRXPYKOL0C5Qi8IRxQdE9YSCXc13nYDf59J0BJTchad4MZ/Yi 8/LtrMtKIy/pnVO9lk9eFbkqV39L1zVduWZ242ljzCOxjIgmwhE4/6b0CtX/OpRAT+Rz NJqw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K6HuP2cy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-41011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a12-20020a17090a8c0c00b00294af473372si1120758pjo.68.2024.01.26.18.31.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 18:31:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-41011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=K6HuP2cy; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-41011-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-41011-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id F2EFCB25247 for ; Sat, 27 Jan 2024 02:15:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D943B1DA36; Sat, 27 Jan 2024 02:08:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="K6HuP2cy" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BAEE13ADC for ; Sat, 27 Jan 2024 02:08:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706321326; cv=none; b=XcSjleWUU/si9Dyey71WGYeLKg1Oc2Q7CRAdbmR9Afv2tzpFMc4rtRQg5tYhyB/k5MKEZFuVtEeQAkhCUi4MUgGcp4S/uwinUOnNyH4o110tIKR+gD83lT5/zD+zoW1HeeYkfvROkvV/MmdPWT0OOLcqYr/2xX73LYZbeU8tKyQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706321326; c=relaxed/simple; bh=I17n2kJwfLP73JxpOT/4Z+XY1RSDVWFd3kwZEjsB2hg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D6NLatV6e0ZAsbPYPlZRklQrRnJYRCdtcSipoeW34mpsixkPuiPTm5ypqb56t3/UGWPkvufIUHfDaCzorgx99XXBMiiubuD2KNEAo+e+eJsHI0Fvonubive2Al8/41i4XD/0uXjIQhTQUChyV/6KVb2DuUIRMrb1UAqkENW0hgQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=K6HuP2cy; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1706321322; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dhcmLJc/KPpam9Xa9GT9+fmxCdezLGqepV5bOxUHdOE=; b=K6HuP2cynzzRdMj+8Oi7h2/kxJYJxkq+MpSDzZ9Wlyk3AJZIDiYVsNznm9zyJjYntOEdOD WZaqIJ/l6rfJKTb14+fL+Z6YOd8/Rcj6w3hIM54Na/Ou0oOiLNjzLp+8w3nL1IDQL+tM5W roD4OH/1l/734jceNVxlAMT2r36o/iE= From: Kent Overstreet To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Kent Overstreet , peterz@infradead.org, boqun.feng@gmail.com, linux-block@vger.kernel.org, Jens Axboe Subject: [PATCH 2/4] pktcdvd: kill mutex_lock_nested() usage Date: Fri, 26 Jan 2024 21:08:29 -0500 Message-ID: <20240127020833.487907-3-kent.overstreet@linux.dev> In-Reply-To: <20240127020833.487907-1-kent.overstreet@linux.dev> References: <20240127020833.487907-1-kent.overstreet@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT Unecessary, we're not actually taking nested locks of the same type. Cc: linux-block@vger.kernel.org Cc: Jens Axboe Signed-off-by: Kent Overstreet --- drivers/block/pktcdvd.c | 8 ++++---- fs/pipe.c | 10 +--------- include/linux/lockdep.h | 3 +++ kernel/locking/lockdep.c | 6 ++++++ 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index d56d972aadb3..2eb68a624fda 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -332,7 +332,7 @@ static ssize_t device_map_show(const struct class *c, const struct class_attribu { int n = 0; int idx; - mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&ctl_mutex); for (idx = 0; idx < MAX_WRITERS; idx++) { struct pktcdvd_device *pd = pkt_devs[idx]; if (!pd) @@ -2639,7 +2639,7 @@ static int pkt_setup_dev(dev_t dev, dev_t* pkt_dev) struct pktcdvd_device *pd; struct gendisk *disk; - mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&ctl_mutex); for (idx = 0; idx < MAX_WRITERS; idx++) if (!pkt_devs[idx]) @@ -2729,7 +2729,7 @@ static int pkt_remove_dev(dev_t pkt_dev) int idx; int ret = 0; - mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&ctl_mutex); for (idx = 0; idx < MAX_WRITERS; idx++) { pd = pkt_devs[idx]; @@ -2780,7 +2780,7 @@ static void pkt_get_status(struct pkt_ctrl_command *ctrl_cmd) { struct pktcdvd_device *pd; - mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING); + mutex_lock(&ctl_mutex); pd = pkt_find_dev_from_minor(ctrl_cmd->dev_index); if (pd) { diff --git a/fs/pipe.c b/fs/pipe.c index 50c8a8596b52..abe171566015 100644 --- a/fs/pipe.c +++ b/fs/pipe.c @@ -78,14 +78,6 @@ static unsigned long pipe_user_pages_soft = PIPE_DEF_BUFFERS * INR_OPEN_CUR; #define cmp_int(l, r) ((l > r) - (l < r)) -#ifdef CONFIG_PROVE_LOCKING -static int pipe_lock_cmp_fn(const struct lockdep_map *a, - const struct lockdep_map *b) -{ - return cmp_int((unsigned long) a, (unsigned long) b); -} -#endif - void pipe_lock(struct pipe_inode_info *pipe) { if (pipe->files) @@ -824,7 +816,7 @@ struct pipe_inode_info *alloc_pipe_info(void) pipe->nr_accounted = pipe_bufs; pipe->user = user; mutex_init(&pipe->mutex); - lock_set_cmp_fn(&pipe->mutex, pipe_lock_cmp_fn, NULL); + lock_set_cmp_fn_ptr_order(&pipe->mutex); return pipe; } diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h index 08b0d1d9d78b..e0b121f96c80 100644 --- a/include/linux/lockdep.h +++ b/include/linux/lockdep.h @@ -391,6 +391,7 @@ extern int lockdep_is_held(const void *); #endif /* !LOCKDEP */ #ifdef CONFIG_PROVE_LOCKING +int lockdep_ptr_order_cmp_fn(const struct lockdep_map *, const struct lockdep_map *); void lockdep_set_lock_cmp_fn(struct lockdep_map *, lock_cmp_fn, lock_print_fn); #define lock_set_cmp_fn(lock, ...) lockdep_set_lock_cmp_fn(&(lock)->dep_map, __VA_ARGS__) @@ -398,6 +399,8 @@ void lockdep_set_lock_cmp_fn(struct lockdep_map *, lock_cmp_fn, lock_print_fn); #define lock_set_cmp_fn(lock, ...) do { } while (0) #endif +#define lock_set_cmp_fn_ptr_order(lock) lock_set_cmp_fn(lock, lockdep_ptr_order_cmp_fn); + enum xhlock_context_t { XHLOCK_HARD, XHLOCK_SOFT, diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c index 151bd3de5936..5630be7f5cb2 100644 --- a/kernel/locking/lockdep.c +++ b/kernel/locking/lockdep.c @@ -4919,6 +4919,12 @@ struct lock_class_key __lockdep_no_validate__; EXPORT_SYMBOL_GPL(__lockdep_no_validate__); #ifdef CONFIG_PROVE_LOCKING +int lockdep_ptr_order_cmp_fn(const struct lockdep_map *a, + const struct lockdep_map *b) +{ + return cmp_int((unsigned long) a, (unsigned long) b); +} + void lockdep_set_lock_cmp_fn(struct lockdep_map *lock, lock_cmp_fn cmp_fn, lock_print_fn print_fn) { -- 2.43.0