From nobody Tue Dec 16 14:24:37 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 0EF7D17597 for ; Sun, 9 Feb 2025 04:17:22 +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=1739074644; cv=none; b=n5ZtUVli22TYfVxSpzPzgdDkiS3912Z3SNoIomAEkQs+i52mH8GfOvbYoUzzvX8UOYqZY6Tsws/NObUR7XY4VPMwpDBgbYQ1mclw0zVmGEz5TUKPZ0mcF2rM6Zs4BvY5StflONujl40Gg8r+B/Z3KMRZSSPQTRJPoU19H1I4t7Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074644; c=relaxed/simple; bh=gGGEYK7VGgFWWdh/qLZbuuJY+xZwb2aTgVHnwmrr23c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MX/kmdxdY2P9idjfQOnpCfIvqWoR/MGr3oSBsT2iGpjQw3T42iC53fmOA8I0NdZauhsOKqNXXcw2jWi588byxmPizycK9ZDp7o9OwNqnpXj7y9ixaybpYYGRsX2e96kQvy0Nmy09iU229Vg8WtaFGpkJo1nSO55ZfmWw2jQu1Rk= 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=AzPoVJD+; 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="AzPoVJD+" Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2fa51743d80so819121a91.2 for ; Sat, 08 Feb 2025 20:17:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074642; x=1739679442; 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=DvFsqgBHoepkWBjGC1yP+KOn/8qryanxa+3zb4U83Ao=; b=AzPoVJD+RGzbpA/i/EAv1blZwA0kZ9x/yV6QUjS/UhlN4P8ydtwSfIXKUdedValTT5 e0rpRIKvs9qwp8Ihug5j9oZuyGaqBOH/Rd3FVpUc1EkVcgY4KQcXvrn3InXD24P9gBHO X/yr1X1Sv/o06IQRB0Kop/KgBazDRxnJDu2p6Y1JF7maPboeU+bifeM/nTq03SnQeIpv qKMnLc8I8VdIRHd+RcgpIEvDWVXr2d5NIluAVliuyHJEBArvIwFuJDtMZTLZi0+qh8D6 TWX0MLZXiJz+7OEYmvA24luIol8cnTn46RiV3CKHVUHiiQZBQstIjaTOQslMExZvYJgY HS0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074642; x=1739679442; 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=DvFsqgBHoepkWBjGC1yP+KOn/8qryanxa+3zb4U83Ao=; b=Z4htPsxSN88HMY4W2A6qBJJ4dipDFRG9HKkYZyP4t9FFPhEcHzCydSLrGq8WMnR3OX /m6YhVEWUBTCSWs3JZooq0JWmENVnhOgDf6wdbHVkcRNMlgfdozyylUZkBSgwgqPfma6 SmwNbb0TdTQ7+I5N92ELbTsFyDisrbfKMxNr4mmInTrJ+pPtd1hZ2znjnxuSthoDuZAy S4yd/64CxS8ghurxYG6/E3qb954WLXeVbup6gux41AMaNUkZ9mtQT8EVScfuYcSGD7tV ofr4OUxL75nlLZ7iwkDDo7Yqq3TlZm7fQeOYPssXPOnqAakSYjUWLRU5UDVDXPBvutVn rdUQ== X-Forwarded-Encrypted: i=1; AJvYcCXwHQq9v9hsTDU75k41w4EGSaSafOqpMjFqCciPJ5+x8RIxtulAuQCkYOXXZ8DEdV9COfkJAjMDEDx1f2Y=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9qiyXeu9YQpmz1WIKFDYJmecYBECbNJLDRTcbnlVKq8SLGl/z RRvHM10wV2awvXT0S5a6PyBvNyNmobW3O187b9LpbcZfKAtfX0ggw4g+TLIxz74= X-Gm-Gg: ASbGncvaSOWQTzgmgijHe05qZDgMocay+hiurOkn/u4BhdbqHeg5ZnD9xEP02t+SXbL hehSj0SmBkqzCf3yjhSEVkUIiH952coT6XQZWDXG85hVnEiBXK72indppiuq8m3/9pXJrAr7ovL V6VCZPp5PRLPTXB+wsWAMikimvToQNQ9EkJUc8gL0Z9zL0o1NcoI8cY19SGshq1oBERVfgpJZvO ub+Kc7Z7iHtUTBtlu+SwqOOoPJdwkNmtQakPukBrSR73U2RbQO9PnGjbUSjaQPkDmo6D4llAiyu 8aYKY74v+N5+TQEecfNZDOcM9PUhkB2cPbgGmaLZmnfIYIXtrlmfS5E= X-Google-Smtp-Source: AGHT+IHRXdIPs1mvVVeCpBykzAl+ifFcG5qlvMFYrTkFKgREylWnQV7fAuN/+eShJoWgxmV452gK/Q== X-Received: by 2002:a05:6a00:b41:b0:730:8a0a:9f06 with SMTP id d2e1a72fcca58-7308a0aad32mr287596b3a.16.1739074642169; Sat, 08 Feb 2025 20:17:22 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:17: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 v5 01/11] irqchip/riscv-imsic: Set irq_set_affinity for IMSIC base Date: Sun, 9 Feb 2025 09:46:45 +0530 Message-ID: <20250209041655.331470-2-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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. 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 Tue Dec 16 14:24:37 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 8BA6B17597 for ; Sun, 9 Feb 2025 04:17:31 +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=1739074653; cv=none; b=a1OrPnsQDIaJgWLhAhHcGPzHZ5kDSR55ECP3Qz1dw2UzNCGOLSRdGDZp80dElipINDGIt5BUSaymPkek6jqPY8HHDxs1YghyIFRbVKBK6v2jPdz82oNVW1zcPVVd1ja/92aJbv0+Ew0sXYfCjSJ5hYre9Tv9d8IfAK4zQKFi5rA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074653; c=relaxed/simple; bh=GQ6h6qnifBeRvwI5lbrzx5DePz9FG/7AwYjLLcTRLyo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oDYln+R6ij5XL5CKj7MDJtqSHE0+bjJDLeK3iNIYH3aj5b96D0pyBfKsVq03gK8WSZDdxBjQimvesYSgzMP6HFpblMzcSXj0hVNT0ZIof5f5o9kT0SvtLVPmEumG5+B9YTh5KWk51VrOtiTZkGVSEHTl69oGs7EObn2JZ++s2xo= 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=cNYua6yx; 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="cNYua6yx" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-2fa48404207so1577797a91.1 for ; Sat, 08 Feb 2025 20:17:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074651; x=1739679451; 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=cNYua6yx1cNF4qlqTD2M0aoJhVNrKcnt8T1PTqTZW5Kzmg5SyMLj/p0l2y5Jaog8tR qx6NXITYm5Ro9Fv2OmQBcCLwq9IGsG+g7oKN1jikqNqrNMzpNyUMJ1iTnd3Ys2YaaQb5 lSdKfRwsHwRqvypmOC/AlV3+kkEwYDSTvLIAPz9Jm4DrJbDvgd7yZ3M4QwY3qk4XqyNw padXsj4lkByZjG9c0E3r9BDDGTNTy9rOBK0diOABB6bRRvPaOYwH2ZiKlUmUeCvcr8wx cIfSKY3vBvtPZdBPCLAVCMrXHzlRqUh63WrwzlLCH2WG1s75kGte854wVsNzQsfvxWBe ZheA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074651; x=1739679451; 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=wL3Gy3pZwCY0eRbDwnNCu3Y3jPROOP3LPlAnbjnsc7hr3rMyUXWRWDFEhXRTshs8i3 Lr2lNpe6pO0UjkSC+brPlFxBf8npjCSpoFYcm1FBM8cr7xa1tXPeeg7quDELrMB56jqQ 88S/+rsLGAPuAV4EKgqK6jgaFxr3bStSRr5Yd4nSqcAEIMiBf50XVVKEk6W1fqMyc+6a xPxB8H5Jes8Np1tLlbbl4VdepXxx26kC/prFqTMw4Ook6hCTWe3Gfl6CSgATYxufSEkI FyQgI6LEZ7JbGoXchv6kqImXQEMB7yjYTZ2VwzU0kyO2/wDA0mpqI7tjXPBOV96dnwiW Zn7Q== X-Forwarded-Encrypted: i=1; AJvYcCVA7pR7gxGFkz8ecT25JejpR1CRlIcFTISoe6dNhxoH3cTz+5wxp0lcSU89qTtdR/CNncnL2GFHEWHNHJg=@vger.kernel.org X-Gm-Message-State: AOJu0Yzipu7J1FAwXKmH2LhHWnc0hlpoMizjErdqH06YgRy5Hk54Zlj4 6kdnVjBNMObgnydoVQjM+oB8YT2gQTy6bwTcsLhgkdBgNgbCbABarnibfKPsVA8= X-Gm-Gg: ASbGnctlrmZ1g/9ql6zvR55bU+6U3PhHKm4ex8hCsZ5VNMy6J2mz2gyEjxnc0HIBvL9 ruRsTc9WT741rfomlElDlcH/upgESFuzh8CwAluK5bZXlDp+tcWAudjvG8YNIeQMHOSF7PlfUXq mfR/uyLddzfq5CEDEh3HNxPZsFNsygjWOqrB0unNBFHuhdsgisQ6yx5qfc7ssejQ8FTY+x35grg KJrx0oJBrQJvbrI1m4d87e/I+I9yog7ECUqceMc2ArSs8CreYfdrhWALCkgA4o2/rlbr9HyEIMX /EAeBBjRRiG65jaNvKgEyQ/cH+Kextp90MPIlIIWKTVPPAwhZZmW9sw= X-Google-Smtp-Source: AGHT+IG1pX64iVcHBvRjhghD+pT2OaoFkAmw6b8bnet5SDDEvBV2yIiEcMLZqESX2yxzwT//jElybA== X-Received: by 2002:a05:6a00:cd1:b0:725:e444:2505 with SMTP id d2e1a72fcca58-7305d431970mr12792467b3a.4.1739074650717; Sat, 08 Feb 2025 20:17:30 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:17:30 -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 v5 02/11] irqchip/irq-msi-lib: Optionally set default irq_eoi/irq_ack Date: Sun, 9 Feb 2025 09:46:46 +0530 Message-ID: <20250209041655.331470-3-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 Tue Dec 16 14:24:37 2025 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 090E470807 for ; Sun, 9 Feb 2025 04:17:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074661; cv=none; b=ANNEjce1X7mhtCrnOMbW3loNVvVQQ7tvaPUqVwbi5ShjN9DC2VdPTjI4sAEZXIqFyw3DxWQZ0CpPtElERPlkv/N8VYI/K8uCdNFpMNOiww1Zn8WYQm90TixYiUDqlT4Tx85gHWb+rZJKt0xpzstWDgx5IMaJ+k6IDGioRY607oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074661; c=relaxed/simple; bh=tqqED4GgT6fv8GxxWX7wObYflu49BH84mKUSrCVBeKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cn8Q8CncMzTYoJX/TWh7CT3w5KkPqRp1onLZC56pAET/Rqrefbi7mQTExunGZJMReK6Q9WW+MiEDkhmR2GNdd3mzvV6GFX+S+VG/T6YXksMJq/ZUo9D9O0G2ACjLra6kEjokaWEOcAw7QBEZTCDa+aAc6WGPZPwPVILkqPLcgGw= 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=OFQF9Frn; arc=none smtp.client-ip=209.85.214.172 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="OFQF9Frn" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-21f3c119fe6so71873595ad.0 for ; Sat, 08 Feb 2025 20:17:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074659; x=1739679459; 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=byPW6bNJR29pmHM6qNzPiiUHTFPpVNBWTNf2HlLXfG4=; b=OFQF9FrnuuubH7cNWm2YAZmgH0/G/ZHAj/BUiFFKxJXMYHNJrp+EJ4ivRwwjYIHeME Xk1SZMc/sbmxnLLBH5m67mfk0pRAhURiPAryuQdU7QJZwSoL9r0+obb1/HktQGA3QqUI 5iGftZO8kI8DL+MLF3F9PbOsmCxadvgqdIHOg225UX70u+Xa+isuEBm1PLL6TZCWMZUC l7myVY5Eue4bIkJFj8A5hLGqXyjhWg/quzqZzwjudk2RmK5Y3By6HruSAGd4JsMKJ9Bf f7Lv+Ij5LsZeLZxDi5e73ut9SlyVpn3qiQWBqxnjAshaZKqOalpxmgMfhoi4z8UhUm+u ImgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074659; x=1739679459; 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=byPW6bNJR29pmHM6qNzPiiUHTFPpVNBWTNf2HlLXfG4=; b=EgduV6N59/zO/zb2N9W5PX9D7yx/k78SUSSida/7adJZEj9CR69uLZALPZEIUdbbLw qzw/tEvTLv1jXaafUv8uSig4CW2WoYJMXrH/cBbZMzy4U0z8fXg+lynM1twFfK7ZVCDI PUvPeb43I1PTRvhuIRCbThYi9A6OZXgbLGf6z0X5fr5MuzC9LuVfPGL9z02WRif7oxvK Z8deX58/PnLXPZa6S1iZp4zJZVnuLCm/AJAM5E8jQk8SDbzsjdVCo8jeFIVfeH/KvGN4 ARTK9ZFjsOmAmZIrut20oamBzYdg07jAF4yGwSY70as+FhC4B24QsbNna9ekryycX6EC J2Cw== X-Forwarded-Encrypted: i=1; AJvYcCX4/RR9QSOg7mf7W8DPIJ9zqqOxKlI53V+6f2hsEhO7pRt4TeaKJDZMYbXkdodxNFcbYrfV+8IOXr3clHY=@vger.kernel.org X-Gm-Message-State: AOJu0YygWiLGdtDU5M8apW6SLM2UGJWM/2rL9nF7LOkcvwWvoegx7tx4 6LgaoHm8tRSBe/6IF3wGwOIaCs6RFSgqT2yDOR2wawvhvpOH35rrIfLAZkvIvUg= X-Gm-Gg: ASbGncu8dyqHPCnSjIxMFtsGcVusPGpnrk/D7wHXSSvW+FB5zHUtSHZnFh8Q4ROSPeZ ECNjrOXefA6/W2DsE90XF7S0es57taYF8C4kQ0bh7abi1HEVbVBzGg+CvDwnD3boBcmobkVJP/i ze8ywZvHwZwtDDHqnGB0Hoz4R1qKYweAQ265OL6R/mllGyWsJi/1FfJR1/uNQH9UUQLNzK3J2lh UmPsGK01/868ytzLE4oxhKCk5OQYcsIcF8qR5dbFr0PsAFnFdoBERBkbW56Sm631VXNMkQcizE3 ReSaf+V5m/8rFcgEhv4Pmgtzpmy3kXPtZJd67kUhFj78v/2vJnvVKSU= X-Google-Smtp-Source: AGHT+IH/ik3Ur8iKEEYDe9Hd4WVhXmYUsHE6OOkf8RhOk/pD00c5WvEJC3c0LK+040dao0sK2cXHKQ== X-Received: by 2002:a05:6a20:c6c6:b0:1db:dfc0:d342 with SMTP id adf61e73a8af0-1ee03a247admr16710991637.7.1739074659234; Sat, 08 Feb 2025 20:17:39 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:17:38 -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 v5 03/11] irqchip/riscv-imsic: Move to common MSI lib Date: Sun, 9 Feb 2025 09:46:47 +0530 Message-ID: <20250209041655.331470-4-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 be063bfb50c4..bc3f12af2dc7 100644 --- a/drivers/irqchip/Kconfig +++ b/drivers/irqchip/Kconfig @@ -589,13 +589,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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) (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 BAD21481B1 for ; Sun, 9 Feb 2025 04:17:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074671; cv=none; b=E70hOSMPFpa6ZsFiEuebQgNiliwgPPOHtBE7dP9TUhv8sqW0bApSmn5luapmtVGx1zQgQwoCbwwllhGNhSELEAiyjBiDgKp31q6lBOyT6JQHn/Nh24FenPx2S7nVo6JCBx/kvm1BNHy3vAtujrzhwYJbv4PJldhvrKvL6NNNzn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074671; c=relaxed/simple; bh=yfLmkM6qEAtePtmZAV08Oc3zFbXuNPHytenOkvHgx/Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WQC8Lt7KqnJnVbAehtGcV3eSBfc+VBxvKC9k4uXQ5BhCuZKkJQgoiZxsa9we1VTtyX9MfwRYIIsYrKyFxVAAmVdH08ed/gzoHN6cTpREIkVfqsnQ0y8WXIKfWE7aW2r1AUGEfZAR2IMuhTksWkmS0vwtvcSTRXsYe0jGL4H/BNc= 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=iTbhE/iA; arc=none smtp.client-ip=209.85.216.53 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="iTbhE/iA" Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-2f44353649aso4858879a91.0 for ; Sat, 08 Feb 2025 20:17:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074668; x=1739679468; 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=iTbhE/iAINf0ZQ10g81YUysby9Het7Rn7wv8Ro7jpRue25qJ5SRp16q4SDd/F1MzHY Uco+PmV4knvb6MC5UKnDoi9LTxdQSl86wVjjjfUWzR5VJu/4e33BlgJ8FQP8cEYDq19/ fgRqqoaFK2Zss3yeQBUx7xjcSSH9zSN1zTzP2JSPpxBnMknX+QUMrrtTMjl4VXtflPPA q8y6KQ69ar0jkD3jn9wIIadtyojSgbezMKkiKEHkmUeDqQpbVZyvN8hZB3proFzN0kcD 5MFhy3fql5N3Y4rgCzQe190BeCGM3WP/QSNpmZiT3EVreWAqyX2AOF9p+2Lc6tue8lfM wcXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074668; x=1739679468; 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=ueWzoAR9qHAst0uzwYn8qexfCnq8WFcavjo4kYi/rg2cxkssJhkn1FbttsGjeo3DGE jE4CyLaIx8cX6zDdp9M/25o5GsVTT0YG6m+Vn3uacBqkngN8ivf7z546TSWtJwSPow2i WVa9HXD9Ksip3F/0zkuH3nBYfIbIvAa2Ogh3DqWIHxdSArwYRCQm9ODCvAN5PI8IGYOB VbokMTe8zN2MEeNGYOWsnQd2EfCuIL6Jd2JetoX25pMdOTNxqfUInwz6hbkb57Hs9Z9A lQeAtqvzblZ+0OYJEmZCavoRRy16U/NNd7DnBlxaTMGXgKbLvUhZyF9ooaWOD97ojSSP +9rQ== X-Forwarded-Encrypted: i=1; AJvYcCXDNULsUiGPy1cjB1WmJOD4DApQxLtYJ445uv8t54/GMI+xNE1PC+hv6XlRKg9fyaPsollZaTmGeL6PQgM=@vger.kernel.org X-Gm-Message-State: AOJu0YwTZ1slhfE0NsgqDxrMyrExdrw39xXy7CfEyywaArPWyx6zNsXd h/y8hZq8H8CS011N41yL3AWmxYxCKQlVYI3CR5WvvTiZipDIq1x91NaE6Px41TM= X-Gm-Gg: ASbGncsq4Er2D30olWshCn4VSvwIFX7uQB/T/wfLeeq9cgcZ4awwlQv1sL/oClDzZup a7lm9QKKBOX/m6QMaKAxUQAkn7B8pXQdC1Vsu1LiYMWtXiepTvBRnneRrJMrY93fWltPfTrTG7H AtMz5fUlef3UM6UdxZ8YQVnSKwt/44j3Yd3rnLiB+xgOGbleCdRuSPz9NnpaNXmDgqq6N37P6Tv 6sPq1Eyy//QvepYrZuNohRHWskARqDpRhtZ+9jmFlHrZdYN9i8j2MAdA4Uj+Bi74amBj/8U2T+B kxwbc7C2sm+k/izcnoo1VNJRJBI3E7HTYePZN+VI7k/y613vQFxx0AI= X-Google-Smtp-Source: AGHT+IEZWcVRxpCJ2TdbHZSmXzLBoI3AvA6fXMBlEU2Ke4FpcCw0vGqhdEDkzoqwQdAILQxJgujX8g== X-Received: by 2002:a05:6a00:c86:b0:725:456e:76e with SMTP id d2e1a72fcca58-7305d44a459mr14381121b3a.6.1739074667815; Sat, 08 Feb 2025 20:17:47 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:17:47 -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 v5 04/11] genirq: Introduce common irq_force_complete_move() implementation Date: Sun, 9 Feb 2025 09:46:48 +0530 Message-ID: <20250209041655.331470-5-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 337046A8D2 for ; Sun, 9 Feb 2025 04:17:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074678; cv=none; b=H3uadDXoDeymCEaXzyVDwIVSK2ebtndUh7GvkLToSi7w8mMSZKgRlVWGs4eMSY5/jX+snYaQTxR+jds8ZTZAgGk6d26nTT6c1UgT01OJeVaAgU7p4hqwYrIDx1q7heCC6HBLkACVmRPvo3bvd5d42cMLqy68Rfd7XrIkMSLIkJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074678; c=relaxed/simple; bh=PxpxF0dUlwKn44FGhlpT2SXXiblCpU8cCNLnLI9M4ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TgPg2hWG7plYOBRKegYoMgr3jfvkBL0mMGuDQC3OFh7pmhbMQM/ePBMlBKB8RUmxxwduwrptnO1fwsC6UjDdLeRc+3o90NumSf3C47uSyw7YCpe6ByQBKOuFwY9wZQpNM31Pw/r4gGHxe1+7i9ochh6pNElHvVopLRZR7EYH0II= 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=n5NVt22O; arc=none smtp.client-ip=209.85.216.48 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="n5NVt22O" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2f9ba87f5d4so4708500a91.3 for ; Sat, 08 Feb 2025 20:17:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074676; x=1739679476; 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=n5NVt22O7pTMiV2ZjJ1czreJR4z81gV8mCjG9XyP6EeZjIQZt0bjrquZ1/fbrF5EU/ m4j1pueOk48urnuOdkCFdLMYgKvyvV4GzjSQOKx0INU16JBIlo4pFlmW265YZCH1tuYb cmEwBz0K8NMDFrGpv6U/EiDCQu7DYlcqgGzhKTBcjERtZYZAARV4WCwZLCS490ech8k9 fN76pzTnrPAJfHojqAgja7/WdnITyZglLpWQoDwp9UM7IVJF3g3pfX/Kb5yUoyIgKxCL KZ4mHHfqKY8ugNcU1JP2r5Ka4nLq2n8iehkQWofYz2dp/pTsMH+gDtx1iPv0G2ut1F9n UiTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074676; x=1739679476; 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=kuwit91B8SXl+HMctM4JdypQbrnIeY+S2ROzrK7yoVSg+EcqU9EALaiXsl579sfX3/ rLLLE9C6jHKOX6oyfimuQ5nUswLB1EvT6/AIw5ykLSifRm5UAG7KYcnJcCKhuSKre7UP Kp+jAKbs3dDkuT2vH8UoHIucoj1XmMby04csVu6fYAJBQ+gM2kkFU7VhwmuZdNkjAW5n TgI1d48Kpr0WdQRP/N6SM/7gcN00yhTD7yYfbaQ9jLWsrjcZQnP8kAMz8RL0NK5HaHJ9 Z229vZWep7No1EpcdMb0u3mwbJ+D6DdLnUhQfB24G5rUw3eORV0g1ho8UITxMZu09oka HEHw== X-Forwarded-Encrypted: i=1; AJvYcCU6a5I3XW30eADXwfO+iwS09eNmHAhcasFKrG0ey1jWbRgYc8Z+i5pgV0wQD/OCqez47ctQUclPfwkqRXM=@vger.kernel.org X-Gm-Message-State: AOJu0YxcETWM8F767pbnTwB+0sk8iiBYDPAji29KsFXd/8BMTKJqnDGb YHp+fVp9GfFmOUWW4hkuk5aOR0nzk+Tbm3NICOUNL0JajPeTsVGOFnwSrRWCBrE= X-Gm-Gg: ASbGncvCmOW7iLrZMADaGMzpVdlUhJiq0TUdDWKFKtUqF6Hu3zHz7tC4Kj+htgFXYUu 1KbQ6YuldEZ81TBLEMVXX872JESlFR6eq6szImno4N4a/qHYIDxa6/XdN7XCcXPF7zfNbdlPOfj rNIDJR5WKkqsgei4NXCABgT3e16zYl6FR77iDIJ0l3LFJoki/joXdESm025Bi6TkLn7a0e6VphG Zeeaxtoi3tzFGlyMueuPcusp1GC7+rp7dnxyGqPbYGKIRP32cRUOc/wcTHva/ytNt/9OMMtB+jn 5f52IsaCq99gtiExEFRK7QCJXF7S6Kg9nfuMHwrghON/m8I3B/SSVNo= X-Google-Smtp-Source: AGHT+IHDq8j70VgdWYD0/5rZSoa9FGuz2H9SOfW3ipfEG4foQkrNVKZyKea9+xF989Gz8oAitxsVGw== X-Received: by 2002:a05:6a00:a15:b0:727:d55e:4be3 with SMTP id d2e1a72fcca58-7305d463732mr13313591b3a.7.1739074676324; Sat, 08 Feb 2025 20:17:56 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:17:55 -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 v5 05/11] genirq: Introduce irq_can_move_in_process_context() Date: Sun, 9 Feb 2025 09:46:49 +0530 Message-ID: <20250209041655.331470-6-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (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 9B0871F95E for ; Sun, 9 Feb 2025 04:18:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074687; cv=none; b=RqQnyP8L4mClTrRIejTMoQRoch0eHZJYe87W4mzrxi4GUOuKpGN6iPKX/0rlaQrNgMt5r1DqKgsT+ZDe0apJmZLxbXwaRQVpS+AcKpAGguNF8j1tVpi8mVL1vJBr6vtmu7lHH+7zjO/KYQ1+MgVfk9iRqtQUZb8UFGAZ/S0/0eU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074687; c=relaxed/simple; bh=rPuSUodznHcDcnkXovmaVlnFXIC34eH0em4djJco3jU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OG5wD8CrAs/Xh874cYByIFumjywX5dmHuVPKOo67Vpt6ih0EP1LWiuBFeWahr8uO7emry2uPk+G//8eblUB63aJXQ81p29cXCAfmcSvKF0cdSpqQMDKZHbj1HNXaUUVP/c3cAEKMxV0IJcZ75RFyoSmQvhIT01grQ8YBmFo2C34= 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=QCEajN/Q; arc=none smtp.client-ip=209.85.216.44 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="QCEajN/Q" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2fa1d9fb990so4654473a91.2 for ; Sat, 08 Feb 2025 20:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074685; x=1739679485; 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=+su7Pdf8Wu86Zcml4faTN2UwZ+oipeVYumq+PsYwErw=; b=QCEajN/Q6ofboe3F3JBCO7cxSKQUNh/HtMikyj8w0gXa2lSU2xymFNt83bbWeP3yWr nkeWeUkf88aiXJIoNk7jJ6LvySA8qDbc0YilRUOfXRW+7c0KnlysMec32888oiVQpxUm 0lz6kZkfbzHrsOX9kHjvc7W5mgG+zqJfk18dn/40e13toYIy5wEWiXh+XXeSans0dB2w SVKRkxHwsbHV8d1apmJwZTnm5jk7F5Dj+vZNPmjN4bEsLZo6xeQiuRd7sSedqXh6p/6j b2EbppodKEpiIxOiotvAZrkXby0slpNDP3UvoDkQaut34aT9sVg1R80+yTV0eFXMPgXI HYpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074685; x=1739679485; 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=+su7Pdf8Wu86Zcml4faTN2UwZ+oipeVYumq+PsYwErw=; b=koOU9EQTRcbfftxgs/n1MUItxreFejiTxBVeFQFdqVnWOtGgwNy42/guGBq0ZkeI3A Qljhl9pOloU6+IIJ0o/madQm/wRivh8zNY07N7kxiN7Cswh+NDJey6id1A03HqUnvEZE otWUz/5XVfifyUoLbbJe3YQA2K+JGnDix/Q/XGiv6rvvgw1ZF+TEBivbVuG6hZP4GYH3 JGXoKrJb+R/A4LUJncyhliIX0eastMfRzeI2srANVVIRzkmVdfKc9Cs6uoy/iCtRNa8g 4C4KR6Y1uKR/txfhi7J9VKK1LJ/RxPFShg4+X+O6VDNhwSTLb3bjCphsoQ97ZyfVhseX X5QA== X-Forwarded-Encrypted: i=1; AJvYcCXELdNT5MaQrpFsLjVd4S8i0RKr3On3RL6pXrjROXSNt0FbdDy0e+BxXyfMl00spFFhpD9AwX+GL/wpxXE=@vger.kernel.org X-Gm-Message-State: AOJu0YwsEI4qetSsaKhWtlY3FOP5dOd04dFIWsWuSxtJXZkr94ARS2BY VKojCOdi66OMLFYuGVykYoY5SMo8SooObD8wCNSEp3Q9TT2osdBmEvbRz9Um/JU= X-Gm-Gg: ASbGncsJO2ogxy/PJS8E41FAqOdlNwSokhFfV/U+Ba4td2R5h7y/0uzbiH2tlAwpdbm l/bMlFx8Xd9GukRJAhgzdE1m7qvVNghMogLbf/58RFfNDdhL5q2xfgd1lJkKoWsA51FmJ+CtO4K w2WYGmaVKSI6vanEErHx3bxrubw5ycjZfgEXlzf2Lv/jWeZTGuWZnL/WGtzD4UpTEbbkWwT39pp jXyUpFp1JcRgauw+A2JnKkTGDxwCg8J7v7VQ5GxaPeNPmftNYQBQuVr01OXCoS6QvBOFs8h2WuC lYyROWWp8k+NTNDlbq29n8yTag0mIzq65w/gpq0EM2Fv65Kk5oGA/1E= X-Google-Smtp-Source: AGHT+IHplK1Odn1krUBJui9aJ3bXui5w4fG7ychKlkG3JoJ8qZ1jCX3WfSDt+grELpA1vaZRwG2+1g== X-Received: by 2002:a05:6a00:178c:b0:730:8a5b:6e61 with SMTP id d2e1a72fcca58-7308a5b7c17mr217952b3a.2.1739074684846; Sat, 08 Feb 2025 20:18:04 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18: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 v5 06/11] genirq: Remove unused GENERIC_PENDING_IRQ_CHIPFLAGS kconfig option Date: Sun, 9 Feb 2025 09:46:50 +0530 Message-ID: <20250209041655.331470-7-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 GENERIC_PENDING_IRQ_CHIPFLAGS kconfig option is no used anywhere hence remove it. Fixes: f94a18249b7f ("genirq: Remove IRQ_MOVE_PCNTXT and related code") Signed-off-by: Anup Patel --- kernel/irq/Kconfig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/kernel/irq/Kconfig b/kernel/irq/Kconfig index 5432418c0fea..875f25ed6f71 100644 --- a/kernel/irq/Kconfig +++ b/kernel/irq/Kconfig @@ -31,10 +31,6 @@ config GENERIC_IRQ_EFFECTIVE_AFF_MASK config GENERIC_PENDING_IRQ bool =20 -# Deduce delayed migration from top-level interrupt chip flags -config GENERIC_PENDING_IRQ_CHIPFLAGS - bool - # Support for generic irq migrating off cpu before the cpu is offline. config GENERIC_IRQ_MIGRATION bool --=20 2.43.0 From nobody Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 2E18B18E25 for ; Sun, 9 Feb 2025 04:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074696; cv=none; b=AVj2nqZCTmn+wLQ9hoRkn6/zQu4AeH4VO7Wi5NqCslusRAGkYnOkJf3CnFLFHM/aUpsyBmY96AyLezWmiDXsGB+petz9sRQ3ClKycKQJ0d4NkVjqoLrJH0tlNoV6dP6q1UqlxP1P5KaGoXODRZaSTqMXNpqeDwsSLQ8oMFI6jxI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074696; c=relaxed/simple; bh=n4slH+wgDA6MSJsnkDzYIOL0zzUU8vlxw6wGI5nPdQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B7aqAk87qVAl0QWTDqC6MvFyYveHcIk9Pz2vPLDSFBrKJLr+uKeZZ9vaZjflZXlihRV/vhgOWSlc4fTiV6QzPv5q7JEg2DzmBTNxElnfoQqaDfgJoyopKUBuA6q8XIyRAgLMzdjmM5jpJ5vbbYuBy5H9twe6Kw3hOggd1Tv2NKg= 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=nmps9gQI; arc=none smtp.client-ip=209.85.216.51 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="nmps9gQI" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2fa5af6d743so698481a91.3 for ; Sat, 08 Feb 2025 20:18:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074695; x=1739679495; 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=nmps9gQIWNGYBJI5jrtalJfokIr+Qso5sQqHEuhLytkKOdZKCsEuUUoAYjhY62z2q7 FBkCmulmeyCCZviBZIeb5rh6t2LdjEJGIXkY7toSrBE9pBZlz3G8pTJjwwNNEads2v+w 8U0/RJOdVs70zu4j4aUJf+zzl0d7p4byE4PXLupM1Ij+QD2Xj3/dTHOPkql/Q8NR2sNv m6d3NVj0HnZs8H4yV1E18lt38enIhuzQQEunyxK9bly+oBNHIUWsmGP9Rvk15vkE9QxN iM2dAhoTR2fMgWp0xR8xznCHpfBLSE11VhYv+pNgR01eg0dLJamlVmpoEV+iV9hqhwmo aCuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074695; x=1739679495; 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=bbSW2Mc/fLNvTsNGEjb9geg6xgsrehjMV0P5oMQQfCHaRgXlDx4wyovP6q17mvs3gk cbufcna741ul4EcfdpR5yfYLfJXBIHQJnhz5P17TyeXSC698wgXPSj4Y/d+C3a/dx2ji p71lAv0010FfdiZKTeZl/EQP2GlTXaOSlufrNuGEWEhpBo6qdZ31g31HZZk8MAkGOndG 0S38F7O6It7GDnKz3UnKOkS37tK5gjKFflm//DU++NlW4LuFOmY3zQzcTPyU3mpnEbXN iyG+dfPvpLpcHmf+jl4LWpBBD4pBS5PFC8F5p/Gf22CT3bB+9uHILBRDl++sJO0Et0OA 4fgQ== X-Forwarded-Encrypted: i=1; AJvYcCVtcJIJxSw0PHtHP0v1pSscKDjREDtFa6xkQZh0Ar+dYD8SZYdy+8Q/nnNpuRGGAqOAZM4BbzHXW/+ezu0=@vger.kernel.org X-Gm-Message-State: AOJu0Yxch27zddCoWQJ97UMCTvfLkEZCyam5jE20ZfYojfWU6Qj8Qlua pOQQ+fNWKhe6TrO0JK1UBZSCwSk1TCcvIqyjAkLNNRbhLefoTDovlbIA478J+Eg= X-Gm-Gg: ASbGncvaUenXQAMVmUmHVpK4ZVZetckErgBnnefiyiO22VkLOApmNxG/j+aQjBuJPq8 AxLYgpXs+APqgWniGqQODL0FyncrbfVvWbvlLzy9GHjPWqMcUJtXUL7Y2wWZoC74A8xZrK821X0 ne7A0Gw//zMLsyfwlQUio7MaGMiayChJZ14V2SNOu4o326j0oB+4W4FR4mDAGnaQ/4mp2NB6yGE K47JtMazX3T7r2bpVyXQHi22HkI/3FakJgIrSTKJ3hmajqrdpJDdNBojAIaQUHMDWNTd5xW604o vdDBtQSdwIGbfLD+Cl4tooxX7s+x/sTw43QeZV4UGrTY8bT+ZZgPPa8= X-Google-Smtp-Source: AGHT+IHL0ZAy+b2/HWpMWPKyLFtjwNwqGOrHhxJ1k6glfU7lfaN1/yKHZr4v/qmnwtb+wj+/nQhb2w== X-Received: by 2002:a05:6a00:2289:b0:725:460e:6bc0 with SMTP id d2e1a72fcca58-7305d2ac0admr15896176b3a.0.1739074694598; Sat, 08 Feb 2025 20:18:14 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18:14 -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 v5 07/11] RISC-V: Select GENERIC_PENDING_IRQ Date: Sun, 9 Feb 2025 09:46:51 +0530 Message-ID: <20250209041655.331470-8-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f43.google.com (mail-pj1-f43.google.com [209.85.216.43]) (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 0264D38F91 for ; Sun, 9 Feb 2025 04:18:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074705; cv=none; b=nRdX+l1c1FlEY0HIhfNPRMqG+LR4Kr66ikcNSPWa7n/Cd44TeI3FN1ME4nN2l8ylqHQ2RVuU0qpRZus+ZZp4znF6Ad3HcW6+KCDS10EmyY1syGdIfuCuXFKPA1iEsr0mJRtjBabMuprMWWtVbLucU1S61LIq28YXgUCwum4OUWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074705; c=relaxed/simple; bh=/aguk4ZYg6WQI6RlClB+Z+ge32iMkXIXY6eYPLNpAn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qv6unWAY1KoEh6Fvb/MWzhlfXbWFb1rni7UWJN/vmojzInmCZb+GR7eo5Kzpql7slgof2fhmGoFScaacxulltCBFNDEaYYDDpof3xf7bpQMIyYf0wO+i2N2i9FgqohNXjD1s7cQkVjlGH30L+PZSsSjoEB8sXsyvMjsomDr2Ajg= 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=POHjq9fK; arc=none smtp.client-ip=209.85.216.43 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="POHjq9fK" Received: by mail-pj1-f43.google.com with SMTP id 98e67ed59e1d1-2fa2c1ab145so3276108a91.3 for ; Sat, 08 Feb 2025 20:18:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074703; x=1739679503; 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=li309BKFytEFNs0s+UiLLaDTQ3aEtuOmqKESJ/Lkwhg=; b=POHjq9fKo8NiN4JECMIL+N+WfJogJ5PLaEc/11vcOxmtM7n/SYmWbzDXLxZrQ99cGe Xv8NkaeFSc29ig2R55+pyVTqf2VBSArdWWbuhM3UcAX/MOOiFc6ATVdJqtJlwPSZl2eA RV0WbUss7ApmgBsdJk8SJWInyeiUyo/qOKAAqcXZ5dm2whVTesyFsGXDyyFOX7BvRMN2 QYtoLdKtPtRJE4Qa+TNyaukyvkux3K8Zx0a9RqpxMaw7xIYn4aoooe5VdugQourDSbs9 e9JoaAuhxlUYJUy9eKTBpir72/9Y9fKZNGkeK224B0vQtkPa5jbGcUqo8DGmeFIWjLYE O0ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074703; x=1739679503; 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=li309BKFytEFNs0s+UiLLaDTQ3aEtuOmqKESJ/Lkwhg=; b=ZhbN5dCfVkRlWdlbaykPAsQUnC9kMf+/oQEKB8kY7G5+Fjdy9BSmgrUVcQwQmN3/zj FP9svpryB0zs6Q/6ogF+4t2VA9v+ZC71dktQbrwWgYwMFWu8H4zVmMeKfWdqS+SuKi+E FCX6qajPQWnB+bKhQ/IB8t75k0ahpVEj5xWw48EnzgUsJc11hvlf3Cpku/2Nq5LZS9fu zdoAbvmdZAuz9HxNMFa+gT48KqVW9IinXOgQN6X5zh74HGvR4uo/eveQGBYDkcbX2hIo SOGqyMIRlPLhGCnqgvPpAxuoYPhKUF63yo4DxE+PivvYo6Gw373N7t4IePrElTDjY/+l D4Og== X-Forwarded-Encrypted: i=1; AJvYcCWN3ZLPlb7wmmCJKti0hCJ7fBDIgsGSAOWD6f+W363w3oN21FrLomgBoPjNLDQzgd/qux/Tt8Vnv8/+KLU=@vger.kernel.org X-Gm-Message-State: AOJu0YwWF1JrVxARIPrgyM3Q+9b6kFcwzJ7irded4hgwrhrxf3LHDd0X GWSuVUkcKVgBT5i6/Wm3/2DiWNhhz/vSKAKmLjwftJgv3KIRAy8nSn7N4YE/fH8= X-Gm-Gg: ASbGncuwAhmeM0j6/jIXzWg/Tl2tMNQTvs8lrHO6xOB1gOOKobu65eXqUqeQ7PSPDc9 /FRV9+jhqgD6XzksxUW1dFPXRdnuz2GlF2qSWKe7slD82Y0jjZQeBYlKiC8I9XtN2GBFsIC3Y5K yRr7Va5NaCJ0sV6/VDq1586nx5UTKJVGWsW0zl0/wHzKhetbi8y9amzOdzc/k1aFRqeYCUTsMua Q/n98V4zLghM6CVnsp7yda4oW6qkznu+8FKB33/FV5Lry59DCwDauszTaR+zXPULVGXggiHXGs8 6WUunfqXQiIbu9wSFPynD1U1ej9KJterECR1rZKJWGk259PJv1BSH1A= X-Google-Smtp-Source: AGHT+IGr8DIP/za6PXLubagaC8HrCh4Chcf3SqtLF6bJLforSFiwf8+xl00IhhTWFSgMBoJHAPJZQw== X-Received: by 2002:a05:6a20:6f91:b0:1dc:2365:4d7d with SMTP id adf61e73a8af0-1ee03a4744fmr14841962637.16.1739074703102; Sat, 08 Feb 2025 20:18:23 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.18.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18:22 -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 v5 08/11] irqchip/riscv-imsic: Separate next and previous pointers in IMSIC vector Date: Sun, 9 Feb 2025 09:46:52 +0530 Message-ID: <20250209041655.331470-9-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 c5c2e6929a2f..b5def6268936 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 Tue Dec 16 14:24:37 2025 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 539F154764 for ; Sun, 9 Feb 2025 04:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074713; cv=none; b=pIasuBb0D5InHcOlchIJPjB3QBIMG08E15Pxx3wmDhf5GIn4AW5DLpRML5L0tJJBfQGx/Arnr2L6aV5DD/dOF5pgZ7PC/K6W2aZacSKbcVNw1SsCynf/lvBLLcMOii27xflqmM/G4TacAP1lIxJLMkKCggevIxakTGtld3X//wM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074713; c=relaxed/simple; bh=mFFEh8+hZeEVXl9Ut+Oj3ibjoUtqS7w8eehuqLHhRt0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GSVE6KnP9fgCE6ti33w3CbA96IrTCjO8bahxOVsBhsmcJrtk8JrcMIgy5N65pJI9uPsrq3fP1/byE82I+LEWmZsbs9+DzJqIkj0FQ6Iv8KlksvtA4BXJAG8wS+otoEKujKqYRJIBjuOOzMNIwEYRFaMLs4cHUU+2+r63sAPb0MY= 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=c9CQGNxJ; arc=none smtp.client-ip=209.85.214.179 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="c9CQGNxJ" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21f74c4e586so10096995ad.0 for ; Sat, 08 Feb 2025 20:18:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074712; x=1739679512; 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=c9CQGNxJ9n/UJ7Js5zE1qreHqKdTS+QUAFhgt7CLUS/9agvl9iVStvHZW4yl+sJtEL xr8/x6RL4ElL/z9CZmzW0FC5gFJ+ZFlfn9fhLUaO3irwz6lByuFJvR831ZpNmB50tXLX rc+RbrDHVkehLakUUpyjchF/BaLwEsDWH61x1xV1wjGHbrDr5n0p3ITcPZsbRIrO/M5u ZdaZEE1EfIdvV7zsWA5PePdCw9SLc4zeLS3YtcJFFD5RXX5WWNkVAEv7MrT5LF0g2e78 J8c18IaubPZ7Zw9Ril5cjF6W0ogku2f+ftYUan1UTb0AgUyVOnf++mHw/sEDI6hkKk/S N+ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074712; x=1739679512; 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=gloxtGOXCi2jFvwLg+lpg5u+iknlusNldJK5oiFsT9aBMHp8IJJDBwDBIGuZXg8EHm y14ztK+ZzIX9ECP4DR0/Rn7iUxLDSNvBgCEYs2TooxlzHSbJqgiXIewDY5N+Bl8Tn3Ir A/sC4AV7371SK4FjVzewMoczIW1Lr0LKz4rm/kKVxDe/uT4KMmav22vlVN8XSzaw2rDN fQ5Y1U3rUB3G0Ag5vDwUswVU+I1JD/oa7j2JwXcHm4uEvkqLY+a25N6in/HPpEF0jJXE qAudWRlV5Awx6G2GuCZS29EQS0NnFPuy4MnrYKCTvw1AvvuVAB+lb+EexCnkjVGJxYlw YEfw== X-Forwarded-Encrypted: i=1; AJvYcCUIbHePWWxdNCZe42kWz0IElYCWbjqspkytx4eAveVDaVGaPuDYyRDpQGyvC0OK/DKt6gS1Bp6goAZYaLg=@vger.kernel.org X-Gm-Message-State: AOJu0YyXy7N4N+lO/nGjTk4y3VFpjc/4cvuMctbgLD4ChWX178hhsOTT vPePcghC0lQ0q4qrYSt7WQndOz15bcPCk0TZkPGQ/VKKi+Q+Ijl3c5Ojh3qw9E4= X-Gm-Gg: ASbGncsBB079st8BCZukiRRme6ZZWPSaETSD7WvTsWyS84sXSz4F5KC18kSP7MuyPPk zcr0YTnQprWj/ATEmOYRBASpYNuhcngYrAecoR7Az1ALfxpEcP60cWeXTOvY7Sw/QwlPXakqKuL T0W/zY91Vjthi2a/YH2+e1IOaQ5dN+Ja5//Lf6sX4frUx4zZnoC1jUnKXbQ367hn0dIRxE7akmz nxz8UedJzwaJ3nVEFMWo750pIQhUekjDQkQKXjAD+N2nsxJNLUWDPqypiXVIzjVT0gFdSMs799z HS44TZISCtJg0pPbrS+tkrxURiX1fNIM98CCdJ/m54s6BT+gpjzcDYE= X-Google-Smtp-Source: AGHT+IGE4yR6cgBkkvQcZ0IHX6BsNq+H8UInEThSWisvqbLPPoF9w9oT5fD4cZTzd5CMtWIib7XuTw== X-Received: by 2002:a05:6300:6f82:b0:1ee:1910:803f with SMTP id adf61e73a8af0-1ee191082f5mr4625773637.42.1739074711624; Sat, 08 Feb 2025 20:18:31 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.18.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18:31 -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 v5 09/11] irqchip/riscv-imsic: Implement irq_force_complete_move() for IMSIC Date: Sun, 9 Feb 2025 09:46:53 +0530 Message-ID: <20250209041655.331470-10-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f41.google.com (mail-pj1-f41.google.com [209.85.216.41]) (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 C8FB054764 for ; Sun, 9 Feb 2025 04:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074722; cv=none; b=e8S007W9l6Tso+UQ8Sh7EU+YYSxRqj0Ceso4NI4yu1u/wdj2UL6r4+3ka1FwwV7UyLtn9XxP1vAIWHSnhM79WvjTFlIZPR7iDP3GamM58GWw7bAwfTqLXHeEj17lr96rXlasbwJQUbmh/L7pIiH4SpieOGdTB8PvnuHy1v/RlTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074722; c=relaxed/simple; bh=lcMa5p2pZjzeghLKvVY9ny71KeZ3wMkdol/DU/InCzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oCEDXQK5BKR5xUujer87ZoTpfVu4igncodbLglUlsy+vszwSJeA/9dGKnWGkqiOoS+RnqM0kqHnRBjq+bgqO5ICfcrbob9viC86pBGigCEJl/9z1Z2EcJ7dZzulw4Q0QUZ7Q7BPqc2mWfHGpNxNz7EiJTAMzRnq7FIDyP6vpbAY= 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=XoKXB2Ux; arc=none smtp.client-ip=209.85.216.41 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="XoKXB2Ux" Received: by mail-pj1-f41.google.com with SMTP id 98e67ed59e1d1-2f9bac7699aso4843974a91.1 for ; Sat, 08 Feb 2025 20:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074720; x=1739679520; 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=2uqH0LlhZdZ1/ZJgerOy14gnMEDsVqG8t0Fz3f/FUy8=; b=XoKXB2UxI3+fhtrdquaZ6sY3SONbnSQu2g4jX8UBoi6AGmr7LuZK726WnVovd3cYV+ GYaRV9WGpA1JCui75xhMP3sKcE1Cy5v3iqgqIVmGnUarVbiePYvJyZltpForJfyhXwYz 5ixJ3LhZSjXJalr8nGJ5SvHZzliLPKlORi3yenGYrtqZbwchLe7Ir4xNHnAWkolfuVpk ypNpHYrdM1uT2bVqJCL+jy3/Sm8sRzRmU+XP9w0ob9vj5SPfrjdV7S4bd/FJnD+GHH3u dKdRYrw6XaLn26DCqOPCU5c22QMr+RqTTtjvpnHRSDeNsFTqTDCxN23AiLsdYpoOoI3/ bPXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074720; x=1739679520; 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=2uqH0LlhZdZ1/ZJgerOy14gnMEDsVqG8t0Fz3f/FUy8=; b=iLeoJc05Td0pNEY28XH931cXMrredES3w0LI0dRg3U3BBlt39SPGXDBKmcdAivsXEH zq8m11F7vK7aJo2Mu79UHnChHtRc2O4bqxmW7w5EZZnBerW5D62x/UjxcCLs6nrhPpvw yHBldaJR5ABxaMAW/pG9aiC503SXQ6GqhcwBGizOfIB7/ZvYXvoDtgkEcj2jX/q1b42v HpGI00SpVqjgBEiMwbnfwbmvCyL9XsEw9/4pjmyB5P0HvjkeCCiszYp7g6rmvzxwfSsp wkJ2dD07nreUaeYWMEs6Jtk1NqWhU+vXBxWOk+Q3Wa8mQnvF1OAayUHO9pDe/y2OfUcv 2EyQ== X-Forwarded-Encrypted: i=1; AJvYcCWZO0nDYj2vBm+dVK8wJN3+d+bMyMfLmAMNwCy1gQHnvD/6SKG6Buy6OaV8looInTizriBwgjlV3h6oxCA=@vger.kernel.org X-Gm-Message-State: AOJu0Yxm/EyCiCoaf2340y0cAHFSJNxvojyrPcALz3ihOM8IoyNlOmck Bre+4+vvDSuM6mtcuaLrJmmr9PADEgfAygwnlBbkBqZXvdSUV7c5qxE1dhcMTKY= X-Gm-Gg: ASbGncv4d/9EjCqIzndXjvXZCYBzBuBr6ATDQNlC3n16Ptnz62BSKOgjUGZXwFw6mqO dZbK2o43iJsabiI6rvjD2rKzzSKjJ0PEvA5NZbyewyNHDzw8Io41W/yS5CHyRAzUgc/SSuVeuq8 nYw3DpiIp4Zis6KYHGyB8STzO7714v/k7CIKOQ9HQ4nKWtIowkcfUWzANOdbAISaUKFL6CTMMHV OQJ0rmCIPYhViqsl0py89E2mmi4cmId4cDnIdw3SVxp1mtlhtudUdoih1ADByb7dmpW1w59C5dj pH8EZQ+LohvYKoiTGegVYSrN94o8n8lIrETBhtm9HneDPiuG2seHtZU= X-Google-Smtp-Source: AGHT+IHUzy54yYs2fS4vJemZHOHOIs8APlSMaPpVV2klzUoQAT+FU5F1TyPBFlToppvPWeQiJJcXfw== X-Received: by 2002:a05:6a00:949a:b0:730:75b1:720a with SMTP id d2e1a72fcca58-73075b1752dmr5977536b3a.23.1739074719968; Sat, 08 Feb 2025 20:18:39 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18:39 -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 v5 10/11] irqchip/riscv-imsic: Replace hwirq with irq in the IMSIC vector Date: Sun, 9 Feb 2025 09:46:54 +0530 Message-ID: <20250209041655.331470-11-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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 b5def6268936..d2e8ed70d396 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 Tue Dec 16 14:24:37 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 8B91D3987D for ; Sun, 9 Feb 2025 04:18:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074731; cv=none; b=h7r56xAPcX/V5To0P+InP5WnxUWh74edZLkUPKypQJvU4OKS9P0/12zG3wuGNUV9Kw/4uiVJgv0E6oKcDpZSp+Lhwh/ne6zi/RJQSynRpFLyza7DC+JaHbCMPtdhcvWimnrt36tubxIqF1okuz/hKg4fnDfNx7ETGTMpWr6PL9Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739074731; c=relaxed/simple; bh=tNahCfxLRgNIbiBla43nJrTI1GFGdO1edGYaRhyK8s8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rvmN6e80n9ZzRmQ4Tr5XVb9sE1lUazlyg+adsQFGGQ0QFF9MfSyPtWdbMH7Q5b2qiqhBR0G5uASQmlPqRFmVgszXBtuaxAKFd5O7k3AVdFPRB7c1L4K6Up529E84GQN2VaTHYwH2OBy0dfzCOZILML5y6vp9hKw1oGZyqMGQvJY= 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=a+d3PcTv; arc=none smtp.client-ip=209.85.216.51 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="a+d3PcTv" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-2fa1a3c88c5so3873445a91.3 for ; Sat, 08 Feb 2025 20:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1739074729; x=1739679529; 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=a+d3PcTvxzk1fU4EKT4MlLpKsFTYmfPANlZstWtetx9gW+5wpbP7lW6SURUC4UFdd0 yyKigL9c+6E8PSIhayAqq/yYSN3HlHq7sURVEXNRjYwnYMtb/hk52Iopj7amOWz4+/UE KYQG4jDb0i1640skrsaVL4hIIpP/Q+2netgJRgG9skpSciJCGEFSLz/YGI6klByLjJKe jcoOjiDR5uRez03okjmOzkqieB0TtMMz70p40+czAjs5FK+SQAoFZCu5rOFkq+OK5T+c khARR1TpcpAsIzluWflGEY9BwkOfJG1XQyuGpBOIqBSa5mmGEnjeNhHVk3/h+esanINc 6hzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739074729; x=1739679529; 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=cpiA6FsnMAjTuIAR8tErxNS+AOONkrIVpX0L2q073Y/Eq0jfaiDmdLpoKYT7icxZxK ag3TGtc8qzka8h2OPSwYXkQckIBZaetErGk94D2Uw48cWVl0btUjvt8BYvIeE99uxToc UaeeTHdgY4o4spaqOXZKLwgY0mO6dRurMHv4ZE6EZ6vx58FpAyOiUpqjoHzRb81vp/hn yg4g5qetkSVYaya3CWBajIJsjNKqU3+Kum/fp75eJxHe452fIF7sw++q9Gkmq+rAoIz2 gnK1LgSbGuU4Fa9sMA/rTqZdOB4Lzur1DcghyLCYWU5YiqMQhpQkWp2eV0G9MnbUOMee MakA== X-Forwarded-Encrypted: i=1; AJvYcCVKMFKE2N1ogACVYesKFeXjcMuO6DW/jKoNLQ2OGL/7OL4SeEeXDY7y/M/l9+4Md384fFY375HK+mq37G0=@vger.kernel.org X-Gm-Message-State: AOJu0Yw8hDaNVLuM4jgt+/0A1Co27+UzDkiT7hVMMF3rJtQ/mpK0bDn1 GK08ohHDEnJwneV/AMDLDvJqNGS6JL9Ts2acSHzgFtqVkDImy5Hzlph/yVYuXrM= X-Gm-Gg: ASbGnctZQOntXvmfNyn5Y9eT1O3ZsxDI7keA33ei/0BXbNaIkcqI1wwWLPxCqxyLJ/r tCP1IAfQUwh78NdLyHnWGXgeNONPXSJlq17e/22opVb/QzCu4uq68sTK5OC+pluMEaGnTArCrzn xoPk4DJHHh6v7N9CwF8DZn+zIwfyLgN5JFlPxNS1kw1uwI4dzD24+MI/9C6vdSuyDGtn4uY9Z5m o6h8W/70MQgXOW46OD7Aj82yqewDrbwmZKiqB3edhFHCdFGx735WXyGpjHflac+Klvtczaw5wUd axnlXA6hlnCQfUiPeGqYN+84FELwnwKNb7JSwp/RgAqFFxtwe96P0Ts= X-Google-Smtp-Source: AGHT+IFzlqSdIaYHLSZI599cWVBA7dW7jlgFu/OL/NbLRylvBc/ItMiequCd7pzuj7u4ZD8d08JvJw== X-Received: by 2002:a05:6a00:2342:b0:730:7d3f:8c70 with SMTP id d2e1a72fcca58-7307d3f9339mr5011190b3a.21.1739074728662; Sat, 08 Feb 2025 20:18:48 -0800 (PST) Received: from anup-ubuntu-vm.localdomain ([103.97.166.196]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-73073eba116sm1898410b3a.124.2025.02.08.20.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Feb 2025 20:18:48 -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 v5 11/11] irqchip/riscv-imsic: Special handling for non-atomic device MSI update Date: Sun, 9 Feb 2025 09:46:55 +0530 Message-ID: <20250209041655.331470-12-apatel@ventanamicro.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250209041655.331470-1-apatel@ventanamicro.com> References: <20250209041655.331470-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