mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: torvalds@linux-foundation.org, akpm@linux-foundation.org,
	alan@lxorguk.ukuu.org.uk, "David S. Miller" <davem@davemloft.net>
Subject: [59/75] sparc: Fix handling of orig_i0 wrt. debugging when restarting syscalls.
Date: Tue, 03 Jan 2012 14:33:32 -0800	[thread overview]
Message-ID: <20120103223325.991636596@clark.kroah.org> (raw)
In-Reply-To: <20120103223332.GA4112@kroah.com>

3.1-stable review patch.  If anyone has any objections, please let me know.

------------------


From: "David S. Miller" <davem@davemloft.net>

[ A combination of upstream commits 1d299bc7732c34d85bd43ac1a8745f5a2fed2078 and
  e88d2468718b0789b4c33da2f7e1cef2a1eee279 ]

Although we provide a proper way for a debugger to control whether
syscall restart occurs, we run into problems because orig_i0 is not
saved and restored properly.

Luckily we can solve this problem without having to make debuggers
aware of the issue.  Across system calls, several registers are
considered volatile and can be safely clobbered.

Therefore we use the pt_regs save area of one of those registers, %g6,
as a place to save and restore orig_i0.

Debuggers transparently will do the right thing because they save and
restore this register already.

Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 arch/sparc/kernel/signal32.c  |   18 ++++++++++--------
 arch/sparc/kernel/signal_32.c |   30 +++++++++++++++++++++++++-----
 arch/sparc/kernel/signal_64.c |   42 ++++++++++++++++++++++++++++--------------
 3 files changed, 63 insertions(+), 27 deletions(-)

