Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp37125ybl; Tue, 7 Jan 2020 01:38:11 -0800 (PST) X-Google-Smtp-Source: APXvYqz6kAJtVujAG0VlzkenB4rwtXlE8n+zRKOujrkmtJNmkh5lCBInKJ6JPfKCSLVLfqCKBAEh X-Received: by 2002:a9d:4692:: with SMTP id z18mr117417056ote.163.1578389891014; Tue, 07 Jan 2020 01:38:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578389891; cv=none; d=google.com; s=arc-20160816; b=LTGpXD6GIIxDOQ55XupFvK9cOCUXXCxFaysD/+GXxTfoTj+mOUuib4Z462nK9kzSXD C8HFXTWJYKxVCaaSdECreEGpIGpkk3Zr/jkpWKReL4LLvFVRrWl3zWThddiailgU7Z4C dOWzxZgsMbevgrf+MnU9g/PMti+VyZVt5fHHMgbsd/p+Li62V+MGSr08Hx3fjbV1B9tU 03jHhq8UwkXsBKLLhxb8oi4eNQpmtXkXMTUt9Df1/fsd9KdIguS9aGoO2xxjGyypt8LO zFV5Oycl8Eol8S4U/ol4kq+BtAjC5YZWsc7EcZxIXhFrOHXvAWRtnepcq/oKAkzvhc/c 28DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=EjaL6TQQ67z3Hiza8RIJBFEWpIcxuINQkeVUEw4p0bg=; b=QLo1scHVZI/wBLKQOtnje8xWUrRF7L9rY2+Vapr9xbcWWqKz0RpKlKQNDssFnFr056 csSSQI8IibminDJg1+/VTTfaV71l+0RlMHPu1O0Q3wWXngt2qHhctca80THsRuLX+C6L 3yyl5tQgv+whxyYe5s0QNqIyMQmRZiAqGMBt6hA2Wqoh2w8wuNQ63sCymnC+ZVLpqXbU BUcC1YJvqslL/KL41vdvOFy1pnaxU+oHG0NcVLo78IKndi9ZeVmUNSOc6xPrSKBJ316m 05NTmUJo3razXI1XrEVmWf2OpymwBJBYgbnL5I45RVoxr3SIBOGqQgVd89g4W34hjJS2 jDpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TlO9sELl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z1si37895979otq.21.2020.01.07.01.37.57; Tue, 07 Jan 2020 01:38:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TlO9sELl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727720AbgAGJhQ (ORCPT + 99 others); Tue, 7 Jan 2020 04:37:16 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:36255 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726485AbgAGJhP (ORCPT ); Tue, 7 Jan 2020 04:37:15 -0500 Received: by mail-lj1-f193.google.com with SMTP id r19so53992464ljg.3 for ; Tue, 07 Jan 2020 01:37:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=EjaL6TQQ67z3Hiza8RIJBFEWpIcxuINQkeVUEw4p0bg=; b=TlO9sELlXVwO6vHRNSdRj0yMgj7w5fcPcrhI59kz1i5xLmAPlByZzg6ceNKc51aFD+ z/ouDTFq9LN+RS6pHBrLleeFSV7kRH63Lqxr+sI7XG6VAeejnpmn3nxdPDv4qr5jfNtj xNMAZVGIk56yodRwLq+KV1Ug7pVQIAG9DqD7F5AEM8NR+u1tdqp50WhSNyBxxPExIWt3 lBAGD5mSE5KkTla33goZBBg9B48WcRu95LEtmO6m/HMyHoVrsTXsfDzlKabFaSJ4+BaH 9dKIj+sF58tbGXkIgJPiMDbZ38NISl2YLtQdl1pn0HasmP0uM0FAEVd28rvFEYbkkysI tzCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=EjaL6TQQ67z3Hiza8RIJBFEWpIcxuINQkeVUEw4p0bg=; b=ALZ37yxWDrH8HesqX4mLpQzq2z0hBatiwtAEWBvYwLiJV3RMxUGkfGQO5KKG6zT+qe ZscEes8gy9LMFQpbjNwYtsHBEuD7zd15FtCfF+1TnYtD2DgojVKpKxd38hQOijjUrFei CporlCPirG3h8g7jNfNV5bzOb8U0hfTn2jWh1xY/9q9GYYJwst+hEJsfsAb0moGUV3ER LKS+udueI25fT8uCauonXE2jcctwCl9bc8900eC/O6hWVkqkogG4xQ4I0+3QsMf3FMas CVNLD/vyE+HDOhHMqZia1wtKMYjBlFr187njk2nRP5c/p1ufUvsR8hgnB/Eyun4A/Jv0 IcWQ== X-Gm-Message-State: APjAAAWfkilWhg0FWm76Wnx9AlcQK8DrfApzTHMOuQsKYhwsyiHOlOqb 3BJK/mtq7kcXbcgz+GJo09Y0EJpw43Sfd9J0fB7Zaw== X-Received: by 2002:a2e:9587:: with SMTP id w7mr60204347ljh.42.1578389833544; Tue, 07 Jan 2020 01:37:13 -0800 (PST) MIME-Version: 1.0 References: <20191218132605.10594-1-baijiaju1990@gmail.com> In-Reply-To: <20191218132605.10594-1-baijiaju1990@gmail.com> From: Linus Walleij Date: Tue, 7 Jan 2020 10:37:02 +0100 Message-ID: Subject: Re: [PATCH 2/2] gpio: gpio-grgpio: fix possible sleep-in-atomic-context bugs in grgpio_irq_map/unmap() To: Jia-Ju Bai , Andreas Larsson Cc: Bartosz Golaszewski , "open list:GPIO SUBSYSTEM" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 18, 2019 at 2:26 PM Jia-Ju Bai wrote: > The driver may sleep while holding a spinlock. > The function call path (from bottom to top) in Linux 4.19 is: > > drivers/gpio/gpio-grgpio.c, 261: > request_irq in grgpio_irq_map > drivers/gpio/gpio-grgpio.c, 255: > _raw_spin_lock_irqsave in grgpio_irq_map > > drivers/gpio/gpio-grgpio.c, 318: > free_irq in grgpio_irq_unmap > drivers/gpio/gpio-grgpio.c, 299: > _raw_spin_lock_irqsave in grgpio_irq_unmap > > request_irq() and free_irq() can sleep at runtime. > > To fix these bugs, request_irq() and free_irq() are called without > holding the spinlock. > > These bugs are found by a static analysis tool STCheck written by myself. > > Signed-off-by: Jia-Ju Bai I suppose this is correct, so patch applied. However there is a deeper problem, this code was added by Andreas Larsson in 2013 and at the time this was a hacky way to deal with an interrupt that is actually hierarchical. Since 2013 we have gained: - Hierarchical interrupt controllers - Hierarchical interrupt chip helpers in gpiolib So this code really needs to be modernized using a hierarchical irqchip. See for example commit: aa7d618ac65f ("gpio: ixp4xx: Convert to hierarchical GPIOLIB_IRQCHIP") for an example. Who is using grgpio these days and could work on fixing this up? Yours, Linus Walleij