From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04E5DC433FE for ; Fri, 8 Apr 2022 11:39:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234877AbiDHLlk (ORCPT ); Fri, 8 Apr 2022 07:41:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbiDHLlj (ORCPT ); Fri, 8 Apr 2022 07:41:39 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 578D631900; Fri, 8 Apr 2022 04:39:36 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id r13so16778019ejd.5; Fri, 08 Apr 2022 04:39:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=18wquxzAz+n1ScgoEWY4/IKvflx8A2Z+AYoS3QqfJ8Q=; b=VEQC5+bvls2vZOkiJIYl1IXx7Thh7i+nLcFJJZwKWxidPwY8EbyKVR/mOthKGWGe80 jFMYCChnOfbFTpejdBW83KuqPnKFZvKeJWAkbcooEJQO4I7IHnD96PA5thg7oV+j3lW1 zd54tBmUVKPot/mup6F9Ct9yjhHmzzexQPpIEkgI24xK6E14j63g8tdk1lrg9nVN99FG cHt1wCk6iqvcdSmDnYcDBFzMz/U919wDrm7AMw0VIQXEpaEoeWbxTd1HIt/+vQXtgwMq c1uyvfez63x9v1YV6jXX0jMW1DcXN6QK7oz/8pv5A/4qbbnupiAvxQ42YLAJ9zvzYIVh mGSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=18wquxzAz+n1ScgoEWY4/IKvflx8A2Z+AYoS3QqfJ8Q=; b=ePNMih11DzExwjhqvFrCOpnRYTC4MIUteDJ/fU69PQlHqhqqvT/MheJCXhqg/GRn0R nQb4YFlWIwKE+qdkKjyI5DT7esryUoY3ZkXKDh+BZ8H/CsvQBVe7AP6D7x3luHN2DGRM jYEzGFPSFK20wa/RCITZrdRvh5vSQ2PpxeSdcDdGJVI9bOwQ6oIxz+SDgx17tZqitLw8 lLR+4t7JQZaBc8yvWksQ4MOc6Rk6fASIaul0G75ZmXMVRY6jOP7d+8O4zvGCRmTfby/d GqQLswuKkk7VpWgWzVBtdHtNEAOllGrM5het9P/QxKSZDbqI7SHiVoFgfX9PYV9YPqhi qkLg== X-Gm-Message-State: AOAM530/Yh73IaT+D2i7KGPqNIJ6f/mV0cGaPs/Hyrg42pCyVd77qdpz 7Ch5hi/4pJhGiSFu/eUl7O/hjVPf8dPUM1ry+ng= X-Google-Smtp-Source: ABdhPJyx4Hwm0L/rT6G2qrVhVrJfK29yddhRF03FHn7KTlBGfpFZBD/fguFHm5wVg0Jk1STV60qEKREpFAs0jgVsJjY= X-Received: by 2002:a17:907:968e:b0:6db:aed5:43c8 with SMTP id hd14-20020a170907968e00b006dbaed543c8mr17992154ejc.636.1649417974738; Fri, 08 Apr 2022 04:39:34 -0700 (PDT) MIME-Version: 1.0 References: <20220405135444.199295-1-maz@kernel.org> In-Reply-To: <20220405135444.199295-1-maz@kernel.org> From: Andy Shevchenko Date: Fri, 8 Apr 2022 14:35:20 +0300 Message-ID: Subject: Re: [PATCH v2 00/10] gpiolib: Handle immutable irq_chip structures To: Marc Zyngier Cc: Linux Kernel Mailing List , Linus Walleij , Bartosz Golaszewski , Thierry Reding , Joey Gouly , Jonathan Hunter , Hector Martin , Sven Peter , Alyssa Rosenzweig , Bjorn Andersson , Andy Gross , Jeffrey Hugo , Thomas Gleixner , Basavaraj Natikar , Shyam Sundar S K , "open list:GPIO SUBSYSTEM" , linux-tegra , linux-arm Mailing List , linux-arm-msm@vger.kernel.org, Android Kernel Team Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org On Wed, Apr 6, 2022 at 2:06 PM Marc Zyngier wrote: > > This is a followup from [1]. > > I recently realised that the gpiolib play ugly tricks on the > unsuspecting irq_chip structures by patching the callbacks. > > Not only this breaks when an irq_chip structure is made const (which > really should be the default case), but it also forces this structure > to be copied at nauseam for each instance of the GPIO block, which is > a waste of memory. > > My current approach is to add a new irq_chip flag (IRQCHIP_IMMUTABLE) > which does what it says on the tin: don't you dare writing to them. > Gpiolib is further updated not to install its own callbacks, and it > becomes the responsibility of the driver to call into the gpiolib when > required. This is similar to what we do for other subsystems such as > PCI-MSI. > > 5 drivers are updated to this new model: M1, QC, Tegra, pl061 and AMD > (as I actively use them) keeping a single irq_chip structure, marking > it const, and exposing the new flag. > > Nothing breaks, the volume of change is small, the memory usage goes > down and we have fewer callbacks that can be used as attack vectors. > What's not to love? Reviewed-by: Andy Shevchenko for the patches 1-3,9 and 10 after clarifying one example case. > * From v1 [1]: > - pl061 and AMD drivers converted > - New helpers to keep the changes small > - New warning for non-converted drivers > - Documentation and TODO updates > > [1] https://lore.kernel.org/r/20220223154405.54912-1-maz@kernel.org > > Marc Zyngier (10): > gpio: Don't fiddle with irqchips marked as immutable > gpio: Expose the gpiochip_irq_re[ql]res helpers > gpio: Add helpers to ease the transition towards immutable irq_chip > gpio: tegra186: Make the irqchip immutable > gpio: pl061: Make the irqchip immutable > pinctrl: apple-gpio: Make the irqchip immutable > pinctrl: msmgpio: Make the irqchip immutable > pinctrl: amd: Make the irqchip immutable > gpio: Update TODO to mention immutable irq_chip structures > Documentation: Update the recommended pattern for GPIO irqchips > > Documentation/driver-api/gpio/driver.rst | 175 ++++++++++++++++++----- > drivers/gpio/TODO | 19 +++ > drivers/gpio/gpio-pl061.c | 32 +++-- > drivers/gpio/gpio-tegra186.c | 32 +++-- > drivers/gpio/gpiolib.c | 13 +- > drivers/pinctrl/pinctrl-amd.c | 11 +- > drivers/pinctrl/pinctrl-apple-gpio.c | 29 ++-- > drivers/pinctrl/qcom/pinctrl-msm.c | 53 ++++--- > include/linux/gpio/driver.h | 16 +++ > include/linux/irq.h | 2 + > kernel/irq/debugfs.c | 1 + > 11 files changed, 293 insertions(+), 90 deletions(-) > > -- > 2.34.1 > -- With Best Regards, Andy Shevchenko From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8A4AC433FE for ; Fri, 8 Apr 2022 11:41:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Reibt9P0XpBxRxadCTltKVwduJ8BScdr8Mbc2Vh1nGs=; b=HD3uEntfWNnH/2 TNzmeUnmEP2t5AdPKXMmIrOIemgb1NpnOqhl/2GjgJb0ANNfBnnzOJyv2LrBmkNS2bVjTzSf0kJBL LTgdD15DKjsmLve4pnbwmODAVARmH6T0AMsjRgS2goBhFVcXo9R9X3harAfJqzkT0+Rid6570A96h AEf7BcXzXuiueV2AaYqEOWRm6AV8/PZv26gbTMGj5GOrsNyHKG4/ly5b6+zdK3xhfnDtuCYwjY65l K+G02a3WRqNsUtWEQevz33l71L38F7LrdVksSmOGB4HoXDbRSPFGXfw3lr9IvucuVlPvtypTW1et4 jSzdGsUwCMq+fkqn7eDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncmyI-00Gh8q-7U; Fri, 08 Apr 2022 11:40:10 +0000 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ncmxm-00GguB-Hg for linux-arm-kernel@lists.infradead.org; Fri, 08 Apr 2022 11:39:40 +0000 Received: by mail-ej1-x633.google.com with SMTP id l26so16797107ejx.1 for ; Fri, 08 Apr 2022 04:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=18wquxzAz+n1ScgoEWY4/IKvflx8A2Z+AYoS3QqfJ8Q=; b=VEQC5+bvls2vZOkiJIYl1IXx7Thh7i+nLcFJJZwKWxidPwY8EbyKVR/mOthKGWGe80 jFMYCChnOfbFTpejdBW83KuqPnKFZvKeJWAkbcooEJQO4I7IHnD96PA5thg7oV+j3lW1 zd54tBmUVKPot/mup6F9Ct9yjhHmzzexQPpIEkgI24xK6E14j63g8tdk1lrg9nVN99FG cHt1wCk6iqvcdSmDnYcDBFzMz/U919wDrm7AMw0VIQXEpaEoeWbxTd1HIt/+vQXtgwMq c1uyvfez63x9v1YV6jXX0jMW1DcXN6QK7oz/8pv5A/4qbbnupiAvxQ42YLAJ9zvzYIVh mGSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=18wquxzAz+n1ScgoEWY4/IKvflx8A2Z+AYoS3QqfJ8Q=; b=eoGHs8nEFGB/xhXJdz9azR4qaL1Wi1FebN2ey/wTe7uFgy6gcfWMl+PX4ZiPRP3j4J gt9XpWS3aB78pRTMcBvyNTqxYoMvw3fcZUvLnz+NG+zbpmnsVhkmDjxC8xknaIJmLYyF /U1/vj5AnXqdxMdTcllBAwZ7VhZN2moUXIpoTtCR6d2XsTCpWPxm57cVzc98RV3YI7O9 z08N9WTbFpk4jVouCMSGxRb+umb9bubkO9hBwzqx8NFLPr50Nwoxt9zofmQEgWKOdOmU eU/wR/DNRxp9QSW7rEiU9yANTe4ZcPnifHZ1q6sODUX/25OMePpIPP/l0Pld3yv8pCZn Q40g== X-Gm-Message-State: AOAM530B0lALRzMfeOdRPsQRrwZLcEXEYI1tRQyX65jkk646WI8nmAxL x1QDftvH+4gLGq3lrfIG7QScVn43Rl6j+yYGNOk= X-Google-Smtp-Source: ABdhPJyx4Hwm0L/rT6G2qrVhVrJfK29yddhRF03FHn7KTlBGfpFZBD/fguFHm5wVg0Jk1STV60qEKREpFAs0jgVsJjY= X-Received: by 2002:a17:907:968e:b0:6db:aed5:43c8 with SMTP id hd14-20020a170907968e00b006dbaed543c8mr17992154ejc.636.1649417974738; Fri, 08 Apr 2022 04:39:34 -0700 (PDT) MIME-Version: 1.0 References: <20220405135444.199295-1-maz@kernel.org> In-Reply-To: <20220405135444.199295-1-maz@kernel.org> From: Andy Shevchenko Date: Fri, 8 Apr 2022 14:35:20 +0300 Message-ID: Subject: Re: [PATCH v2 00/10] gpiolib: Handle immutable irq_chip structures To: Marc Zyngier Cc: Linux Kernel Mailing List , Linus Walleij , Bartosz Golaszewski , Thierry Reding , Joey Gouly , Jonathan Hunter , Hector Martin , Sven Peter , Alyssa Rosenzweig , Bjorn Andersson , Andy Gross , Jeffrey Hugo , Thomas Gleixner , Basavaraj Natikar , Shyam Sundar S K , "open list:GPIO SUBSYSTEM" , linux-tegra , linux-arm Mailing List , linux-arm-msm@vger.kernel.org, Android Kernel Team X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220408_043938_683999_AE75576A X-CRM114-Status: GOOD ( 26.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Apr 6, 2022 at 2:06 PM Marc Zyngier wrote: > > This is a followup from [1]. > > I recently realised that the gpiolib play ugly tricks on the > unsuspecting irq_chip structures by patching the callbacks. > > Not only this breaks when an irq_chip structure is made const (which > really should be the default case), but it also forces this structure > to be copied at nauseam for each instance of the GPIO block, which is > a waste of memory. > > My current approach is to add a new irq_chip flag (IRQCHIP_IMMUTABLE) > which does what it says on the tin: don't you dare writing to them. > Gpiolib is further updated not to install its own callbacks, and it > becomes the responsibility of the driver to call into the gpiolib when > required. This is similar to what we do for other subsystems such as > PCI-MSI. > > 5 drivers are updated to this new model: M1, QC, Tegra, pl061 and AMD > (as I actively use them) keeping a single irq_chip structure, marking > it const, and exposing the new flag. > > Nothing breaks, the volume of change is small, the memory usage goes > down and we have fewer callbacks that can be used as attack vectors. > What's not to love? Reviewed-by: Andy Shevchenko for the patches 1-3,9 and 10 after clarifying one example case. > * From v1 [1]: > - pl061 and AMD drivers converted > - New helpers to keep the changes small > - New warning for non-converted drivers > - Documentation and TODO updates > > [1] https://lore.kernel.org/r/20220223154405.54912-1-maz@kernel.org > > Marc Zyngier (10): > gpio: Don't fiddle with irqchips marked as immutable > gpio: Expose the gpiochip_irq_re[ql]res helpers > gpio: Add helpers to ease the transition towards immutable irq_chip > gpio: tegra186: Make the irqchip immutable > gpio: pl061: Make the irqchip immutable > pinctrl: apple-gpio: Make the irqchip immutable > pinctrl: msmgpio: Make the irqchip immutable > pinctrl: amd: Make the irqchip immutable > gpio: Update TODO to mention immutable irq_chip structures > Documentation: Update the recommended pattern for GPIO irqchips > > Documentation/driver-api/gpio/driver.rst | 175 ++++++++++++++++++----- > drivers/gpio/TODO | 19 +++ > drivers/gpio/gpio-pl061.c | 32 +++-- > drivers/gpio/gpio-tegra186.c | 32 +++-- > drivers/gpio/gpiolib.c | 13 +- > drivers/pinctrl/pinctrl-amd.c | 11 +- > drivers/pinctrl/pinctrl-apple-gpio.c | 29 ++-- > drivers/pinctrl/qcom/pinctrl-msm.c | 53 ++++--- > include/linux/gpio/driver.h | 16 +++ > include/linux/irq.h | 2 + > kernel/irq/debugfs.c | 1 + > 11 files changed, 293 insertions(+), 90 deletions(-) > > -- > 2.34.1 > -- With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel