From patchwork Thu Nov 8 20:58:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason J. Herne" X-Patchwork-Id: 197898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E28122C00F8 for ; Fri, 9 Nov 2012 08:40:58 +1100 (EST) Received: from localhost ([::1]:32962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWZqK-0006K8-VW for incoming@patchwork.ozlabs.org; Thu, 08 Nov 2012 16:40:56 -0500 Received: from eggs.gnu.org ([208.118.235.92]:52744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWZLk-0001Fn-Mj for qemu-devel@nongnu.org; Thu, 08 Nov 2012 16:09:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TWZLj-0005ih-3o for qemu-devel@nongnu.org; Thu, 08 Nov 2012 16:09:20 -0500 Received: from e8.ny.us.ibm.com ([32.97.182.138]:48259) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TWZLi-0005Vj-UX for qemu-devel@nongnu.org; Thu, 08 Nov 2012 16:09:19 -0500 Received: from /spool/local by e8.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Nov 2012 15:58:44 -0500 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e8.ny.us.ibm.com (192.168.1.108) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 8 Nov 2012 15:58:41 -0500 Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com [9.56.227.234]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 1B68B38C8041 for ; Thu, 8 Nov 2012 15:58:41 -0500 (EST) Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by d01relay02.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id qA8KwemQ303464 for ; Thu, 8 Nov 2012 15:58:40 -0500 Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id qA8KwdXg008490 for ; Thu, 8 Nov 2012 18:58:40 -0200 Received: from w500-1204.endicott.ibm.com (w500-1204.endicott.ibm.com [9.60.75.153] (may be forged)) by d01av03.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id qA8KwdBT008467; Thu, 8 Nov 2012 18:58:39 -0200 From: "Jason J. Herne" To: qemu-devel@nongnu.org Date: Thu, 8 Nov 2012 15:58:38 -0500 Message-Id: <1352408318-10303-1-git-send-email-jjherne@us.ibm.com> X-Mailer: git-send-email 1.7.9.5 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12110820-9360-0000-0000-00000C94856D X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.182.138 X-Mailman-Approved-At: Thu, 08 Nov 2012 16:40:49 -0500 Cc: borntraeger@de.ibm.com, "Jason J. Herne" Subject: [Qemu-devel] [PATCH] Bugfix: Align cpu_physical_memory_set_dirty_flags() addr to page boundary X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Jason J. Herne" Some code paths call cpu_physical_memory_set_dirty_flags() with an address that is not on a page boundary. The subsequent call to cpu_physical_memory_get_dirty is assuming page boundary alignment because it hard codes a length of TARGET_PAGE_SIZE. This causes problems when the target address lies within a page whose "migration dirty bit" is NOT set, but the following page's "migration dirty bit" is set. In this case, cpu_physical_memory_get_dirty will claim that the page is already dirty when it is not. cpu_physical_memory_set_dirty_flags then skips incrementing ram_list.dirty_pages but still updates the target page's dirty bit with the following code: ram_list.phys_dirty[addr >> TARGET_PAGE_BITS] |= dirty_flags; This causes our counter to less than the actual number of dirty bits. This can cause our migration remaining ram counter to underflow and can even hang migration in some cases. Signed-off-by: Jason J. Herne --- exec-obsolete.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/exec-obsolete.h b/exec-obsolete.h index c099256..8746578 100644 --- a/exec-obsolete.h +++ b/exec-obsolete.h @@ -74,6 +74,9 @@ static inline int cpu_physical_memory_get_dirty(ram_addr_t start, static inline int cpu_physical_memory_set_dirty_flags(ram_addr_t addr, int dirty_flags) { + /* align addr to a page boundary */ + addr = (addr >> TARGET_PAGE_BITS) << TARGET_PAGE_BITS; + if ((dirty_flags & MIGRATION_DIRTY_FLAG) && !cpu_physical_memory_get_dirty(addr, TARGET_PAGE_SIZE, MIGRATION_DIRTY_FLAG)) {