From: Cam Macdonell <cam@cs.ualberta.ca>
To: Valdir Stumm Junior <stummjr@gmail.com>
Cc: kvm@vger.kernel.org
Subject: Re: inter-vm shared memory (ivshmem) documentation
Date: Thu, 23 Apr 2009 11:15:33 -0600 [thread overview]
Message-ID: <49F0A235.7070500@cs.ualberta.ca> (raw)
In-Reply-To: <7384320d0904230836o623bbef5pb2abab7f3fa08459@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1758 bytes --]
Valdir Stumm Junior wrote:
> On Thu, Apr 23, 2009 at 12:52 AM, Cameron Macdonell <cam@cs.ualberta.ca> 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 <shm object> 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
[-- Attachment #2: dump.c --]
[-- Type: text/x-csrc, Size: 1341 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <string.h>
#include <openssl/sha.h>
#include <unistd.h>
#include <errno.h>
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 <filename> <size>\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);
}
[-- Attachment #3: sum.c --]
[-- Type: text/x-csrc, Size: 1357 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <openssl/sha.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
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 <file> <size in MB>\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");
}
[-- Attachment #4: Makefile --]
[-- Type: text/plain, Size: 293 bytes --]
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
[-- Attachment #5: sum_host.c --]
[-- Type: text/x-csrc, Size: 1574 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <openssl/sha.h>
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
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 <shm object> <size in MB>\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");
}
prev parent reply other threads:[~2009-04-23 17:15 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-22 23:23 inter-vm shared memory (ivshmem) documentation Valdir Stumm Junior
2009-04-23 3:52 ` Cameron Macdonell
2009-04-23 15:36 ` Valdir Stumm Junior
2009-04-23 17:15 ` Cam Macdonell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49F0A235.7070500@cs.ualberta.ca \
--to=cam@cs.ualberta.ca \
--cc=kvm@vger.kernel.org \
--cc=stummjr@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox