[Crash-utility] patch to add vmss memory regions support

Dyno (Hongjun) Fu hfu at vmware.com
Tue Mar 24 17:03:47 UTC 2015


Dave,
  patch attached. thanks.
rgds,
Dyno

On 3/24/15 10:00 AM, Dyno Hongjun Fu wrote:
> ---------- Forwarded message ----------
> From: Dave Anderson <anderson at redhat.com>
> Date: Tue, Mar 24, 2015 at 7:17 AM
> Subject: Re: [Crash-utility] patch to add vmss memory regions support
> To: "Discussion list for crash utility usage, maintenance and
> development" <crash-utility at redhat.com>
> 
> 
> 
> Dyno,
> 
> Can you re-post this path so that it applies cleanly to the
> current git repository?  This is what happens:
> 
>  $ git clone https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_crash-2Dutility_crash.git&d=AwIBaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=g2Vka_25x09RSowRkQw8pA&m=CMSBEaJrUe0l1I8xeRN7TmIsyloBPUmxxxRDdOkWC_0&s=urNZ6YRJ7FSXVWnWZBOKvR8FnqMpawcqdLe_2jNTvo0&e= 
>  Cloning into 'crash'...
>  remote: Counting objects: 811, done.
>  remote: Total 811 (delta 0), reused 0 (delta 0), pack-reused 811
>  Receiving objects: 100% (811/811), 1.87 MiB | 1.04 MiB/s, done.
>  Resolving deltas: 100% (532/532), done.
>  $ cd crash
>  $ patch -p1 < ../vmware_memory_region_support.patch
>  patching file vmware_vmss.c
>  Reversed (or previously applied) patch detected!  Assume -R? [n] n
>  Apply anyway? [n] y
>  Hunk #1 succeeded at 42 with fuzz 2 (offset 2 lines).
>  Hunk #2 succeeded at 141 (offset 2 lines).
>  Hunk #3 succeeded at 164 (offset 2 lines).
>  Hunk #4 succeeded at 192 (offset 2 lines).
>  Hunk #5 succeeded at 217 (offset 2 lines).
>  Hunk #6 FAILED at 256.
>  Hunk #7 succeeded at 276 (offset 2 lines).
>  1 out of 7 hunks FAILED -- saving rejects to file vmware_vmss.c.rej
>  patching file vmware_vmss.h
>  $
> 
> Thanks,
>   Dave
> 
> 
> ----- Original Message -----
>> Dave,
>>
>> attached patch is to add vmss memroy regions support.
>>
>> There might be holes in the memory address saved for PCI etc.
>> In such case memory dump is divided into regions. Currently
>> up to 3 regions are supported.
>>
>> Memory dump larger than 3GB will have the first hole.
>> My dropbox space used up, I cannot attach a 4GB memory dump.
>> and here is how it looks like in the vmss meta data dump.
>>
>> 3GB:
>> ===
>> - Group: memory pos=0x1f6f6 size=0xc000090c
>> ------------------------------------
>> align_mask[0, 0] => 0x00ffff
>> regionsCount => 0x000000
>> Memory[0, 0] => BLOCK, pos=0x20000, size=0xc0000000
>>
>> 4GB:
>> ===
>> - Group: memory pos=0x1f6f6 size=0x10000090c
>> -----------------------------------
>> align_mask[0, 0] => 0x00ffff
>> regionsCount => 0x000002
>> regionPageNum[0] => 0x000000
>> regionPPN[0] => 0x000000
>> regionSize[0] => 0x0c0000
>> regionPageNum[1] => 0x0c0000
>> regionPPN[1] => 0x100000
>> regionSize[1] => 0x040000
>> Memory[0, 0] => BLOCK, pos=0x20000, size=0x100000000
>>
>> rgds,
>> Dyno
>>
>> --
>> Crash-utility mailing list
>> Crash-utility at redhat.com
>> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.redhat.com_mailman_listinfo_crash-2Dutility&d=AwIBaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=g2Vka_25x09RSowRkQw8pA&m=CMSBEaJrUe0l1I8xeRN7TmIsyloBPUmxxxRDdOkWC_0&s=jsnuoM4kieLx44ivbcbd1s3TI9JGIOUsTTtZ4j5ytZw&e= 
> 
> --
> Crash-utility mailing list
> Crash-utility at redhat.com
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.redhat.com_mailman_listinfo_crash-2Dutility&d=AwIBaQ&c=Sqcl0Ez6M0X8aeM67LKIiDJAXVeAw-YihVMNtXt-uEs&r=g2Vka_25x09RSowRkQw8pA&m=CMSBEaJrUe0l1I8xeRN7TmIsyloBPUmxxxRDdOkWC_0&s=jsnuoM4kieLx44ivbcbd1s3TI9JGIOUsTTtZ4j5ytZw&e= 
> 
> 
-------------- next part --------------
commit 7099b9744d0e728875ba5c7224c8448da6246f8c
Author: Dyno (Hongjun) Fu <hfu at vmware.com>
Date:   Tue Mar 24 09:38:27 2015 -0700

    add vmss memory regions support
    
    There might be holes in the guest os memory address saved for PCI etc.
    The memory dump will be divided into regions to skip these holes.
    
    On vSphere 5.5, RHEL 6.5 memory dump larger than 3GB is such a case.

diff --git a/vmware_vmss.c b/vmware_vmss.c
index aeb1c1d..cc54c8d 100644
--- a/vmware_vmss.c
+++ b/vmware_vmss.c
@@ -139,8 +139,7 @@ vmware_vmss_init(char *filename, FILE *ofp)
 				break;
 			}
 			name[nameLen] = 0;