--- a/arch/sparc/kernel/signal32.c
+++ b/arch/sparc/kernel/signal32.c
@@ -822,21 +822,23 @@ static inline void syscall_restart32(uns
  * want to handle. Thus you cannot kill init even with a SIGKILL even by
  * mistake.
  */
-void do_signal32(sigset_t *oldset, struct pt_regs * regs,
-		 int restart_syscall, unsigned long orig_i0)
+void do_signal32(sigset_t *oldset, struct pt_regs * regs)
 {
 	struct k_sigaction ka;
+	unsigned long orig_i0;
+	int restart_syscall;
 	siginfo_t info;
 	int signr;
 	
 	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
 
-	/* If the debugger messes with the program counter, it clears
-	 * the "in syscall" bit, directing us to not perform a syscall
-	 * restart.
-	 */
-	if (restart_syscall && !pt_regs_is_syscall(regs))
-		restart_syscall = 0;
+	restart_syscall = 0;
+	orig_i0 = 0;
+	if (pt_regs_is_syscall(regs) &&
+	    (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
+		restart_syscall = 1;
+		orig_i0 = regs->u_regs[UREG_G6];
+	}
 
 	if (signr > 0) {
 		if (restart_syscall)
--- a/arch/sparc/kernel/signal_32.c
+++ b/arch/sparc/kernel/signal_32.c
@@ -519,10 +519,26 @@ static void do_signal(struct pt_regs *re
 	siginfo_t info;
 	int signr;
 
+	/* It's a lot of work and synchronization to add a new ptrace
+	 * register for GDB to save and restore in order to get
+	 * orig_i0 correct for syscall restarts when debugging.
+	 *
+	 * Although it should be the case that most of the global
+	 * registers are volatile across a system call, glibc already
+	 * depends upon that fact that we preserve them.  So we can't
+	 * just use any global register to save away the orig_i0 value.
+	 *
+	 * In particular %g2, %g3, %g4, and %g5 are all assumed to be
+	 * preserved across a system call trap by various pieces of
+	 * code in glibc.
+	 *
+	 * %g7 is used as the "thread register".   %g6 is not used in
+	 * any fixed manner.  %g6 is used as a scratch register and
+	 * a compiler temporary, but it's value is never used across
+	 * a system call.  Therefore %g6 is usable for orig_i0 storage.
+	 */
 	if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C))
-		restart_syscall = 1;
-	else
-		restart_syscall = 0;
+		regs->u_regs[UREG_G6] = orig_i0;
 
 	if (test_thread_flag(TIF_RESTORE_SIGMASK))
 		oldset = &current->saved_sigmask;
@@ -535,8 +551,12 @@ static void do_signal(struct pt_regs *re
 	 * the software "in syscall" bit, directing us to not perform
 	 * a syscall restart.
 	 */
-	if (restart_syscall && !pt_regs_is_syscall(regs))
-		restart_syscall = 0;
+	restart_syscall = 0;
+	if (pt_regs_is_syscall(regs) && (regs->psr & PSR_C)) {
+		restart_syscall = 1;
+		orig_i0 = regs->u_regs[UREG_G6];
+	}
+
 
 	if (signr > 0) {
 		if (restart_syscall)
--- a/arch/sparc/kernel/signal_64.c
+++ b/arch/sparc/kernel/signal_64.c
@@ -529,11 +529,27 @@ static void do_signal(struct pt_regs *re
 	siginfo_t info;
 	int signr;
 	
+	/* It's a lot of work and synchronization to add a new ptrace
+	 * register for GDB to save and restore in order to get
+	 * orig_i0 correct for syscall restarts when debugging.
+	 *
+	 * Although it should be the case that most of the global
+	 * registers are volatile across a system call, glibc already
+	 * depends upon that fact that we preserve them.  So we can't
+	 * just use any global register to save away the orig_i0 value.
+	 *
+	 * In particular %g2, %g3, %g4, and %g5 are all assumed to be
+	 * preserved across a system call trap by various pieces of
+	 * code in glibc.
+	 *
+	 * %g7 is used as the "thread register".   %g6 is not used in
+	 * any fixed manner.  %g6 is used as a scratch register and
+	 * a compiler temporary, but it's value is never used across
+	 * a system call.  Therefore %g6 is usable for orig_i0 storage.
+	 */
 	if (pt_regs_is_syscall(regs) &&
-	    (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
-		restart_syscall = 1;
-	} else
-		restart_syscall = 0;
+	    (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY)))
+		regs->u_regs[UREG_G6] = orig_i0;
 
 	if (current_thread_info()->status & TS_RESTORE_SIGMASK)
 		oldset = &current->saved_sigmask;
@@ -542,22 +558,20 @@ static void do_signal(struct pt_regs *re
 
 #ifdef CONFIG_COMPAT
 	if (test_thread_flag(TIF_32BIT)) {
-		extern void do_signal32(sigset_t *, struct pt_regs *,
-					int restart_syscall,
-					unsigned long orig_i0);
-		do_signal32(oldset, regs, restart_syscall, orig_i0);
+		extern void do_signal32(sigset_t *, struct pt_regs *);
+		do_signal32(oldset, regs);
 		return;
 	}
 #endif	
 
 	signr = get_signal_to_deliver(&info, &ka, regs, NULL);
 
-	/* If the debugger messes with the program counter, it clears
-	 * the software "in syscall" bit, directing us to not perform
-	 * a syscall restart.
-	 */
-	if (restart_syscall && !pt_regs_is_syscall(regs))
-		restart_syscall = 0;
+	restart_syscall = 0;
+	if (pt_regs_is_syscall(regs) &&
+	    (regs->tstate & (TSTATE_XCARRY | TSTATE_ICARRY))) {
+		restart_syscall = 1;
+		orig_i0 = regs->u_regs[UREG_G6];
+	}
 
 	if (signr > 0) {
 		if (restart_syscall)



  parent reply	other threads:[~2012-01-03 22:43 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-03 22:33 [00/75] 3.1.8-stable review Greg KH
2012-01-03 22:32 ` [01/75] ARM: OMAP: rx51: fix USB Greg KH
2012-01-03 22:32 ` [02/75] ipip, sit: copy parms.name after register_netdevice Greg KH
2012-01-03 22:32 ` [03/75] rtc: Expire alarms after the time is set Greg KH
2012-01-03 22:46   ` John Stultz
2012-01-03 22:53     ` Greg KH
2012-01-03 22:32 ` [04/75] rtc: m41t80: Workaround broken alarm functionality Greg KH
2012-01-03 22:32 ` [05/75] ALSA: HDA: Set position fix to LPIB for an Atom/Poulsbo based device Greg KH
2012-01-03 22:32 ` [06/75] drm/i915: set the right SDVO transcoder for CPT Greg KH
2012-01-03 22:32 ` [07/75] drm/i915: prevent division by zero when asking for chipset power Greg KH
2012-01-03 22:32 ` [08/75] cfq-iosched: free cic_index if blkio_alloc_blkg_stats fails Greg KH
2012-01-03 22:32 ` [09/75] cfq-iosched: fix cfq_cic_link() race confition Greg KH
2012-01-03 22:32 ` [10/75] SCSI: zfcp: return early from slave_destroy if slave_alloc returned early Greg KH
2012-01-03 22:32 ` [11/75] SCSI: mpt2sas: _scsih_smart_predicted_fault uses GFP_KERNEL in interrupt context Greg KH
2012-01-03 22:32 ` [12/75] SCSI: fcoe: Fix preempt count leak in fcoe_filter_frames() Greg KH
2012-01-03 22:32 ` [13/75] mac80211: fix another race in aggregation start Greg KH
2012-01-03 22:32 ` [14/75] ASoC: Fix WM8996 24.576MHz clock operation Greg KH
2012-01-03 22:32 ` [15/75] block: initialize request_queues numa node during Greg KH
2012-01-03 22:32 ` [16/75] ssb: fix init regression with SoCs Greg KH
2012-01-03 22:32 ` [17/75] rtl8192{ce,cu,de,se}: avoid problems because of possible ERFOFF -> ERFSLEEP transition Greg KH
2012-01-03 22:32 ` [18/75] MXC PWM: should active during DOZE/WAIT/DBG mode Greg KH
2012-01-03 22:32 ` [19/75] Input: synaptics - fix touchpad not working after S2R on Vostro V13 Greg KH
2012-01-03 22:32 ` [20/75] percpu: fix per_cpu_ptr_to_phys() handling of non-page-aligned addresses Greg KH
2012-01-03 22:32 ` [21/75] IB/mlx4: Fix shutdown crash accessing a non-existent bitmap Greg KH
2012-01-03 22:32 ` [22/75] binary_sysctl(): fix memory leak Greg KH
2012-01-03 22:32 ` [23/75] oom: fix integer overflow of points in oom_badness Greg KH
2012-01-03 22:32 ` [24/75] oprofile: Fix uninitialized memory access when writing to writing to oprofilefs Greg KH
2012-01-03 22:32 ` [25/75] SUNRPC: Ensure we always bump the backlog queue in xprt_free_slot Greg KH
2012-01-03 22:32 ` [26/75] NFS: Fix a regression in nfs_file_llseek() Greg KH
2012-01-03 22:33 ` [27/75] NFSv4.1: Ensure that we handle _all_ SEQUENCE status bits Greg KH
2012-01-03 22:33 ` [28/75] SELinux: Fix RCU deref check warning in sel_netport_insert() Greg KH
2012-01-03 22:33 ` [29/75] media: omap_vout: Fix compile error in 3.1 Greg KH
2012-01-03 22:33 ` [30/75] nilfs2: unbreak compat ioctl Greg KH
2012-01-03 22:33 ` [31/75] mmc: vub300: fix type of firmware_rom_wait_states module parameter Greg KH
2012-01-03 22:33 ` [32/75] cgroups: fix a css_set not found bug in cgroup_attach_proc Greg KH
2012-01-03 22:33 ` [33/75] mfd: Fix twl-core oops while calling twl_i2c_* for unbound driver Greg KH
2012-01-03 22:33 ` [34/75] vfs: __read_cache_page should use gfp argument rather than GFP_KERNEL Greg KH
2012-01-03 22:33 ` [35/75] media: s5p-fimc: Use correct fourcc for RGB565 colour format Greg KH
2012-01-03 22:33 ` [36/75] ath9k: fix max phy rate at rate control init Greg KH
2012-01-03 22:33 ` [37/75] iwlwifi: do not set the sequence control bit is not needed Greg KH
2012-01-03 22:33 ` [38/75] iwlwifi: allow to switch to HT40 if not associated Greg KH
2012-01-03 22:33 ` [39/75] memcg: keep root group unchanged if creation fails Greg KH
2012-01-03 22:33 ` [40/75] VFS: Fix race between CPU hotplug and lglocks Greg KH
2012-01-03 22:33 ` [41/75] ARM:imx:fix pwm period value Greg KH
2012-01-03 22:33 ` [42/75] ARM: 7214/1: mmc: mmci: Fixup handling of MCI_STARTBITERR Greg KH
2012-01-03 22:33 ` [43/75] ARM: 7220/1: mmc: mmci: Fixup error handling for dma Greg KH
2012-01-03 22:33 ` [44/75] oprofile, arm/sh: Fix oprofile_arch_exit() linkage issue Greg KH
2012-01-03 22:33 ` [45/75] futex: Fix uninterruptible loop due to gate_area Greg KH
2012-01-03 22:33 ` [46/75] watchdog: hpwdt: Changes to handle NX secure bit in 32bit path Greg KH
2012-01-03 22:33 ` [47/75] drm/radeon/kms: bail on BTC parts if MC ucode is missing Greg KH
2012-01-03 22:33 ` [48/75] mm: hugetlb: fix non-atomic enqueue of huge page Greg KH
2012-01-03 22:33 ` [49/75] mm/mempolicy.c: refix mbind_range() vma issue Greg KH
2012-01-03 22:33 ` [50/75] mpt2sas crashes on shutdown Greg KH
2012-01-04  8:53   ` Nandigama, Nagalakshmi
2012-01-04 15:18     ` Greg KH
2012-01-04 15:19     ` James Bottomley
2012-01-04 15:25       ` [PATCH] mpt2sas: fix non-x86 crash " James Bottomley
2012-01-04 19:21         ` Greg KH
2012-01-04 19:39           ` David Miller
2012-01-05 19:10         ` Patch "mpt2sas: fix non-x86 crash on shutdown" has been added to the 3.0-stable tree gregkh
2012-01-05 19:25         ` Patch "mpt2sas: fix non-x86 crash on shutdown" has been added to the 3.1-stable tree gregkh
2012-01-03 22:33 ` [51/75] sparc64: Fix MSIQ HV call ordering in pci_sun4v_msiq_build_irq() Greg KH
2012-01-03 22:33 ` [52/75] sparc32: Be less strict in matching %lo part of relocation Greg KH
2012-01-03 22:33 ` [53/75] sparc64: Patch sun4v code sequences properly on module load Greg KH
2012-01-03 22:33 ` [54/75] sparc: Kill custom io_remap_pfn_range() Greg KH
2012-01-03 22:33 ` [55/75] sparc32: Remove non-kernel code from memcpy implementation Greg KH
2012-01-03 22:33 ` [56/75] sparc32: Remove uses of %g7 in " Greg KH
2012-01-03 22:33 ` [57/75] sparc32: Correct the return value of memcpy Greg KH
2012-01-03 22:33 ` [58/75] sparc64: Fix masking and shifting in VIS fpcmp emulation Greg KH
2012-01-03 22:33 ` Greg KH [this message]
2012-01-03 22:33 ` [60/75] net: bpf_jit: fix an off-one bug in x86_64 cond jump target Greg KH
2012-01-03 22:33 ` [61/75] ppp: fix pptp double release_sock in pptp_bind() Greg KH
2012-01-03 22:33 ` [62/75] llc: llc_cmsg_rcv was getting called after sk_eat_skb Greg KH
2012-01-03 22:33 ` [63/75] mqprio: Avoid panic if no options are provided Greg KH
2012-01-03 22:33 ` [64/75] net: have ipconfig not wait if no dev is available Greg KH
2012-01-03 22:33 ` [65/75] sch_gred: should not use GFP_KERNEL while holding a spinlock Greg KH
2012-01-03 22:33 ` [66/75] sctp: fix incorrect overflow check on autoclose Greg KH
2012-01-03 22:33 ` [67/75] sctp: Do not account for sizeof(struct sk_buff) in estimated rwnd Greg KH
2012-01-03 22:33 ` [68/75] net: Add a flow_cache_flush_deferred function Greg KH
2012-01-03 22:33 ` [69/75] ipv4: flush route cache after change accept_local Greg KH
2012-01-03 22:33 ` [70/75] ipv6: Check dest prefix length on original route not copied one in rt6_alloc_cow() Greg KH
2012-01-03 22:33 ` [71/75] net: introduce DST_NOPEER dst flag Greg KH
2012-01-03 22:33 ` [72/75] ipv4: reintroduce route cache garbage collector Greg KH
2012-01-03 22:33 ` [73/75] ipv4: using prefetch requires including prefetch.h Greg KH
2012-01-03 22:33 ` [74/75] iwlwifi: update SCD BC table for all SCD queues Greg KH
2012-01-03 22:33 ` [75/75] mfd: Turn on the twl4030-madc MADC clock Greg KH
2012-01-05 19:26 ` [00/75] 3.1.8-stable review Greg KH
2012-01-05 22:36   ` Greg KH
2012-01-05 22:30     ` [49/80] mpt2sas: fix non-x86 crash on shutdown Greg KH
2012-01-05 22:30     ` [75/80] drm/radeon/kms/atom: fix possible segfault in pm setup Greg KH
2012-01-05 22:30     ` [76/80] hung_task: fix false positive during vfork Greg KH
2012-01-05 22:30     ` [77/80] Revert "rtc: Disable the alarm in the hardware" Greg KH
2012-01-05 22:30     ` [78/80] ptrace: partially fix the do_wait(WEXITED) vs EXIT_DEAD->EXIT_ZOMBIE race Greg KH
2012-01-05 22:30     ` [79/80] ptrace: ensure JOBCTL_STOP_SIGMASK is not zero after detach Greg KH
2012-01-05 22:30     ` [80/80] ath9k: Fix kernel panic in AR2427 in AP mode Greg KH
2012-01-05 19:29 ` [00/75] 3.1.8-stable review Linus Torvalds
2012-01-05 19:36   ` Greg KH

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=20120103223325.991636596@clark.kroah.org \
    --to=gregkh@suse.de \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --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

Powered by JetHome