Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp849062rdb; Fri, 23 Feb 2024 01:44:08 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXDIzclefX/bZwdYFEVA6HXPwdVMPUdruLWTeqE63NJKsYZ+cEo3h05LYaTlJBetACAXnRly0wgYGF9n6u72+3AhqOxVHfw7KGWsOASvg== X-Google-Smtp-Source: AGHT+IE+bKNRZrwBFLEO78uJUwi5bIe+HkAG6poRe6WLS9Shh7hcADJO8LSqPqfGfyi2l+24T5RZ X-Received: by 2002:a05:620a:21c9:b0:787:ada5:b5c9 with SMTP id h9-20020a05620a21c900b00787ada5b5c9mr1689218qka.58.1708681448749; Fri, 23 Feb 2024 01:44:08 -0800 (PST) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id d2-20020a05620a204200b00787b0fc1375si934147qka.436.2024.02.23.01.44.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 01:44:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78048-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linutronix.de header.s=2020 header.b=x4tKrKwr; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=NFkI9fI6; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-78048-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78048-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6085F1C24429 for ; Fri, 23 Feb 2024 09:44:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4CA8D5C8F8; Fri, 23 Feb 2024 09:44:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="x4tKrKwr"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="NFkI9fI6" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 DE69714F8C; Fri, 23 Feb 2024 09:43:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681441; cv=none; b=U0vGo4LO3iXShJoAY7Ga+CxSqSxuL42IplMyvcYCrQu86Xy60Jl7oafycEL2Ixwxw5EMXfWETQs2lgIbcNKFOwOcOd5hIA76ujHe2P/4bLqEToME99pzGrf90GOsCGSrK/hS0iODI0xdyFYaWY9AArwJCGBxFQh1B5qXgsQ13GA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708681441; c=relaxed/simple; bh=ab2I6JkexfU+9v41SMqz4psQrcPaq4GJN2LCA6JMPsU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=lC8B6djAqxYearDuFtyiC2O8DvBSwnsiRhauPuGsFDbke/PFE3qrUSNo8gfRE5+LuuF96EO73F2KBeFPO0RFfm25ApNGk1FQoCkJ+oF6MGwTsQ/9f99Peo7aTmxOnwMfFWcRIsNPHF6mphPLZf/gCEpu0drHmZ8773XI26GUdJM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=x4tKrKwr; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=NFkI9fI6; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Fri, 23 Feb 2024 09:43:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1708681432; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ucm4lAwyWPcwo/tq+3h/qsYC19yBS3eu8e1YCZAEME0=; b=x4tKrKwrg+8mKQ3YXADmdfbf1hU6//wecawbuCH5SJjnq7KC8CGNhWTmetGjNlzZxh8zb4 2AwT9MnH+QAetVhrGlnffPK0TgHUrJYJ4BrRvjsiuMZA84p8lHvkgr/7yGW+McdVsoF/cG uHh7/n4JHX3QK20GQFG2CHYfBSoYFKcl9GoV1tD3cLNPXGG/IkkdY0Mc8bw0FPuT9OYNr3 WvFk/83V1D9qtoTWjojX7wKbUS32dK11QZd3cP8iJUKfgr56P3U+VXzCrhbOD7NcswBskF Nwx7blsUaDcDsMeVIHRSpSjCypnIVeajPtjDYCZjuGlZr4FaPWZcqbmy1rgidg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1708681432; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ucm4lAwyWPcwo/tq+3h/qsYC19yBS3eu8e1YCZAEME0=; b=NFkI9fI65JwjrUfXzn4Mqnug2hmLU/C36SoFl+U41oe5gRQ5k8uvRul6kQ1lqOoAkzq/la 0CBxOGoIUb3n5iCg== From: tip-bot2 for =?utf-8?q?Bj=C3=B6rn_T=C3=B6pel?= Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/msi] genirq/matrix: Dynamic bitmap allocation Cc: bjorn@rivosinc.com, Anup Patel , Thomas Gleixner , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240222094006.1030709-11-apatel@ventanamicro.com> References: <20240222094006.1030709-11-apatel@ventanamicro.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170868143119.398.7440083204320178509.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the irq/msi branch of tip: Commit-ID: 5b98d210ac1e4eb35abfbd940df50dec10ae81e1 Gitweb: https://git.kernel.org/tip/5b98d210ac1e4eb35abfbd940df50dec10a= e81e1 Author: Bj=C3=B6rn T=C3=B6pel AuthorDate: Thu, 22 Feb 2024 15:09:58 +05:30 Committer: Thomas Gleixner CommitterDate: Fri, 23 Feb 2024 10:18:44 +01:00 genirq/matrix: Dynamic bitmap allocation A future user of the matrix allocator, does not know the size of the matrix bitmaps at compile time. To avoid wasting memory on unnecessary large bitmaps, size the bitmap at matrix allocation time. Signed-off-by: Bj=C3=B6rn T=C3=B6pel Signed-off-by: Anup Patel Signed-off-by: Thomas Gleixner Link: https://lore.kernel.org/r/20240222094006.1030709-11-apatel@ventanamicro= com --- arch/x86/include/asm/hw_irq.h | 2 -- kernel/irq/matrix.c | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h index b02c3cd..edebf10 100644 --- a/arch/x86/include/asm/hw_irq.h +++ b/arch/x86/include/asm/hw_irq.h @@ -16,8 +16,6 @@ =20 #include =20 -#define IRQ_MATRIX_BITS NR_VECTORS - #ifndef __ASSEMBLY__ =20 #include diff --git a/kernel/irq/matrix.c b/kernel/irq/matrix.c index 75d0ae4..8f222d1 100644 --- a/kernel/irq/matrix.c +++ b/kernel/irq/matrix.c @@ -8,8 +8,6 @@ #include #include =20 -#define IRQ_MATRIX_SIZE (BITS_TO_LONGS(IRQ_MATRIX_BITS)) - struct cpumap { unsigned int available; unsigned int allocated; @@ -17,8 +15,8 @@ struct cpumap { unsigned int managed_allocated; bool initialized; bool online; - unsigned long alloc_map[IRQ_MATRIX_SIZE]; - unsigned long managed_map[IRQ_MATRIX_SIZE]; + unsigned long *managed_map; + unsigned long alloc_map[]; }; =20 struct irq_matrix { @@ -32,8 +30,8 @@ struct irq_matrix { unsigned int total_allocated; unsigned int online_maps; struct cpumap __percpu *maps; - unsigned long scratch_map[IRQ_MATRIX_SIZE]; - unsigned long system_map[IRQ_MATRIX_SIZE]; + unsigned long *system_map; + unsigned long scratch_map[]; }; =20 #define CREATE_TRACE_POINTS @@ -50,24 +48,32 @@ __init struct irq_matrix *irq_alloc_matrix(unsigned int m= atrix_bits, unsigned int alloc_start, unsigned int alloc_end) { + unsigned int cpu, matrix_size =3D BITS_TO_LONGS(matrix_bits); struct irq_matrix *m; =20 - if (matrix_bits > IRQ_MATRIX_BITS) - return NULL; - - m =3D kzalloc(sizeof(*m), GFP_KERNEL); + m =3D kzalloc(struct_size(m, scratch_map, matrix_size * 2), GFP_KERNEL); if (!m) return NULL; =20 + m->system_map =3D &m->scratch_map[matrix_size]; + m->matrix_bits =3D matrix_bits; m->alloc_start =3D alloc_start; m->alloc_end =3D alloc_end; m->alloc_size =3D alloc_end - alloc_start; - m->maps =3D alloc_percpu(*m->maps); + m->maps =3D __alloc_percpu(struct_size(m->maps, alloc_map, matrix_size * 2), + __alignof__(*m->maps)); if (!m->maps) { kfree(m); return NULL; } + + for_each_possible_cpu(cpu) { + struct cpumap *cm =3D per_cpu_ptr(m->maps, cpu); + + cm->managed_map =3D &cm->alloc_map[matrix_size]; + } + return m; } =20