From patchwork Thu Sep 20 10:32:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84C671390 for ; Thu, 20 Sep 2018 10:34:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 757732CCC1 for ; Thu, 20 Sep 2018 10:34:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69D792CCCB; Thu, 20 Sep 2018 10:34:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1C19F2CCC1 for ; Thu, 20 Sep 2018 10:34:26 +0000 (UTC) Received: from localhost ([::1]:49337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHx-0003dg-9n for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:34:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGd-0002TZ-V5 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGZ-0005yA-Q5 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:62388) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGZ-0005xG-JA; Thu, 20 Sep 2018 06:32:59 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87B04792B7; Thu, 20 Sep 2018 10:32:57 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D5A63091330; Thu, 20 Sep 2018 10:32:54 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:22 +0200 Message-Id: <20180920103243.28474-2-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Sep 2018 10:32:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 01/22] memory-device: fix error message when hinted address is too small X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The "at" should actually be a "before". if (new_addr < address_space_start) -> "can't add memory ... before... $address_space_start" So it looks similar to the other check } else if ((new_addr + size) > address_space_end) -> "can't add memory ... beyond..." Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 6de4f70bb4..efacbc2a7d 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -146,7 +146,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, new_addr = *hint; if (new_addr < address_space_start) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 - "] at 0x%" PRIx64, new_addr, size, address_space_start); + "] before 0x%" PRIx64, new_addr, size, + address_space_start); return 0; } else if ((new_addr + size) > address_space_end) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 From patchwork Thu Sep 20 10:32:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D49BC1390 for ; Thu, 20 Sep 2018 10:37:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C35092CCD9 for ; Thu, 20 Sep 2018 10:37:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6F262CCFB; Thu, 20 Sep 2018 10:37:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F0D02CCF5 for ; Thu, 20 Sep 2018 10:37:22 +0000 (UTC) Received: from localhost ([::1]:49357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wKn-00069H-21 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:37:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGd-0002TY-V2 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGc-0005za-Ce for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGc-0005zB-4I; Thu, 20 Sep 2018 06:33:02 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 58FA25D5EA; Thu, 20 Sep 2018 10:33:01 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id D29F43091327; Thu, 20 Sep 2018 10:32:57 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:23 +0200 Message-Id: <20180920103243.28474-3-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Sep 2018 10:33:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 02/22] memory-device: handle integer overflows properly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Although unlikely in practice, we could have integer overflows on some calculations based on addresses and sizes, leading to error checks not triggering. Let's properly handle this whenever we do an addition. Make address_space_end point at the real end, instead of end + 1, so we don't have to handle special cases like it being 0. This will allow us to place a memory device at the very end of the guest physical 64bit address space (if ever possible). Also, QEMU_ALIGN_UP(md_addr + md_size, align) could (theoretically) wrap to address 0, so add a final check for 0. Reported-by: Dr. David Alan Gilbert Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index efacbc2a7d..020aad102a 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -85,7 +85,8 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size, /* will we exceed the total amount of memory specified */ memory_device_used_region_size(OBJECT(ms), &used_region_size); - if (used_region_size + size > ms->maxram_size - ms->ram_size) { + if (used_region_size + size < used_region_size || + used_region_size + size > ms->maxram_size - ms->ram_size) { error_setg(errp, "not enough space, currently 0x%" PRIx64 " in use of total hot pluggable 0x" RAM_ADDR_FMT, used_region_size, ms->maxram_size - ms->ram_size); @@ -115,7 +116,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, } address_space_start = ms->device_memory->base; address_space_end = address_space_start + - memory_region_size(&ms->device_memory->mr); + memory_region_size(&ms->device_memory->mr) - 1; g_assert(address_space_end >= address_space_start); /* address_space_start indicates the maximum alignment we expect */ @@ -149,7 +150,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, "] before 0x%" PRIx64, new_addr, size, address_space_start); return 0; - } else if ((new_addr + size) > address_space_end) { + } else if (new_addr + size - 1 < new_addr || + new_addr + size - 1 > address_space_end) { error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 "] beyond 0x%" PRIx64, new_addr, size, address_space_end); @@ -182,7 +184,8 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, } } - if (new_addr + size > address_space_end) { + if (new_addr + size - 1 < new_addr || !new_addr || + new_addr + size - 1 > address_space_end) { error_setg(errp, "could not find position in guest address space for " "memory device - memory fragmented due to alignments"); goto out; From patchwork Thu Sep 20 10:32:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6AD1114BD for ; Thu, 20 Sep 2018 10:35:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B5902C9C8 for ; Thu, 20 Sep 2018 10:35:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E6D22CCCB; Thu, 20 Sep 2018 10:35:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F32312C9C8 for ; Thu, 20 Sep 2018 10:35:06 +0000 (UTC) Received: from localhost ([::1]:49342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIc-0004GI-7y for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:35:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGj-0002Wz-BK for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGi-00063Q-BP for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34372) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGf-00061k-PL; Thu, 20 Sep 2018 06:33:08 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0F560C058CB8; Thu, 20 Sep 2018 10:33:05 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A66C53091330; Thu, 20 Sep 2018 10:33:01 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:24 +0200 Message-Id: <20180920103243.28474-4-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 20 Sep 2018 10:33:05 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 03/22] memory-device: use memory device terminology in error messages X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP While we rephrased most error messages, we missed these. Reviewed-by: Dr. David Alan Gilbert Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 020aad102a..909566756a 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -88,7 +88,7 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size, if (used_region_size + size < used_region_size || used_region_size + size > ms->maxram_size - ms->ram_size) { error_setg(errp, "not enough space, currently 0x%" PRIx64 - " in use of total hot pluggable 0x" RAM_ADDR_FMT, + " in use of total space for memory devices 0x" RAM_ADDR_FMT, used_region_size, ms->maxram_size - ms->ram_size); return; } @@ -146,13 +146,13 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, if (hint) { new_addr = *hint; if (new_addr < address_space_start) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" PRIx64 "] before 0x%" PRIx64, new_addr, size, address_space_start); return 0; } else if (new_addr + size - 1 < new_addr || new_addr + size - 1 > address_space_end) { - error_setg(errp, "can't add memory [0x%" PRIx64 ":0x%" PRIx64 + error_setg(errp, "can't add memory device [0x%" PRIx64 ":0x%" PRIx64 "] beyond 0x%" PRIx64, new_addr, size, address_space_end); return 0; From patchwork Thu Sep 20 10:32:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E72401390 for ; Thu, 20 Sep 2018 10:37:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5DD02CCF5 for ; Thu, 20 Sep 2018 10:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C92772CCD9; Thu, 20 Sep 2018 10:37:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6B43F2CCD9 for ; Thu, 20 Sep 2018 10:37:41 +0000 (UTC) Received: from localhost ([::1]:49358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wL6-0006b6-Jl for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:37:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGp-0002cz-Nx for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGo-00068f-MF for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGo-00067h-EI; Thu, 20 Sep 2018 06:33:14 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A652330024DC; Thu, 20 Sep 2018 10:33:13 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A56C3091327; Thu, 20 Sep 2018 10:33:05 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:25 +0200 Message-Id: <20180920103243.28474-5-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 20 Sep 2018 10:33:13 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 04/22] memory-device: introduce separate config option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some architectures might support memory devices, while they don't support DIMM/NVDIMM. So let's - Rename CONFIG_MEM_HOTPLUG to CONFIG_MEM_DEVICE - Introduce CONFIG_DIMM and use it similarly to CONFIG NVDIMM CONFIG_DIMM and CONFIG_NVDIMM require CONFIG_MEM_DEVICE. Reviewed-by: Igor Mammedov Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Acked-by: David Gibson --- default-configs/i386-softmmu.mak | 3 ++- default-configs/ppc64-softmmu.mak | 3 ++- hw/Makefile.objs | 2 +- hw/mem/Makefile.objs | 4 ++-- qapi/misc.json | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 8c7d4a0fa0..4c1637338b 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -50,7 +50,8 @@ CONFIG_PCI_Q35=y CONFIG_APIC=y CONFIG_IOAPIC=y CONFIG_PVPANIC=y -CONFIG_MEM_HOTPLUG=y +CONFIG_MEM_DEVICE=y +CONFIG_DIMM=y CONFIG_NVDIMM=y CONFIG_ACPI_NVDIMM=y CONFIG_PCIE_PORT=y diff --git a/default-configs/ppc64-softmmu.mak b/default-configs/ppc64-softmmu.mak index b94af6c7c6..f550573782 100644 --- a/default-configs/ppc64-softmmu.mak +++ b/default-configs/ppc64-softmmu.mak @@ -16,4 +16,5 @@ CONFIG_VIRTIO_VGA=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) -CONFIG_MEM_HOTPLUG=y +CONFIG_MEM_DEVICE=y +CONFIG_DIMM=y diff --git a/hw/Makefile.objs b/hw/Makefile.objs index a19c1417ed..58872e27e0 100644 --- a/hw/Makefile.objs +++ b/hw/Makefile.objs @@ -33,7 +33,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += vfio/ devices-dirs-$(CONFIG_SOFTMMU) += virtio/ devices-dirs-$(CONFIG_SOFTMMU) += watchdog/ devices-dirs-$(CONFIG_SOFTMMU) += xen/ -devices-dirs-$(CONFIG_MEM_HOTPLUG) += mem/ +devices-dirs-$(CONFIG_MEM_DEVICE) += mem/ devices-dirs-$(CONFIG_SOFTMMU) += smbios/ devices-dirs-y += core/ common-obj-y += $(devices-dirs-y) diff --git a/hw/mem/Makefile.objs b/hw/mem/Makefile.objs index 10be4df2a2..3e2f7c5ca2 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,3 +1,3 @@ -common-obj-$(CONFIG_MEM_HOTPLUG) += pc-dimm.o -common-obj-$(CONFIG_MEM_HOTPLUG) += memory-device.o +common-obj-$(CONFIG_DIMM) += pc-dimm.o +common-obj-$(CONFIG_MEM_DEVICE) += memory-device.o common-obj-$(CONFIG_NVDIMM) += nvdimm.o diff --git a/qapi/misc.json b/qapi/misc.json index d450cfef21..7c36de0464 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2061,7 +2061,7 @@ # # @plugged-memory: size of memory that can be hot-unplugged. This field # is omitted if target doesn't support memory hotplug -# (i.e. CONFIG_MEM_HOTPLUG not defined on build time). +# (i.e. CONFIG_MEM_DEVICE not defined at build time). # # Since: 2.11.0 ## From patchwork Thu Sep 20 10:32:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8561A1390 for ; Thu, 20 Sep 2018 10:38:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D99D292D1 for ; Thu, 20 Sep 2018 10:38:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3CC2929140; Thu, 20 Sep 2018 10:38:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B4EF728754 for ; Thu, 20 Sep 2018 10:38:00 +0000 (UTC) Received: from localhost ([::1]:49359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wLQ-0006r9-0s for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:38:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32938) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGt-0002gN-E4 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGs-0006CO-Bj for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGs-0006Bw-2c; Thu, 20 Sep 2018 06:33:18 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 550633097025; Thu, 20 Sep 2018 10:33:17 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F26A23091327; Thu, 20 Sep 2018 10:33:13 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:26 +0200 Message-Id: <20180920103243.28474-6-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 20 Sep 2018 10:33:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 05/22] memory-device: forward errors in get_region_size()/get_plugged_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Let's properly forward the errors, so errors from get_region_size() / get_plugged_size() can be handled. Users right now call both functions after the device has been realized, which is will never fail, so it is fine to continue using error_abort. While at it, remove a leftover error check (suggedted by Igor). Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 9 +++------ hw/mem/pc-dimm.c | 5 +++-- include/hw/mem/memory-device.h | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 909566756a..bdcee6fd55 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -60,7 +60,7 @@ static int memory_device_used_region_size(Object *obj, void *opaque) const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj); if (dev->realized) { - *size += mdc->get_region_size(md); + *size += mdc->get_region_size(md, &error_abort); } } @@ -169,10 +169,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, uint64_t md_size, md_addr; md_addr = mdc->get_addr(md); - md_size = mdc->get_region_size(md); - if (*errp) { - goto out; - } + md_size = mdc->get_region_size(md, &error_abort); if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { @@ -236,7 +233,7 @@ static int memory_device_plugged_size(Object *obj, void *opaque) const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj); if (dev->realized) { - *size += mdc->get_plugged_size(md); + *size += mdc->get_plugged_size(md, &error_abort); } } diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index fb6bcaedc4..4bf1a0acc9 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -236,14 +236,15 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md) return dimm->addr; } -static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md) +static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, + Error **errp) { /* dropping const here is fine as we don't touch the memory region */ PCDIMMDevice *dimm = PC_DIMM(md); const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md); MemoryRegion *mr; - mr = ddc->get_memory_region(dimm, &error_abort); + mr = ddc->get_memory_region(dimm, errp); if (!mr) { return 0; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2853b084b5..f02b229837 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -33,8 +33,8 @@ typedef struct MemoryDeviceClass { InterfaceClass parent_class; uint64_t (*get_addr)(const MemoryDeviceState *md); - uint64_t (*get_plugged_size)(const MemoryDeviceState *md); - uint64_t (*get_region_size)(const MemoryDeviceState *md); + uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp); + uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); } MemoryDeviceClass; From patchwork Thu Sep 20 10:32:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D7E5112B for ; Thu, 20 Sep 2018 10:40:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C5E62CD09 for ; Thu, 20 Sep 2018 10:40:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F4892CD3C; Thu, 20 Sep 2018 10:40:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 349462CD22 for ; Thu, 20 Sep 2018 10:40:59 +0000 (UTC) Received: from localhost ([::1]:49385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wOI-0001II-Eu for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:40:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32996) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wGz-0002nr-NX for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGv-0006FW-VN for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34424) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGv-0006Eg-Ot; Thu, 20 Sep 2018 06:33:21 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08E6EC057F20; Thu, 20 Sep 2018 10:33:21 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E42A3091327; Thu, 20 Sep 2018 10:33:17 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:27 +0200 Message-Id: <20180920103243.28474-7-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 20 Sep 2018 10:33:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 06/22] memory-device: document MemoryDeviceClass X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Document the functions and when to not expect errors. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- include/hw/mem/memory-device.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index f02b229837..d6853156ff 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -29,9 +29,22 @@ typedef struct MemoryDeviceState { Object parent_obj; } MemoryDeviceState; +/** + * MemoryDeviceClass: + * @get_addr: The address of the @md in guest physical memory. "0" means that + * no address has been specified by the user and that no address has been + * assigned yet. + * @get_plugged_size: The amount of memory provided by this @md currently + * usable ("plugged") by the guest. + * @get_region_size: The size of the memory region of the @md that's mapped + * in guest physical memory at @get_addr. + * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. + */ typedef struct MemoryDeviceClass { + /* private */ InterfaceClass parent_class; + /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp); uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); From patchwork Thu Sep 20 10:32:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 443DB1390 for ; Thu, 20 Sep 2018 10:35:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 313BF2C9C8 for ; Thu, 20 Sep 2018 10:35:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 235622CCCB; Thu, 20 Sep 2018 10:35:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 849032C9C8 for ; Thu, 20 Sep 2018 10:35:05 +0000 (UTC) Received: from localhost ([::1]:49341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIa-0004FU-Om for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:35:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33011) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wH0-0002px-Uw for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wGz-0006H5-Nz for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40400) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wGz-0006Go-Et; Thu, 20 Sep 2018 06:33:25 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD66CC049D5C; Thu, 20 Sep 2018 10:33:24 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4E70F3091327; Thu, 20 Sep 2018 10:33:21 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:28 +0200 Message-Id: <20180920103243.28474-8-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 20 Sep 2018 10:33:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 07/22] memory-device: add and use memory_device_get_region_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We will factor out get_memory_region() from pc-dimm to memory device code soon. Once that is done, get_region_size() can be implemented generically and essentially be replaced by memory_device_get_region_size (and work only on get_memory_region()). We have some users of get_memory_region() (spapr and pc-dimm code) that are only interested in the size. So let's rework them to use memory_device_get_region_size() first, then we can factor out get_memory_region() and eventually remove get_region_size() without touching the same code multiple times. Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 13 ++++++++++--- hw/mem/pc-dimm.c | 10 ++++------ hw/ppc/spapr.c | 27 +++++++++------------------ include/hw/mem/memory-device.h | 2 ++ 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index bdcee6fd55..2fa68b3730 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -57,10 +57,9 @@ static int memory_device_used_region_size(Object *obj, void *opaque) if (object_dynamic_cast(obj, TYPE_MEMORY_DEVICE)) { const DeviceState *dev = DEVICE(obj); const MemoryDeviceState *md = MEMORY_DEVICE(obj); - const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(obj); if (dev->realized) { - *size += mdc->get_region_size(md, &error_abort); + *size += memory_device_get_region_size(md, &error_abort); } } @@ -169,7 +168,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, uint64_t md_size, md_addr; md_addr = mdc->get_addr(md); - md_size = mdc->get_region_size(md, &error_abort); + md_size = memory_device_get_region_size(md, &error_abort); if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { @@ -268,6 +267,14 @@ void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) memory_region_del_subregion(&ms->device_memory->mr, mr); } +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp) +{ + MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + + return mdc->get_region_size(md, errp); +} + static const TypeInfo memory_device_info = { .name = TYPE_MEMORY_DEVICE, .parent = TYPE_INTERFACE, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 4bf1a0acc9..a06da7e08e 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -163,16 +163,14 @@ static Property pc_dimm_properties[] = { static void pc_dimm_get_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) { + Error *local_err = NULL; uint64_t value; - MemoryRegion *mr; - PCDIMMDevice *dimm = PC_DIMM(obj); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(obj); - mr = ddc->get_memory_region(dimm, errp); - if (!mr) { + value = memory_device_get_region_size(MEMORY_DEVICE(obj), errp); + if (local_err) { + error_propagate(errp, local_err); return; } - value = memory_region_size(mr); visit_type_uint64(v, name, &value, errp); } diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 4edb6c7d16..b56ce6b7aa 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -3124,20 +3124,17 @@ static void spapr_memory_plug(HotplugHandler *hotplug_dev, DeviceState *dev, { Error *local_err = NULL; sPAPRMachineState *ms = SPAPR_MACHINE(hotplug_dev); - PCDIMMDevice *dimm = PC_DIMM(dev); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); uint64_t size, addr; uint32_t node; - size = memory_region_size(mr); + size = memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abort); pc_dimm_plug(dev, MACHINE(ms), &local_err); if (local_err) { goto out; } - addr = object_property_get_uint(OBJECT(dimm), + addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, &local_err); if (local_err) { goto out_unplug; @@ -3165,10 +3162,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, { const sPAPRMachineClass *smc = SPAPR_MACHINE_GET_CLASS(hotplug_dev); sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev); - PCDIMMDevice *dimm = PC_DIMM(dev); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); Error *local_err = NULL; - MemoryRegion *mr; uint64_t size; Object *memdev; hwaddr pagesize; @@ -3178,11 +3172,11 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, return; } - mr = ddc->get_memory_region(dimm, errp); - if (!mr) { + size = memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abort); + if (local_err) { + error_propagate(errp, local_err); return; } - size = memory_region_size(mr); if (size % SPAPR_MEMORY_BLOCK_SIZE) { error_setg(errp, "Hotplugged memory size must be a multiple of " @@ -3190,7 +3184,7 @@ static void spapr_memory_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev, return; } - memdev = object_property_get_link(OBJECT(dimm), PC_DIMM_MEMDEV_PROP, + memdev = object_property_get_link(OBJECT(dev), PC_DIMM_MEMDEV_PROP, &error_abort); pagesize = host_memory_backend_pagesize(MEMORY_BACKEND(memdev)); spapr_check_pagesize(spapr, pagesize, &local_err); @@ -3254,9 +3248,8 @@ static sPAPRDIMMState *spapr_recover_pending_dimm_state(sPAPRMachineState *ms, PCDIMMDevice *dimm) { sPAPRDRConnector *drc; - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); - uint64_t size = memory_region_size(mr); + uint64_t size = memory_device_get_region_size(MEMORY_DEVICE(dimm), + &error_abort); uint32_t nr_lmbs = size / SPAPR_MEMORY_BLOCK_SIZE; uint32_t avail_lmbs = 0; uint64_t addr_start, addr; @@ -3322,14 +3315,12 @@ static void spapr_memory_unplug_request(HotplugHandler *hotplug_dev, sPAPRMachineState *spapr = SPAPR_MACHINE(hotplug_dev); Error *local_err = NULL; PCDIMMDevice *dimm = PC_DIMM(dev); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); uint32_t nr_lmbs; uint64_t size, addr_start, addr; int i; sPAPRDRConnector *drc; - size = memory_region_size(mr); + size = memory_device_get_region_size(MEMORY_DEVICE(dev), &error_abort); nr_lmbs = size / SPAPR_MEMORY_BLOCK_SIZE; addr_start = object_property_get_uint(OBJECT(dimm), PC_DIMM_ADDR_PROP, diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index d6853156ff..12f8ca9eb1 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -60,5 +60,7 @@ uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); +uint64_t memory_device_get_region_size(const MemoryDeviceState *md, + Error **errp); #endif From patchwork Thu Sep 20 10:32:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A51C161F for ; Thu, 20 Sep 2018 10:40:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4845A2CD09 for ; Thu, 20 Sep 2018 10:40:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BB302CD3C; Thu, 20 Sep 2018 10:40:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8F0522CD09 for ; Thu, 20 Sep 2018 10:40:35 +0000 (UTC) Received: from localhost ([::1]:49381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wNu-0000yt-Cd for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:40:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHC-0002x5-1S for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wH8-0006Nw-9K for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49156) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wH8-0006Nb-0X; Thu, 20 Sep 2018 06:33:34 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E4F130001DE; Thu, 20 Sep 2018 10:33:33 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15393091327; Thu, 20 Sep 2018 10:33:24 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:29 +0200 Message-Id: <20180920103243.28474-9-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Thu, 20 Sep 2018 10:33:33 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 08/22] memory-device: factor out get_memory_region() from pc-dimm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The memory region is necessary for plugging/unplugging a memory device. The region size (via get_region_size()) is no longer sufficient, as besides the alignment, also the region itself is required in order to add it to the device memory region of the machine via - memory_region_add_subregion - memory_region_del_subregion So, to factor out plugging/unplugging of memory devices from pc-dimm code, we have to factor out access to the memory region first. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/nvdimm.c | 9 ++++++--- hw/mem/pc-dimm.c | 26 ++++++++++++++++---------- include/hw/mem/memory-device.h | 5 +++++ include/hw/mem/pc-dimm.h | 4 ---- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/hw/mem/nvdimm.c b/hw/mem/nvdimm.c index 1c6674c4ed..49324f3fae 100644 --- a/hw/mem/nvdimm.c +++ b/hw/mem/nvdimm.c @@ -27,6 +27,7 @@ #include "qapi/error.h" #include "qapi/visitor.h" #include "hw/mem/nvdimm.h" +#include "hw/mem/memory-device.h" static void nvdimm_get_label_size(Object *obj, Visitor *v, const char *name, void *opaque, Error **errp) @@ -118,9 +119,10 @@ static void nvdimm_prepare_memory_region(NVDIMMDevice *nvdimm, Error **errp) nvdimm->nvdimm_mr->align = align; } -static MemoryRegion *nvdimm_get_memory_region(PCDIMMDevice *dimm, Error **errp) +static MemoryRegion *nvdimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) { - NVDIMMDevice *nvdimm = NVDIMM(dimm); + NVDIMMDevice *nvdimm = NVDIMM(md); Error *local_err = NULL; if (!nvdimm->nvdimm_mr) { @@ -190,11 +192,12 @@ static Property nvdimm_properties[] = { static void nvdimm_class_init(ObjectClass *oc, void *data) { PCDIMMDeviceClass *ddc = PC_DIMM_CLASS(oc); + MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(oc); NVDIMMClass *nvc = NVDIMM_CLASS(oc); DeviceClass *dc = DEVICE_CLASS(oc); ddc->realize = nvdimm_realize; - ddc->get_memory_region = nvdimm_get_memory_region; + mdc->get_memory_region = nvdimm_md_get_memory_region; dc->props = nvdimm_properties; nvc->read_label_data = nvdimm_read_label_data; diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index a06da7e08e..49ad8bac2d 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,8 +32,7 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - PCDIMMDevice *dimm = PC_DIMM(dev); - PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); Error *local_err = NULL; MemoryRegion *mr; uint64_t addr, align; @@ -49,7 +48,7 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_abort); trace_mhp_pc_dimm_assigned_slot(slot); - mr = ddc->get_memory_region(dimm, &local_err); + mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &local_err); if (local_err) { goto out; } @@ -73,9 +72,10 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp) { PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, &error_abort); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort); uint64_t addr; addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, @@ -89,9 +89,10 @@ void pc_dimm_unplug(DeviceState *dev, MachineState *machine) { PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); + MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, &error_abort); - MemoryRegion *mr = ddc->get_memory_region(dimm, &error_abort); + MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort); memory_device_unplug_region(machine, mr); vmstate_unregister_ram(vmstate_mr, dev); @@ -237,12 +238,11 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md) static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, Error **errp) { - /* dropping const here is fine as we don't touch the memory region */ - PCDIMMDevice *dimm = PC_DIMM(md); - const PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(md); + MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); MemoryRegion *mr; - mr = ddc->get_memory_region(dimm, errp); + /* dropping const here is fine as we don't touch the memory region */ + mr = mdc->get_memory_region((MemoryDeviceState *)md, errp); if (!mr) { return 0; } @@ -250,6 +250,12 @@ static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, return memory_region_size(mr); } +static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + return pc_dimm_get_memory_region(PC_DIMM(md), errp); +} + static void pc_dimm_md_fill_device_info(const MemoryDeviceState *md, MemoryDeviceInfo *info) { @@ -291,13 +297,13 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data) dc->props = pc_dimm_properties; dc->desc = "DIMM memory module"; - ddc->get_memory_region = pc_dimm_get_memory_region; ddc->get_vmstate_memory_region = pc_dimm_get_memory_region; mdc->get_addr = pc_dimm_md_get_addr; /* for a dimm plugged_size == region_size */ mdc->get_plugged_size = pc_dimm_md_get_region_size; mdc->get_region_size = pc_dimm_md_get_region_size; + mdc->get_memory_region = pc_dimm_md_get_memory_region; mdc->fill_device_info = pc_dimm_md_fill_device_info; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 12f8ca9eb1..0feed4ec0d 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -38,6 +38,10 @@ typedef struct MemoryDeviceState { * usable ("plugged") by the guest. * @get_region_size: The size of the memory region of the @md that's mapped * in guest physical memory at @get_addr. + * @get_memory_region: The memory region of the @md of the @md that's + * mapped in guest physical memory at @get_addr. If a @md is ever composed + * of multiple successive memory regions, a covering memory region is to + * be used. Scattered memory regions are not supported for single devices. * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. */ typedef struct MemoryDeviceClass { @@ -48,6 +52,7 @@ typedef struct MemoryDeviceClass { uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp); uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); + MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); } MemoryDeviceClass; diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h index b382eb4303..b445687081 100644 --- a/include/hw/mem/pc-dimm.h +++ b/include/hw/mem/pc-dimm.h @@ -61,9 +61,6 @@ typedef struct PCDIMMDevice { * PCDIMMDeviceClass: * @realize: called after common dimm is realized so that the dimm based * devices get the chance to do specified operations. - * @get_memory_region: returns #MemoryRegion associated with @dimm which - * is directly mapped into the physical address space of guest. Will not - * fail after the device was realized. * @get_vmstate_memory_region: returns #MemoryRegion which indicates the * memory of @dimm should be kept during live migration. Will not fail * after the device was realized. @@ -74,7 +71,6 @@ typedef struct PCDIMMDeviceClass { /* public */ void (*realize)(PCDIMMDevice *dimm, Error **errp); - MemoryRegion *(*get_memory_region)(PCDIMMDevice *dimm, Error **errp); MemoryRegion *(*get_vmstate_memory_region)(PCDIMMDevice *dimm, Error **errp); } PCDIMMDeviceClass; From patchwork Thu Sep 20 10:32:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 627BB15E8 for ; Thu, 20 Sep 2018 10:43:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 514CB28C95 for ; Thu, 20 Sep 2018 10:43:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 450512BEB8; Thu, 20 Sep 2018 10:43:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D7B052B527 for ; Thu, 20 Sep 2018 10:43:20 +0000 (UTC) Received: from localhost ([::1]:49398 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wQZ-0003UG-RJ for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:43:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHD-0002y9-3b for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHC-0006RG-2F for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHB-0006Qb-Nb; Thu, 20 Sep 2018 06:33:37 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0927A81101; Thu, 20 Sep 2018 10:33:37 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9D4983091327; Thu, 20 Sep 2018 10:33:33 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:30 +0200 Message-Id: <20180920103243.28474-10-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Sep 2018 10:33:37 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 09/22] memory-device: drop get_region_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP We now have get_memory_region(), which can be used generically to detect the region size. Use memory_device_get_region_size() where get_region_size() was used and use memory_device_get_region_size() as callback for get_plugged_size() (pc-dimm only for now). Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 11 +++++++++-- hw/mem/pc-dimm.c | 18 +----------------- include/hw/mem/memory-device.h | 3 --- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 2fa68b3730..1ab28e42cf 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -270,9 +270,16 @@ void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp) { - MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr; - return mdc->get_region_size(md, errp); + /* dropping const here is fine as we don't touch the memory region */ + mr = mdc->get_memory_region((MemoryDeviceState *)md, errp); + if (!mr) { + return 0; + } + + return memory_region_size(mr); } static const TypeInfo memory_device_info = { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 49ad8bac2d..95c3c4bd76 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -235,21 +235,6 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md) return dimm->addr; } -static uint64_t pc_dimm_md_get_region_size(const MemoryDeviceState *md, - Error **errp) -{ - MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); - MemoryRegion *mr; - - /* dropping const here is fine as we don't touch the memory region */ - mr = mdc->get_memory_region((MemoryDeviceState *)md, errp); - if (!mr) { - return 0; - } - - return memory_region_size(mr); -} - static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, Error **errp) { @@ -301,8 +286,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data) mdc->get_addr = pc_dimm_md_get_addr; /* for a dimm plugged_size == region_size */ - mdc->get_plugged_size = pc_dimm_md_get_region_size; - mdc->get_region_size = pc_dimm_md_get_region_size; + mdc->get_plugged_size = memory_device_get_region_size; mdc->get_memory_region = pc_dimm_md_get_memory_region; mdc->fill_device_info = pc_dimm_md_fill_device_info; } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 0feed4ec0d..64df232919 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -36,8 +36,6 @@ typedef struct MemoryDeviceState { * assigned yet. * @get_plugged_size: The amount of memory provided by this @md currently * usable ("plugged") by the guest. - * @get_region_size: The size of the memory region of the @md that's mapped - * in guest physical memory at @get_addr. * @get_memory_region: The memory region of the @md of the @md that's * mapped in guest physical memory at @get_addr. If a @md is ever composed * of multiple successive memory regions, a covering memory region is to @@ -51,7 +49,6 @@ typedef struct MemoryDeviceClass { /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp); - uint64_t (*get_region_size)(const MemoryDeviceState *md, Error **errp); MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); From patchwork Thu Sep 20 10:32:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D162014BD for ; Thu, 20 Sep 2018 10:38:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1DB82BAEB for ; Thu, 20 Sep 2018 10:38:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B55592BB34; Thu, 20 Sep 2018 10:38:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5781D2BAEB for ; Thu, 20 Sep 2018 10:38:02 +0000 (UTC) Received: from localhost ([::1]:49360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wLR-0006rd-K3 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:38:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHG-00031u-JW for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHF-0006Ws-MX for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHF-0006WK-Dy; Thu, 20 Sep 2018 06:33:41 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AEA443001773; Thu, 20 Sep 2018 10:33:40 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 558D83091327; Thu, 20 Sep 2018 10:33:37 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:31 +0200 Message-Id: <20180920103243.28474-11-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 20 Sep 2018 10:33:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 10/22] memory-device: add device class function set_addr() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP To be able to factor out address asignment of memory devices, we will have to read (get_addr()) and write (set_addr()) the address. We can't use properties for this purpose, as properties are device specific. E.g. while the address property for a DIMM is called "addr", it might be called differently (e.g. "memaddr") for other devices. Especially virtio based memory devices cannot use "addr" as that is already reserved and used for the address on the bus (for the proxy device). Also, it might be possible to have memory devices without address properties (e.g. internal DIMM-like thingies). In contrast to get_addr(), we expect that set_addr() can fail. Keep it simple for now for pc-dimm and simply set the static property, that will fail once realized from the callback. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/pc-dimm.c | 7 +++++++ include/hw/mem/memory-device.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 95c3c4bd76..3474b810ef 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -235,6 +235,12 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md) return dimm->addr; } +static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, PC_DIMM_ADDR_PROP, errp); +} + static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md, Error **errp) { @@ -285,6 +291,7 @@ static void pc_dimm_class_init(ObjectClass *oc, void *data) ddc->get_vmstate_memory_region = pc_dimm_get_memory_region; mdc->get_addr = pc_dimm_md_get_addr; + mdc->set_addr = pc_dimm_md_set_addr; /* for a dimm plugged_size == region_size */ mdc->get_plugged_size = memory_device_get_region_size; mdc->get_memory_region = pc_dimm_md_get_memory_region; diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 64df232919..b2fd26c262 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -34,6 +34,7 @@ typedef struct MemoryDeviceState { * @get_addr: The address of the @md in guest physical memory. "0" means that * no address has been specified by the user and that no address has been * assigned yet. + * @set_addr: Set the address of the @md in guest physical memory. * @get_plugged_size: The amount of memory provided by this @md currently * usable ("plugged") by the guest. * @get_memory_region: The memory region of the @md of the @md that's @@ -48,6 +49,7 @@ typedef struct MemoryDeviceClass { /* public */ uint64_t (*get_addr)(const MemoryDeviceState *md); + void (*set_addr)(MemoryDeviceState *md, uint64_t addr, Error **errp); uint64_t (*get_plugged_size)(const MemoryDeviceState *md, Error **errp); MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, From patchwork Thu Sep 20 10:32:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BD29F112B for ; Thu, 20 Sep 2018 10:44:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACA112CCC1 for ; Thu, 20 Sep 2018 10:44:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0E3C2CD49; Thu, 20 Sep 2018 10:44:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2A7882CCC1 for ; Thu, 20 Sep 2018 10:44:04 +0000 (UTC) Received: from localhost ([::1]:49401 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wRH-0004Xo-Dy for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:44:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33201) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHO-0003AQ-C7 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHJ-0006aw-EJ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:33:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39446) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHJ-0006aD-57; Thu, 20 Sep 2018 06:33:45 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6C56FCA36D; Thu, 20 Sep 2018 10:33:44 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 055333091330; Thu, 20 Sep 2018 10:33:40 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:32 +0200 Message-Id: <20180920103243.28474-12-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Sep 2018 10:33:44 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 11/22] memory-device: complete factoring out pre_plug handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP With all required memory device class functions in place, we can factor out pre_plug handling of memory devices. Take proper care of errors. We still have to carry along legacy_align required for pc compatibility handling. We will factor out tracing of the address separately in a follow-up patch. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 32 +++++++++++++++++++++++++++++--- hw/mem/pc-dimm.c | 15 +++------------ include/hw/mem/memory-device.h | 5 ++--- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 1ab28e42cf..ec20c8a2bc 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -94,9 +94,10 @@ static void memory_device_check_addable(MachineState *ms, uint64_t size, } -uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, - uint64_t align, uint64_t size, - Error **errp) +static uint64_t memory_device_get_free_addr(MachineState *ms, + const uint64_t *hint, + uint64_t align, uint64_t size, + Error **errp) { uint64_t address_space_start, address_space_end; GSList *list = NULL, *item; @@ -249,6 +250,31 @@ uint64_t get_plugged_memory_size(void) return size; } +void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, + const uint64_t *legacy_align, Error **errp) +{ + const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + Error *local_err = NULL; + uint64_t addr, align; + MemoryRegion *mr; + + mr = mdc->get_memory_region(md, &local_err); + if (local_err) { + goto out; + } + + align = legacy_align ? *legacy_align : memory_region_get_alignment(mr); + addr = mdc->get_addr(md); + addr = memory_device_get_free_addr(ms, !addr ? NULL : &addr, align, + memory_region_size(mr), &local_err); + if (local_err) { + goto out; + } + mdc->set_addr(md, addr, &local_err); +out: + error_propagate(errp, local_err); +} + void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr) { diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 3474b810ef..39dbb69f61 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -32,10 +32,8 @@ static int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp); void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, const uint64_t *legacy_align, Error **errp) { - MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); Error *local_err = NULL; - MemoryRegion *mr; - uint64_t addr, align; + uint64_t addr; int slot; slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, @@ -48,22 +46,15 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, object_property_set_int(OBJECT(dev), slot, PC_DIMM_SLOT_PROP, &error_abort); trace_mhp_pc_dimm_assigned_slot(slot); - mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &local_err); + memory_device_pre_plug(MEMORY_DEVICE(dev), machine, legacy_align, + &local_err); if (local_err) { goto out; } - align = legacy_align ? *legacy_align : memory_region_get_alignment(mr); addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, &error_abort); - addr = memory_device_get_free_addr(machine, !addr ? NULL : &addr, align, - memory_region_size(mr), &local_err); - if (local_err) { - goto out; - } trace_mhp_pc_dimm_assigned_address(addr); - object_property_set_uint(OBJECT(dev), addr, PC_DIMM_ADDR_PROP, - &error_abort); out: error_propagate(errp, local_err); } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index b2fd26c262..2bb8c604b4 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -58,9 +58,8 @@ typedef struct MemoryDeviceClass { MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); -uint64_t memory_device_get_free_addr(MachineState *ms, const uint64_t *hint, - uint64_t align, uint64_t size, - Error **errp); +void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, + const uint64_t *legacy_align, Error **errp); void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, uint64_t addr); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); From patchwork Thu Sep 20 10:32:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0428714BD for ; Thu, 20 Sep 2018 10:47:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E50632CD7E for ; Thu, 20 Sep 2018 10:47:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D82BC2CD8E; Thu, 20 Sep 2018 10:47:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E1172CD7E for ; Thu, 20 Sep 2018 10:47:58 +0000 (UTC) Received: from localhost ([::1]:49428 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wV3-0008J4-EV for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:47:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHZ-0003L7-Be for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHU-0006mw-Aq for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54082) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHS-0006j7-BC; Thu, 20 Sep 2018 06:33:56 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 87CA130024D8; Thu, 20 Sep 2018 10:33:53 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4825309137F; Thu, 20 Sep 2018 10:33:44 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:33 +0200 Message-Id: <20180920103243.28474-13-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 20 Sep 2018 10:33:53 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 12/22] memory-device: complete factoring out plug handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the new memory device functions in place, we can factor out plugging of memory devices completely. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 10 +++++++--- hw/mem/pc-dimm.c | 8 +------- include/hw/mem/memory-device.h | 3 +-- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index ec20c8a2bc..34e92148ec 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -275,10 +275,14 @@ out: error_propagate(errp, local_err); } -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr) +void memory_device_plug(MemoryDeviceState *md, MachineState *ms) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + const uint64_t addr = mdc->get_addr(md); + MemoryRegion *mr; + + /* we expect a previous call to memory_device_pre_plug() */ + mr = mdc->get_memory_region(md, &error_abort); g_assert(ms->device_memory); memory_region_add_subregion(&ms->device_memory->mr, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 39dbb69f61..db8f71c672 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -63,16 +63,10 @@ void pc_dimm_plug(DeviceState *dev, MachineState *machine, Error **errp) { PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, &error_abort); - MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort); - uint64_t addr; - - addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, - &error_abort); - memory_device_plug_region(machine, mr, addr); + memory_device_plug(MEMORY_DEVICE(dev), machine); vmstate_register_ram(vmstate_mr, dev); } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 2bb8c604b4..5ba36f98fb 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -60,8 +60,7 @@ MemoryDeviceInfoList *qmp_memory_device_list(void); uint64_t get_plugged_memory_size(void); void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, const uint64_t *legacy_align, Error **errp); -void memory_device_plug_region(MachineState *ms, MemoryRegion *mr, - uint64_t addr); +void memory_device_plug(MemoryDeviceState *md, MachineState *ms); void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp); From patchwork Thu Sep 20 10:32:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8781014BD for ; Thu, 20 Sep 2018 10:47:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 779FE2CD7D for ; Thu, 20 Sep 2018 10:47:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B53F2CD84; Thu, 20 Sep 2018 10:47:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 158612CD7D for ; Thu, 20 Sep 2018 10:47:03 +0000 (UTC) Received: from localhost ([::1]:49420 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wUA-0005pc-Bc for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:47:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHZ-0003L8-Bn for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHW-0006p4-Lu for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHW-0006o3-DE; Thu, 20 Sep 2018 06:33:58 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 43CB9C057FAB; Thu, 20 Sep 2018 10:33:57 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEE4B3091330; Thu, 20 Sep 2018 10:33:53 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:34 +0200 Message-Id: <20180920103243.28474-14-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 20 Sep 2018 10:33:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 13/22] memory-device: complete factoring out unplug handling X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP With the new memory device functions in place, we can factor out unplugging of memory devices completely. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 8 ++++++-- hw/mem/pc-dimm.c | 4 +--- include/hw/mem/memory-device.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 34e92148ec..3e5a3a7951 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -289,9 +289,13 @@ void memory_device_plug(MemoryDeviceState *md, MachineState *ms) addr - ms->device_memory->base, mr); } -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr) +void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) { - /* we expect a previous call to memory_device_get_free_addr() */ + const MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(md); + MemoryRegion *mr; + + /* we expect a previous call to memory_device_pre_plug() */ + mr = mdc->get_memory_region(md, &error_abort); g_assert(ms->device_memory); memory_region_del_subregion(&ms->device_memory->mr, mr); diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index db8f71c672..915908b104 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -74,12 +74,10 @@ void pc_dimm_unplug(DeviceState *dev, MachineState *machine) { PCDIMMDevice *dimm = PC_DIMM(dev); PCDIMMDeviceClass *ddc = PC_DIMM_GET_CLASS(dimm); - MemoryDeviceClass *mdc = MEMORY_DEVICE_GET_CLASS(dev); MemoryRegion *vmstate_mr = ddc->get_vmstate_memory_region(dimm, &error_abort); - MemoryRegion *mr = mdc->get_memory_region(MEMORY_DEVICE(dev), &error_abort); - memory_device_unplug_region(machine, mr); + memory_device_unplug(MEMORY_DEVICE(dev), machine); vmstate_unregister_ram(vmstate_mr, dev); } diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index 5ba36f98fb..fd0b43c224 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -61,7 +61,7 @@ uint64_t get_plugged_memory_size(void); void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, const uint64_t *legacy_align, Error **errp); void memory_device_plug(MemoryDeviceState *md, MachineState *ms); -void memory_device_unplug_region(MachineState *ms, MemoryRegion *mr); +void memory_device_unplug(MemoryDeviceState *md, MachineState *ms); uint64_t memory_device_get_region_size(const MemoryDeviceState *md, Error **errp); From patchwork Thu Sep 20 10:32:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 968A7112B for ; Thu, 20 Sep 2018 10:43:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 862CD2CCC1 for ; Thu, 20 Sep 2018 10:43:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A5C32CD49; Thu, 20 Sep 2018 10:43:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 038612CCC1 for ; Thu, 20 Sep 2018 10:43:52 +0000 (UTC) Received: from localhost ([::1]:49399 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wR5-00043V-9b for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:43:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33326) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHa-0003Mb-UE for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHa-0006tP-3e for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38306) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHZ-0006rK-Mf; Thu, 20 Sep 2018 06:34:01 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EAFA130001D5; Thu, 20 Sep 2018 10:34:00 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 88B9E309137F; Thu, 20 Sep 2018 10:33:57 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:35 +0200 Message-Id: <20180920103243.28474-15-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 20 Sep 2018 10:34:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 14/22] memory-device: trace when pre_assigning/assigning/unassigning addresses X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Let's trace the address when pre_pluggin/plugging/unplugging a memory device. Trace it when pre_plugging as well as when plugging, so we really know when a specific address is actually used. Signed-off-by: David Hildenbrand Reviewed-by: David Gibson Reviewed-by: Igor Mammedov --- hw/mem/memory-device.c | 6 ++++++ hw/mem/pc-dimm.c | 8 -------- hw/mem/trace-events | 5 ++++- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 3e5a3a7951..534bd38313 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -17,6 +17,7 @@ #include "qemu/range.h" #include "hw/virtio/vhost.h" #include "sysemu/kvm.h" +#include "trace.h" static gint memory_device_addr_sort(gconstpointer a, gconstpointer b) { @@ -271,6 +272,9 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, goto out; } mdc->set_addr(md, addr, &local_err); + if (!local_err) { + trace_memory_device_pre_assign_address(addr); + } out: error_propagate(errp, local_err); } @@ -287,6 +291,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineState *ms) memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); + trace_memory_device_assign_address(addr); } void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) @@ -299,6 +304,7 @@ void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) g_assert(ms->device_memory); memory_region_del_subregion(&ms->device_memory->mr, mr); + trace_memory_device_unassign_address(mdc->get_addr(md)); } uint64_t memory_device_get_region_size(const MemoryDeviceState *md, diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c index 915908b104..6c560304a1 100644 --- a/hw/mem/pc-dimm.c +++ b/hw/mem/pc-dimm.c @@ -33,7 +33,6 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, const uint64_t *legacy_align, Error **errp) { Error *local_err = NULL; - uint64_t addr; int slot; slot = object_property_get_int(OBJECT(dev), PC_DIMM_SLOT_PROP, @@ -48,13 +47,6 @@ void pc_dimm_pre_plug(DeviceState *dev, MachineState *machine, memory_device_pre_plug(MEMORY_DEVICE(dev), machine, legacy_align, &local_err); - if (local_err) { - goto out; - } - - addr = object_property_get_uint(OBJECT(dev), PC_DIMM_ADDR_PROP, - &error_abort); - trace_mhp_pc_dimm_assigned_address(addr); out: error_propagate(errp, local_err); } diff --git a/hw/mem/trace-events b/hw/mem/trace-events index e150dcc497..b40482077e 100644 --- a/hw/mem/trace-events +++ b/hw/mem/trace-events @@ -2,4 +2,7 @@ # hw/mem/pc-dimm.c mhp_pc_dimm_assigned_slot(int slot) "%d" -mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64 +# hw/mem/memory-device.c +memory_device_pre_assign_address(uint64_t addr) "0x%"PRIx64 +memory_device_assign_address(uint64_t addr) "0x%"PRIx64 +memory_device_unassign_address(uint64_t addr) "0x%"PRIx64 From patchwork Thu Sep 20 10:32:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 127361508 for ; Thu, 20 Sep 2018 10:50:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C882C9BB for ; Thu, 20 Sep 2018 10:50:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E827D2CDC1; Thu, 20 Sep 2018 10:50:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 939AE2C9BB for ; Thu, 20 Sep 2018 10:50:28 +0000 (UTC) Received: from localhost ([::1]:49445 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wXT-0001Zm-TL for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:50:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHp-0003XI-8T for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHo-00073T-Gx for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHo-000737-8r; Thu, 20 Sep 2018 06:34:16 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D9FBA08EE; Thu, 20 Sep 2018 10:34:15 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41DFF309137F; Thu, 20 Sep 2018 10:34:01 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:36 +0200 Message-Id: <20180920103243.28474-16-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 20 Sep 2018 10:34:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 15/22] hw/acpi-build: only indicate nvdimm and pc-dimm X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Once we have other memory devices that are not ACPI devices (e.g. virtio based), we cannot indicate them via ACPI. So let's skip these devices. Signed-off-by: David Hildenbrand --- hw/i386/acpi-build.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index e1ee8ae9e0..2278522b87 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -2266,7 +2266,6 @@ static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t base, for (cur = base, info = info_list; cur < end; cur += size, info = info->next) { - numamem = acpi_data_push(table_data, sizeof *numamem); if (!info) { /* @@ -2278,19 +2277,30 @@ static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t base, * Memory devices may override proximity set by this entry, * providing _PXM method if necessary. */ + numamem = acpi_data_push(table_data, sizeof *numamem); build_srat_memory(numamem, end - 1, 1, default_node, MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED); break; } mi = info->value; + if (mi->type != MEMORY_DEVICE_INFO_KIND_DIMM && + mi->type != MEMORY_DEVICE_INFO_KIND_NVDIMM) { + /* + * Don't indicate memory devices that are not proper ACPI devices, + * merge them with the empty ranges. + */ + size = 0; + continue; + } + is_nvdimm = (mi->type == MEMORY_DEVICE_INFO_KIND_NVDIMM); di = !is_nvdimm ? mi->u.dimm.data : mi->u.nvdimm.data; if (cur < di->addr) { + numamem = acpi_data_push(table_data, sizeof *numamem); build_srat_memory(numamem, cur, di->addr - cur, default_node, MEM_AFFINITY_HOTPLUGGABLE | MEM_AFFINITY_ENABLED); - numamem = acpi_data_push(table_data, sizeof *numamem); } size = di->size; @@ -2303,6 +2313,7 @@ static void build_srat_hotpluggable_memory(GArray *table_data, uint64_t base, flags |= MEM_AFFINITY_NON_VOLATILE; } + numamem = acpi_data_push(table_data, sizeof *numamem); build_srat_memory(numamem, di->addr, size, di->node, flags); } From patchwork Thu Sep 20 10:32:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B780214BD for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A784B2CD7D for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A4382CD84; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D9442CD7D for ; Thu, 20 Sep 2018 10:47:02 +0000 (UTC) Received: from localhost ([::1]:49425 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wU9-0006tS-5V for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:47:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33454) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wHx-0003fI-8p for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wHw-00079H-DE for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37488) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wHw-00078q-3h; Thu, 20 Sep 2018 06:34:24 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 69C37308404D; Thu, 20 Sep 2018 10:34:23 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74DE53091327; Thu, 20 Sep 2018 10:34:15 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:37 +0200 Message-Id: <20180920103243.28474-17-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 20 Sep 2018 10:34:23 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 16/22] memory-device: add optional function get_device_id() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When reporting the id of virtio-based memory devices, we always have to take the one of the proxy device (parent), not the one of the memory device directly. Let's generalize this by allowing memory devices to specify an optional "get_device_id" function. This id can then be used to report errors to the user from memory-device.c code, without having to special case e.g. virtio devices. While at it, properly treat id == NULL and report "(unnamed)" instead. Details: When the user creates a virtio device (e.g. virtio-balloon-pci), two devices are actually created. 1. Virtio proxy device (e.g. TYPE_VIRTIO_BALLOON_PCI) 2. The "real" virtio device (e.g. TYPE_VIRTIO_BALLOON). 1. aliases all properties of 2, so 2. can be properly configured using 1. 1. gets the device ID set specified by the user. 2. gets no ID set. If we want to make 2. a MemoryDevice but report errors/information to the user, we always have to report the id of 1. (because that's the device the user instantiated and configured). Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/mem/memory-device.c | 7 +++++-- include/hw/mem/memory-device.h | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 534bd38313..92878fc327 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -174,8 +174,11 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, if (ranges_overlap(md_addr, md_size, new_addr, size)) { if (hint) { - const DeviceState *d = DEVICE(md); - error_setg(errp, "address range conflicts with '%s'", d->id); + const char *id = mdc->get_device_id ? mdc->get_device_id(md) : + DEVICE(md)->id; + + error_setg(errp, "address range conflicts with '%s'", + id ? id : "(unnamed)"); goto out; } new_addr = QEMU_ALIGN_UP(md_addr + md_size, align); diff --git a/include/hw/mem/memory-device.h b/include/hw/mem/memory-device.h index fd0b43c224..66143cffc6 100644 --- a/include/hw/mem/memory-device.h +++ b/include/hw/mem/memory-device.h @@ -42,6 +42,9 @@ typedef struct MemoryDeviceState { * of multiple successive memory regions, a covering memory region is to * be used. Scattered memory regions are not supported for single devices. * @fill_device_info: Translate current @md state into #MemoryDeviceInfo. + * @get_device_id: Optional. Allows memory devices behind proxy devices + * (e.g. virtio based) to report the id of the proxy device to the user + * instead of the (empty) id of the memory device. */ typedef struct MemoryDeviceClass { /* private */ @@ -54,6 +57,7 @@ typedef struct MemoryDeviceClass { MemoryRegion *(*get_memory_region)(MemoryDeviceState *md, Error **errp); void (*fill_device_info)(const MemoryDeviceState *md, MemoryDeviceInfo *info); + const char *(*get_device_id)(const MemoryDeviceState *md); } MemoryDeviceClass; MemoryDeviceInfoList *qmp_memory_device_list(void); From patchwork Thu Sep 20 10:32:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B1E414BD for ; Thu, 20 Sep 2018 10:53:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2847928C5C for ; Thu, 20 Sep 2018 10:53:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C40528D58; Thu, 20 Sep 2018 10:53:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 536F128C5C for ; Thu, 20 Sep 2018 10:53:02 +0000 (UTC) Received: from localhost ([::1]:49457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wZx-0004BG-BW for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:53:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wI2-0003mG-KD for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wI1-0007CO-4i for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wI0-0007C2-SW; Thu, 20 Sep 2018 06:34:29 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2292D2DACF6; Thu, 20 Sep 2018 10:34:28 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6B3A3091327; Thu, 20 Sep 2018 10:34:23 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:38 +0200 Message-Id: <20180920103243.28474-18-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 20 Sep 2018 10:34:28 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 17/22] virtio-pmem: prototype X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pankaj Gupta This is the current protoype of virtio-pmem. Support will require machine changes for the architectures that will support it, so it will not yet be compiled. Signed-off-by: Pankaj Gupta [ MemoryDevice/MemoryRegion changes, cleanups, addr property "memaddr", split up patches ] Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/virtio/Makefile.objs | 1 + hw/virtio/virtio-pmem.c | 224 ++++++++++++++++++++ include/hw/virtio/virtio-pmem.h | 40 ++++ include/standard-headers/linux/virtio_ids.h | 1 + qapi/misc.json | 26 ++- 5 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/virtio-pmem.c create mode 100644 include/hw/virtio/virtio-pmem.h diff --git a/hw/virtio/Makefile.objs b/hw/virtio/Makefile.objs index 1b2799cfd8..75cdd90264 100644 --- a/hw/virtio/Makefile.objs +++ b/hw/virtio/Makefile.objs @@ -5,6 +5,7 @@ obj-y += virtio.o common-obj-$(CONFIG_VIRTIO_RNG) += virtio-rng.o common-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o common-obj-$(CONFIG_VIRTIO_MMIO) += virtio-mmio.o +obj-$(call land,$(CONFIG_VIRTIO_PMEM),$(CONFIG_LINUX)) += virtio-pmem.o obj-$(CONFIG_VIRTIO_BALLOON) += virtio-balloon.o obj-$(CONFIG_VIRTIO_CRYPTO) += virtio-crypto.o obj-$(call land,$(CONFIG_VIRTIO_CRYPTO),$(CONFIG_VIRTIO_PCI)) += virtio-crypto-pci.o diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c new file mode 100644 index 0000000000..0f8b509f0f --- /dev/null +++ b/hw/virtio/virtio-pmem.c @@ -0,0 +1,224 @@ +/* + * Virtio pmem device + * + * Copyright (C) 2018 Red Hat, Inc. + * Copyright (C) 2018 Pankaj Gupta + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "qemu/error-report.h" +#include "hw/virtio/virtio-access.h" +#include "hw/virtio/virtio-pmem.h" +#include "hw/mem/memory-device.h" +#include "block/aio.h" +#include "block/thread-pool.h" + +typedef struct VirtIOPMEMresp { + int ret; +} VirtIOPMEMResp; + +typedef struct VirtIODeviceRequest { + VirtQueueElement elem; + int fd; + VirtIOPMEM *pmem; + VirtIOPMEMResp resp; +} VirtIODeviceRequest; + +static int worker_cb(void *opaque) +{ + VirtIODeviceRequest *req = opaque; + int err = 0; + + printf("\n performing flush ..."); + /* flush raw backing image */ + err = fsync(req->fd); + printf("\n performed flush ...:errcode::%d", err); + if (err != 0) { + err = EIO; + } + req->resp.ret = err; + + return 0; +} + +static void done_cb(void *opaque, int ret) +{ + VirtIODeviceRequest *req = opaque; + int len = iov_from_buf(req->elem.in_sg, req->elem.in_num, 0, + &req->resp, sizeof(VirtIOPMEMResp)); + + /* Callbacks are serialized, so no need to use atomic ops. */ + virtqueue_push(req->pmem->rq_vq, &req->elem, len); + virtio_notify((VirtIODevice *)req->pmem, req->pmem->rq_vq); + g_free(req); +} + +static void virtio_pmem_flush(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIODeviceRequest *req; + VirtIOPMEM *pmem = VIRTIO_PMEM(vdev); + HostMemoryBackend *backend = MEMORY_BACKEND(pmem->memdev); + ThreadPool *pool = aio_get_thread_pool(qemu_get_aio_context()); + + req = virtqueue_pop(vq, sizeof(VirtIODeviceRequest)); + if (!req) { + virtio_error(vdev, "virtio-pmem missing request data"); + return; + } + + if (req->elem.out_num < 1 || req->elem.in_num < 1) { + virtio_error(vdev, "virtio-pmem request not proper"); + g_free(req); + return; + } + req->fd = memory_region_get_fd(&backend->mr); + req->pmem = pmem; + thread_pool_submit_aio(pool, worker_cb, req, done_cb, req); +} + +static void virtio_pmem_get_config(VirtIODevice *vdev, uint8_t *config) +{ + VirtIOPMEM *pmem = VIRTIO_PMEM(vdev); + struct virtio_pmem_config *pmemcfg = (struct virtio_pmem_config *) config; + + virtio_stq_p(vdev, &pmemcfg->start, pmem->start); + virtio_stq_p(vdev, &pmemcfg->size, memory_region_size(&pmem->memdev->mr)); +} + +static uint64_t virtio_pmem_get_features(VirtIODevice *vdev, uint64_t features, + Error **errp) +{ + return features; +} + +static void virtio_pmem_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev = VIRTIO_DEVICE(dev); + VirtIOPMEM *pmem = VIRTIO_PMEM(dev); + + if (!pmem->memdev) { + error_setg(errp, "virtio-pmem memdev not set"); + return; + } else if (host_memory_backend_is_mapped(pmem->memdev)) { + char *path = object_get_canonical_path_component(OBJECT(pmem->memdev)); + error_setg(errp, "can't use already busy memdev: %s", path); + g_free(path); + return; + } + + host_memory_backend_set_mapped(pmem->memdev, true); + virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, + sizeof(struct virtio_pmem_config)); + pmem->rq_vq = virtio_add_queue(vdev, 128, virtio_pmem_flush); +} + +static const char *virtio_pmem_md_get_device_id(const MemoryDeviceState *md) +{ + Object *obj = OBJECT(md); + + /* always return the ID of the proxy device the user configured */ + if (obj->parent && object_dynamic_cast(obj->parent, TYPE_DEVICE)) { + const DeviceState *parent_dev = DEVICE(obj->parent); + + return parent_dev->id; + } + return NULL; +} + +static void virtio_pmem_md_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioPMemDeviceInfo *vi = g_new0(VirtioPMemDeviceInfo, 1); + VirtIOPMEM *pmem = VIRTIO_PMEM(md); + const char *id = virtio_pmem_md_get_device_id(md); + + if (id) { + vi->has_id = true; + vi->id = g_strdup(id); + } + + vi->memaddr = pmem->start; + vi->size = pmem->memdev ? memory_region_size(&pmem->memdev->mr) : 0; + vi->memdev = object_get_canonical_path(OBJECT(pmem->memdev)); + + info->u.virtio_pmem.data = vi; + info->type = MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM; +} + +static uint64_t virtio_pmem_md_get_addr(const MemoryDeviceState *md) +{ + VirtIOPMEM *pmem = VIRTIO_PMEM(md); + + return pmem->start; +} + +static void virtio_pmem_md_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, VIRTIO_PMEM_ADDR_PROP, errp); +} + +static MemoryRegion *virtio_pmem_md_get_memory_region(MemoryDeviceState *md, + Error **errp) +{ + VirtIOPMEM *pmem = VIRTIO_PMEM(md); + + if (!pmem->memdev) { + error_setg(errp, "'%s' property must be set", VIRTIO_PMEM_MEMDEV_PROP); + return NULL; + } + + return &pmem->memdev->mr; +} + +static Property virtio_pmem_properties[] = { + DEFINE_PROP_UINT64(VIRTIO_PMEM_ADDR_PROP, VirtIOPMEM, start, 0), + DEFINE_PROP_LINK(VIRTIO_PMEM_MEMDEV_PROP, VirtIOPMEM, memdev, + TYPE_MEMORY_BACKEND, HostMemoryBackend *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_pmem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc = MEMORY_DEVICE_CLASS(klass); + + dc->props = virtio_pmem_properties; + + vdc->realize = virtio_pmem_realize; + vdc->get_config = virtio_pmem_get_config; + vdc->get_features = virtio_pmem_get_features; + + mdc->get_addr = virtio_pmem_md_get_addr; + mdc->set_addr = virtio_pmem_md_set_addr; + /* for virtio-pmem plugged_size == region_size */ + mdc->get_plugged_size = memory_device_get_region_size; + mdc->get_memory_region = virtio_pmem_md_get_memory_region; + mdc->fill_device_info = virtio_pmem_md_fill_device_info; + mdc->get_device_id = virtio_pmem_md_get_device_id; +} + +static TypeInfo virtio_pmem_info = { + .name = TYPE_VIRTIO_PMEM, + .parent = TYPE_VIRTIO_DEVICE, + .class_init = virtio_pmem_class_init, + .instance_size = sizeof(VirtIOPMEM), + .interfaces = (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_pmem_info); +} + +type_init(virtio_register_types) diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pmem.h new file mode 100644 index 0000000000..11e549e0f1 --- /dev/null +++ b/include/hw/virtio/virtio-pmem.h @@ -0,0 +1,40 @@ +/* + * Virtio pmem Device + * + * Copyright Red Hat, Inc. 2018 + * Copyright Pankaj Gupta + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef QEMU_VIRTIO_PMEM_H +#define QEMU_VIRTIO_PMEM_H + +#include "hw/virtio/virtio.h" +#include "sysemu/hostmem.h" +#include "standard-headers/linux/virtio_ids.h" + +#define TYPE_VIRTIO_PMEM "virtio-pmem" + +#define VIRTIO_PMEM(obj) \ + OBJECT_CHECK(VirtIOPMEM, (obj), TYPE_VIRTIO_PMEM) + +#define VIRTIO_PMEM_ADDR_PROP "memaddr" +#define VIRTIO_PMEM_MEMDEV_PROP "memdev" + +/* VirtIOPMEM device structure */ +typedef struct VirtIOPMEM { + VirtIODevice parent_obj; + + VirtQueue *rq_vq; + uint64_t start; + HostMemoryBackend *memdev; +} VirtIOPMEM; + +struct virtio_pmem_config { + uint64_t start; + uint64_t size; +}; +#endif diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard-headers/linux/virtio_ids.h index 6d5c3b2d4f..346389565a 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -43,5 +43,6 @@ #define VIRTIO_ID_INPUT 18 /* virtio input */ #define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */ #define VIRTIO_ID_CRYPTO 20 /* virtio crypto */ +#define VIRTIO_ID_PMEM 25 /* virtio pmem */ #endif /* _LINUX_VIRTIO_IDS_H */ diff --git a/qapi/misc.json b/qapi/misc.json index 7c36de0464..cadbca26ac 100644 --- a/qapi/misc.json +++ b/qapi/misc.json @@ -2907,6 +2907,29 @@ } } +## +# @VirtioPMemDeviceInfo: +# +# VirtioPMem state information +# +# @id: device's ID +# +# @memaddr: physical address in memory, where device is mapped +# +# @size: size of memory that the device provides +# +# @memdev: memory backend linked with device +# +# Since: 3.1 +## +{ 'struct': 'VirtioPMemDeviceInfo', + 'data': { '*id': 'str', + 'memaddr': 'size', + 'size': 'size', + 'memdev': 'str' + } +} + ## # @MemoryDeviceInfo: # @@ -2916,7 +2939,8 @@ ## { 'union': 'MemoryDeviceInfo', 'data': { 'dimm': 'PCDIMMDeviceInfo', - 'nvdimm': 'PCDIMMDeviceInfo' + 'nvdimm': 'PCDIMMDeviceInfo', + 'virtio-pmem': 'VirtioPMemDeviceInfo' } } From patchwork Thu Sep 20 10:32:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607419 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4DB714BD for ; Thu, 20 Sep 2018 10:54:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EE562CE25 for ; Thu, 20 Sep 2018 10:54:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 810942CE39; Thu, 20 Sep 2018 10:54:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 046CF2CE25 for ; Thu, 20 Sep 2018 10:54:49 +0000 (UTC) Received: from localhost ([::1]:49463 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wbh-0005IQ-8Z for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:54:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wI8-0003s4-OZ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wI7-0007H5-Db for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wI7-0007Gh-52; Thu, 20 Sep 2018 06:34:35 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5575C80475; Thu, 20 Sep 2018 10:34:34 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F8DD3091330; Thu, 20 Sep 2018 10:34:28 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:39 +0200 Message-Id: <20180920103243.28474-19-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 20 Sep 2018 10:34:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 18/22] virtio-pci: proxy for virtio-pmem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pankaj Gupta We need a proxy device for virtio-pmem. Signed-off-by: Pankaj Gupta [ split up patches ] Signed-off-by: David Hildenbrand Reviewed-by: David Gibson --- hw/virtio/virtio-pci.c | 41 +++++++++++++++++++++++++++++++++++++++++ hw/virtio/virtio-pci.h | 14 ++++++++++++++ include/hw/pci/pci.h | 1 + 3 files changed, 56 insertions(+) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 3a01fe90f0..dcfcefc1b5 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -2521,6 +2521,46 @@ static const TypeInfo virtio_rng_pci_info = { .class_init = virtio_rng_pci_class_init, }; +/* virtio-pmem-pci */ + +static void virtio_pmem_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp) +{ + VirtIOPMEMPCI *vpmem = VIRTIO_PMEM_PCI(vpci_dev); + DeviceState *vdev = DEVICE(&vpmem->vdev); + + qdev_set_parent_bus(vdev, BUS(&vpci_dev->bus)); + object_property_set_bool(OBJECT(vdev), true, "realized", errp); +} + +static void virtio_pmem_pci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); + PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + k->realize = virtio_pmem_pci_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + pcidev_k->vendor_id = PCI_VENDOR_ID_REDHAT_QUMRANET; + pcidev_k->device_id = PCI_DEVICE_ID_VIRTIO_PMEM; + pcidev_k->revision = VIRTIO_PCI_ABI_VERSION; + pcidev_k->class_id = PCI_CLASS_OTHERS; +} + +static void virtio_pmem_pci_instance_init(Object *obj) +{ + VirtIOPMEMPCI *dev = VIRTIO_PMEM_PCI(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_PMEM); +} + +static const TypeInfo virtio_pmem_pci_info = { + .name = TYPE_VIRTIO_PMEM_PCI, + .parent = TYPE_VIRTIO_PCI, + .instance_size = sizeof(VirtIOPMEMPCI), + .instance_init = virtio_pmem_pci_instance_init, + .class_init = virtio_pmem_pci_class_init, +}; + /* virtio-input-pci */ static Property virtio_input_pci_properties[] = { @@ -2714,6 +2754,7 @@ static void virtio_pci_register_types(void) type_register_static(&virtio_balloon_pci_info); type_register_static(&virtio_serial_pci_info); type_register_static(&virtio_net_pci_info); + type_register_static(&virtio_pmem_pci_info); #ifdef CONFIG_VHOST_SCSI type_register_static(&vhost_scsi_pci_info); #endif diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h index 813082b0d7..fe74fcad3f 100644 --- a/hw/virtio/virtio-pci.h +++ b/hw/virtio/virtio-pci.h @@ -19,6 +19,7 @@ #include "hw/virtio/virtio-blk.h" #include "hw/virtio/virtio-net.h" #include "hw/virtio/virtio-rng.h" +#include "hw/virtio/virtio-pmem.h" #include "hw/virtio/virtio-serial.h" #include "hw/virtio/virtio-scsi.h" #include "hw/virtio/virtio-balloon.h" @@ -57,6 +58,7 @@ typedef struct VirtIOInputHostPCI VirtIOInputHostPCI; typedef struct VirtIOGPUPCI VirtIOGPUPCI; typedef struct VHostVSockPCI VHostVSockPCI; typedef struct VirtIOCryptoPCI VirtIOCryptoPCI; +typedef struct VirtIOPMEMPCI VirtIOPMEMPCI; /* virtio-pci-bus */ @@ -274,6 +276,18 @@ struct VirtIOBlkPCI { VirtIOBlock vdev; }; +/* + * virtio-pmem-pci: This extends VirtioPCIProxy. + */ +#define TYPE_VIRTIO_PMEM_PCI "virtio-pmem-pci" +#define VIRTIO_PMEM_PCI(obj) \ + OBJECT_CHECK(VirtIOPMEMPCI, (obj), TYPE_VIRTIO_PMEM_PCI) + +struct VirtIOPMEMPCI { + VirtIOPCIProxy parent_obj; + VirtIOPMEM vdev; +}; + /* * virtio-balloon-pci: This extends VirtioPCIProxy. */ diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 990d6fcbde..28829b6437 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -85,6 +85,7 @@ extern bool pci_available; #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 #define PCI_DEVICE_ID_VIRTIO_VSOCK 0x1012 +#define PCI_DEVICE_ID_VIRTIO_PMEM 0x1013 #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 From patchwork Thu Sep 20 10:32:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7F6614BD for ; Thu, 20 Sep 2018 10:50:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D71C32C9BB for ; Thu, 20 Sep 2018 10:50:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8C892CDC1; Thu, 20 Sep 2018 10:50:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 632552C9BB for ; Thu, 20 Sep 2018 10:50:11 +0000 (UTC) Received: from localhost ([::1]:49438 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wXC-0001JE-8c for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:50:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33614) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIC-0003vQ-2R for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wIB-0007KH-7P for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39244) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wIB-0007Js-0l; Thu, 20 Sep 2018 06:34:39 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D8B130BD1B5; Thu, 20 Sep 2018 10:34:38 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4B643091327; Thu, 20 Sep 2018 10:34:34 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:40 +0200 Message-Id: <20180920103243.28474-20-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 20 Sep 2018 10:34:38 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 19/22] hmp: handle virtio-pmem when printing memory device infos X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Print the memory device info just like for PCDIMM/NVDIMM. Signed-off-by: David Hildenbrand --- hmp.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/hmp.c b/hmp.c index 4975fa56b0..a592a4af9d 100644 --- a/hmp.c +++ b/hmp.c @@ -2529,27 +2529,21 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err); MemoryDeviceInfoList *info; MemoryDeviceInfo *value; - PCDIMMDeviceInfo *di; + VirtioPMemDeviceInfo *vpi; for (info = info_list; info; info = info->next) { + PCDIMMDeviceInfo *di = NULL; + value = info->value; if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: di = value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - di = value->u.nvdimm.data; - break; - - default: - di = NULL; - break; - } - - if (di) { + if (!di) { + di = value->u.nvdimm.data; + } monitor_printf(mon, "Memory device [%s]: \"%s\"\n", MemoryDeviceInfoKind_str(value->type), di->id ? di->id : ""); @@ -2562,6 +2556,17 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict) di->hotplugged ? "true" : "false"); monitor_printf(mon, " hotpluggable: %s\n", di->hotpluggable ? "true" : "false"); + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi = value->u.virtio_pmem.data; + monitor_printf(mon, "Memory device [%s]: \"%s\"\n", + MemoryDeviceInfoKind_str(value->type), + vpi->id ? vpi->id : ""); + monitor_printf(mon, " memaddr: 0x%" PRIx64 "\n", vpi->memaddr); + monitor_printf(mon, " size: %" PRIu64 "\n", vpi->size); + monitor_printf(mon, " memdev: %s\n", vpi->memdev); + default: + break; } } } From patchwork Thu Sep 20 10:32:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A739614BD for ; Thu, 20 Sep 2018 10:41:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94B792CD09 for ; Thu, 20 Sep 2018 10:41:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87D5D2CD3C; Thu, 20 Sep 2018 10:41:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3CE562CD09 for ; Thu, 20 Sep 2018 10:41:58 +0000 (UTC) Received: from localhost ([::1]:49387 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wP3-0001tb-Im for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:41:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33660) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wII-0003yf-QH for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wII-0007P1-2w for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6813) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wIH-0007Ni-SN; Thu, 20 Sep 2018 06:34:45 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 134182E9595; Thu, 20 Sep 2018 10:34:45 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 697BD3091327; Thu, 20 Sep 2018 10:34:38 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:41 +0200 Message-Id: <20180920103243.28474-21-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 20 Sep 2018 10:34:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 20/22] numa: handle virtio-pmem in NUMA stats X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Account the memory to node 0 for now. Once (if ever) virtio-pmem supports NUMA, we can account it to the right node. Signed-off-by: David Hildenbrand --- numa.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/numa.c b/numa.c index 81542d4ebb..8aa9b21a22 100644 --- a/numa.c +++ b/numa.c @@ -544,30 +544,31 @@ static void numa_stat_memory_devices(NumaNodeMem node_mem[]) { MemoryDeviceInfoList *info_list = qmp_memory_device_list(); MemoryDeviceInfoList *info; - PCDIMMDeviceInfo *pcdimm_info; + VirtioPMemDeviceInfo *vpi; for (info = info_list; info; info = info->next) { MemoryDeviceInfo *value = info->value; + PCDIMMDeviceInfo *pcdimm_info = NULL; if (value) { switch (value->type) { case MEMORY_DEVICE_INFO_KIND_DIMM: pcdimm_info = value->u.dimm.data; - break; - case MEMORY_DEVICE_INFO_KIND_NVDIMM: - pcdimm_info = value->u.nvdimm.data; - break; - - default: - pcdimm_info = NULL; - break; - } - - if (pcdimm_info) { + if (!pcdimm_info) { + pcdimm_info = value->u.nvdimm.data; + } node_mem[pcdimm_info->node].node_mem += pcdimm_info->size; node_mem[pcdimm_info->node].node_plugged_mem += pcdimm_info->size; + break; + case MEMORY_DEVICE_INFO_KIND_VIRTIO_PMEM: + vpi = value->u.virtio_pmem.data; + /* TODO: once we support numa, assign to right node */ + node_mem[0].node_mem += vpi->size; + node_mem[0].node_plugged_mem += vpi->size; + default: + break; } } } From patchwork Thu Sep 20 10:32:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607415 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF9E51508 for ; Thu, 20 Sep 2018 10:51:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEA4B2CDCB for ; Thu, 20 Sep 2018 10:51:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B0E522CDD5; Thu, 20 Sep 2018 10:51:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48B792CDCB for ; Thu, 20 Sep 2018 10:51:29 +0000 (UTC) Received: from localhost ([::1]:49448 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wYS-0002GO-Gs for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:51:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIM-00042O-OJ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wIL-0007TN-OJ for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:18023) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wIL-0007SR-GO; Thu, 20 Sep 2018 06:34:49 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BE0ED3003091; Thu, 20 Sep 2018 10:34:48 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 623AE3091327; Thu, 20 Sep 2018 10:34:45 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:42 +0200 Message-Id: <20180920103243.28474-22-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 20 Sep 2018 10:34:48 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 21/22] virtio-pmem: hotplug support functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP virtio-pmem devices will have to be hotplugged using the machine hotplug handler just like other memory devices. Therefore, all machines that want to support virtio-pmem will have to modify their machine hotplug handler. virtio-pmem devices are realized when their parent proxy device (virtio-pmem-pci) is realized. Therefore, they are attached to a bus without a hotplug handler. This makes things a lot easier, because without a hotplug handler, we can directly get control over the device in the machine hotplug handler (otherwise we would have to overwrite control and pass control to the bus hotplug handler from the machine hotplug handler). As we have to implement support for each machine we want to support, add a safety net ("pre_plugged") that catches if the pre_plug handler was not called - if trying to realize it with a machine that does not support it. Otherwise creating and realizing virtio-pmem-pci along with virtio-pmem would work, however the memory-device part would not properly get hotplugged. Signed-off-by: David Hildenbrand --- hw/virtio/virtio-pmem.c | 34 +++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-pmem.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index 0f8b509f0f..0342e4482b 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -112,6 +112,12 @@ static void virtio_pmem_realize(DeviceState *dev, Error **errp) return; } + /* pre_plug handler wasn't executed (e.g. from machine hotplug handler) */ + if (!pmem->pre_plugged) { + error_setg(errp, "virtio-pmem is not compatible with the machine"); + return; + } + host_memory_backend_set_mapped(pmem->memdev, true); virtio_init(vdev, TYPE_VIRTIO_PMEM, VIRTIO_ID_PMEM, sizeof(struct virtio_pmem_config)); @@ -205,6 +211,34 @@ static void virtio_pmem_class_init(ObjectClass *klass, void *data) mdc->get_device_id = virtio_pmem_md_get_device_id; } +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + /* + * The proxy device (e.g. virtio-pmem-pci) has an hotplug handler and + * will attach the virtio-pmem device to its bus (parent_bus). This + * device will realize the virtio-mem device from its realize function, + * therefore when it is hotplugged itself. The proxy device bus + * therefore has no hotplug handler and we don't have to forward any + * calls. + */ + if (!DEVICE(pmem)->parent_bus || + DEVICE(pmem)->parent_bus->hotplug_handler) { + error_setg(errp, "virtio-pmem is not compatible with the proxy."); + } + memory_device_pre_plug(MEMORY_DEVICE(pmem), ms, NULL, errp); + pmem->pre_plugged = true; +} + +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + memory_device_plug(MEMORY_DEVICE(pmem), ms); +} + +void virtio_pmem_unplug(VirtIOPMEM *pmem, MachineState *ms, Error **errp) +{ + memory_device_unplug(MEMORY_DEVICE(pmem), ms); +} + static TypeInfo virtio_pmem_info = { .name = TYPE_VIRTIO_PMEM, .parent = TYPE_VIRTIO_DEVICE, diff --git a/include/hw/virtio/virtio-pmem.h b/include/hw/virtio/virtio-pmem.h index 11e549e0f1..640051f3b6 100644 --- a/include/hw/virtio/virtio-pmem.h +++ b/include/hw/virtio/virtio-pmem.h @@ -31,10 +31,21 @@ typedef struct VirtIOPMEM { VirtQueue *rq_vq; uint64_t start; HostMemoryBackend *memdev; + + /* + * Safety net to make sure we can catch trying to be realized on a + * machine that is not prepared to properly hotplug virtio-pmem from + * its machine hotplug handler. + */ + bool pre_plugged; } VirtIOPMEM; struct virtio_pmem_config { uint64_t start; uint64_t size; }; + +void virtio_pmem_pre_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); +void virtio_pmem_plug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); +void virtio_pmem_unplug(VirtIOPMEM *pmem, MachineState *ms, Error **errp); #endif From patchwork Thu Sep 20 10:32:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 10607421 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 93B2C157B for ; Thu, 20 Sep 2018 10:56:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77EA72CE9F for ; Thu, 20 Sep 2018 10:56:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68C152CEA8; Thu, 20 Sep 2018 10:56:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 106752CE9F for ; Thu, 20 Sep 2018 10:56:33 +0000 (UTC) Received: from localhost ([::1]:49479 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wdN-0006C8-2H for patchwork-qemu-devel@patchwork.kernel.org; Thu, 20 Sep 2018 06:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33788) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g2wIU-00049i-QK for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:35:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g2wIT-0007YX-U1 for qemu-devel@nongnu.org; Thu, 20 Sep 2018 06:34:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38248) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g2wIT-0007Xw-Lh; Thu, 20 Sep 2018 06:34:57 -0400 Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3395308404D; Thu, 20 Sep 2018 10:34:56 +0000 (UTC) Received: from t460s.redhat.com (ovpn-117-43.ams2.redhat.com [10.36.117.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16CA13091327; Thu, 20 Sep 2018 10:34:48 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Date: Thu, 20 Sep 2018 12:32:43 +0200 Message-Id: <20180920103243.28474-23-david@redhat.com> In-Reply-To: <20180920103243.28474-1-david@redhat.com> References: <20180920103243.28474-1-david@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Thu, 20 Sep 2018 10:34:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 22/22] pc: support for virtio-pmem X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pankaj Gupta , Eduardo Habkost , "Michael S . Tsirkin" , Xiao Guangrong , David Hildenbrand , "Dr . David Alan Gilbert" , Markus Armbruster , Alexander Graf , qemu-ppc@nongnu.org, Paolo Bonzini , Igor Mammedov , Luiz Capitulino , David Gibson , Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Compile virtio-pmem for x86 and properly hotplug virtio-pmem devices (memory-device part) from our pc machine hotplug handler. Signed-off-by: David Hildenbrand --- default-configs/i386-softmmu.mak | 1 + hw/i386/pc.c | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/default-configs/i386-softmmu.mak b/default-configs/i386-softmmu.mak index 4c1637338b..dfb1e6d63a 100644 --- a/default-configs/i386-softmmu.mak +++ b/default-configs/i386-softmmu.mak @@ -51,6 +51,7 @@ CONFIG_APIC=y CONFIG_IOAPIC=y CONFIG_PVPANIC=y CONFIG_MEM_DEVICE=y +CONFIG_VIRTIO_PMEM=y CONFIG_DIMM=y CONFIG_NVDIMM=y CONFIG_ACPI_NVDIMM=y diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 03148450c8..bea043fe23 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -74,6 +74,7 @@ #include "hw/nmi.h" #include "hw/i386/intel_iommu.h" #include "hw/net/ne2000-isa.h" +#include "hw/virtio/virtio-pmem.h" /* debug PC/ISA interrupts */ //#define DEBUG_IRQ @@ -2013,6 +2014,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev, pc_memory_pre_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_pre_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_pre_plug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev), errp); } } @@ -2023,6 +2026,8 @@ static void pc_machine_device_plug_cb(HotplugHandler *hotplug_dev, pc_memory_plug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_plug(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_plug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev), errp); } } @@ -2046,6 +2051,8 @@ static void pc_machine_device_unplug_cb(HotplugHandler *hotplug_dev, pc_memory_unplug(hotplug_dev, dev, errp); } else if (object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { pc_cpu_unplug_cb(hotplug_dev, dev, errp); + } else if (object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { + virtio_pmem_unplug(VIRTIO_PMEM(dev), MACHINE(hotplug_dev), errp); } else { error_setg(errp, "acpi: device unplug for not supported device" " type: %s", object_get_typename(OBJECT(dev))); @@ -2056,7 +2063,8 @@ static HotplugHandler *pc_get_hotpug_handler(MachineState *machine, DeviceState *dev) { if (object_dynamic_cast(OBJECT(dev), TYPE_PC_DIMM) || - object_dynamic_cast(OBJECT(dev), TYPE_CPU)) { + object_dynamic_cast(OBJECT(dev), TYPE_CPU) || + object_dynamic_cast(OBJECT(dev), TYPE_VIRTIO_PMEM)) { return HOTPLUG_HANDLER(machine); }