From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cam Macdonell Subject: Re: inter-vm shared memory (ivshmem) documentation Date: Thu, 23 Apr 2009 11:15:33 -0600 Message-ID: <49F0A235.7070500@cs.ualberta.ca> References: <7384320d0904221623v748ea477y691a5ad4db88a7a0@mail.gmail.com> <28A70B4E-5015-4429-9D52-A88DB304F9A6@cs.ualberta.ca> <7384320d0904230836o623bbef5pb2abab7f3fa08459@mail.gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010904080008000904080005" Cc: kvm@vger.kernel.org To: Valdir Stumm Junior Return-path: Received: from fleet.cs.ualberta.ca ([129.128.22.22]:58833 "EHLO fleet.cs.ualberta.ca" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752327AbZDWRPm (ORCPT ); Thu, 23 Apr 2009 13:15:42 -0400 Received: from fleet.cs.ualberta.ca (localhost.localdomain [127.0.0.1]) by fleet-spampd (Postfix) with ESMTP id E138F28019 for ; Thu, 23 Apr 2009 11:15:33 -0600 (MDT) In-Reply-To: <7384320d0904230836o623bbef5pb2abab7f3fa08459@mail.gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: This is a multi-part message in MIME format. --------------010904080008000904080005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Valdir Stumm Junior wrote: > On Thu, Apr 23, 2009 at 12:52 AM, Cameron Macdonell wrote: >> Hi Valdir, >> >> Documentation is under development. I have some simple test programs that I >> can supply when you get it up and running. As well as boot scripts to >> create the /dev file. >> Are you running the patched kernel on the host or in the guest. It's meant >> to run in the guest. > > Cameron, > > now I am running the patched kernel in the guest and it's working. > I modprobed "kvm_jvshmem" and then I made the following steps: > > num =`cat /proc/devices | grep kvm_ivshmem | awk '{print $1}` > mknod --mode=666 /dev/ivshmem c $num 0 > > I've added to the mknod command the "c" option, to create a character > device (in the original post it was "mknod --mode=666 /dev/ivshmem > $num 0", without that option). The file creation was succesful. So, > what's next? Could you send your own test programs? Great. I've attached some simple programs "dump" and "sum". They are meant to run in the guest. dump will fill the shared memory region with random numbers via the character device, so you run it dump /dev/ivshmem 256 (if your device is 256 MB) And on the other guest sum /dev/ivshmem 256 will do a SHA1 sum on the region. Dump also prints out the SHA1 sum, so make sure they match. There is a third source file for the host - sum_host.c. sum_host 256 256 will do the sum on the host shm object file. All the sums should match. On the host, only specify the name of the shm object, not the full path since shm_open just takes the name "foo" and then creates /dev/shm/foo. Eventually, I will move these tests to the wiki if/when the patch is accepted in some form. Good luck, Cam --------------010904080008000904080005 Content-Type: text/x-csrc; name="dump.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="dump.c" #include #include #include #include #include #include #include #include #include #include int main(int argc, char ** argv){ int fd, length=4*1024; void * memptr; long * long_array; int i; SHA_CTX context; char md[20]; if (argc != 3){ printf("USAGE: dump \n"); exit(-1); } printf("[DUMP] opening file %s\n", argv[1]); length=atoi(argv[2])*1024*1024; // length=atoi(argv[2]); printf("[DUMP] size is %d\n", length); fd=open(argv[1], O_RDWR); if ((memptr = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (caddr_t)-1){ printf("mmap failed (0x%x)\n", memptr); close (fd); exit (-1); } srand(time()); long_array=(long *)memptr; for (i=0; i < length/sizeof(long); i++){ long_array[i]=rand(); } memset(md,0,20); SHA1_Init(&context); SHA1_Update(&context,memptr,length); SHA1_Final(md,&context); printf("[DUMP] "); for(i = 0; i < SHA_DIGEST_LENGTH; ++i ) { unsigned char c = md[i]; printf("%2.2x",c); } printf("\n"); printf("munmap is unmapping %x\n", memptr); munmap(memptr, length); close(fd); } --------------010904080008000904080005 Content-Type: text/x-csrc; name="sum.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sum.c" #include #include #include #include #include #include #include #include #include #include int main(int argc, char ** argv){ long size; char * file; void * map_region; long * long_array; int i,fd; SHA_CTX context; unsigned char md[20]; struct test * myptr; if (argc!=3){ fprintf(stderr, "USAGE: sum \n"); exit(-1); } size=atol(argv[2])*1024*1024; file=strdup(argv[1]); printf("[SUM] reading %d bytes from %s\n", size, file); if ((fd=open(file, O_RDWR)) < 0){ fprintf(stderr, "ERROR: cannot open file\n"); exit(-1); } if ((map_region=mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0))<0){ fprintf(stderr, "ERROR: cannot mmap file\n"); } else { printf("[SUM] mapped to %p\n", map_region); } memset(md,0,20); SHA1_Init(&context); SHA1_Update(&context,map_region,size); SHA1_Final(md,&context); printf("[SUM] "); for(i = 0; i < SHA_DIGEST_LENGTH; ++i ) { unsigned char c = md[i]; printf("%2.2x",c); } printf("\n"); // printf("md is *%20s*\n", md); munmap(map_region,size); close(fd); printf("[SUM] Exiting...\n"); } --------------010904080008000904080005 Content-Type: text/plain; name="Makefile" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Makefile" CC=gcc CFLAGS= -g -lcrypto -lrt all: sum dump writedump unlink_mem sum: sum.c $(CC) $^ -o $@ $(CFLAGS) writedump: writedump.c $(CC) $^ -o $@ $(CFLAGS) dump: dump.c $(CC) $^ -o $@ $(CFLAGS) unlink_mem: unlink_mem.c $(CC) $^ -o $@ $(CFLAGS) clean: rm -f sum dump unlink_mem writedump --------------010904080008000904080005 Content-Type: text/x-csrc; name="sum_host.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="sum_host.c" #include #include #include #include #include #include #include #include #include #include int main(int argc, char ** argv){ long size; char file[1024]; void * map_region; long * long_array; int i,fd; SHA_CTX context; unsigned char md[20]; struct test * myptr; if (argc!=3){ fprintf(stderr, "USAGE: sum \n"); fprintf(stderr, "this is meant to run on the host\n"); exit(-1); } size=atol(argv[2])*1024*1024; memset(file,0,1024); snprintf(file, 1024, "/%s",argv[1]); printf("[SUM] reading %ld bytes from %s\n", size, file); if ((fd=shm_open(file, O_RDWR|O_CREAT, S_IREAD | S_IWRITE)) > 0){ printf("[SUM] second\n"); } else { fprintf(stderr, "ERROR: cannot open file\n"); exit(-1); } ftruncate(fd,size); if ((map_region=mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0))<0){ fprintf(stderr, "ERROR: cannot mmap file\n"); } else { printf("[SUM] mapped to %p\n", map_region); } memset(md,0,20); SHA1_Init(&context); SHA1_Update(&context,map_region,size); SHA1_Final(md,&context); printf("[SUM] "); for(i = 0; i < SHA_DIGEST_LENGTH; ++i ) { unsigned char c = md[i]; printf("%2.2x",c); } printf("\n"); // printf("md is *%20s*\n", md); munmap(map_region,size); close(fd); printf("[SUM] Exiting...\n"); } --------------010904080008000904080005--