mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Suresh Siddha <suresh.b.siddha@intel.com>
To: Hans Rosenfeld <hans.rosenfeld@amd.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@elte.hu>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	tglx@linutronix.de, robert.richter@amd.com,
	andreas.herrmann3@amd.com
Subject: Re: [RFC] x86, fpu: unify signal handling code paths for x86 and x86_64 kernels
Date: Thu, 14 Jun 2012 17:10:35 -0700	[thread overview]
Message-ID: <1339719035.3475.52.camel@sbsiddha-desk.sc.intel.com> (raw)
In-Reply-To: <20120614143727.GF7922@escobedo.osrc.amd.com>

On Thu, 2012-06-14 at 13:45 -0700, Suresh Siddha wrote:
> On Thu, 2012-06-14 at 16:37 +0200, Hans Rosenfeld wrote:
> > Thank you for working on this.
> > 
> > I didn't see anything obviously wrong in a quick review of this code,
> > but this stuff is too complex for this to mean anything :)
> > 
> > I ran a quick test of your code. I found a signal frame corruption when
> > running a 32bit test program on a 64bit kernel. I didn't try to find out
> > why it failed, but I'll send you the test program in a private mail so
> > you can look at it yourself.
> > 
> 
> Ok. The problem was that I was using is_ia32_task() (which uses
> TS_COMPAT) to check if the task is a compat task or not. And that flag
> is not set during the signal delivery paths for the compat task.
> 
> I guess I should be using TIF_IA32 check instead. Using TIF_IA32 check
> makes your test case run fine.
> 
> Will update it accordingly.
> 

For the above mentioned reason, I guess the current usage of
is_ia32_task() in copy_siginfo_to_user32() (added recently for x32
support) is broken, as the TS_COMPAT flag may not be set for the x86
compat mode apps in those paths.

Peter offline suggested that the signal  delivery path should probably
set/clear the TS_COMPAT flag (just like we do it for syscall paths), so
that is_ia32_task() will work in those paths.

But the exception paths for the 32bit and 64bit apps in the 64-bit
kernel is same. So I really need to use something like TIF_IA32 to find
out the compat mode of the task. Anyways, the comment in the below patch
explains the problem ;) What should we do? Just remove the
is_ia32_task() checks in signal paths and just use TIF_IA32 or do
something like below.

My personal preference is to use TIF_IA32 check and avoid  the usage of
is_ia32_task() in the signal delivery paths.

Signal return goes through a system call which already sets the
TS_COMPAT. It is the signal delivery that is causing the asymmetry.
---

diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
index b280908..d7f01fc 100644
--- a/arch/x86/kernel/signal.c
+++ b/arch/x86/kernel/signal.c
@@ -791,9 +791,39 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
 	}
 
 	/* deal with pending signal delivery */
-	if (thread_info_flags & _TIF_SIGPENDING)
+	if (thread_info_flags & _TIF_SIGPENDING) {
+		bool compat_flag = false;
+
+		/*
+		 * Check if the task is a compat task and we are here
+		 * in a non-syscall path. If so, set TS_COMPAT explicitly
+		 * so that do_signal() can use is_compat_task()/is_ia32_task().
+		 *
+		 * Or Should we just use test_thread_flag(TIF_IA32) check
+		 * (which is called just 'is_ia32' in this file) instead of
+		 * using is_ia32_task() in signal delivery paths.
+		 *
+		 * BTW, ideally is_[ia32|x32|compat]_task() should be really
+		 * called as is_[ia32|x32|compat]_syscall() and the
+		 * TIF_IA32 check can then be called as is_ia32_task etc..
+		 *
+		 * Sigh...
+		 *
+		 */
+		if (is_ia32 && !is_ia32_task()) {
+			current_thread_info()->status |= TS_COMPAT;
+			compat_flag = true;
+		}
+
 		do_signal(regs);
 
+		/*
+		 * Clear the TS_COMPAT only if we set it above.
+		 */
+		if (compat_flag)
+			current_thread_info()->status &= ~TS_COMPAT;
+	}
+
 	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
 		clear_thread_flag(TIF_NOTIFY_RESUME);
 		tracehook_notify_resume(regs);



  parent reply	other threads:[~2012-06-15  0:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13  0:03 Suresh Siddha
2012-06-13  0:17 ` H. Peter Anvin
2012-06-14 14:37 ` Hans Rosenfeld
2012-06-14 20:45   ` Suresh Siddha
2012-06-15  0:10   ` Suresh Siddha [this message]
2012-06-15  0:16     ` H. Peter Anvin
2012-06-15  1:07       ` Suresh Siddha
2012-06-15  1:13         ` H. Peter Anvin
2012-06-15  1:16           ` Suresh Siddha
2012-06-15  1:17             ` H. Peter Anvin
2012-06-16  3:14         ` [tip:x86/urgent] x86, compat: Use test_thread_flag(TIF_IA32) in compat signal delivery tip-bot for Suresh Siddha
2012-06-14 20:48 ` [RFC] x86, fpu: unify signal handling code paths for x86 and x86_64 kernels H. Peter Anvin
2012-06-14 20:49   ` Suresh Siddha

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=1339719035.3475.52.camel@sbsiddha-desk.sc.intel.com \
    --to=suresh.b.siddha@intel.com \
    --cc=andreas.herrmann3@amd.com \
    --cc=hans.rosenfeld@amd.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=robert.richter@amd.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /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

all inboxes | Powered by JetHome®