From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KwCrK-0001U3-6J for qemu-devel@nongnu.org; Sat, 01 Nov 2008 05:33:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KwCrH-0001Tj-Rd for qemu-devel@nongnu.org; Sat, 01 Nov 2008 05:33:29 -0400 Received: from [199.232.76.173] (port=56509 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KwCrH-0001Tg-Nb for qemu-devel@nongnu.org; Sat, 01 Nov 2008 05:33:27 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:54814) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KwCrG-0008Fh-CG for qemu-devel@nongnu.org; Sat, 01 Nov 2008 05:33:27 -0400 Message-ID: <490C2253.3020005@web.de> Date: Sat, 01 Nov 2008 10:33:07 +0100 From: Jan Kiszka MIME-Version: 1.0 References: <1223892640-15545-13-git-send-email-kirill@shutemov.name> <1224225264-8483-1-git-send-email-kirill@shutemov.name> <1224225264-8483-2-git-send-email-kirill@shutemov.name> In-Reply-To: <1224225264-8483-2-git-send-email-kirill@shutemov.name> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigC3304EBA2D44DF10EA2981C2" Sender: jan.kiszka@web.de Subject: [Qemu-devel] Re: [PATCH] linux-user, x86: use target_mmap() to allocate idt, gdt and ldt tables Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Kirill A. Shutemov" This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigC3304EBA2D44DF10EA2981C2 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: quoted-printable Kirill A. Shutemov wrote: > env->*dt.base should fits target address space, so we should use > target_mmap to allocate it. I just noticed that this bug is still unfixed upstream, was about to repost my corresponding patch [1], but then found this even nicer approach. Could someone please finally merge a fix? Kirill, do you also have a patch for the problem [2] addresses in your queue? Last time I posted my series, Anthony remarked that the role of the linux-user maintainer is vacant. My impression is that this is still the case while at the same time Kirill is doing quite a good job now getting this corner of qemu in shape again...... :-> Jan [1] http://permalink.gmane.org/gmane.comp.emulators.qemu/28386 [2] http://permalink.gmane.org/gmane.comp.emulators.qemu/28385 >=20 > Signed-off-by: Kirill A. Shutemov > --- > linux-user/main.c | 23 +++++++++++++++-------- > linux-user/syscall.c | 10 ++++++---- > 2 files changed, 21 insertions(+), 12 deletions(-) >=20 > diff --git a/linux-user/main.c b/linux-user/main.c > index 25b2867..61d497e 100644 > --- a/linux-user/main.c > +++ b/linux-user/main.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > =20 > #include "qemu.h" > #include "qemu-common.h" > @@ -283,9 +284,8 @@ static void write_dt(void *ptr, unsigned long addr,= unsigned long limit, > p[1] =3D tswap32(e2); > } > =20 > +uint64_t *idt_table; This should become static... > #ifdef TARGET_X86_64 > -uint64_t idt_table[512]; =2E..as this is now static as well. > - > static void set_gate64(void *ptr, unsigned int type, unsigned int dpl,= > uint64_t addr, unsigned int sel) > { > @@ -304,8 +304,6 @@ static void set_idt(int n, unsigned int dpl) > set_gate64(idt_table + n * 2, 0, dpl, 0, 0); > } > #else > -uint64_t idt_table[256]; > - > static void set_gate(void *ptr, unsigned int type, unsigned int dpl, > uint32_t addr, unsigned int sel) > { > @@ -2500,8 +2498,15 @@ int main(int argc, char **argv, char **envp) > #endif > =20 > /* linux interrupt setup */ > - env->idt.base =3D h2g(idt_table); > - env->idt.limit =3D sizeof(idt_table) - 1; > +#ifndef TARGET_ABI32 > + env->idt.limit =3D 511; > +#else > + env->idt.limit =3D 255; > +#endif > + env->idt.base =3D target_mmap(0, sizeof(uint64_t) * (env->idt.limi= t + 1), > + PROT_READ|PROT_WRITE, > + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > + idt_table =3D g2h(env->idt.base); > set_idt(0, 0); > set_idt(1, 0); > set_idt(2, 0); > @@ -2527,9 +2532,11 @@ int main(int argc, char **argv, char **envp) > /* linux segment setup */ > { > uint64_t *gdt_table; > - gdt_table =3D qemu_mallocz(sizeof(uint64_t) * TARGET_GDT_ENTRI= ES); > - env->gdt.base =3D h2g((unsigned long)gdt_table); > + env->gdt.base =3D target_mmap(0, sizeof(uint64_t) * TARGET_GDT= _ENTRIES, > + PROT_READ|PROT_WRITE, > + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);= > env->gdt.limit =3D sizeof(uint64_t) * TARGET_GDT_ENTRIES - 1; > + gdt_table =3D g2h(env->gdt.base); > #ifdef TARGET_ABI32 > write_dt(&gdt_table[__USER_CS >> 3], 0, 0xfffff, > DESC_G_MASK | DESC_B_MASK | DESC_P_MASK | DESC_S_MASK= | > diff --git a/linux-user/syscall.c b/linux-user/syscall.c > index db3538b..27bd7e1 100644 > --- a/linux-user/syscall.c > +++ b/linux-user/syscall.c > @@ -2823,12 +2823,14 @@ static abi_long write_ldt(CPUX86State *env, > } > /* allocate the LDT */ > if (!ldt_table) { > - ldt_table =3D malloc(TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZ= E); > - if (!ldt_table) > + env->ldt.base =3D target_mmap(0, TARGET_LDT_ENTRIES * TARGET_L= DT_ENTRY_SIZE, > + PROT_READ|PROT_WRITE, > + MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);= > + if (env->ldt.base =3D=3D -1) > return -TARGET_ENOMEM; > - memset(ldt_table, 0, TARGET_LDT_ENTRIES * TARGET_LDT_ENTRY_SIZ= E); > - env->ldt.base =3D h2g((unsigned long)ldt_table); > + memset(g2h(env->ldt.base), 0, TARGET_LDT_ENTRIES * TARGET_LDT_= ENTRY_SIZE); > env->ldt.limit =3D 0xffff; > + ldt_table =3D g2h(env->ldt.base); > } > =20 > /* NOTE: same code as Linux kernel */ --------------enigC3304EBA2D44DF10EA2981C2 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iEYEARECAAYFAkkMIlYACgkQniDOoMHTA+kyPwCfZOqjSvF+qvha3OZfHYckOaCx SoEAnjGi8DCTtmYkQGJX4UVI3i+wgxeV =OgPf -----END PGP SIGNATURE----- --------------enigC3304EBA2D44DF10EA2981C2--