sysctl_uac patch for 2.6.4

Jay Maynard <[email protected]>
Newsgroups gmane.linux.gentoo.alpha
Message-ID <[email protected]>
This patch applies to a Gentoo 2.6.4-r1 kernel as installed by "emerge
gentoo-dev-sources". It builds and appears to function on my box. As always,
more testing is in order.

John, I'll do the ebuild changes next.

--
[email protected] mailing list
sysctl_uac.patch (text/plain, 5.6 KB)
diff -Nur linux-2.6.4-gentoo-r1/arch/alpha/Kconfig linux-2.6.4-sysctl_uac/arch/alpha/Kconfig
--- linux-2.6.4-gentoo-r1/arch/alpha/Kconfig	2004-03-16 19:13:12.000000000 -0600
+++ linux-2.6.4-sysctl_uac/arch/alpha/Kconfig	2004-03-17 11:07:55.000000000 -0600
@@ -566,6 +566,32 @@
 
 	  Take the default (1) unless you want more control or more info.
 
+config ALPHA_UAC_SYSCTL
+	bool "Configure UAC policy via sysctl"
+	depends on SYSCTL
+	default y
+	---help---
+	  Configuring the UAC (unaligned access control) policy on a Linux
+	  system usually involves setting a compile time define. If you say
+	  Y here, you will be able to modify the UAC policy at runtime using
+	  the /proc interface.
+
+	  The UAC policy defines the action Linux should take when an
+	  unaligned memory access occurs. The action can include printing a
+	  warning message (NOPRINT), sending a signal to the offending
+	  program to help developers debug their applications (SIGBUS), or
+	  disabling the transparent fixing (NOFIX).
+
+	  The sysctls will be initialized to the compile-time defined UAC
+	  policy. You can change these manually, or with the sysctl(8)
+	  userspace utility.
+
+	  To disable the warning messages at runtime, you would use
+
+	    echo 1 > /proc/sys/kernel/uac/noprint
+
+	  This is pretty harmless. Say Y if you're not sure.
+
 source "drivers/pci/Kconfig"
 source "drivers/eisa/Kconfig"
 
diff -Nur linux-2.6.4-gentoo-r1/arch/alpha/kernel/traps.c linux-2.6.4-sysctl_uac/arch/alpha/kernel/traps.c
--- linux-2.6.4-gentoo-r1/arch/alpha/kernel/traps.c	2004-03-16 19:13:12.000000000 -0600
+++ linux-2.6.4-sysctl_uac/arch/alpha/kernel/traps.c	2004-03-17 13:44:42.000000000 -0600
@@ -15,6 +15,8 @@
 #include <linux/delay.h>
 #include <linux/smp_lock.h>
 #include <linux/module.h>
+#include <linux/sysctl.h>
+#include <linux/init.h>
 
 #include <asm/gentrap.h>
 #include <asm/uaccess.h>
@@ -33,6 +35,40 @@
 static int opDEC_checked = 0;
 static unsigned long opDEC_test_pc = 0;
 
