From nobody Wed Oct 30 19:55:50 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1694797364; cv=none; d=zohomail.com; s=zohoarc; b=dVs/8buD7g6N3YarQhESQf5ybVUKG9EDl4t3Bsb8KLBKnuw00Msa99JXoDGi95wn23jMrWGNumEhAwoTW36kg7BV0gimuwIFw5lkBF9FgoizuUS47KNabQ5Xmr8PHPseNXoqinoQEiIzDbohpN50MLdAoj8TDTon0nvpLaPY8u4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694797364; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=271dWGSnrPrZmSkc1ZOMJavGXnqksEpNUC/AjjrXlbo=; b=maqb9voVrgbyGa8xl7U4jQ1d/YuTJVFDL7lGz38gKFlRi4HODLl3Zcn66v4m5oC3bDV3Q8+bWkWnrGpOqhB34/Dg+A12B3Vq2/84auC7pIlDIae1V3WyWU4foIEGU8wUw4zRZTP/0PjAJ/WNor1YXzCZGxylaep9bffhtbd9Fww= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694797364836930.0494791009936; Fri, 15 Sep 2023 10:02:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qhCCp-0003Ny-Qk; Fri, 15 Sep 2023 13:02:11 -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 1qhCCn-0003MY-Th for qemu-devel@nongnu.org; Fri, 15 Sep 2023 13:02:09 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qhCCm-0000LE-62 for qemu-devel@nongnu.org; Fri, 15 Sep 2023 13:02:09 -0400 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-502984f5018so3945695e87.3 for ; Fri, 15 Sep 2023 10:02:07 -0700 (PDT) Received: from localhost.localdomain (109-252-90-8.nat.spd-mgts.ru. [109.252.90.8]) by smtp.gmail.com with ESMTPSA id u7-20020a056512040700b005009ab1992esm690431lfk.154.2023.09.15.10.02.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 10:02:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694797326; x=1695402126; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=271dWGSnrPrZmSkc1ZOMJavGXnqksEpNUC/AjjrXlbo=; b=YKiHnal5kPU03Mliq1FirXF6j1EqmN1wP+9YlJQAgUq8E65SEUGoDKiK7kA02kQa4i p9hpxFi30PqOb+MEclfAbwYIM6tvdM2FQ6zVZjvri87dMbisFoeVQT5VbOefuv80KRNt IV0PInSu4UgVn2rm53gWrOVB4iWDrGcfTxH6T9Jth5xlgUsvvCBcvyeAHYETKaeQlK3X 1HpQwcZjhKWFmbfVqnhxay0ju2ZVi3ZSM2qmiXbCk7gqTDBcYE/NAS9eokDC2JifQP6o MyNulzt4O8N2DK/Gcn/AC1g1pVrb2dysXALiQjBONC5ogVPdfyK5a0EkfP/pKerqCpJ3 cdxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694797326; x=1695402126; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=271dWGSnrPrZmSkc1ZOMJavGXnqksEpNUC/AjjrXlbo=; b=Hn2YTuP0R9f7tPcCuc5J/IMuhmWkAge2xg5SDcUPP522p7UQmkfVvkifN5e/SHjgUH u5vfKpm89q+PTrUm6SjDMD6KrnfuCAZuC05pdcsBJi4dM7KIHCeWP+whV88fMWQyfkUP dEeSw7NXQveVg4UmI7VIkamEphfUlOBbH37dvnDDhuSrtXXl0hReIErXdebDoWn8h0tn kzyxHQKiaeD3hbv1qkJgx+MN3mzYA1mR/l5Vnb5h+3AYuLImSKCoOBdoqVW1ahYTshDM kB7YGggF8AkGw73Ealf+ZJdyDRILPIf2p6+KAvpga6h51EX20wCv74zZkeL7MSG1rKP6 LdDA== X-Gm-Message-State: AOJu0YwtMxFzUVwt74cTf3AqUMimkPYr68QkcAtB1UrpWttzMb5tYjll zzpeXQjsbHHtimsx5aZ0/LgXVg== X-Google-Smtp-Source: AGHT+IFiuWEr+A1uDCQQNju3g8Ij93JcB/aeQ341BKvV0sT3TF4UW1iZhtzJlbEdEo/9cCVXH6KlXg== X-Received: by 2002:a19:4f1a:0:b0:4ff:95c:e158 with SMTP id d26-20020a194f1a000000b004ff095ce158mr2103744lfb.64.1694797326437; Fri, 15 Sep 2023 10:02:06 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH v2 3/5] elf2dmp: introduce merging of physical memory runs Date: Fri, 15 Sep 2023 20:01:51 +0300 Message-Id: <20230915170153.10959-4-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230915170153.10959-1-viktor@daynix.com> References: <20230915170153.10959-1-viktor@daynix.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2a00:1450:4864:20::130; envelope-from=viktor@daynix.com; helo=mail-lf1-x130.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1694797367029100003 Content-Type: text/plain; charset="utf-8" DMP supports 42 physical memory runs at most. So, merge adjacent physical memory ranges from QEMU ELF when possible to minimize total number of runs. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/main.c | 56 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index b7e3930164..b4683575fd 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -20,6 +20,7 @@ #define PE_NAME "ntoskrnl.exe" =20 #define INITIAL_MXCSR 0x1f80 +#define MAX_NUMBER_OF_RUNS 42 =20 typedef struct idt_desc { uint16_t offset1; /* offset bits 0..15 */ @@ -234,6 +235,42 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) return 1; } =20 +static void try_merge_runs(struct pa_space *ps, + WinDumpPhyMemDesc64 *PhysicalMemoryBlock) +{ + unsigned int merge_cnt =3D 0, run_idx =3D 0; + + PhysicalMemoryBlock->NumberOfRuns =3D 0; + + for (size_t idx =3D 0; idx < ps->block_nr; idx++) { + struct pa_block *blk =3D ps->block + idx; + struct pa_block *next =3D blk + 1; + + PhysicalMemoryBlock->NumberOfPages +=3D blk->size / ELF2DMP_PAGE_S= IZE; + + if (idx + 1 !=3D ps->block_nr && blk->paddr + blk->size =3D=3D nex= t->paddr) { + printf("Block #%lu 0x%"PRIx64"+:0x%"PRIx64" and %u previous wi= ll be" + " merged\n", idx, blk->paddr, blk->size, merge_cnt); + merge_cnt++; + } else { + struct pa_block *first_merged =3D blk - merge_cnt; + + printf("Block #%lu 0x%"PRIx64"+:0x%"PRIx64" and %u previous wi= ll be" + " merged to 0x%"PRIx64"+:0x%"PRIx64" (run #%u)\n", + idx, blk->paddr, blk->size, merge_cnt, first_merged->p= addr, + blk->paddr + blk->size - first_merged->paddr, run_idx); + PhysicalMemoryBlock->Run[run_idx] =3D (WinDumpPhyMemRun64) { + .BasePage =3D first_merged->paddr / ELF2DMP_PAGE_SIZE, + .PageCount =3D (blk->paddr + blk->size - first_merged->pad= dr) / + ELF2DMP_PAGE_SIZE, + }; + PhysicalMemoryBlock->NumberOfRuns++; + run_idx++; + merge_cnt =3D 0; + } + } +} + static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, struct va_space *vs, uint64_t KdDebuggerDataBlock, KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, int nr_cpus) @@ -244,7 +281,6 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_= space *ps, KUSD_OFFSET_PRODUCT_TYPE); DBGKD_GET_VERSION64 kvb; WinDumpHeader64 h; - size_t i; =20 QEMU_BUILD_BUG_ON(KUSD_OFFSET_SUITE_MASK >=3D ELF2DMP_PAGE_SIZE); QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >=3D ELF2DMP_PAGE_SIZE); @@ -282,13 +318,17 @@ static int fill_header(WinDumpHeader64 *hdr, struct p= a_space *ps, .RequiredDumpSpace =3D sizeof(h), }; =20 - for (i =3D 0; i < ps->block_nr; i++) { - h.PhysicalMemoryBlock.NumberOfPages +=3D - ps->block[i].size / ELF2DMP_PAGE_SIZE; - h.PhysicalMemoryBlock.Run[i] =3D (WinDumpPhyMemRun64) { - .BasePage =3D ps->block[i].paddr / ELF2DMP_PAGE_SIZE, - .PageCount =3D ps->block[i].size / ELF2DMP_PAGE_SIZE, - }; + if (h.PhysicalMemoryBlock.NumberOfRuns <=3D MAX_NUMBER_OF_RUNS) { + for (size_t idx =3D 0; idx < ps->block_nr; idx++) { + h.PhysicalMemoryBlock.NumberOfPages +=3D + ps->block[idx].size / ELF2DMP_PAGE_SIZE; + h.PhysicalMemoryBlock.Run[idx] =3D (WinDumpPhyMemRun64) { + .BasePage =3D ps->block[idx].paddr / ELF2DMP_PAGE_SIZE, + .PageCount =3D ps->block[idx].size / ELF2DMP_PAGE_SIZE, + }; + } + } else { + try_merge_runs(ps, &h.PhysicalMemoryBlock); } =20 h.RequiredDumpSpace +=3D --=20 2.21.0