Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp786276ybf; Fri, 28 Feb 2020 07:36:38 -0800 (PST) X-Google-Smtp-Source: APXvYqxyrt6JyNXYvYh8y7jwhCO9W0W/zbV8WVlObCx5kec+f1URhD7KGCH8gPLVwhTGYR4gFMWn X-Received: by 2002:a05:6830:13da:: with SMTP id e26mr3599175otq.97.1582904198186; Fri, 28 Feb 2020 07:36:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582904198; cv=none; d=google.com; s=arc-20160816; b=rYE4zEMvtAVt2cTy+PEL0AxdUf3Qx/pItF2MG8VEZMIPebgwRGUVksxWoZ3GQyOAf3 Cfy7oIKS1oKJs1efi0Xxv1X+SA4UldZSvvcUkYpwHmp5FCaZ9vvP31WOndZ+3rUdsqlz nG4ZqmZh7nxNYH4XjWuQzSuXox8gvOBSM2V1H5sCKPDOKku0Ri7VcZwlxV2WaFJbQir8 OpVn0bBeblHRjJkpEuanGudmuuEFV55I4M919lqLlhNtTxg0Om1WQisM/2xjHup7DpOU vm2F1BtNwJimwnSgpw3v4gO3Ztz2o1QB+tvdCBWS3FvgkUqY5SX02qzqp7W4eZpQDqCz C3yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=bQeqin6G0h1mGpgFqEZpngmwoczQcaHry2ks9SF68gQ=; b=Hzh92EvuISUMocKkGsR6iflTDQ5XXauvpWMXYNu2dJAF206SM3E2sbHyvKbTPQNs2x 1lzCezMOPRufbWo/T+dZ5tDe+IcPSAH+RSX8qEJsBNA5TbU6ld53icC8LKGrBw816Xdy DvV8452P+EYU9xTVqbXU3RbvwFMIJPT7godh02l2g7jJmWo1+ozmBOL0dL8UFacLccMK J41X/VxL+FagUBp2x0rU+4z6rEdHou//veDxMb4xDD97nnFNCtwXgOriq1XkUCx6u5SQ 0TXYlaNPMHhP2GqrK/L2PGSo46PypmIvllpG1zrudpll/t6dPT445sti9ewaNzgX2w0N Makg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t3si1776622oth.247.2020.02.28.07.36.26; Fri, 28 Feb 2020 07:36:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727159AbgB1Pfy (ORCPT + 99 others); Fri, 28 Feb 2020 10:35:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:38722 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbgB1Pfy (ORCPT ); Fri, 28 Feb 2020 10:35:54 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 01DFFAD5D; Fri, 28 Feb 2020 15:35:51 +0000 (UTC) Subject: Re: [PATCH] x86/ioperm: add new paravirt function update_io_bitmap To: xen-devel@lists.xenproject.org, x86@kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Thomas Hellstrom , "VMware, Inc." , Boris Ostrovsky , Stefano Stabellini , stable@vger.kernel.org References: <20200218154712.25490-1-jgross@suse.com> From: =?UTF-8?B?SsO8cmdlbiBHcm/Dnw==?= Message-ID: <4715c1af-5854-9f2c-2145-fba43e82d350@suse.com> Date: Fri, 28 Feb 2020 16:35:50 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: <20200218154712.25490-1-jgross@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Friendly ping... On 18.02.20 16:47, Juergen Gross wrote: > Commit 111e7b15cf10f6 ("x86/ioperm: Extend IOPL config to control > ioperm() as well") reworked the iopl syscall to use I/O bitmaps. > > Unfortunately this broke Xen PV domains using that syscall as there > is currently no I/O bitmap support in PV domains. > > Add I/O bitmap support via a new paravirt function update_io_bitmap > which Xen PV domains can use to update their I/O bitmaps via a > hypercall. > > Fixes: 111e7b15cf10f6 ("x86/ioperm: Extend IOPL config to control ioperm() as well") > Reported-by: Jan Beulich > Cc: # 5.5 > Signed-off-by: Juergen Gross > Reviewed-by: Jan Beulich > Tested-by: Jan Beulich > --- > arch/x86/include/asm/io_bitmap.h | 9 ++++++++- > arch/x86/include/asm/paravirt.h | 7 +++++++ > arch/x86/include/asm/paravirt_types.h | 4 ++++ > arch/x86/kernel/paravirt.c | 5 +++++ > arch/x86/kernel/process.c | 2 +- > arch/x86/xen/enlighten_pv.c | 25 +++++++++++++++++++++++++ > 6 files changed, 50 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/include/asm/io_bitmap.h b/arch/x86/include/asm/io_bitmap.h > index 02c6ef8f7667..07344d82e88e 100644 > --- a/arch/x86/include/asm/io_bitmap.h > +++ b/arch/x86/include/asm/io_bitmap.h > @@ -19,7 +19,14 @@ struct task_struct; > void io_bitmap_share(struct task_struct *tsk); > void io_bitmap_exit(void); > > -void tss_update_io_bitmap(void); > +void native_tss_update_io_bitmap(void); > + > +#ifdef CONFIG_PARAVIRT_XXL > +#include > +#else > +#define tss_update_io_bitmap native_tss_update_io_bitmap > +#endif > + > #else > static inline void io_bitmap_share(struct task_struct *tsk) { } > static inline void io_bitmap_exit(void) { } > diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h > index 86e7317eb31f..694d8daf4983 100644 > --- a/arch/x86/include/asm/paravirt.h > +++ b/arch/x86/include/asm/paravirt.h > @@ -295,6 +295,13 @@ static inline void write_idt_entry(gate_desc *dt, int entry, const gate_desc *g) > PVOP_VCALL3(cpu.write_idt_entry, dt, entry, g); > } > > +#ifdef CONFIG_X86_IOPL_IOPERM > +static inline void tss_update_io_bitmap(void) > +{ > + PVOP_VCALL0(cpu.update_io_bitmap); > +} > +#endif > + > static inline void paravirt_activate_mm(struct mm_struct *prev, > struct mm_struct *next) > { > diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h > index 84812964d3dd..732f62e04ddb 100644 > --- a/arch/x86/include/asm/paravirt_types.h > +++ b/arch/x86/include/asm/paravirt_types.h > @@ -140,6 +140,10 @@ struct pv_cpu_ops { > > void (*load_sp0)(unsigned long sp0); > > +#ifdef CONFIG_X86_IOPL_IOPERM > + void (*update_io_bitmap)(void); > +#endif > + > void (*wbinvd)(void); > > /* cpuid emulation, mostly so that caps bits can be disabled */ > diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c > index 789f5e4f89de..c131ba4e70ef 100644 > --- a/arch/x86/kernel/paravirt.c > +++ b/arch/x86/kernel/paravirt.c > @@ -30,6 +30,7 @@ > #include > #include > #include > +#include > > /* > * nop stub, which must not clobber anything *including the stack* to > @@ -341,6 +342,10 @@ struct paravirt_patch_template pv_ops = { > .cpu.iret = native_iret, > .cpu.swapgs = native_swapgs, > > +#ifdef CONFIG_X86_IOPL_IOPERM > + .cpu.update_io_bitmap = native_tss_update_io_bitmap, > +#endif > + > .cpu.start_context_switch = paravirt_nop, > .cpu.end_context_switch = paravirt_nop, > > diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c > index 839b5244e3b7..3053c85e0e42 100644 > --- a/arch/x86/kernel/process.c > +++ b/arch/x86/kernel/process.c > @@ -374,7 +374,7 @@ static void tss_copy_io_bitmap(struct tss_struct *tss, struct io_bitmap *iobm) > /** > * tss_update_io_bitmap - Update I/O bitmap before exiting to usermode > */ > -void tss_update_io_bitmap(void) > +void native_tss_update_io_bitmap(void) > { > struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); > struct thread_struct *t = ¤t->thread; > diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c > index 1f756ffffe8b..feaf2e68ee5c 100644 > --- a/arch/x86/xen/enlighten_pv.c > +++ b/arch/x86/xen/enlighten_pv.c > @@ -72,6 +72,9 @@ > #include > #include > #include > +#ifdef CONFIG_X86_IOPL_IOPERM > +#include > +#endif > > #ifdef CONFIG_ACPI > #include > @@ -837,6 +840,25 @@ static void xen_load_sp0(unsigned long sp0) > this_cpu_write(cpu_tss_rw.x86_tss.sp0, sp0); > } > > +#ifdef CONFIG_X86_IOPL_IOPERM > +static void xen_update_io_bitmap(void) > +{ > + struct physdev_set_iobitmap iobitmap; > + struct tss_struct *tss = this_cpu_ptr(&cpu_tss_rw); > + > + native_tss_update_io_bitmap(); > + > + iobitmap.bitmap = (uint8_t *)(&tss->x86_tss) + > + tss->x86_tss.io_bitmap_base; > + if (tss->x86_tss.io_bitmap_base == IO_BITMAP_OFFSET_INVALID) > + iobitmap.nr_ports = 0; > + else > + iobitmap.nr_ports = IO_BITMAP_BITS; > + > + HYPERVISOR_physdev_op(PHYSDEVOP_set_iobitmap, &iobitmap); > +} > +#endif > + > static void xen_io_delay(void) > { > } > @@ -1046,6 +1068,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initconst = { > .write_idt_entry = xen_write_idt_entry, > .load_sp0 = xen_load_sp0, > > +#ifdef CONFIG_X86_IOPL_IOPERM > + .update_io_bitmap = xen_update_io_bitmap, > +#endif > .io_delay = xen_io_delay, > > /* Xen takes care of %gs when switching to usermode for us */ >