From: David Vrabel <david.vrabel@citrix.com>
To: Andy Lutomirski <luto@amacapital.net>,
"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Cc: Juergen Gross <jgross@suse.com>,
Peter Zijlstra <peterz@infradead.org>,
"Luis R. Rodriguez" <mcgrof@suse.com>, X86 ML <x86@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
David Vrabel <david.vrabel@citrix.com>,
Jan Beulich <JBeulich@suse.com>, "H. Peter Anvin" <hpa@zytor.com>,
Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@suse.de>, <bpoirier@suse.de>
Subject: Re: [Xen-devel] [PATCH v2 2/2] x86/xen: allow privcmd hypercalls to be preempted
Date: Thu, 11 Dec 2014 11:09:42 +0000 [thread overview]
Message-ID: <54897B76.6070500@citrix.com> (raw)
In-Reply-To: <CALCETrVAQ5JRoyL=V=fj+KxwUXfOTibKQkEDcvSqJzEi2sgshA@mail.gmail.com>
On 10/12/14 23:51, Andy Lutomirski wrote:
> On Wed, Dec 10, 2014 at 3:34 PM, Luis R. Rodriguez
>> --- a/arch/x86/kernel/entry_64.S
>> +++ b/arch/x86/kernel/entry_64.S
>> @@ -1170,7 +1170,23 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
>> popq %rsp
>> CFI_DEF_CFA_REGISTER rsp
>> decl PER_CPU_VAR(irq_count)
>> +#ifdef CONFIG_PREEMPT
>> jmp error_exit
>> +#else
>> + movl %ebx, %eax
>> + RESTORE_REST
>> + DISABLE_INTERRUPTS(CLBR_NONE)
>> + TRACE_IRQS_OFF
>> + GET_THREAD_INFO(%rcx)
>> + testl %eax, %eax
>> + je error_exit_user
>> + cmpb $0,PER_CPU_VAR(xen_in_preemptible_hcall)
>> + jz retint_kernel
>
> I think I understand this part.
>
>> + movb $0,PER_CPU_VAR(xen_in_preemptible_hcall)
>
> Why? Is the issue that, if preemptible hypercalls nest, you don't
> want to preempt again?
We need to clear and reset this per-cpu variable around the schedule
point since the current task may be rescheduled on a different CPU, or
we may switch to a task that was previously preempted at this point.
That this prevents nested preemption is fine because we only want
hypercalls issued by the privcmd driver on behalf of userspace to be
preemptible.
>> + call cond_resched_irq
>
> On !CONFIG_PREEMPT, there's no preempt_disable, right? So how do you
> guarantee that you don't preempt something you shouldn't? Is the idea
> that these events will only fire nested *directly* inside a
> preemptible hypercall? Also, should you check that IRQs were on when
> the event fired? (Are they on in pt_regs?)
Testing xen_in_preemptible_hcall is sufficient. We bracket the
hypercalls we want to be preemptible like so:
xen_preemptible_hcall_begin();
ret = privcmd_call(hypercall.op,
hypercall.arg[0], hypercall.arg[1],
hypercall.arg[2], hypercall.arg[3],
hypercall.arg[4]);
xen_preemptible_hcall_end();
begin() and end() are somewhat like a Xen-specific prempt_enable() and
preempt_disable(), overriding the default no-preempt state.
>> + movb $1,PER_CPU_VAR(xen_in_preemptible_hcall)
>> + jmp retint_kernel
>> +#endif /* CONFIG_PREEMPT */
>> CFI_ENDPROC
>
> All that being said, this is IMO a bit gross. You've added a bunch of
> asm that's kind of like a parallel error_exit, and the error entry and
> exit code is hairy enough that this scares me. Can you do this mostly
> in C instead? This would look a nicer if it could be:
I abandoned my initial attempt that looked like this because I thought
it was gross too.
> call xen_evtchn_do_upcall
> popq %rsp
> CFI_DEF_CFA_REGISTER rsp
> decl PER_CPU_VAR(irq_count)
> + call xen_end_upcall
> jmp error_exit
>
> Where xen_end_upcall would be witten in C, nokprobes and notrace (if
> needed) and would check pt_regs and whatever else and just call
> schedule if needed?
Oh that's a good idea, thanks!
David
next prev parent reply other threads:[~2014-12-11 11:09 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-10 23:34 [PATCH v2 0/2] x86: add xen hypercall preemption Luis R. Rodriguez
2014-12-10 23:34 ` [PATCH v2 1/2] sched: add cond_resched_irq() Luis R. Rodriguez
2014-12-11 13:31 ` Jan Beulich
[not found] ` <5489AADA020000780004EFB9@suse.com>
2014-12-11 21:06 ` Luis R. Rodriguez
2014-12-10 23:34 ` [PATCH v2 2/2] x86/xen: allow privcmd hypercalls to be preempted Luis R. Rodriguez
2014-12-10 23:51 ` Andy Lutomirski
2014-12-11 0:55 ` Luis R. Rodriguez
2014-12-11 1:04 ` Andy Lutomirski
2014-12-11 11:09 ` David Vrabel [this message]
2014-12-11 21:05 ` [Xen-devel] " Luis R. Rodriguez
2014-12-11 0:29 ` H. Peter Anvin
2014-12-11 1:03 ` Luis R. Rodriguez
2014-12-11 18:47 ` H. Peter Anvin
2014-12-11 20:39 ` Luis R. Rodriguez
2014-12-18 19:23 ` [Xen-devel] " Konrad Rzeszutek Wilk
2015-01-13 21:21 ` Luis R. Rodriguez
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=54897B76.6070500@citrix.com \
--to=david.vrabel@citrix.com \
--cc=JBeulich@suse.com \
--cc=bp@suse.de \
--cc=bpoirier@suse.de \
--cc=hpa@zytor.com \
--cc=jgross@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=masami.hiramatsu.pt@hitachi.com \
--cc=mcgrof@do-not-panic.com \
--cc=mcgrof@suse.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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