virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Josh Triplett <josh@joshtriplett.org>
To: Alexander van Heukelum <heukelum@fastmail.fm>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>,
	x86@kernel.org, Len Brown <len.brown@intel.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	virtualization@lists.linux-foundation.org,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Raghavendra K T <raghavendra.kt@linux.vnet.ibm.com>,
	David Herrmann <dh.herrmann@gmail.com>,
	Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
	Seiji Aguchi <seiji.aguchi@hds.com>, Jiri Slaby <jslaby@suse.cz>,
	Alok Kataria <akataria@vmware.com>,
	Jesper Nilsson <jesper.nilsson@axis.com>,
	Andi Kleen <ak@linux.intel.com>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	xen-devel@lists.xenproject.org, Borislav Petkov <bp@suse.de>,
	Fenghua Yu <fenghua.yu@intel.com>,
	Kees Cook <keescook@chromium.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	Ross
Subject: Re: [PATCH 3/3] x86: Support compiling out userspace I/O (iopl and ioperm)
Date: Fri, 1 Nov 2013 10:19:12 -0700	[thread overview]
Message-ID: <20131101171911.GA1122@leaf> (raw)
In-Reply-To: <1383249882.6635.41326997.4D0EF91B@webmail.messagingengine.com>

On Thu, Oct 31, 2013 at 09:04:42PM +0100, Alexander van Heukelum wrote:
> On Tue, Oct 22, 2013, at 3:35, Josh Triplett wrote:
> > --- a/arch/x86/Kconfig
> > +++ b/arch/x86/Kconfig
> > @@ -976,6 +976,16 @@ config VM86
> >  	  XFree86 to initialize some video cards via BIOS. Disabling this
> >  	  option saves about 6k.
> >  
> > +config X86_IOPORT
> > +	bool "iopl and ioperm system calls"
> > +	default y
> > +	---help---
> > +	  This option enables the iopl and ioperm system calls, which allow
> > +	  privileged userspace processes to directly access I/O ports. This
> > +	  is used by some legacy software to drive hardware directly from
> > +	  userspace rather than via a proper kernel driver. Unless you intend
> > +	  to run such software, you can safely say N here.
> > +
> 
> I think this entry should be under General setup / Configure standard kernel
> features (expert users).

It's entirely x86-specific, and it's similar to VM86 just above it; it
belongs on the x86-specific menu.

> Remove references to "legacy" and "proper driver".

Hardware drivers belong in the kernel, and anything using iopl or ioperm
won't run on x86-64, which argues rather strongly for its obsolescence.
There's also /dev/port for cleaner access to ports from userspace.
However, I've rephrased this for v2.

> > --- a/arch/x86/kernel/cpu/common.c
> > +++ b/arch/x86/kernel/cpu/common.c
> > @@ -1223,7 +1223,6 @@ void cpu_init(void)
> >  	struct tss_struct *t;
> >  	unsigned long v;
> >  	int cpu;
> > -	int i;
> >  
> >  	/*
> >  	 * Load microcode on this cpu if a valid microcode is available.
> > @@ -1285,14 +1284,7 @@ void cpu_init(void)
> >  		}
> >  	}
> >  
> > -	t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
> > -
> > -	/*
> > -	 * <= is required because the CPU will access up to
> > -	 * 8 bits beyond the end of the IO permission bitmap.
> > -	 */
> > -	for (i = 0; i <= IO_BITMAP_LONGS; i++)
> > -		t->io_bitmap[i] = ~0UL;
> > +	init_tss_io(t);
> >  
> >  	atomic_inc(&init_mm.mm_count);
> >  	me->active_mm = &init_mm;
> > @@ -1351,7 +1343,7 @@ void cpu_init(void)
> >  	load_TR_desc();
> >  	load_LDT(&init_mm.context);
> >  
> > -	t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
> > +	init_tss_io(t);
> 
> This patch is too big. I think it would all look nicer if you added ioport.c in
> one patch, and then convert the users in a separate patch?

I'm not sure what you mean by "added ioport.c"; ioport.c already exists,
and this patch just makes it optional.

