Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp736492lqs; Tue, 5 Mar 2024 15:14:30 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVr8xYLmvUFm6/+M4RCqLkTTJI2af43wLy1brLkMX4/NXqQJM9as20fLEFyZhGi2YZpiYGGqaLrGZXxl1lUoscw6jJkAsfLSR+mPQhLfg== X-Google-Smtp-Source: AGHT+IF6S1426klLIO9xm+KGlBryY4V6/CvqFaayB8pHRBQRaUo7PnyPhgr2aBwYqSXb3/S0s8Fp X-Received: by 2002:a05:620a:56d3:b0:787:fd8e:6195 with SMTP id wh19-20020a05620a56d300b00787fd8e6195mr2877874qkn.51.1709680470048; Tue, 05 Mar 2024 15:14:30 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709680470; cv=pass; d=google.com; s=arc-20160816; b=CNcoYlUWu0LWalhlAiGKi6ZttXOnlrKO3phts555IHKBtYgn6jKaN4NOP2jyUGL72I kOFMsMHSNUHWsjmNYFilP7EPQZKDZgU8kIShs7p2UFZJnrxDZNUAnVDr/VA/891mgt0/ iBL9Eil/SygXrlY+JJZS2fecMw1CDXXvUShGY/EIuXUfqdmc9m7kvRTFHHF65renDlHw S4uZ9tGe3gvLVq5hbno753P3FqWi0S8+RLm52xtZWOGhya9YKubrgdqvcBQjZV4yx7Pq /Yp30kz0k62fZhfliSQQoP5Ml/vawDKeW3jcQn22Dq3cbCl4+gbJppItZTNnsdbeBRqN 9ifA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=QZKWR0J2srML+eyhC61XR43/wjQEkRkTGp8CW9dDv+M=; fh=//uktxlojOqEkEi7NsIx3KkoNzPQYm5XwWlH5/DNuHU=; b=jS4iMT25g6E7OwHryWDhXF9TChRhZb9NVXZdp/DKZGhGiWavytG/AwvCoOZ4xsMjaC AK+vykUPBpoclUZZ+oJaXRRgD6JViToGYEC7HW8MXV2Ly03VoNuNhPXdJwDhIO3OOw3r JytPku7B/cXessXSQ2Utqlwjnlb+v443eikYCxBJFs4nbBLp+leBUBHGu5S/i+H4R5x/ fMLdODGOM7eprXIbpRIw8ur039OY2GEYIdRaCpbkWs0/4WgLJWcmBXHR8wpkNI33sH2+ hYgPul26/M8VqruBaZ0jGLtdUBzLViscNkVK96FmOsXuP65uNxQJjy6C9xqZ73J1JKT7 jpQA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NAfDVBqM; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-93083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l4-20020a05620a28c400b007883c232230si1035130qkp.632.2024.03.05.15.14.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 15:14:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NAfDVBqM; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-93083-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93083-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8A7CA1C24D68 for ; Tue, 5 Mar 2024 23:14:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CF9112D21E; Tue, 5 Mar 2024 23:14:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="NAfDVBqM" Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE4BA12D218 for ; Tue, 5 Mar 2024 23:13:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680439; cv=none; b=PTuSgZI5P+UMKeX2W52GS1G4PD+iB35bhAiy4+8JOWjkJFf13WRLOWHf1ttg2swe80xePE9T3SsaI69hZGePC2xpqatmNWRkc6sfVYr00uTw4vMa+hUDaugQDDO/MH5Atznt2y/OqBQMmSCG2tOkjiYe1ezZT2pp5uoJda0YXX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709680439; c=relaxed/simple; bh=ZSE908MrL3W9EF4A9/FeE48VeA9QUapWInD9HpQG3I0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=pGQeZVxedNKnwltrCfWPRsAPiGm6CC3QiMfTCfmY2zoZJjkFSYR0BbJADp2JTEXHewiZdYeMKNEDEi3Gt/NHbS5cuqtO6gyjvmgMAFRuMMcFOuy5Zo7ves3i8X9AjXDOrDIJf4NhEA8dM7QlCaJTgvwbPZrR7rPjmQMnJjazWhQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=NAfDVBqM; arc=none smtp.client-ip=209.85.166.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-36523b9fa11so26710365ab.3 for ; Tue, 05 Mar 2024 15:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1709680437; x=1710285237; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=QZKWR0J2srML+eyhC61XR43/wjQEkRkTGp8CW9dDv+M=; b=NAfDVBqM+p5SRXWtSIgOYxV9sxY/2zgZfqzQCPpIYxRFqFXeQ5isK3k7txHHdhTuAo NDu6m7gpRJRyJBDq5OJg7LNq5YEq7sHrhfWl/2mzVB26dNdsIPuFXVgZFv60c4cQ9AlY T+ri09c0i6+A8oFm1NTtbz4pWQpPQtftBxI8U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709680437; x=1710285237; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QZKWR0J2srML+eyhC61XR43/wjQEkRkTGp8CW9dDv+M=; b=LChFOukNB8toY284WVOBT7k36jPzros9taw50g1Vzho28bpkcQcRObQbyyU7xAWH06 /35Kdcj1SAgTNBqvkQ8WdVFTN/Do2C/4PMsm4iao4IROpiRd+/Ed2hmEf8jKOLbt+hXx U3bVJn9ROHZy/ieAdHRNr3zc7mbMNJIxgrdyBpJgU2PVuu9m0bq9XWjPqHadYg1V5aP4 G7W8TmtyNAhS8q51dbJqsKRFuNx0dmRaryt71Ar7qeYWySuYYKGQ2NbV1tLX+d+hul1K R3msQO5HFpaWQSSh3XfD4h50UYDxmiVjymHyCScMCB3xBZ3dxcjWVZVjZx73lf1cWLFm sluw== X-Forwarded-Encrypted: i=1; AJvYcCWjLg3E68cLTt6FfqdB4LyQUpN2gPytDicAnY/33R+N1Hlo5b4RbuXYBQvvbI3JOYHTXquvYB1+KIyfPHQLK3pe5zFGWVtIF5Qz0Ydu X-Gm-Message-State: AOJu0YyWLQ4IOLzM/83rRothCiIEt4g+YZ3c0nKh1XEYGmRoo8LYa05h kro6wei6FgHG56KBr+o1lA9UjI5EiIfgaM2niaanqVfwR8ttJPm9xM82Mjfs+KK6Yo/u+ZceSv/ XJ9aqvfFHnLdePiU+cBweLWcp67ank//JaT7E8QWI2dpwToA= X-Received: by 2002:a05:6e02:1a68:b0:365:7607:3f5d with SMTP id w8-20020a056e021a6800b0036576073f5dmr17242881ilv.3.1709680436858; Tue, 05 Mar 2024 15:13:56 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240305225652.22872-1-quic_mdtipton@quicinc.com> In-Reply-To: <20240305225652.22872-1-quic_mdtipton@quicinc.com> From: Rob Clark Date: Tue, 5 Mar 2024 15:13:46 -0800 Message-ID: Subject: Re: [PATCH] interconnect: Don't access req_list while it's being manipulated To: Mike Tipton Cc: djakov@kernel.org, quic_rlaggysh@quicinc.com, quic_okukatla@quicinc.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Mar 5, 2024 at 2:57=E2=80=AFPM Mike Tipton wrote: > > The icc_lock mutex was split into separate icc_lock and icc_bw_lock > mutexes in [1] to avoid lockdep splats. However, this didn't adequately > protect access to icc_node::req_list. > > The icc_set_bw() function will eventually iterate over req_list while > only holding icc_bw_lock, but req_list can be modified while only > holding icc_lock. This causes races between icc_set_bw(), of_icc_get(), > and icc_put(). > > Example A: > > CPU0 CPU1 > ---- ---- > icc_set_bw(path_a) > mutex_lock(&icc_bw_lock); > icc_put(path_b) > mutex_lock(&icc_lock); > aggregate_requests() > hlist_for_each_entry(r, ... > hlist_del(... > > > Example B: > > CPU0 CPU1 > ---- ---- > icc_set_bw(path_a) > mutex_lock(&icc_bw_lock); > path_b =3D of_icc_get() > of_icc_get_by_index() > mutex_lock(&icc_lock); > path_find() > path_init() > aggregate_requests() > hlist_for_each_entry(r, ... > hlist_add_head(... > > > Fix this by ensuring icc_bw_lock is always held before manipulating > icc_node::req_list. The additional places icc_bw_lock is held don't > perform any memory allocations, so we should still be safe from the > original lockdep splats that motivated the separate locks. > > [1] commit af42269c3523 ("interconnect: Fix locking for runpm vs reclaim"= ) > > Signed-off-by: Mike Tipton > Fixes: af42269c3523 ("interconnect: Fix locking for runpm vs reclaim") Looks good from a memory/lockdep standpoint, Reviewed-by: Rob Clark > --- > drivers/interconnect/core.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/drivers/interconnect/core.c b/drivers/interconnect/core.c > index 5d1010cafed8..7e9b996b47c8 100644 > --- a/drivers/interconnect/core.c > +++ b/drivers/interconnect/core.c > @@ -176,6 +176,8 @@ static struct icc_path *path_init(struct device *dev,= struct icc_node *dst, > > path->num_nodes =3D num_nodes; > > + mutex_lock(&icc_bw_lock); > + > for (i =3D num_nodes - 1; i >=3D 0; i--) { > node->provider->users++; > hlist_add_head(&path->reqs[i].req_node, &node->req_list); > @@ -186,6 +188,8 @@ static struct icc_path *path_init(struct device *dev,= struct icc_node *dst, > node =3D node->reverse; > } > > + mutex_unlock(&icc_bw_lock); > + > return path; > } > > @@ -792,12 +796,16 @@ void icc_put(struct icc_path *path) > pr_err("%s: error (%d)\n", __func__, ret); > > mutex_lock(&icc_lock); > + mutex_lock(&icc_bw_lock); > + > for (i =3D 0; i < path->num_nodes; i++) { > node =3D path->reqs[i].node; > hlist_del(&path->reqs[i].req_node); > if (!WARN_ON(!node->provider->users)) > node->provider->users--; > } > + > + mutex_unlock(&icc_bw_lock); > mutex_unlock(&icc_lock); > > kfree_const(path->name); > -- > 2.17.1 >