From nobody Thu Dec 18 09:39:49 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6C621531C1; Thu, 4 Dec 2025 05:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824722; cv=none; b=XemPpPnXpdW4nb0c4qFNvxuHwcd6CCCYMfS05ijBAceqY6iWcKqS81OthpyhosbAX0qadDTKdBvdA9zAdzBDqm5qGGylZr9kWhhX8s3Y+QYCg0fNSw9YmWkrMvshlUfEtqdsov7HSyLywViVqOonSzgzjQtQ2ybAbBJNUXvnikA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824722; c=relaxed/simple; bh=h+0JO5F1BsCL6T/czUkyOQMStbUrks45PvRwGKRVQak=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lfzxFnwSfSDDGLuIA5UbEnu9ipjXaJYJCdBa519JtT4CrEYTk8gJwvSZQbaj7wAaailIzNEIkUVBchAA2ZCRIZrhCyIX9GVLTVTlLtsBLN05uCHtfJ+/6QhHfAjOMd/OXiE1Rlmlfmg9dyhJY3NVcczbN63Hx7p9a7uLv/D8hSg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=k5i0C5FP; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="k5i0C5FP" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5B3NhX2o006817; Thu, 4 Dec 2025 05:05:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=8fugNI aWueeCYJGLShvhSZYH/P22+ioQYQT4sBg2aJs=; b=k5i0C5FPcKiTQYYbgRqfQA TNCO7VH1ks5xbF04AUXBscFEvgdA2eB3aKmCrXF+XKA9IpAQ6htKFmTuBriOHWnw jkWIWojEFuDC4qkC9RLHLYua2mGTSSy71zS0pJAMXl44MKgt0Gs/frBnWZhgRK6t honnfgLyjzefg9uIa5ujP6CZAAR9Mdb2ovaNX9nqh93DSduUDG4YFg1OOrVJrh7q G6efQB7cDCtO4vRytZwBYO+tyIfZBKQUgW2baRFTJIeBzug25OBL3w1KqY4e01GR sBWO/7K+SoBmboI9JP9n6z3OHzBExG4FDY2OMgs4WFSFfnsgOPyyc3ps3vvEeUcA == Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4aqrbgenk8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Dec 2025 05:05:17 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5B43G3lb019035; Thu, 4 Dec 2025 05:05:16 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4arbhy61vq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Dec 2025 05:05:16 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5B455COl59179348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 4 Dec 2025 05:05:12 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1B70420040; Thu, 4 Dec 2025 05:05:12 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E54B02004B; Thu, 4 Dec 2025 05:05:11 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 4 Dec 2025 05:05:11 +0000 (GMT) From: Tobias Schumacher Date: Thu, 04 Dec 2025 06:05:01 +0100 Subject: [PATCH v9 1/2] genirq: Change hwirq parameter to irq_hw_number_t Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251204-implement-msi-domain-v9-1-d2152235701b@linux.ibm.com> References: <20251204-implement-msi-domain-v9-0-d2152235701b@linux.ibm.com> In-Reply-To: <20251204-implement-msi-domain-v9-0-d2152235701b@linux.ibm.com> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Gerd Bayer , Halil Pasic , Matthew Rosato , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Tobias Schumacher , Farhan Ali X-Mailer: b4 0.14.2 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: -cLa3txQWTNOQStWR0FMiRKwgiZ6017o X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTI5MDAxNiBTYWx0ZWRfX4SBfJ5CWYZi1 BNEQvQVw2rLsvvIoAfcH1t5medyw1Lz9qu9ty/wk67lqyAk1PtxXTyv6xl1udCL7W3yjk4TV09w LGFVVyH2DsMI8Fhke6tQskpn6UJ6xgaHNRkEaLREcM2EjQ7Xor4aTz8W5XVSzSxINqky0TWfZfY kLOlGhpHHHe4l6d5Vd8JDwX199rLhKrA3xYDM795/Dd+TJs9fu8U+Y4i+8nRgRROz1MOtZvphAV 9z/kK+y0q3gmqZq90JGfoRARRNnAyw4iXWiYwn3jD0eGHCuwMhdosZT29HTJo5q6k2GEZj6/PG/ CO7q7MPp2NXPvL82+XeZC0/+vrgUu64f9gXocBHikOs6eYJzFZ1AIAXy5ZHZ0zL1OaLmOHO48vl +cXGKsA8hi1hzz5Hn+UAxYUFvqE2Vw== X-Authority-Analysis: v=2.4 cv=UO7Q3Sfy c=1 sm=1 tr=0 ts=6931168d cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VnNF1IyMAAAA:8 a=apPMBW2BC5_Ovgk0KuUA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: -cLa3txQWTNOQStWR0FMiRKwgiZ6017o X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-04_01,2025-12-03_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 adultscore=0 priorityscore=1501 impostorscore=0 spamscore=0 phishscore=0 clxscore=1015 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2511290016 The irqdomain implementation internally represents hardware IRQs as irq_hw_number_t, which is defined as unsigned long int. When providing an irq_hw_number_t to the generic_handle_domain() functions that expect and unsigned int hwirq, this can lead to a loss of information. Change the hwirq parameter to irq_hw_number_t to support the full range of hwirqs. Reviewed-by: Thomas Gleixner Reviewed-by: Niklas Schnelle Reviewed-by: Farhan Ali Signed-off-by: Tobias Schumacher --- include/linux/irqdesc.h | 6 +++--- kernel/irq/irqdesc.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/linux/irqdesc.h b/include/linux/irqdesc.h index fd091c35d5721eee37a2fd3d5526559671d5048d..03b63aea73bb21ae1456910afa5= 34d60f9cfa94d 100644 --- a/include/linux/irqdesc.h +++ b/include/linux/irqdesc.h @@ -183,9 +183,9 @@ int generic_handle_irq_safe(unsigned int irq); * and handle the result interrupt number. Return -EINVAL if * conversion failed. */ -int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwir= q); -int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int= hwirq); -int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwir= q); +int generic_handle_domain_irq(struct irq_domain *domain, irq_hw_number_t h= wirq); +int generic_handle_domain_irq_safe(struct irq_domain *domain, irq_hw_numbe= r_t hwirq); +int generic_handle_domain_nmi(struct irq_domain *domain, irq_hw_number_t h= wirq); #endif =20 /* Test to see if a driver has successfully requested an irq */ diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index db714d3014b5f7b62403ea04b80331ec6b1dc642..0cd3198496bc0766c81c353c3ff= 80ea184793d6a 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -720,7 +720,7 @@ EXPORT_SYMBOL_GPL(generic_handle_irq_safe); * This function must be called from an IRQ context with irq regs * initialized. */ -int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwir= q) +int generic_handle_domain_irq(struct irq_domain *domain, irq_hw_number_t h= wirq) { return handle_irq_desc(irq_resolve_mapping(domain, hwirq)); } @@ -738,7 +738,7 @@ EXPORT_SYMBOL_GPL(generic_handle_domain_irq); * context). If the interrupt is marked as 'enforce IRQ-context only' then * the function must be invoked from hard interrupt context. */ -int generic_handle_domain_irq_safe(struct irq_domain *domain, unsigned int= hwirq) +int generic_handle_domain_irq_safe(struct irq_domain *domain, irq_hw_numbe= r_t hwirq) { unsigned long flags; int ret; @@ -761,7 +761,7 @@ EXPORT_SYMBOL_GPL(generic_handle_domain_irq_safe); * This function must be called from an NMI context with irq regs * initialized. **/ -int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwir= q) +int generic_handle_domain_nmi(struct irq_domain *domain, irq_hw_number_t h= wirq) { WARN_ON_ONCE(!in_nmi()); return handle_irq_desc(irq_resolve_mapping(domain, hwirq)); --=20 2.51.0 From nobody Thu Dec 18 09:39:49 2025 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6CE32FFDF2; Thu, 4 Dec 2025 05:05:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824723; cv=none; b=KvQWMSKlgl4V11uKCM6Gni2M1VumWBGZQKGM0GGxD2xTygGZrGC2MZeUWWqvdWJfS8TxaR0P+h0h00G14BiCLfPcPgVGYATRXLA9qjGF/YXJJVMlHSKQYulUL+VZNJb9Q29iELWqJtgGrPL4JdPxZ/Hg9emM9Ku/Wjyxzr6gRnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764824723; c=relaxed/simple; bh=Sq8WNk2+ohUqHClUZndxP7d+3qxjZSZsA8mqAXZQJfU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YI2znrvWDkjnFIhOQEmd1ZXcQIcba+H61RlEbT0zvY9eGSORdkFZj7N/Ua+yxPefQXhkQDa+WBhggYor7FErr2zFfj6Wgj4YSP+7nuGXEUfgnCv4RSQxr2fZPuUWSTtpIYt0SJN18bSa6c8sQKJucQkvRhH8Yl3y1m35YntwNL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=oPaWy3aO; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="oPaWy3aO" Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5B3Kwexd010280; Thu, 4 Dec 2025 05:05:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=8U8CrC j03O3U/jmhmux4YNZGTCR3ZUv29LPR+LOVh1A=; b=oPaWy3aOW3LSti10uBwBIS VJ4/4wZboi7r5d7MvvOLzjZy0HbQVua7BX0fAqPL2myLWh4yLCB5AVh6pORwRw3J fAvnp5v4H23IGZFDrkDmSletfuz8zJdJsJkcwj4rS4xfUYdUntH66quJKnD7mlKm 8Rp09ICSsqxCWOHu6o3zKpus0BC2ioT7Bpp0QUDMTR4YJ5qPdcfVWlkx4xgc+8XX fkCxMZQJs0wixI83MdiBfJh39YFOCt5xlBmclznSOJsXyOWOyebMJG2X7bPUJ7pr vvllouHavMu5by3zebFKGjxqpvyktM/VZK4IRBNiArBruIEkTvbi/QuvcJcMIRjw == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4aqrh76j2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Dec 2025 05:05:17 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5B44snUl029328; Thu, 4 Dec 2025 05:05:16 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4ardv1nqbj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 04 Dec 2025 05:05:16 +0000 Received: from smtpav06.fra02v.mail.ibm.com (smtpav06.fra02v.mail.ibm.com [10.20.54.105]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5B455Coi43581872 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 4 Dec 2025 05:05:12 GMT Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5B23320040; Thu, 4 Dec 2025 05:05:12 +0000 (GMT) Received: from smtpav06.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1ED8920049; Thu, 4 Dec 2025 05:05:12 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.87.85.9]) by smtpav06.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 4 Dec 2025 05:05:12 +0000 (GMT) From: Tobias Schumacher Date: Thu, 04 Dec 2025 06:05:02 +0100 Subject: [PATCH v9 2/2] s390/pci: Migrate s390 IRQ logic to IRQ domain API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251204-implement-msi-domain-v9-2-d2152235701b@linux.ibm.com> References: <20251204-implement-msi-domain-v9-0-d2152235701b@linux.ibm.com> In-Reply-To: <20251204-implement-msi-domain-v9-0-d2152235701b@linux.ibm.com> To: Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Niklas Schnelle , Gerald Schaefer , Gerd Bayer , Halil Pasic , Matthew Rosato , Thomas Gleixner Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, Tobias Schumacher , Farhan Ali X-Mailer: b4 0.14.2 X-TM-AS-GCONF: 00 X-Authority-Analysis: v=2.4 cv=dK+rWeZb c=1 sm=1 tr=0 ts=6931168d cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VwQbUJbxAAAA:8 a=VnNF1IyMAAAA:8 a=pn-msHsI0j841b3IYMsA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: UWeLSROeHqRkqcW4NQY2GCTYRFjCl6Q0 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTI5MDAyMCBTYWx0ZWRfX11TFQwPzw9yP Ps8lrpJdb0AD95+0l/FbrszvNYZ325+XTCgkVmIyTdy3aIFlVnMJ3FScE4USAu2V7EmYm2SFI1+ xyyASMlzpLNilDJRfB5R8eOUt1Zxz8KL+q1e7tmc50hhHtRFwQY3F46gm7OwUtm/c7l4HeUYKi0 PDtDRWaT5N0rNbswC23fRmL/vzYIJvHLos0QJdI/UTCACTQHOQlkaw+t9ddQZocdYzK4xFipJpY faniT8lQRk3PHDqR0HciQIRzNaSEFtO4uqDYQExatB2rOWK5oSys5bB1b65Hve/oRwe2v3WhfM6 f/eza2MT1eUMnhWfoVrD9Bf5RrazdZTyEO5wL8vFys4r2eqbQ9fIP8TyNMvPPED4DC5kdTMmYZn CThLCxbdskN8TGfRPLZOeBC4WaE4OQ== X-Proofpoint-ORIG-GUID: UWeLSROeHqRkqcW4NQY2GCTYRFjCl6Q0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-04_01,2025-12-03_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 adultscore=0 phishscore=0 impostorscore=0 spamscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2511290020 s390 is one of the last architectures using the legacy API for setup and teardown of PCI MSI IRQs. Migrate the s390 IRQ allocation and teardown to the MSI parent domain API. For details, see: https://lore.kernel.org/lkml/20221111120501.026511281@linutronix.de In detail, create an MSI parent domain for each PCI domain. When a PCI device sets up MSI or MSI-X IRQs, the library creates a per-device IRQ domain for this device, which is used by the device for allocating and freeing IRQs. The per-device domain delegates this allocation and freeing to the parent-domain. In the end, the corresponding callbacks of the parent domain are responsible for allocating and freeing the IRQs. The allocation is split into two parts: - zpci_msi_prepare() is called once for each device and allocates the required resources. On s390, each PCI function has its own airq vector and a summary bit, which must be configured once per function. This is done in prepare(). - zpci_msi_alloc() can be called multiple times for allocating one or more MSI/MSI-X IRQs. This creates a mapping between the virtual IRQ number in the kernel and the hardware IRQ number. Freeing is split into two counterparts: - zpci_msi_free() reverts the effects of zpci_msi_alloc() and - zpci_msi_teardown() reverts the effects of zpci_msi_prepare(). This is called once when all IRQs are freed before a device is removed. Since the parent domain in the end allocates the IRQs, the hwirq encoding must be unambiguous for all IRQs of all devices. This is achieved by encoding the hwirq using the devfn and the MSI index. Reviewed-by: Niklas Schnelle Reviewed-by: Farhan Ali Signed-off-by: Tobias Schumacher Reviewed-by: Gerd Bayer --- arch/s390/Kconfig | 1 + arch/s390/include/asm/pci.h | 5 + arch/s390/pci/pci.c | 6 + arch/s390/pci/pci_bus.c | 18 ++- arch/s390/pci/pci_irq.c | 332 +++++++++++++++++++++++++++++-----------= ---- 5 files changed, 247 insertions(+), 115 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 778ce20d34046cad84dd4ef57cab5a662e5796d9..fc82dd4f893d78f12837f36ab82= a05f2c52e0501 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -251,6 +251,7 @@ config S390 select HOTPLUG_SMT select IOMMU_HELPER if PCI select IOMMU_SUPPORT if PCI + select IRQ_MSI_LIB if PCI select KASAN_VMALLOC if KASAN select LOCK_MM_AND_FIND_VMA select MMU_GATHER_MERGE_VMAS diff --git a/arch/s390/include/asm/pci.h b/arch/s390/include/asm/pci.h index a32f465ecf73a5cc3408a312d94ec888d62848cc..0aa6915346a50077f22868cef39= 638919979d478 100644 --- a/arch/s390/include/asm/pci.h +++ b/arch/s390/include/asm/pci.h @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -109,6 +110,7 @@ struct zpci_bus { struct list_head resources; struct list_head bus_next; struct resource bus_resource; + struct irq_domain *msi_parent_domain; int topo; /* TID if topo_is_tid, PCHID otherwise */ int domain_nr; u8 multifunction : 1; @@ -310,6 +312,9 @@ int zpci_dma_exit_device(struct zpci_dev *zdev); /* IRQ */ int __init zpci_irq_init(void); void __init zpci_irq_exit(void); +int zpci_set_irq(struct zpci_dev *zdev); +int zpci_create_parent_msi_domain(struct zpci_bus *zbus); +void zpci_remove_parent_msi_domain(struct zpci_bus *zbus); =20 /* FMB */ int zpci_fmb_enable_device(struct zpci_dev *); diff --git a/arch/s390/pci/pci.c b/arch/s390/pci/pci.c index c82c577db2bcd2143476cb8189fd89b9a4dc9836..2e47bf6a3289615307c71cae7b0= 4ef77d964144a 100644 --- a/arch/s390/pci/pci.c +++ b/arch/s390/pci/pci.c @@ -709,6 +709,12 @@ int zpci_reenable_device(struct zpci_dev *zdev) if (rc) return rc; =20 + if (zdev->msi_nr_irqs > 0) { + rc =3D zpci_set_irq(zdev); + if (rc) + return rc; + } + rc =3D zpci_iommu_register_ioat(zdev, &status); if (rc) zpci_disable_device(zdev); diff --git a/arch/s390/pci/pci_bus.c b/arch/s390/pci/pci_bus.c index be8c697fea0cc755cfdb4fb0a9e3b95183bec0dc..2d7b389f36e8682c3f0a10befe8= 7698751596584 100644 --- a/arch/s390/pci/pci_bus.c +++ b/arch/s390/pci/pci_bus.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -199,19 +200,27 @@ static int zpci_bus_create_pci_bus(struct zpci_bus *z= bus, struct zpci_dev *fr, s zbus->multifunction =3D zpci_bus_is_multifunction_root(fr); zbus->max_bus_speed =3D fr->max_bus_speed; =20 + if (zpci_create_parent_msi_domain(zbus)) + goto out_free_domain; + /* * Note that the zbus->resources are taken over and zbus->resources * is empty after a successful call */ bus =3D pci_create_root_bus(NULL, ZPCI_BUS_NR, ops, zbus, &zbus->resource= s); - if (!bus) { - zpci_free_domain(zbus->domain_nr); - return -EFAULT; - } + if (!bus) + goto out_remove_msi_domain; =20 zbus->bus =3D bus; + dev_set_msi_domain(&zbus->bus->dev, zbus->msi_parent_domain); =20 return 0; + +out_remove_msi_domain: + zpci_remove_parent_msi_domain(zbus); +out_free_domain: + zpci_free_domain(zbus->domain_nr); + return -ENOMEM; } =20 static void zpci_bus_release(struct kref *kref) @@ -232,6 +241,7 @@ static void zpci_bus_release(struct kref *kref) mutex_lock(&zbus_list_lock); list_del(&zbus->bus_next); mutex_unlock(&zbus_list_lock); + zpci_remove_parent_msi_domain(zbus); kfree(zbus); } =20 diff --git a/arch/s390/pci/pci_irq.c b/arch/s390/pci/pci_irq.c index e73be96ce5fe6473fc193d65b8f0ff635d6a98ba..9699927b5d9d94e5becd7aa5385= 367a56e151f44 100644 --- a/arch/s390/pci/pci_irq.c +++ b/arch/s390/pci/pci_irq.c @@ -7,6 +7,7 @@ #include #include #include +#include #include =20 #include @@ -98,7 +99,7 @@ static int zpci_clear_directed_irq(struct zpci_dev *zdev) } =20 /* Register adapter interruptions */ -static int zpci_set_irq(struct zpci_dev *zdev) +int zpci_set_irq(struct zpci_dev *zdev) { int rc; =20 @@ -126,27 +127,53 @@ static int zpci_clear_irq(struct zpci_dev *zdev) static int zpci_set_irq_affinity(struct irq_data *data, const struct cpuma= sk *dest, bool force) { - struct msi_desc *entry =3D irq_data_get_msi_desc(data); - struct msi_msg msg =3D entry->msg; - int cpu_addr =3D smp_cpu_get_cpu_address(cpumask_first(dest)); + irq_data_update_affinity(data, dest); + return IRQ_SET_MASK_OK; +} =20 - msg.address_lo &=3D 0xff0000ff; - msg.address_lo |=3D (cpu_addr << 8); - pci_write_msi_msg(data->irq, &msg); +/* + * Encode the hwirq number for the parent domain. The encoding must be uni= que + * for each IRQ of each device in the parent domain, so it uses the devfn = to + * identify the device and the msi_index to identify the IRQ within that d= evice. + */ +static inline u32 zpci_encode_hwirq(u8 devfn, u16 msi_index) +{ + return (devfn << 16) | msi_index; +} =20 - return IRQ_SET_MASK_OK; +static inline u16 zpci_decode_hwirq_msi_index(irq_hw_number_t hwirq) +{ + return hwirq & 0xffff; +} + +static void zpci_compose_msi_msg(struct irq_data *data, struct msi_msg *ms= g) +{ + struct msi_desc *desc =3D irq_data_get_msi_desc(data); + struct zpci_dev *zdev =3D to_zpci_dev(desc->dev); + + if (irq_delivery =3D=3D DIRECTED) { + int cpu =3D cpumask_first(irq_data_get_affinity_mask(data)); + + msg->address_lo =3D zdev->msi_addr & 0xff0000ff; + msg->address_lo |=3D (smp_cpu_get_cpu_address(cpu) << 8); + } else { + msg->address_lo =3D zdev->msi_addr & 0xffffffff; + } + msg->address_hi =3D zdev->msi_addr >> 32; + msg->data =3D zpci_decode_hwirq_msi_index(data->hwirq); } =20 static struct irq_chip zpci_irq_chip =3D { .name =3D "PCI-MSI", - .irq_unmask =3D pci_msi_unmask_irq, - .irq_mask =3D pci_msi_mask_irq, + .irq_compose_msi_msg =3D zpci_compose_msi_msg, }; =20 static void zpci_handle_cpu_local_irq(bool rescan) { struct airq_iv *dibv =3D zpci_ibv[smp_processor_id()]; union zpci_sic_iib iib =3D {{0}}; + struct irq_domain *msi_domain; + irq_hw_number_t hwirq; unsigned long bit; int irqs_on =3D 0; =20 @@ -164,7 +191,9 @@ static void zpci_handle_cpu_local_irq(bool rescan) continue; } inc_irq_stat(IRQIO_MSI); - generic_handle_irq(airq_iv_get_data(dibv, bit)); + hwirq =3D airq_iv_get_data(dibv, bit); + msi_domain =3D (struct irq_domain *)airq_iv_get_ptr(dibv, bit); + generic_handle_domain_irq(msi_domain, hwirq); } } =20 @@ -229,6 +258,8 @@ static void zpci_floating_irq_handler(struct airq_struc= t *airq, struct tpi_info *tpi_info) { union zpci_sic_iib iib =3D {{0}}; + struct irq_domain *msi_domain; + irq_hw_number_t hwirq; unsigned long si, ai; struct airq_iv *aibv; int irqs_on =3D 0; @@ -256,7 +287,9 @@ static void zpci_floating_irq_handler(struct airq_struc= t *airq, break; inc_irq_stat(IRQIO_MSI); airq_iv_lock(aibv, ai); - generic_handle_irq(airq_iv_get_data(aibv, ai)); + hwirq =3D airq_iv_get_data(aibv, ai); + msi_domain =3D (struct irq_domain *)airq_iv_get_ptr(aibv, ai); + generic_handle_domain_irq(msi_domain, hwirq); airq_iv_unlock(aibv, ai); } } @@ -278,7 +311,9 @@ static int __alloc_airq(struct zpci_dev *zdev, int msi_= vecs, zdev->aisb =3D *bit; =20 /* Create adapter interrupt vector */ - zdev->aibv =3D airq_iv_create(msi_vecs, AIRQ_IV_DATA | AIRQ_IV_BITLOCK, = NULL); + zdev->aibv =3D airq_iv_create(msi_vecs, + AIRQ_IV_PTR | AIRQ_IV_DATA | AIRQ_IV_BITLOCK, + NULL); if (!zdev->aibv) return -ENOMEM; =20 @@ -290,146 +325,220 @@ static int __alloc_airq(struct zpci_dev *zdev, int = msi_vecs, return 0; } =20 -int arch_setup_msi_irqs(struct pci_dev *pdev, int nvec, int type) +bool arch_restore_msi_irqs(struct pci_dev *pdev) { - unsigned int hwirq, msi_vecs, irqs_per_msi, i, cpu; struct zpci_dev *zdev =3D to_zpci(pdev); - struct msi_desc *msi; - struct msi_msg msg; - unsigned long bit; - int cpu_addr; - int rc, irq; =20 + zpci_set_irq(zdev); + return true; +} + +static struct airq_struct zpci_airq =3D { + .handler =3D zpci_floating_irq_handler, + .isc =3D PCI_ISC, +}; + +static void zpci_msi_teardown_directed(struct zpci_dev *zdev) +{ + airq_iv_free(zpci_ibv[0], zdev->msi_first_bit, zdev->max_msi); + zdev->msi_first_bit =3D -1U; + zdev->msi_nr_irqs =3D 0; +} + +static void zpci_msi_teardown_floating(struct zpci_dev *zdev) +{ + airq_iv_release(zdev->aibv); + zdev->aibv =3D NULL; + airq_iv_free_bit(zpci_sbv, zdev->aisb); zdev->aisb =3D -1UL; zdev->msi_first_bit =3D -1U; + zdev->msi_nr_irqs =3D 0; +} + +static void zpci_msi_teardown(struct irq_domain *domain, msi_alloc_info_t = *arg) +{ + struct zpci_dev *zdev =3D to_zpci_dev(domain->dev); + + zpci_clear_irq(zdev); + if (irq_delivery =3D=3D DIRECTED) + zpci_msi_teardown_directed(zdev); + else + zpci_msi_teardown_floating(zdev); +} + +static int zpci_msi_prepare(struct irq_domain *domain, + struct device *dev, int nvec, + msi_alloc_info_t *info) +{ + struct zpci_dev *zdev =3D to_zpci_dev(dev); + struct pci_dev *pdev =3D to_pci_dev(dev); + unsigned long bit; + int msi_vecs, rc; =20 msi_vecs =3D min_t(unsigned int, nvec, zdev->max_msi); if (msi_vecs < nvec) { - pr_info("%s requested %d irqs, allocate system limit of %d", + pr_info("%s requested %d IRQs, allocate system limit of %d\n", pci_name(pdev), nvec, zdev->max_msi); } =20 rc =3D __alloc_airq(zdev, msi_vecs, &bit); - if (rc < 0) + if (rc) { + pr_err("Allocating adapter IRQs for %s failed\n", pci_name(pdev)); return rc; + } =20 - /* - * Request MSI interrupts: - * When using MSI, nvec_used interrupt sources and their irq - * descriptors are controlled through one msi descriptor. - * Thus the outer loop over msi descriptors shall run only once, - * while two inner loops iterate over the interrupt vectors. - * When using MSI-X, each interrupt vector/irq descriptor - * is bound to exactly one msi descriptor (nvec_used is one). - * So the inner loops are executed once, while the outer iterates - * over the MSI-X descriptors. - */ - hwirq =3D bit; - msi_for_each_desc(msi, &pdev->dev, MSI_DESC_NOTASSOCIATED) { - if (hwirq - bit >=3D msi_vecs) - break; - irqs_per_msi =3D min_t(unsigned int, msi_vecs, msi->nvec_used); - irq =3D __irq_alloc_descs(-1, 0, irqs_per_msi, 0, THIS_MODULE, - (irq_delivery =3D=3D DIRECTED) ? - msi->affinity : NULL); - if (irq < 0) - return -ENOMEM; + zdev->msi_first_bit =3D bit; + zdev->msi_nr_irqs =3D msi_vecs; + rc =3D zpci_set_irq(zdev); + if (rc) { + pr_err("Registering adapter IRQs for %s failed\n", + pci_name(pdev)); + + if (irq_delivery =3D=3D DIRECTED) + zpci_msi_teardown_directed(zdev); + else + zpci_msi_teardown_floating(zdev); + return rc; + } + return 0; +} =20 - for (i =3D 0; i < irqs_per_msi; i++) { - rc =3D irq_set_msi_desc_off(irq, i, msi); - if (rc) - return rc; - irq_set_chip_and_handler(irq + i, &zpci_irq_chip, - handle_percpu_irq); - } +static int zpci_msi_domain_alloc(struct irq_domain *domain, unsigned int v= irq, + unsigned int nr_irqs, void *args) +{ + struct msi_desc *desc =3D ((msi_alloc_info_t *)args)->desc; + struct zpci_dev *zdev =3D to_zpci_dev(desc->dev); + struct zpci_bus *zbus =3D zdev->zbus; + unsigned int cpu, hwirq; + unsigned long bit; + int i; =20 - msg.data =3D hwirq - bit; - if (irq_delivery =3D=3D DIRECTED) { - if (msi->affinity) - cpu =3D cpumask_first(&msi->affinity->mask); - else - cpu =3D 0; - cpu_addr =3D smp_cpu_get_cpu_address(cpu); + bit =3D zdev->msi_first_bit + desc->msi_index; + hwirq =3D zpci_encode_hwirq(zdev->devfn, desc->msi_index); =20 - msg.address_lo =3D zdev->msi_addr & 0xff0000ff; - msg.address_lo |=3D (cpu_addr << 8); + if (desc->msi_index + nr_irqs > zdev->max_msi) + return -EINVAL; =20 + for (i =3D 0; i < nr_irqs; i++) { + irq_domain_set_info(domain, virq + i, hwirq + i, + &zpci_irq_chip, zdev, + handle_percpu_irq, NULL, NULL); + + if (irq_delivery =3D=3D DIRECTED) { for_each_possible_cpu(cpu) { - for (i =3D 0; i < irqs_per_msi; i++) - airq_iv_set_data(zpci_ibv[cpu], - hwirq + i, irq + i); + airq_iv_set_ptr(zpci_ibv[cpu], bit + i, + (unsigned long)zbus->msi_parent_domain); + airq_iv_set_data(zpci_ibv[cpu], bit + i, hwirq + i); } } else { - msg.address_lo =3D zdev->msi_addr & 0xffffffff; - for (i =3D 0; i < irqs_per_msi; i++) - airq_iv_set_data(zdev->aibv, hwirq + i, irq + i); + airq_iv_set_ptr(zdev->aibv, bit + i, + (unsigned long)zbus->msi_parent_domain); + airq_iv_set_data(zdev->aibv, bit + i, hwirq + i); } - msg.address_hi =3D zdev->msi_addr >> 32; - pci_write_msi_msg(irq, &msg); - hwirq +=3D irqs_per_msi; } =20 - zdev->msi_first_bit =3D bit; - zdev->msi_nr_irqs =3D hwirq - bit; - - rc =3D zpci_set_irq(zdev); - if (rc) - return rc; - - return (zdev->msi_nr_irqs =3D=3D nvec) ? 0 : zdev->msi_nr_irqs; + return 0; } =20 -void arch_teardown_msi_irqs(struct pci_dev *pdev) +static void zpci_msi_clear_airq(struct irq_data *d, int i) { - struct zpci_dev *zdev =3D to_zpci(pdev); - struct msi_desc *msi; - unsigned int i; - int rc; + struct msi_desc *desc =3D irq_data_get_msi_desc(d); + struct zpci_dev *zdev =3D to_zpci_dev(desc->dev); + unsigned long bit; + unsigned int cpu; + u16 msi_index; =20 - /* Disable interrupts */ - rc =3D zpci_clear_irq(zdev); - if (rc) - return; + msi_index =3D zpci_decode_hwirq_msi_index(d->hwirq); + bit =3D zdev->msi_first_bit + msi_index; =20 - /* Release MSI interrupts */ - msi_for_each_desc(msi, &pdev->dev, MSI_DESC_ASSOCIATED) { - for (i =3D 0; i < msi->nvec_used; i++) { - irq_set_msi_desc(msi->irq + i, NULL); - irq_free_desc(msi->irq + i); + if (irq_delivery =3D=3D DIRECTED) { + for_each_possible_cpu(cpu) { + airq_iv_set_ptr(zpci_ibv[cpu], bit + i, 0); + airq_iv_set_data(zpci_ibv[cpu], bit + i, 0); } - msi->msg.address_lo =3D 0; - msi->msg.address_hi =3D 0; - msi->msg.data =3D 0; - msi->irq =3D 0; + } else { + airq_iv_set_ptr(zdev->aibv, bit + i, 0); + airq_iv_set_data(zdev->aibv, bit + i, 0); } +} =20 - if (zdev->aisb !=3D -1UL) { - zpci_ibv[zdev->aisb] =3D NULL; - airq_iv_free_bit(zpci_sbv, zdev->aisb); - zdev->aisb =3D -1UL; - } - if (zdev->aibv) { - airq_iv_release(zdev->aibv); - zdev->aibv =3D NULL; - } +static void zpci_msi_domain_free(struct irq_domain *domain, unsigned int v= irq, + unsigned int nr_irqs) +{ + struct irq_data *d; + int i; =20 - if ((irq_delivery =3D=3D DIRECTED) && zdev->msi_first_bit !=3D -1U) - airq_iv_free(zpci_ibv[0], zdev->msi_first_bit, zdev->msi_nr_irqs); + for (i =3D 0; i < nr_irqs; i++) { + d =3D irq_domain_get_irq_data(domain, virq + i); + zpci_msi_clear_airq(d, i); + irq_domain_reset_irq_data(d); + } } =20 -bool arch_restore_msi_irqs(struct pci_dev *pdev) +static const struct irq_domain_ops zpci_msi_domain_ops =3D { + .alloc =3D zpci_msi_domain_alloc, + .free =3D zpci_msi_domain_free, +}; + +static bool zpci_init_dev_msi_info(struct device *dev, struct irq_domain *= domain, + struct irq_domain *real_parent, + struct msi_domain_info *info) { - struct zpci_dev *zdev =3D to_zpci(pdev); + if (!msi_lib_init_dev_msi_info(dev, domain, real_parent, info)) + return false; + + info->ops->msi_prepare =3D zpci_msi_prepare; + info->ops->msi_teardown =3D zpci_msi_teardown; =20 - zpci_set_irq(zdev); return true; } =20 -static struct airq_struct zpci_airq =3D { - .handler =3D zpci_floating_irq_handler, - .isc =3D PCI_ISC, +static struct msi_parent_ops zpci_msi_parent_ops =3D { + .supported_flags =3D MSI_GENERIC_FLAGS_MASK | + MSI_FLAG_PCI_MSIX | + MSI_FLAG_MULTI_PCI_MSI, + .required_flags =3D MSI_FLAG_USE_DEF_DOM_OPS | + MSI_FLAG_USE_DEF_CHIP_OPS, + .init_dev_msi_info =3D zpci_init_dev_msi_info, }; =20 +int zpci_create_parent_msi_domain(struct zpci_bus *zbus) +{ + char fwnode_name[18]; + + snprintf(fwnode_name, sizeof(fwnode_name), "ZPCI_MSI_DOM_%04x", zbus->dom= ain_nr); + struct irq_domain_info info =3D { + .fwnode =3D irq_domain_alloc_named_fwnode(fwnode_name), + .ops =3D &zpci_msi_domain_ops, + }; + + if (!info.fwnode) { + pr_err("Failed to allocate fwnode for MSI IRQ domain\n"); + return -ENOMEM; + } + + if (irq_delivery =3D=3D FLOATING) + zpci_msi_parent_ops.required_flags |=3D MSI_FLAG_NO_AFFINITY; + + zbus->msi_parent_domain =3D msi_create_parent_irq_domain(&info, &zpci_msi= _parent_ops); + if (!zbus->msi_parent_domain) { + irq_domain_free_fwnode(info.fwnode); + pr_err("Failed to create MSI IRQ domain\n"); + return -ENOMEM; + } + + return 0; +} + +void zpci_remove_parent_msi_domain(struct zpci_bus *zbus) +{ + struct fwnode_handle *fn; + + fn =3D zbus->msi_parent_domain->fwnode; + irq_domain_remove(zbus->msi_parent_domain); + irq_domain_free_fwnode(fn); +} + static void __init cpu_enable_directed_irq(void *unused) { union zpci_sic_iib iib =3D {{0}}; @@ -466,6 +575,7 @@ static int __init zpci_directed_irq_init(void) * is only done on the first vector. */ zpci_ibv[cpu] =3D airq_iv_create(cache_line_size() * BITS_PER_BYTE, + AIRQ_IV_PTR | AIRQ_IV_DATA | AIRQ_IV_CACHELINE | (!cpu ? AIRQ_IV_ALLOC : 0), NULL); --=20 2.51.0