Re: [GIT PULL] x86: unify sys_iopl

From: Brian Gerst
Date: Fri Sep 25 2009 - 18:56:45 EST


The correct fix is to move set_iopl_mask into do_iopl. sys_iopl
should only be a wrapper around do_iopl to manage the different
calling convention used by 32-bit and 64-bit.

On Fri, Sep 25, 2009 at 6:05 PM, Jeremy Fitzhardinge <jeremy@xxxxxxxx> wrote:
> Hi Ingo,
>
> The x86-64 implementation of iopl was buggy because it never ended up calling
> set_iopl_mask(). ÂThis had no effect on native sys_iopl (because set_iopl_mask
> is normally no-op on 64-bit), but it ended up never calling the pvop, which caused
> iopl to have no effect on 64-bit Xen guests.
>
> The two functions are needlessly different anyway. ÂThis patch just unifies them
> into a single function which is mostly derived from the 32-bit version.
>
> Thanks,
> Â Â Â ÂJ
>
> The following changes since commit c44c9ec0f38b939b3200436e3aa95c1aa83c41c7:
> ÂJeremy Fitzhardinge (1):
> Â Â Â Âx86: split NX setup into separate file to limit unstack-protected code
>
> are available in the git repository at:
>
> Âgit://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git bugfix
>
> Jeremy Fitzhardinge (1):
> Â Â Âx86: unify sys_iopl
>
> Âarch/x86/include/asm/syscalls.h | Â Â8 +++-----
> Âarch/x86/kernel/ioport.c    Â|  11 ++---------
> Â2 files changed, 5 insertions(+), 14 deletions(-)
>
> From 8dbb1d168eb8be6bf43d123fdfb3ba3b03762e62 Mon Sep 17 00:00:00 2001
> From: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
> Date: Wed, 23 Sep 2009 16:35:24 -0700
> Subject: [PATCH] x86: unify sys_iopl
>
> The 32 and 64-bit versions of sys_iopl were needlessly different:
> Â- The 32-bit version ignored its function argument and directly
> Â fetched the parameter from struct regs, presumably code dating
> Â from the neolithic era.
> Â- The 64-bit version never called set_iopl_mask(). ÂUsually this
> Â is a no-op for 64-bit, but it is also a pvop, which meant that
> Â that iopl never worked for 64-bit guests under Xen.
> Â- Both versions use the archaic style of getting pt_regs passed
> Â to them. ÂWe can get the current pt_regs with task_pt_regs, which
> Â avoids worrying about the fine details of stack layout.
>
> We can use the body of the 32-bit function with a few small
> adjustments to the function definition.
>
> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@xxxxxxxxxx>
>
> diff --git a/arch/x86/include/asm/syscalls.h b/arch/x86/include/asm/syscalls.h
> index 372b76e..5336ce2 100644
> --- a/arch/x86/include/asm/syscalls.h
> +++ b/arch/x86/include/asm/syscalls.h
> @@ -33,11 +33,11 @@ long sys_rt_sigreturn(struct pt_regs *);
> Âasmlinkage int sys_set_thread_area(struct user_desc __user *);
> Âasmlinkage int sys_get_thread_area(struct user_desc __user *);
>
> -/* X86_32 only */
> -#ifdef CONFIG_X86_32
> Â/* kernel/ioport.c */
> -long sys_iopl(struct pt_regs *);
> +asmlinkage long sys_iopl(unsigned int);
>
> +/* X86_32 only */
> +#ifdef CONFIG_X86_32
> Â/* kernel/process_32.c */
> Âint sys_clone(struct pt_regs *);
> Âint sys_execve(struct pt_regs *);
> @@ -70,8 +70,6 @@ int sys_vm86(struct pt_regs *);
> Â#else /* CONFIG_X86_32 */
>
> Â/* X86_64 only */
> -/* kernel/ioport.c */
> -asmlinkage long sys_iopl(unsigned int, struct pt_regs *);
>
> Â/* kernel/process_64.c */
> Âasmlinkage long sys_clone(unsigned long, unsigned long,
> diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
> index 99c4d30..bad4f22 100644
> --- a/arch/x86/kernel/ioport.c
> +++ b/arch/x86/kernel/ioport.c
> @@ -119,11 +119,10 @@ static int do_iopl(unsigned int level, struct pt_regs *regs)
> Â Â Â Âreturn 0;
> Â}
>
> -#ifdef CONFIG_X86_32
> -long sys_iopl(struct pt_regs *regs)
> +asmlinkage long sys_iopl(unsigned int level)
> Â{
> - Â Â Â unsigned int level = regs->bx;
> Â Â Â Âstruct thread_struct *t = &current->thread;
> + Â Â Â struct pt_regs *regs = task_pt_regs(current);
> Â Â Â Âint rc;
>
> Â Â Â Ârc = do_iopl(level, regs);
> @@ -135,9 +134,3 @@ long sys_iopl(struct pt_regs *regs)
> Âout:
> Â Â Â Âreturn rc;
> Â}
> -#else
> -asmlinkage long sys_iopl(unsigned int level, struct pt_regs *regs)
> -{
> - Â Â Â return do_iopl(level, regs);
> -}
> -#endif
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
> Please read the FAQ at Âhttp://www.tux.org/lkml/
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/