xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Paul Durrant <Paul.Durrant@citrix.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Keir (Xen.org)" <keir@xen.org>,
	Ian Campbell <Ian.Campbell@citrix.com>,
	Jan Beulich <jbeulich@suse.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [PATCH] blkif: add indirect descriptors interface to	public headers
Date: Thu, 14 Nov 2013 13:14:40 -0500	[thread overview]
Message-ID: <20131114181440.GA27306@phenom.dumpdata.com> (raw)
In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD0173E2D@AMSPEX01CL01.citrite.net>

> > I must be really thick here but I am not seeing it. Could you explain to me
> > exactly why we would not get the same size?
> > 
> 
> Maybe I'm misunderstanding this but by my reading this section:
> 
> uint8_t        indirect_op;
> uint16_t       nr_segments;
> #ifdef CONFIG_X86_64
> uint32_t       _pad1;        /* offsetof(blkif_...,u.indirect.id) == 8 */
> #endif
> uint64_t       id;
> 
> would be 11 bytes long in a 32-bit build and 15 bytes long in a 64-bit build (as it's part of a packed struct).

Damm! I somehow thought we had it done _Right_ so it would be the same
exact and offset on both 64-bit and 32-bit. ARGH!

konrad@phenom:/tmp$ ./blk-interface-64
RING TOTAL SIZE         2368
Each entry              64
Each request            60
64-bit
op:0, indirect_op=1, nr_segment=2,id=8 sector_number=16
gref[0] == (24)
gref[1] == (28)
gref[2] == (32)
gref[3] == (36)
gref[4] == (40)
gref[5] == (44)
gref[6] == (48)
gref[7] == (52)
konrad@phenom:/tmp$ ./blk-interface-32
konrad@phenom:/tmp$ ./blk-interface
RING TOTAL SIZE         1792
Each entry              48
Each request            48
32-bit
op:0, indirect_op=1, nr_segment=2,id=4 sector_number=8
gref[0] == (12)
gref[1] == (16)
gref[2] == (20)
gref[3] == (24)
gref[4] == (28)
gref[5] == (32)
gref[6] == (36)
gref[7] == (40)

Attached is the simple test program.

#include <stdio.h>
#include <sys/types.h>

#include <stddef.h>

/* These are only 64-bit defined */
typedef __signed__ char __s8;
typedef unsigned char __u8;

typedef __signed__ short __s16;
typedef unsigned short __u16;

typedef __signed__ int __s32;
typedef unsigned int __u32;

typedef __signed__ long __s64;
typedef unsigned long __u64;

typedef		__u8		uint8_t;
typedef		__u16		uint16_t;
typedef		__u32		uint32_t;

#if defined(__GNUC__)
typedef		__u64		uint64_t;
//typedef		__u64		u_int64_t;
//typedef		__s64		int64_t;
#endif

typedef uint16_t blkif_vdev_t;
typedef uint64_t blkif_sector_t;
typedef uint32_t grant_ref_t;

/*
 * Maximum scatter/gather segments per request.
 * This is carefully chosen so that sizeof(struct blkif_ring) <= PAGE_SIZE.
 * NB. This could be 12 if the ring indexes weren't stored in the same page.
 */
#define BLKIF_MAX_SEGMENTS_PER_REQUEST 11


//#define CONFIG_X86_64 1

struct blkif_request_rw {
	uint8_t        nr_segments;  /* number of segments                   */
	blkif_vdev_t   handle;       /* only for read/write requests         */
#ifdef CONFIG_X86_64
	uint32_t       _pad1;	     /* offsetof(blkif_request,u.rw.id) == 8 */
#endif
	uint64_t       id;           /* private guest value, echoed in resp  */
	blkif_sector_t sector_number;/* start sector idx on disk (r/w only)  */
	struct blkif_request_segment {
		grant_ref_t gref;        /* reference to I/O buffer frame        */
		/* @first_sect: first sector in frame to transfer (inclusive).   */
		/* @last_sect: last sector in frame to transfer (inclusive).     */
		uint8_t     first_sect, last_sect;
	} seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
} __attribute__((__packed__));

#define BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST 8


/* so 64 bytes under 64-bit  */
struct blkif_request_indirect {
	uint8_t        indirect_op;  /* BLKIF_OP_* (usually READ or WRITE    */	// 1
	uint16_t       nr_segments;
#ifdef CONFIG_X86_64
	uint32_t       _pad1;	     /* offsetof(blkif_request,u.rw.id) == 8 */ // 2
#endif
	uint64_t       id;           /* private guest value, echoed in resp  */
	blkif_sector_t sector_number;
	grant_ref_t    indirect_grefs[BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST];
#ifdef CONFIG_X86_64
        uint32_t      _pad3;         /* make it 64 byte aligned */
#else
        uint64_t      _pad3;         /* make it 64 byte aligned */
#endif

} __attribute__((__packed__));


struct blkif_request {
	uint8_t        operation;    /* BLKIF_OP_???                         */
	union {
		/* struct blkif_request_rw rw; */
		struct blkif_request_indirect indirect;
	} u;
} __attribute__((__packed__));

struct blkif_response {
	uint64_t        id;              /* copied from request */
	uint8_t         operation;       /* copied from request */
	int16_t         status;          /* BLKIF_RSP_???       */
};
typedef unsigned int RING_IDX; /* 4 bytes */

union blkif_sring_entry {
	struct blkif_request req;
	struct blkif_response rsp;
};

struct blkif_ring {
	/* 8 */
    RING_IDX req_prod, req_event; /* #1 front writest req_prod,
				 blkback updates req_event by interal reqs_cons consumed + 1 */
	/* 8 */
    RING_IDX rsp_prod, rsp_event; /* #2 blkback writes rsp_prod, and #4 blkfront updates rsp_event
			by its internal rsp_cons + 1 */
    uint8_t  pad[48];
	/* 48 + 16 = 64 */
    union blkif_sring_entry ring[36]; /* variable-length */
};

void main(void)
{
	int i;
	printf("RING TOTAL SIZE\t\t%d\n", sizeof(struct blkif_ring));
	printf("Each entry\t\t%d\n", sizeof(union blkif_sring_entry));
	printf("Each request\t\t%d\n", sizeof(struct blkif_request));
	printf("%s\n", 
#ifdef CONFIG_X86_64
		"64-bit"
#else
		"32-bit"
#endif
	);

	printf("op:%d, indirect_op=%d, nr_segment=%d,id=%d sector_number=%d\n",
		offsetof(struct blkif_request, operation),
		offsetof(struct blkif_request, u.indirect.indirect_op),
		offsetof(struct blkif_request, u.indirect.nr_segments),
		offsetof(struct blkif_request, u.indirect.id),
		offsetof(struct blkif_request, u.indirect.sector_number));

	for (i = 0; i < BLKIF_MAX_INDIRECT_PAGES_PER_REQUEST; i++) {
		printf("gref[%d] == (%d)\n", i, offsetof(struct blkif_request, u.indirect.indirect_grefs[i]));
	}
	return;
}

  reply	other threads:[~2013-11-14 18:14 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-12 10:36 [PATCH] blkif: add indirect descriptors interface to public headers Roger Pau Monne
2013-11-12 13:46 ` Paul Durrant
2013-11-12 14:12   ` David Vrabel
2013-11-12 14:18     ` Paul Durrant
2013-11-12 14:43     ` Jan Beulich
2013-11-12 14:49       ` David Vrabel
2013-11-12 14:54         ` Roger Pau Monné
2013-11-12 14:58           ` Jan Beulich
2013-11-14  9:57             ` Roger Pau Monné
2013-11-12 14:22   ` Konrad Rzeszutek Wilk
2013-11-12 14:29     ` Ian Campbell
2013-11-12 14:42       ` Konrad Rzeszutek Wilk
2013-11-12 14:54         ` Ian Campbell
2013-11-12 15:16       ` Paul Durrant
2013-11-13  9:26         ` Ian Campbell
2013-11-13 11:07           ` Paul Durrant
2013-11-13 11:11             ` Ian Campbell
2013-11-13 11:24               ` Paul Durrant
2013-11-14 10:06                 ` Roger Pau Monné
2013-11-14 10:14                   ` Paul Durrant
2013-11-14 10:27                     ` Roger Pau Monné
2013-11-14 10:38                       ` Paul Durrant
2013-11-14 10:52                         ` Roger Pau Monné
2013-11-14 11:26                           ` Paul Durrant
2013-11-14 16:24                         ` Konrad Rzeszutek Wilk
2013-11-14 16:26                           ` Paul Durrant
2013-11-14 16:34                             ` Konrad Rzeszutek Wilk
2013-11-14 16:53                               ` Paul Durrant
2013-11-14 16:57                                 ` Konrad Rzeszutek Wilk
2013-11-14 17:13                                   ` Paul Durrant
2013-11-14 18:14                                     ` Konrad Rzeszutek Wilk [this message]
2013-11-15  8:01                                     ` Roger Pau Monné
2013-11-15  9:05                                       ` Paul Durrant
2013-11-15  9:44                                         ` Ian Campbell
2013-11-14 19:16                                 ` Paul Durrant
2013-11-15  8:04                                   ` Roger Pau Monné
2013-11-13 12:01             ` Konrad Rzeszutek Wilk
2013-11-28 17:02 ` Roger Pau Monné
2013-11-29 10:14   ` Jan Beulich
2013-11-29 10:28     ` Ian Campbell
2013-11-29 12:47       ` Julien Grall
2013-11-29 12:49         ` Ian Campbell
2013-12-03  9:22     ` Keir Fraser

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=20131114181440.GA27306@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=Ian.Campbell@citrix.com \
    --cc=Paul.Durrant@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=keir@xen.org \
    --cc=roger.pau@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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;
as well as URLs for NNTP newsgroup(s).