public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Richard Earnshaw <Richard.Earnshaw@foss.arm.com>
To: Srinath Parvathaneni <srinath.parvathaneni@arm.com>,
	newlib@sourceware.org
Cc: Richard Earnshaw <Richard.Earnshaw@arm.com>, nd <nd@arm.com>
Subject: Re: [PATCH v2][Newlib] arm: Restrict processor mode change when in hypervisor mode.
Date: Thu, 2 Mar 2023 13:05:22 +0000	[thread overview]
Message-ID: <409759de-41a3-2f52-e7d3-f74582f59efe@foss.arm.com> (raw)
In-Reply-To: <33476d31-2d9d-3aee-cd60-7f70e256e3dd@arm.com>



On 23/02/2023 17:10, Srinath Parvathaneni wrote:
> Hi All,
> 
> In _stack_init function of crt0.S file, when the current mode is not 
> user mode,
> all the processor modes are parsed and the corresponding stack limit are 
> set for
> these modes for all A-profile and R-profile CPU's. But when the current 
> processor
> mode is hypervisor mode, changing to any other mode using CPSR will 
> result in an
> illegal instruction as per Arm-arm and simulator throws undefined 
> instruction
> exception.

The reference to a simulator here is confusing.  You might have found 
this on one, but it's a reflection of the way the architecture is 
specified and not specific to running under simulation.

> This patch prevent the change of hypervisor mode to any other mode in 
> _stack_init
> function in crt0.S files.
> 
> Regression tested on arm-none-eabi target for newlib and newlib-nano and 
> found
> no regressions.
> 
> Ok for newlib master?
> 
> Regards,
> Srinath.
> 
> libgloss/ChangeLog:
> 
> 2023-02-23  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>
> 
>          * arm/crt0.S (_stack_init): Add check for hypervisor mode.
> 
> newlib/ChangeLog:
> 
> 2023-02-23  Srinath Parvathaneni  <srinath.parvathaneni@arm.com>
> 
>          * libc/sys/arm/crt0.S (_stack_init): Add check for hypervisor 
> mode.

-	/* Test mode bits - in User of all are 0.  */
-	tst	r4, #(CPSR_M_MASK)
-	/* "eq" means r4 AND #0x0F is 0.  */
+	mov	r3, sp
+	ands	r1, r4, #(CPSR_M_MASK)
+	beq	.Lskip_cpu_modes
+	cmp	r1, #(CPSR_M_HYP)

You don't mention anywhere why you've moved the instruction that copies 
SP into R3 before the user-mode check.  I think it's probably right, but 
I think really that's a separate issue that deserves a separate patch 
(even though it's pretty trivial).

So please can you resend as two patches, the first fixing the SP->r3 
copy and the second for the hypervisor mode issue.

R.

      reply	other threads:[~2023-03-02 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-23 17:10 Srinath Parvathaneni
2023-03-02 13:05 ` Richard Earnshaw [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=409759de-41a3-2f52-e7d3-f74582f59efe@foss.arm.com \
    --to=richard.earnshaw@foss.arm.com \
    --cc=Richard.Earnshaw@arm.com \
    --cc=nd@arm.com \
    --cc=newlib@sourceware.org \
    --cc=srinath.parvathaneni@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).