From: Paul Brook <paul@codesourcery.com>
To: qemu-devel@nongnu.org, thayne@c2.net
Cc: TJ <linux@tjworld.net>
Subject: Re: [Qemu-devel] RFC: x86_64 Best way to fix 'cast to pointer from integer of different size' problems?
Date: Tue, 6 Nov 2007 01:05:03 +0000 [thread overview]
Message-ID: <200711060105.04529.paul@codesourcery.com> (raw)
In-Reply-To: <1194292268.5154.73.camel@phantasm.home.enterpriseandprosperity.com>
> access_ok() and lock_user() perform essential functions. lock_user(),
> however, isn't directly comparable to how the kernel operates and should
> therefore be encapsulated inside more typical kernel functions such as
> {get,put}_user(), copy_{to,from}_user() and the like. access_ok() and
> lock_user() also have overhead and should therefore be used with the
> largest memory hunks possible (e.g.: they should be used with an entire
> structure - not with each individual data member of the structure).
> That is why __{get,put}_user() exist: for copying the individual data
> members of a structure once the *entire* structure has had access
> checked and the address translation is performed.
> I don't think there's an appropriate way
> to eliminate either {lock,unlock}_user() or {get,put}_user() and keep
> comparable coding semantics to the kernel.
Your argument seems inconsistent to me. The kernel doesn't have lock_user at
all, so how can using it be consistent with kernel code?
There are two different strategies for accessing user data. Either:
- Use a copying interface. i.e. get_user (for single values) or
copy_from_user (for blocks/structures).
- Use a locking interface. i.e. lock_user.
Personally I like the locking interface as it allows a zero-copy
implementation. However the kernel uses a copying interface, and my
understanding is that other qemu maintainers also prefer the copying
interface.
You need to pick one interface (get/put/copy or lock) and stick to it. If
get_user actually just does byteswapping of values in host memory then IMHO
it really needs to be renamed (to tswap).
Part of the problem may be that linux assumes that both kernel and userspace
pointers can be represented by the compiler. This allows it to do address
arithmetic and take the address of members of pointers to userspace
structures. qemu can not do this.
qemu also has to deal with endian conversion. The kernel does not. This means
that some data the kernel may be able to copy/pass/access unmodified needs
special treatment in qemu.
Paul
next prev parent reply other threads:[~2007-11-06 1:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-03 17:26 [Qemu-devel] RFC: x86_64 Best way to fix 'cast to pointer from integer of different size' problems? TJ
2007-11-03 17:52 ` Paul Brook
2007-11-05 19:51 ` Thayne Harbaugh
2007-11-06 1:05 ` Paul Brook [this message]
2007-11-06 2:00 ` Thayne Harbaugh
2007-11-07 19:18 ` Fabrice Bellard
2007-11-07 20:59 ` Thayne Harbaugh
2007-11-07 23:02 ` Paul Brook
2007-11-12 16:42 ` Thayne Harbaugh
2007-11-06 20:05 ` Fabrice Bellard
2007-11-06 21:52 ` Stuart Anderson
2007-11-06 22:05 ` Paul Brook
2007-11-06 22:19 ` Stuart Anderson
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=200711060105.04529.paul@codesourcery.com \
--to=paul@codesourcery.com \
--cc=linux@tjworld.net \
--cc=qemu-devel@nongnu.org \
--cc=thayne@c2.net \
/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).