+#ifdef CONFIG_ALPHA_UAC_SYSCTL
+static struct ctl_table_header *uac_sysctl_header;
+
+static int enabled_noprint = 0;
+static int enabled_sigbus = 0;
+static int enabled_nofix = 0;
+
+ctl_table uac_table[] = {
+	{KERN_UAC_NOPRINT, "noprint", &enabled_noprint, sizeof (int), 0644, NULL, &proc_dointvec},
+	{KERN_UAC_SIGBUS, "sigbus", &enabled_sigbus, sizeof (int), 0644, NULL, &proc_dointvec},
+	{KERN_UAC_NOFIX, "nofix", &enabled_nofix, sizeof (int), 0644, NULL, &proc_dointvec},
+        {0}
+};
+
+static int __init init_uac_sysctl(void)
+//static void init_uac_sysctl(void)
+{
+	/* Initialize sysctls with the #defined UAC policy */
+	enabled_noprint = (test_thread_flag (TIF_UAC_NOPRINT)) ? 1 : 0;
+        enabled_sigbus = (test_thread_flag (TIF_UAC_SIGBUS)) ? 1 : 0;
+	enabled_nofix = (test_thread_flag (TIF_UAC_NOFIX)) ? 1 : 0;
+
+	/* save this for later so we can clean up */	
+	uac_sysctl_header = register_sysctl_table(uac_table, 0);
+	return 0;
+}
+
+static void __exit exit_uac_sysctl(void)
+//static void exit_uac_sysctl(void)
+{
+	unregister_sysctl_table(uac_sysctl_header);
+}
+#endif
+
 static void
 opDEC_check(void)
 {
@@ -793,7 +829,11 @@
 	/* Check the UAC bits to decide what the user wants us to do
 	   with the unaliged access.  */
 
+#ifndef CONFIG_ALPHA_UAC_SYSCTL
 	if (!test_thread_flag (TIF_UAC_NOPRINT)) {
+#else  /* CONFIG_ALPHA_UAC_SYSCTL */
+	if (!(enabled_noprint)) {
+#endif /* CONFIG_ALPHA_UAC_SYSCTL */
 		if (cnt >= 5 && jiffies - last_time > 5*HZ) {
 			cnt = 0;
 		}
@@ -804,10 +844,18 @@
 		}
 		last_time = jiffies;
 	}
+#ifndef CONFIG_ALPHA_UAC_SYSCTL
 	if (test_thread_flag (TIF_UAC_SIGBUS))
+#else  /* CONFIG_ALPHA_UAC_SYSCTL */
+	if (enabled_sigbus)
+#endif /* CONFIG_ALPHA_UAC_SYSCTL */
 		goto give_sigbus;
 	/* Not sure why you'd want to use this, but... */
+#ifndef CONFIG_ALPHA_UAC_SYSCTL
 	if (test_thread_flag (TIF_UAC_NOFIX))
+#else  /* CONFIG_ALPHA_UAC_SYSCTL */
+	if (enabled_nofix)
+#endif /* CONFIG_ALPHA_UAC_SYSCTL */
 		return;
 
 	/* Don't bother reading ds in the access check since we already
@@ -1102,3 +1150,6 @@
 	if (implver() == IMPLVER_EV4)
 		opDEC_check();
 }
+
+__initcall(init_uac_sysctl);
+//module_exit(exit_uac_sysctl);
diff -Nur linux-2.6.4-gentoo-r1/include/linux/sysctl.h linux-2.6.4-sysctl_uac/include/linux/sysctl.h
--- linux-2.6.4-gentoo-r1/include/linux/sysctl.h	2004-03-16 19:13:12.000000000 -0600
+++ linux-2.6.4-sysctl_uac/include/linux/sysctl.h	2004-03-17 11:30:16.000000000 -0600
@@ -131,6 +131,7 @@
 	KERN_PRINTK_RATELIMIT_BURST=61,	/* int: tune printk ratelimiting */
 	KERN_PTY=62,		/* dir: pty driver */
 	KERN_NGROUPS_MAX=63,	/* int: NGROUPS_MAX */
+	KERN_UAC_POLICY=64,	/* int: Alpha unaligned access control policy flags */
 };
 
 
@@ -202,6 +203,15 @@
 	PTY_NR=2
 };
 
+/* /proc/sys/kernel/uac */
+enum
+{
+	/* UAC policy on Alpha */
+	KERN_UAC_NOPRINT=1,    /* int: printk() on unaligned access */
+	KERN_UAC_SIGBUS=2,     /* int: send SIGBUS on unaligned access */
+	KERN_UAC_NOFIX=3,      /* int: don't fix the unaligned access */
+};
+
 /* /proc/sys/bus/isa */
 enum
 {
diff -Nur linux-2.6.4-gentoo-r1/kernel/sysctl.c linux-2.6.4-sysctl_uac/kernel/sysctl.c
--- linux-2.6.4-gentoo-r1/kernel/sysctl.c	2004-03-16 19:13:12.000000000 -0600
+++ linux-2.6.4-sysctl_uac/kernel/sysctl.c	2004-03-17 11:50:03.000000000 -0600
@@ -139,6 +139,9 @@
 #ifdef CONFIG_UNIX98_PTYS
 extern ctl_table pty_table[];
 #endif
+#ifdef CONFIG_ALPHA_UAC_SYSCTL
+extern ctl_table uac_table[];
+#endif
 
 /* /proc declarations: */
 
@@ -615,6 +618,12 @@
 		.mode		= 0444,
 		.proc_handler	= &proc_dointvec,
 	},
+	{
+		.ctl_name	= KERN_UAC_POLICY,
+		.procname	= "uac",
+		.mode		= 0555,
+		.child		= uac_table,
+	},
 	{ .ctl_name = 0 }
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.