From patchwork Thu Mar 9 11:34:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Pinto X-Patchwork-Id: 9613135 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 45F6F602B4 for ; Thu, 9 Mar 2017 11:38:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24CF828480 for ; Thu, 9 Mar 2017 11:38:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19314285B5; Thu, 9 Mar 2017 11:38:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7ADF928480 for ; Thu, 9 Mar 2017 11:38:15 +0000 (UTC) Received: from localhost ([::1]:33394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clwOc-00080k-MG for patchwork-qemu-devel@patchwork.kernel.org; Thu, 09 Mar 2017 06:38:14 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60958) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clwLy-0005z5-7J for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:35:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clwLu-0004kj-VU for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:35:30 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34784) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1clwLu-0004kK-PP for qemu-devel@nongnu.org; Thu, 09 Mar 2017 06:35:26 -0500 Received: by mail-wm0-x244.google.com with SMTP id u132so10439156wmg.1 for ; Thu, 09 Mar 2017 03:35:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtualopensystems-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7jBwjdB+oWeqe36f4z96Isj5MxjmDRSykRniu76fhNA=; b=Zcf5FAhfcTbPvdpkmQ+uigKqc3YwFku2tHvDOACtet662zuAxsd06prnt5qSgPkbxm 8CTe+4cZ0hSgdnFJqu7yZM/nWYQ/9UWnjMIuIdICbGDBxMEeOfdy/P2q37X4JFNZmWYt bDGmzxbEgdJ479DK84hRCRQibqQF6lzor1OH+H6nzgP9ML2GlHAb4OVCFAtPjH31Xctw BhTxyXX+PurpkrYtqZPPutnCyfRId18aRcByTD9NesKQiu82lRVkAyXb1bselvaFgQxp 20tPh+uTpXdJW7GgghqNpEXeefBEl+JDe5QcQXw27BITMctdYYdmxU14Cr0nagEBpFA4 O0bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7jBwjdB+oWeqe36f4z96Isj5MxjmDRSykRniu76fhNA=; b=CHVDcEYEVpBK/amOisfWnrQbnT9LwiFtBNzciqIU/LjBMcl+cPy6Q13iDJw00IDWZV 4uDVnaqM25sKYIhdxxNeafJK7m6xSMXrGIPVATf7cCx2zFwOARXvrjlJKm153Gs1RyFH FAQFgjnYK4y+5eXtGT5uhSEtEVV2L6CC5b/iBleylm0HLeAPtFuhNcttpckSn6JONo+e eRwgH9xoy41NsfnvobZ40yKFQ+80hK5L3lc0zCMbv/eLmnUOwQa22ZUygtQ6pMfC60PB sUm7lxD0ao7mBthOMMmhGz8ZmQKWh0sdRMrdwN4lBa6vyFdftiZBW9rwH7MLMQF7UIg/ Zy8A== X-Gm-Message-State: AMke39nhxalZNHtkpunSP+bukLkqW78GHfej5OPqIe8pYlQ4JexPPfVhdsrJkC6E/J+vIg== X-Received: by 10.28.150.136 with SMTP id y130mr9860892wmd.103.1489059325654; Thu, 09 Mar 2017 03:35:25 -0800 (PST) Received: from bumma.localdomain ([151.67.127.177]) by smtp.googlemail.com with ESMTPSA id 36sm7876460wrk.57.2017.03.09.03.35.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Mar 2017 03:35:24 -0800 (PST) From: Christian Pinto To: zhang.zhanghailiang@huawei.com Date: Thu, 9 Mar 2017 12:34:35 +0100 Message-Id: <20170309113437.9667-3-c.pinto@virtualopensystems.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170309113437.9667-1-c.pinto@virtualopensystems.com> References: <57B7F948.9040701@huawei.com> <20170309113437.9667-1-c.pinto@virtualopensystems.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [RFC PATCH 2/4] migration/ram: Fix for ARM/ARM64 page size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aarcange@redhat.com, b.reynal@virtualopensystems.com, quintela@redhat.com, qemu-devel@nongnu.org, hanweidong@huawei.com, peter.huangpeng@huawei.com, Christian Pinto , dgilbert@redhat.com, amit.shah@redhat.com, tech@virtualopensystems.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Architecture such as ARM use a page size of 1KB, while write protection is done at the granularity of host pages (generally 4KB). All addresses must always be aligned to the size of a host page. Signed-off-by: Christian Pinto Signed-off-by: Baptiste Reynal --- migration/postcopy-ram.c | 6 +++--- migration/ram.c | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c index 9c45f1059f..97382067b3 100644 --- a/migration/postcopy-ram.c +++ b/migration/postcopy-ram.c @@ -373,7 +373,7 @@ int postcopy_ram_prepare_discard(MigrationIncomingState *mis) return 0; } -int ram_set_pages_wp(uint64_t page_addr, +int ram_set_pages_wp(ram_addr_t page_addr, uint64_t size, bool remove, int uffd) @@ -556,10 +556,10 @@ static void *postcopy_ram_fault_thread(void *opaque) * will be an deadlock error. */ if (migration_in_setup(ms)) { - uint64_t host = msg.arg.pagefault.address; + ram_addr_t host = msg.arg.pagefault.address; host &= ~(hostpagesize - 1); - ret = ram_set_pages_wp(host, getpagesize(), true, + ret = ram_set_pages_wp(host, hostpagesize, true, us->userfault_fd); if (ret < 0) { error_report("Remove page's write-protect failed"); diff --git a/migration/ram.c b/migration/ram.c index 3417c56f29..7a3b1c7ed3 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1383,14 +1383,24 @@ static int ram_find_and_save_block(QEMUFile *f, bool last_stage, /* For snapshot, we will remove the page write-protect here */ if (migration_in_snapshot(ms)) { int ret; - uint64_t host_addr = (uint64_t)(pss.block->host + pss.offset); - + /* + * Some architectures in QEMU use a smaller memory page size + * with respect to the host page size. ARM as an example + * uses 1K memory pages, while Linux supports pages of minimum + * size of 4K. + * Userfault write protection works at the level of a host page + * and thus one full host page has to be protected/unprotected + * every time. + */ + ram_addr_t host_addr = (ram_addr_t)(pss.block->host + + pss.offset) & (~(qemu_host_page_size - 1)); ret = ram_set_pages_wp(host_addr, getpagesize(), true, ms->userfault_state.userfault_fd); if (ret < 0) { error_report("Failed to remove the write-protect for page:" - "%"PRIx64 " length: %d, block: %s", host_addr, - getpagesize(), pss.block->idstr); + "%"PRIx64 " length: %d, offset: %"PRIx64 + ", block: %s", host_addr, getpagesize(), + pss.offset, pss.block->idstr); } } }