Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xtensa High priority interrupts cannot be masked during initialization #40974

Closed
hongshui3000 opened this issue Dec 8, 2021 · 3 comments
Closed
Assignees
Labels
area: Xtensa Xtensa Architecture bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug

Comments

@hongshui3000
Copy link
Contributor

hongshui3000 commented Dec 8, 2021

Describe the bug
High priority interrupts cannot be masked during initialization

Once the high-priority interrupt is enabled later before the interrupt stack is initialized and the interrupt occurs again, there will be issues.

XCHAL_EXCM_LEVEL cannot disable all interrupts, unless the architecture does not have high priority interrupts, we can leave only debug interrupts and NMI interrupts

file :crt1.s

# ifdef __XTENSA_CALL0_ABI__
	/*
	 * PS.WOE = 0
	 * PS.UM = 1
	 * PS.EXCM = 0
	 * PS.INTLEVEL = XCHAL_EXCM_LEVEL
	 */
	movi	a3, PS_UM|PS_INTLEVEL(XCHAL_EXCM_LEVEL)
# else
	/*
	 * PS.WOE = 1
	 * PS.UM = 1
	 * PS.EXCM = 0
	 * PS.INTLEVEL =XCHAL_EXCM_LEVEL
	 */
	movi	a3, PS_UM|PS_WOE|PS_INTLEVEL(XCHAL_EXCM_LEVEL)
# endif

My fix

#if XCHAL_HAVE_EXCEPTIONS
# ifdef __XTENSA_CALL0_ABI__
	/*
	 * PS.WOE = 0
	 * PS.UM = 1
	 * PS.EXCM = 0
	 * PS.INTLEVEL = XCHAL_DEBUGLEVEL-1
	 */
	movi	a3, PS_UM|PS_INTLEVEL(XCHAL_DEBUGLEVEL-1)
# else
	/*
	 * PS.WOE = 1
	 * PS.UM = 1
	 * PS.EXCM = 0
	 * PS.INTLEVEL = XCHAL_DEBUGLEVEL-1
	 */
	movi	a3, PS_UM|PS_WOE|PS_INTLEVEL(XCHAL_DEBUGLEVEL-1)
# endif

The same here uses XCHAL_EXCM_LEVEL. Some architectures also cannot disable high-priority interrupts.
I suggest using XCHAL_NUM_INTLEVELS -1 or XCHAL_DEBUGLEVEL-1, which may be better

static ALWAYS_INLINE unsigned int arch_irq_lock(void)
{
	unsigned int key;

	__asm__ volatile("rsil %0, %1"
			 : "=r"(key) : "i"(XCHAL_EXCM_LEVEL) : "memory");
	return key;
}

image

zephyr V2.7

@hongshui3000 hongshui3000 added the bug The issue is a bug, or the PR is fixing a bug label Dec 8, 2021
@carlescufi carlescufi added area: Xtensa Xtensa Architecture priority: medium Medium impact/importance bug labels Dec 10, 2021
@andyross
Copy link
Contributor

This is the same comment from a different bug: That's not a Zephyr interrupt. It's not a Zephyr handler. If you want to interrupt the OS at arbitrary times with an interrupt that it does not mask, you need to write a safe handler for that interrupt.

I don't know what you want the OS to do for you?

@hongshui3000
Copy link
Contributor Author

hongshui3000 commented Jan 21, 2022

These are the xtensa arch code, it exists in zephyr, I think it should be reusable by most of the xtensa architecture, so I think this should be part of the zephyrrtos xtensa architecture.

I don't know what you want the OS to do for you?

The zephyrrtos xtensa architecture should support high priority interrupts or warn the user that it is not currently supported.
At present, it will affect the user's judgment on the stability of zephyrrtos. If the user uses a high-priority interrupt, it will easily fall into this trap, and the error is difficult to debug (random crashes may occur)

@andyross
Copy link
Contributor

I'm going to close this one, as it's effectively a duplicate of #41039

Zephyr doesn't have a solution currently for applications registering interrupts at or beyond EXCM_LEVEL. It would be a good feature if we had it, but we don't yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Xtensa Xtensa Architecture bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

No branches or pull requests

3 participants