From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87F3739659F for ; Mon, 16 Mar 2026 13:19:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773667187; cv=none; b=TiNg6knqBlU0OO11IYPCMVLX3C+J2y3l8jA5KCj8VqZHtwnehRyoeO7glT91QErobe0eNQ+vyQCo7tVOrEuJI53HnW+3ieV+MxFg0BEi4ngG54dq2V2Fyr2Ofoc8YuHAPx8UU1IE/h6BbixFgO44XYxomOYuKGzScqAuZYzAiyI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773667187; c=relaxed/simple; bh=C/H+TBBfu3Qjm4dPe+82YtksFTvsUEbO98NuROuWH3w=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=j9dL/qRbrEZaw9jDGcbGKOIcPSr2x2pOgJuKTaaIHtn5H4eiaengsMyw3Dw2OS4jDHkoSHrT0YIzyLcDZRrfUopphNt27FKJ030V2EVMpK4jySydj3Vb8Yt3Q4/zpSky0ju9KZI0G/kLgsb4B+WsJuW2wSMwb6DppzOO1Gjun5M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=mX0Js6WX; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="mX0Js6WX" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-463f00cda04so2717828b6e.2 for ; Mon, 16 Mar 2026 06:19:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1773667185; x=1774271985; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fcUQdthu3w3MmzOBiSvMw8yvWhLEb2QVxffY5zYz7z0=; b=mX0Js6WXc1Nge0PbGIs9uvSNioi2ZTZzKSrZUiu9QS7mYNYC+bLHrJX8HFXxmP3V4q Zs1hRRt4PYcTmytcTdp9prwxG05klUJM6/8XSPJi6XyudwpSxpKBp4CWZ9WJxuMUUO3s xD+dDQIctEP5rYOb7/4KggH2wtXLIWlQDtD0vPAHL4eQf02S2Cjonc0VoVXBm9G+bn+J qpwFPTFSNChpaKkYC1vRD1kd6LygLoVfxXW4ZoYyq0RcKyhVOmhOwn2rkecGHqPJe5Zr fpJ3hmQvIJc4BMfDkA3ZxmVVHO/VWpVWBl5raFR0ZALE2CHewV+jc/AyRswMKzQprauB eb3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773667185; x=1774271985; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fcUQdthu3w3MmzOBiSvMw8yvWhLEb2QVxffY5zYz7z0=; b=PqB955MOUNfg+0R5jpyklJ+3BLqj7nnNF4BROp+N/6lZs62wmft28HjRiq9yeLK6fA 2LPZpQQj3MtLiY2Q1FS5Cs7HjKLvdLeVWlDNu5qwtqG5YsZhD1GSC+pn/NnA4GkVMbpo K7JqScPxqr3oGWNAHiri1in0qxLhOVrJUl2RtBL8rAEvU07kJQhaBfL4tpzjn2TY87AA C2IhLBrU6Zm9pr4L2/zQRe6rg4m2viyW/I6DakRiRsgJKw605rkQOqJ1lVHpMkDN0oGF uwgyBybqpig4mz6srsgOSSioe7jV1kzRMhUbzAZeARKFh8IW/VFqUIyuaSC+Y51ejB40 4RDg== X-Forwarded-Encrypted: i=1; AJvYcCW62YCZh0+IMbve1vbXG8j/PGt2Wty7xfzeC9sEsqvHRunDSRl3+iUKWiXquocTJnTduS6YLnaAhwnjJis=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/noUb9udfmAm32Qe8psHn/b3dp+PLrWchvCVwE3AodaBnBR+p 4jz2Z7wcCKoMWOqTA3Ds6RlL2bUDnzh5i9Yxi3tDfUXUJ7QRb0T0+yVXA52GT8yk0u0= X-Gm-Gg: ATEYQzx3h3ySuyz6V+TQ8myYcqFzHypOGLRvHyhO5MYaDMVUbCEQBMPgtBB+2qvEWja vlyQ0F9i+7P6kXF14MgCRWU8aJgq4Ov/5DkSWPZ0NxW/X6d11OhSMJNkx1a/nND5+J83A5akG/p zCMSoEIgrRPU5JZaeQcGW4lK2P3CT65Rq9xfx3KjiBOphgrLleHUZOqZfnnBEqc6Y6O6iQMF37R VQoKrD0XnABM/zG3de7Jf6oZTPweSZ2YaPoZUpqI/owv9f3zP7A9aOLXsV319PGNAehJH7pWWm9 +KdNCEV0vBcP94gu25i1xykI3Jxk+V0j01nn6WiQeUfY6CA94YnAe7NHKWvVoeXB+BzUKCvdNQp dk5kr3mW8HHs2TJlV//IZZCqxzIE+CPJ8WpUYu2j2UWhzujJHPIqpmenz/ZNwHUQWMxDf3KvQeY Jh8Idj5HS0XzVq+mHR84XYTA9d+yG3Okhzd65VzfPY X-Received: by 2002:a05:6808:a596:20b0:467:1ad3:7ee with SMTP id 5614622812f47-4675753157fmr5424703b6e.40.1773667185289; Mon, 16 Mar 2026 06:19:45 -0700 (PDT) Received: from [100.64.0.1] ([170.85.103.33]) by smtp.gmail.com with ESMTPSA id 5614622812f47-46734164245sm9151715b6e.8.2026.03.16.06.19.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 16 Mar 2026 06:19:44 -0700 (PDT) Message-ID: Date: Mon, 16 Mar 2026 08:19:44 -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 RFC] riscv: disable local interrupts and stop other CPUs before restart To: Troy Mitchell , Vivian Wang , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260311-v7-0-rc1-rv-dis-int-before-restart-v1-1-bc46b4351cac@linux.dev> From: Samuel Holland Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Troy, On 2026-03-16 2:23 AM, Troy Mitchell wrote: > On Thu Mar 12, 2026 at 11:05 AM CST, Vivian Wang wrote: >> On 3/11/26 10:51, Troy Mitchell wrote: >>> Currently, the RISC-V implementation of machine_restart() directly calls >>> do_kernel_restart() without disabling local interrupts or stopping other >>> CPUs. This missing architectural setup causes fatal issues for systems >>> that rely on external peripherals (e.g., I2C PMICs) to execute the system >>> restart when CONFIG_PREEMPT_RCU is enabled. >>> >>> When a restart handler relies on the I2C subsystem, the I2C core checks >>> i2c_in_atomic_xfer_mode() to decide whether to use the sleepable xfer >>> or the polling atomic_xfer. This check evaluates to true if >>> (!preemptible() || irqs_disabled()). >>> >>> During do_kernel_restart(), the restart handlers are invoked via >>> atomic_notifier_call_chain(), which holds an RCU read lock. >>> The behavior diverges based on the preemption model: >>> 1. Under CONFIG_PREEMPT_VOLUNTARY or CONFIG_PREEMPT_NONE, rcu_read_lock() >>> implicitly disables preemption. preemptible() evaluates to false, and >>> the I2C core correctly routes to the atomic, polling transfer path. >>> 2. Under CONFIG_PREEMPT_RCU, rcu_read_lock() does NOT disable preemption. >>> Since machine_restart() left local interrupts enabled, irqs_disabled() >>> is false, and preempt_count is 0. Consequently, preemptible() evaluates >>> to true. >>> >>> As a result, the I2C core falsely assumes a sleepable context and routes >>> the transfer to the standard master_xfer path. This inevitably triggers a >>> schedule() call while holding the RCU read lock, resulting in a fatal splat: >>> "Voluntary context switch within RCU read-side critical section!" and >>> a system hang. >>> >>> Align RISC-V with other major architectures (e.g., ARM64) by adding >>> local_irq_disable() and smp_send_stop() to machine_restart(). >>> - local_irq_disable() guarantees a strict atomic context, forcing sub- >>> systems like I2C to always fall back to polling mode. >>> - smp_send_stop() ensures exclusive hardware access by quiescing other >>> CPUs, preventing them from holding bus locks (e.g., I2C spinlocks) >>> during the final restart phase. >> >> Maybe while we're at it, we can fix the other functions in this file as >> well? > Nice catch. I'll fix other functions in the next version. >> >> I think the reason we ended up with the "unsafe" implementations of the >> reboot/shutdown functions is that on the backend it is usually SBI SRST >> calls, which can protect itself from other CPUs and interrupts. Since on >> K1 we're going to be poking I2C directly, we run into the problem >> described above. So all of these should disable interrupts and stop >> other CPUs before calling the handlers, and can't assume the handlers >> are all SBI SRST. > Yes, we cannot assume that all platforms rely on this. Why isn't K1 using the SBI SRST extension? Resetting the platform from S-mode directly causes problems if you ever want to run another supervisor domain (for example a TEE or EFI runtime services), which may need to clean up before a system reset. As you mention, other platforms use the standard SBI SRST interface, event if they need to poke a PMIC to perform a system reset. Is there something preventing K1 from following this path? Regards, Samuel