From nobody Sun Feb 8 17:36:46 2026 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 88A38C77B73 for ; Tue, 30 May 2023 21:47:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233589AbjE3Vrd (ORCPT ); Tue, 30 May 2023 17:47:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbjE3Vr3 (ORCPT ); Tue, 30 May 2023 17:47:29 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE846106 for ; Tue, 30 May 2023 14:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685483206; 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=VqBO6vTTzk4oznJ9hlyfyIGAmPcF6erUeOSR8ZOo0PY=; b=OW58rvcUtcki+xz7VT5F9+UETeGNCkfHo9a6qSIfAaM6uxPMeP1rhRyga6FkGCF61mazU9 3fMYDN31KnBWG9m+OA4ZrKk9vBuBsb3vD6fxDn4qEJ7k965vyq+h3egj8I538Cw2b3SADA b0gC+QnR9xfZFCxImVcmI11k0bXEY+g= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-OGnXMq6ANB6wrNGukqlJpA-1; Tue, 30 May 2023 17:46:45 -0400 X-MC-Unique: OGnXMq6ANB6wrNGukqlJpA-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3f80f8e5eb1so29727291cf.1 for ; Tue, 30 May 2023 14:46:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483204; x=1688075204; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VqBO6vTTzk4oznJ9hlyfyIGAmPcF6erUeOSR8ZOo0PY=; b=jObzNqv7DJrokVuyoErZ6uhPepsbthrV3uCxgxEadOhFVjSlDlGprPBap9zOH74E28 J9tuaWdzf1f+pfad6sFwmQazM9dewLUw+fs0DUlsePXi4CYzPFI7b2MPrleuWu4oZ6fz zb3GmDNJwoQU+hVDfF2frbhhZmCmVLaitAFyKlspH0TjBAv2BLMNJd2l80PyQVPJYwXD axnqXXqeraDnUvEsj/RHgW44857qsQ5kMe43Ecw6hf6HoQ3AP0l50N88/RZ6en5EB/KZ 3LzboP8/AKqqLRHmXE81gCnjAN8zobdUJhvxJmnv+Po9o1H7OH4wp60DZ870fvwKkXkX fESQ== X-Gm-Message-State: AC+VfDwZ2qofCGrNbHlSQU7QngptG2qVfMP0XrysWtUWLAUlre3Co7a/ JtyhXGePSPrhutZ/Yb3mXRK5/iap8cssYBajr9Gfhf60yXOtMNnpdMOQL5px04PtfzM5gOvvW52 Z5Mx3OSsXGCFmEu0qZnuKVEJeffzg+nQvTAGFBCdHk78BXtKxVmFa947UswmJC/CVYt4SrnuSU3 N8kGyX7jA= X-Received: by 2002:a05:622a:203:b0:3f3:669f:473a with SMTP id b3-20020a05622a020300b003f3669f473amr3798147qtx.57.1685483204472; Tue, 30 May 2023 14:46:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5qcQD/xcCnlOGQcJjUFjRM/CuzaO9UDyH56GpMOoIAI4SyN1rp1LEW0R+l/WFlqgoPFhwTrw== X-Received: by 2002:a05:622a:203:b0:3f3:669f:473a with SMTP id b3-20020a05622a020300b003f3669f473amr3798132qtx.57.1685483204182; Tue, 30 May 2023 14:46:44 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm5121602qtc.82.2023.05.30.14.46.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 14:46:43 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Marc Zyngier , Thomas Gleixner Subject: [RFC PATCH 1/5] irq: Always enable parent interrupt tracking Date: Tue, 30 May 2023 17:45:46 -0400 Message-Id: <20230530214550.864894-2-rrendec@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530214550.864894-1-rrendec@redhat.com> References: <20230530214550.864894-1-rrendec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The kernel already has some support for tracking the parent interrupt in the case of chained interrupts, but it is currently used only by the IRQ-resend code. This patch enables the parent interrupt tracking code unconditionally. The IRQ-resend code still depends on CONFIG_HARDIRQS_SW_RESEND. The intention is to (re)use the existing parent interrupt tracking support for different purposes, more specifically to expose chained interrupt topology to userspace. That, in turn, makes it possible to control the SMP affinity of chained interrupts in a way that does not break the existing interface and the promises it makes. Signed-off-by: Radu Rendec --- include/linux/irq.h | 7 ------- kernel/irq/manage.c | 2 -- 2 files changed, 9 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index b1b28affb32a7..7710f157e12de 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -641,14 +641,7 @@ static inline void irq_force_complete_move(struct irq_= desc *desc) { } =20 extern int no_irq_affinity; =20 -#ifdef CONFIG_HARDIRQS_SW_RESEND int irq_set_parent(int irq, int parent_irq); -#else -static inline int irq_set_parent(int irq, int parent_irq) -{ - return 0; -} -#endif =20 /* * Built-in IRQ handlers for various IRQ types, diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index eb862b5f91c42..49683e55261eb 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1004,7 +1004,6 @@ int __irq_set_trigger(struct irq_desc *desc, unsigned= long flags) return ret; } =20 -#ifdef CONFIG_HARDIRQS_SW_RESEND int irq_set_parent(int irq, int parent_irq) { unsigned long flags; @@ -1019,7 +1018,6 @@ int irq_set_parent(int irq, int parent_irq) return 0; } EXPORT_SYMBOL_GPL(irq_set_parent); -#endif =20 /* * Default primary interrupt handler for threaded interrupts. Is --=20 2.40.1 From nobody Sun Feb 8 17:36:46 2026 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 59090C7EE23 for ; Tue, 30 May 2023 21:47:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232653AbjE3Vrp (ORCPT ); Tue, 30 May 2023 17:47:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231723AbjE3Vrl (ORCPT ); Tue, 30 May 2023 17:47:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87897113 for ; Tue, 30 May 2023 14:46:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685483210; 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=aiTjFtC5d0ywUVJqroEDBw4SKoGPctycpTO5H1+bDbM=; b=ZGQGNDwghOz/zHt6JCmxWxPFGR/fOxQRPokCUgNScpBe4HutbhCUCeX4/NdkEwUVs20NET kB3Z6/pXvbUqmPdMjhBqLZ4WMM8EnDEBEbHwC8fxNQ5NqnG8+zCfvpRHFAGpLk+PksD7CZ VLZLqrJaHvkz/zp5drXddcV8uIy2cKk= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-499-sm858xiiNDm4UL5gzh2iyQ-1; Tue, 30 May 2023 17:46:49 -0400 X-MC-Unique: sm858xiiNDm4UL5gzh2iyQ-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-3f6aaa6df23so33489581cf.0 for ; Tue, 30 May 2023 14:46:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483208; x=1688075208; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aiTjFtC5d0ywUVJqroEDBw4SKoGPctycpTO5H1+bDbM=; b=RLQYXE/MATdKC/lPPl8QxquWtyHIc987oauSx4OZfsRdrBNdnnz0Ya+UCTmri0GLm1 xsTKxCQHdoKIKaQ9LZsIHDqSW0mxjL3iDy6hPQy+Z4Ay0bpBa0yvUgM/tKp1RPUCVKvP 7qtzzmzqTBinf916uw1hXd/y16hQ9K58zIoWxB5Cj2trzIT9yNAw/F7X+sLyjUFcfuYb lQx9/Aa9JjajKCvxpDdInd3ajX1ek5ZOrHV2vifsZiMBqHYqJqmwGpHGMdFmiPxnQp8R 819IbdFoHdwwZQ5xnSrZbAbPsanBzHYAPaUvdwiv8DyYq/Q8olfQyRBLr+2qVrsaS3Gm YAlA== X-Gm-Message-State: AC+VfDzKBcF+uokrFuOyt0uI8ezjByc0jGQ8MUv1VBrdNnCOJ0W5vpa2 Q7BtB1W7nefbnEu+AUw8Rm1aT4PFZfV8bKrdhJ28kaOnF/EoFheG3CsdIIlQC5TfrQLVMhy9irn Xb9/pmjkFk0TVnRkxCxMrb0wMY4pTo3JjqWdQK6/39t4p2p/ubw21+pii5DdN7nfbe3YgclJ50Q 19UxdEQxs= X-Received: by 2002:a05:622a:4d:b0:3f6:b760:f3dd with SMTP id y13-20020a05622a004d00b003f6b760f3ddmr4181189qtw.33.1685483208516; Tue, 30 May 2023 14:46:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ507wIALjSuHpRo1cS0IkJi/HtXsdUCgPGx8sAhAVNpmCGQpGDAweoxaSLIhaiw8o3q/Hd8/A== X-Received: by 2002:a05:622a:4d:b0:3f6:b760:f3dd with SMTP id y13-20020a05622a004d00b003f6b760f3ddmr4181173qtw.33.1685483208211; Tue, 30 May 2023 14:46:48 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm5121602qtc.82.2023.05.30.14.46.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 14:46:47 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Marc Zyngier , Thomas Gleixner Subject: [RFC PATCH 2/5] irq: Show the parent chained interrupt in debugfs Date: Tue, 30 May 2023 17:45:47 -0400 Message-Id: <20230530214550.864894-3-rrendec@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530214550.864894-1-rrendec@redhat.com> References: <20230530214550.864894-1-rrendec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This is a trivial change to expose the parent chained interrupt. The intention is to make it easier to debug chained interrupts, particularly in the context of setting the SMP affinity. Signed-off-by: Radu Rendec --- kernel/irq/debugfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/irq/debugfs.c b/kernel/irq/debugfs.c index bbcaac64038ef..3ada976df8612 100644 --- a/kernel/irq/debugfs.c +++ b/kernel/irq/debugfs.c @@ -177,6 +177,7 @@ static int irq_debug_show(struct seq_file *m, void *p) ARRAY_SIZE(irqdesc_istates)); seq_printf(m, "ddepth: %u\n", desc->depth); seq_printf(m, "wdepth: %u\n", desc->wake_depth); + seq_printf(m, "parent: %d\n", desc->parent_irq); seq_printf(m, "dstate: 0x%08x\n", irqd_get(data)); irq_debug_show_bits(m, 0, irqd_get(data), irqdata_states, ARRAY_SIZE(irqdata_states)); --=20 2.40.1 From nobody Sun Feb 8 17:36:46 2026 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 5DB68C77B73 for ; Tue, 30 May 2023 21:47:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233613AbjE3Vrt (ORCPT ); Tue, 30 May 2023 17:47:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233597AbjE3Vrp (ORCPT ); Tue, 30 May 2023 17:47:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8876F3 for ; Tue, 30 May 2023 14:46:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685483213; 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=kO4HrmMAvzIB24zLmV9JKi88Zlv8JWkZRaktK8Z6cck=; b=dHEmpEDMHj94zg7ZzUId3cjxT9LF9rQUlHN/aJYAfTSuGBpzrGBJVrAKX38ln1CWorpLIW R0ciF5NKfYJskFekid60TgR11azHR7JmzcPEAKspbcpJDkRVzTpCwcVSVdoHDRNkIWBdTS jDqIqfVE8v1PbEPEdeHYwAnEfeRB1B4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-589-V95T6UtyMda73xeVsM7tvw-1; Tue, 30 May 2023 17:46:52 -0400 X-MC-Unique: V95T6UtyMda73xeVsM7tvw-1 Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-75cac31d806so680799885a.1 for ; Tue, 30 May 2023 14:46:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483212; x=1688075212; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kO4HrmMAvzIB24zLmV9JKi88Zlv8JWkZRaktK8Z6cck=; b=I8uq4mIh804DxMbdeF440DKunMex9edkObEM/wuLLYN1kwwCPoiRfGBT5nkdePdSZm 6ZB5utfGdIAcxfi713aj2d5gBHfSjd9GzRxDldQnGJp1KPpYEGqAXO56PEQWhqte/2vh uNR9J84Ky3639YjTCnPv4LSrol8uFJ5JtqD58dK3KY+Zb/XEx1utHYxcBwgysVWyeXve FsxuKgtDy2y9BE01HwNudv2GyPAY/fNb78Zt2EZgoJzVlPdrtAoW6QsuNjrwrXLgt2Rv K05pQU3DKCZSdSx9lE1TRdws/TzeOmtcJstuwv0INoWlL2ERVxDQix/PixwnONs3bZQr T+Vw== X-Gm-Message-State: AC+VfDxgg0ou4hqfLzRVUy1NBF6+mk1SuU8uZ/sWUB7enF1dqzmSvuf1 yNpAniJN5iBC9UPEhtFKZA6xGscTG507PrI8ldw/3ljXYNQXto77p6jJ+jlQ4xqSTHwKlO6kzt+ PH4+vrqYl6uTVBTFMKcxhcvnaZD221KrksNe6NRmGy1KVZ/+NfIzlFYvqik0U/d5jffeZw2GLo2 bBul8+mAo= X-Received: by 2002:a05:622a:1aa7:b0:3f6:a725:25a1 with SMTP id s39-20020a05622a1aa700b003f6a72525a1mr3933602qtc.6.1685483211600; Tue, 30 May 2023 14:46:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7lzkB2UWPHFLtb06YvCGpmh+Kt1MdRddN01szlDEF7jY7DAeFlNcyjMjep14IIklu9GbZlfQ== X-Received: by 2002:a05:622a:1aa7:b0:3f6:a725:25a1 with SMTP id s39-20020a05622a1aa700b003f6a72525a1mr3933574qtc.6.1685483211078; Tue, 30 May 2023 14:46:51 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm5121602qtc.82.2023.05.30.14.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 14:46:50 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Marc Zyngier , Thomas Gleixner Subject: [RFC PATCH 3/5] irq: Expose chained interrupt parents in sysfs Date: Tue, 30 May 2023 17:45:48 -0400 Message-Id: <20230530214550.864894-4-rrendec@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530214550.864894-1-rrendec@redhat.com> References: <20230530214550.864894-1-rrendec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch extends irq_set_parent() by adding the ability to show the direct parent of a chained interrupt as a symlink in sysfs. In addition, the root level interrupt (in a multi-level chained interrupt topology) will also show all child interrupts. Example: $ ls -l /sys/kernel/irq/38/muxed_irqs/ total 0 lrwxrwxrwx 1 root root 0 May 24 16:00 41 -> ../../41 lrwxrwxrwx 1 root root 0 May 24 16:00 42 -> ../../42 $ ls -l /sys/kernel/irq/41/parent lrwxrwxrwx 1 root root 0 May 24 16:00 /sys/kernel/irq/41/parent -> ../38 $ ls -l /sys/kernel/irq/42/parent lrwxrwxrwx 1 root root 0 May 24 16:18 /sys/kernel/irq/42/parent -> ../38 Chained IRQ chip drivers are expected to call irq_set_parent() in their .map domain op handler. A few already do (for the purpose of enabling IRQ-resend support). An IRQ chip driver may also implement the newer hierarchical domain API and still use chained interrupts. In that case, irq_set_parent() would be called in the .alloc domain op handler. Since most legacy drivers do not implement the .unmap domain op and most hierarchical drivers use irq_domain_free_irqs_common() as their .free domain op, the irqdomain core is modified to remove an existing parent mapping automatically when the interrupt is disassociated with the domain. The whole purpose of exposing interrupt topology in sysfs is to be able to control the SMP affinity of chained interrupts. Since chained IRQ chips can be stacked and the affinity can be typically controlled only at the root level, irq_set_parent() will always populate the muxed_irqs directory of the root interrupt, not the one of the direct parent. However, the "parent" symlink will always point to the direct parent. Notes (RFC/draft patch): * The muxed_irqs directory may not be necessary to control the SMP affinity. See the cover letter for details. * Synchronization around muxed_irqs is likely broken. But since we may decide to get rid of muxed_irqs altogether, the implementation here is provided as a proof of concept and ground for discussion. Signed-off-by: Radu Rendec --- include/linux/irqdesc.h | 1 + kernel/irq/internals.h | 8 ++++ kernel/irq/irqdesc.c | 84 +++++++++++++++++++++++++++++++++++------ kernel/irq/irqdomain.c | 15 ++++++++ kernel/irq/manage.c | 16 ++++++-- 5 files changed, 110 insertions(+), 14 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index 844a8e30e6de5..b57450745857f 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -97,6 +97,7 @@ struct irq_desc { #ifdef CONFIG_SPARSE_IRQ struct rcu_head rcu; struct kobject kobj; + struct kobject *muxed_irqs; #endif struct mutex request_mutex; int parent_irq; diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index 5fdc0b5575797..c75cd836155c9 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -101,6 +101,14 @@ static inline void irq_mark_irq(unsigned int irq) { } extern void irq_mark_irq(unsigned int irq); #endif =20 +#if defined(CONFIG_SPARSE_IRQ) && defined(CONFIG_SYSFS) +extern void irq_sysfs_update_parent(struct irq_desc *desc, + struct irq_desc *parent); +#else +static inline void irq_sysfs_update_parent(struct irq_desc *desc, + struct irq_desc *parent) { } +#endif + extern int __irq_get_irqchip_state(struct irq_data *data, enum irqchip_irq_state which, bool *state); diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index d45c163dbb749..ec52b8b41002e 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -285,17 +285,27 @@ static const struct kobj_type irq_kobj_type =3D { =20 static void irq_sysfs_add(int irq, struct irq_desc *desc) { - if (irq_kobj_base) { - /* - * Continue even in case of failure as this is nothing - * crucial and failures in the late irq_sysfs_init() - * cannot be rolled back. - */ - if (kobject_add(&desc->kobj, irq_kobj_base, "%d", irq)) - pr_warn("Failed to add kobject for irq %d\n", irq); - else - desc->istate |=3D IRQS_SYSFS; + if (!irq_kobj_base) + return; + + /* + * Continue even in case of failure as this is nothing + * crucial and failures in the late irq_sysfs_init() + * cannot be rolled back. + */ + if (kobject_add(&desc->kobj, irq_kobj_base, "%d", irq)) { + pr_warn("Failed to add kobject for irq %d\n", irq); + return; + } + + desc->muxed_irqs =3D kobject_create_and_add("muxed_irqs", &desc->kobj); + if (!desc->muxed_irqs) { + pr_warn("Failed to add mux kobject for irq %d\n", irq); + kobject_del(&desc->kobj); + return; } + + desc->istate |=3D IRQS_SYSFS; } =20 static void irq_sysfs_del(struct irq_desc *desc) @@ -306,8 +316,10 @@ static void irq_sysfs_del(struct irq_desc *desc) * sysfs is not initialized yet, and the case of a failed * kobject_add() invocation. */ - if (desc->istate & IRQS_SYSFS) + if (desc->istate & IRQS_SYSFS) { + kobject_del(desc->muxed_irqs); kobject_del(&desc->kobj); + } } =20 static int __init irq_sysfs_init(void) @@ -333,6 +345,55 @@ static int __init irq_sysfs_init(void) } postcore_initcall(irq_sysfs_init); =20 +static inline struct irq_desc *irq_find_root_desc(struct irq_desc *desc) +{ + while (desc && desc->parent_irq) + desc =3D irq_to_desc(desc->parent_irq); + + return desc; +} + +/* + * Update sysfs entries to show that parent_desc is the new parent of desc + * + * At this point, desc->parent_irq is the old parent, and parent_desc is t= he + * new parent. If no parent has been set yet, desc->parent is 0. If the pa= rent + * is being removed, parent_desc is NULL. + * + * Called with desc->request_mutex locked. + */ +void irq_sysfs_update_parent(struct irq_desc *desc, struct irq_desc *paren= t_desc) +{ + unsigned int irq =3D desc->irq_data.irq; + struct irq_desc *root_desc; + int err; + + /* First, remove all references to the old parent (if any). */ + if (desc->parent_irq) { + sysfs_remove_link(&desc->kobj, "parent"); + root_desc =3D irq_find_root_desc(irq_to_desc(desc->parent_irq)); + if (!WARN_ON(!root_desc)) + sysfs_remove_link(root_desc->muxed_irqs, desc->kobj.name); + } + + /* Next, create references to the new parent (if any). */ + if (!parent_desc) + return; + + err =3D sysfs_create_link(&desc->kobj, &parent_desc->kobj, "parent"); + if (err) + pr_warn("Failed to link irq %u parent: %d\n", irq, err); + + root_desc =3D irq_find_root_desc(parent_desc); + if (WARN_ON(!root_desc)) + return; + + err =3D sysfs_create_link(root_desc->muxed_irqs, &desc->kobj, + desc->kobj.name); + if (err) + pr_warn("Failed to link irq %u root: %d\n", irq, err); +} + #else /* !CONFIG_SYSFS */ =20 static const struct kobj_type irq_kobj_type =3D { @@ -438,6 +499,7 @@ static void delayed_free_desc(struct rcu_head *rhp) { struct irq_desc *desc =3D container_of(rhp, struct irq_desc, rcu); =20 + kobject_put(desc->muxed_irqs); kobject_put(&desc->kobj); } =20 diff --git a/kernel/irq/irqdomain.c b/kernel/irq/irqdomain.c index f34760a1e2226..fad1559587c3e 100644 --- a/kernel/irq/irqdomain.c +++ b/kernel/irq/irqdomain.c @@ -553,6 +553,14 @@ static void irq_domain_disassociate(struct irq_domain = *domain, unsigned int irq) =20 mutex_lock(&domain->root->mutex); =20 + /* + * For domains that support it, irq_set_parent() is called in the map() + * op. The reverse operation of removing the parent mapping should be + * done in the unmap() op which is called below. Since most domains do + * not implement unmap(), remove the parent mapping here. + */ + irq_set_parent(irq, 0); + irq_set_status_flags(irq, IRQ_NOREQUEST); =20 /* remove chip and handler */ @@ -1748,6 +1756,13 @@ void irq_domain_free_irqs(unsigned int virq, unsigne= d int nr_irqs) domain =3D data->domain; =20 mutex_lock(&domain->root->mutex); + /* + * Typically irq_set_parent() would be called in the alloc() op. The + * reverse operation of removing the parent mapping should be done in + * the free() op which is called indirectly below. Since most domains + * use irq_domain_free_irqs_common(), remove the parent mapping here. + */ + irq_set_parent(virq, 0); for (i =3D 0; i < nr_irqs; i++) irq_domain_remove_irq(virq + i); irq_domain_free_irqs_hierarchy(domain, virq, nr_irqs); diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index 49683e55261eb..eec9b94747439 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -1007,14 +1007,24 @@ int __irq_set_trigger(struct irq_desc *desc, unsign= ed long flags) int irq_set_parent(int irq, int parent_irq) { unsigned long flags; - struct irq_desc *desc =3D irq_get_desc_lock(irq, &flags, 0); + struct irq_desc *desc =3D irq_to_desc(irq); + struct irq_desc *parent_desc =3D parent_irq ? + irq_to_desc(parent_irq) : NULL; =20 - if (!desc) + if (!desc || (parent_irq && !parent_desc)) return -EINVAL; =20 + mutex_lock(&desc->request_mutex); + + if (desc->parent_irq !=3D parent_irq) + irq_sysfs_update_parent(desc, parent_desc); + + raw_spin_lock_irqsave(&desc->lock, flags); desc->parent_irq =3D parent_irq; + raw_spin_unlock_irqrestore(&desc->lock, flags); + + mutex_unlock(&desc->request_mutex); =20 - irq_put_desc_unlock(desc, flags); return 0; } EXPORT_SYMBOL_GPL(irq_set_parent); --=20 2.40.1 From nobody Sun Feb 8 17:36:46 2026 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 917CEC77B73 for ; Tue, 30 May 2023 21:47:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233603AbjE3Vrq (ORCPT ); Tue, 30 May 2023 17:47:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233598AbjE3Vrn (ORCPT ); Tue, 30 May 2023 17:47:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1DB25C7 for ; Tue, 30 May 2023 14:46:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685483217; 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=Tqxh8RwR0SLkelcDFbazXgBZl6jZFQi1SW6VSeth23s=; b=HVok3aIfylnD6NvpwishC7Gs0+RaAmtWmSsd5zSvxBZjLx6+6JkzBfgfCm7mEUaoFMO/fO 1i3pLhqrowuSKl13TC13X6NuMOZuLQY7m8t9zXeCXnc0knsHUg7sy/mpG2mNi9Gpg3i0V0 TbUnizsmhKENp+WBKX/+Fh9caGkigcI= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-mJGqZ-pkMFiXSDovd4REFQ-1; Tue, 30 May 2023 17:46:56 -0400 X-MC-Unique: mJGqZ-pkMFiXSDovd4REFQ-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-3f6c9fef4beso34421771cf.0 for ; Tue, 30 May 2023 14:46:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483215; x=1688075215; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Tqxh8RwR0SLkelcDFbazXgBZl6jZFQi1SW6VSeth23s=; b=fKXPGOtM5AZGMGXYiy2B/WF9/Ddceh3/6ZHO8hZYAAqZmahtZNw5VGFiLjsV9UK/Pl Ku1CM58pbxc5i+1v56j2P2ldJmKI14+lSscRv0ipeiOoaAPvqs4cPbT0SrZe/tvxpT7M PbiBEuA1JGQVX4I7m2DWqkO3i7fuyi8wiisYaZ2eGx47BVEYWES7SB9WVR4UFFdlnuBO LO3vdYQa1vl7D8iIdMRfn+2RkFHyvxTY/0KkO5OsLVnjnntePvDfgmVEbKg0gIuPUu4D jwac5+woOf61MhV4UcTlD/2SNaLIp5K4e4DVN02vjH4BoPQQd2gqVtwr5cVu4QpOv3HO bZbw== X-Gm-Message-State: AC+VfDxw4llYmDtmgbuaCRXM17E6cBzWdDKj2t0peUkYnb3kIyY3lqQD VLVzCHVQrRJB3i7tUReo3oZy8x9GgFjHcbLXGag/ndjzRx9788fT5LIVsRbe9fpswEyD1zQrZJi JHC8o9tlYTfNz+9euBVC9NsPOmbZkPsdIx/GW5xQdCSoXAD8Iigd2Srm2qgnSHt60p1WBohskAr VL7NDePpg= X-Received: by 2002:a05:622a:489:b0:3f5:456b:d565 with SMTP id p9-20020a05622a048900b003f5456bd565mr4276916qtx.24.1685483215026; Tue, 30 May 2023 14:46:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5sVCstOadQ3lvyLpuXD2JCAzbScKi5fJ0RtGpdAet/ZxrWfXxKbD2DB4wvPuKP1yEMB5h43A== X-Received: by 2002:a05:622a:489:b0:3f5:456b:d565 with SMTP id p9-20020a05622a048900b003f5456bd565mr4276895qtx.24.1685483214683; Tue, 30 May 2023 14:46:54 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm5121602qtc.82.2023.05.30.14.46.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 14:46:54 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Marc Zyngier , Thomas Gleixner Subject: [RFC PATCH 4/5] irq: Move SMP affinity write handler out of proc.c Date: Tue, 30 May 2023 17:45:49 -0400 Message-Id: <20230530214550.864894-5-rrendec@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530214550.864894-1-rrendec@redhat.com> References: <20230530214550.864894-1-rrendec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch prepares the ground for setting the SMP affinity from sysfs. The bulk of the code is identical for procfs and sysfs, except for the cpumask parsing functions, where procfs requires the _user variants. Summary of changes: - irq_select_affinity_usr() and write_irq_affinity() are moved from from proc.c to irqdesc.c - write_irq_affinity() is slightly modified to allow using the other variant of cpumask parsing functions - the definition of no_irq_affinity is moved from proc.c to manage.c and available only when CONFIG_SMP is enabled - the declaration of no_irq_affinity is available only when CONFIG_SMP is enabled Note that all existing use cases of no_irq_affinity were already confined within CONFIG_SMP preprocessor conditionals. Signed-off-by: Radu Rendec --- include/linux/irq.h | 2 ++ kernel/irq/internals.h | 2 ++ kernel/irq/irqdesc.c | 67 +++++++++++++++++++++++++++++++++++++++ kernel/irq/manage.c | 2 ++ kernel/irq/proc.c | 72 +++--------------------------------------- 5 files changed, 78 insertions(+), 67 deletions(-) diff --git a/include/linux/irq.h b/include/linux/irq.h index 7710f157e12de..0393fc02cfd46 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -639,7 +639,9 @@ static inline void irq_move_masked_irq(struct irq_data = *data) { } static inline void irq_force_complete_move(struct irq_desc *desc) { } #endif =20 +#ifdef CONFIG_SMP extern int no_irq_affinity; +#endif =20 int irq_set_parent(int irq, int parent_irq); =20 diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index c75cd836155c9..381a0b4c1d381 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -147,6 +147,8 @@ extern int irq_do_set_affinity(struct irq_data *data, =20 #ifdef CONFIG_SMP extern int irq_setup_affinity(struct irq_desc *desc); +extern ssize_t write_irq_affinity(unsigned int irq, const char __user *buf= fer, + size_t count, bool is_list, bool is_user); #else static inline int irq_setup_affinity(struct irq_desc *desc) { return 0; } #endif diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index ec52b8b41002e..a46a76c29b8d1 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -133,6 +133,73 @@ EXPORT_SYMBOL_GPL(nr_irqs); static DEFINE_MUTEX(sparse_irq_lock); static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS); =20 +#ifdef CONFIG_SMP + +#ifndef CONFIG_AUTO_IRQ_AFFINITY +static inline int irq_select_affinity_usr(unsigned int irq) +{ + /* + * If the interrupt is started up already then this fails. The + * interrupt is assigned to an online CPU already. There is no + * point to move it around randomly. Tell user space that the + * selected mask is bogus. + * + * If not then any change to the affinity is pointless because the + * startup code invokes irq_setup_affinity() which will select + * a online CPU anyway. + */ + return -EINVAL; +} +#else +/* ALPHA magic affinity auto selector. Keep it for historical reasons. */ +static inline int irq_select_affinity_usr(unsigned int irq) +{ + return irq_select_affinity(irq); +} +#endif + +ssize_t write_irq_affinity(unsigned int irq, const char __user *buffer, + size_t count, bool is_list, bool is_user) +{ + cpumask_var_t mask; + int err; + + if (!irq_can_set_affinity_usr(irq) || no_irq_affinity) + return -EIO; + + if (!zalloc_cpumask_var(&mask, GFP_KERNEL)) + return -ENOMEM; + + if (is_user) + err =3D is_list ? cpumask_parselist_user(buffer, count, mask) : + cpumask_parse_user(buffer, count, mask); + else + err =3D is_list ? cpulist_parse(buffer, mask) : + cpumask_parse(buffer, mask); + if (err) + goto free_cpumask; + + /* + * Do not allow disabling IRQs completely - it's a too easy + * way to make the system unusable accidentally :-) At least + * one online CPU still has to be targeted. + */ + if (!cpumask_intersects(mask, cpu_online_mask)) { + /* + * Special case for empty set - allow the architecture code + * to set default SMP affinity. + */ + err =3D irq_select_affinity_usr(irq) ? -EINVAL : count; + } else { + err =3D irq_set_affinity(irq, mask) ?: count; + } + +free_cpumask: + free_cpumask_var(mask); + return err; +} +#endif + #ifdef CONFIG_SPARSE_IRQ =20 static void irq_kobj_release(struct kobject *kobj); diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c index eec9b94747439..91cee7270d221 100644 --- a/kernel/irq/manage.c +++ b/kernel/irq/manage.c @@ -143,6 +143,8 @@ EXPORT_SYMBOL(synchronize_irq); #ifdef CONFIG_SMP cpumask_var_t irq_default_affinity; =20 +int no_irq_affinity; + static bool __irq_can_set_affinity(struct irq_desc *desc) { if (!desc || !irqd_can_balance(&desc->irq_data) || diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 623b8136e9af3..76f0dda1f26b8 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c @@ -100,7 +100,6 @@ static int irq_affinity_hint_proc_show(struct seq_file = *m, void *v) return 0; } =20 -int no_irq_affinity; static int irq_affinity_proc_show(struct seq_file *m, void *v) { return show_irq_affinity(AFFINITY, m); @@ -111,81 +110,20 @@ static int irq_affinity_list_proc_show(struct seq_fil= e *m, void *v) return show_irq_affinity(AFFINITY_LIST, m); } =20 -#ifndef CONFIG_AUTO_IRQ_AFFINITY -static inline int irq_select_affinity_usr(unsigned int irq) -{ - /* - * If the interrupt is started up already then this fails. The - * interrupt is assigned to an online CPU already. There is no - * point to move it around randomly. Tell user space that the - * selected mask is bogus. - * - * If not then any change to the affinity is pointless because the - * startup code invokes irq_setup_affinity() which will select - * a online CPU anyway. - */ - return -EINVAL; -} -#else -/* ALPHA magic affinity auto selector. Keep it for historical reasons. */ -static inline int irq_select_affinity_usr(unsigned int irq) -{ - return irq_select_affinity(irq); -} -#endif - -static ssize_t write_irq_affinity(int type, struct file *file, +static ssize_t irq_affinity_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos) { unsigned int irq =3D (int)(long)pde_data(file_inode(file)); - cpumask_var_t new_value; - int err; - - if (!irq_can_set_affinity_usr(irq) || no_irq_affinity) - return -EIO; - - if (!zalloc_cpumask_var(&new_value, GFP_KERNEL)) - return -ENOMEM; - - if (type) - err =3D cpumask_parselist_user(buffer, count, new_value); - else - err =3D cpumask_parse_user(buffer, count, new_value); - if (err) - goto free_cpumask; =20 - /* - * Do not allow disabling IRQs completely - it's a too easy - * way to make the system unusable accidentally :-) At least - * one online CPU still has to be targeted. - */ - if (!cpumask_intersects(new_value, cpu_online_mask)) { - /* - * Special case for empty set - allow the architecture code - * to set default SMP affinity. - */ - err =3D irq_select_affinity_usr(irq) ? -EINVAL : count; - } else { - err =3D irq_set_affinity(irq, new_value); - if (!err) - err =3D count; - } - -free_cpumask: - free_cpumask_var(new_value); - return err; -} - -static ssize_t irq_affinity_proc_write(struct file *file, - const char __user *buffer, size_t count, loff_t *pos) -{ - return write_irq_affinity(0, file, buffer, count, pos); + return write_irq_affinity(irq, buffer, count, false, true); } =20 static ssize_t irq_affinity_list_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *pos) { - return write_irq_affinity(1, file, buffer, count, pos); + unsigned int irq =3D (int)(long)pde_data(file_inode(file)); + + return write_irq_affinity(irq, buffer, count, true, true); } =20 static int irq_affinity_proc_open(struct inode *inode, struct file *file) --=20 2.40.1 From nobody Sun Feb 8 17:36:46 2026 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 75D22C7EE23 for ; Tue, 30 May 2023 21:47:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233615AbjE3Vr6 (ORCPT ); Tue, 30 May 2023 17:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233605AbjE3Vrr (ORCPT ); Tue, 30 May 2023 17:47:47 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CE1DE5 for ; Tue, 30 May 2023 14:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685483220; 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=Mzt6sKEeGzbAhjgpcG+38PHhkqIkbsGljCwJXP3Xp9M=; b=V5JJHPYTJis3IcKAzRh5Mu1Yul7fL2MMXCXTUTs0FgohOyPKu/OAfOojCUkH8uc1Ugr6MY hsCaSnoEAMdz8h+qd0+KuTiSvTMrkvdt2Ws6xKs7FLWUINh6xnk70NimXn55Co9I/rsHZM pPXxsDI5yUOLspcYXEbAyhaHoRHbqwA= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-134-Vw-0BepCOKGPYqD7M1bJPg-1; Tue, 30 May 2023 17:46:59 -0400 X-MC-Unique: Vw-0BepCOKGPYqD7M1bJPg-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-62628df5347so17341036d6.2 for ; Tue, 30 May 2023 14:46:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483218; x=1688075218; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Mzt6sKEeGzbAhjgpcG+38PHhkqIkbsGljCwJXP3Xp9M=; b=fI/aBKVg9GapZzYPqilb8k5Nm/V6+pyEbzR0OwcWkrXZCiyKCXNOfSlGtUKaluHLB8 STCPB+zaZuOM6dn51nUqD1fMr+GUcHaKePoWmNlcSU46lkXF/0f71m1jTtfnQy8Gazz6 tQM81KROkLld0SDaOms1rahVYpKVRtkD+5ipgppq1GmjkT4jKT4J6oVQBdv5ybbc/FaB mtZwcTjikxsef/83ny+KxUg22zXT1YeM4HfX8fk48zzSRTZiyNyfdjbIkQh/wVJ7Z5NG KAfB1CMNrD5sFH/ZXShDM6053v0S410Zgv/rLsutqqdjd0nrRCv0MtV5PW+TmEHUUrsc qIDQ== X-Gm-Message-State: AC+VfDxe6eHa4/SQmwAMkEFUMAOuZj2AJ5596BZSUtTJyufCu1smsT2X gIJ80LEX4zBb+/ewm94VZPUw2HpUbxZOIjC2pTPtGz9bJCIMcFr/giKpK3FL7yjVAGiNYXX04dE uL1fzP2fQBG2np6I+oY7eA/7tyRKcbp2+Nyjc9KomHhBmZK1ODEFtexBnywhXodNiaSVKQh6WZU H/LAU+eKg= X-Received: by 2002:ac8:5a86:0:b0:3f6:c5c7:fc4e with SMTP id c6-20020ac85a86000000b003f6c5c7fc4emr3188024qtc.28.1685483218357; Tue, 30 May 2023 14:46:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zCQBYTcNi3MNR4maQxvAuFFkrUSI9JhR5Cr2+0YfjZ9mnql4AGPNwdm54QH3B3he3a40f9w== X-Received: by 2002:ac8:5a86:0:b0:3f6:c5c7:fc4e with SMTP id c6-20020ac85a86000000b003f6c5c7fc4emr3188009qtc.28.1685483218068; Tue, 30 May 2023 14:46:58 -0700 (PDT) Received: from thinkpad-p1.kanata.rendec.net (cpe00fc8d79db03-cm00fc8d79db00.cpe.net.fido.ca. [72.137.118.218]) by smtp.gmail.com with ESMTPSA id w16-20020a05622a191000b003ef13aa5b0bsm5121602qtc.82.2023.05.30.14.46.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 May 2023 14:46:57 -0700 (PDT) From: Radu Rendec To: linux-kernel@vger.kernel.org Cc: Marc Zyngier , Thomas Gleixner Subject: [RFC PATCH 5/5] irq: Add smp_affinity/list attributes to sysfs Date: Tue, 30 May 2023 17:45:50 -0400 Message-Id: <20230530214550.864894-6-rrendec@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230530214550.864894-1-rrendec@redhat.com> References: <20230530214550.864894-1-rrendec@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This patch adds the smp_affinity and smp_affinity_list attributes to the sysfs interrupt interface. The implementation is identical to procfs, and the attributes are visible only when CONFIG_SMP is enabled. The intention is to allow SMP affinity to be controlled for chained interrupt parents, which are typically not visible in procfs because they are not requested through request_irq(). Signed-off-by: Radu Rendec --- kernel/irq/irqdesc.c | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index a46a76c29b8d1..5b014df9fd730 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -210,6 +210,9 @@ static struct kobject *irq_kobj_base; #define IRQ_ATTR_RO(_name) \ static struct kobj_attribute _name##_attr =3D __ATTR_RO(_name) =20 +#define IRQ_ATTR_RW(_name) \ +static struct kobj_attribute _name##_attr =3D __ATTR_RW(_name) + static ssize_t per_cpu_count_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -332,6 +335,54 @@ static ssize_t actions_show(struct kobject *kobj, } IRQ_ATTR_RO(actions); =20 +#ifdef CONFIG_SMP +static ssize_t smp_affinity_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct irq_desc *desc =3D container_of(kobj, struct irq_desc, kobj); + const struct cpumask *mask =3D desc->irq_common_data.affinity; + +#ifdef CONFIG_GENERIC_PENDING_IRQ + if (irqd_is_setaffinity_pending(&desc->irq_data)) + mask =3D desc->pending_mask; +#endif + + return scnprintf(buf, PAGE_SIZE, "%*pb\n", cpumask_pr_args(mask)); +} +static ssize_t smp_affinity_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct irq_desc *desc =3D container_of(kobj, struct irq_desc, kobj); + + return write_irq_affinity(desc->irq_data.irq, buf, count, false, false); +} +IRQ_ATTR_RW(smp_affinity); + +static ssize_t smp_affinity_list_show(struct kobject *kobj, + struct kobj_attribute *attr, char *buf) +{ + struct irq_desc *desc =3D container_of(kobj, struct irq_desc, kobj); + const struct cpumask *mask =3D desc->irq_common_data.affinity; + +#ifdef CONFIG_GENERIC_PENDING_IRQ + if (irqd_is_setaffinity_pending(&desc->irq_data)) + mask =3D desc->pending_mask; +#endif + + return scnprintf(buf, PAGE_SIZE, "%*pbl\n", cpumask_pr_args(mask)); +} +static ssize_t smp_affinity_list_store(struct kobject *kobj, + struct kobj_attribute *attr, + const char *buf, size_t count) +{ + struct irq_desc *desc =3D container_of(kobj, struct irq_desc, kobj); + + return write_irq_affinity(desc->irq_data.irq, buf, count, true, false); +} +IRQ_ATTR_RW(smp_affinity_list); +#endif + static struct attribute *irq_attrs[] =3D { &per_cpu_count_attr.attr, &chip_name_attr.attr, @@ -340,6 +391,10 @@ static struct attribute *irq_attrs[] =3D { &wakeup_attr.attr, &name_attr.attr, &actions_attr.attr, +#ifdef CONFIG_SMP + &smp_affinity_attr.attr, + &smp_affinity_list_attr.attr, +#endif NULL }; ATTRIBUTE_GROUPS(irq); --=20 2.40.1