> > --- a/arch/x86/kernel/process-io.h
> > +++ b/arch/x86/kernel/process-io.h
> > @@ -1,9 +1,17 @@
> >  #ifndef _X86_KERNEL_PROCESS_IO_H
> >  #define _X86_KERNEL_PROCESS_IO_H
> >  
> > +static inline void clear_thread_io_bitmap(struct task_struct *p)
> > +{
> > +#ifdef CONFIG_X86_IOPORT
> > +	p->thread.io_bitmap_ptr = NULL;
> > +#endif /* CONFIG_X86_IOPORT */
> > +}
> > +
> 
> This is thought of as ugly... Instead, do something like
> 
> #ifndef CONFIG_X86_IOPORT
> 
> static inline void clear_thread_io_bitmap(struct task_struct *p) {}
> static inline int copy_io_bitmap(struct task_struct *me, struct task_struct *p) {return 0}
> ... etc...
> 
> #else
> 
> static inline void clear_thread_io_bitmap(struct task_struct *p)
> {
>    p->thread.io_bitmap_ptr = NULL;
> }
> ... etc...
> 
> #endif

In .c files, any ifdefs at all are ugly; in .h files, both styles are
quite common, and in particular the style I used is common when omitting
the entire body of the function.  It has the advantage of keeping a
common function signature rather than duplicating it.

> > --- a/arch/x86/kernel/process_32.c
> > +++ b/arch/x86/kernel/process_32.c
> > @@ -155,7 +155,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
> >  		childregs->cs = __KERNEL_CS | get_kernel_rpl();
> >  		childregs->flags = X86_EFLAGS_IF | X86_EFLAGS_FIXED;
> >  		p->fpu_counter = 0;
> > -		p->thread.io_bitmap_ptr = NULL;
> > +		clear_thread_io_bitmap(p);
> >  		memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
> >  		return 0;
> >  	}
> > @@ -269,14 +269,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
> >  	 */
> >  	load_TLS(next, cpu);
> >  
> > -	/*
> > -	 * Restore IOPL if needed.  In normal use, the flags restore
> > -	 * in the switch assembly will handle this.  But if the kernel
> > -	 * is running virtualized at a non-zero CPL, the popf will
> > -	 * not restore flags, so it must be done in a separate step.
> > -	 */
> > -	if (get_kernel_rpl() && unlikely(prev->iopl != next->iopl))
> > -		set_iopl_mask(next->iopl);
> > +	switch_iopl_mask(prev, next);
> >  
> >  	/*
> >  	 * Now maybe handle debug registers and/or IO bitmaps
> 
> If copy_thread would be in process.c instead, the .h-file would be unnecessary,
> right?

No, there are calls to the new functions in the .h file in several other
places.

- Josh Triplett

      reply	other threads:[~2013-11-01 17:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-22  2:33 [PATCH 0/3] x86: Support compiling out userspace I/O (iopl and ioperm) Josh Triplett
2013-10-22  2:34 ` [PATCH 1/3] x86: process: Unify 32-bit and 64-bit copy_thread I/O bitmap handling Josh Triplett
2013-10-30 22:21   ` Kees Cook
2013-10-31 20:01   ` Alexander van Heukelum
2013-11-01 16:33     ` Josh Triplett
2013-10-22  2:34 ` [PATCH 2/3] x86: tss: Eliminate fragile calculation of TSS segment limit Josh Triplett
2013-10-30 22:22   ` Kees Cook
2013-10-30 22:53     ` H. Peter Anvin
2013-10-31 11:17       ` Josh Triplett
2013-10-31 11:12     ` Josh Triplett
2013-10-31 20:02   ` Alexander van Heukelum
2013-11-01 16:40     ` Josh Triplett
2013-10-22  2:35 ` [PATCH 3/3] x86: Support compiling out userspace I/O (iopl and ioperm) Josh Triplett
2013-10-26  3:17   ` Stephen Hemminger
2013-10-26  4:30     ` Kees Cook
2013-10-31 20:04   ` Alexander van Heukelum
2013-11-01 17:19     ` Josh Triplett [this message]

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=20131101171911.GA1122@leaf \
    --to=josh@joshtriplett.org \
    --cc=ak@linux.intel.com \
    --cc=akataria@vmware.com \
    --cc=bp@suse.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=dh.herrmann@gmail.com \
    --cc=fenghua.yu@intel.com \
    --cc=fweisbec@gmail.com \
    --cc=heukelum@fastmail.fm \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=jesper.nilsson@axis.com \
    --cc=jslaby@suse.cz \
    --cc=keescook@chromium.org \
    --cc=konrad.wilk@oracle.com \
    --cc=len.brown@intel.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mingo@redhat.com \
    --cc=paul.gortmaker@windriver.com \
    --cc=raghavendra.kt@linux.vnet.ibm.com \
    --cc=rostedt@goodmis.org \
    --cc=seiji.aguchi@hds.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=x86@kernel.org \
    --cc=xen-devel@lists.xenproject.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;
as well as URLs for NNTP newsgroup(s).