Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2479473rdh; Wed, 27 Sep 2023 04:06:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgL0wshNqPNmv6op5x9EGO2YXm07mK4A3uvHlbSyPU6IBJLM3pr6F6HAiFz6sv8ljowrMV X-Received: by 2002:a05:6a20:9751:b0:14c:5dc3:f1c9 with SMTP id hs17-20020a056a20975100b0014c5dc3f1c9mr1441968pzc.49.1695812818506; Wed, 27 Sep 2023 04:06:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695812818; cv=none; d=google.com; s=arc-20160816; b=Axe28KDPt4GU90nqLdLSbjBqqYpH4UICd3IJ0Wq/9KKiofLxWVcPSYffddUr7dpRoJ lEahBdeQzn0ejUpA/5gIHr3mrUyEWFVMESAorqOOA7GtrHzaW/fGGZQmjGOM/sq0JpV8 WXe9d430i9UIIkkYb+fUoMFTuc0hqj5JCKvQEeppkS+SEe4E5g9Ogp/4mX8YeA8NDcDT NTeZvlyXZqwSOIPtk1LRYg4NsIBDPYxWnMbTuy+rfN69nKu8x5vqqxkWsn/Vr0ygMo8s QGaB86Ig7q60UKLty9Dqe99d8XVC1qo1LtNrMhxBgZVTug9MjiUxLwvS5UjU25VMH0pk Yeeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vONsYLGOxldofhantov650b3RsYyY86s9ccAwhGuM0E=; fh=ES9GRm0OvHTGrlR9q9AUKWlovFf84z3d3o+NUQAmxBE=; b=nRF7x/8jTRuHoeY3fdfXyvZrcsYW5SDO9e0foK2KVZvEbHoExUJEwnaZy1wK0kxGlt BKIQxTk9SR5sd/ZSqyYuo9Zqas+62Q3bM++w5P/g4uH+FWGJK+shW8A7TPuRHmhroY7l 7fBqhy2/NdCh/9r5x5FSPAEFhajfmCE5cPlu7MesZS7Iwmvp0wLmoeEpMosem0aTuqL2 GEHqYI6uK4MfbZlf+jzaWbMAo+WKLaWrvmOQr5A6AfK5t2K35J+pAWsSQXVplqIoTAwY 1oGYm4gjm/owlCdxn7fdCQ+HuX3rsg6c6HC+j25DeksBRMJ6jqcueCT35719Ht6eI/Ou w7/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=sqYBT4jB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b13-20020a17090aa58d00b00274caaa057asi16860392pjq.42.2023.09.27.04.06.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 04:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=sqYBT4jB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 1B672805FD74; Tue, 26 Sep 2023 23:52:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229499AbjI0GwQ (ORCPT + 99 others); Wed, 27 Sep 2023 02:52:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjI0GwO (ORCPT ); Wed, 27 Sep 2023 02:52:14 -0400 Received: from mail-vs1-xe2f.google.com (mail-vs1-xe2f.google.com [IPv6:2607:f8b0:4864:20::e2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D8D4A3 for ; Tue, 26 Sep 2023 23:52:13 -0700 (PDT) Received: by mail-vs1-xe2f.google.com with SMTP id ada2fe7eead31-4526d872941so4822875137.1 for ; Tue, 26 Sep 2023 23:52:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1695797532; x=1696402332; 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=vONsYLGOxldofhantov650b3RsYyY86s9ccAwhGuM0E=; b=sqYBT4jB24sBI9VmRNewatyCpQeIF+kM2YXk941i8xb0loKDix6f8JRGJSUmL/8wdW MBvJfCw0j9uM1uKJAgeMXCtEjgZ91AT0pf9SQJNmuuI94ND6Q+vRVmQtmU2fP7TePCmN 9dFn4DdiSUwhW7xRD26eBqaeedXhEGweTRvhzKR/e/gBYnTOD2rYsLfZMH2NHkCvXgdG POil6sM5mLuMOO0IscYt/0SWxCvc7c0dGhtAugC4Oji1tDV6vFqMGDdmyKaG8WuLbl6f KP+oZSmDwSiDxyrAsgTMY/Fbw3QyMhMDns/0YFecBhL0gS2wn28IwrdXDDm2QhubL0Ce pCpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695797532; x=1696402332; 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=vONsYLGOxldofhantov650b3RsYyY86s9ccAwhGuM0E=; b=Lsnhk9B5Em9a127Jy0LKut5Cjhg7qFUpFfP9SuP6U5MaFt4mOk9f248UR9HGWPOlue IZW4oAx+6EvVOtTh53a+NoUEhiwBVF77pmGpIain3K9/h40+oMwS04hfUSfuQ2qEQIum vs+KAj9DA4VUXpBGm7pVo19i5MjSSdHC++re3EeQQW1dMcLIKjoBIe93N8l3bUZ1ifib aiRY84I2gJTsmOQH3rWYlN3DQCYot3AyFyUoLm4K3pGUWnD2QHPPDB9BNcUXiqzZhkBR QafOF+21whou+gpxUS17dShCBXslmGoYgOQayJKSSWzS+t20OqkmdSviisde3nxBMkCL 54Ow== X-Gm-Message-State: AOJu0Ywd0VpGvhoYzHVtBIO8jAx+hE1lAKhJS9LtXMs3PdeZ99tMtJxV 8TvMLKYZYrC1yYC7G6ZYrxp6j8LdlrTU+G82PuRrag== X-Received: by 2002:a05:6102:3551:b0:452:4d64:9347 with SMTP id e17-20020a056102355100b004524d649347mr1086522vss.35.1695797532493; Tue, 26 Sep 2023 23:52:12 -0700 (PDT) MIME-Version: 1.0 References: <20230926102914.6145-1-dg573847474@gmail.com> In-Reply-To: <20230926102914.6145-1-dg573847474@gmail.com> From: Bartosz Golaszewski Date: Wed, 27 Sep 2023 08:52:01 +0200 Message-ID: Subject: Re: [PATCH] gpio: timberdale: Fix potential deadlock on &tgpio->lock To: Chengfeng Ye Cc: linus.walleij@linaro.org, andy@kernel.org, alex@shruggie.ro, aboutphysycs@gmail.com, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 26 Sep 2023 23:52:22 -0700 (PDT) On Tue, Sep 26, 2023 at 12:29=E2=80=AFPM Chengfeng Ye wrote: > > As timbgpio_irq_enable()/timbgpio_irq_disable() callback could be > executed under irq context, it could introduce double locks on > &tgpio->lock if it preempts other execution units requiring > the same locks. > > timbgpio_gpio_set() > --> timbgpio_update_bit() > --> spin_lock(&tgpio->lock) > > --> timbgpio_irq_disable() > --> spin_lock_irqsave(&tgpio->lock) > > This flaw was found by an experimental static analysis tool I am > developing for irq-related deadlock. > > To prevent the potential deadlock, the patch uses spin_lock_irqsave() > on &tgpio->lock inside timbgpio_gpio_set() to prevent the possible > deadlock scenario. > > Signed-off-by: Chengfeng Ye > --- > drivers/gpio/gpio-timberdale.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdal= e.c > index bbd9e9191199..fad979797486 100644 > --- a/drivers/gpio/gpio-timberdale.c > +++ b/drivers/gpio/gpio-timberdale.c > @@ -43,9 +43,10 @@ static int timbgpio_update_bit(struct gpio_chip *gpio,= unsigned index, > unsigned offset, bool enabled) > { > struct timbgpio *tgpio =3D gpiochip_get_data(gpio); > + unsigned long flags; > u32 reg; > > - spin_lock(&tgpio->lock); > + spin_lock_irqsave(&tgpio->lock, flags); > reg =3D ioread32(tgpio->membase + offset); > > if (enabled) > @@ -54,7 +55,7 @@ static int timbgpio_update_bit(struct gpio_chip *gpio, = unsigned index, > reg &=3D ~(1 << index); > > iowrite32(reg, tgpio->membase + offset); > - spin_unlock(&tgpio->lock); > + spin_unlock_irqrestore(&tgpio->lock, flags); > > return 0; > } > -- > 2.17.1 > Applied, thanks! Bart