translate-all: ensure host page mask is always extended with 1's

Anthony reported that >4GB guests on Xen with 32bit QEMU broke after
commit 4ed023c ("Round up RAMBlock sizes to host page sizes", 2015-11-05).

In that patch sizes are masked against qemu_host_page_size/mask which
are uintptr_t, and thus 32bit on a 32bit QEMU, even though the ram space
might be bigger than 4GB on Xen.

Since ram_addr_t is not available on user-mode emulation targets, ensure
that we get a sign extension when masking away the low bits of the address.
Remove the ~10 year old scary comment that the type of these variables
is probably wrong, with another equally scary comment. The new comment
however does not have "???" in it, which is arguably an improvement.

For completeness use the alignment macros in linux-user and bsd-user
instead of manually doing an &. linux-user and bsd-user are not affected
by the Xen issue, however.

Backports commit 0c2d70c448b7853a91cfa63659aa3cc6630fb9be from qemu
This commit is contained in:
Lioncash 2018-02-17 19:17:16 -05:00
parent 86436964b5
commit c8be425439
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7

View file

@ -119,9 +119,9 @@ typedef struct PageDesc {
#define V_L1_SHIFT (L1_MAP_ADDR_SPACE_BITS - TARGET_PAGE_BITS - V_L1_BITS)
static uintptr_t qemu_real_host_page_size;
static intptr_t qemu_real_host_page_mask;
static uintptr_t qemu_host_page_size;
static uintptr_t qemu_host_page_mask;
static intptr_t qemu_host_page_mask;
static void tb_link_page(struct uc_struct *uc, TranslationBlock *tb,
tb_page_addr_t phys_pc, tb_page_addr_t phys_page2);
@ -317,13 +317,14 @@ static void page_size_init(void)
/* NOTE: we can always suppose that qemu_host_page_size >=
TARGET_PAGE_SIZE */
qemu_real_host_page_size = getpagesize();
qemu_real_host_page_mask = -(intptr_t)qemu_real_host_page_size;
if (qemu_host_page_size == 0) {
qemu_host_page_size = qemu_real_host_page_size;
}
if (qemu_host_page_size < TARGET_PAGE_SIZE) {
qemu_host_page_size = TARGET_PAGE_SIZE;
}
qemu_host_page_mask = ~(qemu_host_page_size - 1);
qemu_host_page_mask = -(intptr_t)qemu_host_page_size;
}
static void page_init(void)