From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 CC3423A4F51 for ; Wed, 13 May 2026 05:35:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778650543; cv=none; b=X1R+sLteFN10Cwzy2QXS++/ryjnwHqtOmG4xG0uCdiOao+RdomsTDLKwGb20G3lJHLfSHIgbANz4OOvWbJpeqmvw54Iafg9gkdjcECHWRo41HFEjPzUO9Vx6Z9xzJVtkflpuuRJOI+cNXZIz8rPgCFTnxi7n5yRuk7R3VbmRo1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778650543; c=relaxed/simple; bh=hnWneg4mEjP9WTzCNkuXt025lZvokzBRcLSrcOGpCnA=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=ZyzMFua84tbiqpcAOxke1QBnPwBdieWysJbRwWaVXo7Y/TVNb+umcWQSallOEVdLEF3P7yroJbhv696XcISjVqFfGxB0/NyDXvAQhNF/D14CMPdr4aLosSgboONHmRwiNaNOevAaRtBl+UkRjECLfAcp0OyXHEA5JebHw7i+E5c= 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=VndogxBT; arc=none smtp.client-ip=148.163.158.5 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="VndogxBT" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 64D23AZc3775682; Wed, 13 May 2026 05:35:35 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=zcoiNG 9cEyP+nL4uxgFRnI+EezDV+bgUmox8t27Hpfo=; b=VndogxBTAo/YRD2Fv12IXU XwqzVbxsxgro0V20kUk2HEeMNVEmPNjDBSFaCNqXnaTylWBdK8tD64QunZHucKHk XHb+JNE/EpocfIpLeaGycefZzxK+9Z4EUObO5Odo9QYv+GWlgDEzBaRD9Yth1cZ7 Jq/GAtwDB7cTsN1oD3k6OBWc4EcwnjG+9n7vP2J9UTzUxUS4vgWRBG8Pt5pfz6Fg qeSYCLIhUqKgnuAEhLg7tyKSGBQA58Yc29ssqOIMmLrirgsvQTf+7QdJ95VoD2YW FIrXaJCaG4wTixXrEHwGd5l9Oa7KZ1L2/se8ky8BTls00OJ1OAC9qc3BQlSqWnZQ == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4e3nv6nx1b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 05:35:34 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.7/8.18.1.7) with ESMTP id 64D5OR5m031964; Wed, 13 May 2026 05:35:33 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4e3nfgpbhn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 13 May 2026 05:35:33 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 64D5ZUBc49086728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 13 May 2026 05:35:30 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6D1320040; Wed, 13 May 2026 05:35:29 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C0632004B; Wed, 13 May 2026 05:35:28 +0000 (GMT) Received: from [9.39.28.2] (unknown [9.39.28.2]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 13 May 2026 05:35:28 +0000 (GMT) Message-ID: Date: Wed, 13 May 2026 11:05:27 +0530 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 1/3] powerpc/time: remove preempt_disable/enable from arch_irq_work_raise() To: "Ritesh Harjani (IBM)" , Sayali Patil , linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com Cc: linux-kernel@vger.kernel.org, Mahesh Salgaonkar , chleroy@kernel.org References: From: Shrikanth Hegde Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=KbvidwYD c=1 sm=1 tr=0 ts=6a040da6 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=IkcTkHD0fZMA:10 a=NGcC8JguVDcA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=pGLkceISAAAA:8 a=v7GjVOmr5oXViBslm-QA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNTEzMDA0OSBTYWx0ZWRfX7qlmWm6eKoy5 GI3SLg/3J/ripKfqpaoZNoGckZ4AThDaO8cJkSypTqFRzqhs1/bXr/o5tN7NY1BAI7iiDMDeKUu XQOXRuhLfEyDXcG5GQUHgKzcG+lJOl26/G8Y60yI594BO0YT9dQ9EHH9dj3CezZZUynjAtVfqcR 6t3S5aOUDmeGmj9K2FbYN7lRQTRMvEaPRWFEgssURV30qaWcKziB2TAhzy97lnG8uKYMaCK2r2C +aSlHSWPuTcEgrKMa2CUzqN0CCf1yBfukLrefpS4G8cVGxsmysjOil7ScIEL7uTXkUhp5wsGT0o 7TeS9OnvzYwdsmFL2y7wInUdFU7CehoCOOXNEOtgmURJ+iNtppDO6p/bFUReXVOcoZvXVdvSaKI /va++DYSbN54h3N9sDUet1GR5MxzvW+4hAGrLJBffGQEh+dZwU+l8PGDRuTJKKid0atCnGo8Udd fKkn6K1XY6rywR66toQ== X-Proofpoint-GUID: D_itOF8TvEN-EncmPBTqyJg8dpN8gcKu X-Proofpoint-ORIG-GUID: U3lz9non03QtN8HWEx95oSypQv83MXK7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-05-11_05,2026-05-08_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 clxscore=1015 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2605050000 definitions=main-2605130049 On 5/13/26 10:00 AM, Ritesh Harjani (IBM) wrote: > Sayali Patil writes: > >> A kernel panic is observed when handling machine check exceptions from >> real mode. >> >> BUG: Unable to handle kernel data access on read at 0xc00000006be21300 >> Oops: Kernel access of bad area, sig: 11 [#1] >> NIP [c000000000029e40] arch_irq_work_raise+0x10/0x70 >> LR [c00000000003ffc8] machine_check_queue_event+0xa8/0x150 > > [14626.841925] MSR: 8000000000001003 CR: 88222248 XER: 00000005 > [14626.841939] CFAR: c00000000003ffc4 DAR: c00000006be21300 DSISR: 40000000 IRQMASK: 0 > > > Let's also add the above MSR state along with the call stack showing > MSR[EE] was 0 when this triggered. This also shows the DAR as 0xc.... > while MSR[IR|DR] = 0. > >> Call Trace: >> [c0000000179d3c70] [c00000000003ff64] machine_check_queue_event+0x44/0x150 >> [c0000000179d3d30] [c0000000000084e0] machine_check_early_common+0x1f0/0x2c0 >> >> The crash occurs because arch_irq_work_raise() calls preempt_disable() >> from machine check exception (MCE) handlers running in real mode. In >> this context, accessing the preempt_count can fault, leading to the panic. >> >> The preempt_disable()/preempt_enable() pair in arch_irq_work_raise() >> was originally added by commit 0fe1ac48bef0 ("powerpc/perf_event: Fix >> oops due to perf_event_do_pending call") to avoid races while raising >> irq work from exception context. >> >> Later, commit 471ba0e686cb ("irq_work: Do not raise an IPI when >> queueing work on the local CPU") added preemption protection in >> irq_work_queue() path, while commit 20b876918c06 ("irq_work: Use per >> cpu atomics instead of regular atomics") added equivalent >> protection in irq_work_queue_on() before reaching arch_irq_work_raise(): >> >> irq_work_queue() / irq_work_queue_on() >> -> preempt_disable() >> -> __irq_work_queue_local() >> -> irq_work_raise() >> -> arch_irq_work_raise() >> >> As a result, callers other than mce_irq_work_raise() already execute >> with preemption disabled, making the additional >> preempt_disable()/preempt_enable() pair in arch_irq_work_raise() >> redundant. >> >> Remove it to avoid accessing preempt_count from real mode context. >> >> Fixes: cc15ff327569 ("powerpc/mce: Avoid using irq_work_queue() in realmode") > > Agree with the Fixes tag. This patch actually moved mce to use > arch_irq_work_raise(). It was ok until the CONFIG_PREEMPTION was > disabled on powerpc since macros like preempt_enable|disable() were > mostly a no-op. However, after lazy preemption got enabled, access to Both full/lazy preemption. With upstream now, one can choose full or lazy only. Leading to issue being discovered. > preempt_count while in real mode can cause the issue you described. > > > One more thing which we should add to the commit msg is: > The arch_irq_work_raise() function executes in NMI context when called > from MCE handler, hence we won't be preempted or scheduled out since we > are in NMI context with MSR[EE]=0, hence it is safe to remove > preempt_disable|enable() call from here. > > And let's change the commit subject to: > powerpc/time: Remove redundant preempt_disable|enable() calls from arch_irq_work_raise() > > > BTW, thanks for adding a nice commit msg with the sequence of events. > With the above changes - pease feel free to add: > > Reviewed-by: Ritesh Harjani (IBM) > > >> Suggested-by: Mahesh Salgaonkar >> Signed-off-by: Sayali Patil >> --- >> arch/powerpc/kernel/time.c | 2 -- >> 1 file changed, 2 deletions(-) >> >> diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c >> index 4bbeb8644d3d..a99eb43f6ce9 100644 >> --- a/arch/powerpc/kernel/time.c >> +++ b/arch/powerpc/kernel/time.c >> @@ -471,10 +471,8 @@ void arch_irq_work_raise(void) >> * which could get tangled up if we're messing with the same state >> * here. >> */ >> - preempt_disable(); >> set_irq_work_pending_flag(); >> set_dec(1); >> - preempt_enable(); >> } >> >> static void set_dec_or_work(u64 val) >> -- >> 2.52.0