-			DEBUG_PARSE_PRINT((vmss.ofp, LOGPRX"\t Item %20s",
-					   name));
+			DEBUG_PARSE_PRINT((vmss.ofp, LOGPRX"\t Item %20s", name));
 
 			nindx = TAG_NINDX(tag);
 			if (nindx > 3) {
@@ -163,6 +162,8 @@ vmware_vmss_init(char *filename, FILE *ofp)
 				int compressed = IS_BLOCK_COMPRESSED_TAG(tag);
 				uint16_t padsize;
 
+				assert(strcmp(name, "Memory") == 0);
+
 				if (fread(&nbytes, sizeof(nbytes), 1, vmss.dfp) != 1) {
 					fprintf(vmss.ofp, LOGPRX"Cannot read block size.\n");
 					break;
@@ -188,15 +189,13 @@ vmware_vmss_init(char *filename, FILE *ofp)
 				}
 
 				/* The things that we really care about...*/
-				if (strcmp(grps[i].name, "memory") == 0 &&
-				    strcmp(name, "Memory") == 0) {
-					vmss.memoffset = blockpos;
-					vmss.memsize = nbytesinmem;
-				}
+				vmss.memoffset = blockpos;
+				vmss.memsize = nbytesinmem;
 
 				DEBUG_PARSE_PRINT((vmss.ofp, "\t=> %sBLOCK: position=%#llx size=%#llx memsize=%#llx\n",
 						  compressed ? "COMPRESSED " : "",
 						  (ulonglong)blockpos, (ulonglong)nbytes, (ulonglong)nbytesinmem));
+				assert (!compressed);
 
 			} else {
 				uint8_t val[TAG_VALSIZE_MASK];
@@ -216,18 +215,21 @@ vmware_vmss_init(char *filename, FILE *ofp)
 
 				if (strcmp(grps[i].name, "memory") == 0) {
 					if (strcmp(name, "regionsCount") == 0) {
-						vmss.regionscount = (uint32_t) *val;
-						if (vmss.regionscount != 0) {
-							fprintf(vmss.ofp, LOGPRX"regionsCount=%d (!= 0) NOT TESTED!",
-							        vmss.regionscount);
-						}
+						vmss.regionscount = *(uint32_t*)val;
+						assert(vmss.regionscount <= MAX_REGIONS);
+					}
+				        if (strcmp(name, "regionPageNum") == 0) {
+						vmss.regions[idx[0]].startpagenum = *(uint32_t*)val;
+					}
+					if (strcmp(name, "regionPPN") == 0) {
+						vmss.regions[idx[0]].startppn = *(uint32_t*)val;
+					}
+					if (strcmp(name, "regionSize") == 0) {
+						vmss.regions[idx[0]].size = *(uint32_t*)val;
 					}
 					if (strcmp(name, "align_mask") == 0) {
-						vmss.alignmask = (uint32_t) *val;
-						if (vmss.alignmask != 0xff) {
-							fprintf(vmss.ofp, LOGPRX"align_mask=%d (!= 0xff) NOT TESTED!",
-							        vmss.regionscount);
-						}
+						vmss.alignmask = *(uint32_t*)val;
+						assert(vmss.alignmask == 0xFFFF);
 					}
 				}
 
@@ -272,27 +274,35 @@ vmware_vmss_init(char *filename, FILE *ofp)
 
 uint vmware_vmss_page_size(void)
 {
-	return 4096;
+	return PAGE_SIZE;
 }
 
 int
 read_vmware_vmss(int fd, void *bufptr, int cnt, ulong addr, physaddr_t paddr)
 {
-	uint64_t pos = vmss.memoffset + paddr;
+	uint64_t pos = paddr;
+
+	if (vmss.regionscount > 0) {
+		/* Memory is divided into regions and there are holes between them. */
+		uint32_t ppn = (uint32_t) (pos >> PAGE_SHIFT);
+	        int i;
+
+		for (i = 0; i < vmss.regionscount; i++) {
+			if (ppn < vmss.regions[i].startppn)
+				break;
 
-	if (pos + cnt > vmss.memoffset + vmss.memsize) {
-		cnt -= ((pos + cnt) - (vmss.memoffset + vmss.memsize));
-		if (cnt < 0) {
-			error(INFO, LOGPRX"Read beyond the end of file! paddr=%#lx\n",
-			      paddr);
+			/* skip holes. */
+			pos -= ((vmss.regions[i].startppn - vmss.regions[i].startpagenum)
+				<< PAGE_SHIFT);
 		}
 	}
+	assert(pos + cnt <= vmss.memsize);
 
+	pos += vmss.memoffset;
         if (fseek(vmss.dfp, pos, SEEK_SET) != 0)
 		return SEEK_ERROR;
 
-        if (fread(bufptr, 1 , cnt, vmss.dfp) != cnt)
-		return READ_ERROR;
+	cnt = fread(bufptr, 1, cnt, vmss.dfp);
 
 	return cnt;
 }
diff --git a/vmware_vmss.h b/vmware_vmss.h
index dcbde2d..3f46188 100644
--- a/vmware_vmss.h
+++ b/vmware_vmss.h
@@ -82,6 +82,14 @@ struct cptgroupdesc {
 };
 typedef struct cptgroupdesc	cptgroupdesc;
 
+struct memregion {
+   uint32_t startpagenum;
+   uint32_t startppn;
+   uint32_t size;
+};
+typedef struct memregion	memregion;
+
+#define MAX_REGIONS	3
 struct vmssdata {
 	int32_t	cpt64bit;
 	FILE	*dfp;
@@ -89,6 +97,7 @@ struct vmssdata {
 	/* about the memory */
 	uint32_t	alignmask;
 	uint32_t	regionscount;
+        memregion	regions[MAX_REGIONS];
 	uint64_t	memoffset;
 	uint64_t	memsize;
 };


More information about the Crash-utility mailing list