From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979512; cv=none; d=zohomail.com; s=zohoarc; b=kQH5Kazj/TVohDtl8MjXlGclupJVE2ZixZZ/otDz8sOfgM3fuIZYEQ3Vof1A8ukx1L4x1iSaRLafiPJTXpqYIbyKynCXNfrA2IVJg+/QGBQ1TWMJRpbHDXsE6n4FHmd3zlKmSKkWuHRe4Cg+voAxGqbEHh1PU/xWM4SeRxv7Jss= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979512; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=X6R5SODDqvfe3Gp9I1X7nXyO5kwGwphXiKxDLZtl7/E=; b=Zg+RK23by9+n4pocEDd8Wwz3UqEt3ZNUkWZ5GdMEK16I1tZ0il38DKoD2wB+29OSUvf+KiUNZ2L1SX8Wt4qanTJWZVLTrcTcMslwBHXWqE89eyZhlXJHquKH3qn3Utwxi58NNKAWm6BNXDe1qKdblSWPYeb9ccFfWjC/9GjOAJQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979512606395.1769123529332; Tue, 14 Nov 2023 08:31:52 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632934.987442 (Exim 4.92) (envelope-from ) id 1r2wK9-0002is-O7; Tue, 14 Nov 2023 16:31:37 +0000 Received: by outflank-mailman (output) from mailman id 632934.987442; Tue, 14 Nov 2023 16:31:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wK9-0002il-JS; Tue, 14 Nov 2023 16:31:37 +0000 Received: by outflank-mailman (input) for mailman id 632934; Tue, 14 Nov 2023 16:31:35 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wK7-0002h9-Q8 for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:31:35 +0000 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [2a00:1450:4864:20::635]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 46155b1f-830b-11ee-9b0e-b553b5be7939; Tue, 14 Nov 2023 17:31:34 +0100 (CET) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9c53e8b7cf4so855639266b.1 for ; Tue, 14 Nov 2023 08:31:34 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id dt10-20020a170906b78a00b009a5f1d15644sm5694182ejb.119.2023.11.14.08.31.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:31:33 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 46155b1f-830b-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979493; x=1700584293; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X6R5SODDqvfe3Gp9I1X7nXyO5kwGwphXiKxDLZtl7/E=; b=wva71bQqkzgC4iTeUR4DPuogn0twh9Lq8kki33rYFo5rOfZerJnotHI3O8Wu9nMh7R VeeEnl+s+zGmJrrsVZLZsLaxfhUBX6WJ3sLGiesQ5u1CF4KWMavfLWek1cWcvlyK2xzm 7bJRpkWh7116PwykZqPjsu2Gq1e8UCjyC8QsOTxYTTKiYeOMqQtiOVSFEYMtfeJ1//rL Wlt1a8FsOuc7KgKQ7W5iuqGRBy42SW/WImV9f9ZHk3VmabS/Dn55bFqsvh6LWFEAsydO 4Ndeh0cy6sVraRxN9zZ4dXXl73dKhDu7KoP7tjKws3F+0rNnWvi5mkBKSk4CYIJmxych nR0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979493; x=1700584293; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X6R5SODDqvfe3Gp9I1X7nXyO5kwGwphXiKxDLZtl7/E=; b=lgDUgMxIKFE1rta4B5mMXG1Y0Aa3Gs7WwgidnuX3oxKEGICwFixmK4KKVD69tGAzDU 3aLHovLvtb3QyNTzQ1TYpG5Y5TlxHsLWw7mRAGgljpQP2Optkmg4wurNuzON05Li4x4m bt3i8OZZfgAnlFzkmceGCSDBsPw0YY0QgU75rXnpy/vgdM8GNzqXtwlBgiBpk5updPnT ofh6JH+Ac8AF0ksIxE8hHiBpyVaA/SJxd4b92yi8+VTasFBFmDr623z8Ky20a0+Z2pZX /2Wussyf3UTkTTFePueBEUdAtb1IadP8kRVAMAy3szdkx5xoMRkUHY+KxaYadOJwEMgr wHCg== X-Gm-Message-State: AOJu0YwIKmwuYBk/O/l5tgi4RbEJax8GuDzHWm3iKYDukBySoA4ZaJbD I4H/RkDB8NeFsNozrrS4VNPpOQ== X-Google-Smtp-Source: AGHT+IGutQxHrTQ0PDT/rm4Hi1BwUJSaiBc/cWKJ03y/patFhv44C9aSztIA1kKfAa9MrKB6HwgJAQ== X-Received: by 2002:a17:907:1c9b:b0:9e7:c9e3:d63d with SMTP id nb27-20020a1709071c9b00b009e7c9e3d63dmr8902204ejc.7.1699979493603; Tue, 14 Nov 2023 08:31:33 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum Subject: [PATCH-for-9.0 1/9] hw/xen/hvm: Inline TARGET_PAGE_ALIGN() macro Date: Tue, 14 Nov 2023 17:31:15 +0100 Message-ID: <20231114163123.74888-2-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979514395100001 Use TARGET_PAGE_SIZE to calculate TARGET_PAGE_ALIGN. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- hw/i386/xen/xen-hvm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index f1c30d1384..8aa6a1ec3b 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -678,7 +678,7 @@ void xen_arch_set_memory(XenIOState *state, MemoryRegio= nSection *section, trace_xen_client_set_memory(start_addr, size, log_dirty); =20 start_addr &=3D TARGET_PAGE_MASK; - size =3D TARGET_PAGE_ALIGN(size); + size =3D ROUND_UP(size, TARGET_PAGE_SIZE); =20 if (add) { if (!memory_region_is_rom(section->mr)) { --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979520; cv=none; d=zohomail.com; s=zohoarc; b=CzsmzYqf/XU6Ea7xCMpbMLBuJcVWZxS/5ajaUCdb77TogBwztugT2s8O55uWfBsYAEzCoGH4KLgOszTS/TrceEHj9Ch/SRcqZ+0cUcCm9n2ZrQWsrJg5DGbp/kYL9zHyCtBY376eaE3NTU5jmSIoex1zIIwfz7V2qOOtnC5THkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979520; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SmG1RvmEVqSdouF1EAJ1JhQ2v4iViVsF9xcNQ9FZB1E=; b=iQJMP1+A0iheY7JI7KaMLu+aiXJKmS6vHPyGoMJUshY7kxtjcVNUy2LAKmYye4xGCru4lpYFDwYETpAFtI8f0bCRDre54k332TLWZ8nD/c8BOrjuv3rWPRvuWYbpkZ8ctkXTxb75nL78/RRF7BsK7QORxJBIFKlOzYq4IVUtrJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979520221940.622769386685; Tue, 14 Nov 2023 08:32:00 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632935.987452 (Exim 4.92) (envelope-from ) id 1r2wKE-00032c-UT; Tue, 14 Nov 2023 16:31:42 +0000 Received: by outflank-mailman (output) from mailman id 632935.987452; Tue, 14 Nov 2023 16:31:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKE-00032T-Qx; Tue, 14 Nov 2023 16:31:42 +0000 Received: by outflank-mailman (input) for mailman id 632935; Tue, 14 Nov 2023 16:31:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKC-0002Oz-Qn for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:31:40 +0000 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [2a00:1450:4864:20::52d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 49bc6004-830b-11ee-98db-6d05b1d4d9a1; Tue, 14 Nov 2023 17:31:40 +0100 (CET) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-54553e4888bso8736942a12.2 for ; Tue, 14 Nov 2023 08:31:40 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id d17-20020aa7c1d1000000b0052febc781bfsm5326899edp.36.2023.11.14.08.31.37 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:31:39 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 49bc6004-830b-11ee-98db-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979499; x=1700584299; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SmG1RvmEVqSdouF1EAJ1JhQ2v4iViVsF9xcNQ9FZB1E=; b=sLUq4ApkxaFV5M0N6k5rmOi/jNIwkaLCvcLA92qa1l+0O2wypPLVDp7wc1LRhtimvf NoVqbT1+6iqq7ymnZKVgwwZ3O5g3SpMkOsgaQ53qRCPGwzbE23cqQ+Ww4bSBWhJWcgif ghtAxjlE9CTKyMNXrJ4FOsoxehhJVrVfhxz9KgeihtCNMBrx6xdeKesBK63lD9usZ3lh m7piNZActxx5euhiY+H4Mi5hj6it2SjKWcdBrDhHqulHOF0VYSz690E/EpsUYmK+BAEJ pAyMs7XelfTMTgGwGnERkCNDsY1dHKUuq/+a0RR+guNVeUdFPkpZpSCi9LDOpz2ZoPSE tSvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979499; x=1700584299; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SmG1RvmEVqSdouF1EAJ1JhQ2v4iViVsF9xcNQ9FZB1E=; b=Sh+V5h6ZCJ6otzxKAuPOzHd+bMuRm9ij+YXZjXi7SUQh3CCpdve1ljO6MSBWUGvuTv qkoxDeNrw1Q8Zx5aTqc7hBjtNuwnsUrK2f4ufyl36iam2TaZIM8YOANkZqqkqMmn85Ns 39+0lvAL9YFjCwye9CadHjX2mbnQDS7gjRJHpqb4s74A6134uI+Z5+/fcClkoS4wHer2 X0FC+LLDIQdUMYdXucBdeYlLZaaS8rHKyAYWOO6GSCOFNsog5wN49hmF8oSitKZ+lWqs E89M26QASEseNWLKmzubcL3cGixKcoVJOGoMNa8ZPa2agn1Cx2ASmDdUVdwNJXQWzJS/ S/Mg== X-Gm-Message-State: AOJu0YzKq8BfHq6+XQCmiVkZmGIfBX2fOieuweav+lRaEiFWtSC4nk4V ZNMBqRxaF1bNUTr4A0Liks244A== X-Google-Smtp-Source: AGHT+IHL3uPIWo3k1FIfttqQPpxRZY2ZBH7YhX3W4Qy+3Zh4pc0MQhOvVP2dpnkHA2n+Lr+G86EpBQ== X-Received: by 2002:aa7:c487:0:b0:547:cbc:e07d with SMTP id m7-20020aa7c487000000b005470cbce07dmr7903450edq.1.1699979499591; Tue, 14 Nov 2023 08:31:39 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Subject: [PATCH-for-9.0 2/9] hw/xen/hvm: Propagate page_mask to a pair of functions Date: Tue, 14 Nov 2023 17:31:16 +0100 Message-ID: <20231114163123.74888-3-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979522366100001 We are going to replace TARGET_PAGE_MASK by a runtime variable. In order to reduce code duplication, propagate TARGET_PAGE_MASK to get_physmapping() and xen_phys_offset_to_gaddr(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- hw/i386/xen/xen-hvm.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 8aa6a1ec3b..3b10425986 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -174,11 +174,12 @@ static void xen_ram_init(PCMachineState *pcms, } } =20 -static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size) +static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size, + int page_mask) { XenPhysmap *physmap =3D NULL; =20 - start_addr &=3D TARGET_PAGE_MASK; + start_addr &=3D page_mask; =20 QLIST_FOREACH(physmap, &xen_physmap, list) { if (range_covers_byte(physmap->start_addr, physmap->size, start_ad= dr)) { @@ -188,9 +189,10 @@ static XenPhysmap *get_physmapping(hwaddr start_addr, = ram_addr_t size) return NULL; } =20 -static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size) +static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, + int page_mask) { - hwaddr addr =3D phys_offset & TARGET_PAGE_MASK; + hwaddr addr =3D phys_offset & page_mask; XenPhysmap *physmap =3D NULL; =20 QLIST_FOREACH(physmap, &xen_physmap, list) { @@ -252,7 +254,7 @@ static int xen_add_to_physmap(XenIOState *state, hwaddr phys_offset =3D memory_region_get_ram_addr(mr); const char *mr_name; =20 - if (get_physmapping(start_addr, size)) { + if (get_physmapping(start_addr, size, TARGET_PAGE_MASK)) { return 0; } if (size <=3D 0) { @@ -325,7 +327,7 @@ static int xen_remove_from_physmap(XenIOState *state, XenPhysmap *physmap =3D NULL; hwaddr phys_offset =3D 0; =20 - physmap =3D get_physmapping(start_addr, size); + physmap =3D get_physmapping(start_addr, size, TARGET_PAGE_MASK); if (physmap =3D=3D NULL) { return -1; } @@ -373,7 +375,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state, int rc, i, j; const XenPhysmap *physmap =3D NULL; =20 - physmap =3D get_physmapping(start_addr, size); + physmap =3D get_physmapping(start_addr, size, TARGET_PAGE_MASK); if (physmap =3D=3D NULL) { /* not handled */ return; @@ -633,7 +635,7 @@ void xen_hvm_modified_memory(ram_addr_t start, ram_addr= _t length) int rc; ram_addr_t start_pfn, nb_pages; =20 - start =3D xen_phys_offset_to_gaddr(start, length); + start =3D xen_phys_offset_to_gaddr(start, length, TARGET_PAGE_MASK= ); =20 if (length =3D=3D 0) { length =3D TARGET_PAGE_SIZE; --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979523; cv=none; d=zohomail.com; s=zohoarc; b=EScmAvCWzItUxPuXGpqX65xw5DcWEA9AO8ZNPf+f80P7NkBGzKxuvhoa7LP9wdv/hl7pDc257C6g1HvS8mH5ts+i/qGfQN28WSHwvea0dM0pSh+sm3yFxkN/G1NRZmCoE3rN8lHtz//rBHCSJzh1co2YgClh581T8gLvGDYAqGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979523; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NT+opHNXDD+8bNoiCh7g5pdE2RHJ23alItnJp/zxUjY=; b=kNE3w18g5nPVR7u/UeJTWrYtM0V5vNv6XMd58YUsJRLOM8faMs6R9EP/Or3Q46z4U+KNP3IdOGKOrgnU/AMfSBG6H3dQuKpM310o3EcfnaHFSAzESV9z1dTtQPfzkR/yeSLc2AxEUyHEphk/dgiy2MrxEz+GFsjRAt+jnp4RxHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979523878152.20597712094127; Tue, 14 Nov 2023 08:32:03 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632936.987462 (Exim 4.92) (envelope-from ) id 1r2wKJ-0003Lo-78; Tue, 14 Nov 2023 16:31:47 +0000 Received: by outflank-mailman (output) from mailman id 632936.987462; Tue, 14 Nov 2023 16:31:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKJ-0003Lh-3c; Tue, 14 Nov 2023 16:31:47 +0000 Received: by outflank-mailman (input) for mailman id 632936; Tue, 14 Nov 2023 16:31:46 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKI-0002Oz-NN for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:31:46 +0000 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [2a00:1450:4864:20::62d]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4d4a08e9-830b-11ee-98db-6d05b1d4d9a1; Tue, 14 Nov 2023 17:31:46 +0100 (CET) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-9e8b36e36e0so361036766b.2 for ; Tue, 14 Nov 2023 08:31:46 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id ay1-20020a170906d28100b009dd606ce80fsm5783743ejb.31.2023.11.14.08.31.43 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:31:45 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4d4a08e9-830b-11ee-98db-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979505; x=1700584305; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NT+opHNXDD+8bNoiCh7g5pdE2RHJ23alItnJp/zxUjY=; b=VoVDfZxH6iB3TtiiAQr/rNyvp7xw04uAtkVHf+sH7+TNt8i4JZkd5kydRavLuimoTm 5t+SzuLN1iYZ8KS/Ln9BcxvwLo2c8G+0aegwxi4tLPajdN3UZXB6/cNeSTg9DslEodMY Rb6pxU+NwxRBtAIuvVWqaE0pD+lOl3nBzzSP+PfEoqCvEzwNYOcweBBFw6AF4egZptlf PBDnFjOW2MkTRjJwnNXsc88Z4SBstQvT1VGe+O0eOSHaS6L37ytGPJV+wIO0l6dDpD7Y gcx5SuubnUpklzeHlPuv3qBNNZLVY2pRSwRTlR+jJOHVCVudrTLqAMYPrUP2cFNRd91p XOlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979505; x=1700584305; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NT+opHNXDD+8bNoiCh7g5pdE2RHJ23alItnJp/zxUjY=; b=qAIAtSXUdha2bj+tTDNTwZIjTtO828FjuSflfw5PgXJRRYx1FI/TyY6ApCDodleLH9 eaSKxIH35Qq8YFC+/HOtJKwVt8+1JlPT+nWlbSS21nsd2xeLyeIxIXC0lkN146Oot5vY pupnvH1woUkWFo/cMgE/msWHuDvsiwFGvjte7seUSrV8hFsk7n2i5PBoHIX1+6AntfLW kTRTQSlA/01PQVlyQINK0JyCCYjlfGeoY44SIxPvQXt5YeE6SV+Lqn1ocJB0yRF9ESrM hmV6nZTX3Xf6EryQkQ4hDOJ2A7dcDRflUQ1Q2N9ixAZsPJ4SuhE98FV7Z3dx8FhEt+0n TqGw== X-Gm-Message-State: AOJu0YzzXuQNcwBkajQd5h1eRB7RwFIts6CAbi0mZR0wte9Oc+qnwQFx HG594h+uqPPd0ev0SzUrWYC3kQ== X-Google-Smtp-Source: AGHT+IFzZ/WlakywfS2j4RNnJu+KHOxUEpzbwil6pYOK3zfVQW64jjDAFiv/57u6cKngaCaBboQSjg== X-Received: by 2002:a17:907:7b8f:b0:9da:f85a:233f with SMTP id ne15-20020a1709077b8f00b009daf85a233fmr9830571ejc.28.1699979505694; Tue, 14 Nov 2023 08:31:45 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum Subject: [PATCH-for-9.0 3/9] hw/xen/hvm: Get target page size at runtime Date: Tue, 14 Nov 2023 17:31:17 +0100 Message-ID: <20231114163123.74888-4-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979524375100003 In order to build this file once for all targets, replace: TARGET_PAGE_BITS -> qemu_target_page_bits() TARGET_PAGE_SIZE -> qemu_target_page_size() TARGET_PAGE_MASK -> -qemu_target_page_size() Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- hw/i386/xen/xen-hvm.c | 62 +++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 3b10425986..b64204ea94 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -22,6 +22,7 @@ =20 #include "hw/xen/xen-hvm-common.h" #include +#include "exec/target_page.h" #include "cpu.h" =20 static MemoryRegion ram_640k, ram_lo, ram_hi; @@ -247,6 +248,9 @@ static int xen_add_to_physmap(XenIOState *state, MemoryRegion *mr, hwaddr offset_within_region) { + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; unsigned long nr_pages; int rc =3D 0; XenPhysmap *physmap =3D NULL; @@ -254,7 +258,7 @@ static int xen_add_to_physmap(XenIOState *state, hwaddr phys_offset =3D memory_region_get_ram_addr(mr); const char *mr_name; =20 - if (get_physmapping(start_addr, size, TARGET_PAGE_MASK)) { + if (get_physmapping(start_addr, size, page_mask)) { return 0; } if (size <=3D 0) { @@ -294,9 +298,9 @@ go_physmap: return 0; } =20 - pfn =3D phys_offset >> TARGET_PAGE_BITS; - start_gpfn =3D start_addr >> TARGET_PAGE_BITS; - nr_pages =3D size >> TARGET_PAGE_BITS; + pfn =3D phys_offset >> target_page_bits; + start_gpfn =3D start_addr >> target_page_bits; + nr_pages =3D size >> target_page_bits; rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, start_gpfn); if (rc) { @@ -310,8 +314,8 @@ go_physmap: } =20 rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, - start_addr >> TARGET_PAGE_BITS, - (start_addr + size - 1) >> TARGET_PAGE_= BITS, + start_addr >> target_page_bits, + (start_addr + size - 1) >> target_page_= bits, XEN_DOMCTL_MEM_CACHEATTR_WB); if (rc) { error_report("pin_memory_cacheattr failed: %s", strerror(errno)); @@ -323,11 +327,14 @@ static int xen_remove_from_physmap(XenIOState *state, hwaddr start_addr, ram_addr_t size) { + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; int rc =3D 0; XenPhysmap *physmap =3D NULL; hwaddr phys_offset =3D 0; =20 - physmap =3D get_physmapping(start_addr, size, TARGET_PAGE_MASK); + physmap =3D get_physmapping(start_addr, size, page_mask); if (physmap =3D=3D NULL) { return -1; } @@ -338,9 +345,9 @@ static int xen_remove_from_physmap(XenIOState *state, DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at " "%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset= ); =20 - size >>=3D TARGET_PAGE_BITS; - start_addr >>=3D TARGET_PAGE_BITS; - phys_offset >>=3D TARGET_PAGE_BITS; + size >>=3D target_page_bits; + start_addr >>=3D target_page_bits; + phys_offset >>=3D target_page_bits; rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, phys_offset); if (rc) { @@ -369,13 +376,16 @@ static void xen_sync_dirty_bitmap(XenIOState *state, hwaddr start_addr, ram_addr_t size) { - hwaddr npages =3D size >> TARGET_PAGE_BITS; + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr npages =3D size >> target_page_bits; const int width =3D sizeof(unsigned long) * 8; size_t bitmap_size =3D DIV_ROUND_UP(npages, width); int rc, i, j; const XenPhysmap *physmap =3D NULL; =20 - physmap =3D get_physmapping(start_addr, size, TARGET_PAGE_MASK); + physmap =3D get_physmapping(start_addr, size, page_mask); if (physmap =3D=3D NULL) { /* not handled */ return; @@ -389,7 +399,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state, return; } =20 - rc =3D xen_track_dirty_vram(xen_domid, start_addr >> TARGET_PAGE_BITS, + rc =3D xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits, npages, dirty_bitmap); if (rc < 0) { #ifndef ENODATA @@ -410,8 +420,7 @@ static void xen_sync_dirty_bitmap(XenIOState *state, j =3D ctzl(map); map &=3D ~(1ul << j); memory_region_set_dirty(framebuffer, - (i * width + j) * TARGET_PAGE_SIZE, - TARGET_PAGE_SIZE); + (i * width + j) * page_size, page_size= ); }; } } @@ -631,17 +640,21 @@ void xen_register_framebuffer(MemoryRegion *mr) =20 void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) { + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + if (unlikely(xen_in_migration)) { int rc; ram_addr_t start_pfn, nb_pages; =20 - start =3D xen_phys_offset_to_gaddr(start, length, TARGET_PAGE_MASK= ); + start =3D xen_phys_offset_to_gaddr(start, length, page_mask); =20 if (length =3D=3D 0) { - length =3D TARGET_PAGE_SIZE; + length =3D page_size; } - start_pfn =3D start >> TARGET_PAGE_BITS; - nb_pages =3D ((start + length + TARGET_PAGE_SIZE - 1) >> TARGET_PA= GE_BITS) + start_pfn =3D start >> target_page_bits; + nb_pages =3D ((start + length + page_size - 1) >> target_page_bits) - start_pfn; rc =3D xen_modified_memory(xen_domid, start_pfn, nb_pages); if (rc) { @@ -664,6 +677,9 @@ void qmp_xen_set_global_dirty_log(bool enable, Error **= errp) void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, bool add) { + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; hwaddr start_addr =3D section->offset_within_address_space; ram_addr_t size =3D int128_get64(section->size); bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); @@ -679,8 +695,8 @@ void xen_arch_set_memory(XenIOState *state, MemoryRegio= nSection *section, =20 trace_xen_client_set_memory(start_addr, size, log_dirty); =20 - start_addr &=3D TARGET_PAGE_MASK; - size =3D ROUND_UP(size, TARGET_PAGE_SIZE); + start_addr &=3D page_mask; + size =3D ROUND_UP(size, page_size); =20 if (add) { if (!memory_region_is_rom(section->mr)) { @@ -689,8 +705,8 @@ void xen_arch_set_memory(XenIOState *state, MemoryRegio= nSection *section, } else { mem_type =3D HVMMEM_ram_ro; if (xen_set_mem_type(xen_domid, mem_type, - start_addr >> TARGET_PAGE_BITS, - size >> TARGET_PAGE_BITS)) { + start_addr >> target_page_bits, + size >> target_page_bits)) { DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", start_addr); } --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979529; cv=none; d=zohomail.com; s=zohoarc; b=SQRRwXGU7eUOZpIap8NmRwldf0CK3qlkC/pfX3QuveJo86VTRm7A4Dow8IJzSwE7AWu1MfQxm/pk2XBOFkxnYCGENAVbIf/NdXlp76FhHUtyEDMgpQwpquorQPshWaqdN76P98uGUcB0OVDzgQCDt+m17U2u2XxZsHJoxTRsdHY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979529; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hRnzgqjbzRTGqJ5jrYQJxW1BmP5r27YtuyDu1IVzHFA=; b=hmjC0IL2K2XbRSDuKV2Rw69UqmuOhfr1cYJbxc4dN39q9T+0vk1Q/FygyILS+jT6D3KrWeIBMpGQJPk7Inm9OCw2iIlycDg/MoznoWg/QoOb5T1m/92PQRnU9AKUWfZycsfbLc2UCJa63kZuQFTY0d5MhfOkWIbyr1eIeDBkfZc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979529176154.72100976523348; Tue, 14 Nov 2023 08:32:09 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632938.987472 (Exim 4.92) (envelope-from ) id 1r2wKQ-0003pQ-Kv; Tue, 14 Nov 2023 16:31:54 +0000 Received: by outflank-mailman (output) from mailman id 632938.987472; Tue, 14 Nov 2023 16:31:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKQ-0003pE-G8; Tue, 14 Nov 2023 16:31:54 +0000 Received: by outflank-mailman (input) for mailman id 632938; Tue, 14 Nov 2023 16:31:52 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKO-0002Oz-Tt for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:31:52 +0000 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [2a00:1450:4864:20::535]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 51145ac1-830b-11ee-98db-6d05b1d4d9a1; Tue, 14 Nov 2023 17:31:52 +0100 (CET) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-53de0d1dc46so9475907a12.3 for ; Tue, 14 Nov 2023 08:31:52 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id d17-20020aa7c1d1000000b0052febc781bfsm5327156edp.36.2023.11.14.08.31.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:31:51 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 51145ac1-830b-11ee-98db-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979512; x=1700584312; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hRnzgqjbzRTGqJ5jrYQJxW1BmP5r27YtuyDu1IVzHFA=; b=bsneDyKfYbpDwR3rGe0BtvHR/DdJGyarFuW8xGzMLja2PnMQX2lT56n287T6Oy+CDe 0d4TMkq857BpgEg5HI48JauWFhCyhMLJNuM9xWdBJPWCRYDQ0r+gh3VPiF0zJjvbh9sK cTaCQJhwjtVNfbQh9Th8NAHXWnil6ercsK8xqDtxiks6gxCPZKHhzMKAiOzR0pN5ea+A dMPhEXbZ1vXp2hX4i/css0iM8asTlRN6Wote5KINbNl7SNTp5779ZHNmHoKys8TXLvZ1 z1Y3+IzP58/Bxi/+B5RLl6Ixbn8dfYuUIQeOgjyMfXml+6HwRmcbm3fjBTcLzc6r4R8c nBTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979512; x=1700584312; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hRnzgqjbzRTGqJ5jrYQJxW1BmP5r27YtuyDu1IVzHFA=; b=X12z9V+M7NcU6ID1cb3X/3BAABv/BAbLrnIvXeXdjvTKdeRyikvQww7eSIGFawdOLL jmonxu9ngxOtp+ASCE8WXYGmhq8AVMvaHv3dFx/UMvvobHyuMiu8JPp1K1FCfmjCjbMQ 2JRym7k6Jw5J2/s8OOYPTtK6VWORSt/oX0gkh9NfcPNW/qlb90pkMLMD0ss1l+v28ahI NwHOViML4TXo9FVWeFTGD54Mi+D4GgIM9dSJR8zhKW8WtsBv/+gigkHI+na7qljOn8CM b50m+qKn088si85PozhKD8xAmORL+C+QmPA9tF1NA/5uApnoCvTL3U3snx1+Lft9O66T aBPA== X-Gm-Message-State: AOJu0Yy/qFhMsR7RmEoxK8JOtjXaxAf/EYj8miIIT5NN/kO2UmIlTpzM 1yMxktosvu8bGrBDIDEtQzr9ig== X-Google-Smtp-Source: AGHT+IE8/KnAMA1FjOTiA03DDYyTyNl6glp0CwMJ10smYv5ORjVAvozuUmjkzAh9auk1H2jVfOhg2Q== X-Received: by 2002:a05:6402:3cf:b0:543:70c2:aa8d with SMTP id t15-20020a05640203cf00b0054370c2aa8dmr7379909edw.15.1699979511911; Tue, 14 Nov 2023 08:31:51 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Subject: [PATCH-for-9.0 4/9] hw/xen/hvm: Expose xen_memory_listener declaration Date: Tue, 14 Nov 2023 17:31:18 +0100 Message-ID: <20231114163123.74888-5-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979530392100001 There can only be a single xen_memory_listener definition in a qemu-system binary. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- include/hw/xen/xen-hvm-common.h | 1 + hw/arm/xen_arm.c | 2 +- hw/i386/xen/xen-hvm.c | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h index 83ed16f425..0fed15ed04 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -18,6 +18,7 @@ extern MemoryRegion xen_memory; extern MemoryListener xen_io_listener; extern DeviceListener xen_device_listener; +extern const MemoryListener xen_memory_listener; =20 //#define DEBUG_XEN_HVM =20 diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index b478d74ea0..39dcd74d07 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -38,7 +38,7 @@ #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh") OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM) =20 -static const MemoryListener xen_memory_listener =3D { +const MemoryListener xen_memory_listener =3D { .region_add =3D xen_region_add, .region_del =3D xen_region_del, .log_start =3D NULL, diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index b64204ea94..a65a96f0de 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -469,7 +469,7 @@ static void xen_log_global_stop(MemoryListener *listene= r) xen_in_migration =3D false; } =20 -static const MemoryListener xen_memory_listener =3D { +const MemoryListener xen_memory_listener =3D { .name =3D "xen-memory", .region_add =3D xen_region_add, .region_del =3D xen_region_del, --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979532; cv=none; d=zohomail.com; s=zohoarc; b=Kwp6QhrIcmGjWZacGA0/6mDCZOiqoRqgS/GkXkzSa65S7EoUlqJC4ADMViAaSh7qFv+Ie1QJFdMARy+k21hx+gTKyYBmUp4B3TOhbtTmrjWpZJIGu6MN29LKRZjSjNqdeKWYFZJgsNiPL2qCry2KD0LIeJUuWrkcK0fupaVXFys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979532; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3H+/pStoCerFaavD4+6+pbKHikmNIDPKszX2p8LZLs8=; b=fGkuXGji4/h7PvKUOQY//qlMz8RH8Yp93C+C9DcXgUeVI5Z0sAwN4v8l/O19PahCNNZHHx+OZob5pau9yQamTUVU4aocO7GlmWfEnY0emkCZjcvxkoQWLMo4lDn7gZrBxXgbMJTeRvzSi0ugRh1SCYvu6A6STt58AmJj6GjZk68= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979532896729.5189309924742; Tue, 14 Nov 2023 08:32:12 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632940.987482 (Exim 4.92) (envelope-from ) id 1r2wKV-0004E7-SG; Tue, 14 Nov 2023 16:31:59 +0000 Received: by outflank-mailman (output) from mailman id 632940.987482; Tue, 14 Nov 2023 16:31:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKV-0004Dy-PH; Tue, 14 Nov 2023 16:31:59 +0000 Received: by outflank-mailman (input) for mailman id 632940; Tue, 14 Nov 2023 16:31:58 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKU-0002Oz-NA for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:31:58 +0000 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [2a00:1450:4864:20::12c]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 54908170-830b-11ee-98db-6d05b1d4d9a1; Tue, 14 Nov 2023 17:31:58 +0100 (CET) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-507a98517f3so7716957e87.0 for ; Tue, 14 Nov 2023 08:31:58 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id c19-20020a50f613000000b00542d3e470f9sm5386152edn.10.2023.11.14.08.31.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:31:57 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 54908170-830b-11ee-98db-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979518; x=1700584318; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3H+/pStoCerFaavD4+6+pbKHikmNIDPKszX2p8LZLs8=; b=o/OPdGQn4KcF5VVKQ0LWuogs5ExlPRxZPFqJXgi8kjyDO6uFoV6gH0FM2D+L0rzeVA gEBJHtbgMJFIyULkBjuydwU7v1Iuk1YWLqoKx4pmIJHYuR2nJSpiae1DBdeDSJ1R7niK 9q4v352CJRZ2aLYTqZZnoB5SXq/MaRX5rKSNDzD3P7k8KdDfCftETxf0u6vCsaQ+ORCn piTOLlujWDch8XkYqWpOCRx1TYlx/2w/RRLgGQ5NPdVF8xarUIekU0zNESDOtOMpCWQP UAC1QNzXXTYwVUQjJWZ2RbLtvHYLcbxyxJUL2SuqLFNGcfX62o5vj3k+pXcjz2DxnWH/ 3z9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979518; x=1700584318; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3H+/pStoCerFaavD4+6+pbKHikmNIDPKszX2p8LZLs8=; b=P0xFNq5bo7XJS10wA4BV/FmEzedACuku6sxTSxlop6iigzlPYK7NDz6vFdsxSK1lN4 EKe+jKeu3wjLoF+a1U38Y7Qd50eR8jgT0r7rWlLiWiu4TBYm3XwgBVmt3GemLnkOblCX c6ZAaH4uF2My4Gg3BZN+/A292ZVLq6avmKx35QwoJ0FKh9JFSURYOq2A33e9yN08qFqp A+CaMbJYDc3Ea1JFZ+JvvtkDW4+VO7ttOc6Ngp5fXtUTvQ6mLP+m8vBI+swnYtfyQhOs KmK7Py4L+SXsNoBrju3JsYFeI2rXO2oz6LKk59j7xZ2RZgBk4z9aqpHHlPC2Abs4raZR K60w== X-Gm-Message-State: AOJu0YwV1NupNyMpOA4xw9fKyElm+ROzvElDf5n5qNxgai3o+gtBE5jW i5Ye4Ih299NBhExIWF8vzpsyqg== X-Google-Smtp-Source: AGHT+IFU6wDkoylQ5/58cZgzmE5wfkRGyUxVY57V7J9SRhQ2EOS6zAeN62VBuenc3iIc8vTnT/LH0w== X-Received: by 2002:a19:9103:0:b0:507:9f4c:b72 with SMTP id t3-20020a199103000000b005079f4c0b72mr5872272lfd.15.1699979517897; Tue, 14 Nov 2023 08:31:57 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Richard Henderson , Eduardo Habkost , "Michael S. Tsirkin" , Marcel Apfelbaum Subject: [PATCH-for-9.0 5/9] hw/xen/hvm: Expose xen_read_physmap() prototype Date: Tue, 14 Nov 2023 17:31:19 +0100 Message-ID: <20231114163123.74888-6-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979534416100005 In a pair of commit we are going to call xen_read_physmap() out of hw/i386/xen/xen-hvm.c. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- include/hw/xen/xen-hvm-common.h | 1 + hw/i386/xen/xen-hvm.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h index 0fed15ed04..536712dc83 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -97,6 +97,7 @@ void xen_register_ioreq(XenIOState *state, unsigned int m= ax_cpus, =20 void cpu_ioreq_pio(ioreq_t *req); =20 +void xen_read_physmap(XenIOState *state); void xen_arch_handle_ioreq(XenIOState *state, ioreq_t *req); void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index a65a96f0de..789779d02c 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -525,7 +525,7 @@ static void handle_vmport_ioreq(XenIOState *state, iore= q_t *req) } =20 #ifdef XEN_COMPAT_PHYSMAP -static void xen_read_physmap(XenIOState *state) +void xen_read_physmap(XenIOState *state) { XenPhysmap *physmap =3D NULL; unsigned int len, num, i; @@ -573,7 +573,7 @@ static void xen_read_physmap(XenIOState *state) free(entries); } #else -static void xen_read_physmap(XenIOState *state) +void xen_read_physmap(XenIOState *state) { } #endif --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979587; cv=none; d=zohomail.com; s=zohoarc; b=FPUtT6E0oOuxBh5KWbJVmq+t0RWEvceSWkpm3gCadzZRg5QGt8ai/ePDxkXMb8P8Gqie0TFHRmE4ndksCmQ8XU2wxz/wuaCxRh/ljb4loKZLEoZ5R154AmyGXxCSdS6SdU42MQj2hvugv0S9Ux0qBqMtr4C40cyS4ankbcs1c5E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979587; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WTlDtVgsnwcqvtsJBU/yKayNDVYOQAUQMToAEPEK6Gk=; b=OMQ0shuDTjFVnKQpxzsj7Gol6TzaQJM89SJiMSlAvLEmiBHHlpclP8XiezzGs4Iaa/5UPvj6U/wLuQru/AANNAeosMvOSzGxbDVflLOlZfVmaRgetNg7oKVRPLHn4ObNGfncR5cyfRmqEmZKhI0HDMaFQZ1g/QTEXX1qdRmxrbU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699979587132654.7956447826421; Tue, 14 Nov 2023 08:33:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2wKe-00039C-JU; Tue, 14 Nov 2023 11:32:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2wKd-00038R-Du for qemu-devel@nongnu.org; Tue, 14 Nov 2023 11:32:07 -0500 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r2wKb-0006an-G3 for qemu-devel@nongnu.org; Tue, 14 Nov 2023 11:32:07 -0500 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9bf86b77a2aso858903566b.0 for ; Tue, 14 Nov 2023 08:32:05 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id b11-20020a1709062b4b00b009b2b47cd757sm5740724ejg.9.2023.11.14.08.32.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:32:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979524; x=1700584324; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WTlDtVgsnwcqvtsJBU/yKayNDVYOQAUQMToAEPEK6Gk=; b=nuEFZDw3TtMaKNUd/Hh5GoHAP/wESvt2MJgXiPM6t+xxDuHDHHxWsOhjSR4dVo8TT4 CzK5yFV8O2PTZ1gZ5bZStx1B6rWH+sRa26teHx+cxpwDUmMTindf/fWN+UV6dX3cSse/ JQ8qfMGUO089TzH4LEdYydR2sP/G/sgCZdcBP2nlRoBTesQV+pXMUsbnjn07WSLovSx2 ygGNGn7uILSuSkQB2gzhZjtej5rOUz+gsAo1Z7MP840FMX0P6sG+8sYumODdPrbe4NPS Bfy/BYKwKplX2C9sA5B3ySfOQIuXopCqE76kxOXmCMjw1PXS5IW419ErUJXoK3reuEL5 usPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979524; x=1700584324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WTlDtVgsnwcqvtsJBU/yKayNDVYOQAUQMToAEPEK6Gk=; b=TgZpzUqOE7HHWIQKBW0MrTBv1YxI+yYxU8I3iV/qF7mxInctr+bn4gF1cyJpczmu77 +8nadDvRxVleB1QWGpHDKdmRMh6e0CJwgc7UquKXNpylHd+Y9eCQF0Ok2x7pBMZOEMjF vGFv7jY3nTWoduLhu3CFJU4rLfHXx7gtILW3Oev74VJP0lljJdwlotbw7/c5qIIxIoXu GyRCaKWKoKxqhcxUDrvSmUkfd2LWTsbdTvawPWt5FRXl1ntNPy1tYi5aKdKqZumj+Zor l8MfM5PVBudqY1EnpFQpR6Q7cW7y/iOGQxJTUwvhA2TYSZOVkA5fQaUaX0HX3Knw6/ga dnpw== X-Gm-Message-State: AOJu0Yz97l7C2mwu6QI2XojexvpDeVveEd4osVioBN4HzDVFf+AAdWpE 18r3Auas4heppjW7yk+uL2T137Uk6EsJySuqVtM= X-Google-Smtp-Source: AGHT+IHt381u+VrZTF53LFbjgSQ6v/t56GRcLe7EuiK5Y6nqGj9R0LI6bw4MbxrPYnsq1mWw3maHWw== X-Received: by 2002:a17:906:3458:b0:9dd:dc2a:eb8b with SMTP id d24-20020a170906345800b009dddc2aeb8bmr6116891ejb.41.1699979523898; Tue, 14 Nov 2023 08:32:03 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Subject: [RFC PATCH-for-9.0 6/9] hw/xen/hvm: Initialize xen_physmap QLIST in xen_read_physmap() Date: Tue, 14 Nov 2023 17:31:20 +0100 Message-ID: <20231114163123.74888-7-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62b; envelope-from=philmd@linaro.org; helo=mail-ej1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979588897100006 xen_read_physmap() is the first function requiring xen_physmap QLIST being initialized. Move the init call there. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- hw/i386/xen/xen-hvm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 789779d02c..3b9c31c1c8 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -532,6 +532,8 @@ void xen_read_physmap(XenIOState *state) char path[80], *value =3D NULL; char **entries =3D NULL; =20 + QLIST_INIT(&xen_physmap); + snprintf(path, sizeof(path), "/local/domain/0/device-model/%d/physmap", xen_domid); entries =3D xs_directory(state->xenstore, 0, path, &num); @@ -575,6 +577,7 @@ void xen_read_physmap(XenIOState *state) #else void xen_read_physmap(XenIOState *state) { + QLIST_INIT(&xen_physmap); } #endif =20 @@ -595,7 +598,6 @@ void xen_hvm_init_pc(PCMachineState *pcms, MemoryRegion= **ram_memory) =20 xen_register_ioreq(state, max_cpus, &xen_memory_listener); =20 - QLIST_INIT(&xen_physmap); xen_read_physmap(state); =20 suspend.notify =3D xen_suspend_notifier; --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979550; cv=none; d=zohomail.com; s=zohoarc; b=AtLTrYKzG2dU0TtfW2dxfeAIvYqs+XjrMENyYhalPPrBG54WlD47sSHgX/A57dYek47iWnInD0s39YK8Q8dffes4j+DcL7F1NxcFdbuGEOk8k8HQeVgvwRgTF1Y3O+NxZemG5XHYeTVm8WTcm7O/mqPNWbGkB2JDv07MLyXGkmI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979550; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=H4vt0ZlqdP4cApbIjAIfqTCMR9wYqBXojziD0Op/yXU=; b=lBrgIXQ65+3fLBC+uQ+UtZKDCXc/PAMVrHlQO9lVYD2CQE0HgPg/ZYXyhkasNC4WSTm1GpH5hTWK9D3J1bM52dOdEO5VfW4ez4GvaBPfC2eHxUm54i1rLq2ZeMAzDHaRCoxxo2g7UlXionIcRDi7OfTG4/GxSXAxRXA18Vigbco= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979550051131.43176489784491; Tue, 14 Nov 2023 08:32:30 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632946.987502 (Exim 4.92) (envelope-from ) id 1r2wKk-0005VO-Dm; Tue, 14 Nov 2023 16:32:14 +0000 Received: by outflank-mailman (output) from mailman id 632946.987502; Tue, 14 Nov 2023 16:32:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKk-0005UW-9e; Tue, 14 Nov 2023 16:32:14 +0000 Received: by outflank-mailman (input) for mailman id 632946; Tue, 14 Nov 2023 16:32:12 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKi-0002Oz-4v for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:32:12 +0000 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [2a00:1450:4864:20::62e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 5bf9eee4-830b-11ee-98db-6d05b1d4d9a1; Tue, 14 Nov 2023 17:32:10 +0100 (CET) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9c3aec5f326so1398320966b.1 for ; Tue, 14 Nov 2023 08:32:10 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id k15-20020a17090646cf00b009932337747esm5670007ejs.86.2023.11.14.08.32.08 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:32:09 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5bf9eee4-830b-11ee-98db-6d05b1d4d9a1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979530; x=1700584330; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=H4vt0ZlqdP4cApbIjAIfqTCMR9wYqBXojziD0Op/yXU=; b=P61Y/Nxs3dbHEhVx2tPNAjHA/dA6sZPIiWVkw0hpDXm9EFaXRHyfvl+utnXmDW+ke5 WjD1tkcaUULyK/YGNpup/LBk3O6jEs0mOhZebmDbsl4PoCRpeba+ZEu8EFL63BrzWS3R KOAkxQAW96X0yesf1cK8SLn/N6ViwC0i9zJu65MvH8SW/gQ2nXf3IPjS9EQ+wtgwYJxm Lyba8P+nagdAPMfmlugRUDHLflJ0BzRLoYOz5YF21TB4qsAy9mqrf6npkg7QgFDN9TvN STTFNGhgI6sfNPlBT+3iyn+zQnbOqhB75JxiQrfgUzIlIjuANU+LRwHjfEJ6mQvRUU/V 8Ctw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979530; x=1700584330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=H4vt0ZlqdP4cApbIjAIfqTCMR9wYqBXojziD0Op/yXU=; b=UG+LzPg8NNvJHNFMFe+n5Mb+5AWPz9tTzABVOO/HxfNpfOPQMqZiAFPVfHuz99FyBa 5h1DVYH/90UnF98SUr4Gnc6PWOQvm2lXc/Z6JE3OliyqcE1i40uNVI90a9QD9Y3rrvsX W0QJPksiWfjJKYkFKwLFXfgJvD205ztj1SBh1SKA+CU2eg/dlROkcr0PtOYODMg0IMNR mhCoGIM4KNoS4Rjhs3mK0nfUE06ezbrk7NUcm0FLwxxgXHbtkAfjfliHEhFft/F3rFLu ocrov1gvDD4BP+F40+Xpzm7WXLbgzudwAmLSHux+qAdUnt4ANjXMCtnX5WEFhlwpzm5D cR8w== X-Gm-Message-State: AOJu0YxPhfvBjj9eOTUyppJks6ETBBbOHu373QPaowhsBCOxFq02mKBy DhMDuWxTYtkEsKo6yno5JKHWVQ== X-Google-Smtp-Source: AGHT+IELT61PbPjwVXxuH+TJlXpsuDAjuE2mWwi9Afbapfuv6KVhTt3679yscvvJRLV4fCglxsflqg== X-Received: by 2002:a17:906:4fc8:b0:9a2:295a:9bbc with SMTP id i8-20020a1709064fc800b009a2295a9bbcmr3242168ejw.37.1699979530242; Tue, 14 Nov 2023 08:32:10 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Subject: [PATCH-for-9.0 7/9] hw/xen/hvm: Extract common code to xen-hvm-common.c Date: Tue, 14 Nov 2023 17:31:21 +0100 Message-ID: <20231114163123.74888-8-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979550640100001 Extract non-x86 specific code out of xen-hvm.c, to xen-hvm-common.c. For now this new file is only build for x86 targets. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Manos Pitsidianakis --- hw/i386/xen/xen-hvm-common.c | 473 +++++++++++++++++++++++++++++++++++ hw/i386/xen/xen-hvm.c | 459 --------------------------------- hw/i386/xen/meson.build | 1 + 3 files changed, 474 insertions(+), 459 deletions(-) create mode 100644 hw/i386/xen/xen-hvm-common.c diff --git a/hw/i386/xen/xen-hvm-common.c b/hw/i386/xen/xen-hvm-common.c new file mode 100644 index 0000000000..e8ef0e0c94 --- /dev/null +++ b/hw/i386/xen/xen-hvm-common.c @@ -0,0 +1,473 @@ +/* + * Copyright (C) 2010 Citrix Ltd. + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + * Contributions after 2012-01-13 are licensed under the terms of the + * GNU GPL, version 2 or (at your option) any later version. + */ + +#include "qemu/osdep.h" +#include "qemu/range.h" +#include "qapi/qapi-commands-migration.h" +#include "exec/target_page.h" +#include "hw/xen/xen-hvm-common.h" +#include "trace.h" + +static MemoryRegion *framebuffer; +static bool xen_in_migration; + +static QLIST_HEAD(, XenPhysmap) xen_physmap; +static const XenPhysmap *log_for_dirtybit; +/* Buffer used by xen_sync_dirty_bitmap */ +static unsigned long *dirty_bitmap; + +static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size, + int page_mask) +{ + XenPhysmap *physmap =3D NULL; + + start_addr &=3D -page_mask; + + QLIST_FOREACH(physmap, &xen_physmap, list) { + if (range_covers_byte(physmap->start_addr, physmap->size, start_ad= dr)) { + return physmap; + } + } + return NULL; +} + +static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, + int page_mask) +{ + hwaddr addr =3D phys_offset & -page_mask; + XenPhysmap *physmap =3D NULL; + + QLIST_FOREACH(physmap, &xen_physmap, list) { + if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) { + return physmap->start_addr + (phys_offset - physmap->phys_offs= et); + } + } + + return phys_offset; +} + +#ifdef XEN_COMPAT_PHYSMAP +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + char path[80], value[17]; + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->start_add= r); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->size); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + if (physmap->name) { + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", + xen_domid, (uint64_t)physmap->phys_offset); + if (!xs_write(state->xenstore, 0, path, + physmap->name, strlen(physmap->name))) { + return -1; + } + } + return 0; +} +#else +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + return 0; +} +#endif + +static int xen_add_to_physmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size, + MemoryRegion *mr, + hwaddr offset_within_region) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + unsigned long nr_pages; + int rc =3D 0; + XenPhysmap *physmap =3D NULL; + hwaddr pfn, start_gpfn; + hwaddr phys_offset =3D memory_region_get_ram_addr(mr); + const char *mr_name; + + if (get_physmapping(start_addr, size, page_mask)) { + return 0; + } + if (size <=3D 0) { + return -1; + } + + /* Xen can only handle a single dirty log region for now and we want + * the linear framebuffer to be that region. + * Avoid tracking any regions that is not videoram and avoid tracking + * the legacy vga region. */ + if (mr =3D=3D framebuffer && start_addr > 0xbffff) { + goto go_physmap; + } + return -1; + +go_physmap: + DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", + start_addr, start_addr + size); + + mr_name =3D memory_region_name(mr); + + physmap =3D g_new(XenPhysmap, 1); + + physmap->start_addr =3D start_addr; + physmap->size =3D size; + physmap->name =3D mr_name; + physmap->phys_offset =3D phys_offset; + + QLIST_INSERT_HEAD(&xen_physmap, physmap, list); + + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* Now when we have a physmap entry we can replace a dummy mapping= with + * a real one of guest foreign memory. */ + uint8_t *p =3D xen_replace_cache_entry(phys_offset, start_addr, si= ze); + assert(p && p =3D=3D memory_region_get_ram_ptr(mr)); + + return 0; + } + + pfn =3D phys_offset >> target_page_bits; + start_gpfn =3D start_addr >> target_page_bits; + nr_pages =3D size >> target_page_bits; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, + start_gpfn); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + nr_pages, pfn, start_gpfn, strerror(saved_errno)); + errno =3D saved_errno; + return -1; + } + + rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, + start_addr >> target_page_bits, + (start_addr + size - 1) >> target_page_= bits, + XEN_DOMCTL_MEM_CACHEATTR_WB); + if (rc) { + error_report("pin_memory_cacheattr failed: %s", strerror(errno)); + } + return xen_save_physmap(state, physmap); +} + +static int xen_remove_from_physmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + int rc =3D 0; + XenPhysmap *physmap =3D NULL; + hwaddr phys_offset =3D 0; + + physmap =3D get_physmapping(start_addr, size, page_mask); + if (physmap =3D=3D NULL) { + return -1; + } + + phys_offset =3D physmap->phys_offset; + size =3D physmap->size; + + DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at " + "%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset= ); + + size >>=3D target_page_bits; + start_addr >>=3D target_page_bits; + phys_offset >>=3D target_page_bits; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, + phys_offset); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory "RAM_ADDR_FMT" pages" + " from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + size, start_addr, phys_offset, strerror(saved_errno)); + errno =3D saved_errno; + return -1; + } + + QLIST_REMOVE(physmap, list); + if (log_for_dirtybit =3D=3D physmap) { + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; + } + g_free(physmap); + + return 0; +} + +static void xen_sync_dirty_bitmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr npages =3D size >> target_page_bits; + const int width =3D sizeof(unsigned long) * 8; + size_t bitmap_size =3D DIV_ROUND_UP(npages, width); + int rc, i, j; + const XenPhysmap *physmap =3D NULL; + + physmap =3D get_physmapping(start_addr, size, page_mask); + if (physmap =3D=3D NULL) { + /* not handled */ + return; + } + + if (log_for_dirtybit =3D=3D NULL) { + log_for_dirtybit =3D physmap; + dirty_bitmap =3D g_new(unsigned long, bitmap_size); + } else if (log_for_dirtybit !=3D physmap) { + /* Only one range for dirty bitmap can be tracked. */ + return; + } + + rc =3D xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits, + npages, dirty_bitmap); + if (rc < 0) { +#ifndef ENODATA +#define ENODATA ENOENT +#endif + if (errno =3D=3D ENODATA) { + memory_region_set_dirty(framebuffer, 0, size); + DPRINTF("xen: track_dirty_vram failed (0x" HWADDR_FMT_plx + ", 0x" HWADDR_FMT_plx "): %s\n", + start_addr, start_addr + size, strerror(errno)); + } + return; + } + + for (i =3D 0; i < bitmap_size; i++) { + unsigned long map =3D dirty_bitmap[i]; + while (map !=3D 0) { + j =3D ctzl(map); + map &=3D ~(1ul << j); + memory_region_set_dirty(framebuffer, + (i * width + j) * page_size, + page_size); + }; + } +} + +static void xen_log_start(MemoryListener *listener, + MemoryRegionSection *section, + int old, int new) +{ + XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + + if (new & ~old & (1 << DIRTY_MEMORY_VGA)) { + xen_sync_dirty_bitmap(state, section->offset_within_address_space, + int128_get64(section->size)); + } +} + +static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *se= ction, + int old, int new) +{ + if (old & ~new & (1 << DIRTY_MEMORY_VGA)) { + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; + /* Disable dirty bit tracking */ + xen_track_dirty_vram(xen_domid, 0, 0, NULL); + } +} + +static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *se= ction) +{ + XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + + xen_sync_dirty_bitmap(state, section->offset_within_address_space, + int128_get64(section->size)); +} + +static void xen_log_global_start(MemoryListener *listener) +{ + if (xen_enabled()) { + xen_in_migration =3D true; + } +} + +static void xen_log_global_stop(MemoryListener *listener) +{ + xen_in_migration =3D false; +} + +const MemoryListener xen_memory_listener =3D { + .name =3D "xen-memory", + .region_add =3D xen_region_add, + .region_del =3D xen_region_del, + .log_start =3D xen_log_start, + .log_stop =3D xen_log_stop, + .log_sync =3D xen_log_sync, + .log_global_start =3D xen_log_global_start, + .log_global_stop =3D xen_log_global_stop, + .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, +}; + +#ifdef XEN_COMPAT_PHYSMAP +void xen_read_physmap(XenIOState *state) +{ + XenPhysmap *physmap =3D NULL; + unsigned int len, num, i; + char path[80], *value =3D NULL; + char **entries =3D NULL; + + QLIST_INIT(&xen_physmap); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap", xen_domid); + entries =3D xs_directory(state->xenstore, 0, path, &num); + if (entries =3D=3D NULL) + return; + + for (i =3D 0; i < num; i++) { + physmap =3D g_new(XenPhysmap, 1); + physmap->phys_offset =3D strtoull(entries[i], NULL, 16); + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/start_addr", + xen_domid, entries[i]); + value =3D xs_read(state->xenstore, 0, path, &len); + if (value =3D=3D NULL) { + g_free(physmap); + continue; + } + physmap->start_addr =3D strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/size", + xen_domid, entries[i]); + value =3D xs_read(state->xenstore, 0, path, &len); + if (value =3D=3D NULL) { + g_free(physmap); + continue; + } + physmap->size =3D strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/name", + xen_domid, entries[i]); + physmap->name =3D xs_read(state->xenstore, 0, path, &len); + + QLIST_INSERT_HEAD(&xen_physmap, physmap, list); + } + free(entries); +} +#else +void xen_read_physmap(XenIOState *state) +{ + QLIST_INIT(&xen_physmap); +} +#endif + +void xen_register_framebuffer(MemoryRegion *mr) +{ + framebuffer =3D mr; +} + +void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + + if (unlikely(xen_in_migration)) { + int rc; + ram_addr_t start_pfn, nb_pages; + + start =3D xen_phys_offset_to_gaddr(start, length, page_mask); + + if (length =3D=3D 0) { + length =3D page_size; + } + start_pfn =3D start >> target_page_bits; + nb_pages =3D ((start + length + page_size - 1) >> target_page_bits) + - start_pfn; + rc =3D xen_modified_memory(xen_domid, start_pfn, nb_pages); + if (rc) { + fprintf(stderr, + "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s= \n", + __func__, start, nb_pages, errno, strerror(errno)); + } + } +} + +void qmp_xen_set_global_dirty_log(bool enable, Error **errp) +{ + if (enable) { + memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); + } else { + memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); + } +} + +void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, + bool add) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr start_addr =3D section->offset_within_address_space; + ram_addr_t size =3D int128_get64(section->size); + bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); + hvmmem_type_t mem_type; + + if (!memory_region_is_ram(section->mr)) { + return; + } + + if (log_dirty !=3D add) { + return; + } + + trace_xen_client_set_memory(start_addr, size, log_dirty); + + start_addr &=3D page_mask; + size =3D ROUND_UP(size, page_size); + + if (add) { + if (!memory_region_is_rom(section->mr)) { + xen_add_to_physmap(state, start_addr, size, + section->mr, section->offset_within_region); + } else { + mem_type =3D HVMMEM_ram_ro; + if (xen_set_mem_type(xen_domid, mem_type, + start_addr >> target_page_bits, + size >> target_page_bits)) { + DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", + start_addr); + } + } + } else { + if (xen_remove_from_physmap(state, start_addr, size) < 0) { + DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); + } + } +} diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index 3b9c31c1c8..5657693e1b 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -9,16 +9,11 @@ */ =20 #include "qemu/osdep.h" -#include "qemu/units.h" -#include "qapi/error.h" -#include "qapi/qapi-commands-migration.h" -#include "trace.h" =20 #include "hw/i386/pc.h" #include "hw/irq.h" #include "hw/i386/apic-msidef.h" #include "hw/xen/xen-x86.h" -#include "qemu/range.h" =20 #include "hw/xen/xen-hvm-common.h" #include @@ -26,8 +21,6 @@ #include "cpu.h" =20 static MemoryRegion ram_640k, ram_lo, ram_hi; -static MemoryRegion *framebuffer; -static bool xen_in_migration; =20 /* Compatibility with older version */ =20 @@ -56,10 +49,6 @@ typedef struct shared_vmport_iopage shared_vmport_iopage= _t; =20 static shared_vmport_iopage_t *shared_vmport_page; =20 -static QLIST_HEAD(, XenPhysmap) xen_physmap; -static const XenPhysmap *log_for_dirtybit; -/* Buffer used by xen_sync_dirty_bitmap */ -static unsigned long *dirty_bitmap; static Notifier suspend; static Notifier wakeup; =20 @@ -175,312 +164,6 @@ static void xen_ram_init(PCMachineState *pcms, } } =20 -static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size, - int page_mask) -{ - XenPhysmap *physmap =3D NULL; - - start_addr &=3D page_mask; - - QLIST_FOREACH(physmap, &xen_physmap, list) { - if (range_covers_byte(physmap->start_addr, physmap->size, start_ad= dr)) { - return physmap; - } - } - return NULL; -} - -static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, - int page_mask) -{ - hwaddr addr =3D phys_offset & page_mask; - XenPhysmap *physmap =3D NULL; - - QLIST_FOREACH(physmap, &xen_physmap, list) { - if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) { - return physmap->start_addr + (phys_offset - physmap->phys_offs= et); - } - } - - return phys_offset; -} - -#ifdef XEN_COMPAT_PHYSMAP -static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) -{ - char path[80], value[17]; - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", - xen_domid, (uint64_t)physmap->phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->start_add= r); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", - xen_domid, (uint64_t)physmap->phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->size); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - if (physmap->name) { - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", - xen_domid, (uint64_t)physmap->phys_offset); - if (!xs_write(state->xenstore, 0, path, - physmap->name, strlen(physmap->name))) { - return -1; - } - } - return 0; -} -#else -static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) -{ - return 0; -} -#endif - -static int xen_add_to_physmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size, - MemoryRegion *mr, - hwaddr offset_within_region) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - unsigned long nr_pages; - int rc =3D 0; - XenPhysmap *physmap =3D NULL; - hwaddr pfn, start_gpfn; - hwaddr phys_offset =3D memory_region_get_ram_addr(mr); - const char *mr_name; - - if (get_physmapping(start_addr, size, page_mask)) { - return 0; - } - if (size <=3D 0) { - return -1; - } - - /* Xen can only handle a single dirty log region for now and we want - * the linear framebuffer to be that region. - * Avoid tracking any regions that is not videoram and avoid tracking - * the legacy vga region. */ - if (mr =3D=3D framebuffer && start_addr > 0xbffff) { - goto go_physmap; - } - return -1; - -go_physmap: - DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", - start_addr, start_addr + size); - - mr_name =3D memory_region_name(mr); - - physmap =3D g_new(XenPhysmap, 1); - - physmap->start_addr =3D start_addr; - physmap->size =3D size; - physmap->name =3D mr_name; - physmap->phys_offset =3D phys_offset; - - QLIST_INSERT_HEAD(&xen_physmap, physmap, list); - - if (runstate_check(RUN_STATE_INMIGRATE)) { - /* Now when we have a physmap entry we can replace a dummy mapping= with - * a real one of guest foreign memory. */ - uint8_t *p =3D xen_replace_cache_entry(phys_offset, start_addr, si= ze); - assert(p && p =3D=3D memory_region_get_ram_ptr(mr)); - - return 0; - } - - pfn =3D phys_offset >> target_page_bits; - start_gpfn =3D start_addr >> target_page_bits; - nr_pages =3D size >> target_page_bits; - rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, - start_gpfn); - if (rc) { - int saved_errno =3D errno; - - error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx - " to GFN %"HWADDR_PRIx" failed: %s", - nr_pages, pfn, start_gpfn, strerror(saved_errno)); - errno =3D saved_errno; - return -1; - } - - rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, - start_addr >> target_page_bits, - (start_addr + size - 1) >> target_page_= bits, - XEN_DOMCTL_MEM_CACHEATTR_WB); - if (rc) { - error_report("pin_memory_cacheattr failed: %s", strerror(errno)); - } - return xen_save_physmap(state, physmap); -} - -static int xen_remove_from_physmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - int rc =3D 0; - XenPhysmap *physmap =3D NULL; - hwaddr phys_offset =3D 0; - - physmap =3D get_physmapping(start_addr, size, page_mask); - if (physmap =3D=3D NULL) { - return -1; - } - - phys_offset =3D physmap->phys_offset; - size =3D physmap->size; - - DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at " - "%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset= ); - - size >>=3D target_page_bits; - start_addr >>=3D target_page_bits; - phys_offset >>=3D target_page_bits; - rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, - phys_offset); - if (rc) { - int saved_errno =3D errno; - - error_report("relocate_memory "RAM_ADDR_FMT" pages" - " from GFN %"HWADDR_PRIx - " to GFN %"HWADDR_PRIx" failed: %s", - size, start_addr, phys_offset, strerror(saved_errno)); - errno =3D saved_errno; - return -1; - } - - QLIST_REMOVE(physmap, list); - if (log_for_dirtybit =3D=3D physmap) { - log_for_dirtybit =3D NULL; - g_free(dirty_bitmap); - dirty_bitmap =3D NULL; - } - g_free(physmap); - - return 0; -} - -static void xen_sync_dirty_bitmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - hwaddr npages =3D size >> target_page_bits; - const int width =3D sizeof(unsigned long) * 8; - size_t bitmap_size =3D DIV_ROUND_UP(npages, width); - int rc, i, j; - const XenPhysmap *physmap =3D NULL; - - physmap =3D get_physmapping(start_addr, size, page_mask); - if (physmap =3D=3D NULL) { - /* not handled */ - return; - } - - if (log_for_dirtybit =3D=3D NULL) { - log_for_dirtybit =3D physmap; - dirty_bitmap =3D g_new(unsigned long, bitmap_size); - } else if (log_for_dirtybit !=3D physmap) { - /* Only one range for dirty bitmap can be tracked. */ - return; - } - - rc =3D xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits, - npages, dirty_bitmap); - if (rc < 0) { -#ifndef ENODATA -#define ENODATA ENOENT -#endif - if (errno =3D=3D ENODATA) { - memory_region_set_dirty(framebuffer, 0, size); - DPRINTF("xen: track_dirty_vram failed (0x" HWADDR_FMT_plx - ", 0x" HWADDR_FMT_plx "): %s\n", - start_addr, start_addr + size, strerror(errno)); - } - return; - } - - for (i =3D 0; i < bitmap_size; i++) { - unsigned long map =3D dirty_bitmap[i]; - while (map !=3D 0) { - j =3D ctzl(map); - map &=3D ~(1ul << j); - memory_region_set_dirty(framebuffer, - (i * width + j) * page_size, page_size= ); - }; - } -} - -static void xen_log_start(MemoryListener *listener, - MemoryRegionSection *section, - int old, int new) -{ - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - - if (new & ~old & (1 << DIRTY_MEMORY_VGA)) { - xen_sync_dirty_bitmap(state, section->offset_within_address_space, - int128_get64(section->size)); - } -} - -static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *se= ction, - int old, int new) -{ - if (old & ~new & (1 << DIRTY_MEMORY_VGA)) { - log_for_dirtybit =3D NULL; - g_free(dirty_bitmap); - dirty_bitmap =3D NULL; - /* Disable dirty bit tracking */ - xen_track_dirty_vram(xen_domid, 0, 0, NULL); - } -} - -static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *se= ction) -{ - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - - xen_sync_dirty_bitmap(state, section->offset_within_address_space, - int128_get64(section->size)); -} - -static void xen_log_global_start(MemoryListener *listener) -{ - if (xen_enabled()) { - xen_in_migration =3D true; - } -} - -static void xen_log_global_stop(MemoryListener *listener) -{ - xen_in_migration =3D false; -} - -const MemoryListener xen_memory_listener =3D { - .name =3D "xen-memory", - .region_add =3D xen_region_add, - .region_del =3D xen_region_del, - .log_start =3D xen_log_start, - .log_stop =3D xen_log_stop, - .log_sync =3D xen_log_sync, - .log_global_start =3D xen_log_global_start, - .log_global_stop =3D xen_log_global_stop, - .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, -}; - static void regs_to_cpu(vmware_regs_t *vmport_regs, ioreq_t *req) { X86CPU *cpu; @@ -524,63 +207,6 @@ static void handle_vmport_ioreq(XenIOState *state, ior= eq_t *req) current_cpu =3D NULL; } =20 -#ifdef XEN_COMPAT_PHYSMAP -void xen_read_physmap(XenIOState *state) -{ - XenPhysmap *physmap =3D NULL; - unsigned int len, num, i; - char path[80], *value =3D NULL; - char **entries =3D NULL; - - QLIST_INIT(&xen_physmap); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap", xen_domid); - entries =3D xs_directory(state->xenstore, 0, path, &num); - if (entries =3D=3D NULL) - return; - - for (i =3D 0; i < num; i++) { - physmap =3D g_new(XenPhysmap, 1); - physmap->phys_offset =3D strtoull(entries[i], NULL, 16); - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/start_addr", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->start_addr =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/size", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->size =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/name", - xen_domid, entries[i]); - physmap->name =3D xs_read(state->xenstore, 0, path, &len); - - QLIST_INSERT_HEAD(&xen_physmap, physmap, list); - } - free(entries); -} -#else -void xen_read_physmap(XenIOState *state) -{ - QLIST_INIT(&xen_physmap); -} -#endif - static void xen_wakeup_notifier(Notifier *notifier, void *data) { xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); @@ -635,91 +261,6 @@ err: exit(1); } =20 -void xen_register_framebuffer(MemoryRegion *mr) -{ - framebuffer =3D mr; -} - -void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - - if (unlikely(xen_in_migration)) { - int rc; - ram_addr_t start_pfn, nb_pages; - - start =3D xen_phys_offset_to_gaddr(start, length, page_mask); - - if (length =3D=3D 0) { - length =3D page_size; - } - start_pfn =3D start >> target_page_bits; - nb_pages =3D ((start + length + page_size - 1) >> target_page_bits) - - start_pfn; - rc =3D xen_modified_memory(xen_domid, start_pfn, nb_pages); - if (rc) { - fprintf(stderr, - "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s= \n", - __func__, start, nb_pages, errno, strerror(errno)); - } - } -} - -void qmp_xen_set_global_dirty_log(bool enable, Error **errp) -{ - if (enable) { - memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); - } else { - memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); - } -} - -void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, - bool add) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - hwaddr start_addr =3D section->offset_within_address_space; - ram_addr_t size =3D int128_get64(section->size); - bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); - hvmmem_type_t mem_type; - - if (!memory_region_is_ram(section->mr)) { - return; - } - - if (log_dirty !=3D add) { - return; - } - - trace_xen_client_set_memory(start_addr, size, log_dirty); - - start_addr &=3D page_mask; - size =3D ROUND_UP(size, page_size); - - if (add) { - if (!memory_region_is_rom(section->mr)) { - xen_add_to_physmap(state, start_addr, size, - section->mr, section->offset_within_region); - } else { - mem_type =3D HVMMEM_ram_ro; - if (xen_set_mem_type(xen_domid, mem_type, - start_addr >> target_page_bits, - size >> target_page_bits)) { - DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", - start_addr); - } - } - } else { - if (xen_remove_from_physmap(state, start_addr, size) < 0) { - DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); - } - } -} - void xen_arch_handle_ioreq(XenIOState *state, ioreq_t *req) { switch (req->type) { diff --git a/hw/i386/xen/meson.build b/hw/i386/xen/meson.build index 3f0df8bc07..d38759cfe4 100644 --- a/hw/i386/xen/meson.build +++ b/hw/i386/xen/meson.build @@ -1,6 +1,7 @@ i386_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen_apic.c', 'xen_pvdevice.c', + 'xen-hvm-common.c', )) i386_ss.add(when: ['CONFIG_XEN', xen], if_true: files( 'xen-hvm.c', --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979559; cv=none; d=zohomail.com; s=zohoarc; b=nacet/NAcrgSTss9XenDAdWMTB6y8WwU3ZzFUO7Es8MLH2yLzfuV1RVc98JQq447EWRWDHkLkCnl4+wLX2M0nfJpSy1eUtTqEvO2LrQfBnTiMXgABrdDTMxFrfLlSnENAFvXrer/5fYPguerhlyDD9/3B3he71o7CwiU0h8cKdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979559; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=fBoLjADQF92oUz8YGjrCFJ5vAIgrltjc0XkKGW8dGlc=; b=K9vOdqoDf6o28looEb9x7U34LRCEy+9lvzN98qVT9uupDHR/uNJ0Y3Tv+afASyIReauKzW9tYCX/N6kMIrVkHflKMkfjRtH0iQviMpWspRv8DDsAIvF3XzEJ5/0WnS798+Bo0jJkKVQpBB73k9yrjtCjZcIN6y8/hAod0xG3YDo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1699979559204284.66083570797196; Tue, 14 Nov 2023 08:32:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.632947.987512 (Exim 4.92) (envelope-from ) id 1r2wKq-000623-VW; Tue, 14 Nov 2023 16:32:20 +0000 Received: by outflank-mailman (output) from mailman id 632947.987512; Tue, 14 Nov 2023 16:32:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKq-00061u-RT; Tue, 14 Nov 2023 16:32:20 +0000 Received: by outflank-mailman (input) for mailman id 632947; Tue, 14 Nov 2023 16:32:19 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r2wKp-0002h9-Ly for xen-devel@lists.xenproject.org; Tue, 14 Nov 2023 16:32:19 +0000 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [2a00:1450:4864:20::632]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 5fdbd3cf-830b-11ee-9b0e-b553b5be7939; Tue, 14 Nov 2023 17:32:17 +0100 (CET) Received: by mail-ej1-x632.google.com with SMTP id a640c23a62f3a-9d0b4dfd60dso875144566b.1 for ; Tue, 14 Nov 2023 08:32:17 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id s12-20020a1709066c8c00b0099cd008c1a4sm5788138ejr.136.2023.11.14.08.32.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:32:16 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 5fdbd3cf-830b-11ee-9b0e-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979537; x=1700584337; darn=lists.xenproject.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fBoLjADQF92oUz8YGjrCFJ5vAIgrltjc0XkKGW8dGlc=; b=YGlkzW7+UUuHZbgWRszP1Okvh2X3JotR5IEHlRam07sMXB3o9NVe/IWN4o9BwGvcso 9QzdCoiWw26rNv3cXt6B5bPr9jv5Sci1l2FGHl6gMq8reQWoGjNNHvFYMyCzYg5JXsfp EIzRWEPZeKH7dQxzkEMZ7kUR0RWvVK9ztRAVmCG9kPmfpTY6CC4ZZwMq4vR2GFr/hshT 9ZUrhkDhG8u5vnLVm+LHuo/vcJLO4STYLgAO9dOM6OQmglEKLiOW8BOkJc1kpw+hJaVz nLWlZIK4FZt8TEuARf7HjUwq3ln3sDdRa56mOg1JZYR61Nh8A3SgISuNxrS8QXtXdIHc vYww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979537; x=1700584337; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fBoLjADQF92oUz8YGjrCFJ5vAIgrltjc0XkKGW8dGlc=; b=rjZYHQz1ZvgHLRBLFAzR49/qj8bftz9KjSy43mYutf03W8qwL4uN1kG92zoBDcxCsv gVtSLJd47ha9/wFeyqwRaDBzHHxYBOHTNICUWzZUwcUBuDX3ubImVn5XE8BJXbO+uaEl j3KLdkRI4unPted5D+b30ge/l+yes5Fnp+F+YEUYliOshSa/lnVZzYj1FHP0NM6/1QFc ecDKhyG0j2+egxrSS7rAJv34YV4nMuPunMYGuPOMNmcavBE+IWT5mE4l1DMp2ddHnm5G anqWXSQYe9ws9LkYVcyFa0XQcwdNwsZ9u5OuTNxK6zcha0AF//MIjoKY2BEBxiJty4AY Bq+w== X-Gm-Message-State: AOJu0YxTFRE9ycyMDzNn/hHqu4spqYR6nduTbW++DPkt6k+w12r48OVP HsIePbmjptca9k2S0SF6sY0W2A== X-Google-Smtp-Source: AGHT+IHCzaPi5Ki96YFTxblFzU9hUvvVJMXhVG8xP2TJoi7bkBVxcUKkybZuFBTY+HQf7VLJRu7P5A== X-Received: by 2002:a17:906:dc9:b0:9d4:84b6:8709 with SMTP id p9-20020a1709060dc900b009d484b68709mr6908245eji.58.1699979536701; Tue, 14 Nov 2023 08:32:16 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Peter Maydell , "Michael S. Tsirkin" , Marcel Apfelbaum , Richard Henderson , Eduardo Habkost Subject: [RFC PATCH-for-9.0 8/9] hw/xen/hvm: Merge xen-hvm-common.c files Date: Tue, 14 Nov 2023 17:31:22 +0100 Message-ID: <20231114163123.74888-9-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979560798100001 hw/i386/xen/xen-hvm-common.c content is target agnostic, and should be common to all targets. Merge both files. Remove the now unnecessary xen_register_framebuffer() stub. ARM targets now inherit the common xen_memory_listener. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/xen_arm.c | 24 -- hw/i386/xen/xen-hvm-common.c | 473 ----------------------------------- hw/xen/xen-hvm-common.c | 458 +++++++++++++++++++++++++++++++++ stubs/xen-hw-stub.c | 4 - hw/i386/xen/meson.build | 1 - 5 files changed, 458 insertions(+), 502 deletions(-) delete mode 100644 hw/i386/xen/xen-hvm-common.c diff --git a/hw/arm/xen_arm.c b/hw/arm/xen_arm.c index 39dcd74d07..0ead84c9e1 100644 --- a/hw/arm/xen_arm.c +++ b/hw/arm/xen_arm.c @@ -38,17 +38,6 @@ #define TYPE_XEN_ARM MACHINE_TYPE_NAME("xenpvh") OBJECT_DECLARE_SIMPLE_TYPE(XenArmState, XEN_ARM) =20 -const MemoryListener xen_memory_listener =3D { - .region_add =3D xen_region_add, - .region_del =3D xen_region_del, - .log_start =3D NULL, - .log_stop =3D NULL, - .log_sync =3D NULL, - .log_global_start =3D NULL, - .log_global_stop =3D NULL, - .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, -}; - struct XenArmState { /*< private >*/ MachineState parent; @@ -136,19 +125,6 @@ void xen_arch_handle_ioreq(XenIOState *state, ioreq_t = *req) return; } =20 -void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, - bool add) -{ -} - -void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) -{ -} - -void qmp_xen_set_global_dirty_log(bool enable, Error **errp) -{ -} - #ifdef CONFIG_TPM static void xen_enable_tpm(XenArmState *xam) { diff --git a/hw/i386/xen/xen-hvm-common.c b/hw/i386/xen/xen-hvm-common.c deleted file mode 100644 index e8ef0e0c94..0000000000 --- a/hw/i386/xen/xen-hvm-common.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - * Copyright (C) 2010 Citrix Ltd. - * - * This work is licensed under the terms of the GNU GPL, version 2. See - * the COPYING file in the top-level directory. - * - * Contributions after 2012-01-13 are licensed under the terms of the - * GNU GPL, version 2 or (at your option) any later version. - */ - -#include "qemu/osdep.h" -#include "qemu/range.h" -#include "qapi/qapi-commands-migration.h" -#include "exec/target_page.h" -#include "hw/xen/xen-hvm-common.h" -#include "trace.h" - -static MemoryRegion *framebuffer; -static bool xen_in_migration; - -static QLIST_HEAD(, XenPhysmap) xen_physmap; -static const XenPhysmap *log_for_dirtybit; -/* Buffer used by xen_sync_dirty_bitmap */ -static unsigned long *dirty_bitmap; - -static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size, - int page_mask) -{ - XenPhysmap *physmap =3D NULL; - - start_addr &=3D -page_mask; - - QLIST_FOREACH(physmap, &xen_physmap, list) { - if (range_covers_byte(physmap->start_addr, physmap->size, start_ad= dr)) { - return physmap; - } - } - return NULL; -} - -static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, - int page_mask) -{ - hwaddr addr =3D phys_offset & -page_mask; - XenPhysmap *physmap =3D NULL; - - QLIST_FOREACH(physmap, &xen_physmap, list) { - if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) { - return physmap->start_addr + (phys_offset - physmap->phys_offs= et); - } - } - - return phys_offset; -} - -#ifdef XEN_COMPAT_PHYSMAP -static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) -{ - char path[80], value[17]; - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", - xen_domid, (uint64_t)physmap->phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->start_add= r); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", - xen_domid, (uint64_t)physmap->phys_offset); - snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->size); - if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { - return -1; - } - if (physmap->name) { - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", - xen_domid, (uint64_t)physmap->phys_offset); - if (!xs_write(state->xenstore, 0, path, - physmap->name, strlen(physmap->name))) { - return -1; - } - } - return 0; -} -#else -static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) -{ - return 0; -} -#endif - -static int xen_add_to_physmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size, - MemoryRegion *mr, - hwaddr offset_within_region) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - unsigned long nr_pages; - int rc =3D 0; - XenPhysmap *physmap =3D NULL; - hwaddr pfn, start_gpfn; - hwaddr phys_offset =3D memory_region_get_ram_addr(mr); - const char *mr_name; - - if (get_physmapping(start_addr, size, page_mask)) { - return 0; - } - if (size <=3D 0) { - return -1; - } - - /* Xen can only handle a single dirty log region for now and we want - * the linear framebuffer to be that region. - * Avoid tracking any regions that is not videoram and avoid tracking - * the legacy vga region. */ - if (mr =3D=3D framebuffer && start_addr > 0xbffff) { - goto go_physmap; - } - return -1; - -go_physmap: - DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", - start_addr, start_addr + size); - - mr_name =3D memory_region_name(mr); - - physmap =3D g_new(XenPhysmap, 1); - - physmap->start_addr =3D start_addr; - physmap->size =3D size; - physmap->name =3D mr_name; - physmap->phys_offset =3D phys_offset; - - QLIST_INSERT_HEAD(&xen_physmap, physmap, list); - - if (runstate_check(RUN_STATE_INMIGRATE)) { - /* Now when we have a physmap entry we can replace a dummy mapping= with - * a real one of guest foreign memory. */ - uint8_t *p =3D xen_replace_cache_entry(phys_offset, start_addr, si= ze); - assert(p && p =3D=3D memory_region_get_ram_ptr(mr)); - - return 0; - } - - pfn =3D phys_offset >> target_page_bits; - start_gpfn =3D start_addr >> target_page_bits; - nr_pages =3D size >> target_page_bits; - rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, - start_gpfn); - if (rc) { - int saved_errno =3D errno; - - error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx - " to GFN %"HWADDR_PRIx" failed: %s", - nr_pages, pfn, start_gpfn, strerror(saved_errno)); - errno =3D saved_errno; - return -1; - } - - rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, - start_addr >> target_page_bits, - (start_addr + size - 1) >> target_page_= bits, - XEN_DOMCTL_MEM_CACHEATTR_WB); - if (rc) { - error_report("pin_memory_cacheattr failed: %s", strerror(errno)); - } - return xen_save_physmap(state, physmap); -} - -static int xen_remove_from_physmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - int rc =3D 0; - XenPhysmap *physmap =3D NULL; - hwaddr phys_offset =3D 0; - - physmap =3D get_physmapping(start_addr, size, page_mask); - if (physmap =3D=3D NULL) { - return -1; - } - - phys_offset =3D physmap->phys_offset; - size =3D physmap->size; - - DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at " - "%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset= ); - - size >>=3D target_page_bits; - start_addr >>=3D target_page_bits; - phys_offset >>=3D target_page_bits; - rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, - phys_offset); - if (rc) { - int saved_errno =3D errno; - - error_report("relocate_memory "RAM_ADDR_FMT" pages" - " from GFN %"HWADDR_PRIx - " to GFN %"HWADDR_PRIx" failed: %s", - size, start_addr, phys_offset, strerror(saved_errno)); - errno =3D saved_errno; - return -1; - } - - QLIST_REMOVE(physmap, list); - if (log_for_dirtybit =3D=3D physmap) { - log_for_dirtybit =3D NULL; - g_free(dirty_bitmap); - dirty_bitmap =3D NULL; - } - g_free(physmap); - - return 0; -} - -static void xen_sync_dirty_bitmap(XenIOState *state, - hwaddr start_addr, - ram_addr_t size) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - hwaddr npages =3D size >> target_page_bits; - const int width =3D sizeof(unsigned long) * 8; - size_t bitmap_size =3D DIV_ROUND_UP(npages, width); - int rc, i, j; - const XenPhysmap *physmap =3D NULL; - - physmap =3D get_physmapping(start_addr, size, page_mask); - if (physmap =3D=3D NULL) { - /* not handled */ - return; - } - - if (log_for_dirtybit =3D=3D NULL) { - log_for_dirtybit =3D physmap; - dirty_bitmap =3D g_new(unsigned long, bitmap_size); - } else if (log_for_dirtybit !=3D physmap) { - /* Only one range for dirty bitmap can be tracked. */ - return; - } - - rc =3D xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits, - npages, dirty_bitmap); - if (rc < 0) { -#ifndef ENODATA -#define ENODATA ENOENT -#endif - if (errno =3D=3D ENODATA) { - memory_region_set_dirty(framebuffer, 0, size); - DPRINTF("xen: track_dirty_vram failed (0x" HWADDR_FMT_plx - ", 0x" HWADDR_FMT_plx "): %s\n", - start_addr, start_addr + size, strerror(errno)); - } - return; - } - - for (i =3D 0; i < bitmap_size; i++) { - unsigned long map =3D dirty_bitmap[i]; - while (map !=3D 0) { - j =3D ctzl(map); - map &=3D ~(1ul << j); - memory_region_set_dirty(framebuffer, - (i * width + j) * page_size, - page_size); - }; - } -} - -static void xen_log_start(MemoryListener *listener, - MemoryRegionSection *section, - int old, int new) -{ - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - - if (new & ~old & (1 << DIRTY_MEMORY_VGA)) { - xen_sync_dirty_bitmap(state, section->offset_within_address_space, - int128_get64(section->size)); - } -} - -static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *se= ction, - int old, int new) -{ - if (old & ~new & (1 << DIRTY_MEMORY_VGA)) { - log_for_dirtybit =3D NULL; - g_free(dirty_bitmap); - dirty_bitmap =3D NULL; - /* Disable dirty bit tracking */ - xen_track_dirty_vram(xen_domid, 0, 0, NULL); - } -} - -static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *se= ction) -{ - XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); - - xen_sync_dirty_bitmap(state, section->offset_within_address_space, - int128_get64(section->size)); -} - -static void xen_log_global_start(MemoryListener *listener) -{ - if (xen_enabled()) { - xen_in_migration =3D true; - } -} - -static void xen_log_global_stop(MemoryListener *listener) -{ - xen_in_migration =3D false; -} - -const MemoryListener xen_memory_listener =3D { - .name =3D "xen-memory", - .region_add =3D xen_region_add, - .region_del =3D xen_region_del, - .log_start =3D xen_log_start, - .log_stop =3D xen_log_stop, - .log_sync =3D xen_log_sync, - .log_global_start =3D xen_log_global_start, - .log_global_stop =3D xen_log_global_stop, - .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, -}; - -#ifdef XEN_COMPAT_PHYSMAP -void xen_read_physmap(XenIOState *state) -{ - XenPhysmap *physmap =3D NULL; - unsigned int len, num, i; - char path[80], *value =3D NULL; - char **entries =3D NULL; - - QLIST_INIT(&xen_physmap); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap", xen_domid); - entries =3D xs_directory(state->xenstore, 0, path, &num); - if (entries =3D=3D NULL) - return; - - for (i =3D 0; i < num; i++) { - physmap =3D g_new(XenPhysmap, 1); - physmap->phys_offset =3D strtoull(entries[i], NULL, 16); - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/start_addr", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->start_addr =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/size", - xen_domid, entries[i]); - value =3D xs_read(state->xenstore, 0, path, &len); - if (value =3D=3D NULL) { - g_free(physmap); - continue; - } - physmap->size =3D strtoull(value, NULL, 16); - free(value); - - snprintf(path, sizeof(path), - "/local/domain/0/device-model/%d/physmap/%s/name", - xen_domid, entries[i]); - physmap->name =3D xs_read(state->xenstore, 0, path, &len); - - QLIST_INSERT_HEAD(&xen_physmap, physmap, list); - } - free(entries); -} -#else -void xen_read_physmap(XenIOState *state) -{ - QLIST_INIT(&xen_physmap); -} -#endif - -void xen_register_framebuffer(MemoryRegion *mr) -{ - framebuffer =3D mr; -} - -void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - - if (unlikely(xen_in_migration)) { - int rc; - ram_addr_t start_pfn, nb_pages; - - start =3D xen_phys_offset_to_gaddr(start, length, page_mask); - - if (length =3D=3D 0) { - length =3D page_size; - } - start_pfn =3D start >> target_page_bits; - nb_pages =3D ((start + length + page_size - 1) >> target_page_bits) - - start_pfn; - rc =3D xen_modified_memory(xen_domid, start_pfn, nb_pages); - if (rc) { - fprintf(stderr, - "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s= \n", - __func__, start, nb_pages, errno, strerror(errno)); - } - } -} - -void qmp_xen_set_global_dirty_log(bool enable, Error **errp) -{ - if (enable) { - memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); - } else { - memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); - } -} - -void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, - bool add) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - hwaddr start_addr =3D section->offset_within_address_space; - ram_addr_t size =3D int128_get64(section->size); - bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); - hvmmem_type_t mem_type; - - if (!memory_region_is_ram(section->mr)) { - return; - } - - if (log_dirty !=3D add) { - return; - } - - trace_xen_client_set_memory(start_addr, size, log_dirty); - - start_addr &=3D page_mask; - size =3D ROUND_UP(size, page_size); - - if (add) { - if (!memory_region_is_rom(section->mr)) { - xen_add_to_physmap(state, start_addr, size, - section->mr, section->offset_within_region); - } else { - mem_type =3D HVMMEM_ram_ro; - if (xen_set_mem_type(xen_domid, mem_type, - start_addr >> target_page_bits, - size >> target_page_bits)) { - DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", - start_addr); - } - } - } else { - if (xen_remove_from_physmap(state, start_addr, size) < 0) { - DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); - } - } -} diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 73fa2c414d..50ce45effc 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -1,7 +1,9 @@ #include "qemu/osdep.h" #include "qemu/units.h" #include "qemu/bitops.h" +#include "qemu/range.h" #include "qapi/error.h" +#include "qapi/qapi-commands-migration.h" #include "exec/target_page.h" #include "trace.h" =20 @@ -11,6 +13,462 @@ #include "hw/boards.h" =20 MemoryRegion xen_memory; +static MemoryRegion *framebuffer; +static bool xen_in_migration; + +static QLIST_HEAD(, XenPhysmap) xen_physmap; +static const XenPhysmap *log_for_dirtybit; +/* Buffer used by xen_sync_dirty_bitmap */ +static unsigned long *dirty_bitmap; + +static XenPhysmap *get_physmapping(hwaddr start_addr, ram_addr_t size, + int page_mask) +{ + XenPhysmap *physmap =3D NULL; + + start_addr &=3D -page_mask; + + QLIST_FOREACH(physmap, &xen_physmap, list) { + if (range_covers_byte(physmap->start_addr, physmap->size, start_ad= dr)) { + return physmap; + } + } + return NULL; +} + +static hwaddr xen_phys_offset_to_gaddr(hwaddr phys_offset, ram_addr_t size, + int page_mask) +{ + hwaddr addr =3D phys_offset & -page_mask; + XenPhysmap *physmap =3D NULL; + + QLIST_FOREACH(physmap, &xen_physmap, list) { + if (range_covers_byte(physmap->phys_offset, physmap->size, addr)) { + return physmap->start_addr + (phys_offset - physmap->phys_offs= et); + } + } + + return phys_offset; +} + +#ifdef XEN_COMPAT_PHYSMAP +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + char path[80], value[17]; + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/start_addr", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->start_add= r); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/size", + xen_domid, (uint64_t)physmap->phys_offset); + snprintf(value, sizeof(value), "%"PRIx64, (uint64_t)physmap->size); + if (!xs_write(state->xenstore, 0, path, value, strlen(value))) { + return -1; + } + if (physmap->name) { + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%"PRIx64"/name", + xen_domid, (uint64_t)physmap->phys_offset); + if (!xs_write(state->xenstore, 0, path, + physmap->name, strlen(physmap->name))) { + return -1; + } + } + return 0; +} +#else +static int xen_save_physmap(XenIOState *state, XenPhysmap *physmap) +{ + return 0; +} +#endif + +static int xen_add_to_physmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size, + MemoryRegion *mr, + hwaddr offset_within_region) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + unsigned long nr_pages; + int rc =3D 0; + XenPhysmap *physmap =3D NULL; + hwaddr pfn, start_gpfn; + hwaddr phys_offset =3D memory_region_get_ram_addr(mr); + const char *mr_name; + + if (get_physmapping(start_addr, size, page_mask)) { + return 0; + } + if (size <=3D 0) { + return -1; + } + + /* Xen can only handle a single dirty log region for now and we want + * the linear framebuffer to be that region. + * Avoid tracking any regions that is not videoram and avoid tracking + * the legacy vga region. */ + if (mr =3D=3D framebuffer && start_addr > 0xbffff) { + goto go_physmap; + } + return -1; + +go_physmap: + DPRINTF("mapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx"\n", + start_addr, start_addr + size); + + mr_name =3D memory_region_name(mr); + + physmap =3D g_new(XenPhysmap, 1); + + physmap->start_addr =3D start_addr; + physmap->size =3D size; + physmap->name =3D mr_name; + physmap->phys_offset =3D phys_offset; + + QLIST_INSERT_HEAD(&xen_physmap, physmap, list); + + if (runstate_check(RUN_STATE_INMIGRATE)) { + /* Now when we have a physmap entry we can replace a dummy mapping= with + * a real one of guest foreign memory. */ + uint8_t *p =3D xen_replace_cache_entry(phys_offset, start_addr, si= ze); + assert(p && p =3D=3D memory_region_get_ram_ptr(mr)); + + return 0; + } + + pfn =3D phys_offset >> target_page_bits; + start_gpfn =3D start_addr >> target_page_bits; + nr_pages =3D size >> target_page_bits; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, nr_pages, p= fn, + start_gpfn); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory %lu pages from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + nr_pages, pfn, start_gpfn, strerror(saved_errno)); + errno =3D saved_errno; + return -1; + } + + rc =3D xendevicemodel_pin_memory_cacheattr(xen_dmod, xen_domid, + start_addr >> target_page_bits, + (start_addr + size - 1) >> target_page_= bits, + XEN_DOMCTL_MEM_CACHEATTR_WB); + if (rc) { + error_report("pin_memory_cacheattr failed: %s", strerror(errno)); + } + return xen_save_physmap(state, physmap); +} + +static int xen_remove_from_physmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + int rc =3D 0; + XenPhysmap *physmap =3D NULL; + hwaddr phys_offset =3D 0; + + physmap =3D get_physmapping(start_addr, size, page_mask); + if (physmap =3D=3D NULL) { + return -1; + } + + phys_offset =3D physmap->phys_offset; + size =3D physmap->size; + + DPRINTF("unmapping vram to %"HWADDR_PRIx" - %"HWADDR_PRIx", at " + "%"HWADDR_PRIx"\n", start_addr, start_addr + size, phys_offset= ); + + size >>=3D target_page_bits; + start_addr >>=3D target_page_bits; + phys_offset >>=3D target_page_bits; + rc =3D xendevicemodel_relocate_memory(xen_dmod, xen_domid, size, start= _addr, + phys_offset); + if (rc) { + int saved_errno =3D errno; + + error_report("relocate_memory "RAM_ADDR_FMT" pages" + " from GFN %"HWADDR_PRIx + " to GFN %"HWADDR_PRIx" failed: %s", + size, start_addr, phys_offset, strerror(saved_errno)); + errno =3D saved_errno; + return -1; + } + + QLIST_REMOVE(physmap, list); + if (log_for_dirtybit =3D=3D physmap) { + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; + } + g_free(physmap); + + return 0; +} + +static void xen_sync_dirty_bitmap(XenIOState *state, + hwaddr start_addr, + ram_addr_t size) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr npages =3D size >> target_page_bits; + const int width =3D sizeof(unsigned long) * 8; + size_t bitmap_size =3D DIV_ROUND_UP(npages, width); + int rc, i, j; + const XenPhysmap *physmap =3D NULL; + + physmap =3D get_physmapping(start_addr, size, page_mask); + if (physmap =3D=3D NULL) { + /* not handled */ + return; + } + + if (log_for_dirtybit =3D=3D NULL) { + log_for_dirtybit =3D physmap; + dirty_bitmap =3D g_new(unsigned long, bitmap_size); + } else if (log_for_dirtybit !=3D physmap) { + /* Only one range for dirty bitmap can be tracked. */ + return; + } + + rc =3D xen_track_dirty_vram(xen_domid, start_addr >> target_page_bits, + npages, dirty_bitmap); + if (rc < 0) { +#ifndef ENODATA +#define ENODATA ENOENT +#endif + if (errno =3D=3D ENODATA) { + memory_region_set_dirty(framebuffer, 0, size); + DPRINTF("xen: track_dirty_vram failed (0x" HWADDR_FMT_plx + ", 0x" HWADDR_FMT_plx "): %s\n", + start_addr, start_addr + size, strerror(errno)); + } + return; + } + + for (i =3D 0; i < bitmap_size; i++) { + unsigned long map =3D dirty_bitmap[i]; + while (map !=3D 0) { + j =3D ctzl(map); + map &=3D ~(1ul << j); + memory_region_set_dirty(framebuffer, + (i * width + j) * page_size, + page_size); + }; + } +} + +static void xen_log_start(MemoryListener *listener, + MemoryRegionSection *section, + int old, int new) +{ + XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + + if (new & ~old & (1 << DIRTY_MEMORY_VGA)) { + xen_sync_dirty_bitmap(state, section->offset_within_address_space, + int128_get64(section->size)); + } +} + +static void xen_log_stop(MemoryListener *listener, MemoryRegionSection *se= ction, + int old, int new) +{ + if (old & ~new & (1 << DIRTY_MEMORY_VGA)) { + log_for_dirtybit =3D NULL; + g_free(dirty_bitmap); + dirty_bitmap =3D NULL; + /* Disable dirty bit tracking */ + xen_track_dirty_vram(xen_domid, 0, 0, NULL); + } +} + +static void xen_log_sync(MemoryListener *listener, MemoryRegionSection *se= ction) +{ + XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + + xen_sync_dirty_bitmap(state, section->offset_within_address_space, + int128_get64(section->size)); +} + +static void xen_log_global_start(MemoryListener *listener) +{ + if (xen_enabled()) { + xen_in_migration =3D true; + } +} + +static void xen_log_global_stop(MemoryListener *listener) +{ + xen_in_migration =3D false; +} + +const MemoryListener xen_memory_listener =3D { + .name =3D "xen-memory", + .region_add =3D xen_region_add, + .region_del =3D xen_region_del, + .log_start =3D xen_log_start, + .log_stop =3D xen_log_stop, + .log_sync =3D xen_log_sync, + .log_global_start =3D xen_log_global_start, + .log_global_stop =3D xen_log_global_stop, + .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, +}; + +#ifdef XEN_COMPAT_PHYSMAP +void xen_read_physmap(XenIOState *state) +{ + XenPhysmap *physmap =3D NULL; + unsigned int len, num, i; + char path[80], *value =3D NULL; + char **entries =3D NULL; + + QLIST_INIT(&xen_physmap); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap", xen_domid); + entries =3D xs_directory(state->xenstore, 0, path, &num); + if (entries =3D=3D NULL) + return; + + for (i =3D 0; i < num; i++) { + physmap =3D g_new(XenPhysmap, 1); + physmap->phys_offset =3D strtoull(entries[i], NULL, 16); + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/start_addr", + xen_domid, entries[i]); + value =3D xs_read(state->xenstore, 0, path, &len); + if (value =3D=3D NULL) { + g_free(physmap); + continue; + } + physmap->start_addr =3D strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/size", + xen_domid, entries[i]); + value =3D xs_read(state->xenstore, 0, path, &len); + if (value =3D=3D NULL) { + g_free(physmap); + continue; + } + physmap->size =3D strtoull(value, NULL, 16); + free(value); + + snprintf(path, sizeof(path), + "/local/domain/0/device-model/%d/physmap/%s/name", + xen_domid, entries[i]); + physmap->name =3D xs_read(state->xenstore, 0, path, &len); + + QLIST_INSERT_HEAD(&xen_physmap, physmap, list); + } + free(entries); +} +#else +void xen_read_physmap(XenIOState *state) +{ + QLIST_INIT(&xen_physmap); +} +#endif + +void xen_register_framebuffer(MemoryRegion *mr) +{ + framebuffer =3D mr; +} + +void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + + if (unlikely(xen_in_migration)) { + int rc; + ram_addr_t start_pfn, nb_pages; + + start =3D xen_phys_offset_to_gaddr(start, length, page_mask); + + if (length =3D=3D 0) { + length =3D page_size; + } + start_pfn =3D start >> target_page_bits; + nb_pages =3D ((start + length + page_size - 1) >> target_page_bits) + - start_pfn; + rc =3D xen_modified_memory(xen_domid, start_pfn, nb_pages); + if (rc) { + fprintf(stderr, + "%s failed for "RAM_ADDR_FMT" ("RAM_ADDR_FMT"): %i, %s= \n", + __func__, start, nb_pages, errno, strerror(errno)); + } + } +} + +void qmp_xen_set_global_dirty_log(bool enable, Error **errp) +{ + if (enable) { + memory_global_dirty_log_start(GLOBAL_DIRTY_MIGRATION); + } else { + memory_global_dirty_log_stop(GLOBAL_DIRTY_MIGRATION); + } +} + +void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, + bool add) +{ + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr start_addr =3D section->offset_within_address_space; + ram_addr_t size =3D int128_get64(section->size); + bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); + hvmmem_type_t mem_type; + + if (!memory_region_is_ram(section->mr)) { + return; + } + + if (log_dirty !=3D add) { + return; + } + + trace_xen_client_set_memory(start_addr, size, log_dirty); + + start_addr &=3D page_mask; + size =3D ROUND_UP(size, page_size); + + if (add) { + if (!memory_region_is_rom(section->mr)) { + xen_add_to_physmap(state, start_addr, size, + section->mr, section->offset_within_region); + } else { + mem_type =3D HVMMEM_ram_ro; + if (xen_set_mem_type(xen_domid, mem_type, + start_addr >> target_page_bits, + size >> target_page_bits)) { + DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", + start_addr); + } + } + } else { + if (xen_remove_from_physmap(state, start_addr, size) < 0) { + DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); + } + } +} =20 void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) diff --git a/stubs/xen-hw-stub.c b/stubs/xen-hw-stub.c index 53c6a6f2a0..da8912f037 100644 --- a/stubs/xen-hw-stub.c +++ b/stubs/xen-hw-stub.c @@ -13,7 +13,3 @@ int xen_is_pirq_msi(uint32_t msi_data) { return 0; } - -void xen_register_framebuffer(MemoryRegion *mr) -{ -} diff --git a/hw/i386/xen/meson.build b/hw/i386/xen/meson.build index d38759cfe4..3f0df8bc07 100644 --- a/hw/i386/xen/meson.build +++ b/hw/i386/xen/meson.build @@ -1,7 +1,6 @@ i386_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen_apic.c', 'xen_pvdevice.c', - 'xen-hvm-common.c', )) i386_ss.add(when: ['CONFIG_XEN', xen], if_true: files( 'xen-hvm.c', --=20 2.41.0 From nobody Tue May 21 19:08:13 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1699979614; cv=none; d=zohomail.com; s=zohoarc; b=VrmP6YsdYXdp/RN6axLuz6zbeJjYZUnD4EDRQfJpGchCa0UoODV9CkCIcCY1HVWZpwnf0AImp4WnwCsF/oLWHhBsvNfz/VOHjWBiZxEvyc2lQBaZBQIauA0m71VKWno64aGJuPhrzaZgDmtVdzhuc1f3JceOo8lJ6RmFX0QXUkY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1699979614; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=htjkOQmTZcMenhXqLaaInIEhXImv4mUPxpJWcjUwWD8=; b=c68LJ5LKXdvSsDrEQzfDcrsLAEX0U02nyqd8S266/iVdiTp4FHIlxg7NNRAian7MBUEhnhT6l8wuaPlgTEEkEipdSvetaehb+Ha8kVrGKHe7rBdnADgTgmgUjt8LDzbZrOv3SzE2cQi9ns/9vh6JVaHZvitIsX3Y+MsDBQ3RuXU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1699979614324352.80694647693804; Tue, 14 Nov 2023 08:33:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r2wLO-000486-54; Tue, 14 Nov 2023 11:32:54 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1r2wKy-0003KW-5i for qemu-devel@nongnu.org; Tue, 14 Nov 2023 11:32:32 -0500 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1r2wKt-0006eG-Uf for qemu-devel@nongnu.org; Tue, 14 Nov 2023 11:32:25 -0500 Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9e62f903e88so645816366b.2 for ; Tue, 14 Nov 2023 08:32:23 -0800 (PST) Received: from m1x-phil.lan (cac94-h02-176-184-25-155.dsl.sta.abo.bbox.fr. [176.184.25.155]) by smtp.gmail.com with ESMTPSA id c26-20020a17090603da00b009adce1c97ccsm5731084eja.53.2023.11.14.08.32.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Nov 2023 08:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1699979542; x=1700584342; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=htjkOQmTZcMenhXqLaaInIEhXImv4mUPxpJWcjUwWD8=; b=qXUpAG5U7kUwBh7IMiLEJsYIq5hU3iSNPyp6nnd/GvrOCa+JwebR/jRbvB+C1i6COH lhngntDiU+SVMBI5qXxB6MQ9fnGFtPyrZTd1Vv9bN29WF/PYYaFU+H2S30vjNaahQAqZ tXdLcXV3bluM5jc9mYWibcXKEq401pZGfXhhUzX4TJb4Gj5XqorNsc520tXs8oiePSW6 k/YzjHfvd+0zfIEMCkSqrCfribLuBNnTswYAQeV8Yg1YfQ7VXo1elCmNRUf9TkCFHYz5 fgXmSz71MbLORvFAosRuFr2GuaEhCf7KknGxnkRn52snJmHsiT5K3t0dfWqq0m9jFhge vAyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699979542; x=1700584342; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=htjkOQmTZcMenhXqLaaInIEhXImv4mUPxpJWcjUwWD8=; b=vQXgQ/52JAtVpAbitspi7qvrOM+ipuqiSYhcqHKdA8SJxnHxCFFuSMOlmqKBCyMfGS i0oedCBHVB8bMIaYpETJB8jxtRzhyN3inQHhWzwfP0sssqFGzF48FEF71GC/Cdbeudtj KpuS0FUS3O/4YToyF7rhYCDejJpuZxdRrJYbNgAvyT3tHBBEKOqHaq/14yrvxunE8dp4 1b9xDcyzD1ET2dqPJypfJszaJdAGZfeGr7tpBieztfyKHLWC+klUwHe9/YFhOLFXWXAH W1y9clZlA75dSqu5QOcaFTWQTpr66ELH0Jr3vWdnVSxQYYwYU/6PSLD2MGzQYBIiBdRE xK6Q== X-Gm-Message-State: AOJu0YwRQvKdvA80DlKfVBzTGT2tMvUj3Waq+BWkXJTK1mQ9Kx56P2LB Hz/gAengCku+o8zcSxblfteKy9m/iYG3rlgnWRY= X-Google-Smtp-Source: AGHT+IEJmFgqouqetrQ1cGRifpy+1FzLH8THhoRj/4LtsoCnWeS7Y04NxjXy02qkfonieH2Xog4T5Q== X-Received: by 2002:a17:906:7943:b0:9d3:e48f:30d3 with SMTP id l3-20020a170906794300b009d3e48f30d3mr9901673ejo.31.1699979542369; Tue, 14 Nov 2023 08:32:22 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Anthony Perard , Paul Durrant , David Woodhouse , Thomas Huth , qemu-arm@nongnu.org, Stefano Stabellini , Paolo Bonzini , =?UTF-8?q?Alex=20Benn=C3=A9e?= , xen-devel@lists.xenproject.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-9.0 9/9] hw/xen/hvm: Inline xen_arch_set_memory() Date: Tue, 14 Nov 2023 17:31:23 +0100 Message-ID: <20231114163123.74888-10-philmd@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231114163123.74888-1-philmd@linaro.org> References: <20231114163123.74888-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62e; envelope-from=philmd@linaro.org; helo=mail-ej1-x62e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1699979615112100001 xen_arch_set_memory() is not arch-specific anymore. Being called once, inline it in xen_set_memory(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/xen/xen-hvm-common.h | 3 - hw/xen/xen-hvm-common.c | 104 ++++++++++++++++---------------- 2 files changed, 51 insertions(+), 56 deletions(-) diff --git a/include/hw/xen/xen-hvm-common.h b/include/hw/xen/xen-hvm-commo= n.h index 536712dc83..a1b8a2783b 100644 --- a/include/hw/xen/xen-hvm-common.h +++ b/include/hw/xen/xen-hvm-common.h @@ -99,8 +99,5 @@ void cpu_ioreq_pio(ioreq_t *req); =20 void xen_read_physmap(XenIOState *state); void xen_arch_handle_ioreq(XenIOState *state, ioreq_t *req); -void xen_arch_set_memory(XenIOState *state, - MemoryRegionSection *section, - bool add); =20 #endif /* HW_XEN_HVM_COMMON_H */ diff --git a/hw/xen/xen-hvm-common.c b/hw/xen/xen-hvm-common.c index 50ce45effc..789c6b4b7a 100644 --- a/hw/xen/xen-hvm-common.c +++ b/hw/xen/xen-hvm-common.c @@ -426,50 +426,6 @@ void qmp_xen_set_global_dirty_log(bool enable, Error *= *errp) } } =20 -void xen_arch_set_memory(XenIOState *state, MemoryRegionSection *section, - bool add) -{ - unsigned target_page_bits =3D qemu_target_page_bits(); - int page_size =3D qemu_target_page_size(); - int page_mask =3D -page_size; - hwaddr start_addr =3D section->offset_within_address_space; - ram_addr_t size =3D int128_get64(section->size); - bool log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_= VGA); - hvmmem_type_t mem_type; - - if (!memory_region_is_ram(section->mr)) { - return; - } - - if (log_dirty !=3D add) { - return; - } - - trace_xen_client_set_memory(start_addr, size, log_dirty); - - start_addr &=3D page_mask; - size =3D ROUND_UP(size, page_size); - - if (add) { - if (!memory_region_is_rom(section->mr)) { - xen_add_to_physmap(state, start_addr, size, - section->mr, section->offset_within_region); - } else { - mem_type =3D HVMMEM_ram_ro; - if (xen_set_mem_type(xen_domid, mem_type, - start_addr >> target_page_bits, - size >> target_page_bits)) { - DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", - start_addr); - } - } - } else { - if (xen_remove_from_physmap(state, start_addr, size) < 0) { - DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); - } - } -} - void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size, MemoryRegion *mr, Error **errp) { @@ -512,20 +468,62 @@ static void xen_set_memory(struct MemoryListener *lis= tener, bool add) { XenIOState *state =3D container_of(listener, XenIOState, memory_listen= er); + unsigned target_page_bits =3D qemu_target_page_bits(); + int page_size =3D qemu_target_page_size(); + int page_mask =3D -page_size; + hwaddr start_addr; + ram_addr_t size; + bool log_dirty; + hvmmem_type_t mem_type; + =20 if (section->mr =3D=3D &xen_memory) { return; - } else { - if (add) { - xen_map_memory_section(xen_domid, state->ioservid, - section); - } else { - xen_unmap_memory_section(xen_domid, state->ioservid, - section); - } } =20 - xen_arch_set_memory(state, section, add); + if (add) { + xen_map_memory_section(xen_domid, state->ioservid, + section); + } else { + xen_unmap_memory_section(xen_domid, state->ioservid, + section); + } + + if (!memory_region_is_ram(section->mr)) { + return; + } + + log_dirty =3D memory_region_is_logging(section->mr, DIRTY_MEMORY_VGA); + + if (log_dirty !=3D add) { + return; + } + + start_addr =3D section->offset_within_address_space; + size =3D int128_get64(section->size); + trace_xen_client_set_memory(start_addr, size, log_dirty); + + start_addr &=3D page_mask; + size =3D ROUND_UP(size, page_size); + + if (add) { + if (!memory_region_is_rom(section->mr)) { + xen_add_to_physmap(state, start_addr, size, + section->mr, section->offset_within_region); + } else { + mem_type =3D HVMMEM_ram_ro; + if (xen_set_mem_type(xen_domid, mem_type, + start_addr >> target_page_bits, + size >> target_page_bits)) { + DPRINTF("xen_set_mem_type error, addr: "HWADDR_FMT_plx"\n", + start_addr); + } + } + } else { + if (xen_remove_from_physmap(state, start_addr, size) < 0) { + DPRINTF("physmapping does not exist at "HWADDR_FMT_plx"\n", st= art_addr); + } + } } =20 void xen_region_add(MemoryListener *listener, --=20 2.41.0