All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Chen Gang <xili_gchen_5257@hotmail.com>,
	Alexander Graf <agraf@suse.de>,
	qemu-devel <qemu-devel@nongnu.org>
Subject: [Qemu-devel] Plan for using softmmu with linux-user
Date: Thu, 13 Aug 2015 09:55:29 -0700	[thread overview]
Message-ID: <55CCCC01.3050501@twiddle.net> (raw)
In-Reply-To: <BLU436-SMTP24171B64C1E70913A13FD0DB97D0@phx.gbl>

[ Re-adding qemu-devel so that the plan can be critiqued. ]

On 08/13/2015 07:32 AM, Chen Gang wrote:
> On 8/13/15 22:05, Richard Henderson wrote:
>> On 08/13/2015 12:20 AM, gchen gchen wrote:
>>> Excuse me, I am not quite familiar with it, could any members provide
>>> more details about "use softmmu with linux-user" or "softmmu but without
>>> system emulation"?
>>
>> It doesn't exist yet.  It must be written.
>>
> 
> OK, thanks, and I shall try to implement it ...

My best guess that this is 3-4 months of work.

The current code within linux-user needs to be abstracted.  The new interface
must handle several things:

 (1) Finding unmapped portions of the guest address space.
 (2) Mapping anonymous memory into the guest address space.
 (3) Mapping files into the guest address space.
 (4) Filling in struct iovec for the host pages of a
     contiguous guest memory block.
 (5) Copying guest data to/from a contiguous host data block
     (like lock_user/unlock_user).

The current code has some of the above.

With the current implementation, (2) and (3) are mostly trivial.  There is
extra complex code to attempt these when host and guest page sizes differ, but
it's not completely correct.  And it definitely fails when 64-bit guests
running on 32-bit hosts attempt to map data above 4GB.

We don't currently have a need for (4), as contiguous guest pages currently
always imply contiguous host pages.  But with softmmu that will change, and the
speed of emulation for basic operations like read and write will be much
improved if we can issue readv and writev syscalls to the host os.

If (4) fails, or if there's no equivalent syscall that takes an iovec, then
copy in/out is the only solution.  Obviously we have a solution for the current
linux-user with lock_user/unlock_user.

The sets of patches that we should see will look something like this:

  (A1) Define the interface, and sets of callbacks.  This, IMO, should be done
       at the top level of qemu so that (eventually) both linux-user
       and bsd-user can share the code.

  (A2) Convert the existing two implementations to the set of callbacks.
       Note that I consider RESERVED_VA and !RESERVED_VA (unreserved_va?)
       different.  They do share some code, so callbacks for (4) and (5)
       will be the same, but certainly not the callbacks for (1), (2) or (3).

  (A3) Update linux-user to use the new interface, without (4).

  (A4) Update linux-user to use the new call for (4), for the syscalls
       that have iovec equivalents.

  (B) Replace the define CONFIG_SOFTMMU with a variable use_softmmu.
      In system mode (ifndef CONFIG_USER_ONLY), this should be a define that
      is always true, so that the dead code can be eliminated.  In user mode,
      this will be set depending on the guest mapping interface selected.

At this point you've really not changed anything, algorithmically. Everything
is working just the same as before you started, but the code is now in a form
where softmmu can be introduced.

  (C) Create the softmmu_user implementation.  You'll need something like the
      kernel's vm_area_struct to record ranges of guest address space
      mappings.  It'll need to be fast, as that data structure will provide
      the implementation for tlb_fill.

  (D) In the absence of command-line options, auto-select the most appropriate
      implementation:

      (1) If the host and guest page sizes don't match, select softmmu_user.
      (2) Otherwise, if 32-bit guest and 64-bit host, select reserved_va.
      (3) Otherwise, if a guest_base can be found to safely map the guest
          binary into the host address space (e.g. a 64-bit binary isn't
          linked above 4GB on a 32-bit host), select unreserved_va.
      (4) Otherwise, select softmmu.


r~

  parent reply	other threads:[~2015-08-13 16:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <55CAE18F.9080004@hotmail.com>
2015-08-12  6:03 ` [Qemu-devel] [PATCH] linux-user: elfload: Still use TARGET_PAGE_SIZE for i386 guest gchen gchen
2015-08-12  6:45   ` Richard Henderson
     [not found]     ` <55CAFCD7.20405@hotmail.com>
2015-08-12  7:59       ` gchen gchen
     [not found]         ` <55CB0ADC.3050303@hotmail.com>
2015-08-12  9:00           ` gchen gchen
2015-09-11  4:06             ` Chen Gang
2015-08-12 15:06         ` Richard Henderson
     [not found]           ` <55CBF7B1.3060001@hotmail.com>
2015-08-13  1:50             ` gchen gchen
     [not found]           ` <55CBF7AA.2050507@hotmail.com>
2015-08-13  2:45             ` gchen gchen
2015-08-13  3:00               ` Alexander Graf
     [not found]                 ` <55CC11C7.5070308@hotmail.com>
     [not found]                   ` <COL130-W265E4C6CD5E6E855799910B97D0@phx.gbl>
     [not found]                     ` <55CC44BF.3010503@hotmail.com>
     [not found]                       ` <COL130-W43A734B70892EBF38C8CD8B97D0@phx.gbl>
     [not found]                         ` <55CCA422.80706@twiddle.net>
     [not found]                           ` <BLU436-SMTP24171B64C1E70913A13FD0DB97D0@phx.gbl>
2015-08-13 16:55                             ` Richard Henderson [this message]
     [not found]                               ` <55CD5ECA.6090705@hotmail.com>
2015-08-14  3:22                                 ` [Qemu-devel] Plan for using softmmu with linux-user gchen gchen
     [not found]                               ` <55CD5F09.8010704@hotmail.com>
2015-08-14  3:25                                 ` gchen gchen
2015-08-14  8:44                                   ` Peter Maydell
     [not found]                                     ` <55CDB679.6000806@hotmail.com>
2015-08-14  9:37                                       ` gchen gchen
2015-08-14 14:44                                         ` Richard Henderson
2015-08-14 20:45                                           ` Chen Gang
     [not found]                                             ` <55D43765.9010101@hotmail.com>
2015-08-19  8:01                                               ` gchen gchen
     [not found]                                                 ` <55DE8C0B.40808@hotmail.com>
2015-08-27  4:04                                                   ` Chen Gang

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=55CCCC01.3050501@twiddle.net \
    --to=rth@twiddle.net \
    --cc=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=xili_gchen_5257@hotmail.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.