LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Chris Wright <chrisw@sous-sol.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Kevin Winchester <kjwinchester@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	"mboton@gmail.com" <mboton@gmail.com>,
	Zach Brown <zach.brown@oracle.com>
Subject: [PATCH] x86: refactor ioport unification
Date: Fri, 11 Jan 2008 17:06:56 -0800	[thread overview]
Message-ID: <20080112010656.GD3627@sequoia.sous-sol.org> (raw)
In-Reply-To: <20080112010443.GA5476@sequoia.sous-sol.org>

Refactor ioport unification to pull out common code.

Cc: mboton@gmail.com
Cc: Kevin Winchester <kjwinchester@gmail.com>
Cc: Zach Brown <zach.brown@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
---
 Applies atop the ioport unification fix for 32-bit

 arch/x86/kernel/ioport.c |   40 +++++++++++++++++++++-------------------
 1 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
index be72d80..50e5e4a 100644
--- a/arch/x86/kernel/ioport.c
+++ b/arch/x86/kernel/ioport.c
@@ -113,13 +113,9 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
  * on system-call entry - see also fork() and the signal handling
  * code.
  */
-#ifdef CONFIG_X86_32
-asmlinkage long sys_iopl(unsigned long regsp)
+static int do_iopl(unsigned int level, struct pt_regs *regs)
 {
-	struct pt_regs *regs = (struct pt_regs *)&regsp;
-	unsigned int level = regs->bx;
 	unsigned int old = (regs->flags >> 12) & 3;
-	struct thread_struct *t = &current->thread;
 
 	if (level > 3)
 		return -EINVAL;
@@ -128,25 +124,31 @@ asmlinkage long sys_iopl(unsigned long regsp)
 		if (!capable(CAP_SYS_RAWIO))
 			return -EPERM;
 	}
-	t->iopl = level << 12;
 	regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
-	set_iopl_mask(t->iopl);
+
 	return 0;
 }
-#else
-asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
+
+#ifdef CONFIG_X86_32
+asmlinkage long sys_iopl(unsigned long regsp)
 {
-	unsigned int old = (regs->flags >> 12) & 3;
+	struct pt_regs *regs = (struct pt_regs *)&regsp;
+	unsigned int level = regs->bx;
+	struct thread_struct *t = &current->thread;
+	int rc;
 
-	if (level > 3)
-		return -EINVAL;
-	/* Trying to gain more privileges? */
-	if (level > old) {
-		if (!capable(CAP_SYS_RAWIO))
-			return -EPERM;
-	}
-	regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
+	rc = do_iopl(level, regs);
+	if (rc < 0)
+		goto out;
 
-	return 0;
+	t->iopl = level << 12;
+	set_iopl_mask(t->iopl);
+out:
+	return rc;
+}
+#else
+asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
+{
+	return do_iopl(level, regs);
 }
 #endif

  reply	other threads:[~2008-01-12  1:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-10 23:28 hwclock failure in x86.git Kevin Winchester
2008-01-10 23:32 ` H. Peter Anvin
2008-01-10 23:50   ` Kevin Winchester
2008-01-11  1:13     ` H. Peter Anvin
2008-01-11  2:04       ` Kevin Winchester
2008-01-11 14:03         ` Ingo Molnar
2008-01-11 23:58           ` Miguel Botón
2008-01-12  1:04           ` [PATCH] x86: fix ioport unification on 32-bit [was: Re: hwclock failure in x86.git] Chris Wright
2008-01-12  1:06             ` Chris Wright [this message]
2008-01-14  8:32               ` [PATCH] x86: refactor ioport unification Ingo Molnar
2008-01-14  8:27             ` [PATCH] x86: fix ioport unification on 32-bit [was: Re: hwclock failure in x86.git] Ingo Molnar
2008-01-11  2:27       ` hwclock failure in x86.git Kevin Winchester
2008-01-11  2:55         ` Zach Brown

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=20080112010656.GD3627@sequoia.sous-sol.org \
    --to=chrisw@sous-sol.org \
    --cc=hpa@zytor.com \
    --cc=kjwinchester@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mboton@gmail.com \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=zach.brown@oracle.com \
    --subject='Re: [PATCH] x86: refactor ioport unification' \
    /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

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 NNTP newsgroup(s).