From patchwork Mon Dec 5 11:01:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 5451 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 85DA723E2A for ; Mon, 5 Dec 2011 11:01:40 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id 65742A183ED for ; Mon, 5 Dec 2011 11:01:40 +0000 (UTC) Received: by lagm6 with SMTP id m6so83806lag.11 for ; Mon, 05 Dec 2011 03:01:40 -0800 (PST) Received: by 10.152.145.233 with SMTP id sx9mr5609698lab.6.1323082900087; Mon, 05 Dec 2011 03:01:40 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs250779lal; Mon, 5 Dec 2011 03:01:39 -0800 (PST) Received: by 10.213.3.80 with SMTP id 16mr796539ebm.59.1323082898462; Mon, 05 Dec 2011 03:01:38 -0800 (PST) Received: from chiark.greenend.org.uk (chiark.greenend.org.uk. [212.13.197.229]) by mx.google.com with ESMTPS id o19si6367873eea.98.2011.12.05.03.01.37 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 05 Dec 2011 03:01:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pmaydell@chiark.greenend.org.uk designates 212.13.197.229 as permitted sender) client-ip=212.13.197.229; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of pmaydell@chiark.greenend.org.uk designates 212.13.197.229 as permitted sender) smtp.mail=pmaydell@chiark.greenend.org.uk Received: by chiark.greenend.org.uk (Debian Exim 4.69 #1) with local (return-path pmaydell@chiark.greenend.org.uk) id 1RXWIj-0003yG-1J; Mon, 05 Dec 2011 11:01:37 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Avi Kivity , Paul Brook Subject: [PATCH] exec.c: Allow memory region start_addr and region_offset to vary in low bits Date: Mon, 5 Dec 2011 11:01:37 +0000 Message-Id: <1323082897-15249-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.5.6.5 Sender: Peter Maydell Fix a long-standing deficiency of cpu_register_physical_memory_log() where the start address and region offset had to have the same low bits (otherwise the IO functions would be passed an incorrect address offset). This was most likely to bite when registering memory regions which started at a non-page-boundary. Signed-off-by: Peter Maydell --- This is such a small change to correct this issue that I'm kind of suspicious of it :-) exec.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-) diff --git a/exec.c b/exec.c index 6b92198..7030cea 100644 --- a/exec.c +++ b/exec.c @@ -2655,10 +2655,7 @@ static subpage_t *subpage_init (target_phys_addr_t base, ram_addr_t *phys, For RAM, 'size' must be a multiple of the target page size. If (phys_offset & ~TARGET_PAGE_MASK) != 0, then it is an io memory page. The address used when calling the IO function is - the offset from the start of the region, plus region_offset. Both - start_addr and region_offset are rounded down to a page boundary - before calculating this offset. This should not be a problem unless - the low bits of start_addr and region_offset differ. */ + the offset from the start of the region, plus region_offset. */ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, ram_addr_t size, ram_addr_t phys_offset, @@ -2677,7 +2674,11 @@ void cpu_register_physical_memory_log(target_phys_addr_t start_addr, if (phys_offset == IO_MEM_UNASSIGNED) { region_offset = start_addr; } - region_offset &= TARGET_PAGE_MASK; + /* Adjust the region offset to account for the start_addr possibly + * not being page aligned, so we end up passing the IO functions + * the true offset from the start of the region. + */ + region_offset -= (start_addr & ~TARGET_PAGE_MASK); size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK; end_addr = start_addr + (target_phys_addr_t)size;