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 6F4713E3140 for ; Tue, 30 Jun 2026 06:15:36 +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=1782800137; cv=none; b=ppXyBSf3S1068iBs/PIYuBEzv12x93E6tNVykB+PDCqlIafbKXakFIvtC/gFoj6+H4Sf3ja65KoJYn4atWIuLK9PlnP9aslFw6w7k5xWRSydjhJMoxLLUZstqZtjcRGv1oIQ3/s6OWNYF72GkjTy4j8fveCU/37J6zWkEE6SfOY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782800137; c=relaxed/simple; bh=x+zZFFfB2pWCH0scPL4Yc+Tj2V3py00zW+fHFof0zbM=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=X2ivd7EHt/ZszS5QbdC2jCiznGT88I3zOvjhc31trRqiGrixKG/3CorfGDHfHAlDNhL2ZLXk64F2e0Qh4CWe97OybIGmGHVD4koIlS3A1GQyo5ukxTZ/fYyhhKS8P1MX4nOvcijYBSgzcEghscq2UGF6Ey9F2m5qRPjG1WjAfOU= 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=gYIEa4KB; 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="gYIEa4KB" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1782800135; 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=0X7/Y7E7vQEfhK/VFN32DkxAjU/cN6PNjZbhEip+Zlc=; b=gYIEa4KBy+S89YWysGb8JLMmjDQA/vjwluPhIsMoyXvXNtZcd2MkWzLwPEiKIoCT+jzbLT 45yXUGrDfjXc79xhkQBnAkKN7AdMlg8lcXzwagRDb4Or75SXUWlMz9GvoOFKLhHd1R01Rx /cnlZfZTCL7+ccMvhdpKgpGuW8LQuaU= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-588-yC0FCb6vMcOeyBh5qCTfuA-1; Tue, 30 Jun 2026 02:15:32 -0400 X-MC-Unique: yC0FCb6vMcOeyBh5qCTfuA-1 X-Mimecast-MFC-AGG-ID: yC0FCb6vMcOeyBh5qCTfuA_1782800131 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 64D391800A3C; Tue, 30 Jun 2026 06:15:30 +0000 (UTC) Received: from [10.2.16.38] (unknown [10.2.16.38]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 658EF3000B4D; Tue, 30 Jun 2026 06:15:28 +0000 (UTC) Message-ID: <905b4d0f-3687-4d06-b344-726daa3005f2@redhat.com> Date: Tue, 30 Jun 2026 02:15:27 -0400 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] locking/lockdep: skip irq save/restore in hardirq context in lock_release() From: Waiman Long To: Deepanshu Kartikey Cc: peterz@infradead.org, mingo@redhat.com, will@kernel.org, boqun@kernel.org, linux-kernel@vger.kernel.org, syzbot+0635dc2e2c3c21a6aa04@syzkaller.appspotmail.com References: <20260629041119.87790-1-kartikey406@gmail.com> <3df76993-ae50-4c28-a78e-fbd1db53e9a0@redhat.com> Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 On 6/30/26 12:57 AM, Waiman Long wrote: > On 6/29/26 7:44 PM, Deepanshu Kartikey wrote: >> On Mon, Jun 29, 2026 at 10:57 AM Waiman Long wrote: >>> >>> On 6/29/26 12:11 AM, Deepanshu Kartikey wrote: >>>> lock_release() performs a raw_local_irq_save/restore dance around its >>>> validation work. While safe in process and softirq context, this is >>>> dangerous in hardirq context where IRQs must remain disabled for the >>>> entire duration of the handler. >>>> >>>> When lock_release() calls raw_local_irq_restore() inside a hardirq >>>> handler, it briefly re-enables IRQs, creating a window where a new >>>> interrupt can fire before the handler returns. This was observed with >>>> taprio's advance_sched() hrtimer callback - the temporary IRQ >>>> re-enablement inside lock_release() prevented CPU 0 from acknowledging >>>> a pending TLB flush IPI sent by CPU 1 via smp_call_function_many(). >>>> CPU 1 then spun indefinitely in csd_lock_wait(), starving the RCU >>>> grace-period kthread and triggering an RCU stall with eventual OOM. >>> Where exactly is the temporary window when interrupt is enabled during >>> the raw_local_irq_restore() call? Interrupt handling is arch specific. >>> Is it specific to certain architectures? >> On x86, raw_local_irq_restore() executes the 'sti' instruction which >> immediately re-enables IRQs. Inside lock_release(), after the validation >> work completes, calling raw_local_irq_restore() with the saved flags >> will execute 'sti' even when called from hardirq context. >> >> The window is between the 'sti' instruction (which re-enables IRQs) and >> the return from lock_release(). During this window, a new interrupt can >> fire and hijack the CPU before the hardirq handler can return and >> acknowledge pending IPIs. >> >> In the syzkaller trace, this window allowed a new IRQ to fire on CPU 0 >> after lock_release()'s sti, preventing CPU 0 from ever acknowledging >> the TLB flush IPI sent by CPU 1, causing CPU 1 to spin indefinitely in >> csd_lock_wait(), which starved the RCU grace-period kthread. >> >> The fix is correct on all architectures - hardirq context must never >> restore IRQs mid-handler since the hardware manages IRQ state for >> interrupt entry/exit. This is why we conditionally skip the >> irq_save/restore dance when in_hardirq() is true. > > I looked at the generated code of raw_local_irq_restore(): > > ./arch/x86/include/asm/irqflags.h: > 146        return !(flags & X86_EFLAGS_IF); >    0x00000000000082b9 <+9>:    test   $0x200,%edi >    0x00000000000082bf <+15>:    je     0x82c2 > > 42        asm volatile("sti": : :"memory"); >    0x00000000000082c1 <+17>:    sti > > kernel/cgroup/cpuset.c: > 4553    } >    0x00000000000082c2 <+18>:    jmp    0x82c7 > > sti should only be called if the saved flags has the IF bit set. In > hardirq context, the IF bit shouldn't be set. Is my interpretation > correct? Or is it because x86 can speculatively execute an sti instruction even if it is the wrong branch and there is a small window that interrupt is enabled before it is rolled back? Cheers, Longman