From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 F2ACF1A8F68 for ; Mon, 17 Feb 2025 08:57:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782679; cv=none; b=ixTmSEnYM29e2u0BBA/Uh4ni6VdR3+d9TSYO60TcjwQ+jduJQ3lWqeo/COXfAbSv5iy4TFFAcdTmXydRrgBqwrLU0k9VwtqPYetVVp2U+knoPrLZ1mnY+OfpeMV09MQRzDknyQRGzG/zYm90pp3FD2pwTO4c6W7msn2fQ40+2f8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782679; c=relaxed/simple; bh=cA1sVz4q2Oqx8B9mzL6c4pNCSDxS/s6iPI+hzJGQ4U0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Tz7ndASa9Qkwe4/ZwIg15FNXYKevRTxD9ku8UokozwMBaaRxKCOgChIaHfjudC0FidzSt8LQDhkCseLDUR2H+YF/dbVqH1x46LjnwPJ0EnlRmsnu5nqoF4Ss3eLsAdEKcRXWmJyB7ocHf0IwP/9sNSu1UK/GfD3+HXVvca5TvE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=Vyk1P1Qk; arc=none smtp.client-ip=209.85.216.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Vyk1P1Qk" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2fc3fa00323so3830761a91.3 for ; Mon, 17 Feb 2025 00:57:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782677; x=1740387477; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Atdfv1u3QJvV1o68tlPZkH3S4E5LyywsJGNj7mblCio=; b=Vyk1P1Qk3rBdIkLYMxD8cJpLt2oGNXCIzVcx2XD/PqfC+5knrWvTjjtrxZxP8khf+5 CAEKL3sbubez34V3BU4M84/SQekVOXn2HPGETC08Bd4OsWXnmoxEb20IMoBefFjPmXmg gS48kT7cxJlRP6INSsownW/E19tat0RvzEE82WrCytQgjvIufzqTpKHdCxVRtGlrvADf kx+qWE+WqRg5RqXNPo7sWv0aUkKBk43/JAab+/pF/TvXR54COWUNpQBQVXRJ6CL2z5m3 kbCVmgtL+qX5OZvZQGckcbiV7V63zZBpNf6lwaWY5iUAeHejxy2K1qshc6hv0hrVCY8p MniA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782677; x=1740387477; 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=Atdfv1u3QJvV1o68tlPZkH3S4E5LyywsJGNj7mblCio=; b=eVoN1/4jqWzgP5iIzErvrK44e3OqkycjBrfWjctb8e6Jbt+ojLl7w4LHnoeIPmYMmq KsDO5DiitHqkYqH01oEXFRCfuggcKb0JxnCnAFf7Rh5Vku7prNY95aMC5km0wtCkEhly Jxv9tkXhBqIMSjvIhUkRPTkBjJ0fX5DDdB8cqnaw+N4mcSqwSIeLVcEtRLo2z8o+fraZ jiRr9HPoXCK9M1DSGkbNBf5omJAsgtGPI6zus5UmS5L8G3G5K7N/xsHvz7kiAi7BoQms Hx42orwUPByEqfFhxxM9eh1DZeR4I1Gdyxc+XX+j3UeEEB5Z1ZCA8zAXTnEM8UUdOS5v NvDw== X-Forwarded-Encrypted: i=1; AJvYcCXyDUIXWDEBgLQJCsjJZRjLJ4TDUMKMWM3M/E43r/MbRisu8jHTv5dd7F/5WmB4dFK5intsRqrZKNwkApk=@vger.kernel.org X-Gm-Message-State: AOJu0YzYeb3QEIxnsYAeMSikuChYlh0ltNE0UlqLMZD0Yoo0Wj/jn9CR VaZs0XRXodNDqlDgZrpiSpHgY7IZQhXKjyQDUL+oMeI0LrIxMrXkWvnVGEqi6CM= X-Gm-Gg: ASbGncuN7e1YQhdSsf75Kh32m8+U15/0jXesIOvN0NM/Ad+v/4atHG940rXsW/Mc/AC aMzPuCS7lG4TxYj+jBL1hJPwLILugyDiHGfnWK/dR2IgglU/OjR37JWfz/Q9QLoo11HgPpj+WjR KkINPsz2lhclfEzdEWRJt/U+KdT5NhEOOX/YMHMT25TC9QoJ0yjtSG1sm4vdRZEmg1ta/me+tLn GEdAZ57A37FXSApG/GsCubjPQCw+7VHKWpBXGPBkzg95GRMhiqPI3W678Y82NHQqd75HY8rMbuk HCJ5bOMCCiZ12hR55szeoeBRf3PinALnigJKT9mEp1ngzC6QjjuuU/c= X-Google-Smtp-Source: AGHT+IFPW0gjXYzToorJlW4AuIzo5YfoCgQvbwScUi6k6HolCkujw1LAnVbhNnt/U0DkIfz+68pqpQ== X-Received: by 2002:a05:6a00:cd4:b0:725:9d70:6ace with SMTP id d2e1a72fcca58-73261798a0amr14960838b3a.6.1739782677006; Mon, 17 Feb 2025 00:57:57 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:57:56 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 01/10] irqchip/riscv-imsic: Set irq_set_affinity for IMSIC base Date: Mon, 17 Feb 2025 14:26:47 +0530 Message-ID: <20250217085657.789309-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Andrew Jones Instead of using imsic_irq_set_affinity() for leaf MSI domains, use imsic_irq_set_affinity() for the non-leaf IMSIC base domain and use irq_chip_set_affinity_parent() for leaf MSI domains. This is required for moving the IMSIC driver to the common MSI lib which uses a generic msi_domain_set_affinity() for device MSI domains. Signed-off-by: Andrew Jones Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-riscv-imsic-platform.c index c708780e8760..5d7c30ad8855 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -96,9 +96,8 @@ static int imsic_irq_set_affinity(struct irq_data *d, con= st struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; - struct irq_data *pd =3D d->parent_data; =20 - old_vec =3D irq_data_get_irq_chip_data(pd); + old_vec =3D irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) return -ENOENT; =20 @@ -116,13 +115,13 @@ static int imsic_irq_set_affinity(struct irq_data *d,= const struct cpumask *mask return -ENOSPC; =20 /* Point device to the new vector */ - imsic_msi_update_msg(d, new_vec); + imsic_msi_update_msg(irq_get_irq_data(d->irq), new_vec); =20 /* Update irq descriptors with the new vector */ - pd->chip_data =3D new_vec; + d->chip_data =3D new_vec; =20 - /* Update effective affinity of parent irq data */ - irq_data_update_effective_affinity(pd, cpumask_of(new_vec->cpu)); + /* Update effective affinity */ + irq_data_update_effective_affinity(d, cpumask_of(new_vec->cpu)); =20 /* Move state of the old vector to the new vector */ imsic_vector_move(old_vec, new_vec); @@ -135,6 +134,9 @@ static struct irq_chip imsic_irq_base_chip =3D { .name =3D "IMSIC", .irq_mask =3D imsic_irq_mask, .irq_unmask =3D imsic_irq_unmask, +#ifdef CONFIG_SMP + .irq_set_affinity =3D imsic_irq_set_affinity, +#endif .irq_retrigger =3D imsic_irq_retrigger, .irq_compose_msi_msg =3D imsic_irq_compose_msg, .flags =3D IRQCHIP_SKIP_SET_WAKE | @@ -245,7 +247,7 @@ static bool imsic_init_dev_msi_info(struct device *dev, if (WARN_ON_ONCE(domain !=3D real_parent)) return false; #ifdef CONFIG_SMP - info->chip->irq_set_affinity =3D imsic_irq_set_affinity; + info->chip->irq_set_affinity =3D irq_chip_set_affinity_parent; #endif break; default: --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pj1-f45.google.com (mail-pj1-f45.google.com [209.85.216.45]) (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 ED37A1AA1EC for ; Mon, 17 Feb 2025 08:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782687; cv=none; b=HkCKMBOewP3ecn/4zHvhXB1fTD6jfU61l7s0ArCGfGk8lws2g4jjs6sZ8DmGi6wpGPmh+wwIPMfQW6EAStvOGxkYcSaDxHToXPkedymltUY50bWPeBFlRMoBW4bLIpQrKW9c9g2UiQ9/XEgVdvStqoAzEnrQjnv5kWN2A0h0ej4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782687; c=relaxed/simple; bh=GQ6h6qnifBeRvwI5lbrzx5DePz9FG/7AwYjLLcTRLyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O5JNLA6q7Sxz8904A91IZuCGHZ7QJZbrHJbXTHeNzjsBEkAwzOx05n3J1a1dccNqbVF/uM6BHkPkGzc+wkJykKditdGP+JwiiiRtHf/kOWOYQVPy2xw2VD3eq4+QV70iT3TD55hekwhxm+4uiE20wX8KKVRY136pvC1mSP3Im8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=NMcy3sQc; arc=none smtp.client-ip=209.85.216.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="NMcy3sQc" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2fc0026eb79so7698875a91.0 for ; Mon, 17 Feb 2025 00:58:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782685; x=1740387485; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=NMcy3sQchoTg9aWZhb1TIagJ5pqsJZnGxYKBtB/NXAq2GA2TagZFCpoP3Q7Jq8sVXL gkwDlvm2IdYtLPm9qeiHuoc4G4oOVUPUeuxYLW1IBa11SyrgQftBbkSkNZAYKkO5zWkg mtPaxPUrE7UL6yoRekWRHV8XHR9ceELABBdV3YpjTbpcmoOuxSXYl/XoHjBcxOaK/a2+ eZSHpW9HFRgmJ3PmQGsr3gWawVXsrAU4WGPmDIPpAQD66P6gAjUQs0wbQWLVallES5Xe vvebxNr4KqheO6H2FAXPKThiD2j5huGXoP6jIlAVMKrSP2R2ovDFraW6hYz6S6BtsIyF UEDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782685; x=1740387485; 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=dDa5uVtGTmKoF+EGxYZ14lQBrXBy+Zgm46G016g9yok=; b=oIOshuc8INDFJcnC0r75eOxeLZUWAmAVUc8QXMsmwQd5RXSz55nDFS/iuYlczpqQw5 +F80AGgowxJAmG+Lnxa2V156ER70Ztjq7MM7zXXIJQ7kxMp+X8W6h3w664a92t7Bl34D vQ5X0pmn7bZ5knqXS8GbZmt8K9l2ByFbFj9VqS4RwlrliQSgRnviWZsyoENd8jFqsCkq wBaMT8Tgv64RYz7Qz0xp9wU0jueqpLth3R5iXM+SFxUXE8Mh3ujcv3ZpyZCKHtkeAvhW QaTTC+fvknVp2TuE77l4pBQsZO6kUQLB3w3c6OiAeTfjcD095Vj/B9SXmOg6Iu2JiC/P Ly2A== X-Forwarded-Encrypted: i=1; AJvYcCXMyNulwIedlpHvrNcSpQj4jZn0dnAqpbMK5OvhRXfQbeqFgwOjSd9L55+idFm6Zjd54cvg86g0LCvOXCM=@vger.kernel.org X-Gm-Message-State: AOJu0YzyIdV+cBLXMrIPVyUvIKq8d7LCnXcjrs6D3TlK2ahGKCa2fqm+ 7jRQuEKCmQd3Ob3wqTf0C+T3agcw5BCkI1GMDV/0ReB/m+nrdyrQNbxw8WfN2KQ= X-Gm-Gg: ASbGncvHVoRTC9HE+lzaSrfiQPkshvmvgcTbZv5kwnim56sjRpBhV0CbvbSXMEgkoRh B5xIh41V5fo2BbcLcwQZuzwZ/N023chOyiiEIu1oxg5HaLiaAgdDnrL5YB9V8f/b7Ih9A/ymPgv q3i2QPctaG3q9DlZ2SRxiG+XiRpxmAQacPYTnwC+vdWsPaujMMsDeWrnBydmgp0K1g5fKPZUex0 heiln1Swshl4m8EDO/szYcQ+dGoFZFzoretFFTwGytBy40aQiaq0jOTLKbNyK3s1tE0UDU+YoV6 Lz58uXbbgerG2Danl1WkpB38EiFJDVN8XD4mW0qKf6vhJ1VYCdxoYeU= X-Google-Smtp-Source: AGHT+IEBiHMsSRSIfUNYli1xMt3Ndd9iF3r/FiZIa8NwO+yyTNgjVUysuPXb/9spmDvKm+4fSFcrjw== X-Received: by 2002:a05:6a00:1816:b0:730:7771:39c6 with SMTP id d2e1a72fcca58-7326179e950mr13452223b3a.8.1739782685095; Mon, 17 Feb 2025 00:58:05 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.57.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:04 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 02/10] irqchip/irq-msi-lib: Optionally set default irq_eoi/irq_ack Date: Mon, 17 Feb 2025 14:26:48 +0530 Message-ID: <20250217085657.789309-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Introduce chip_flags in struct msi_parent_ops. This allows msi_lib_init_dev_msi_info() set default irq_eoi/irq_ack callbacks only when the corresponding flags are set in the chip_flags. Signed-off-by: Thomas Gleixner Signed-off-by: Anup Patel --- drivers/irqchip/irq-gic-v2m.c | 1 + drivers/irqchip/irq-imx-mu-msi.c | 1 + drivers/irqchip/irq-msi-lib.c | 11 ++++++----- drivers/irqchip/irq-mvebu-gicp.c | 1 + drivers/irqchip/irq-mvebu-odmi.c | 1 + drivers/irqchip/irq-mvebu-sei.c | 1 + include/linux/msi.h | 11 +++++++++++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/irqchip/irq-gic-v2m.c b/drivers/irqchip/irq-gic-v2m.c index be35c5349986..1e3476c335ca 100644 --- a/drivers/irqchip/irq-gic-v2m.c +++ b/drivers/irqchip/irq-gic-v2m.c @@ -255,6 +255,7 @@ static void __init gicv2m_teardown(void) static struct msi_parent_ops gicv2m_msi_parent_ops =3D { .supported_flags =3D GICV2M_MSI_FLAGS_SUPPORTED, .required_flags =3D GICV2M_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, .prefix =3D "GICv2m-", diff --git a/drivers/irqchip/irq-imx-mu-msi.c b/drivers/irqchip/irq-imx-mu-= msi.c index 4342a21de1eb..69aacdfc8bef 100644 --- a/drivers/irqchip/irq-imx-mu-msi.c +++ b/drivers/irqchip/irq-imx-mu-msi.c @@ -214,6 +214,7 @@ static void imx_mu_msi_irq_handler(struct irq_desc *des= c) static const struct msi_parent_ops imx_mu_msi_parent_ops =3D { .supported_flags =3D IMX_MU_MSI_FLAGS_SUPPORTED, .required_flags =3D IMX_MU_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "MU-MSI-", diff --git a/drivers/irqchip/irq-msi-lib.c b/drivers/irqchip/irq-msi-lib.c index d8e29fc0d406..51464c6257f3 100644 --- a/drivers/irqchip/irq-msi-lib.c +++ b/drivers/irqchip/irq-msi-lib.c @@ -28,6 +28,7 @@ bool msi_lib_init_dev_msi_info(struct device *dev, struct= irq_domain *domain, struct msi_domain_info *info) { const struct msi_parent_ops *pops =3D real_parent->msi_parent_ops; + struct irq_chip *chip =3D info->chip; u32 required_flags; =20 /* Parent ops available? */ @@ -92,10 +93,10 @@ bool msi_lib_init_dev_msi_info(struct device *dev, stru= ct irq_domain *domain, info->flags |=3D required_flags; =20 /* Chip updates for all child bus types */ - if (!info->chip->irq_eoi) - info->chip->irq_eoi =3D irq_chip_eoi_parent; - if (!info->chip->irq_ack) - info->chip->irq_ack =3D irq_chip_ack_parent; + if (!chip->irq_eoi && (pops->chip_flags & MSI_CHIP_FLAG_SET_EOI)) + chip->irq_eoi =3D irq_chip_eoi_parent; + if (!chip->irq_ack && (pops->chip_flags & MSI_CHIP_FLAG_SET_ACK)) + chip->irq_ack =3D irq_chip_ack_parent; =20 /* * The device MSI domain can never have a set affinity callback. It @@ -105,7 +106,7 @@ bool msi_lib_init_dev_msi_info(struct device *dev, stru= ct irq_domain *domain, * device MSI domain aside of mask/unmask which is provided e.g. by * PCI/MSI device domains. */ - info->chip->irq_set_affinity =3D msi_domain_set_affinity; + chip->irq_set_affinity =3D msi_domain_set_affinity; return true; } EXPORT_SYMBOL_GPL(msi_lib_init_dev_msi_info); diff --git a/drivers/irqchip/irq-mvebu-gicp.c b/drivers/irqchip/irq-mvebu-g= icp.c index 2b6183919ea4..d67f93f6d750 100644 --- a/drivers/irqchip/irq-mvebu-gicp.c +++ b/drivers/irqchip/irq-mvebu-gicp.c @@ -161,6 +161,7 @@ static const struct irq_domain_ops gicp_domain_ops =3D { static const struct msi_parent_ops gicp_msi_parent_ops =3D { .supported_flags =3D GICP_MSI_FLAGS_SUPPORTED, .required_flags =3D GICP_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "GICP-", diff --git a/drivers/irqchip/irq-mvebu-odmi.c b/drivers/irqchip/irq-mvebu-o= dmi.c index ff19bfd258dc..28f7e81df94f 100644 --- a/drivers/irqchip/irq-mvebu-odmi.c +++ b/drivers/irqchip/irq-mvebu-odmi.c @@ -157,6 +157,7 @@ static const struct irq_domain_ops odmi_domain_ops =3D { static const struct msi_parent_ops odmi_msi_parent_ops =3D { .supported_flags =3D ODMI_MSI_FLAGS_SUPPORTED, .required_flags =3D ODMI_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .bus_select_mask =3D MATCH_PLATFORM_MSI, .prefix =3D "ODMI-", diff --git a/drivers/irqchip/irq-mvebu-sei.c b/drivers/irqchip/irq-mvebu-se= i.c index 065166ab5dbc..ebd4a9014e8d 100644 --- a/drivers/irqchip/irq-mvebu-sei.c +++ b/drivers/irqchip/irq-mvebu-sei.c @@ -356,6 +356,7 @@ static void mvebu_sei_reset(struct mvebu_sei *sei) static const struct msi_parent_ops sei_msi_parent_ops =3D { .supported_flags =3D SEI_MSI_FLAGS_SUPPORTED, .required_flags =3D SEI_MSI_FLAGS_REQUIRED, + .chip_flags =3D MSI_CHIP_FLAG_SET_EOI | MSI_CHIP_FLAG_SET_ACK, .bus_select_mask =3D MATCH_PLATFORM_MSI, .bus_select_token =3D DOMAIN_BUS_GENERIC_MSI, .prefix =3D "SEI-", diff --git a/include/linux/msi.h b/include/linux/msi.h index b10093c4d00e..9abef442c146 100644 --- a/include/linux/msi.h +++ b/include/linux/msi.h @@ -558,11 +558,21 @@ enum { MSI_FLAG_NO_AFFINITY =3D (1 << 21), }; =20 +/* + * Flags for msi_parent_ops::chip_flags + */ +enum { + MSI_CHIP_FLAG_SET_EOI =3D (1 << 0), + MSI_CHIP_FLAG_SET_ACK =3D (1 << 1), +}; + /** * struct msi_parent_ops - MSI parent domain callbacks and configuration i= nfo * * @supported_flags: Required: The supported MSI flags of the parent domain * @required_flags: Optional: The required MSI flags of the parent MSI dom= ain + * @chip_flags: Optional: Select MSI chip callbacks to update with defaul= ts + * in msi_lib_init_dev_msi_info(). * @bus_select_token: Optional: The bus token of the real parent domain for * irq_domain::select() * @bus_select_mask: Optional: A mask of supported BUS_DOMAINs for @@ -575,6 +585,7 @@ enum { struct msi_parent_ops { u32 supported_flags; u32 required_flags; + u32 chip_flags; u32 bus_select_token; u32 bus_select_mask; const char *prefix; --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 7EB431A5B99 for ; Mon, 17 Feb 2025 08:58:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782696; cv=none; b=IpeA7e7RhMMjcZThBAdtEVfcsgQNPDxT5eDCqsJ4w2bArZnPH5yZPjrweD36T64Sbp8XX76tl5I9FbsjI8c1zCnL1eRKPLxQF/O7hewwgytKCDZuXsMLQr+GLJRazKy+r5qIjtP/xtfV1iEX1XfaykCGa67AZ1euA/8WXhobMpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782696; c=relaxed/simple; bh=KPNhzopPF/v+rf0DL/xDUy/p8rwZ0ENzF3r/iosIwvI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DG4DNJ7IuEtL3HdwzcNau5Pr2ns4mW55ofTjBWuo+r/oCn2owpcSqof4oXfKGM5XSuBvfFUAwz02R+jGKDDewPQ3o+0KXtjZwW+HSbNXKaBtYRPsHLvpP9jRGuUuBc5rY6Cjd1eexbq0dxaRl0DHI97XQO80Z6eaJL488aXshE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=UggyotyX; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="UggyotyX" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-219f8263ae0so71578495ad.0 for ; Mon, 17 Feb 2025 00:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782694; x=1740387494; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Oop51W2xPzPgS///BRY5kVWjIpIgQEDQeLtCvsidU3M=; b=UggyotyXlEGki5PFRr1rVcg/5iogZAkocDAEMAmlRSfTK67Vsrl1UqDLMJkTmH5sMX yMly4Rf5jHEg1O7G36uhxz6HNYcElbdpmnDc3FYgrNks2iWTFh7MMtDoA9D5q5I9TlHx FqTFYWS5abDFOjVzatkTjKCRLDODdsXXLcCARwiX34lBUrg8kZZ3biG7qex+jLNZoada vbpFE5yzGd6LbDUvR1WFoM3+BQ5qbRSgR4QfedJ0BwAeqHQiH0nSKC+bF+Bx4tqW5rgG st/4lkdrsQ1wHuipX4bN0ZAI5M71QrxswtyjfokX+ATqlHLIIirEIiAjbO8pcVUBV+Uy Co/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782694; x=1740387494; 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=Oop51W2xPzPgS///BRY5kVWjIpIgQEDQeLtCvsidU3M=; b=B+uFc2KniH6twa4t3+qZxcAsAFWF33F4D94cFwV0AWnFAKSgWFvYEoSoXzFfH9YLFU LdlWK8V3sAr/fxcd2UNP7AUKSKF8+/qI3XxgrhE253OTRRDYEfOK9Vcwj3Pquy74EoMw vX2KxEHRJ35ZiJvg0EwST5wdxcDUkZrTS1tfIgRWk7+S0HbBcGlM6r86eDKsZcVfNj+o HaTXWAFDR56mglV4qE9iKPYWf53EgSl/JkdzcktXD9maFO5bsoHC5CTUc+qAwGPpMiV6 EiRllHQTs6Vnd5QORQMicVEmSHNUs79osB/H8MhlAxOuWigxtRy0QiSE83Qx0gnDUWxI y84g== X-Forwarded-Encrypted: i=1; AJvYcCVP5RYH8TNWfnm0HrcUCsSV88qXDcB6RDcO1SHhy5SuuETKX4NI7w/ZmZGWA9//UyKZ7gKKYwL/SbxGvqM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2aDBZaTQN6sNI/U6TiWPKqhkQPZXiyyPMDdQBl0nTsAZcWd0P Xd3GXQwfrPdx9Woqf2mthBs+hAvvn9rmpY5Tu1WbITh2dhwEdx3kkTm9/0Wq/RQ= X-Gm-Gg: ASbGncuGolzxE+cZuyn4mE1RcXSFln9oPc+FPNE25+9rG0lEn9DT3yW0za0fh9i4ciP TiqQeeXVmB49H8mJ2JFzSLp5xwuSCVBFu03B5MDQvqPXrAuSQg7B+eDt5AOMSjnrVa3TfcJRUdM Zssrsb0PP8zpoaw1w3iCRbImo21kk1VRnNqTCZ2PO/TGuV/njnzfr6om4ARes3wuOJSWb8HWLf6 nbZDDF+9yKNvuSkBqKQUGFfQ8qpZ1EUPJv1MrFj71w92qMWW4graJ0/hsmcG7bpPuYr64BUZ9W5 piqectZQ1bIx0mJcuUgz9pqX5s8sK/uAuRmH+UvjzwI7x7Hv9bqjwNE= X-Google-Smtp-Source: AGHT+IHKsFX8G1xeFdGN0LrWZ8KF20LhqcM9UDqb+rrZ1azyG6dWW4gYdjdpQdbPPAsWI3TzMShx/g== X-Received: by 2002:a05:6a21:7886:b0:1e0:ca1c:8581 with SMTP id adf61e73a8af0-1ee8cb3e424mr12892785637.21.1739782693650; Mon, 17 Feb 2025 00:58:13 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:13 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 03/10] irqchip/riscv-imsic: Move to common MSI lib Date: Mon, 17 Feb 2025 14:26:49 +0530 Message-ID: <20250217085657.789309-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner Simplify the leaf MSI domain handling in the RISC-V IMSIC driver by using msi_lib_init_dev_msi_info() and msi_lib_irq_domain_select() provided by common MSI lib. Signed-off-by: Thomas Gleixner Signed-off-by: Andrew Jones Signed-off-by: Anup Patel --- drivers/irqchip/Kconfig | 8 +- drivers/irqchip/irq-riscv-imsic-platform.c | 114 +-------------------- 2 files changed, 6 insertions(+), 116 deletions(-) diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig index c11b9965c4ad..fe95ef723bb3 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -590,13 +590,7 @@ config RISCV_IMSIC select IRQ_DOMAIN_HIERARCHY select GENERIC_IRQ_MATRIX_ALLOCATOR select GENERIC_MSI_IRQ - -config RISCV_IMSIC_PCI - bool - depends on RISCV_IMSIC - depends on PCI - depends on PCI_MSI - default RISCV_IMSIC + select IRQ_MSI_LIB =20 config SIFIVE_PLIC bool diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-riscv-imsic-platform.c index 5d7c30ad8855..9a5e7b4541f6 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -20,6 +20,7 @@ #include #include =20 +#include "irq-msi-lib.h" #include "irq-riscv-imsic-state.h" =20 static bool imsic_cpu_page_phys(unsigned int cpu, unsigned int guest_index, @@ -174,22 +175,6 @@ static void imsic_irq_domain_free(struct irq_domain *d= omain, unsigned int virq, irq_domain_free_irqs_parent(domain, virq, nr_irqs); } =20 -static int imsic_irq_domain_select(struct irq_domain *domain, struct irq_f= wspec *fwspec, - enum irq_domain_bus_token bus_token) -{ - const struct msi_parent_ops *ops =3D domain->msi_parent_ops; - u32 busmask =3D BIT(bus_token); - - if (fwspec->fwnode !=3D domain->fwnode || fwspec->param_count !=3D 0) - return 0; - - /* Handle pure domain searches */ - if (bus_token =3D=3D ops->bus_select_token) - return 1; - - return !!(ops->bus_select_mask & busmask); -} - #ifdef CONFIG_GENERIC_IRQ_DEBUGFS static void imsic_irq_debug_show(struct seq_file *m, struct irq_domain *d, struct irq_data *irqd, int ind) @@ -206,110 +191,21 @@ static void imsic_irq_debug_show(struct seq_file *m,= struct irq_domain *d, static const struct irq_domain_ops imsic_base_domain_ops =3D { .alloc =3D imsic_irq_domain_alloc, .free =3D imsic_irq_domain_free, - .select =3D imsic_irq_domain_select, + .select =3D msi_lib_irq_domain_select, #ifdef CONFIG_GENERIC_IRQ_DEBUGFS .debug_show =3D imsic_irq_debug_show, #endif }; =20 -#ifdef CONFIG_RISCV_IMSIC_PCI - -static void imsic_pci_mask_irq(struct irq_data *d) -{ - pci_msi_mask_irq(d); - irq_chip_mask_parent(d); -} - -static void imsic_pci_unmask_irq(struct irq_data *d) -{ - irq_chip_unmask_parent(d); - pci_msi_unmask_irq(d); -} - -#define MATCH_PCI_MSI BIT(DOMAIN_BUS_PCI_MSI) - -#else - -#define MATCH_PCI_MSI 0 - -#endif - -static bool imsic_init_dev_msi_info(struct device *dev, - struct irq_domain *domain, - struct irq_domain *real_parent, - struct msi_domain_info *info) -{ - const struct msi_parent_ops *pops =3D real_parent->msi_parent_ops; - - /* MSI parent domain specific settings */ - switch (real_parent->bus_token) { - case DOMAIN_BUS_NEXUS: - if (WARN_ON_ONCE(domain !=3D real_parent)) - return false; -#ifdef CONFIG_SMP - info->chip->irq_set_affinity =3D irq_chip_set_affinity_parent; -#endif - break; - default: - WARN_ON_ONCE(1); - return false; - } - - /* Is the target supported? */ - switch (info->bus_token) { -#ifdef CONFIG_RISCV_IMSIC_PCI - case DOMAIN_BUS_PCI_DEVICE_MSI: - case DOMAIN_BUS_PCI_DEVICE_MSIX: - info->chip->irq_mask =3D imsic_pci_mask_irq; - info->chip->irq_unmask =3D imsic_pci_unmask_irq; - break; -#endif - case DOMAIN_BUS_DEVICE_MSI: - /* - * Per-device MSI should never have any MSI feature bits - * set. It's sole purpose is to create a dumb interrupt - * chip which has a device specific irq_write_msi_msg() - * callback. - */ - if (WARN_ON_ONCE(info->flags)) - return false; - - /* Core managed MSI descriptors */ - info->flags |=3D MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS | - MSI_FLAG_FREE_MSI_DESCS; - break; - case DOMAIN_BUS_WIRED_TO_MSI: - break; - default: - WARN_ON_ONCE(1); - return false; - } - - /* Use hierarchial chip operations re-trigger */ - info->chip->irq_retrigger =3D irq_chip_retrigger_hierarchy; - - /* - * Mask out the domain specific MSI feature flags which are not - * supported by the real parent. - */ - info->flags &=3D pops->supported_flags; - - /* Enforce the required flags */ - info->flags |=3D pops->required_flags; - - return true; -} - -#define MATCH_PLATFORM_MSI BIT(DOMAIN_BUS_PLATFORM_MSI) - static const struct msi_parent_ops imsic_msi_parent_ops =3D { .supported_flags =3D MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags =3D MSI_FLAG_USE_DEF_DOM_OPS | - MSI_FLAG_USE_DEF_CHIP_OPS, + MSI_FLAG_USE_DEF_CHIP_OPS | + MSI_FLAG_PCI_MSI_MASK_PARENT, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info =3D imsic_init_dev_msi_info, + .init_dev_msi_info =3D msi_lib_init_dev_msi_info, }; =20 int imsic_irqdomain_init(void) --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 07B6319E7FA for ; Mon, 17 Feb 2025 08:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782704; cv=none; b=d2f6f4yZDHV4QKLlje62jLfR8005XRGmyJvDCBfaD0llelxY9CNbSOsLoJjouleAMkFstESHeAuuXqcv9UKwow705rKT4KI/kEsZSrw6hdoESh++RTuNL/C3qhk0fzt1LtrL9wQouiAg5UUZRmjFY7K1VBaewMaeTxR1DmH+Ppg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782704; c=relaxed/simple; bh=yfLmkM6qEAtePtmZAV08Oc3zFbXuNPHytenOkvHgx/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G22uRTliWYrO0i1j9jnsBG+uOXrxm5Fmi8P7RR1fn37enlmSqwC3P3BSxuhrU9k52G9b5cx2rIK+PS+NVD6ZLgJ6OZK61TloVjlYlZCtqcFUxup0zhuZzkoZgFDWVvMposPaMwmJnlfqSx/jligkQzomvhbPyRqqdgz1qK0gfuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=fv//+QtX; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="fv//+QtX" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2210d92292eso39663755ad.1 for ; Mon, 17 Feb 2025 00:58:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782702; x=1740387502; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=muAXlG/uZk+Ut1w5NICM8ivKf832EJKGEf1Ht7zOCxs=; b=fv//+QtXMvX9e4r14q4FktPSlo8mG+9ZI5qR1G2GDcSqAwiDlP15PT5sj1bqy0sACU UZ1Kr/nrRYCS5LkhigQXFRoGhgYrK02HsdZctqKKU3tLfHUHogVTQK250MCrpUeJuhYS vALAqwcqXCkbo0f9Z7Fzunmre5U711VQ6X1tjxalUg55WRojdhgUGflvBtzlaCP8JSG2 hWXQWT0fbBwTAy5owfYtjZ8wzxA5pZr0VAoP3oTJeWhnzRCHJ/OBWiFwz07TH9ZtyDvZ qk4rS6YhiAfrfrzb9YGyhGg/10k11qCm+lkfum7t943EmpDqxp5XfMIL5jKSkEfH/57x pLFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782702; x=1740387502; 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=muAXlG/uZk+Ut1w5NICM8ivKf832EJKGEf1Ht7zOCxs=; b=iBUf+tvGPtgxgauAnt3P2Q9AMl5m+onsZ8PgcQeoNnnGJS+FSxTCEJMJC6d35B+g1H x5jADdiOJLQAGCObeKrSbPal/8RIdzqOgeTiiROdfu98Sp/Cmez93dJUfJLOeCKrOXlr WF2ZC8CWxy7EknYgnO6G9S+WopSfZ4qGIG2uL62Yxs8I6D5iRRhG/0zIOOB4k2ovmDsv 9TIhDg8R+B8t1nwWnniN6i9LDRuki3UxLy5PwmKo1sMyHgjXVHEzRVHCH0iiWAStPTS/ Q14mWePzY8P+kJ4VKuKezKtkStVaeHrJ6wYr+ptwrwRLn595yjKbGK2jce22p4LJC8QZ dRQQ== X-Forwarded-Encrypted: i=1; AJvYcCUWek/EO7OhJvarRsbD7RCPmThZK5OyzM6P9BIrAzG8fdVeYmSxyTnvC2hRsJbAtvq4trNrgpnBDCIpcwc=@vger.kernel.org X-Gm-Message-State: AOJu0YxyV3a2oyOCRu5Vqn/5R8OtcNOnj7L6lq3cRTBQlAhnlPgLqUPV izrHCdzecQjuhYZydZekK+hhcRv7nXbazh4hs76ADYRvIKyNAXsB/qiX1ZCQ0V4= X-Gm-Gg: ASbGncs38cCwu3AzsSNd3qH4i/bACI8PNfd9hQeRIc+JxdbvsOBJcvHowHLwk4pshec 2nrBvhRrrRAZjuMw4SiOSDZ/xfCuZCikFazo8eVtDStokYDBOxVrFcRlMsDWY0CtNEZU8f5wQbv l0SRErAfGrErzSKafC9ys7vlSGfnI3sZubRBP0EaW6E3CeQ3mvgGLMbzZSMweCpKqaT++dKbbOZ JtiIcVekjgr2gagZNaeZ+WjVY7l06F42BoEL3538fZpeRZ4xnpYUM3KKOdRoA8eX8UQGlIgaXzC Idz/gwWTHH/zy2PMscwL8EFG23yOdD0RQ9lkxYIvzUxFSzNSBY33DaU= X-Google-Smtp-Source: AGHT+IGeeSKqQaB04W0hYbcp5SOMBU/2KVamXBnyldtu8MmORMjRPb5xrOZF3XnR9hLS8Nh0YSNDYA== X-Received: by 2002:a05:6a21:1693:b0:1ee:8099:e657 with SMTP id adf61e73a8af0-1ee8cbe7bb4mr16765666637.40.1739782702160; Mon, 17 Feb 2025 00:58:22 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:21 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 04/10] genirq: Introduce common irq_force_complete_move() implementation Date: Mon, 17 Feb 2025 14:26:50 +0530 Message-ID: <20250217085657.789309-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Thomas Gleixner The GENERIC_PENDING_IRQ requires an arch specific implementation of irq_force_complete_move(). At the moment, only x86 implements this but for RISC-V the irq_force_complete_move() is only needed when RISC-V IMSIC driver is in use and not needed otherwise. To address the above, introduce a common irq_force_complete_move() implementation in kernel irq migration which lets irqchip do the actual irq_force_complete_move() and also update x86 APIC to use this common implementation. Signed-off-by: Thomas Gleixner Signed-off-by: Anup Patel --- arch/x86/kernel/apic/vector.c | 231 ++++++++++++++++------------------ include/linux/irq.h | 5 +- kernel/irq/internals.h | 2 + kernel/irq/migration.c | 10 ++ 4 files changed, 123 insertions(+), 125 deletions(-) diff --git a/arch/x86/kernel/apic/vector.c b/arch/x86/kernel/apic/vector.c index 736f62812f5c..72fa4bb78f0a 100644 --- a/arch/x86/kernel/apic/vector.c +++ b/arch/x86/kernel/apic/vector.c @@ -888,8 +888,109 @@ static int apic_set_affinity(struct irq_data *irqd, return err ? err : IRQ_SET_MASK_OK; } =20 +static void free_moved_vector(struct apic_chip_data *apicd) +{ + unsigned int vector =3D apicd->prev_vector; + unsigned int cpu =3D apicd->prev_cpu; + bool managed =3D apicd->is_managed; + + /* + * Managed interrupts are usually not migrated away + * from an online CPU, but CPU isolation 'managed_irq' + * can make that happen. + * 1) Activation does not take the isolation into account + * to keep the code simple + * 2) Migration away from an isolated CPU can happen when + * a non-isolated CPU which is in the calculated + * affinity mask comes online. + */ + trace_vector_free_moved(apicd->irq, cpu, vector, managed); + irq_matrix_free(vector_matrix, cpu, vector, managed); + per_cpu(vector_irq, cpu)[vector] =3D VECTOR_UNUSED; + hlist_del_init(&apicd->clist); + apicd->prev_vector =3D 0; + apicd->move_in_progress =3D 0; +} + +/* + * Called from fixup_irqs() with @desc->lock held and interrupts disabled. + */ +static void apic_force_complete_move(struct irq_data *irqd) +{ + unsigned int cpu =3D smp_processor_id(); + struct apic_chip_data *apicd; + unsigned int vector; + + guard(raw_spinlock)(&vector_lock); + apicd =3D apic_chip_data(irqd); + if (!apicd) + return; + + /* + * If prev_vector is empty or the descriptor is neither currently + * nor previously on the outgoing CPU no action required. + */ + vector =3D apicd->prev_vector; + if (!vector || (apicd->cpu !=3D cpu && apicd->prev_cpu !=3D cpu)) + return; + + /* + * This is tricky. If the cleanup of the old vector has not been + * done yet, then the following setaffinity call will fail with + * -EBUSY. This can leave the interrupt in a stale state. + * + * All CPUs are stuck in stop machine with interrupts disabled so + * calling __irq_complete_move() would be completely pointless. + * + * 1) The interrupt is in move_in_progress state. That means that we + * have not seen an interrupt since the io_apic was reprogrammed to + * the new vector. + * + * 2) The interrupt has fired on the new vector, but the cleanup IPIs + * have not been processed yet. + */ + if (apicd->move_in_progress) { + /* + * In theory there is a race: + * + * set_ioapic(new_vector) <-- Interrupt is raised before update + * is effective, i.e. it's raised on + * the old vector. + * + * So if the target cpu cannot handle that interrupt before + * the old vector is cleaned up, we get a spurious interrupt + * and in the worst case the ioapic irq line becomes stale. + * + * But in case of cpu hotplug this should be a non issue + * because if the affinity update happens right before all + * cpus rendezvous in stop machine, there is no way that the + * interrupt can be blocked on the target cpu because all cpus + * loops first with interrupts enabled in stop machine, so the + * old vector is not yet cleaned up when the interrupt fires. + * + * So the only way to run into this issue is if the delivery + * of the interrupt on the apic/system bus would be delayed + * beyond the point where the target cpu disables interrupts + * in stop machine. I doubt that it can happen, but at least + * there is a theoretical chance. Virtualization might be + * able to expose this, but AFAICT the IOAPIC emulation is not + * as stupid as the real hardware. + * + * Anyway, there is nothing we can do about that at this point + * w/o refactoring the whole fixup_irq() business completely. + * We print at least the irq number and the old vector number, + * so we have the necessary information when a problem in that + * area arises. + */ + pr_warn("IRQ fixup: irq %d move in progress, old vector %d\n", + irqd->irq, vector); + } + free_moved_vector(apicd); +} + #else -# define apic_set_affinity NULL +# define apic_set_affinity NULL +# define apic_force_complete_move NULL #endif =20 static int apic_retrigger_irq(struct irq_data *irqd) @@ -923,39 +1024,16 @@ static void x86_vector_msi_compose_msg(struct irq_da= ta *data, } =20 static struct irq_chip lapic_controller =3D { - .name =3D "APIC", - .irq_ack =3D apic_ack_edge, - .irq_set_affinity =3D apic_set_affinity, - .irq_compose_msi_msg =3D x86_vector_msi_compose_msg, - .irq_retrigger =3D apic_retrigger_irq, + .name =3D "APIC", + .irq_ack =3D apic_ack_edge, + .irq_set_affinity =3D apic_set_affinity, + .irq_compose_msi_msg =3D x86_vector_msi_compose_msg, + .irq_force_complete_move =3D apic_force_complete_move, + .irq_retrigger =3D apic_retrigger_irq, }; =20 #ifdef CONFIG_SMP =20 -static void free_moved_vector(struct apic_chip_data *apicd) -{ - unsigned int vector =3D apicd->prev_vector; - unsigned int cpu =3D apicd->prev_cpu; - bool managed =3D apicd->is_managed; - - /* - * Managed interrupts are usually not migrated away - * from an online CPU, but CPU isolation 'managed_irq' - * can make that happen. - * 1) Activation does not take the isolation into account - * to keep the code simple - * 2) Migration away from an isolated CPU can happen when - * a non-isolated CPU which is in the calculated - * affinity mask comes online. - */ - trace_vector_free_moved(apicd->irq, cpu, vector, managed); - irq_matrix_free(vector_matrix, cpu, vector, managed); - per_cpu(vector_irq, cpu)[vector] =3D VECTOR_UNUSED; - hlist_del_init(&apicd->clist); - apicd->prev_vector =3D 0; - apicd->move_in_progress =3D 0; -} - static void __vector_cleanup(struct vector_cleanup *cl, bool check_irr) { struct apic_chip_data *apicd; @@ -1068,99 +1146,6 @@ void irq_complete_move(struct irq_cfg *cfg) __vector_schedule_cleanup(apicd); } =20 -/* - * Called from fixup_irqs() with @desc->lock held and interrupts disabled. - */ -void irq_force_complete_move(struct irq_desc *desc) -{ - unsigned int cpu =3D smp_processor_id(); - struct apic_chip_data *apicd; - struct irq_data *irqd; - unsigned int vector; - - /* - * The function is called for all descriptors regardless of which - * irqdomain they belong to. For example if an IRQ is provided by - * an irq_chip as part of a GPIO driver, the chip data for that - * descriptor is specific to the irq_chip in question. - * - * Check first that the chip_data is what we expect - * (apic_chip_data) before touching it any further. - */ - irqd =3D irq_domain_get_irq_data(x86_vector_domain, - irq_desc_get_irq(desc)); - if (!irqd) - return; - - raw_spin_lock(&vector_lock); - apicd =3D apic_chip_data(irqd); - if (!apicd) - goto unlock; - - /* - * If prev_vector is empty or the descriptor is neither currently - * nor previously on the outgoing CPU no action required. - */ - vector =3D apicd->prev_vector; - if (!vector || (apicd->cpu !=3D cpu && apicd->prev_cpu !=3D cpu)) - goto unlock; - - /* - * This is tricky. If the cleanup of the old vector has not been - * done yet, then the following setaffinity call will fail with - * -EBUSY. This can leave the interrupt in a stale state. - * - * All CPUs are stuck in stop machine with interrupts disabled so - * calling __irq_complete_move() would be completely pointless. - * - * 1) The interrupt is in move_in_progress state. That means that we - * have not seen an interrupt since the io_apic was reprogrammed to - * the new vector. - * - * 2) The interrupt has fired on the new vector, but the cleanup IPIs - * have not been processed yet. - */ - if (apicd->move_in_progress) { - /* - * In theory there is a race: - * - * set_ioapic(new_vector) <-- Interrupt is raised before update - * is effective, i.e. it's raised on - * the old vector. - * - * So if the target cpu cannot handle that interrupt before - * the old vector is cleaned up, we get a spurious interrupt - * and in the worst case the ioapic irq line becomes stale. - * - * But in case of cpu hotplug this should be a non issue - * because if the affinity update happens right before all - * cpus rendezvous in stop machine, there is no way that the - * interrupt can be blocked on the target cpu because all cpus - * loops first with interrupts enabled in stop machine, so the - * old vector is not yet cleaned up when the interrupt fires. - * - * So the only way to run into this issue is if the delivery - * of the interrupt on the apic/system bus would be delayed - * beyond the point where the target cpu disables interrupts - * in stop machine. I doubt that it can happen, but at least - * there is a theoretical chance. Virtualization might be - * able to expose this, but AFAICT the IOAPIC emulation is not - * as stupid as the real hardware. - * - * Anyway, there is nothing we can do about that at this point - * w/o refactoring the whole fixup_irq() business completely. - * We print at least the irq number and the old vector number, - * so we have the necessary information when a problem in that - * area arises. - */ - pr_warn("IRQ fixup: irq %d move in progress, old vector %d\n", - irqd->irq, vector); - } - free_moved_vector(apicd); -unlock: - raw_spin_unlock(&vector_lock); -} - #ifdef CONFIG_HOTPLUG_CPU /* * Note, this is not accurate accounting, but at least good enough to diff --git a/include/linux/irq.h b/include/linux/irq.h index 8daa17f0107a..56f6583093d2 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -486,6 +486,7 @@ static inline irq_hw_number_t irqd_to_hwirq(struct irq_= data *d) * @ipi_send_mask: send an IPI to destination cpus in cpumask * @irq_nmi_setup: function called from core code before enabling an NMI * @irq_nmi_teardown: function called from core code after disabling an NMI + * @irq_force_complete_move: optional function to force complete pending i= rq move * @flags: chip specific flags */ struct irq_chip { @@ -537,6 +538,8 @@ struct irq_chip { int (*irq_nmi_setup)(struct irq_data *data); void (*irq_nmi_teardown)(struct irq_data *data); =20 + void (*irq_force_complete_move)(struct irq_data *data); + unsigned long flags; }; =20 @@ -619,11 +622,9 @@ static inline void irq_move_irq(struct irq_data *data) __irq_move_irq(data); } void irq_move_masked_irq(struct irq_data *data); -void irq_force_complete_move(struct irq_desc *desc); #else static inline void irq_move_irq(struct irq_data *data) { } static inline void irq_move_masked_irq(struct irq_data *data) { } -static inline void irq_force_complete_move(struct irq_desc *desc) { } #endif =20 extern int no_irq_affinity; diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h index a979523640d0..d4e190e690bd 100644 --- a/kernel/irq/internals.h +++ b/kernel/irq/internals.h @@ -442,6 +442,7 @@ static inline struct cpumask *irq_desc_get_pending_mask= (struct irq_desc *desc) return desc->pending_mask; } bool irq_fixup_move_pending(struct irq_desc *desc, bool force_clear); +void irq_force_complete_move(struct irq_desc *desc); #else /* CONFIG_GENERIC_PENDING_IRQ */ static inline bool irq_can_move_pcntxt(struct irq_data *data) { @@ -467,6 +468,7 @@ static inline bool irq_fixup_move_pending(struct irq_de= sc *desc, bool fclear) { return false; } +static inline void irq_force_complete_move(struct irq_desc *desc) { } #endif /* !CONFIG_GENERIC_PENDING_IRQ */ =20 #if !defined(CONFIG_IRQ_DOMAIN) || !defined(CONFIG_IRQ_DOMAIN_HIERARCHY) diff --git a/kernel/irq/migration.c b/kernel/irq/migration.c index eb150afd671f..e110300ad650 100644 --- a/kernel/irq/migration.c +++ b/kernel/irq/migration.c @@ -35,6 +35,16 @@ bool irq_fixup_move_pending(struct irq_desc *desc, bool = force_clear) return true; } =20 +void irq_force_complete_move(struct irq_desc *desc) +{ + for (struct irq_data *d =3D irq_desc_get_irq_data(desc); d; d =3D d->pare= nt_data) { + if (d->chip && d->chip->irq_force_complete_move) { + d->chip->irq_force_complete_move(d); + return; + } + } +} + void irq_move_masked_irq(struct irq_data *idata) { struct irq_desc *desc =3D irq_data_to_desc(idata); --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (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 DDFB519E7FA for ; Mon, 17 Feb 2025 08:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782712; cv=none; b=L+JWie+MqubKLt9h0hv5MNwJoaDsgSuh5ZvqQXeWCPK52W9cKV7HzyQS/9AsVHnLkPDZy2KC8frXO1C2f+vYL1gXtJOcviLpUYFfRIBmGXKHTcVZ/gDfkezFhhzlLCpLfHMO1xh+MBcsZIWFfNk5Vi8IGBIU0TIIPYe8kJmTEq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782712; c=relaxed/simple; bh=PxpxF0dUlwKn44FGhlpT2SXXiblCpU8cCNLnLI9M4ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gQ9tL924Pfwp7voMSDXUXqR12mYw65ddnwuHBdYL1GlQ1jJJ3N8/l3o4zZrPqHxMQigIdyvWLDseM0T3i+Ifo/Pm12EScsO75+P6aWQCADOCK/9f3nfH1gl4KxnsI8yIDQnqP9ZD5ojDRpDBetzxR7f4UEHwS5ikDfObtoHcliU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=LmXPHVW0; arc=none smtp.client-ip=209.85.216.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="LmXPHVW0" Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-2fa7465baceso8397917a91.0 for ; Mon, 17 Feb 2025 00:58:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782710; x=1740387510; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3sE/PXdSSokJ0Zgm0Fk4Pk1jUj6qdWvd3FyfD/aEiAI=; b=LmXPHVW0iELFdQz6cBNN/iAH8jN5YvQ7xGPmgV8a9xvf/Gd7At6f4PYitvBt+fnvIh pEhn1+JPCF8d9g76ZnLKA3NVKgEgIo1sitTXp5lrtjA0Qx4CHWZiavNA2JcS5Xcly8AZ 82ayRT+pSEn4hqtgx5zdvUnQsLN2dkeAlRGPtsWTnEPL95vAxX+nEWL89Tos0qqvcnae qLtSDVMCTFnmGTKGmk5koYEt63HQKluM1LHfvgKdAxch5i6q4DTYF/SENxoiQH4L+27E OAgfLVmskrW6hZszUO0WhTNDL0u5t30eYZQNJihqiLGAvIw/TEZ50fvXxMoBRMaa6z5h 6D9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782710; x=1740387510; 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=3sE/PXdSSokJ0Zgm0Fk4Pk1jUj6qdWvd3FyfD/aEiAI=; b=LeVKJH+NLZbc4ATHv6GawO88lkg6PFdFBtm9lWQazMEBd/Ch66kPFDhwaROtPoITpd w/naISBKNfhtuEWGP22dq0rYduPh7taO4CMKgp3YNOpelT7bS/IsYyOHeqfk+yzYHkFp Ke1ym11/hNRNnnreMJYC+BbpeEOH6XB/dcrkVp1z+1e8e9Eyfo3q4Ft9bSBW0exbu9j3 MmE3I1CgG6wFBhOCmNrq3NsSDHUivK7QLNduIldkClfpIkuPMoWlqLtH58qD1EddgNFe xMuB+mK2DvjnZ2wI3pNwqH2SBMsT4cMcD2HggqswcBuEwvx3/pzo+oi8jNSdL5LIj5Gw Ccaw== X-Forwarded-Encrypted: i=1; AJvYcCXYvd+BMCrEA1SFs+VS1BNq2mTLdcBqJCVhoo6bBbZBdTc1waqHTtWRvgTceQTYJ5dexAVJj11AF+o5IOM=@vger.kernel.org X-Gm-Message-State: AOJu0YxW9o3XBJrAJKXS1B0KBVtRdLEJwKeP7wuQlWDlJqcel0SSvIPb x5+U9QsePSvUR5WsbsLTdTFyYVboUCqrfjqZcCvjcDscHzGSBVsr5Bycgo1ihwY= X-Gm-Gg: ASbGnctRqTHcL7oZajvj6s6yhtypc9CeZIHu/4U23DE4y54QGJG7CCugP1IzFR0Vsb6 XHSphcaBgm0RGk1byKuytJr8yh4QdYqAUB9lp3epYgcZnIidbWIx2rzSvecuwEizT+AoVM4XrVY PX74bAAxtM+dlCWmEoRZqLOAx21g0YQjI5uSKaltqF5byDl97qBwDFVVnNFqE1LS831VZYPGGzy Ix/aHvJBG82fCp/vAn7gON9NnEW8frDTOjapzYPmgX6QK0bsl5W6rP1vI5F3RRVKvi/ATeQDZRB 6P98ts1DF3vgPOpg2MS4wHQjrle5E/REzLmbHvTyQmZFW8cR+JAdFZg= X-Google-Smtp-Source: AGHT+IG6/Z+Rri3hr4qvHP6StAr0ON9USjeH/PioUg2db6lXPHGQJycOyjvnq3k1DASkiPsG+dguug== X-Received: by 2002:a05:6a00:a83:b0:732:2967:400 with SMTP id d2e1a72fcca58-732617bfe3amr12464017b3a.12.1739782710139; Mon, 17 Feb 2025 00:58:30 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:29 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 05/10] genirq: Introduce irq_can_move_in_process_context() Date: Mon, 17 Feb 2025 14:26:51 +0530 Message-ID: <20250217085657.789309-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The interrupt controller drivers which use GENERIC_PENDING_IRQ can move interrupts in process context for downstrean devices which support atomic MSI configuration. Introduce irq_can_move_in_process_context() which allows interrupt controller drivers to test whether a particular interrupt can be moved process context. Signed-off-by: Anup Patel --- include/linux/irq.h | 2 ++ kernel/irq/migration.c | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/linux/irq.h b/include/linux/irq.h index 56f6583093d2..dd5df1e2d032 100644 --- a/include/linux/irq.h +++ b/include/linux/irq.h @@ -615,6 +615,7 @@ extern int irq_affinity_online_cpu(unsigned int cpu); #endif =20 #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ) +bool irq_can_move_in_process_context(struct irq_data *data); void __irq_move_irq(struct irq_data *data); static inline void irq_move_irq(struct irq_data *data) { @@ -623,6 +624,7 @@ static inline void irq_move_irq(struct irq_data *data) } void irq_move_masked_irq(struct irq_data *data); #else +static inline bool irq_can_move_in_process_context(struct irq_data *data) = { return true; } static inline void irq_move_irq(struct irq_data *data) { } static inline void irq_move_masked_irq(struct irq_data *data) { } #endif diff --git a/kernel/irq/migration.c b/kernel/irq/migration.c index e110300ad650..5acea2ac57be 100644 --- a/kernel/irq/migration.c +++ b/kernel/irq/migration.c @@ -127,3 +127,14 @@ void __irq_move_irq(struct irq_data *idata) if (!masked) idata->chip->irq_unmask(idata); } + +bool irq_can_move_in_process_context(struct irq_data *data) +{ + /* + * Get top level irq_data when CONFIG_IRQ_DOMAIN_HIERARCHY is enabled, + * and it should be optimized away when CONFIG_IRQ_DOMAIN_HIERARCHY is + * disabled. So we avoid an "#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY" here. + */ + data =3D irq_desc_get_irq_data(irq_data_to_desc(data)); + return irq_can_move_pcntxt(data); +} --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (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 A084519E7FA for ; Mon, 17 Feb 2025 08:58:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782720; cv=none; b=SZyKvvlsgMur1VHLzVtMQ8h21pcwaN1KHdYJXgXOZZbgVj479i+JUKp9gXTqMOXZqueBiG9nHpKWSbRLB/Q/XQBUUvNszLkB8pmSecP7OCEDyBJcJq9BM6GBPtqqpDPvpJk6WHvF31ZwoWRaGkuA8mZcf4dPmjvjW6VFJk4goVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782720; c=relaxed/simple; bh=n4slH+wgDA6MSJsnkDzYIOL0zzUU8vlxw6wGI5nPdQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UU+RZA54FM8uh27PNBSUa1GPsSMA/aILxRecI+cdOWCNIQI50zz5TJNAjuQ3WbF0mQFDeXwaoLoYfwvqz3Zu0fPk62k4yDfYmUqiE6NrLxWbSLprBVnHKhMjyQ2NGEe8E8lqXfVhS7Nw93rYIk+nsHrk3SeoQssRpK1hq+ysehs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=BG1L7W+G; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="BG1L7W+G" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-221206dbd7eso15647325ad.2 for ; Mon, 17 Feb 2025 00:58:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782718; x=1740387518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JBZXTbuS/jzxIISJXLRWUHAJ1oANsva3E4CzlwWomJY=; b=BG1L7W+GJP/Tdwxcw1LxdIh2hvzCJRPde/VyaPhupVxOCqlFzc5cbyeDwXf+8tkx2n izBa4EdSHTriAYf/93FvA+uP4NXe0eXIffuPeYTBBUUMy/GeXP6DOiQhZT2biuzBuI8V S1CdmqsqLVmiZbHbrmQPVTBflTYFjwofpgW8bNq7miqpxMKDAY+kw0/d3aBzwTmZgXVs X6WVQbbvRnTKOU+Wh+fo8Jfvf8Aplqmdny2gcy0Vnl0xXMmpYqSAZLtS7Rwq7zV0ZSuX qBGhSGaPO84rGjCW+vmApxvHOl64A+9VjDB9xKi9Tx8PosxaXkZ/xBIgGJnk2Z1kPOvn qOFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782718; x=1740387518; 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=JBZXTbuS/jzxIISJXLRWUHAJ1oANsva3E4CzlwWomJY=; b=qUSBEu4CqyVdpkYgcog9r50QJb5iokBBgOfGpyko/NocOHO4fIBTZYo1eapz5wUaOt xjdHuVEeJqhYswgVsVch7fJ0RYONoFFDfnsEJj9acfudgDAdIodXXZqAw8vArWcwyrG5 JwyLeP71Z4NNXj6uxP3DAUNS77VRfOTpXgjFhtJA19UYwO13Gdq0YoJV6utN9j7RpPjh ITuCv7TQ1unW/6ZYvx25KaL52PbW78lUJMK5DHRTyNGBO4c5P9ndovOgzbEUmS1MmbbT l4qmaOYtKVALfeIRLyaNnVPKcSsiLXxdDAOepmtxQWHxdvFua7a2RzPb6igSlSpKnf/0 KicQ== X-Forwarded-Encrypted: i=1; AJvYcCWRa2ph8H1qnKrfgG2Clnq+MPyBSJCSFQL9J72UaLOyPob3eT5Ap35GwtK+035CSd+EnY1CmwMC4gHqMFg=@vger.kernel.org X-Gm-Message-State: AOJu0YwsA410yrye7yyUlVN4T+ydvnW7e9rYM5Twd3xXtXsxSRv+k3rb Rx07I/pd0PFbmUP4k/y6KRBA7GfaMcP9JFntNMT6Hzx3A5MKSPrMVQrSz9ViCcY= X-Gm-Gg: ASbGncuWrK1HONicnc8M7AA+k27pGLxs+0Gx03R5OGKeBg4AhIDS4+Ur5vOKlvesYwf KD2Xr6txJhd/jJ9QUtkJphrIzgznDWGR5Pej4vk7Aazgy73Jy+kBwBkrYwT8len6jQRFRB9n22q xGy7DH3Bb5ZKeG/cr66B8by2xKGxcZuiGGwiTHGEE2/0U7LfWokOmvYKYz1g2g59XtKV4mvswLk EFZsAYCdQsKZI3qr65j8iXdPt5r+1C42Kgf0DGCpzN5LLgLj3sjZkZ6NZglEBwMXZAeT/NaZVGO SJhq7VlrOK0Z+0HP83LEwEKHkio/7reR/p5w86+6ymUH5dkEVyGERn8= X-Google-Smtp-Source: AGHT+IF5wHBOeSXkGQAxYL6n4RikPXg1rsQVBSgGjP3SNk1+gp0GdS9NH13FpIk5wtFAo3PxZIMq+w== X-Received: by 2002:a05:6a00:3d0f:b0:732:4c47:f807 with SMTP id d2e1a72fcca58-732618fa196mr12143576b3a.21.1739782717876; Mon, 17 Feb 2025 00:58:37 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:37 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 06/10] RISC-V: Select GENERIC_PENDING_IRQ Date: Mon, 17 Feb 2025 14:26:52 +0530 Message-ID: <20250217085657.789309-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Enable GENERIC_PENDING_IRQ for RISC-V so that RISC-V irqchips can support delayed irq mirgration in the interrupt context. Signed-off-by: Anup Patel --- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 7612c52e9b1e..a32f39748775 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -111,6 +111,7 @@ config RISCV select GENERIC_IRQ_SHOW select GENERIC_IRQ_SHOW_LEVEL select GENERIC_LIB_DEVMEM_IS_ALLOWED + select GENERIC_PENDING_IRQ if SMP select GENERIC_PCI_IOMAP select GENERIC_PTDUMP if MMU select GENERIC_SCHED_CLOCK --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 1C1B91A5B98 for ; Mon, 17 Feb 2025 08:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782727; cv=none; b=cGYy6l1m6xTmDhMv4FldEQDocMKqNE7m93eA6r7xU9YYQmSqc/vq5ORyIhR/Mzckb/ryB03adQV1IZ0SPhptdyjoeVrzJHkktIWwdBTCzZdvTN0+GoMswcQmu5zGvBHC5ge2LzwOrAste8pKrXqweRIJ+pwTm+tDDgdq+dnlVHA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782727; c=relaxed/simple; bh=RPo428/+3N8qHEtW1RONCU54MpHrxK6R0GBkMkmhafs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pbvcpey/fPSSoygH8iLTIXseAI7Wpw564USPepkDtZ2axmLhbTGmNEikhfkFAT0oQfXdTmIVaGS8NVYLgILfgMjgdQJPxtd8JbnsjNpnIdPyirViMo0FGoSZYSL0doZf793X8jnZ/f514Akjukn3mazIqPHdwyyoN92R/esYJg8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=P9zx8gM4; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="P9zx8gM4" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-220dc3831e3so57398525ad.0 for ; Mon, 17 Feb 2025 00:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782725; x=1740387525; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=LSbtd2A+IfFNBQ5eBtv/V1kZK2ZwPWt/jT9RsNuUoAs=; b=P9zx8gM4yLF93l2RFgKu8sB23M8a7JEVnN/nXtSOpcT6KYGS5/dmPhljIrO4VtdYjy 2CBfGkxq0SwXb8o++f8eXORmuDfql2C1a8h/C2A43Bo2DwQ2K5I5yZ1a9yk2u8ivDP2X uFC6baDRAD241chkZNlrgE698wQWRdRRNfv98J0uzHsoGVdVTnk22dIxGvaznPWaVs2V t2IkSEyUfGVcwW+CUBk8uXmWpQch1aQ7IuLxMZZ74vXZXcqXl9lycAZoFMkLCO3dtFdx 3BhBeA2DC+I6zZnzWQVcQBPw28esh4HSmCLBfq4kxxImLK5bNxW2zR0I3CnqEGTz4G7w 3J8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782725; x=1740387525; 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=LSbtd2A+IfFNBQ5eBtv/V1kZK2ZwPWt/jT9RsNuUoAs=; b=vDDZ2R8NauWBj08w3rmsq50NDxt7tGUQwfFNxWu0aauSbRyxQHMRE4hjZoZy8NginH u2qZRGzJQZNx4lPjnKuAKmm8f5tbP72YyIdn+DVYcmXr8KTvfO7+58moFeP89ppti8Da 6tAtaV+MKlcNqUipPIG1QqUj7QzsawGaz8E2DwYlu2afngTRoYqHjM21o5VH+JBL4YNY ogn/mOdpKV/sX3GvpLH/C7KnR8DZ4oJmWN9H1XN3r0W3hIg2kynjFeFpJP6KlHMfdd4y QRt/Oz5xu1VTWFL0xIwfmoO/8ADQQ8AvnjjzwyKj0dtOdREzWRcCrjCGSDmD7IgebcjW tdcw== X-Forwarded-Encrypted: i=1; AJvYcCWHFrBmVcWNALgR9J0S/p79xPiuQ5kK0RhH1BjKrKGYt/kZZFxFXNiFUDr7oLmY6NlDcXFYAtNvtZprSxI=@vger.kernel.org X-Gm-Message-State: AOJu0YwrvKtM0ETpA164/Sm4KKKZ7j7fNwum2gkJf1SiCPM3FPKsVtCr QAdOtIsmj2W0FSOuYuazIevrqnU1m9HZ5EB4dTFHztvx/SpRXtp4VIm+g/EllK8= X-Gm-Gg: ASbGncvtrBV/EF/WDTgJTA+PzETEu0Pr/C5ZVf51m20OmUIIDeGorM/R/a1xP+4/MgP /zK6NKJeM72TnQ0pF94rviIQh6I1YLB+4bGxJbc8FgwK01m3GE5KmHZizdpRjrdH9qbPxNlhMh3 aJVDnFkwVllNoLP8fKHIzEwlPpEAk07cfm100h18SW628IHsBUTxNSIE/MZfKGcL8HtgVHtfVwc EnsGHQPqAskRlQzpBCjL3jyabvczepLqXr9Imef2zD4oJLTEEqSKRar1RMHgVkVoD/di5knkjfx kpAPuQOXh2beaLx8g4w7aPR5esEHJSkBJcgAAsMWMHZKostgUrSygPw= X-Google-Smtp-Source: AGHT+IGxqt1/NXuR/2jkVfU876iHwX+bRPYBCe6t0MKtB0yrApmwkzYXbLbKcxfdEmKjCUbS0U/rew== X-Received: by 2002:a05:6a00:9456:b0:732:57d3:f004 with SMTP id d2e1a72fcca58-73257d3f4d5mr18708318b3a.6.1739782725252; Mon, 17 Feb 2025 00:58:45 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:44 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 07/10] irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector Date: Mon, 17 Feb 2025 14:26:53 +0530 Message-ID: <20250217085657.789309-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, there is only one "move" pointer in the struct imsic_vector so during vector movement the old vector points to the new vector and new vector points to itself. To support force cleanup of old vector, add separate "move_next" and "move_prev" pointers in the struct imsic_vector where during vector movement the "move_next" pointer of the old vector points to the new vector and the "move_prev" pointer of the new vector points to the old vector. Both "move_next" and "move_prev" pointers are cleared separately by __imsic_local_sync() with a restriction that "move_prev" on the new CPU is cleared only after old CPU has cleared "move_next". Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-early.c | 8 ++- drivers/irqchip/irq-riscv-imsic-state.c | 96 +++++++++++++++++-------- drivers/irqchip/irq-riscv-imsic-state.h | 7 +- 3 files changed, 78 insertions(+), 33 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-= riscv-imsic-early.c index 275df5005705..553650932c75 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -77,6 +77,12 @@ static void imsic_handle_irq(struct irq_desc *desc) struct imsic_vector *vec; unsigned long local_id; =20 + /* + * Process pending local synchronization instead of waiting + * for per-CPU local timer to expire. + */ + imsic_local_sync_all(false); + chained_irq_enter(chip, desc); =20 while ((local_id =3D csr_swap(CSR_TOPEI, 0))) { @@ -120,7 +126,7 @@ static int imsic_starting_cpu(unsigned int cpu) * Interrupts identities might have been enabled/disabled while * this CPU was not running so sync-up local enable/disable state. */ - imsic_local_sync_all(); + imsic_local_sync_all(true); =20 /* Enable local interrupt delivery */ imsic_local_delivery(true); diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index b97e6cd89ed7..96e994443fc7 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -124,10 +124,11 @@ void __imsic_eix_update(unsigned long base_id, unsign= ed long num_id, bool pend, } } =20 -static void __imsic_local_sync(struct imsic_local_priv *lpriv) +static bool __imsic_local_sync(struct imsic_local_priv *lpriv) { struct imsic_local_config *mlocal; struct imsic_vector *vec, *mvec; + bool ret =3D true; int i; =20 lockdep_assert_held(&lpriv->lock); @@ -143,35 +144,75 @@ static void __imsic_local_sync(struct imsic_local_pri= v *lpriv) __imsic_id_clear_enable(i); =20 /* - * If the ID was being moved to a new ID on some other CPU - * then we can get a MSI during the movement so check the - * ID pending bit and re-trigger the new ID on other CPU - * using MMIO write. + * Clear the pervious vector pointer of the new vector only + * after the movement is complete on the old CPU. */ - mvec =3D READ_ONCE(vec->move); - WRITE_ONCE(vec->move, NULL); - if (mvec && mvec !=3D vec) { + mvec =3D READ_ONCE(vec->move_prev); + if (mvec) { + /* + * If the old vector has not been updated then + * try again in the next sync-up call. + */ + if (READ_ONCE(mvec->move_next)) { + ret =3D false; + continue; + } + + WRITE_ONCE(vec->move_prev, NULL); + } + + /* + * If a vector was being moved to a new vector on some other + * CPU then we can get a MSI during the movement so check the + * ID pending bit and re-trigger the new ID on other CPU using + * MMIO write. + */ + mvec =3D READ_ONCE(vec->move_next); + if (mvec) { if (__imsic_id_read_clear_pending(i)) { mlocal =3D per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va); } =20 + WRITE_ONCE(vec->move_next, NULL); imsic_vector_free(&lpriv->vectors[i]); } =20 skip: bitmap_clear(lpriv->dirty_bitmap, i, 1); } + + return ret; } =20 -void imsic_local_sync_all(void) +#ifdef CONFIG_SMP +static void __imsic_local_timer_start(struct imsic_local_priv *lpriv) +{ + lockdep_assert_held(&lpriv->lock); + + if (!timer_pending(&lpriv->timer)) { + lpriv->timer.expires =3D jiffies + 1; + add_timer_on(&lpriv->timer, smp_processor_id()); + } +} +#else +static inline void __imsic_local_timer_start(struct imsic_local_priv *lpri= v) +{ +} +#endif + +void imsic_local_sync_all(bool force_all) { struct imsic_local_priv *lpriv =3D this_cpu_ptr(imsic->lpriv); unsigned long flags; =20 raw_spin_lock_irqsave(&lpriv->lock, flags); - bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); - __imsic_local_sync(lpriv); + + if (force_all) + bitmap_fill(lpriv->dirty_bitmap, imsic->global.nr_ids + 1); + if (!__imsic_local_sync(lpriv)) + __imsic_local_timer_start(lpriv); + raw_spin_unlock_irqrestore(&lpriv->lock, flags); } =20 @@ -190,12 +231,7 @@ void imsic_local_delivery(bool enable) #ifdef CONFIG_SMP static void imsic_local_timer_callback(struct timer_list *timer) { - struct imsic_local_priv *lpriv =3D this_cpu_ptr(imsic->lpriv); - unsigned long flags; - - raw_spin_lock_irqsave(&lpriv->lock, flags); - __imsic_local_sync(lpriv); - raw_spin_unlock_irqrestore(&lpriv->lock, flags); + imsic_local_sync_all(false); } =20 static void __imsic_remote_sync(struct imsic_local_priv *lpriv, unsigned i= nt cpu) @@ -216,14 +252,11 @@ static void __imsic_remote_sync(struct imsic_local_pr= iv *lpriv, unsigned int cpu */ if (cpu_online(cpu)) { if (cpu =3D=3D smp_processor_id()) { - __imsic_local_sync(lpriv); - return; + if (__imsic_local_sync(lpriv)) + return; } =20 - if (!timer_pending(&lpriv->timer)) { - lpriv->timer.expires =3D jiffies + 1; - add_timer_on(&lpriv->timer, cpu); - } + __imsic_local_timer_start(lpriv); } } #else @@ -278,8 +311,9 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =20 -static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struc= t imsic_vector *vec, - bool new_enable, struct imsic_vector *new_move) +static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, + struct imsic_vector *vec, bool is_old_vec, + bool new_enable, struct imsic_vector *move_vec) { unsigned long flags; bool enabled; @@ -289,7 +323,10 @@ static bool imsic_vector_move_update(struct imsic_loca= l_priv *lpriv, struct imsi /* Update enable and move details */ enabled =3D READ_ONCE(vec->enable); WRITE_ONCE(vec->enable, new_enable); - WRITE_ONCE(vec->move, new_move); + if (is_old_vec) + WRITE_ONCE(vec->move_next, move_vec); + else + WRITE_ONCE(vec->move_prev, move_vec); =20 /* Mark the vector as dirty and synchronize */ bitmap_set(lpriv->dirty_bitmap, vec->local_id, 1); @@ -322,8 +359,8 @@ void imsic_vector_move(struct imsic_vector *old_vec, st= ruct imsic_vector *new_ve * interrupt on the old vector while device was being moved * to the new vector. */ - enabled =3D imsic_vector_move_update(old_lpriv, old_vec, false, new_vec); - imsic_vector_move_update(new_lpriv, new_vec, enabled, new_vec); + enabled =3D imsic_vector_move_update(old_lpriv, old_vec, true, false, new= _vec); + imsic_vector_move_update(new_lpriv, new_vec, false, enabled, old_vec); } =20 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS @@ -386,7 +423,8 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hw= irq, const struct cpumask vec =3D &lpriv->vectors[local_id]; vec->hwirq =3D hwirq; vec->enable =3D false; - vec->move =3D NULL; + vec->move_next =3D NULL; + vec->move_prev =3D NULL; =20 return vec; } diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-= riscv-imsic-state.h index 391e44280827..f02842b84ed5 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -23,7 +23,8 @@ struct imsic_vector { unsigned int hwirq; /* Details accessed using local lock held */ bool enable; - struct imsic_vector *move; + struct imsic_vector *move_next; + struct imsic_vector *move_prev; }; =20 struct imsic_local_priv { @@ -74,7 +75,7 @@ static inline void __imsic_id_clear_enable(unsigned long = id) __imsic_eix_update(id, 1, false, false); } =20 -void imsic_local_sync_all(void); +void imsic_local_sync_all(bool force_all); void imsic_local_delivery(bool enable); =20 void imsic_vector_mask(struct imsic_vector *vec); @@ -87,7 +88,7 @@ static inline bool imsic_vector_isenabled(struct imsic_ve= ctor *vec) =20 static inline struct imsic_vector *imsic_vector_get_move(struct imsic_vect= or *vec) { - return READ_ONCE(vec->move); + return READ_ONCE(vec->move_prev); } =20 void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *= new_vec); --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 3608A1A314E for ; Mon, 17 Feb 2025 08:58:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782735; cv=none; b=c2COAPjub2U1MXacw0hoYsbV7AgW8t/qLklxy4IA4KsYHHlp6PsKSBNVkDE3LGTkLwc8u++X++7hdkfF4IEt34qg6HHiQAZUTgFHCQE5J5+W8HrdJ3e0OnkKW/LqTjjLp1rMRLrWEkyiuC0pzxRXaYHmbjJq7B2fd6DsHv50gxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782735; c=relaxed/simple; bh=mFFEh8+hZeEVXl9Ut+Oj3ibjoUtqS7w8eehuqLHhRt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gz3u7SgC9P2RW5Npwxyb6ec4vP4CI1qI4mDG+hppJiAvbSxIJaWibAQYtQmjAMUExXDVPeBNG2JWS2GPIWDAjHZD3mebLoVkiygFBYI++jc7krVAg1kdmZgmyUDNgWhZslxPgHs4KEkL32I4H6FL1eoY/CejP3uFw4aVyWfLe9g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=oSOWmpQQ; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="oSOWmpQQ" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-220e83d65e5so59704055ad.1 for ; Mon, 17 Feb 2025 00:58:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782733; x=1740387533; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RoqQmmMLZnhmH7e8y5iCPOfAA2UjM+1/YD5gOA06f3E=; b=oSOWmpQQzqVZiyD4LovIEWCs7VoMAsLfiLKg+Dx19Hr0VzO5W2ioB5838kiSKaCX4G WBxjGQG2tm8pJJZKROGEsmGy/x595OoqlFeLUEby0xs8tIwQF1TKD+DuTh4CYGYAX3ti 2H38B/Wiox+A/YiPt0BPiWTVghS59pF0Kq1ZE17OWMSS9ah3B97GapWJkpzCtLutA2UB 8krvpIDUBhYZVHf2foC0Ejm4ft+kUSqPbtgh2r/AIwPu8zq51q1aoEe5spG6v9+SRU3H gkAslBGTvK9MzykryRIVxQINUyapoZNV9EeayrP4FO5WAaQ7FQkP7WnZuV6cd4E4GpNc dILg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782733; x=1740387533; 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=RoqQmmMLZnhmH7e8y5iCPOfAA2UjM+1/YD5gOA06f3E=; b=vYVY9qEhOqYG9FiZe85zV6G/2NknhSeQzl35xjcFUzt5T8+jDFu9fCYHPX5256ano7 dtkNJ6Ku9Qxkcc77de4LIFYk5dtHadj57DeM1jpJteTPxrwxwzO2Rxikj1eqFj1gwv+O Hxi0U3tYbclvL2coHG0zsKeNcGF5VyKqVmeGK9xDIxfjjJvKtP7jQv/3VIyAb2q/EW+A 8+5joa0RcNEcWChfU4CjtRgYgDFGdeTjDjxCEE2L+XuLIjGihyYVwATcdtCzBOqqqWhA x19JHsPW78LKRlB3XR1hlLmDU7UeGTPhg751Q6ra2VMY4Io3MKr2u/oJPlMPswKJEESu bbkA== X-Forwarded-Encrypted: i=1; AJvYcCWJhuhEW1t+IgEVn6YEnTL8CT81dZalrmUcNndYUD+j3bGeHacNlE79xZ4IjvhFOwNVIPX7KkmfKXcViCc=@vger.kernel.org X-Gm-Message-State: AOJu0YzSRe6ZcxbqQxZvAYtDiTUkvyI9GnOAXMNbWd5x9cG1E9AdIag1 pZYc5QxxK9lTYREY49kKstgOh54Z0q2TzUtS86TWL42HVoj3k83ZYAPV6MtxeCU= X-Gm-Gg: ASbGnct+DlSLeuChOwFu7o1a/l+kgIITjyBKMyHzCr8Hg8wfi0sKMsu5AvLLP9wPJXV eTRIgJOdAWmo+wPBfCSbYsXaR7s7zZTFntPCFZJsUE2Vipxj7viKnE6l/LWa4tYbWfbGiSeIxRA SU76qbhpYlwMlWUnPzCSYyeYHLxIGez8nTMqEZ4aDHblYC2jr6ti4suL2L+uoTfC+dtvq634jDw MEsURrXjYao59GOLjZWtY829palyQYi4sNAOXmeVEj869TcN0JHHJlRANaUo39W6SaUleVK2NQP GTmyLG/kzXubQdwDyghH7nODTs60iBrHYxD+hfS1mWiMxxSgvbhy+wI= X-Google-Smtp-Source: AGHT+IFBSmav50eb95KMP+Wa+2zHfS16N6A6ml9KRa5tGTRfbaBtV9X2/4WT6iaEXHAuO8XqxuEKDQ== X-Received: by 2002:a05:6a21:6d95:b0:1ee:5e7e:bcc2 with SMTP id adf61e73a8af0-1ee8cb176f4mr14239238637.23.1739782733442; Mon, 17 Feb 2025 00:58:53 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:58:52 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 08/10] irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC Date: Mon, 17 Feb 2025 14:26:54 +0530 Message-ID: <20250217085657.789309-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Implement irq_force_complete_move() for IMSIC driver so that in-flight vector movements on a CPU can be cleaned-up when the CPU goes down. Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 32 ++++++++++++++++++++++ drivers/irqchip/irq-riscv-imsic-state.c | 17 ++++++++++++ drivers/irqchip/irq-riscv-imsic-state.h | 1 + 3 files changed, 50 insertions(+) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-riscv-imsic-platform.c index 9a5e7b4541f6..b9e3f9030bdf 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -129,6 +129,37 @@ static int imsic_irq_set_affinity(struct irq_data *d, = const struct cpumask *mask =20 return IRQ_SET_MASK_OK_DONE; } + +static void imsic_irq_force_complete_move(struct irq_data *d) +{ + struct imsic_vector *mvec, *vec =3D irq_data_get_irq_chip_data(d); + unsigned int cpu =3D smp_processor_id(); + + if (WARN_ON(!vec)) + return; + + /* Do nothing if there is no in-flight move */ + mvec =3D imsic_vector_get_move(vec); + if (!mvec) + return; + + /* Do nothing if the old IMSIC vector does not belong to current CPU */ + if (mvec->cpu !=3D cpu) + return; + + /* + * The best we can do is force cleanup the old IMSIC vector. + * + * The challenges over here are same as x86 vector domain so + * refer to the comments in irq_force_complete_move() function + * implemented at arch/x86/kernel/apic/vector.c. + */ + + /* Force cleanup in-flight move */ + pr_info("IRQ fixup: irq %d move in progress, old vector cpu %d local_id %= d\n", + d->irq, mvec->cpu, mvec->local_id); + imsic_vector_force_move_cleanup(vec); +} #endif =20 static struct irq_chip imsic_irq_base_chip =3D { @@ -137,6 +168,7 @@ static struct irq_chip imsic_irq_base_chip =3D { .irq_unmask =3D imsic_irq_unmask, #ifdef CONFIG_SMP .irq_set_affinity =3D imsic_irq_set_affinity, + .irq_force_complete_move =3D imsic_irq_force_complete_move, #endif .irq_retrigger =3D imsic_irq_retrigger, .irq_compose_msi_msg =3D imsic_irq_compose_msg, diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index 96e994443fc7..5ec2b6bdffb2 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -311,6 +311,23 @@ void imsic_vector_unmask(struct imsic_vector *vec) raw_spin_unlock(&lpriv->lock); } =20 +void imsic_vector_force_move_cleanup(struct imsic_vector *vec) +{ + struct imsic_local_priv *lpriv; + struct imsic_vector *mvec; + unsigned long flags; + + lpriv =3D per_cpu_ptr(imsic->lpriv, vec->cpu); + raw_spin_lock_irqsave(&lpriv->lock, flags); + + mvec =3D READ_ONCE(vec->move_prev); + WRITE_ONCE(vec->move_prev, NULL); + if (mvec) + imsic_vector_free(mvec); + + raw_spin_unlock_irqrestore(&lpriv->lock, flags); +} + static bool imsic_vector_move_update(struct imsic_local_priv *lpriv, struct imsic_vector *vec, bool is_old_vec, bool new_enable, struct imsic_vector *move_vec) diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-= riscv-imsic-state.h index f02842b84ed5..19dea0c77738 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -91,6 +91,7 @@ static inline struct imsic_vector *imsic_vector_get_move(= struct imsic_vector *ve return READ_ONCE(vec->move_prev); } =20 +void imsic_vector_force_move_cleanup(struct imsic_vector *vec); void imsic_vector_move(struct imsic_vector *old_vec, struct imsic_vector *= new_vec); =20 struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned= int local_id); --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 4E5731A314E for ; Mon, 17 Feb 2025 08:59:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782743; cv=none; b=UuyTJ4C4TSFm+d0nYq8ZPl3vCRvjtPl3HlyIK2iq50kIwxO/VXjSM1RZQZWuQh8bzNqnnOdXpNTzzT+lITwjDkPQLuGnjLqWIiOrbwN6di9RTiZxOykjRhTXv/48OoGTEw6fUPBhVrWwDv59lEJzhrLstaST0a70tUx1pN8MnIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782743; c=relaxed/simple; bh=a6c0Uq7JBdxZXw7kUxhrWKbabcgA5MuMPGG3EqfXL64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MWaXJWgeE3LsIwEs+KjKhJsaAnqNq+5Q+3NyEzTE2a+2OtUi90DKdpXC/NT8Mgdm2licB4rpAS5DK1T9j6A86J6Ll0zOREQISxe5TkgdPkme0J1vNIuq/CNK8+pqAOkElLdLqvi0DZfag809a98Z5Kp3yxmujYTSOhDlSPLDYjo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=pRDEdXXx; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="pRDEdXXx" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21f61b01630so79537135ad.1 for ; Mon, 17 Feb 2025 00:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782742; x=1740387542; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=koCL3sGSNowxnA2uthh7D1mm9ult5obqPLO5TypzPmY=; b=pRDEdXXxokO+M2WhFucDV+HQ9HUS7av7a7PRHS1ulbIvholmc5VAXboqho1+wY5BUi cSt8GbQlkA8ZmP1y4+MtCflLKAux1cckRs0PVQ+XhC2Ld1dMCRxBDgVlb/kVv6WedwPI UlLzS4qdOKlY4tgSd54pWpNdZB4XmvSW+c5OzkqAeFxoiG0t8W9T/xDW6I9buh+njwbm 5lvSHLclm8fsvf7wjt1FpUmId4+GJB67rCAE0KzgvI1BMxDFAdrhgu4nqw7rwKZejMz6 MEeQv0dlPB7mTmeU7D29sg4WLh34ElzRjpSn9mZP8i0+36flOtlF9Of+W9Jc0S0lGhUL sPLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782742; x=1740387542; 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=koCL3sGSNowxnA2uthh7D1mm9ult5obqPLO5TypzPmY=; b=JeWbNlx6p7T7UVh3RIHm60Ifj/nGbuxE84+RgRDt7t5EDCPtxAsWux9JxR8UyXMl3G Lmi/RXZVwJydOVgmRujMeEKGOol9ZIiDrc9mn66D2CPQKe1fT8kL6oQeQ1Aq2yL8u/11 vUi66wEHu9vg5WIgEXkslydNMOFqry2hjBjy9fpFnMpElzfh7J5wCPGM6yDG1cnYAfJJ tNbrstxh5a5QkC/h+P375KRDq9nkk5RrHAg6IBS6imPoI37BW0jyQOv6ikcOMc9xIG7n JpkpyZJIwR165dlK4HNPNbL6oWi+hyf5Sy6UrUt9QpceT0peQvubSawn5Sj2LXrMpavZ RRBg== X-Forwarded-Encrypted: i=1; AJvYcCXdDe1L238wwD9PHO906cr/KPBn7YDQ8Fz4X2d62TTzfIOMlp+TVDVjYMxlB2ORKoyya3OqVfG/F3KOiXQ=@vger.kernel.org X-Gm-Message-State: AOJu0YydIzsDn/thXHc4/oguKFwSWtRKQE9MPUyJ+sbSJsWslnZSc7L5 JtTH+FtXQBJGfpSuWBVYUWzvLgROR6ovX0SH3yDBPXkfl0JX/adUyG7uxLtv0oc= X-Gm-Gg: ASbGnctdn9I5lW4BTQKmOxAgb0DlJI4efWw+kHvV+xUrwVAYAUCdFkZ2fRIKlR+W3xe 7ZkZhNjsd/GifvxM5AtkaJB4b+DeMhv3TJp2XzgsknkJdJGpQNyxAXvAY3r/K7JhUnmT9hmb4Ns orx/zF9ai70QWDDoC0zL3Zundn4lryyg+Bom6KG2qW+rkh+X11GVbe3CBEb4HSELsZCmlmAFItW 6KuuTbCKwi34XOB9c+EplsqmwDS0GKfVx8xE/KP4ZtPN57WW3tbg56T5HQuABCnr6ttHLhXItjY Yn4RYHp6SCMwLlK53U5871gAh1gNWZVuK5bM5pDv51StZhObjPNxuq8= X-Google-Smtp-Source: AGHT+IHbBvzPw0Wn7/Eyf5Y7dSkIAJVrU71JRxh4insgq9Beex3YYjwNlgnCYaOLqfIHDCH+B/xxjA== X-Received: by 2002:a05:6a00:4fd2:b0:730:949d:2d52 with SMTP id d2e1a72fcca58-73262158ademr14543775b3a.3.1739782741534; Mon, 17 Feb 2025 00:59:01 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:59:00 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 09/10] irqchip/riscv-imsic: Replace hwirq with irq in the IMSIC vector Date: Mon, 17 Feb 2025 14:26:55 +0530 Message-ID: <20250217085657.789309-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently, the imsic_handle_irq() uses generic_handle_domain_irq() to handle the irq which internally has an extra step of resolving hwirq using domain. This extra step can be avoided by replacing hwirq with irq in the IMSIC vector and directly calling generic_handle_irq(). Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-early.c | 6 ++---- drivers/irqchip/irq-riscv-imsic-platform.c | 2 +- drivers/irqchip/irq-riscv-imsic-state.c | 8 ++++---- drivers/irqchip/irq-riscv-imsic-state.h | 4 ++-- 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-early.c b/drivers/irqchip/irq-= riscv-imsic-early.c index 553650932c75..d9ae87808651 100644 --- a/drivers/irqchip/irq-riscv-imsic-early.c +++ b/drivers/irqchip/irq-riscv-imsic-early.c @@ -73,7 +73,7 @@ static int __init imsic_ipi_domain_init(void) { return 0;= } static void imsic_handle_irq(struct irq_desc *desc) { struct irq_chip *chip =3D irq_desc_get_chip(desc); - int err, cpu =3D smp_processor_id(); + int cpu =3D smp_processor_id(); struct imsic_vector *vec; unsigned long local_id; =20 @@ -103,9 +103,7 @@ static void imsic_handle_irq(struct irq_desc *desc) continue; } =20 - err =3D generic_handle_domain_irq(imsic->base_domain, vec->hwirq); - if (unlikely(err)) - pr_warn_ratelimited("hwirq 0x%x mapping not found\n", vec->hwirq); + generic_handle_irq(vec->irq); } =20 chained_irq_exit(chip, desc); diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-riscv-imsic-platform.c index b9e3f9030bdf..6bf5d63f614e 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -111,7 +111,7 @@ static int imsic_irq_set_affinity(struct irq_data *d, c= onst struct cpumask *mask return -EBUSY; =20 /* Get a new vector on the desired set of CPUs */ - new_vec =3D imsic_vector_alloc(old_vec->hwirq, mask_val); + new_vec =3D imsic_vector_alloc(old_vec->irq, mask_val); if (!new_vec) return -ENOSPC; =20 diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index 5ec2b6bdffb2..d0148e48ab05 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -422,7 +422,7 @@ struct imsic_vector *imsic_vector_from_local_id(unsigne= d int cpu, unsigned int l return &lpriv->vectors[local_id]; } =20 -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct c= pumask *mask) +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpu= mask *mask) { struct imsic_vector *vec =3D NULL; struct imsic_local_priv *lpriv; @@ -438,7 +438,7 @@ struct imsic_vector *imsic_vector_alloc(unsigned int hw= irq, const struct cpumask =20 lpriv =3D per_cpu_ptr(imsic->lpriv, cpu); vec =3D &lpriv->vectors[local_id]; - vec->hwirq =3D hwirq; + vec->irq =3D irq; vec->enable =3D false; vec->move_next =3D NULL; vec->move_prev =3D NULL; @@ -451,7 +451,7 @@ void imsic_vector_free(struct imsic_vector *vec) unsigned long flags; =20 raw_spin_lock_irqsave(&imsic->matrix_lock, flags); - vec->hwirq =3D UINT_MAX; + vec->irq =3D 0; irq_matrix_free(imsic->matrix, vec->cpu, vec->local_id, false); raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags); } @@ -510,7 +510,7 @@ static int __init imsic_local_init(void) vec =3D &lpriv->vectors[i]; vec->cpu =3D cpu; vec->local_id =3D i; - vec->hwirq =3D UINT_MAX; + vec->irq =3D 0; } } =20 diff --git a/drivers/irqchip/irq-riscv-imsic-state.h b/drivers/irqchip/irq-= riscv-imsic-state.h index 19dea0c77738..3202ffa4e849 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.h +++ b/drivers/irqchip/irq-riscv-imsic-state.h @@ -20,7 +20,7 @@ struct imsic_vector { unsigned int cpu; unsigned int local_id; /* Details saved by driver in the vector */ - unsigned int hwirq; + unsigned int irq; /* Details accessed using local lock held */ bool enable; struct imsic_vector *move_next; @@ -96,7 +96,7 @@ void imsic_vector_move(struct imsic_vector *old_vec, stru= ct imsic_vector *new_ve =20 struct imsic_vector *imsic_vector_from_local_id(unsigned int cpu, unsigned= int local_id); =20 -struct imsic_vector *imsic_vector_alloc(unsigned int hwirq, const struct c= pumask *mask); +struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpu= mask *mask); void imsic_vector_free(struct imsic_vector *vector); =20 void imsic_vector_debug_show(struct seq_file *m, struct imsic_vector *vec,= int ind); --=20 2.43.0 From nobody Sun Dec 14 06:18:50 2025 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (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 6D01F1A314E for ; Mon, 17 Feb 2025 08:59:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782752; cv=none; b=AYvzedQi5xOuyUivp2Y5w75iC5KZxW3ROGeK2pul/DfvT+Q9R5EGytc40Z2REeE2+noN9cvZ2Y427d3wtr4l2qdXIMDiDiqoBF70Zo/+zvB3mh1kiD75wQ0GgF6+Zj9VWrkQSPtpwdtgSztXobbIp+OLBu0HA1fMT9ZqjlmnPOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739782752; c=relaxed/simple; bh=tNahCfxLRgNIbiBla43nJrTI1GFGdO1edGYaRhyK8s8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D7YId8LG+F/YtNo51cs88f1qVnVes52zO5XZ5FVbNLuzZL7t3BheFRy6pKgYwMXubhwTi32tcAQcD9/9962/RzXxodTonmkZ3kMycaIXEuiCFGXjKRJRQwc6shJTjCRG9Fiv4UB+Nb9xxkfJMKi3/GoXvt/og2QUTXBHtVc2c3c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=Lsc/XXV1; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="Lsc/XXV1" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-22104c4de96so26085415ad.3 for ; Mon, 17 Feb 2025 00:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739782750; x=1740387550; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KEjndyBD35lV6nr6NSLWRRyly4db2axy7koFOHZTKsQ=; b=Lsc/XXV1YimBLdmnaKn9Zsl8BoUbUEzOLaw+rzRvc40/vl1ItqtahNyZ3MeAVQAj4/ y9QEu7hRj1fTAaKvQiSXNTQORBJ2Q8MlVlAKZvqEPe719kzW+1YKOgJO3hdd7RXq4Kux 0tAxqjVwLG0srjj8n9WcT1BodsGEnryDmLDMynT1ghaMojuIOZ6aPr4ZhNsankFCkjT8 Vf1cpQNgOIgiAf/HAjEXrwE+r0DymDS46k6x90h4uuEMQrwn8oBWf+1wVM32sYn1CFgL cYwI++CAs963qvnk0ock1v+ez/lLjZjc07iaG2PAyBYr0RghMcyLi4WCBl3vDmHkKDWX 7dyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739782750; x=1740387550; 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=KEjndyBD35lV6nr6NSLWRRyly4db2axy7koFOHZTKsQ=; b=TIwMcwSufeTi1UxVUTqTk6u1OvynXOrwmyeEueslCE/3eKTyvbNW23lGxQh/s1wLXm n8UksLQ84FiarBReD9yRoXuOCsLnb1qoZy4bRMUmMoiDpY5dVyujdDhZtQyMDPfYUkpa 3bP0z66RmqRZjUItl0K2+IC5Fitbdf7jrNrF4N/GY7qQoEikPVoNpcgkqcg1QbKcuA4R mUGHSuGPdi/hXHRB1+MCpy+8ufw+W61CbmWuCoWNHk1cGwBY+eKA0rw0CXn0vXTYyGrg UAltry+k77JhZKjvYmHXsXObejdr0wNi5lMMoBSjUHgZpPWEXVpsJjt0wsTajeJA3kw1 gUDA== X-Forwarded-Encrypted: i=1; AJvYcCX9VS9JvKJiXU6KrAAFvDWQ2uVPF1LnxKuSgZx+670kLylCVDCRuR9bUrSMETgVYQursH6/TaRm80YqP5U=@vger.kernel.org X-Gm-Message-State: AOJu0Yy+i9Lq5pM6ec1EZH4r8QfI4oPLzHbv3Rc07vhtSsgcQDoeavbo F5BGHOFi/h9hohjHIbYkx9cNpcPrOZ4j5Z6nxEuv0veytsu5P49zPvMkgh1zbwY= X-Gm-Gg: ASbGncsqeNG15WkaWbgyBYUSYufH/a9w9DuwK3Sf32uSQw77DLa01mXL8O1zuvjc7se ubMU+Gfv5lcwv6kuoOZKEtrbGwup05UlMdccJ6PDcMmD8vzDA11QnYhDoa/QiX53TIPgp+EWSXS 90otRCjekKvTLmiU7rVl72wxLbGAeIldooaaLJ0cRro1k8phOk4eGEeuPw8O/v0dXMF7XaRdng7 KQlxcneYv81uD+73ckRpOXDb4AlKFbvaL45ZVLoODje5EtETLekY/xVI6k5nNL00TX6ydd3j+qB J+W5kLSy3FOmx2d7QquFvSQEOir7RqhzNyfq3tab1yTQIJkEZBtVQFI= X-Google-Smtp-Source: AGHT+IH6Tjxl2D2mFXDe6LhFiNV1G6vUFczqpaUqf8nSRh0V0anC6B6P0c3HIggrJMZH7GpsMRQCQA== X-Received: by 2002:a05:6a00:1392:b0:730:74f8:25b6 with SMTP id d2e1a72fcca58-7326179e8a0mr14044686b3a.6.1739782749571; Mon, 17 Feb 2025 00:59:09 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([122.171.22.227]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73242546867sm7632018b3a.24.2025.02.17.00.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Feb 2025 00:59:08 -0800 (PST) From: Anup Patel To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org Cc: hpa@zytor.com, Marc Zyngier , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Palmer Dabbelt , Paul Walmsley , Atish Patra , Andrew Jones , Sunil V L , Anup Patel , linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, Anup Patel Subject: [PATCH v6 10/10] irqchip/riscv-imsic: Special handling for non-atomic device MSI update Date: Mon, 17 Feb 2025 14:26:56 +0530 Message-ID: <20250217085657.789309-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217085657.789309-1-apatel@ventanamicro.com> References: <20250217085657.789309-1-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Device having non-atomic MSI update might see an intermediate state when changing target IMSIC vector from one CPU to another. To avoid losing interrupt to such intermediate state, do the following (just like x86 APIC): 1) First write a temporary IMSIC vector to the device which has MSI address same as the old IMSIC vector but with MSI data matches the new IMSIC vector. 2) Next write the new IMSIC vector to the device. Based on the above, the __imsic_local_sync() must check pending status of both old MSI data and new MSI data on the old CPU. In addition, the movement of IMSIC vector for non-atomic device MSI update must be done in interrupt context using IRQCHIP_MOVE_DEFERRED. Signed-off-by: Anup Patel --- drivers/irqchip/irq-riscv-imsic-platform.c | 73 +++++++++++++++++++++- drivers/irqchip/irq-riscv-imsic-state.c | 31 +++++++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/drivers/irqchip/irq-riscv-imsic-platform.c b/drivers/irqchip/i= rq-riscv-imsic-platform.c index 6bf5d63f614e..828102c46f51 100644 --- a/drivers/irqchip/irq-riscv-imsic-platform.c +++ b/drivers/irqchip/irq-riscv-imsic-platform.c @@ -64,6 +64,11 @@ static int imsic_irq_retrigger(struct irq_data *d) return 0; } =20 +static void imsic_irq_ack(struct irq_data *d) +{ + irq_move_irq(d); +} + static void imsic_irq_compose_vector_msg(struct imsic_vector *vec, struct = msi_msg *msg) { phys_addr_t msi_addr; @@ -97,6 +102,21 @@ static int imsic_irq_set_affinity(struct irq_data *d, c= onst struct cpumask *mask bool force) { struct imsic_vector *old_vec, *new_vec; + struct imsic_vector tmp_vec; + + /* + * Requirements for the downstream irqdomains (or devices): + * + * 1) Downstream irqdomains (or devices) with atomic MSI update can + * happily do imsic_irq_set_affinity() in the process-context on + * any CPU so the irqchip of such irqdomains must not set the + * IRQCHIP_MOVE_DEFERRED flag. + * + * 2) Downstream irqdomains (or devices) with non-atomic MSI update + * must do imsic_irq_set_affinity() in the interrupt-context upon + * next interrupt so the irqchip of such irqdomains must set the + * IRQCHIP_MOVE_DEFERRED flag. + */ =20 old_vec =3D irq_data_get_irq_chip_data(d); if (WARN_ON(!old_vec)) @@ -115,6 +135,33 @@ static int imsic_irq_set_affinity(struct irq_data *d, = const struct cpumask *mask if (!new_vec) return -ENOSPC; =20 + /* + * Device having non-atomic MSI update might see an intermediate + * state when changing target IMSIC vector from one CPU to another. + * + * To avoid losing interrupt to such intermediate state, do the + * following (just like x86 APIC): + * + * 1) First write a temporary IMSIC vector to the device which + * has MSI address same as the old IMSIC vector but MSI data + * matches the new IMSIC vector. + * + * 2) Next write the new IMSIC vector to the device. + * + * Based on the above, the __imsic_local_sync() must check pending + * status of both old MSI data and new MSI data on the old CPU. + */ + + if (!irq_can_move_in_process_context(d) && + new_vec->local_id !=3D old_vec->local_id) { + /* Setup temporary vector */ + tmp_vec.cpu =3D old_vec->cpu; + tmp_vec.local_id =3D new_vec->local_id; + + /* Point device to the temporary vector */ + imsic_msi_update_msg(irq_get_irq_data(d->irq), &tmp_vec); + } + /* Point device to the new vector */ imsic_msi_update_msg(irq_get_irq_data(d->irq), new_vec); =20 @@ -171,6 +218,7 @@ static struct irq_chip imsic_irq_base_chip =3D { .irq_force_complete_move =3D imsic_irq_force_complete_move, #endif .irq_retrigger =3D imsic_irq_retrigger, + .irq_ack =3D imsic_irq_ack, .irq_compose_msi_msg =3D imsic_irq_compose_msg, .flags =3D IRQCHIP_SKIP_SET_WAKE | IRQCHIP_MASK_ON_SUSPEND, @@ -190,7 +238,7 @@ static int imsic_irq_domain_alloc(struct irq_domain *do= main, unsigned int virq, return -ENOSPC; =20 irq_domain_set_info(domain, virq, virq, &imsic_irq_base_chip, vec, - handle_simple_irq, NULL, NULL); + handle_edge_irq, NULL, NULL); irq_set_noprobe(virq); irq_set_affinity(virq, cpu_online_mask); irq_data_update_effective_affinity(irq_get_irq_data(virq), cpumask_of(vec= ->cpu)); @@ -229,15 +277,36 @@ static const struct irq_domain_ops imsic_base_domain_= ops =3D { #endif }; =20 +static bool imsic_init_dev_msi_info(struct device *dev, + struct irq_domain *domain, + struct irq_domain *real_parent, + struct msi_domain_info *info) +{ + if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info)) + return false; + + switch (info->bus_token) { + case DOMAIN_BUS_PCI_DEVICE_MSI: + case DOMAIN_BUS_PCI_DEVICE_MSIX: + info->chip->flags |=3D IRQCHIP_MOVE_DEFERRED; + break; + default: + break; + } + + return true; +} + static const struct msi_parent_ops imsic_msi_parent_ops =3D { .supported_flags =3D MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX, .required_flags =3D MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS | MSI_FLAG_PCI_MSI_MASK_PARENT, + .chip_flags =3D MSI_CHIP_FLAG_SET_ACK, .bus_select_token =3D DOMAIN_BUS_NEXUS, .bus_select_mask =3D MATCH_PCI_MSI | MATCH_PLATFORM_MSI, - .init_dev_msi_info =3D msi_lib_init_dev_msi_info, + .init_dev_msi_info =3D imsic_init_dev_msi_info, }; =20 int imsic_irqdomain_init(void) diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-= riscv-imsic-state.c index d0148e48ab05..3a2a381e4fa1 100644 --- a/drivers/irqchip/irq-riscv-imsic-state.c +++ b/drivers/irqchip/irq-riscv-imsic-state.c @@ -126,8 +126,8 @@ void __imsic_eix_update(unsigned long base_id, unsigned= long num_id, bool pend, =20 static bool __imsic_local_sync(struct imsic_local_priv *lpriv) { - struct imsic_local_config *mlocal; - struct imsic_vector *vec, *mvec; + struct imsic_local_config *tlocal, *mlocal; + struct imsic_vector *vec, *tvec, *mvec; bool ret =3D true; int i; =20 @@ -169,13 +169,36 @@ static bool __imsic_local_sync(struct imsic_local_pri= v *lpriv) */ mvec =3D READ_ONCE(vec->move_next); if (mvec) { - if (__imsic_id_read_clear_pending(i)) { + /* + * Device having non-atomic MSI update might see an + * intermediate state so check both old ID and new ID + * for pending interrupts. + * + * For details, refer imsic_irq_set_affinity(). + */ + + tvec =3D vec->local_id =3D=3D mvec->local_id ? + NULL : &lpriv->vectors[mvec->local_id]; + if (tvec && + !irq_can_move_in_process_context(irq_get_irq_data(vec->irq)) && + __imsic_id_read_clear_pending(tvec->local_id)) { + /* Retrigger temporary vector if it was already in-use */ + if (READ_ONCE(tvec->enable)) { + tlocal =3D per_cpu_ptr(imsic->global.local, tvec->cpu); + writel_relaxed(tvec->local_id, tlocal->msi_va); + } + + mlocal =3D per_cpu_ptr(imsic->global.local, mvec->cpu); + writel_relaxed(mvec->local_id, mlocal->msi_va); + } + + if (__imsic_id_read_clear_pending(vec->local_id)) { mlocal =3D per_cpu_ptr(imsic->global.local, mvec->cpu); writel_relaxed(mvec->local_id, mlocal->msi_va); } =20 WRITE_ONCE(vec->move_next, NULL); - imsic_vector_free(&lpriv->vectors[i]); + imsic_vector_free(vec); } =20 skip: --=20 2.43.0