From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 0AC6E19D071 for ; Sat, 10 Jan 2026 21:48:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768081686; cv=none; b=Kq3tFjwe5cX+CWOkydZCsPd9W2SFDhE7tS1s1WRomqKK3SyhpLcBOw4Qc5I6heHDXmVaEXz3PP0jx3OnHV8oylWMCEyKw/amfVzcd4+38k3b+zSu3hsB7ApefqhoPmyJSmK7ET60scIV0WzBP5am8A0/4JRD0Hv7ZgaibT3vUhM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768081686; c=relaxed/simple; bh=QPHUoEpXPQPguZms/TBtw2hIhj0+tGVcWsN2AvszUDk=; h=From:Message-ID:Date:MIME-Version:Subject:To:Cc:References: In-Reply-To:Content-Type; b=L6v6pnPrfwKa6Y7Vg6GtIyVzFDYXnHfw461q8h4KZUwlqNn4RIYW292UOvIvdYyjpM+PP6WE5X3FXwog2xbP4+qUNlatczs5TWrzkaOj7CMRCOeqsqQvkAcBTUO731H94VqRrdceIv2pt9UKo2Tl1RNu1OzxPa0gKsH6CEBptso= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f+xohMIC; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=NhUe+KSY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f+xohMIC"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="NhUe+KSY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1768081683; h=from:from: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=046XaQZFAu8wvEAuybB5UMKwHOUklXTERb1ZGpwxEns=; b=f+xohMIC3aLWgs3Ac40sNUto1DyZeDrmfx5LVywoo0Ur32T6+6zda1VdlvllupGH7xIxv+ xSap0Wr77T323Z6uhG1bophrEuBdz9pf9v+JQm/+tE3L4xlhWH/ZweGbbzLGJpW4IqT5sh cmE0PHQspKmACNXI8iT+zfKtfAuIMU8= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-564-G1yiVFHONmmnEqtMNVyz2A-1; Sat, 10 Jan 2026 16:48:02 -0500 X-MC-Unique: G1yiVFHONmmnEqtMNVyz2A-1 X-Mimecast-MFC-AGG-ID: G1yiVFHONmmnEqtMNVyz2A_1768081682 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-8804b991a54so202515796d6.2 for ; Sat, 10 Jan 2026 13:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1768081680; x=1768686480; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:from:to :cc:subject:date:message-id:reply-to; bh=046XaQZFAu8wvEAuybB5UMKwHOUklXTERb1ZGpwxEns=; b=NhUe+KSYCkjFeqI6MPO0nhYtAGpb6kQwbwabGko/61mKLfddL+8bBYwgHpeAcupZMr wZizyIJE3307lgp+Zgox6u1+0kKcYQzKxuu7zTZASlH/Na7f4P3JnPK5HK0bkgzBis+W LtQIeyw8aqHRt8aOVTA6TaoRO1kdCpkWpmCvWXU0nlbPAhHCJrf47w/5eTPUQncPs3R5 D3mk9UowG0+1mT5i57aRlQKxmqEd1xOVYkpM8tE4Ehk09qInSmmub3VU60Mb7llRn+o1 qQXo+QDPsAyPYr5jrRjz1LLbljVa7BqW5sn3f0wukWc6+je9gbdRIV8DUwZdjoZakScT Bhsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768081680; x=1768686480; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:subject:user-agent:mime-version:date:message-id:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=046XaQZFAu8wvEAuybB5UMKwHOUklXTERb1ZGpwxEns=; b=v04Mgjz2kaIDegqTyxGpRED5Rn/GQ+2spHjv7zPCZG/C2d35SWxRskT8NBgrKEdsL5 MpOIntmo5lBIsDGTMencO6qTalEt+f1VkGN+0IGQY4c6Okh3cLi4NUfI2+vvVJ0JhEK9 JuaF39GNXyswMes/NCuMXFrAx1nLTheYUwl9AHPy1C3ljIkJdWiBenK65dI3E/3Dh9oi 1uknSHSfG4eaze6+yQ1pVus+TrJ3G5seSgKLTy7VEUHcyP6zkkNQ4dPvDHA8RK5EJrlK sh7X2mCaZaCY0KF9rSlKDMaXwZx+X+IdJdsVkEEEJVOErkpffeE2W80dDugWpGGUyjeH /jYQ== X-Forwarded-Encrypted: i=1; AJvYcCUA5WFcPP3wy6P4lOjLHkaz0S7BUtxERBHXdfEN9XKuwA4GROTJcLJ+OX2f4/uQhudlFM8B69g5iHNq1VY=@vger.kernel.org X-Gm-Message-State: AOJu0YxL9jkeg63nkQ7qSf1hOMif/qQl+MaiGPNBJb57fxZq7MDkk7V6 uu5anNxFE3NRRgWEwGZJanbpOUXMbidOb41XI17FEjuTU9owaehvF+zgRXY9aSyKs6sxp+gA1j9 NO1/s7yrdFOZrTrUqgFhZ5LBwIIX8+guMnkoOgA7AXwkGx/B7SRUPJCwbKBMdSalU/0Qe+idWug == X-Gm-Gg: AY/fxX5I+kSi61P5Oa+m6eceQEZDXe0JQpd+UclMOYvf8EkjCvghaNsPRSNqDhEgwws 2cZKIaY/ZTkCqUclpOH3JZw8Mn+EJhyoBIPqpt4aB1g+KcVVLDV1/ZLE+3NBs1xFXsd5k1Xx/gi omC4eJL8LQk51yphL1NzDQHQ0tAyCdQ8GOD/wF4B2LHqhamMJPnxnPZ/+bsZpmVl4HJrZrBQ5qj icfTs+s1HDdraykWhkCdHTQu32bhMg/lhg6BtldTbT1Q+lNF7KI7XZpopVbVpm6Wy4EyAjXpRn/ tebSGjSVJK1i0Fn8XNYms1ADOcOssVqmFKAWTY4ah0Bh8eIKQ8nwH0I0DiPZ26iMloJ+Nkl3iL8 q0JF3rbFB2TMTL9QsfuJZOODGux7uAToTzjjRmj3pMo/GbW4QROuYUDwF X-Received: by 2002:ad4:4bca:0:b0:890:811c:16d9 with SMTP id 6a1803df08f44-8908424f388mr141000596d6.35.1768081680476; Sat, 10 Jan 2026 13:48:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqa/3EIlrrQmROvvSM1H5fKER/EbV32WZRI2pHHklaF5oYvOg0tNb2w/JZbDah9Xf2BIYWDw== X-Received: by 2002:ad4:4bca:0:b0:890:811c:16d9 with SMTP id 6a1803df08f44-8908424f388mr141000496d6.35.1768081680082; Sat, 10 Jan 2026 13:48:00 -0800 (PST) Received: from ?IPV6:2601:188:c102:b180:1f8b:71d0:77b1:1f6e? ([2601:188:c102:b180:1f8b:71d0:77b1:1f6e]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-890770d17a3sm104961296d6.9.2026.01.10.13.47.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Jan 2026 13:47:59 -0800 (PST) From: Waiman Long X-Google-Original-From: Waiman Long Message-ID: <9c0791ea-edb7-44b3-b8ec-ae0452400497@redhat.com> Date: Sat, 10 Jan 2026 16:47:58 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] irqchip/gic-v3-its: Don't acquire rt_spin_lock in allocate_vpe_l1_table() To: Marc Zyngier Cc: Thomas Gleixner , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev References: <20260107215353.75612-1-longman@redhat.com> <864iowmrx6.wl-maz@kernel.org> Content-Language: en-US In-Reply-To: <864iowmrx6.wl-maz@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/8/26 3:26 AM, Marc Zyngier wrote: > On Wed, 07 Jan 2026 21:53:53 +0000, > Waiman Long wrote: >> When running a PREEMPT_RT debug kernel on a 2-socket Grace arm64 system, >> the following bug report was produced at bootup time. >> >> BUG: sleeping function called from invalid context at kernel/locking/spinlock_rt.c:48 >> in_atomic(): 1, irqs_disabled(): 1, non_block: 0, pid: 0, name: swapper/72 >> preempt_count: 1, expected: 0 >> RCU nest depth: 1, expected: 1 >> : >> CPU: 72 UID: 0 PID: 0 Comm: swapper/72 Tainted: G W 6.19.0-rc4-test+ #4 PREEMPT_{RT,(full)} >> Tainted: [W]=WARN >> Call trace: >> : >> rt_spin_lock+0xe4/0x408 >> rmqueue_bulk+0x48/0x1de8 >> __rmqueue_pcplist+0x410/0x650 >> rmqueue.constprop.0+0x6a8/0x2b50 >> get_page_from_freelist+0x3c0/0xe68 >> __alloc_frozen_pages_noprof+0x1dc/0x348 >> alloc_pages_mpol+0xe4/0x2f8 >> alloc_frozen_pages_noprof+0x124/0x190 >> allocate_slab+0x2f0/0x438 >> new_slab+0x4c/0x80 >> ___slab_alloc+0x410/0x798 >> __slab_alloc.constprop.0+0x88/0x1e0 >> __kmalloc_cache_noprof+0x2dc/0x4b0 >> allocate_vpe_l1_table+0x114/0x788 >> its_cpu_init_lpis+0x344/0x790 >> its_cpu_init+0x60/0x220 >> gic_starting_cpu+0x64/0xe8 >> cpuhp_invoke_callback+0x438/0x6d8 >> __cpuhp_invoke_callback_range+0xd8/0x1f8 >> notify_cpu_starting+0x11c/0x178 >> secondary_start_kernel+0xc8/0x188 >> __secondary_switched+0xc0/0xc8 >> >> This is due to the fact that allocate_vpe_l1_table() will call >> kzalloc() to allocate a cpumask_t when the first CPU of the >> second node of the 72-cpu Grace system is being called from the >> CPUHP_AP_MIPS_GIC_TIMER_STARTING state inside the starting section of > Surely *not* that particular state. My mistake, it should be CPUHP_AP_IRQ_GIC_STARTING. There are three static gic_starting_cpu() functions that confuse me. >> the CPU hotplug bringup pipeline where interrupt is disabled. This is an >> atomic context where sleeping is not allowed and acquiring a sleeping >> rt_spin_lock within kzalloc() may lead to system hang in case there is >> a lock contention. >> >> To work around this issue, a static buffer is used for cpumask >> allocation when running a PREEMPT_RT kernel via the newly introduced >> vpe_alloc_cpumask() helper. The static buffer is currently set to be >> 4 kbytes in size. As only one cpumask is needed per node, the current >> size should be big enough as long as (cpumask_size() * nr_node_ids) >> is not bigger than 4k. > What role does the node play here? The GIC topology has nothing to do > with NUMA. It may be true on your particular toy, but that's > definitely not true architecturally. You could, at worse, end-up with > one such cpumask per *CPU*. That'd be a braindead system, but this > code is written to support the architecture, not any particular > implementation. > It is just what I have observed on the hardware that I used for reproducing the problem. I agree that it may be different in other arm64 CPUs. >> Signed-off-by: Waiman Long >> --- >> drivers/irqchip/irq-gic-v3-its.c | 26 +++++++++++++++++++++++++- >> 1 file changed, 25 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c >> index ada585bfa451..9185785524dc 100644 >> --- a/drivers/irqchip/irq-gic-v3-its.c >> +++ b/drivers/irqchip/irq-gic-v3-its.c >> @@ -2896,6 +2896,30 @@ static bool allocate_vpe_l2_table(int cpu, u32 id) >> return true; >> } >> >> +static void *vpe_alloc_cpumask(void) >> +{ >> + /* >> + * With PREEMPT_RT kernel, we can't call any k*alloc() APIs as they >> + * may acquire a sleeping rt_spin_lock in an atomic context. So use >> + * a pre-allocated buffer instead. >> + */ >> + if (IS_ENABLED(CONFIG_PREEMPT_RT)) { >> + static unsigned long mask_buf[512]; >> + static atomic_t alloc_idx; >> + int idx, mask_size = cpumask_size(); >> + int nr_cpumasks = sizeof(mask_buf)/mask_size; >> + >> + /* >> + * Fetch an allocation index and if it points to a buffer within >> + * mask_buf[], return that. Fall back to kzalloc() otherwise. >> + */ >> + idx = atomic_fetch_inc(&alloc_idx); >> + if (idx < nr_cpumasks) >> + return &mask_buf[idx * mask_size/sizeof(long)]; >> + } > Err, no. That's horrible. I can see three ways to address this in a > more appealing way: > > - you give RT a generic allocator that works for (small) atomic > allocations. I appreciate that's not easy, and even probably > contrary to the RT goals. But I'm also pretty sure that the GIC code > is not the only pile of crap being caught doing that. > > - you pre-compute upfront how many cpumasks you are going to require, > based on the actual GIC topology. You do that on CPU0, outside of > the hotplug constraints, and allocate what you need. This is > difficult as you need to ensure the RD<->CPU matching without the > CPUs having booted, which means wading through the DT/ACPI gunk to > try and guess what you have. > > - you delay the allocation of L1 tables to a context where you can > perform allocations, and before we have a chance of running a guest > on this CPU. That's probably the simplest option (though dealing > with late onlining while guests are already running could be > interesting...). > > But I'm always going to say no to something that is a poor hack and > ultimately falling back to the same broken behaviour. Thanks for the suggestion. I will try  the first alternative of a more generic memory allocator. Cheers, Longman > > Thanks, > > M. >