linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <liu.song.a23@gmail.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Borislav Petkov <bp@alien8.de>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Tariq Toukan <tariqt@mellanox.com>,
	Joerg Roedel <jroedel@suse.de>, Mike Travis <mike.travis@hpe.com>,
	stable@vger.kernel.org
Subject: Re: [patch 1/8] x86/apic/vector: Prevent hlist corruption and leaks
Date: Tue, 5 Jun 2018 00:06:25 -0700	[thread overview]
Message-ID: <CAPhsuW60JCLpVkkJdixd1M1MNGXMwng8YwLoAF6KP_Uo3POE6g@mail.gmail.com> (raw)
In-Reply-To: <20180604162224.303870257@linutronix.de>

On Mon, Jun 4, 2018 at 8:33 AM, Thomas Gleixner <tglx@linutronix.de> wrote:
> Several people observed the WARN_ON() in irq_matrix_free() which triggers
> when the caller tries to free an vector which is not in the allocation
> range. Song provided the trace information which allowed to decode the root
> cause.
>
> The rework of the vector allocation mechanism failed to preserve a sanity
> check, which prevents setting a new target vector/CPU when the previous
> affinity change has not fully completed.
>
> As a result a half finished affinity change can be overwritten, which can
> cause the leak of a irq descriptor pointer on the previous target CPU and
> double enqueue of the hlist head into the cleanup lists of two or more
> CPUs. After one CPU cleaned up its vector the next CPU will invoke the
> cleanup handler with vector 0, which triggers the out of range warning in
> the matrix allocator.
>
> Prevent this by checking the apic_data of the interrupt whether the
> move_in_progress flag is false and the hlist node is not hashed. Return
> -EBUSY if not.
>
> This prevents the damage and restores the behaviour before the vector
> allocation rework, but due to other changes in that area it also widens the
> chance that user space can observe -EBUSY. In theory this should be fine,
> but actually not all user space tools handle -EBUSY correctly. Addressing
> that is not part of this fix, but will be addressed in follow up patches.
>
> Fixes: 69cde0004a4b ("x86/vector: Use matrix allocator for vector assignment")
> Reported-by: Dmitry Safonov <0x7f454c46@gmail.com>
> Reported-by: Tariq Toukan <tariqt@mellanox.com>
> Reported-by: Song Liu <liu.song.a23@gmail.com>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: stable@vger.kernel.org

Thanks Thomas!

This patch alone fixes my test: ethtool -L in a loop.

I also run the same test for the full set, and it works well.

Tested-by: Song Liu <songliubraving@fb.com>


> ---
>  arch/x86/kernel/apic/vector.c |    9 +++++++++
>  1 file changed, 9 insertions(+)
>
> --- a/arch/x86/kernel/apic/vector.c
> +++ b/arch/x86/kernel/apic/vector.c
> @@ -235,6 +235,15 @@ static int allocate_vector(struct irq_da
>         if (vector && cpu_online(cpu) && cpumask_test_cpu(cpu, dest))
>                 return 0;
>
> +       /*
> +        * Careful here. @apicd might either have move_in_progress set or
> +        * be enqueued for cleanup. Assigning a new vector would either
> +        * leave a stale vector on some CPU around or in case of a pending
> +        * cleanup corrupt the hlist.
> +        */
> +       if (apicd->move_in_progress || !hlist_unhashed(&apicd->clist))
> +               return -EBUSY;
> +
>         vector = irq_matrix_alloc(vector_matrix, dest, resvd, &cpu);
>         if (vector > 0)
>                 apic_update_vector(irqd, vector, cpu);
>
>

  reply	other threads:[~2018-06-05  7:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-04 15:33 [patch 1/8] x86/apic/vector: Prevent hlist corruption and leaks Thomas Gleixner
2018-06-05  7:06 ` Song Liu [this message]
2018-06-06 13:30 ` [tip:x86/urgent] " tip-bot for Thomas Gleixner

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=CAPhsuW60JCLpVkkJdixd1M1MNGXMwng8YwLoAF6KP_Uo3POE6g@mail.gmail.com \
    --to=liu.song.a23@gmail.com \
    --cc=0x7f454c46@gmail.com \
    --cc=bp@alien8.de \
    --cc=jroedel@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mike.travis@hpe.com \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=tariqt@mellanox.com \
    --cc=tglx@linutronix.de \
    /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).