From: Dario Faggioli <dario.faggioli@citrix.com>
To: Meng Xu <xumengpanda@gmail.com>, "Xu, Quan" <quan.xu@intel.com>
Cc: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>,
Jan Beulich <jbeulich@suse.com>,
"xen-devel@lists.xen.org" <xen-devel@lists.xen.org>
Subject: Re: [PATCH v3 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization
Date: Fri, 11 Mar 2016 16:55:53 +0100 [thread overview]
Message-ID: <1457711753.3102.597.camel@citrix.com> (raw)
In-Reply-To: <CAENZ-+nR4C848CvfNms-hygfZyHY-S76Wzioe3XvUerR24xjgQ@mail.gmail.com>
[-- Attachment #1.1: Type: text/plain, Size: 4599 bytes --]
On Fri, 2016-03-11 at 09:49 -0500, Meng Xu wrote:
> > Yes.
> > Consistency may be helpful to avoid some easy-to-avoid lock errors.
> > Moreover, without my fix, I think it would not lead dead lock, as
> > the pcidevs_lock is not being taken
> > In IRQ context. Right?
> I think without your fix, the deadlock may still happen due to the
> rendezvous condition.
> CPU A | CPU B
> | CPU C
> Step 1| spin_lock |
> Step 2| |
> spin_lock_irq |
> Step 3| | wait for A to
> unlock |
> Step 4|
> | send rendezvous IPI to A and B
> Step 5| receive IPI | wait for A to
> unlock |
> Step 6| wait for B to handle the IPI | wait for A to unlock |
> Step 7| spin_unlock
>
>
> Deadlock occurs at Step 6, IMO.
>
> Unless we can prove that rendezvous won't happen while
> spin_lock_irqsave is taken, we have the deadlock hazard.
>
Yes. But, in the case of Quan's patch (without it, I mean), have you
seen where in the code it is that we use spin_lock_irqsave()?
It's inside a function that is called during Xen boot, whose callchain
starts with iommu_setup(), from __start_xen(). Here's a (big, sorry)
code snippet of what is around iommu_setup():
...
init_idle_domain();
this_cpu(stubs.addr) = alloc_stub_page(smp_processor_id(),
&this_cpu(stubs).mfn);
BUG_ON(!this_cpu(stubs.addr));
trap_init();
rcu_init();
early_time_init();
arch_init_memory();
alternative_instructions();
local_irq_enable();
pt_pci_init();
vesa_mtrr_init();
acpi_mmcfg_init();
early_msi_init();
iommu_setup(); /* setup iommu if available */
smp_prepare_cpus(max_cpus);
spin_debug_enable();
/*
* Initialise higher-level timer functions. We do this fairly late
* (after interrupts got enabled) because the time bases and scale
* factors need to be updated regularly.
*/
init_xen_time();
initialize_keytable();
console_init_postirq();
system_state = SYS_STATE_smp_boot;
do_presmp_initcalls();
for_each_present_cpu ( i )
{
/* Set up cpu_to_node[]. */
srat_detect_node(i);
/* Set up node_to_cpumask based on cpu_to_node[]. */
numa_add_cpu(i);
if ( (num_online_cpus() < max_cpus) && !cpu_online(i) )
{
int ret = cpu_up(i);
if ( ret != 0 )
printk("Failed to bring up CPU %u (error %d)\n", i, ret);
}
}
printk("Brought up %ld CPUs\n", (long)num_online_cpus());
...
As you can see, it is only *after* iommu_setup() that we call functions
like smp_prepare_cpus(), do_presmp_initcalls(), and then the loop that
waits for all the present CPUs to come online.
What that means is that, at iommu_setup() time, there still is only one
CPU online, and there is not much chances that one single CPU deadlocks
in a rendezvous!
Honestly, the biggest issue that I think Quan's patch solves, is that
if we ever want/manage to move spin_debug_enable() up above it, then
the BUG_ON in check_lock() would trigger the first time that
pcidevs_lock would be taken with interrupts enabled.
Until then, code is technically fine, and, as a matter of fact, I think
that removing the locking from that particular instance would be an
equally effective fix!
All that being said, consistency is indeed important, and for the sake
of it and for other reasons too, even if, strictly speaking, there
isn't any actual buggy behavior to be fixed here, and it is worthwhile
conforming to a locking pattern that is consistent with the rules that
we sat ourselves, unless there's specific reasons not to.
Regards,
Dario
--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
[-- Attachment #2: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-03-11 15:55 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-09 13:17 [PATCH v3 0/2] Make the pcidevs_lock a recursive one Quan Xu
2016-03-09 13:17 ` [PATCH v3 1/2] IOMMU/spinlock: Fix a bug found in AMD IOMMU initialization Quan Xu
2016-03-09 14:59 ` Dario Faggioli
2016-03-10 6:12 ` Xu, Quan
2016-03-11 3:24 ` Meng Xu
2016-03-11 6:54 ` Xu, Quan
2016-03-11 10:35 ` Dario Faggioli
2016-03-11 12:36 ` Xu, Quan
2016-03-11 13:58 ` Dario Faggioli
2016-03-11 14:49 ` Meng Xu
2016-03-11 15:55 ` Dario Faggioli [this message]
2016-03-11 17:17 ` Meng Xu
2016-03-11 14:41 ` Meng Xu
2016-03-11 16:12 ` Dario Faggioli
2016-03-09 13:17 ` [PATCH v3 2/2] IOMMU/spinlock: Make the pcidevs_lock a recursive one Quan Xu
2016-03-09 17:45 ` Dario Faggioli
2016-03-10 1:21 ` Xu, Quan
2016-03-10 9:52 ` Jan Beulich
2016-03-10 11:27 ` Xu, Quan
2016-03-10 13:06 ` Jan Beulich
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=1457711753.3102.597.camel@citrix.com \
--to=dario.faggioli@citrix.com \
--cc=jbeulich@suse.com \
--cc=quan.xu@intel.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=xen-devel@lists.xen.org \
--cc=xumengpanda@gmail.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.