From patchwork Thu Jan 8 17:34:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 42880 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 199BD26CD8 for ; Thu, 8 Jan 2015 18:27:02 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf6142604eek.1 for ; Thu, 08 Jan 2015 10:27:00 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:cc:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=GgSlPw68rAP1BEF6kTL43zqBD3f+u39rpSBWfO/LN7k=; b=Lew4Ar2n9zQg4v8zccypdJ5p+/38V8dcSfuIxj8EWIFmMjc7QAZYNib1BaCOuCHdF5 cm3Avku8OXMVswKnFcmUev1PUZ8c1LXlfsd3AuyFjwJg9Z5sM9HFAx0s4goJB74L4R+U DmfwXq3gtkO84vZbLWTVG9n0NlbdReTCG7ZIaAywM0KDyARjtzU7jMzj5BOeQHCJDiQc hq2Kn6FLoEW8KFFn2uw9b5igJtP1H3Cyjfc12uY7uYxxQ3ssVQ9dwZL46TkA/D3LOMVZ dwgh3cWKkebloN5QAOdV3NPENqQmXoSXPESO1qLdmsT4ylLvfLdWP5JtYVFkXp+5GTou AmwQ== X-Gm-Message-State: ALoCoQmWYw0eUAKA2xNDwFYXv1uo6qG5FlsBgCah0r2RqQCM9BKJfg1gOYPo6Jct0zwGNfCnjXwV X-Received: by 10.194.78.42 with SMTP id y10mr446178wjw.4.1420741620538; Thu, 08 Jan 2015 10:27:00 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.220.164 with SMTP id px4ls143802lac.34.gmail; Thu, 08 Jan 2015 10:27:00 -0800 (PST) X-Received: by 10.152.27.100 with SMTP id s4mr15910945lag.87.1420741620341; Thu, 08 Jan 2015 10:27:00 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id uj9si9923554lbb.97.2015.01.08.10.26.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 08 Jan 2015 10:26:58 -0800 (PST) Received-SPF: temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id hs14so11084823lab.11 for ; Thu, 08 Jan 2015 10:26:58 -0800 (PST) X-Received: by 10.112.104.4 with SMTP id ga4mr16292746lbb.24.1420741618128; Thu, 08 Jan 2015 10:26:58 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.9.200 with SMTP id c8csp83572lbb; Thu, 8 Jan 2015 10:26:57 -0800 (PST) X-Received: by 10.229.48.132 with SMTP id r4mr18360317qcf.5.1420741616244; Thu, 08 Jan 2015 10:26:56 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o10si7941599qah.118.2015.01.08.10.26.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 08 Jan 2015 10:26:56 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:47627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9HnL-0003FE-4j for patch@linaro.org; Thu, 08 Jan 2015 13:26:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9H0H-0004fz-DF for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:36:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y9Gzw-0006rP-Et for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:36:13 -0500 Received: from e31.co.us.ibm.com ([32.97.110.149]:56903) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y9Gzw-0006ql-6H for qemu-devel@nongnu.org; Thu, 08 Jan 2015 12:35:52 -0500 Received: from /spool/local by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 8 Jan 2015 10:35:51 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 8 Jan 2015 10:35:50 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (b03cxnp07028.gho.boulder.ibm.com [9.17.130.15]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id A232D19D803E; Thu, 8 Jan 2015 10:24:27 -0700 (MST) Received: from d03av05.boulder.ibm.com (d03av05.boulder.ibm.com [9.17.195.85]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t08HYcuv30801982; Thu, 8 Jan 2015 10:34:38 -0700 Received: from d03av05.boulder.ibm.com (localhost [127.0.0.1]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t08HZnEO023676; Thu, 8 Jan 2015 10:35:50 -0700 Received: from localhost (morrigu.austin.ibm.com [9.41.105.45]) by d03av05.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t08HZm2m023548; Thu, 8 Jan 2015 10:35:48 -0700 From: Michael Roth To: qemu-devel@nongnu.org Date: Thu, 8 Jan 2015 11:34:07 -0600 Message-Id: <1420738472-23267-64-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1420738472-23267-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15010817-8236-0000-0000-000008730EC5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 32.97.110.149 Cc: qemu-stable@nongnu.org Subject: [Qemu-devel] [PATCH 63/88] exec: Handle multipage ranges in invalidate_and_set_dirty() 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+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mdroth@linux.vnet.ibm.com X-Original-Authentication-Results: mx.google.com; spf=temperror (google.com: error in processing during lookup of patch+caf_=patchwork-forward=linaro.org@linaro.org: DNS timeout) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Peter Maydell The code in invalidate_and_set_dirty() needs to handle addr/length combinations which cross guest physical page boundaries. This can happen, for example, when disk I/O reads large blocks into guest RAM which previously held code that we have cached translations for. Unfortunately we were only checking the clean/dirty status of the first page in the range, and then were calling a tb_invalidate function which only handles ranges that don't cross page boundaries. Fix the function to deal with multipage ranges. The symptoms of this bug were that guest code would misbehave (eg segfault), in particular after a guest reboot but potentially any time the guest reused a page of its physical RAM for new code. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell Reviewed-by: Paolo Bonzini Message-id: 1416167061-13203-1-git-send-email-peter.maydell@linaro.org (cherry picked from commit f874bf905ff2f8dcc17acbfc61e49a92a6f4d04b) Signed-off-by: Michael Roth --- exec.c | 6 ++---- include/exec/ram_addr.h | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index a7d7daa..bfee04a 100644 --- a/exec.c +++ b/exec.c @@ -2009,10 +2009,8 @@ int cpu_memory_rw_debug(CPUState *cpu, target_ulong addr, static void invalidate_and_set_dirty(hwaddr addr, hwaddr length) { - if (cpu_physical_memory_is_clean(addr)) { - /* invalidate code */ - tb_invalidate_phys_page_range(addr, addr + length, 0); - /* set dirty bit */ + if (cpu_physical_memory_range_includes_clean(addr, length)) { + tb_invalidate_phys_range(addr, addr + length, 0); cpu_physical_memory_set_dirty_range_nocode(addr, length); } xen_modified_memory(addr, length); diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h index 6593be1..e50e71c 100644 --- a/include/exec/ram_addr.h +++ b/include/exec/ram_addr.h @@ -49,6 +49,21 @@ static inline bool cpu_physical_memory_get_dirty(ram_addr_t start, return next < end; } +static inline bool cpu_physical_memory_get_clean(ram_addr_t start, + ram_addr_t length, + unsigned client) +{ + unsigned long end, page, next; + + assert(client < DIRTY_MEMORY_NUM); + + end = TARGET_PAGE_ALIGN(start + length) >> TARGET_PAGE_BITS; + page = start >> TARGET_PAGE_BITS; + next = find_next_zero_bit(ram_list.dirty_memory[client], end, page); + + return next < end; +} + static inline bool cpu_physical_memory_get_dirty_flag(ram_addr_t addr, unsigned client) { @@ -64,6 +79,16 @@ static inline bool cpu_physical_memory_is_clean(ram_addr_t addr) return !(vga && code && migration); } +static inline bool cpu_physical_memory_range_includes_clean(ram_addr_t start, + ram_addr_t length) +{ + bool vga = cpu_physical_memory_get_clean(start, length, DIRTY_MEMORY_VGA); + bool code = cpu_physical_memory_get_clean(start, length, DIRTY_MEMORY_CODE); + bool migration = + cpu_physical_memory_get_clean(start, length, DIRTY_MEMORY_MIGRATION); + return vga || code || migration; +} + static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr, unsigned client) {