From patchwork Fri Jun 16 09:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13282385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 218EBEB64DB for ; Fri, 16 Jun 2023 09:30:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243558AbjFPJag (ORCPT ); Fri, 16 Jun 2023 05:30:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344371AbjFPJ3y (ORCPT ); Fri, 16 Jun 2023 05:29:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2EAD230E4 for ; Fri, 16 Jun 2023 02:28:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686907638; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iYAGcIiBozkpSp3T5+K2LJNfVGImLOKVErgdOfZyLGs=; b=dQCuBjqCUBF+hP47RD3MSNix/+pA6nB/FfFs+A97hNE+gAqzfMhFmwTspdnIrOomtdKKE+ fde+9CZqY8QyCtHspG7vI0EGsuZmJVaql+/378yKW77EaQ1oJ5VKgIsKFsMrdRNDXtdpLN RwswEwOU9yxy3SpyqTllBgYihHYDuo0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-314-603ggW9-NtO0DCIu0SPyKQ-1; Fri, 16 Jun 2023 05:27:12 -0400 X-MC-Unique: 603ggW9-NtO0DCIu0SPyKQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5187A810BBA; Fri, 16 Jun 2023 09:27:12 +0000 (UTC) Received: from t480s.fritz.box (unknown [10.39.194.44]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5447C1121314; Fri, 16 Jun 2023 09:27:09 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: David Hildenbrand , Paolo Bonzini , Igor Mammedov , Xiao Guangrong , "Michael S. Tsirkin" , Peter Xu , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Eduardo Habkost , Marcel Apfelbaum , Yanan Wang , Michal Privoznik , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , Gavin Shan , Alex Williamson , kvm@vger.kernel.org Subject: [PATCH v1 01/15] memory-device: Track the required memslots in DeviceMemoryState Date: Fri, 16 Jun 2023 11:26:40 +0200 Message-Id: <20230616092654.175518-2-david@redhat.com> In-Reply-To: <20230616092654.175518-1-david@redhat.com> References: <20230616092654.175518-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's track how many memslots are currently required by plugged memory devices. We'll use this number to perform sanity checks next (soft limit to warn the user). Right now, each memory device consumes exactly one memslot, and the number of required memslots matches the number of used memslots. Once we support memory devices that consume multiple memslots dynamically, the requested number of memslots will no longer correspond to the number of memory devices, and there will be a difference between required and actually used memslots. Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 2 ++ include/hw/boards.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 667d56bd29..28ad419dc0 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -275,6 +275,7 @@ void memory_device_plug(MemoryDeviceState *md, MachineState *ms) g_assert(ms->device_memory); ms->device_memory->used_region_size += memory_region_size(mr); + ms->device_memory->required_memslots++; memory_region_add_subregion(&ms->device_memory->mr, addr - ms->device_memory->base, mr); trace_memory_device_plug(DEVICE(md)->id ? DEVICE(md)->id : "", addr); @@ -294,6 +295,7 @@ void memory_device_unplug(MemoryDeviceState *md, MachineState *ms) memory_region_del_subregion(&ms->device_memory->mr, mr); ms->device_memory->used_region_size -= memory_region_size(mr); + ms->device_memory->required_memslots--; trace_memory_device_unplug(DEVICE(md)->id ? DEVICE(md)->id : "", mdc->get_addr(md)); } diff --git a/include/hw/boards.h b/include/hw/boards.h index fcaf40b9da..a346b4ec4a 100644 --- a/include/hw/boards.h +++ b/include/hw/boards.h @@ -297,12 +297,14 @@ struct MachineClass { * @mr: address space container for memory devices * @dimm_size: the sum of plugged DIMMs' sizes * @used_region_size: the part of @mr already used by memory devices + * @required_memslots: the number of memslots required by memory devices */ typedef struct DeviceMemoryState { hwaddr base; MemoryRegion mr; uint64_t dimm_size; uint64_t used_region_size; + unsigned int required_memslots; } DeviceMemoryState; /**