All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Bharata B Rao <bharata.rao@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Igor Mammedov <imammedo@redhat.com>,
	Riku Voipio <riku.voipio@iki.fi>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [RFC 2/2] linux-user: Fix cpu_index generation
Date: Thu, 14 Jul 2016 21:59:45 +1000	[thread overview]
Message-ID: <20160714115945.GQ14615@voom.fritz.box> (raw)
In-Reply-To: <CAGZKiBo-H6P++fnHG1Ts3d=My7=rWDHwLz8+JH+RWUa01AiA2g@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3191 bytes --]

On Thu, Jul 14, 2016 at 03:50:56PM +0530, Bharata B Rao wrote:
> On Thu, Jul 14, 2016 at 3:24 PM, Peter Maydell <peter.maydell@linaro.org> wrote:
> > On 14 July 2016 at 08:57, David Gibson <david@gibson.dropbear.id.au> wrote:
> >> With CONFIG_USER_ONLY, generation of cpu_index values is done differently
> >> than for full system targets.  This method turns out to be broken, since
> >> it can fairly easily result in duplicate cpu_index values for
> >> simultaneously active cpus (i.e. threads in the emulated process).
> >>
> >> Consider this sequence:
> >>     Create thread 1
> >>     Create thread 2
> >>     Exit thread 1
> >>     Create thread 3
> >>
> >> With the current logic thread 1 will get cpu_index 1, thread 2 will get
> >> cpu_index 2 and thread 3 will also get cpu_index 2 (because there are 2
> >> threads in the cpus list at the point of its creation).
> >>
> >> We mostly get away with this because cpu_index values aren't that important
> >> for userspace emulation.  Still, it can't be good, so this patch fixes it
> >> by making CONFIG_USER_ONLY use the same bitmap based allocation that full
> >> system targets already use.
> >>
> >> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> >> ---
> >>  exec.c | 19 -------------------
> >>  1 file changed, 19 deletions(-)
> >>
> >> diff --git a/exec.c b/exec.c
> >> index 011babd..e410dab 100644
> >> --- a/exec.c
> >> +++ b/exec.c
> >> @@ -596,7 +596,6 @@ AddressSpace *cpu_get_address_space(CPUState *cpu, int asidx)
> >>  }
> >>  #endif
> >>
> >> -#ifndef CONFIG_USER_ONLY
> >>  static DECLARE_BITMAP(cpu_index_map, MAX_CPUMASK_BITS);
> >>
> >>  static int cpu_get_free_index(Error **errp)
> >> @@ -617,24 +616,6 @@ static void cpu_release_index(CPUState *cpu)
> >>  {
> >>      bitmap_clear(cpu_index_map, cpu->cpu_index, 1);
> >>  }
> >> -#else
> >> -
> >> -static int cpu_get_free_index(Error **errp)
> >> -{
> >> -    CPUState *some_cpu;
> >> -    int cpu_index = 0;
> >> -
> >> -    CPU_FOREACH(some_cpu) {
> >> -        cpu_index++;
> >> -    }
> >> -    return cpu_index;
> >> -}
> >> -
> >> -static void cpu_release_index(CPUState *cpu)
> >> -{
> >> -    return;
> >> -}
> >> -#endif
> >
> > Won't this change impose a maximum limit of 256 simultaneous
> > threads? That seems a little low for comfort.
> 
> This was the reason why the bitmap logic wasn't applied to
> CONFIG_USER_ONLY when it was introduced.
> 
> https://lists.gnu.org/archive/html/qemu-devel/2015-05/msg01980.html

Ah.. good point.

Hrm, ok, my next idea would be to just (globally) sequentially
allocate cpu_index values for CONFIG_USER, and never try to re-use
them.  Does that seem reasonable?

> But then we didn't have actual removal, but we do now.

You mean patch 1/2 in this set?  Or something else?

Even so, 256 does seem a bit low for a number of simultaneously active
threads - there are some bug hairy multi-threaded programs out there.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-07-14 12:57 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14  7:57 [Qemu-devel] [RFC 0/2] Fix some bugs in usermode cpu tracking David Gibson
2016-07-14  7:57 ` [Qemu-devel] [RFC 1/2] linux-user: Don't leak cpus on thread exit David Gibson
2016-07-14  9:52   ` Peter Maydell
2016-07-14 12:02     ` David Gibson
2016-07-14 13:05       ` Igor Mammedov
2016-07-15  2:53         ` David Gibson
2016-07-14  7:57 ` [Qemu-devel] [RFC 2/2] linux-user: Fix cpu_index generation David Gibson
2016-07-14  9:54   ` Peter Maydell
2016-07-14 10:20     ` Bharata B Rao
2016-07-14 11:59       ` David Gibson [this message]
2016-07-15 22:11         ` Greg Kurz
2016-07-18  1:17           ` David Gibson
2016-07-18  7:25             ` Igor Mammedov
2016-07-18  9:58               ` David Gibson
2016-07-18  8:52             ` Greg Kurz
2016-07-18  9:50               ` David Gibson

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=20160714115945.GQ14615@voom.fritz.box \
    --to=david@gibson.dropbear.id.au \
    --cc=bharata.rao@gmail.com \
    --cc=imammedo@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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.