Received: by 2002:a17:906:d7a2:b0:96f:a786:ac5c with SMTP id pk2csp2109482ejb; Tue, 30 May 2023 04:43:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4NU41CsKstEGOS9IuR1ASMghwwZVdvTPP+sE6P3Rck8e42rBnjiBSufSLgngoN/wGCCNbp X-Received: by 2002:a05:620a:38c2:b0:75b:23a1:8e4d with SMTP id qq2-20020a05620a38c200b0075b23a18e4dmr1401408qkn.30.1685446986812; Tue, 30 May 2023 04:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685446986; cv=none; d=google.com; s=arc-20160816; b=zbVSjH6pDBrTm4Mr+p6crlDDV0JBDKqWLq9usXrtdeoKKRlU8lh7j4dST1+YVEsik7 eWclHRfbc2R1wUT3QlheeEkQl2FHUgTOKA2NTdn4KbOXrbXCzErAX/KaF9Boj0PXko49 sbqRs8AGdClVbPQMDij1kn2N4/VVOgNZ2bxxCwsWoP/K5pNui1rML5ABCcN66z01HMrg gPrW8GY2Rr4AzrtG6wQxzU70/G2R/sR9+u/KhdIP6gg5pGi0bTb3kMn96CE8FbrTlAve WUune5MJnDKEjxIEfVBA/SRZH7O2z9bXGV1JSONHNBP+rrzZsDMCw8IlIgKhAJ6b3a1k uxOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cb4iSjQQh27x17LFuIUvzkQ0NEv7gRmk65M7DLN/NpQ=; b=fg1FkUHnTdLbVCYxnXWDznG5DOg6gxPAAKFMVqa2KNrgzooFFI04zrM5B3px4FCHJF TBmiPLQmWUdUFtvfcSzyTU6MuwqZVy6AtQ7zGnfGpBqNAQ/IkOb3z1GGLzVNSuJwPqDn n7jSDPWCC4cWiYfbyD5Khxo2xmMFQU/3n2WgzB1Lbx5SbZIoIJZX1gE3JHpnY+pxgPq7 2ScglYxPDcFY+yXhs/Py+9VlCWwAxD/zLZ8IK4+ohiXS1OXgY4O8jjEWyA3U6E4bN8+R 4L1PrJZWN2ajp8A8aEbXvEpj6OH90YibH4e53puU/TCyI6NQhtXgPocXWALcNnGa+QKl LMng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ALV/c8bz"; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id j7-20020a37c247000000b0075cf0bebab5si1882619qkm.757.2023.05.30.04.43.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 May 2023 04:43:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="ALV/c8bz"; spf=pass (google.com: domain of qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q3xhL-0008Cv-Ex; Tue, 30 May 2023 07:39:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q3xhI-00086p-0a for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q3xhG-0004FZ-ED for qemu-devel@nongnu.org; Tue, 30 May 2023 07:39:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685446765; 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=cb4iSjQQh27x17LFuIUvzkQ0NEv7gRmk65M7DLN/NpQ=; b=ALV/c8bzelu/zWfKe2KJy8g73JjRNIKzVgutFeDyfmzXMgkUSBAUVPj1qb8ftRT5X1qyR/ Ns+oUfR4jKWgf1cAKOw090aZm0wYmHG6MCHq78VXpN6CP2xLoOte+cYbHH+MvyFMkWDQzx 7KsF1fUADYzFlmN/EdccMiqSuRtrq1o= 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-600-aM7XQF0uO6CQpYbyd7cHhg-1; Tue, 30 May 2023 07:39:19 -0400 X-MC-Unique: aM7XQF0uO6CQpYbyd7cHhg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F3CF85A5A8; Tue, 30 May 2023 11:39:18 +0000 (UTC) Received: from t480s.redhat.com (unknown [10.39.194.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50FF940CFD45; Tue, 30 May 2023 11:39:15 +0000 (UTC) From: David Hildenbrand To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, qemu-ppc@nongnu.org, Igor Mammedov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Xiao Guangrong , David Hildenbrand , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Daniel Henrique Barboza , David Gibson , Eduardo Habkost , Greg Kurz , Harsh Prateek Bora , Marcel Apfelbaum , "Michael S. Tsirkin" , Paolo Bonzini , Peter Maydell , Richard Henderson , Song Gao , Xiaojuan Yang Subject: [PATCH 09/10] memory-device: Refactor memory_device_pre_plug() Date: Tue, 30 May 2023 13:38:37 +0200 Message-Id: <20230530113838.257755-10-david@redhat.com> In-Reply-To: <20230530113838.257755-1-david@redhat.com> References: <20230530113838.257755-1-david@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass client-ip=170.10.133.124; envelope-from=david@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.167, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-devel-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: bliMALwNyO/V Let's move memory_device_check_addable() and basic checks out of memory_device_get_free_addr() directly into memory_device_pre_plug(). Separating basic checks from address assignment is cleaner and prepares for further changes. As all memory device users now use memory_devices_init(), and that function enforces that the size is 0, we can drop the check for an empty region. Signed-off-by: David Hildenbrand --- hw/mem/memory-device.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/hw/mem/memory-device.c b/hw/mem/memory-device.c index 2197dcf356..616067cbdc 100644 --- a/hw/mem/memory-device.c +++ b/hw/mem/memory-device.c @@ -69,9 +69,10 @@ static int memory_device_used_region_size(Object *obj, void *opaque) return 0; } -static void memory_device_check_addable(MachineState *ms, uint64_t size, +static void memory_device_check_addable(MachineState *ms, MemoryRegion *mr, Error **errp) { + const uint64_t size = memory_region_size(mr); uint64_t used_region_size = 0; /* we will need a new memory slot for kvm and vhost */ @@ -101,16 +102,9 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, uint64_t align, uint64_t size, Error **errp) { - Error *err = NULL; GSList *list = NULL, *item; Range as, new = range_empty; - if (!ms->device_memory || !memory_region_size(&ms->device_memory->mr)) { - error_setg(errp, "the configuration is not prepared for memory devices" - " (e.g., for memory hotplug), consider specifying the" - " maxmem option"); - return 0; - } range_init_nofail(&as, ms->device_memory->base, memory_region_size(&ms->device_memory->mr)); @@ -122,12 +116,6 @@ static uint64_t memory_device_get_free_addr(MachineState *ms, align); } - memory_device_check_addable(ms, size, &err); - if (err) { - error_propagate(errp, err); - return 0; - } - if (hint && !QEMU_IS_ALIGNED(*hint, align)) { error_setg(errp, "address must be aligned to 0x%" PRIx64 " bytes", align); @@ -251,11 +239,23 @@ void memory_device_pre_plug(MemoryDeviceState *md, MachineState *ms, uint64_t addr, align = 0; MemoryRegion *mr; + if (!ms->device_memory) { + error_setg(errp, "the configuration is not prepared for memory devices" + " (e.g., for memory hotplug), consider specifying the" + " maxmem option"); + return; + } + mr = mdc->get_memory_region(md, &local_err); if (local_err) { goto out; } + memory_device_check_addable(ms, mr, &local_err); + if (local_err) { + goto out; + } + if (legacy_align) { align = *legacy_align; } else { -- 2.40.1