ia64/xen-unstable
changeset 9132:d088ce2d3528
Merged.
author | emellor@leeni.uk.xensource.com |
---|---|
date | Fri Mar 03 15:56:34 2006 +0100 (2006-03-03) |
parents | 9e19dcb05f56 fab6deef7e87 |
children | 621d32a54e2d 8853631252d8 |
files |
line diff
1.1 --- a/docs/src/interface.tex Fri Mar 03 15:56:03 2006 +0100 1.2 +++ b/docs/src/interface.tex Fri Mar 03 15:56:34 2006 +0100 1.3 @@ -1059,6 +1059,21 @@ This path contains: 1.4 \item[domain] the name of the frontend 1.5 \end{description} 1.6 \end{description} 1.7 + 1.8 + \item[vtpm/] a directory containin vtpm backends 1.9 + \begin{description} 1.10 + \item[$<$domid$>$/] a directory containing vtpm's for domid 1.11 + \begin{description} 1.12 + \item[$<$vtpm number$>$/] a directory for each vtpm 1.13 + \item[frontend-id] the domain id of the frontend 1.14 + \item[frontend] the path to the frontend 1.15 + \item[instance] the instance of the virtual TPM that is used 1.16 + \item[pref{\textunderscore}instance] the instance number as given in the VM configuration file; 1.17 + may be different from {\bf instance} 1.18 + \item[domain] the name of the domain of the frontend 1.19 + \end{description} 1.20 + \end{description} 1.21 + 1.22 \end{description} 1.23 1.24 \item[device/] a directory containing the frontend devices for the 1.25 @@ -1094,6 +1109,18 @@ This path contains: 1.26 \item[event-channel] the event channel used for the two ring queues 1.27 \end{description} 1.28 \end{description} 1.29 + 1.30 + \item[vtpm/] a directory containing the vtpm frontend device for the 1.31 + domain 1.32 + \begin{description} 1.33 + \item[$<$id$>$] a directory for vtpm id frontend device for the domain 1.34 + \begin{description} 1.35 + \item[backend-id] the backend domain id 1.36 + \item[backend] a path to the backend's store entry 1.37 + \item[ring-ref] the grant table reference for the tx/rx ring 1.38 + \item[event-channel] the event channel used for the ring 1.39 + \end{description} 1.40 + \end{description} 1.41 1.42 \item[device-misc/] miscellanous information for devices 1.43 \begin{description} 1.44 @@ -1450,6 +1477,76 @@ The fields are as follows: 1.45 value of {\tt first\_sect}. 1.46 \end{description} 1.47 1.48 +\section{Virtual TPM} 1.49 + 1.50 +Virtual TPM (VTPM) support provides TPM functionality to each virtual 1.51 +machine that requests this functionality in its configuration file. 1.52 +The interface enables domains to access therr own private TPM like it 1.53 +was a hardware TPM built into the machine. 1.54 + 1.55 +The virtual TPM interface is implemented as a split driver, 1.56 +similar to the network and block interfaces described above. 1.57 +The user domain hosting the frontend exports a character device /dev/tpm0 1.58 +to user-level applications for communicating with the virtual TPM. 1.59 +This is the same device interface that is also offered if a hardware TPM 1.60 +is available in the system. The backend provides a single interface 1.61 +/dev/vtpm where the virtual TPM is waiting for commands from all domains 1.62 +that have located their backend in a given domain. 1.63 + 1.64 +\subsection{Data Transfer} 1.65 + 1.66 +A single shared memory ring is used between the frontend and backend 1.67 +drivers. TPM requests and responses are sent in pages where a pointer 1.68 +to those pages and other information is placed into the ring such that 1.69 +the backend can map the pages into its memory space using the grant 1.70 +table mechanism. 1.71 + 1.72 +The backend driver has been implemented to only accept well-formed 1.73 +TPM requests. To meet this requirement, the length inidicator in the 1.74 +TPM request must correctly indicate the length of the request. 1.75 +Otherwise an error message is automatically sent back by the device driver. 1.76 + 1.77 +The virtual TPM implementation listenes for TPM request on /dev/vtpm. Since 1.78 +it must be able to apply the TPM request packet to the virtual TPM instance 1.79 +associated with the virtual machine, a 4-byte virtual TPM instance 1.80 +identifier is prepended to each packet by the backend driver (in network 1.81 +byte order) for internal routing of the request. 1.82 + 1.83 +\subsection{Virtual TPM ring interface} 1.84 + 1.85 +The TPM protocol is a strict request/response protocol and therefore 1.86 +only one ring is used to send requests from the frontend to the backend 1.87 +and responses on the reverse path. 1.88 + 1.89 +The request/response structure is defined as follows: 1.90 + 1.91 +\scriptsize 1.92 +\begin{verbatim} 1.93 +typedef struct { 1.94 + unsigned long addr; /* Machine address of packet. */ 1.95 + grant_ref_t ref; /* grant table access reference. */ 1.96 + uint16_t unused; /* unused */ 1.97 + uint16_t size; /* Packet size in bytes. */ 1.98 +} tpmif_tx_request_t; 1.99 +\end{verbatim} 1.100 +\normalsize 1.101 + 1.102 +The fields are as follows: 1.103 + 1.104 +\begin{description} 1.105 +\item[addr] The machine address of the page asscoiated with the TPM 1.106 + request/response; a request/response may span multiple 1.107 + pages 1.108 +\item[ref] The grant table reference associated with the address. 1.109 +\item[size] The size of the remaining packet; up to 1.110 + PAGE{\textunderscore}SIZE bytes can be found in the 1.111 + page referenced by 'addr' 1.112 +\end{description} 1.113 + 1.114 +The frontend initially allocates several pages whose addresses 1.115 +are stored in the ring. Only these pages are used for exchange of 1.116 +requests and responses. 1.117 + 1.118 1.119 \chapter{Further Information} 1.120
2.1 --- a/linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c Fri Mar 03 15:56:03 2006 +0100 2.2 +++ b/linux-2.6-xen-sparse/arch/i386/kernel/io_apic-xen.c Fri Mar 03 15:56:34 2006 +0100 2.3 @@ -61,8 +61,8 @@ static inline unsigned int xen_io_apic_r 2.4 int ret; 2.5 2.6 op.cmd = PHYSDEVOP_APIC_READ; 2.7 - op.u.apic_op.apic = mp_ioapics[apic].mpc_apicid; 2.8 - op.u.apic_op.offset = reg; 2.9 + op.u.apic_op.apic_physbase = mp_ioapics[apic].mpc_apicaddr; 2.10 + op.u.apic_op.reg = reg; 2.11 ret = HYPERVISOR_physdev_op(&op); 2.12 if (ret) 2.13 return ret; 2.14 @@ -74,8 +74,8 @@ static inline void xen_io_apic_write(uns 2.15 physdev_op_t op; 2.16 2.17 op.cmd = PHYSDEVOP_APIC_WRITE; 2.18 - op.u.apic_op.apic = mp_ioapics[apic].mpc_apicid; 2.19 - op.u.apic_op.offset = reg; 2.20 + op.u.apic_op.apic_physbase = mp_ioapics[apic].mpc_apicaddr; 2.21 + op.u.apic_op.reg = reg; 2.22 op.u.apic_op.value = value; 2.23 HYPERVISOR_physdev_op(&op); 2.24 }
3.1 --- a/linux-2.6-xen-sparse/arch/x86_64/kernel/io_apic-xen.c Fri Mar 03 15:56:03 2006 +0100 3.2 +++ b/linux-2.6-xen-sparse/arch/x86_64/kernel/io_apic-xen.c Fri Mar 03 15:56:34 2006 +0100 3.3 @@ -108,8 +108,8 @@ static inline unsigned int xen_io_apic_r 3.4 int ret; 3.5 3.6 op.cmd = PHYSDEVOP_APIC_READ; 3.7 - op.u.apic_op.apic = mp_ioapics[apic].mpc_apicid; 3.8 - op.u.apic_op.offset = reg; 3.9 + op.u.apic_op.apic_physbase = mp_ioapics[apic].mpc_apicaddr; 3.10 + op.u.apic_op.reg = reg; 3.11 ret = HYPERVISOR_physdev_op(&op); 3.12 if (ret) 3.13 return ret; 3.14 @@ -121,8 +121,8 @@ static inline void xen_io_apic_write(uns 3.15 physdev_op_t op; 3.16 3.17 op.cmd = PHYSDEVOP_APIC_WRITE; 3.18 - op.u.apic_op.apic = mp_ioapics[apic].mpc_apicid; 3.19 - op.u.apic_op.offset = reg; 3.20 + op.u.apic_op.apic_physbase = mp_ioapics[apic].mpc_apicaddr; 3.21 + op.u.apic_op.reg = reg; 3.22 op.u.apic_op.value = value; 3.23 HYPERVISOR_physdev_op(&op); 3.24 }
4.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Fri Mar 03 15:56:03 2006 +0100 4.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/interface.c Fri Mar 03 15:56:34 2006 +0100 4.3 @@ -19,8 +19,7 @@ int num_frontends = 0; 4.4 4.5 LIST_HEAD(tpmif_list); 4.6 4.7 -tpmif_t * 4.8 -alloc_tpmif(domid_t domid, long int instance) 4.9 +static tpmif_t *alloc_tpmif(domid_t domid, long int instance) 4.10 { 4.11 struct page *page; 4.12 tpmif_t *tpmif; 4.13 @@ -45,16 +44,14 @@ alloc_tpmif(domid_t domid, long int inst 4.14 return tpmif; 4.15 } 4.16 4.17 -void 4.18 -free_tpmif(tpmif_t * tpmif) 4.19 +static void free_tpmif(tpmif_t * tpmif) 4.20 { 4.21 num_frontends--; 4.22 list_del(&tpmif->tpmif_list); 4.23 kmem_cache_free(tpmif_cachep, tpmif); 4.24 } 4.25 4.26 -tpmif_t * 4.27 -tpmif_find(domid_t domid, long int instance) 4.28 +tpmif_t *tpmif_find(domid_t domid, long int instance) 4.29 { 4.30 tpmif_t *tpmif; 4.31 4.32 @@ -72,8 +69,7 @@ tpmif_find(domid_t domid, long int insta 4.33 return alloc_tpmif(domid, instance); 4.34 } 4.35 4.36 -static int 4.37 -map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) 4.38 +static int map_frontend_page(tpmif_t *tpmif, unsigned long shared_page) 4.39 { 4.40 int ret; 4.41 struct gnttab_map_grant_ref op = { 4.42 @@ -99,8 +95,7 @@ map_frontend_page(tpmif_t *tpmif, unsign 4.43 return 0; 4.44 } 4.45 4.46 -static void 4.47 -unmap_frontend_page(tpmif_t *tpmif) 4.48 +static void unmap_frontend_page(tpmif_t *tpmif) 4.49 { 4.50 struct gnttab_unmap_grant_ref op; 4.51 int ret; 4.52 @@ -115,14 +110,14 @@ unmap_frontend_page(tpmif_t *tpmif) 4.53 BUG_ON(ret); 4.54 } 4.55 4.56 -int 4.57 -tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn) 4.58 +int tpmif_map(tpmif_t *tpmif, unsigned long shared_page, unsigned int evtchn) 4.59 { 4.60 int err; 4.61 evtchn_op_t op = { 4.62 .cmd = EVTCHNOP_bind_interdomain, 4.63 .u.bind_interdomain.remote_dom = tpmif->domid, 4.64 - .u.bind_interdomain.remote_port = evtchn }; 4.65 + .u.bind_interdomain.remote_port = evtchn, 4.66 + }; 4.67 4.68 if (tpmif->irq) { 4.69 return 0; 4.70 @@ -156,8 +151,7 @@ tpmif_map(tpmif_t *tpmif, unsigned long 4.71 return 0; 4.72 } 4.73 4.74 -static void 4.75 -__tpmif_disconnect_complete(void *arg) 4.76 +static void __tpmif_disconnect_complete(void *arg) 4.77 { 4.78 tpmif_t *tpmif = (tpmif_t *) arg; 4.79 4.80 @@ -172,22 +166,19 @@ static void 4.81 free_tpmif(tpmif); 4.82 } 4.83 4.84 -void 4.85 -tpmif_disconnect_complete(tpmif_t * tpmif) 4.86 +void tpmif_disconnect_complete(tpmif_t * tpmif) 4.87 { 4.88 INIT_WORK(&tpmif->work, __tpmif_disconnect_complete, (void *)tpmif); 4.89 schedule_work(&tpmif->work); 4.90 } 4.91 4.92 -void __init 4.93 -tpmif_interface_init(void) 4.94 +void __init tpmif_interface_init(void) 4.95 { 4.96 tpmif_cachep = kmem_cache_create("tpmif_cache", sizeof (tpmif_t), 4.97 0, 0, NULL, NULL); 4.98 } 4.99 4.100 -void __init 4.101 -tpmif_interface_exit(void) 4.102 +void __init tpmif_interface_exit(void) 4.103 { 4.104 kmem_cache_destroy(tpmif_cachep); 4.105 }
5.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Fri Mar 03 15:56:03 2006 +0100 5.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmback/tpmback.c Fri Mar 03 15:56:34 2006 +0100 5.3 @@ -22,17 +22,23 @@ 5.4 #include <xen/xenbus.h> 5.5 #include <xen/interface/grant_table.h> 5.6 5.7 - 5.8 /* local data structures */ 5.9 struct data_exchange { 5.10 struct list_head pending_pak; 5.11 struct list_head current_pak; 5.12 unsigned int copied_so_far; 5.13 u8 has_opener; 5.14 - rwlock_t pak_lock; // protects all of the previous fields 5.15 + rwlock_t pak_lock; // protects all of the previous fields 5.16 wait_queue_head_t wait_queue; 5.17 }; 5.18 5.19 +struct vtpm_resp_hdr { 5.20 + uint32_t instance_no; 5.21 + uint16_t tag_no; 5.22 + uint32_t len_no; 5.23 + uint32_t ordinal_no; 5.24 +} __attribute__ ((packed)); 5.25 + 5.26 struct packet { 5.27 struct list_head next; 5.28 unsigned int data_len; 5.29 @@ -50,36 +56,43 @@ enum { 5.30 PACKET_FLAG_CHECK_RESPONSESTATUS = 2, 5.31 }; 5.32 5.33 +/* local variables */ 5.34 static struct data_exchange dataex; 5.35 5.36 /* local function prototypes */ 5.37 -static int vtpm_queue_packet(struct packet *pak); 5.38 static int _packet_write(struct packet *pak, 5.39 - const char *data, size_t size, 5.40 - int userbuffer); 5.41 + const char *data, size_t size, int userbuffer); 5.42 static void processing_timeout(unsigned long ptr); 5.43 -static int packet_read_shmem(struct packet *pak, 5.44 - tpmif_t *tpmif, 5.45 - u32 offset, 5.46 - char *buffer, 5.47 - int isuserbuffer, 5.48 - u32 left); 5.49 - 5.50 +static int packet_read_shmem(struct packet *pak, 5.51 + tpmif_t * tpmif, 5.52 + u32 offset, 5.53 + char *buffer, int isuserbuffer, u32 left); 5.54 +static int vtpm_queue_packet(struct packet *pak); 5.55 5.56 #define MIN(x,y) (x) < (y) ? (x) : (y) 5.57 5.58 - 5.59 /*************************************************************** 5.60 - Buffer copying 5.61 + Buffer copying fo user and kernel space buffes. 5.62 ***************************************************************/ 5.63 -static inline int 5.64 -copy_from_buffer(void *to, 5.65 - const void *from, 5.66 - unsigned long size, 5.67 - int userbuffer) 5.68 +static inline int copy_from_buffer(void *to, 5.69 + const void *from, unsigned long size, 5.70 + int isuserbuffer) 5.71 { 5.72 - if (userbuffer) { 5.73 - if (copy_from_user(to, from, size)) 5.74 + if (isuserbuffer) { 5.75 + if (copy_from_user(to, (void __user *)from, size)) 5.76 + return -EFAULT; 5.77 + } else { 5.78 + memcpy(to, from, size); 5.79 + } 5.80 + return 0; 5.81 +} 5.82 + 5.83 +static inline int copy_to_buffer(void *to, 5.84 + const void *from, unsigned long size, 5.85 + int isuserbuffer) 5.86 +{ 5.87 + if (isuserbuffer) { 5.88 + if (copy_to_user((void __user *)to, from, size)) 5.89 return -EFAULT; 5.90 } else { 5.91 memcpy(to, from, size); 5.92 @@ -91,17 +104,19 @@ copy_from_buffer(void *to, 5.93 Packet-related functions 5.94 ***************************************************************/ 5.95 5.96 -static struct packet * 5.97 -packet_find_instance(struct list_head *head, u32 tpm_instance) 5.98 +static struct packet *packet_find_instance(struct list_head *head, 5.99 + u32 tpm_instance) 5.100 { 5.101 struct packet *pak; 5.102 struct list_head *p; 5.103 + 5.104 /* 5.105 * traverse the list of packets and return the first 5.106 * one with the given instance number 5.107 */ 5.108 list_for_each(p, head) { 5.109 pak = list_entry(p, struct packet, next); 5.110 + 5.111 if (pak->tpm_instance == tpm_instance) { 5.112 return pak; 5.113 } 5.114 @@ -109,17 +124,18 @@ packet_find_instance(struct list_head *h 5.115 return NULL; 5.116 } 5.117 5.118 -static struct packet * 5.119 -packet_find_packet(struct list_head *head, void *packet) 5.120 +static struct packet *packet_find_packet(struct list_head *head, void *packet) 5.121 { 5.122 struct packet *pak; 5.123 struct list_head *p; 5.124 + 5.125 /* 5.126 * traverse the list of packets and return the first 5.127 * one with the given instance number 5.128 */ 5.129 list_for_each(p, head) { 5.130 pak = list_entry(p, struct packet, next); 5.131 + 5.132 if (pak == packet) { 5.133 return pak; 5.134 } 5.135 @@ -127,22 +143,20 @@ packet_find_packet(struct list_head *hea 5.136 return NULL; 5.137 } 5.138 5.139 -static struct packet * 5.140 -packet_alloc(tpmif_t *tpmif, u32 size, u8 req_tag, u8 flags) 5.141 +static struct packet *packet_alloc(tpmif_t * tpmif, 5.142 + u32 size, u8 req_tag, u8 flags) 5.143 { 5.144 struct packet *pak = NULL; 5.145 - pak = kmalloc(sizeof(struct packet), 5.146 - GFP_KERNEL); 5.147 + pak = kzalloc(sizeof (struct packet), GFP_KERNEL); 5.148 if (NULL != pak) { 5.149 - memset(pak, 0x0, sizeof(*pak)); 5.150 if (tpmif) { 5.151 pak->tpmif = tpmif; 5.152 pak->tpm_instance = tpmif->tpm_instance; 5.153 } 5.154 - pak->data_len = size; 5.155 - pak->req_tag = req_tag; 5.156 + pak->data_len = size; 5.157 + pak->req_tag = req_tag; 5.158 pak->last_read = 0; 5.159 - pak->flags = flags; 5.160 + pak->flags = flags; 5.161 5.162 /* 5.163 * cannot do tpmif_get(tpmif); bad things happen 5.164 @@ -155,16 +169,16 @@ packet_alloc(tpmif_t *tpmif, u32 size, u 5.165 return pak; 5.166 } 5.167 5.168 -static void inline 5.169 -packet_reset(struct packet *pak) 5.170 +static void inline packet_reset(struct packet *pak) 5.171 { 5.172 pak->last_read = 0; 5.173 } 5.174 5.175 -static void inline 5.176 -packet_free(struct packet *pak) 5.177 +static void packet_free(struct packet *pak) 5.178 { 5.179 - del_singleshot_timer_sync(&pak->processing_timer); 5.180 + if (timer_pending(&pak->processing_timer)) { 5.181 + BUG(); 5.182 + } 5.183 kfree(pak->data_buffer); 5.184 /* 5.185 * cannot do tpmif_put(pak->tpmif); bad things happen 5.186 @@ -173,13 +187,13 @@ packet_free(struct packet *pak) 5.187 kfree(pak); 5.188 } 5.189 5.190 -static int 5.191 -packet_set(struct packet *pak, 5.192 - const unsigned char *buffer, u32 size) 5.193 +static int packet_set(struct packet *pak, 5.194 + const unsigned char *buffer, u32 size) 5.195 { 5.196 int rc = 0; 5.197 unsigned char *buf = kmalloc(size, GFP_KERNEL); 5.198 - if (NULL != buf) { 5.199 + 5.200 + if (buf) { 5.201 pak->data_buffer = buf; 5.202 memcpy(buf, buffer, size); 5.203 pak->data_len = size; 5.204 @@ -189,27 +203,21 @@ packet_set(struct packet *pak, 5.205 return rc; 5.206 } 5.207 5.208 - 5.209 /* 5.210 * Write data to the shared memory and send it to the FE. 5.211 */ 5.212 -static int 5.213 -packet_write(struct packet *pak, 5.214 - const char *data, size_t size, 5.215 - int userbuffer) 5.216 +static int packet_write(struct packet *pak, 5.217 + const char *data, size_t size, int isuserbuffer) 5.218 { 5.219 int rc = 0; 5.220 5.221 - DPRINTK("Supposed to send %d bytes to front-end!\n", 5.222 - size); 5.223 - 5.224 - if (0 != (pak->flags & PACKET_FLAG_CHECK_RESPONSESTATUS)) { 5.225 + if ((pak->flags & PACKET_FLAG_CHECK_RESPONSESTATUS)) { 5.226 #ifdef CONFIG_XEN_TPMDEV_CLOSE_IF_VTPM_FAILS 5.227 u32 res; 5.228 + 5.229 if (copy_from_buffer(&res, 5.230 - &data[2+4], 5.231 - sizeof(res), 5.232 - userbuffer)) { 5.233 + &data[2 + 4], sizeof (res), 5.234 + isuserbuffer)) { 5.235 return -EFAULT; 5.236 } 5.237 5.238 @@ -230,17 +238,14 @@ packet_write(struct packet *pak, 5.239 /* Don't send a respone to this packet. Just acknowledge it. */ 5.240 rc = size; 5.241 } else { 5.242 - rc = _packet_write(pak, data, size, userbuffer); 5.243 + rc = _packet_write(pak, data, size, isuserbuffer); 5.244 } 5.245 5.246 return rc; 5.247 } 5.248 5.249 - 5.250 -static int 5.251 -_packet_write(struct packet *pak, 5.252 - const char *data, size_t size, 5.253 - int userbuffer) 5.254 +int _packet_write(struct packet *pak, 5.255 + const char *data, size_t size, int isuserbuffer) 5.256 { 5.257 /* 5.258 * Write into the shared memory pages directly 5.259 @@ -254,7 +259,7 @@ static int 5.260 5.261 if (tpmif == NULL) { 5.262 return -EFAULT; 5.263 - } 5.264 + } 5.265 5.266 if (tpmif->status == DISCONNECTED) { 5.267 return size; 5.268 @@ -273,16 +278,13 @@ static int 5.269 return 0; 5.270 } 5.271 5.272 - map_op.host_addr = MMAP_VADDR(tpmif, i); 5.273 - map_op.flags = GNTMAP_host_map; 5.274 - map_op.ref = tx->ref; 5.275 - map_op.dom = tpmif->domid; 5.276 + map_op.host_addr = MMAP_VADDR(tpmif, i); 5.277 + map_op.flags = GNTMAP_host_map; 5.278 + map_op.ref = tx->ref; 5.279 + map_op.dom = tpmif->domid; 5.280 5.281 - if(unlikely( 5.282 - HYPERVISOR_grant_table_op( 5.283 - GNTTABOP_map_grant_ref, 5.284 - &map_op, 5.285 - 1))) { 5.286 + if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, 5.287 + &map_op, 1))) { 5.288 BUG(); 5.289 } 5.290 5.291 @@ -292,28 +294,27 @@ static int 5.292 DPRINTK(" Grant table operation failure !\n"); 5.293 return 0; 5.294 } 5.295 - set_phys_to_machine(__pa(MMAP_VADDR(tpmif,i)) >> PAGE_SHIFT, 5.296 - FOREIGN_FRAME(map_op.dev_bus_addr >> PAGE_SHIFT)); 5.297 + set_phys_to_machine(__pa(MMAP_VADDR(tpmif, i)) >> PAGE_SHIFT, 5.298 + FOREIGN_FRAME(map_op. 5.299 + dev_bus_addr >> PAGE_SHIFT)); 5.300 5.301 tocopy = MIN(size - offset, PAGE_SIZE); 5.302 5.303 - if (copy_from_buffer((void *)(MMAP_VADDR(tpmif,i)| 5.304 - (tx->addr & ~PAGE_MASK)), 5.305 - &data[offset], 5.306 - tocopy, 5.307 - userbuffer)) { 5.308 + if (copy_from_buffer((void *)(MMAP_VADDR(tpmif, i) | 5.309 + (tx->addr & ~PAGE_MASK)), 5.310 + &data[offset], tocopy, isuserbuffer)) { 5.311 tpmif_put(tpmif); 5.312 return -EFAULT; 5.313 } 5.314 tx->size = tocopy; 5.315 5.316 - unmap_op.host_addr = MMAP_VADDR(tpmif, i); 5.317 - unmap_op.handle = handle; 5.318 + unmap_op.host_addr = MMAP_VADDR(tpmif, i); 5.319 + unmap_op.handle = handle; 5.320 unmap_op.dev_bus_addr = 0; 5.321 5.322 - if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, 5.323 - &unmap_op, 5.324 - 1))) { 5.325 + if (unlikely 5.326 + (HYPERVISOR_grant_table_op 5.327 + (GNTTABOP_unmap_grant_ref, &unmap_op, 1))) { 5.328 BUG(); 5.329 } 5.330 5.331 @@ -322,8 +323,7 @@ static int 5.332 } 5.333 5.334 rc = offset; 5.335 - DPRINTK("Notifying frontend via irq %d\n", 5.336 - tpmif->irq); 5.337 + DPRINTK("Notifying frontend via irq %d\n", tpmif->irq); 5.338 notify_remote_via_irq(tpmif->irq); 5.339 5.340 return rc; 5.341 @@ -334,26 +334,19 @@ static int 5.342 * provided buffer. Advance the read_last indicator which tells 5.343 * how many bytes have already been read. 5.344 */ 5.345 -static int 5.346 -packet_read(struct packet *pak, size_t numbytes, 5.347 - char *buffer, size_t buffersize, 5.348 - int userbuffer) 5.349 +static int packet_read(struct packet *pak, size_t numbytes, 5.350 + char *buffer, size_t buffersize, int isuserbuffer) 5.351 { 5.352 tpmif_t *tpmif = pak->tpmif; 5.353 + 5.354 /* 5.355 - * I am supposed to read 'numbytes' of data from the 5.356 - * buffer. 5.357 - * The first 4 bytes that are read are the instance number in 5.358 - * network byte order, after that comes the data from the 5.359 - * shared memory buffer. 5.360 + * Read 'numbytes' of data from the buffer. The first 4 5.361 + * bytes are the instance number in network byte order, 5.362 + * after that come the data from the shared memory buffer. 5.363 */ 5.364 u32 to_copy; 5.365 u32 offset = 0; 5.366 u32 room_left = buffersize; 5.367 - /* 5.368 - * Ensure that we see the request when we copy it. 5.369 - */ 5.370 - mb(); 5.371 5.372 if (pak->last_read < 4) { 5.373 /* 5.374 @@ -361,18 +354,13 @@ packet_read(struct packet *pak, size_t n 5.375 */ 5.376 u32 instance_no = htonl(pak->tpm_instance); 5.377 u32 last_read = pak->last_read; 5.378 + 5.379 to_copy = MIN(4 - last_read, numbytes); 5.380 5.381 - if (userbuffer) { 5.382 - if (copy_to_user(&buffer[0], 5.383 - &(((u8 *)&instance_no)[last_read]), 5.384 - to_copy)) { 5.385 - return -EFAULT; 5.386 - } 5.387 - } else { 5.388 - memcpy(&buffer[0], 5.389 - &(((u8 *)&instance_no)[last_read]), 5.390 - to_copy); 5.391 + if (copy_to_buffer(&buffer[0], 5.392 + &(((u8 *) & instance_no)[last_read]), 5.393 + to_copy, isuserbuffer)) { 5.394 + return -EFAULT; 5.395 } 5.396 5.397 pak->last_read += to_copy; 5.398 @@ -388,39 +376,30 @@ packet_read(struct packet *pak, size_t n 5.399 if (pak->data_buffer) { 5.400 u32 to_copy = MIN(pak->data_len - offset, room_left); 5.401 u32 last_read = pak->last_read - 4; 5.402 - if (userbuffer) { 5.403 - if (copy_to_user(&buffer[offset], 5.404 - &pak->data_buffer[last_read], 5.405 - to_copy)) { 5.406 - return -EFAULT; 5.407 - } 5.408 - } else { 5.409 - memcpy(&buffer[offset], 5.410 - &pak->data_buffer[last_read], 5.411 - to_copy); 5.412 + 5.413 + if (copy_to_buffer(&buffer[offset], 5.414 + &pak->data_buffer[last_read], 5.415 + to_copy, isuserbuffer)) { 5.416 + return -EFAULT; 5.417 } 5.418 pak->last_read += to_copy; 5.419 offset += to_copy; 5.420 } else { 5.421 offset = packet_read_shmem(pak, 5.422 - tpmif, 5.423 - offset, 5.424 - buffer, 5.425 - userbuffer, 5.426 - room_left); 5.427 + tpmif, 5.428 + offset, 5.429 + buffer, 5.430 + isuserbuffer, room_left); 5.431 } 5.432 } 5.433 return offset; 5.434 } 5.435 5.436 - 5.437 -static int 5.438 -packet_read_shmem(struct packet *pak, 5.439 - tpmif_t *tpmif, 5.440 - u32 offset, 5.441 - char *buffer, 5.442 - int isuserbuffer, 5.443 - u32 room_left) { 5.444 +static int packet_read_shmem(struct packet *pak, 5.445 + tpmif_t * tpmif, 5.446 + u32 offset, char *buffer, int isuserbuffer, 5.447 + u32 room_left) 5.448 +{ 5.449 u32 last_read = pak->last_read - 4; 5.450 u32 i = (last_read / PAGE_SIZE); 5.451 u32 pg_offset = last_read & (PAGE_SIZE - 1); 5.452 @@ -428,6 +407,7 @@ packet_read_shmem(struct packet *pak, 5.453 grant_handle_t handle; 5.454 5.455 tpmif_tx_request_t *tx; 5.456 + 5.457 tx = &tpmif->tx->ring[0].req; 5.458 /* 5.459 * Start copying data at the page with index 'index' 5.460 @@ -443,13 +423,12 @@ packet_read_shmem(struct packet *pak, 5.461 tx = &tpmif->tx->ring[i].req; 5.462 5.463 map_op.host_addr = MMAP_VADDR(tpmif, i); 5.464 - map_op.flags = GNTMAP_host_map; 5.465 - map_op.ref = tx->ref; 5.466 - map_op.dom = tpmif->domid; 5.467 + map_op.flags = GNTMAP_host_map; 5.468 + map_op.ref = tx->ref; 5.469 + map_op.dom = tpmif->domid; 5.470 5.471 - if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, 5.472 - &map_op, 5.473 - 1))) { 5.474 + if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, 5.475 + &map_op, 1))) { 5.476 BUG(); 5.477 } 5.478 5.479 @@ -462,41 +441,33 @@ packet_read_shmem(struct packet *pak, 5.480 5.481 if (to_copy > tx->size) { 5.482 /* 5.483 - * This is the case when the user wants to read more 5.484 - * than what we have. So we just give him what we 5.485 - * have. 5.486 + * User requests more than what's available 5.487 */ 5.488 to_copy = MIN(tx->size, to_copy); 5.489 } 5.490 5.491 DPRINTK("Copying from mapped memory at %08lx\n", 5.492 - (unsigned long)(MMAP_VADDR(tpmif,i) | 5.493 - (tx->addr & ~PAGE_MASK))); 5.494 + (unsigned long)(MMAP_VADDR(tpmif, i) | 5.495 + (tx->addr & ~PAGE_MASK))); 5.496 5.497 - src = (void *)(MMAP_VADDR(tpmif,i) | ((tx->addr & ~PAGE_MASK) + pg_offset)); 5.498 - if (isuserbuffer) { 5.499 - if (copy_to_user(&buffer[offset], 5.500 - src, 5.501 - to_copy)) { 5.502 - return -EFAULT; 5.503 - } 5.504 - } else { 5.505 - memcpy(&buffer[offset], 5.506 - src, 5.507 - to_copy); 5.508 + src = (void *)(MMAP_VADDR(tpmif, i) | 5.509 + ((tx->addr & ~PAGE_MASK) + pg_offset)); 5.510 + if (copy_to_buffer(&buffer[offset], 5.511 + src, to_copy, isuserbuffer)) { 5.512 + return -EFAULT; 5.513 } 5.514 5.515 + DPRINTK("Data from TPM-FE of domain %d are %d %d %d %d\n", 5.516 + tpmif->domid, buffer[offset], buffer[offset + 1], 5.517 + buffer[offset + 2], buffer[offset + 3]); 5.518 5.519 - DPRINTK("Data from TPM-FE of domain %d are %d %d %d %d\n", 5.520 - tpmif->domid, buffer[offset], buffer[offset+1],buffer[offset+2],buffer[offset+3]); 5.521 - 5.522 - unmap_op.host_addr = MMAP_VADDR(tpmif, i); 5.523 - unmap_op.handle = handle; 5.524 + unmap_op.host_addr = MMAP_VADDR(tpmif, i); 5.525 + unmap_op.handle = handle; 5.526 unmap_op.dev_bus_addr = 0; 5.527 5.528 - if(unlikely(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, 5.529 - &unmap_op, 5.530 - 1))) { 5.531 + if (unlikely 5.532 + (HYPERVISOR_grant_table_op 5.533 + (GNTTABOP_unmap_grant_ref, &unmap_op, 1))) { 5.534 BUG(); 5.535 } 5.536 5.537 @@ -507,7 +478,7 @@ packet_read_shmem(struct packet *pak, 5.538 5.539 to_copy = MIN(PAGE_SIZE, room_left); 5.540 i++; 5.541 - } /* while (to_copy > 0) */ 5.542 + } /* while (to_copy > 0) */ 5.543 /* 5.544 * Adjust the last_read pointer 5.545 */ 5.546 @@ -515,13 +486,11 @@ packet_read_shmem(struct packet *pak, 5.547 return offset; 5.548 } 5.549 5.550 - 5.551 /* ============================================================ 5.552 * The file layer for reading data from this device 5.553 * ============================================================ 5.554 */ 5.555 -static int 5.556 -vtpm_op_open(struct inode *inode, struct file *f) 5.557 +static int vtpm_op_open(struct inode *inode, struct file *f) 5.558 { 5.559 int rc = 0; 5.560 unsigned long flags; 5.561 @@ -536,9 +505,8 @@ vtpm_op_open(struct inode *inode, struct 5.562 return rc; 5.563 } 5.564 5.565 -static ssize_t 5.566 -vtpm_op_read(struct file *file, 5.567 - char __user * data, size_t size, loff_t * offset) 5.568 +static ssize_t vtpm_op_read(struct file *file, 5.569 + char __user * data, size_t size, loff_t * offset) 5.570 { 5.571 int ret_size = -ENODATA; 5.572 struct packet *pak = NULL; 5.573 @@ -549,7 +517,7 @@ vtpm_op_read(struct file *file, 5.574 if (list_empty(&dataex.pending_pak)) { 5.575 write_unlock_irqrestore(&dataex.pak_lock, flags); 5.576 wait_event_interruptible(dataex.wait_queue, 5.577 - !list_empty(&dataex.pending_pak)); 5.578 + !list_empty(&dataex.pending_pak)); 5.579 write_lock_irqsave(&dataex.pak_lock, flags); 5.580 } 5.581 5.582 @@ -561,7 +529,7 @@ vtpm_op_read(struct file *file, 5.583 5.584 DPRINTK("size given by app: %d, available: %d\n", size, left); 5.585 5.586 - ret_size = MIN(size,left); 5.587 + ret_size = MIN(size, left); 5.588 5.589 ret_size = packet_read(pak, ret_size, data, size, 1); 5.590 if (ret_size < 0) { 5.591 @@ -574,7 +542,8 @@ vtpm_op_read(struct file *file, 5.592 DPRINTK("All data from this packet given to app.\n"); 5.593 /* All data given to app */ 5.594 5.595 - del_singleshot_timer_sync(&pak->processing_timer); 5.596 + del_singleshot_timer_sync(&pak-> 5.597 + processing_timer); 5.598 list_del(&pak->next); 5.599 list_add_tail(&pak->next, &dataex.current_pak); 5.600 /* 5.601 @@ -582,7 +551,7 @@ vtpm_op_read(struct file *file, 5.602 * the more time we give the TPM to process the request. 5.603 */ 5.604 mod_timer(&pak->processing_timer, 5.605 - jiffies + (num_frontends * 60 * HZ)); 5.606 + jiffies + (num_frontends * 60 * HZ)); 5.607 dataex.copied_so_far = 0; 5.608 } 5.609 } 5.610 @@ -597,16 +566,15 @@ vtpm_op_read(struct file *file, 5.611 /* 5.612 * Write operation - only works after a previous read operation! 5.613 */ 5.614 -static ssize_t 5.615 -vtpm_op_write(struct file *file, const char __user * data, size_t size, 5.616 - loff_t * offset) 5.617 +static ssize_t vtpm_op_write(struct file *file, 5.618 + const char __user * data, size_t size, 5.619 + loff_t * offset) 5.620 { 5.621 struct packet *pak; 5.622 int rc = 0; 5.623 unsigned int off = 4; 5.624 unsigned long flags; 5.625 - u32 instance_no = 0; 5.626 - u32 len_no = 0; 5.627 + struct vtpm_resp_hdr vrh; 5.628 5.629 /* 5.630 * Minimum required packet size is: 5.631 @@ -616,45 +584,38 @@ vtpm_op_write(struct file *file, const c 5.632 * 4 bytes for the ordinal 5.633 * sum: 14 bytes 5.634 */ 5.635 - if ( size < off + 10 ) { 5.636 + if (size < sizeof (vrh)) 5.637 return -EFAULT; 5.638 - } 5.639 + 5.640 + if (copy_from_user(&vrh, data, sizeof (vrh))) 5.641 + return -EFAULT; 5.642 5.643 - if (copy_from_user(&instance_no, 5.644 - (void __user *)&data[0], 5.645 - 4)) { 5.646 + /* malformed packet? */ 5.647 + if ((off + ntohl(vrh.len_no)) != size) 5.648 + return -EFAULT; 5.649 + 5.650 + write_lock_irqsave(&dataex.pak_lock, flags); 5.651 + pak = packet_find_instance(&dataex.current_pak, 5.652 + ntohl(vrh.instance_no)); 5.653 + 5.654 + if (pak == NULL) { 5.655 + write_unlock_irqrestore(&dataex.pak_lock, flags); 5.656 + printk(KERN_ALERT "No associated packet! (inst=%d)\n", 5.657 + ntohl(vrh.instance_no)); 5.658 return -EFAULT; 5.659 } 5.660 5.661 - if (copy_from_user(&len_no, 5.662 - (void __user *)&data[off+2], 5.663 - 4) || 5.664 - (off + ntohl(len_no) != size)) { 5.665 - return -EFAULT; 5.666 - } 5.667 - 5.668 - write_lock_irqsave(&dataex.pak_lock, flags); 5.669 - pak = packet_find_instance(&dataex.current_pak, ntohl(instance_no)); 5.670 - 5.671 - if (pak == NULL) { 5.672 - write_unlock_irqrestore(&dataex.pak_lock, flags); 5.673 - printk(KERN_ALERT "No associated packet!\n"); 5.674 - return -EFAULT; 5.675 - } else { 5.676 - del_singleshot_timer_sync(&pak->processing_timer); 5.677 - list_del(&pak->next); 5.678 - } 5.679 + del_singleshot_timer_sync(&pak->processing_timer); 5.680 + list_del(&pak->next); 5.681 5.682 write_unlock_irqrestore(&dataex.pak_lock, flags); 5.683 5.684 /* 5.685 - * The first 'offset' bytes must be the instance number. 5.686 - * I will just pull that from the packet. 5.687 + * The first 'offset' bytes must be the instance number - skip them. 5.688 */ 5.689 size -= off; 5.690 - data = &data[off]; 5.691 5.692 - rc = packet_write(pak, data, size, 1); 5.693 + rc = packet_write(pak, &data[off], size, 1); 5.694 5.695 if (rc > 0) { 5.696 /* I neglected the first 4 bytes */ 5.697 @@ -664,10 +625,10 @@ vtpm_op_write(struct file *file, const c 5.698 return rc; 5.699 } 5.700 5.701 -static int 5.702 -vtpm_op_release(struct inode *inode, struct file *file) 5.703 +static int vtpm_op_release(struct inode *inode, struct file *file) 5.704 { 5.705 unsigned long flags; 5.706 + 5.707 vtpm_release_packets(NULL, 1); 5.708 write_lock_irqsave(&dataex.pak_lock, flags); 5.709 dataex.has_opener = 0; 5.710 @@ -675,10 +636,11 @@ vtpm_op_release(struct inode *inode, str 5.711 return 0; 5.712 } 5.713 5.714 -static unsigned int 5.715 -vtpm_op_poll(struct file *file, struct poll_table_struct *pts) 5.716 +static unsigned int vtpm_op_poll(struct file *file, 5.717 + struct poll_table_struct *pts) 5.718 { 5.719 unsigned int flags = POLLOUT | POLLWRNORM; 5.720 + 5.721 poll_wait(file, &dataex.wait_queue, pts); 5.722 if (!list_empty(&dataex.pending_pak)) { 5.723 flags |= POLLIN | POLLRDNORM; 5.724 @@ -696,54 +658,47 @@ static struct file_operations vtpm_ops = 5.725 .poll = vtpm_op_poll, 5.726 }; 5.727 5.728 -static struct miscdevice ibmvtpms_miscdevice = { 5.729 +static struct miscdevice vtpms_miscdevice = { 5.730 .minor = 225, 5.731 .name = "vtpm", 5.732 .fops = &vtpm_ops, 5.733 }; 5.734 5.735 - 5.736 /*************************************************************** 5.737 Virtual TPM functions and data stuctures 5.738 ***************************************************************/ 5.739 5.740 static u8 create_cmd[] = { 5.741 - 1,193, /* 0: TPM_TAG_RQU_COMMAMD */ 5.742 - 0,0,0,19, /* 2: length */ 5.743 - 0,0,0,0x1, /* 6: VTPM_ORD_OPEN */ 5.744 - 0, /* 10: VTPM type */ 5.745 - 0,0,0,0, /* 11: domain id */ 5.746 - 0,0,0,0 /* 15: instance id */ 5.747 + 1, 193, /* 0: TPM_TAG_RQU_COMMAMD */ 5.748 + 0, 0, 0, 19, /* 2: length */ 5.749 + 0, 0, 0, 0x1, /* 6: VTPM_ORD_OPEN */ 5.750 + 0, /* 10: VTPM type */ 5.751 + 0, 0, 0, 0, /* 11: domain id */ 5.752 + 0, 0, 0, 0 /* 15: instance id */ 5.753 }; 5.754 5.755 -static u8 destroy_cmd[] = { 5.756 - 1,193, /* 0: TPM_TAG_RQU_COMMAMD */ 5.757 - 0,0,0,14, /* 2: length */ 5.758 - 0,0,0,0x2, /* 6: VTPM_ORD_CLOSE */ 5.759 - 0,0,0,0 /* 10: instance id */ 5.760 -}; 5.761 - 5.762 -int tpmif_vtpm_open(tpmif_t *tpmif, domid_t domid, u32 instance) 5.763 +int tpmif_vtpm_open(tpmif_t * tpmif, domid_t domid, u32 instance) 5.764 { 5.765 int rc = 0; 5.766 struct packet *pak; 5.767 5.768 pak = packet_alloc(tpmif, 5.769 - sizeof(create_cmd), 5.770 - create_cmd[0], 5.771 - PACKET_FLAG_DISCARD_RESPONSE| 5.772 - PACKET_FLAG_CHECK_RESPONSESTATUS); 5.773 + sizeof (create_cmd), 5.774 + create_cmd[1], 5.775 + PACKET_FLAG_DISCARD_RESPONSE | 5.776 + PACKET_FLAG_CHECK_RESPONSESTATUS); 5.777 if (pak) { 5.778 - u8 buf[sizeof(create_cmd)]; 5.779 - u32 domid_no = htonl((u32)domid); 5.780 + u8 buf[sizeof (create_cmd)]; 5.781 + u32 domid_no = htonl((u32) domid); 5.782 u32 instance_no = htonl(instance); 5.783 - memcpy(buf, create_cmd, sizeof(create_cmd)); 5.784 + 5.785 + memcpy(buf, create_cmd, sizeof (create_cmd)); 5.786 5.787 - memcpy(&buf[11], &domid_no, sizeof(u32)); 5.788 - memcpy(&buf[15], &instance_no, sizeof(u32)); 5.789 + memcpy(&buf[11], &domid_no, sizeof (u32)); 5.790 + memcpy(&buf[15], &instance_no, sizeof (u32)); 5.791 5.792 /* copy the buffer into the packet */ 5.793 - rc = packet_set(pak, buf, sizeof(buf)); 5.794 + rc = packet_set(pak, buf, sizeof (buf)); 5.795 5.796 if (rc == 0) { 5.797 pak->tpm_instance = 0; 5.798 @@ -759,23 +714,30 @@ int tpmif_vtpm_open(tpmif_t *tpmif, domi 5.799 return rc; 5.800 } 5.801 5.802 +static u8 destroy_cmd[] = { 5.803 + 1, 193, /* 0: TPM_TAG_RQU_COMMAMD */ 5.804 + 0, 0, 0, 14, /* 2: length */ 5.805 + 0, 0, 0, 0x2, /* 6: VTPM_ORD_CLOSE */ 5.806 + 0, 0, 0, 0 /* 10: instance id */ 5.807 +}; 5.808 + 5.809 int tpmif_vtpm_close(u32 instid) 5.810 { 5.811 int rc = 0; 5.812 struct packet *pak; 5.813 5.814 pak = packet_alloc(NULL, 5.815 - sizeof(create_cmd), 5.816 - create_cmd[0], 5.817 - PACKET_FLAG_DISCARD_RESPONSE); 5.818 + sizeof (destroy_cmd), 5.819 + destroy_cmd[1], PACKET_FLAG_DISCARD_RESPONSE); 5.820 if (pak) { 5.821 - u8 buf[sizeof(destroy_cmd)]; 5.822 + u8 buf[sizeof (destroy_cmd)]; 5.823 u32 instid_no = htonl(instid); 5.824 - memcpy(buf, destroy_cmd, sizeof(destroy_cmd)); 5.825 - memcpy(&buf[10], &instid_no, sizeof(u32)); 5.826 + 5.827 + memcpy(buf, destroy_cmd, sizeof (destroy_cmd)); 5.828 + memcpy(&buf[10], &instid_no, sizeof (u32)); 5.829 5.830 /* copy the buffer into the packet */ 5.831 - rc = packet_set(pak, buf, sizeof(buf)); 5.832 + rc = packet_set(pak, buf, sizeof (buf)); 5.833 5.834 if (rc == 0) { 5.835 pak->tpm_instance = 0; 5.836 @@ -791,23 +753,22 @@ int tpmif_vtpm_close(u32 instid) 5.837 return rc; 5.838 } 5.839 5.840 - 5.841 /*************************************************************** 5.842 Utility functions 5.843 ***************************************************************/ 5.844 5.845 -static int 5.846 -tpm_send_fail_message(struct packet *pak, u8 req_tag) 5.847 +static int tpm_send_fail_message(struct packet *pak, u8 req_tag) 5.848 { 5.849 int rc; 5.850 static const unsigned char tpm_error_message_fail[] = { 5.851 0x00, 0x00, 5.852 0x00, 0x00, 0x00, 0x0a, 5.853 - 0x00, 0x00, 0x00, 0x09 /* TPM_FAIL */ 5.854 + 0x00, 0x00, 0x00, 0x09 /* TPM_FAIL */ 5.855 }; 5.856 - unsigned char buffer[sizeof(tpm_error_message_fail)]; 5.857 + unsigned char buffer[sizeof (tpm_error_message_fail)]; 5.858 5.859 - memcpy(buffer, tpm_error_message_fail, sizeof(tpm_error_message_fail)); 5.860 + memcpy(buffer, tpm_error_message_fail, 5.861 + sizeof (tpm_error_message_fail)); 5.862 /* 5.863 * Insert the right response tag depending on the given tag 5.864 * All response tags are '+3' to the request tag. 5.865 @@ -817,23 +778,24 @@ tpm_send_fail_message(struct packet *pak 5.866 /* 5.867 * Write the data to shared memory and notify the front-end 5.868 */ 5.869 - rc = packet_write(pak, buffer, sizeof(buffer), 0); 5.870 + rc = packet_write(pak, buffer, sizeof (buffer), 0); 5.871 5.872 return rc; 5.873 } 5.874 5.875 - 5.876 -static void 5.877 -_vtpm_release_packets(struct list_head *head, tpmif_t *tpmif, 5.878 - int send_msgs) 5.879 +static void _vtpm_release_packets(struct list_head *head, 5.880 + tpmif_t * tpmif, int send_msgs) 5.881 { 5.882 struct packet *pak; 5.883 - struct list_head *pos, *tmp; 5.884 + struct list_head *pos, 5.885 + *tmp; 5.886 5.887 list_for_each_safe(pos, tmp, head) { 5.888 pak = list_entry(pos, struct packet, next); 5.889 + 5.890 if (tpmif == NULL || pak->tpmif == tpmif) { 5.891 int can_send = 0; 5.892 + 5.893 del_singleshot_timer_sync(&pak->processing_timer); 5.894 list_del(&pak->next); 5.895 5.896 @@ -849,9 +811,7 @@ static void 5.897 } 5.898 } 5.899 5.900 - 5.901 -int 5.902 -vtpm_release_packets(tpmif_t *tpmif, int send_msgs) 5.903 +int vtpm_release_packets(tpmif_t * tpmif, int send_msgs) 5.904 { 5.905 unsigned long flags; 5.906 5.907 @@ -860,23 +820,22 @@ vtpm_release_packets(tpmif_t *tpmif, int 5.908 _vtpm_release_packets(&dataex.pending_pak, tpmif, send_msgs); 5.909 _vtpm_release_packets(&dataex.current_pak, tpmif, send_msgs); 5.910 5.911 - write_unlock_irqrestore(&dataex.pak_lock, 5.912 - flags); 5.913 + write_unlock_irqrestore(&dataex.pak_lock, flags); 5.914 return 0; 5.915 } 5.916 5.917 - 5.918 static int vtpm_queue_packet(struct packet *pak) 5.919 { 5.920 int rc = 0; 5.921 + 5.922 if (dataex.has_opener) { 5.923 unsigned long flags; 5.924 + 5.925 write_lock_irqsave(&dataex.pak_lock, flags); 5.926 list_add_tail(&pak->next, &dataex.pending_pak); 5.927 /* give the TPM some time to pick up the request */ 5.928 mod_timer(&pak->processing_timer, jiffies + (30 * HZ)); 5.929 - write_unlock_irqrestore(&dataex.pak_lock, 5.930 - flags); 5.931 + write_unlock_irqrestore(&dataex.pak_lock, flags); 5.932 5.933 wake_up_interruptible(&dataex.wait_queue); 5.934 } else { 5.935 @@ -885,24 +844,22 @@ static int vtpm_queue_packet(struct pack 5.936 return rc; 5.937 } 5.938 5.939 - 5.940 -static int vtpm_receive(tpmif_t *tpmif, u32 size) 5.941 +static int vtpm_receive(tpmif_t * tpmif, u32 size) 5.942 { 5.943 int rc = 0; 5.944 unsigned char buffer[10]; 5.945 __be32 *native_size; 5.946 + struct packet *pak = packet_alloc(tpmif, size, 0, 0); 5.947 5.948 - struct packet *pak = packet_alloc(tpmif, size, buffer[4], 0); 5.949 - if (NULL == pak) { 5.950 + if (!pak) 5.951 return -ENOMEM; 5.952 - } 5.953 /* 5.954 * Read 10 bytes from the received buffer to test its 5.955 * content for validity. 5.956 */ 5.957 - if (sizeof(buffer) != packet_read(pak, 5.958 - sizeof(buffer), buffer, 5.959 - sizeof(buffer), 0)) { 5.960 + if (sizeof (buffer) != packet_read(pak, 5.961 + sizeof (buffer), buffer, 5.962 + sizeof (buffer), 0)) { 5.963 goto failexit; 5.964 } 5.965 /* 5.966 @@ -911,7 +868,7 @@ static int vtpm_receive(tpmif_t *tpmif, 5.967 */ 5.968 packet_reset(pak); 5.969 5.970 - native_size = (__force __be32 *)(&buffer[4+2]); 5.971 + native_size = (__force __be32 *) (&buffer[4 + 2]); 5.972 /* 5.973 * Verify that the size of the packet is correct 5.974 * as indicated and that there's actually someone reading packets. 5.975 @@ -920,26 +877,24 @@ static int vtpm_receive(tpmif_t *tpmif, 5.976 */ 5.977 if (size < 10 || 5.978 be32_to_cpu(*native_size) != size || 5.979 - 0 == dataex.has_opener || 5.980 - tpmif->status != CONNECTED) { 5.981 - rc = -EINVAL; 5.982 - goto failexit; 5.983 + 0 == dataex.has_opener || tpmif->status != CONNECTED) { 5.984 + rc = -EINVAL; 5.985 + goto failexit; 5.986 } else { 5.987 - if ((rc = vtpm_queue_packet(pak)) < 0) { 5.988 + rc = vtpm_queue_packet(pak); 5.989 + if (rc < 0) 5.990 goto failexit; 5.991 - } 5.992 } 5.993 return 0; 5.994 5.995 -failexit: 5.996 + failexit: 5.997 if (pak) { 5.998 - tpm_send_fail_message(pak, buffer[4+1]); 5.999 + tpm_send_fail_message(pak, buffer[4 + 1]); 5.1000 packet_free(pak); 5.1001 } 5.1002 return rc; 5.1003 } 5.1004 5.1005 - 5.1006 /* 5.1007 * Timeout function that gets invoked when a packet has not been processed 5.1008 * during the timeout period. 5.1009 @@ -951,44 +906,42 @@ static void processing_timeout(unsigned 5.1010 { 5.1011 struct packet *pak = (struct packet *)ptr; 5.1012 unsigned long flags; 5.1013 + 5.1014 write_lock_irqsave(&dataex.pak_lock, flags); 5.1015 /* 5.1016 * The packet needs to be searched whether it 5.1017 * is still on the list. 5.1018 */ 5.1019 if (pak == packet_find_packet(&dataex.pending_pak, pak) || 5.1020 - pak == packet_find_packet(&dataex.current_pak, pak) ) { 5.1021 + pak == packet_find_packet(&dataex.current_pak, pak)) { 5.1022 list_del(&pak->next); 5.1023 - tpm_send_fail_message(pak, pak->req_tag); 5.1024 + if ((pak->flags & PACKET_FLAG_DISCARD_RESPONSE) == 0) { 5.1025 + tpm_send_fail_message(pak, pak->req_tag); 5.1026 + } 5.1027 packet_free(pak); 5.1028 } 5.1029 5.1030 write_unlock_irqrestore(&dataex.pak_lock, flags); 5.1031 } 5.1032 5.1033 - 5.1034 - 5.1035 static void tpm_tx_action(unsigned long unused); 5.1036 static DECLARE_TASKLET(tpm_tx_tasklet, tpm_tx_action, 0); 5.1037 5.1038 static struct list_head tpm_schedule_list; 5.1039 static spinlock_t tpm_schedule_list_lock; 5.1040 5.1041 -static inline void 5.1042 -maybe_schedule_tx_action(void) 5.1043 +static inline void maybe_schedule_tx_action(void) 5.1044 { 5.1045 smp_mb(); 5.1046 tasklet_schedule(&tpm_tx_tasklet); 5.1047 } 5.1048 5.1049 -static inline int 5.1050 -__on_tpm_schedule_list(tpmif_t * tpmif) 5.1051 +static inline int __on_tpm_schedule_list(tpmif_t * tpmif) 5.1052 { 5.1053 return tpmif->list.next != NULL; 5.1054 } 5.1055 5.1056 -static void 5.1057 -remove_from_tpm_schedule_list(tpmif_t * tpmif) 5.1058 +static void remove_from_tpm_schedule_list(tpmif_t * tpmif) 5.1059 { 5.1060 spin_lock_irq(&tpm_schedule_list_lock); 5.1061 if (likely(__on_tpm_schedule_list(tpmif))) { 5.1062 @@ -999,8 +952,7 @@ remove_from_tpm_schedule_list(tpmif_t * 5.1063 spin_unlock_irq(&tpm_schedule_list_lock); 5.1064 } 5.1065 5.1066 -static void 5.1067 -add_to_tpm_schedule_list_tail(tpmif_t * tpmif) 5.1068 +static void add_to_tpm_schedule_list_tail(tpmif_t * tpmif) 5.1069 { 5.1070 if (__on_tpm_schedule_list(tpmif)) 5.1071 return; 5.1072 @@ -1013,22 +965,18 @@ add_to_tpm_schedule_list_tail(tpmif_t * 5.1073 spin_unlock_irq(&tpm_schedule_list_lock); 5.1074 } 5.1075 5.1076 -void 5.1077 -tpmif_schedule_work(tpmif_t * tpmif) 5.1078 +void tpmif_schedule_work(tpmif_t * tpmif) 5.1079 { 5.1080 add_to_tpm_schedule_list_tail(tpmif); 5.1081 maybe_schedule_tx_action(); 5.1082 } 5.1083 5.1084 -void 5.1085 -tpmif_deschedule_work(tpmif_t * tpmif) 5.1086 +void tpmif_deschedule_work(tpmif_t * tpmif) 5.1087 { 5.1088 remove_from_tpm_schedule_list(tpmif); 5.1089 } 5.1090 5.1091 - 5.1092 -static void 5.1093 -tpm_tx_action(unsigned long unused) 5.1094 +static void tpm_tx_action(unsigned long unused) 5.1095 { 5.1096 struct list_head *ent; 5.1097 tpmif_t *tpmif; 5.1098 @@ -1042,10 +990,6 @@ tpm_tx_action(unsigned long unused) 5.1099 tpmif = list_entry(ent, tpmif_t, list); 5.1100 tpmif_get(tpmif); 5.1101 remove_from_tpm_schedule_list(tpmif); 5.1102 - /* 5.1103 - * Ensure that we see the request when we read from it. 5.1104 - */ 5.1105 - mb(); 5.1106 5.1107 tx = &tpmif->tx->ring[0].req; 5.1108 5.1109 @@ -1056,22 +1000,22 @@ tpm_tx_action(unsigned long unused) 5.1110 } 5.1111 } 5.1112 5.1113 -irqreturn_t 5.1114 -tpmif_be_int(int irq, void *dev_id, struct pt_regs *regs) 5.1115 +irqreturn_t tpmif_be_int(int irq, void *dev_id, struct pt_regs *regs) 5.1116 { 5.1117 - tpmif_t *tpmif = dev_id; 5.1118 + tpmif_t *tpmif = (tpmif_t *) dev_id; 5.1119 + 5.1120 add_to_tpm_schedule_list_tail(tpmif); 5.1121 maybe_schedule_tx_action(); 5.1122 return IRQ_HANDLED; 5.1123 } 5.1124 5.1125 -static int __init 5.1126 -tpmback_init(void) 5.1127 +static int __init tpmback_init(void) 5.1128 { 5.1129 int rc; 5.1130 5.1131 - if ((rc = misc_register(&ibmvtpms_miscdevice)) != 0) { 5.1132 - printk(KERN_ALERT "Could not register misc device for TPM BE.\n"); 5.1133 + if ((rc = misc_register(&vtpms_miscdevice)) != 0) { 5.1134 + printk(KERN_ALERT 5.1135 + "Could not register misc device for TPM BE.\n"); 5.1136 return rc; 5.1137 } 5.1138 5.1139 @@ -1094,13 +1038,11 @@ tpmback_init(void) 5.1140 5.1141 module_init(tpmback_init); 5.1142 5.1143 -static void __exit 5.1144 -tpmback_exit(void) 5.1145 +static void __exit tpmback_exit(void) 5.1146 { 5.1147 - 5.1148 tpmif_xenbus_exit(); 5.1149 tpmif_interface_exit(); 5.1150 - misc_deregister(&ibmvtpms_miscdevice); 5.1151 + misc_deregister(&vtpms_miscdevice); 5.1152 } 5.1153 5.1154 module_exit(tpmback_exit);
6.1 --- a/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Fri Mar 03 15:56:03 2006 +0100 6.2 +++ b/linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c Fri Mar 03 15:56:34 2006 +0100 6.3 @@ -602,7 +602,6 @@ tpm_xmit(struct tpm_private *tp, 6.4 6.5 tx = &tp->tx->ring[i].req; 6.6 6.7 - tx->id = i; 6.8 tx->addr = virt_to_machine(txb->data); 6.9 tx->size = txb->len; 6.10
7.1 --- a/tools/debugger/gdb/gdbbuild Fri Mar 03 15:56:03 2006 +0100 7.2 +++ b/tools/debugger/gdb/gdbbuild Fri Mar 03 15:56:34 2006 +0100 7.3 @@ -1,7 +1,9 @@ 7.4 #!/bin/sh 7.5 7.6 +[ "$GDB_MIRROR" ] || GDB_MIRROR="ftp://ftp.gnu.org/gnu/gdb/" 7.7 + 7.8 rm -rf gdb-6.2.1 gdb-6.2.1-linux-i386-xen 7.9 -[ -a gdb-6.2.1.tar.bz2 ] || wget -c ftp://ftp.gnu.org/gnu/gdb/gdb-6.2.1.tar.bz2 7.10 +[ -a gdb-6.2.1.tar.bz2 ] || wget -c "$GDB_MIRROR/gdb-6.2.1.tar.bz2" 7.11 tar xjf gdb-6.2.1.tar.bz2 7.12 7.13 cd gdb-6.2.1-xen-sparse 7.14 @@ -12,8 +14,10 @@ mkdir gdb-6.2.1-linux-i386-xen 7.15 cd gdb-6.2.1-linux-i386-xen 7.16 ../gdb-6.2.1/configure 7.17 7.18 -# some people don't have gmake 7.19 -if which gmake ; then 7.20 +# Use $MAKE if set, else use gmake if present, otherwise use make 7.21 +if [ "$MAKE" ]; then 7.22 + $MAKE 7.23 +elif which gmake ; then 7.24 gmake -j4 7.25 else 7.26 make -j4
8.1 --- a/tools/firmware/hvmloader/Makefile Fri Mar 03 15:56:03 2006 +0100 8.2 +++ b/tools/firmware/hvmloader/Makefile Fri Mar 03 15:56:34 2006 +0100 8.3 @@ -18,6 +18,9 @@ 8.4 # Place - Suite 330, Boston, MA 02111-1307 USA. 8.5 # 8.6 8.7 +# External CFLAGS can do more harm than good. 8.8 +CFLAGS := 8.9 + 8.10 XEN_ROOT = ../../.. 8.11 include $(XEN_ROOT)/Config.mk 8.12
9.1 --- a/tools/firmware/vmxassist/Makefile Fri Mar 03 15:56:03 2006 +0100 9.2 +++ b/tools/firmware/vmxassist/Makefile Fri Mar 03 15:56:34 2006 +0100 9.3 @@ -18,6 +18,9 @@ 9.4 # Place - Suite 330, Boston, MA 02111-1307 USA. 9.5 # 9.6 9.7 +# External CFLAGS can do more harm than good. 9.8 +CFLAGS := 9.9 + 9.10 XEN_ROOT = ../../.. 9.11 include $(XEN_ROOT)/Config.mk 9.12
10.1 --- a/tools/python/xen/xend/image.py Fri Mar 03 15:56:03 2006 +0100 10.2 +++ b/tools/python/xen/xend/image.py Fri Mar 03 15:56:34 2006 +0100 10.3 @@ -274,6 +274,10 @@ class HVMImageHandler(ImageHandler): 10.4 uname = sxp.child_value(info, 'uname') 10.5 typedev = sxp.child_value(info, 'dev') 10.6 (_, vbdparam) = string.split(uname, ':', 1) 10.7 + 10.8 + if 'file:' in uname and not os.path.isfile(vbdparam): 10.9 + raise VmError('Disk image does not exist: %s' % vbdparam) 10.10 + 10.11 if 'ioemu:' in typedev: 10.12 (emtype, vbddev) = string.split(typedev, ':', 1) 10.13 else:
11.1 --- a/tools/python/xen/xend/server/blkif.py Fri Mar 03 15:56:03 2006 +0100 11.2 +++ b/tools/python/xen/xend/server/blkif.py Fri Mar 03 15:56:34 2006 +0100 11.3 @@ -42,10 +42,6 @@ class BlkifController(DevController): 11.4 """@see DevController.getDeviceDetails""" 11.5 11.6 dev = sxp.child_value(config, 'dev') 11.7 - if 'ioemu:' in dev: 11.8 - return (None,{},{}) 11.9 - 11.10 - devid = blkif.blkdev_name_to_number(dev) 11.11 11.12 (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1) 11.13 back = { 'dev' : dev, 11.14 @@ -54,7 +50,13 @@ class BlkifController(DevController): 11.15 'mode' : sxp.child_value(config, 'mode', 'r') 11.16 } 11.17 11.18 - front = { 'virtual-device' : "%i" % devid } 11.19 + if 'ioemu:' in dev: 11.20 + (dummy, dev1) = string.split(dev, ':', 1) 11.21 + devid = blkif.blkdev_name_to_number(dev1) 11.22 + front = {} 11.23 + else: 11.24 + devid = blkif.blkdev_name_to_number(dev) 11.25 + front = { 'virtual-device' : "%i" % devid } 11.26 11.27 return (devid, back, front) 11.28
12.1 --- a/tools/vtpm_manager/manager/dmictl.c Fri Mar 03 15:56:03 2006 +0100 12.2 +++ b/tools/vtpm_manager/manager/dmictl.c Fri Mar 03 15:56:34 2006 +0100 12.3 @@ -74,7 +74,13 @@ TPM_RESULT close_dmi( VTPM_DMI_RESOURCE 12.4 12.5 close(dmi_res->guest_tx_fh); dmi_res->guest_tx_fh = -1; 12.6 close(dmi_res->vtpm_tx_fh); dmi_res->vtpm_tx_fh = -1; 12.7 - 12.8 + vtpm_globals->connected_dmis--; 12.9 + 12.10 + if (vtpm_globals->connected_dmis == 0) { 12.11 + // No more DMI's connected. Close fifo to prevent a broken pipe. 12.12 + close(vtpm_globals->guest_rx_fh); 12.13 + vtpm_globals->guest_rx_fh = -1; 12.14 + } 12.15 #ifndef MANUAL_DM_LAUNCH 12.16 if (dmi_res->dmi_id != VTPM_CTL_DM) { 12.17 if (dmi_res->dmi_pid != 0) { 12.18 @@ -118,6 +124,7 @@ TPM_RESULT VTPM_Handle_New_DMI( const bu 12.19 status = TPM_BAD_PARAMETER; 12.20 goto abort_egress; 12.21 } else { 12.22 + vtpm_globals->connected_dmis++; // Put this here so we don't count Dom0 12.23 BSG_UnpackList( param_buf->bytes, 3, 12.24 BSG_TYPE_BYTE, &type, 12.25 BSG_TYPE_UINT32, &domain_id,
13.1 --- a/tools/vtpm_manager/manager/securestorage.c Fri Mar 03 15:56:03 2006 +0100 13.2 +++ b/tools/vtpm_manager/manager/securestorage.c Fri Mar 03 15:56:34 2006 +0100 13.3 @@ -307,8 +307,8 @@ TPM_RESULT VTPM_SaveService(void) { 13.4 TPM_RESULT status=TPM_SUCCESS; 13.5 int fh, dmis=-1; 13.6 13.7 - BYTE *flat_boot_key, *flat_dmis, *flat_enc; 13.8 - buffer_t clear_flat_global, enc_flat_global; 13.9 + BYTE *flat_boot_key=NULL, *flat_dmis=NULL, *flat_enc=NULL; 13.10 + buffer_t clear_flat_global=NULL_BUF, enc_flat_global=NULL_BUF; 13.11 UINT32 storageKeySize = buffer_len(&vtpm_globals->storageKeyWrap); 13.12 UINT32 bootKeySize = buffer_len(&vtpm_globals->bootKeyWrap); 13.13 struct pack_buf_t storage_key_pack = {storageKeySize, vtpm_globals->storageKeyWrap.bytes}; 13.14 @@ -328,12 +328,9 @@ TPM_RESULT VTPM_SaveService(void) { 13.15 sizeof(UINT32) +// storagekeysize 13.16 storageKeySize, NULL) ); // storage key 13.17 13.18 - flat_dmis_size = (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0) 13.19 - (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)); // Per DMI info 13.20 13.21 flat_boot_key = (BYTE *) malloc( boot_key_size ); 13.22 flat_enc = (BYTE *) malloc( sizeof(UINT32) ); 13.23 - flat_dmis = (BYTE *) malloc( flat_dmis_size ); 13.24 13.25 boot_key_size = BSG_PackList(flat_boot_key, 1, 13.26 BSG_TPM_SIZE32_DATA, &boot_key_pack); 13.27 @@ -349,9 +346,13 @@ TPM_RESULT VTPM_SaveService(void) { 13.28 13.29 BSG_PackConst(buffer_len(&enc_flat_global), 4, flat_enc); 13.30 13.31 - // Per DMI values to be saved 13.32 + // Per DMI values to be saved (if any exit) 13.33 if (hashtable_count(vtpm_globals->dmi_map) > 0) { 13.34 13.35 + flat_dmis_size = (hashtable_count(vtpm_globals->dmi_map) - 1) * // num DMIS (-1 for Dom0) 13.36 + (sizeof(UINT32) + 2*sizeof(TPM_DIGEST)); // Per DMI info 13.37 + flat_dmis = (BYTE *) malloc( flat_dmis_size ); 13.38 + 13.39 dmi_itr = hashtable_iterator(vtpm_globals->dmi_map); 13.40 do { 13.41 dmi_res = (VTPM_DMI_RESOURCE *) hashtable_iterator_value(dmi_itr);
14.1 --- a/tools/vtpm_manager/manager/vtpm_manager.c Fri Mar 03 15:56:03 2006 +0100 14.2 +++ b/tools/vtpm_manager/manager/vtpm_manager.c Fri Mar 03 15:56:34 2006 +0100 14.3 @@ -754,6 +754,7 @@ TPM_RESULT VTPM_Init_Service() { 14.4 #ifndef VTPM_MULTI_VM 14.5 vtpm_globals->vtpm_rx_fh = -1; 14.6 vtpm_globals->guest_rx_fh = -1; 14.7 + vtpm_globals->connected_dmis = 0; 14.8 #endif 14.9 if ((vtpm_globals->dmi_map = create_hashtable(10, hashfunc32, equals32)) == NULL){ 14.10 status = TPM_FAIL;
15.1 --- a/tools/vtpm_manager/manager/vtpmpriv.h Fri Mar 03 15:56:03 2006 +0100 15.2 +++ b/tools/vtpm_manager/manager/vtpmpriv.h Fri Mar 03 15:56:34 2006 +0100 15.3 @@ -98,6 +98,7 @@ typedef struct tdVTPM_GLOBALS { 15.4 #ifndef VTPM_MULTI_VM 15.5 int vtpm_rx_fh; 15.6 int guest_rx_fh; 15.7 + int connected_dmis; // Used to close guest_rx when no dmis are connected 15.8 15.9 pid_t master_pid; 15.10 #endif
16.1 --- a/xen/arch/ia64/xen/xensetup.c Fri Mar 03 15:56:03 2006 +0100 16.2 +++ b/xen/arch/ia64/xen/xensetup.c Fri Mar 03 15:56:34 2006 +0100 16.3 @@ -12,7 +12,7 @@ 16.4 #include <xen/sched.h> 16.5 #include <xen/mm.h> 16.6 #include <public/version.h> 16.7 -//#include <xen/delay.h> 16.8 +#include <xen/gdbstub.h> 16.9 #include <xen/compile.h> 16.10 #include <xen/console.h> 16.11 #include <xen/serial.h> 16.12 @@ -360,6 +360,8 @@ printk("About to call __cpu_up(%d)\n",i) 16.13 smp_cpus_done(max_cpus); 16.14 #endif 16.15 16.16 + initialise_gdb(); /* could be moved earlier */ 16.17 + 16.18 do_initcalls(); 16.19 printk("About to call sort_main_extable()\n"); 16.20 sort_main_extable();
17.1 --- a/xen/arch/x86/hvm/vioapic.c Fri Mar 03 15:56:03 2006 +0100 17.2 +++ b/xen/arch/x86/hvm/vioapic.c Fri Mar 03 15:56:34 2006 +0100 17.3 @@ -52,20 +52,6 @@ static void ioapic_enable(hvm_vioapic_t 17.4 s->flags &= ~IOAPIC_ENABLE_FLAG; 17.5 } 17.6 17.7 -static void ioapic_dump_redir(hvm_vioapic_t *s, uint8_t entry) 17.8 -{ 17.9 - RedirStatus redir = s->redirtbl[entry]; 17.10 - 17.11 - printk("ioapic_dump_redir entry %x vector %x " 17.12 - "deliver_mod %x destmode %x delivestatus %x " 17.13 - "polarity %x remote_irr %x trigmod %x mask %x dest_id %x\n", 17.14 - entry, redir.RedirForm.vector, redir.RedirForm.deliver_mode, 17.15 - redir.RedirForm.destmode, redir.RedirForm.delivestatus, 17.16 - redir.RedirForm.polarity, redir.RedirForm.remoteirr, 17.17 - redir.RedirForm.trigmod, redir.RedirForm.mask, 17.18 - redir.RedirForm.dest_id); 17.19 -} 17.20 - 17.21 #ifdef HVM_DOMAIN_SAVE_RESTORE 17.22 void ioapic_save(QEMUFile* f, void* opaque) 17.23 { 17.24 @@ -534,7 +520,19 @@ void hvm_vioapic_set_irq(struct domain * 17.25 if (!IOAPICEnabled(s) || s->redirtbl[irq].RedirForm.mask) 17.26 return; 17.27 17.28 - ioapic_dump_redir(s, irq); 17.29 + HVM_DBG_LOG(DBG_LEVEL_IOAPIC, "hvm_vioapic_set_irq entry %x " 17.30 + "vector %x deliver_mod %x destmode %x delivestatus %x " 17.31 + "polarity %x remote_irr %x trigmod %x mask %x dest_id %x\n", 17.32 + irq, 17.33 + s->redirtbl[irq].RedirForm.vector, 17.34 + s->redirtbl[irq].RedirForm.deliver_mode, 17.35 + s->redirtbl[irq].RedirForm.destmode, 17.36 + s->redirtbl[irq].RedirForm.delivestatus, 17.37 + s->redirtbl[irq].RedirForm.polarity, 17.38 + s->redirtbl[irq].RedirForm.remoteirr, 17.39 + s->redirtbl[irq].RedirForm.trigmod, 17.40 + s->redirtbl[irq].RedirForm.mask, 17.41 + s->redirtbl[irq].RedirForm.dest_id); 17.42 17.43 if (irq >= 0 && irq < IOAPIC_NUM_PINS) { 17.44 uint32_t bit = 1 << irq;
18.1 --- a/xen/arch/x86/io_apic.c Fri Mar 03 15:56:03 2006 +0100 18.2 +++ b/xen/arch/x86/io_apic.c Fri Mar 03 15:56:34 2006 +0100 18.3 @@ -1548,8 +1548,9 @@ static inline void check_timer(void) 18.4 */ 18.5 apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT); 18.6 init_8259A(1); 18.7 - timer_ack = 1; 18.8 - enable_8259A_irq(0); 18.9 + /* XEN: Ripped out the legacy missed-tick logic, so below is not needed. */ 18.10 + /*timer_ack = 1;*/ 18.11 + /*enable_8259A_irq(0);*/ 18.12 18.13 pin1 = find_isa_irq_pin(0, mp_INT); 18.14 apic1 = find_isa_irq_apic(0, mp_INT); 18.15 @@ -1617,7 +1618,7 @@ static inline void check_timer(void) 18.16 18.17 printk(KERN_INFO "...trying to set up timer as ExtINT IRQ..."); 18.18 18.19 - timer_ack = 0; 18.20 + /*timer_ack = 0;*/ 18.21 init_8259A(0); 18.22 make_8259A_irq(0); 18.23 apic_write_around(APIC_LVT0, APIC_DM_EXTINT); 18.24 @@ -1633,16 +1634,6 @@ static inline void check_timer(void) 18.25 "report. Then try booting with the 'noapic' option"); 18.26 } 18.27 18.28 -#define NR_IOAPIC_BIOSIDS 256 18.29 -static u8 ioapic_biosid_to_apic_enum[NR_IOAPIC_BIOSIDS]; 18.30 -static void store_ioapic_biosid_mapping(void) 18.31 -{ 18.32 - u8 apic; 18.33 - memset(ioapic_biosid_to_apic_enum, ~0, NR_IOAPIC_BIOSIDS); 18.34 - for ( apic = 0; apic < nr_ioapics; apic++ ) 18.35 - ioapic_biosid_to_apic_enum[mp_ioapics[apic].mpc_apicid] = apic; 18.36 -} 18.37 - 18.38 /* 18.39 * 18.40 * IRQ's that are handled by the PIC in the MPS IOAPIC case. 18.41 @@ -1654,8 +1645,6 @@ static void store_ioapic_biosid_mapping( 18.42 18.43 void __init setup_IO_APIC(void) 18.44 { 18.45 - store_ioapic_biosid_mapping(); 18.46 - 18.47 enable_IO_APIC(); 18.48 18.49 if (acpi_ioapic) 18.50 @@ -1839,50 +1828,45 @@ int io_apic_set_pci_routing (int ioapic, 18.51 18.52 #endif /*CONFIG_ACPI_BOOT*/ 18.53 18.54 - 18.55 -int ioapic_guest_read(int apicid, int address, u32 *pval) 18.56 +static int ioapic_physbase_to_id(unsigned long physbase) 18.57 { 18.58 - u32 val; 18.59 - int apicenum; 18.60 - union IO_APIC_reg_00 reg_00; 18.61 + int apic; 18.62 + for ( apic = 0; apic < nr_ioapics; apic++ ) 18.63 + if ( mp_ioapics[apic].mpc_apicaddr == physbase ) 18.64 + return apic; 18.65 + return -EINVAL; 18.66 +} 18.67 + 18.68 +int ioapic_guest_read(unsigned long physbase, unsigned int reg, u32 *pval) 18.69 +{ 18.70 + int apic; 18.71 unsigned long flags; 18.72 18.73 - if ( (apicid >= NR_IOAPIC_BIOSIDS) || 18.74 - ((apicenum = ioapic_biosid_to_apic_enum[apicid]) >= nr_ioapics) ) 18.75 - return -EINVAL; 18.76 + if ( (apic = ioapic_physbase_to_id(physbase)) < 0 ) 18.77 + return apic; 18.78 18.79 spin_lock_irqsave(&ioapic_lock, flags); 18.80 - val = io_apic_read(apicenum, address); 18.81 + *pval = io_apic_read(apic, reg); 18.82 spin_unlock_irqrestore(&ioapic_lock, flags); 18.83 18.84 - /* Rewrite APIC ID to what the BIOS originally specified. */ 18.85 - if ( address == 0 ) 18.86 - { 18.87 - reg_00.raw = val; 18.88 - reg_00.bits.ID = apicid; 18.89 - val = reg_00.raw; 18.90 - } 18.91 - 18.92 - *pval = val; 18.93 return 0; 18.94 } 18.95 18.96 -int ioapic_guest_write(int apicid, int address, u32 val) 18.97 +int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val) 18.98 { 18.99 - int apicenum, pin, irq; 18.100 + int apic, pin, irq; 18.101 struct IO_APIC_route_entry rte = { 0 }; 18.102 struct irq_pin_list *entry; 18.103 unsigned long flags; 18.104 18.105 - if ( (apicid >= NR_IOAPIC_BIOSIDS) || 18.106 - ((apicenum = ioapic_biosid_to_apic_enum[apicid]) >= nr_ioapics) ) 18.107 - return -EINVAL; 18.108 + if ( (apic = ioapic_physbase_to_id(physbase)) < 0 ) 18.109 + return apic; 18.110 18.111 /* Only write to the first half of a route entry. */ 18.112 - if ( (address < 0x10) || (address & 1) ) 18.113 + if ( (reg < 0x10) || (reg & 1) ) 18.114 return 0; 18.115 18.116 - pin = (address - 0x10) >> 1; 18.117 + pin = (reg - 0x10) >> 1; 18.118 18.119 *(u32 *)&rte = val; 18.120 rte.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS); 18.121 @@ -1898,7 +1882,7 @@ int ioapic_guest_write(int apicid, int a 18.122 if ( rte.delivery_mode > dest_LowestPrio ) 18.123 { 18.124 printk("ERROR: Attempt to write weird IOAPIC destination mode!\n"); 18.125 - printk(" APIC=%d/%d, lo-reg=%x\n", apicid, pin, val); 18.126 + printk(" APIC=%d/%d, lo-reg=%x\n", apic, pin, val); 18.127 return -EINVAL; 18.128 } 18.129 18.130 @@ -1923,19 +1907,19 @@ int ioapic_guest_write(int apicid, int a 18.131 /* Record the pin<->irq mapping. */ 18.132 for ( entry = &irq_2_pin[irq]; ; entry = &irq_2_pin[entry->next] ) 18.133 { 18.134 - if ( (entry->apic == apicenum) && (entry->pin == pin) ) 18.135 + if ( (entry->apic == apic) && (entry->pin == pin) ) 18.136 break; 18.137 if ( !entry->next ) 18.138 { 18.139 - add_pin_to_irq(irq, apicenum, pin); 18.140 + add_pin_to_irq(irq, apic, pin); 18.141 break; 18.142 } 18.143 } 18.144 } 18.145 18.146 spin_lock_irqsave(&ioapic_lock, flags); 18.147 - io_apic_write(apicenum, 0x10 + 2 * pin, *(((int *)&rte) + 0)); 18.148 - io_apic_write(apicenum, 0x11 + 2 * pin, *(((int *)&rte) + 1)); 18.149 + io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&rte) + 0)); 18.150 + io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&rte) + 1)); 18.151 spin_unlock_irqrestore(&ioapic_lock, flags); 18.152 18.153 return 0;
19.1 --- a/xen/arch/x86/physdev.c Fri Mar 03 15:56:03 2006 +0100 19.2 +++ b/xen/arch/x86/physdev.c Fri Mar 03 15:56:34 2006 +0100 19.3 @@ -11,8 +11,12 @@ 19.4 #include <public/xen.h> 19.5 #include <public/physdev.h> 19.6 19.7 -extern int ioapic_guest_read(int apicid, int address, u32 *pval); 19.8 -extern int ioapic_guest_write(int apicid, int address, u32 pval); 19.9 +extern int 19.10 +ioapic_guest_read( 19.11 + unsigned long physbase, unsigned int reg, u32 *pval); 19.12 +extern int 19.13 +ioapic_guest_write( 19.14 + unsigned long physbase, unsigned int reg, u32 pval); 19.15 19.16 /* 19.17 * Demuxing hypercall. 19.18 @@ -49,7 +53,9 @@ long do_physdev_op(struct physdev_op *uo 19.19 if ( !IS_PRIV(current->domain) ) 19.20 break; 19.21 ret = ioapic_guest_read( 19.22 - op.u.apic_op.apic, op.u.apic_op.offset, &op.u.apic_op.value); 19.23 + op.u.apic_op.apic_physbase, 19.24 + op.u.apic_op.reg, 19.25 + &op.u.apic_op.value); 19.26 break; 19.27 19.28 case PHYSDEVOP_APIC_WRITE: 19.29 @@ -57,7 +63,9 @@ long do_physdev_op(struct physdev_op *uo 19.30 if ( !IS_PRIV(current->domain) ) 19.31 break; 19.32 ret = ioapic_guest_write( 19.33 - op.u.apic_op.apic, op.u.apic_op.offset, op.u.apic_op.value); 19.34 + op.u.apic_op.apic_physbase, 19.35 + op.u.apic_op.reg, 19.36 + op.u.apic_op.value); 19.37 break; 19.38 19.39 case PHYSDEVOP_ASSIGN_VECTOR:
20.1 --- a/xen/arch/x86/setup.c Fri Mar 03 15:56:03 2006 +0100 20.2 +++ b/xen/arch/x86/setup.c Fri Mar 03 15:56:34 2006 +0100 20.3 @@ -13,6 +13,7 @@ 20.4 #include <xen/multiboot.h> 20.5 #include <xen/domain_page.h> 20.6 #include <xen/compile.h> 20.7 +#include <xen/gdbstub.h> 20.8 #include <public/version.h> 20.9 #include <asm/bitops.h> 20.10 #include <asm/smp.h> 20.11 @@ -479,6 +480,8 @@ void __init __start_xen(multiboot_info_t 20.12 printk("Brought up %ld CPUs\n", (long)num_online_cpus()); 20.13 smp_cpus_done(max_cpus); 20.14 20.15 + initialise_gdb(); /* could be moved earlier */ 20.16 + 20.17 do_initcalls(); 20.18 20.19 schedulers_start();
21.1 --- a/xen/arch/x86/time.c Fri Mar 03 15:56:03 2006 +0100 21.2 +++ b/xen/arch/x86/time.c Fri Mar 03 15:56:34 2006 +0100 21.3 @@ -41,7 +41,6 @@ boolean_param("hpet_force", opt_hpet_for 21.4 unsigned long cpu_khz; /* CPU clock frequency in kHz. */ 21.5 unsigned long hpet_address; 21.6 spinlock_t rtc_lock = SPIN_LOCK_UNLOCKED; 21.7 -int timer_ack = 0; 21.8 unsigned long volatile jiffies; 21.9 static u32 wc_sec, wc_nsec; /* UTC time at last 'time update'. */ 21.10 static spinlock_t wc_lock = SPIN_LOCK_UNLOCKED; 21.11 @@ -148,16 +147,6 @@ void timer_interrupt(int irq, void *dev_ 21.12 { 21.13 ASSERT(local_irq_is_enabled()); 21.14 21.15 - if ( timer_ack ) 21.16 - { 21.17 - extern spinlock_t i8259A_lock; 21.18 - spin_lock_irq(&i8259A_lock); 21.19 - outb(0x0c, 0x20); 21.20 - /* Ack the IRQ; AEOI will end it automatically. */ 21.21 - inb(0x20); 21.22 - spin_unlock_irq(&i8259A_lock); 21.23 - } 21.24 - 21.25 /* Update jiffies counter. */ 21.26 (*(unsigned long *)&jiffies)++; 21.27
22.1 --- a/xen/arch/x86/traps.c Fri Mar 03 15:56:03 2006 +0100 22.2 +++ b/xen/arch/x86/traps.c Fri Mar 03 15:56:34 2006 +0100 22.3 @@ -1410,7 +1410,13 @@ long do_set_trap_table(struct trap_info 22.4 struct trap_info *dst = current->arch.guest_context.trap_ctxt; 22.5 long rc = 0; 22.6 22.7 - LOCK_BIGLOCK(current->domain); 22.8 + /* If no table is presented then clear the entire virtual IDT. */ 22.9 + if ( traps == NULL ) 22.10 + { 22.11 + memset(dst, 0, 256 * sizeof(*dst)); 22.12 + init_int80_direct_trap(current); 22.13 + return 0; 22.14 + } 22.15 22.16 for ( ; ; ) 22.17 { 22.18 @@ -1440,8 +1446,6 @@ long do_set_trap_table(struct trap_info 22.19 traps++; 22.20 } 22.21 22.22 - UNLOCK_BIGLOCK(current->domain); 22.23 - 22.24 return rc; 22.25 } 22.26
23.1 --- a/xen/common/gdbstub.c Fri Mar 03 15:56:03 2006 +0100 23.2 +++ b/xen/common/gdbstub.c Fri Mar 03 15:56:34 2006 +0100 23.3 @@ -376,7 +376,6 @@ process_command(struct cpu_user_regs *re 23.4 break; 23.5 case 'g': /* Read registers */ 23.6 gdb_arch_read_reg_array(regs, ctx); 23.7 - ASSERT(!local_irq_is_enabled()); 23.8 break; 23.9 case 'G': /* Write registers */ 23.10 gdb_arch_write_reg_array(regs, ctx->in_buf + 1, ctx); 23.11 @@ -395,7 +394,6 @@ process_command(struct cpu_user_regs *re 23.12 return 0; 23.13 } 23.14 gdb_cmd_read_mem(addr, length, ctx); 23.15 - ASSERT(!local_irq_is_enabled()); 23.16 break; 23.17 case 'M': /* Write memory */ 23.18 addr = simple_strtoul(ctx->in_buf + 1, &ptr, 16); 23.19 @@ -477,7 +475,7 @@ int 23.20 { 23.21 int resume = 0; 23.22 int r; 23.23 - unsigned flags; 23.24 + unsigned long flags; 23.25 23.26 if ( gdb_ctx->serhnd < 0 ) 23.27 { 23.28 @@ -506,7 +504,7 @@ int 23.29 23.30 if ( !gdb_ctx->connected ) 23.31 { 23.32 - printk("GDB connection activated\n"); 23.33 + printk("GDB connection activated.\n"); 23.34 gdb_arch_print_state(regs); 23.35 gdb_ctx->connected = 1; 23.36 } 23.37 @@ -522,7 +520,7 @@ int 23.38 23.39 /* Shouldn't really do this, but otherwise we stop for no 23.40 obvious reason, which is Bad */ 23.41 - printk("Waiting for GDB to attach to Gdb\n"); 23.42 + printk("Waiting for GDB to attach...\n"); 23.43 23.44 gdb_arch_enter(regs); 23.45 gdb_ctx->signum = gdb_arch_signal_num(regs, cookie); 23.46 @@ -535,9 +533,7 @@ int 23.47 23.48 while ( resume == 0 ) 23.49 { 23.50 - ASSERT(!local_irq_is_enabled()); 23.51 r = receive_command(gdb_ctx); 23.52 - ASSERT(!local_irq_is_enabled()); 23.53 if ( r < 0 ) 23.54 { 23.55 dbg_printk("GDB disappeared, trying to resume Xen...\n"); 23.56 @@ -545,9 +541,7 @@ int 23.57 } 23.58 else 23.59 { 23.60 - ASSERT(!local_irq_is_enabled()); 23.61 resume = process_command(regs, gdb_ctx); 23.62 - ASSERT(!local_irq_is_enabled()); 23.63 } 23.64 } 23.65 23.66 @@ -561,28 +555,14 @@ int 23.67 return 0; 23.68 } 23.69 23.70 -/* 23.71 - * initialization 23.72 - * XXX TODO 23.73 - * This should be an explicit call from architecture code. 23.74 - * initcall is far too late for some early debugging, and only the 23.75 - * architecture code knows when this call can be made. 23.76 - */ 23.77 -static int 23.78 -initialize_gdb(void) 23.79 +void 23.80 +initialise_gdb(void) 23.81 { 23.82 - if ( !strcmp(opt_gdb, "none") ) 23.83 - return 0; 23.84 gdb_ctx->serhnd = serial_parse_handle(opt_gdb); 23.85 - if ( gdb_ctx->serhnd == -1 ) 23.86 - panic("Can't parse %s as GDB serial info.\n", opt_gdb); 23.87 - 23.88 - printk("Gdb initialised.\n"); 23.89 - return 0; 23.90 + if ( gdb_ctx->serhnd != -1 ) 23.91 + printk("GDB stub initialised.\n"); 23.92 } 23.93 23.94 -__initcall(initialize_gdb); 23.95 - 23.96 /* 23.97 * Local variables: 23.98 * mode: C
24.1 --- a/xen/include/asm-x86/time.h Fri Mar 03 15:56:03 2006 +0100 24.2 +++ b/xen/include/asm-x86/time.h Fri Mar 03 15:56:34 2006 +0100 24.3 @@ -4,8 +4,6 @@ 24.4 24.5 #include <asm/msr.h> 24.6 24.7 -extern int timer_ack; 24.8 - 24.9 extern void calibrate_tsc_bp(void); 24.10 extern void calibrate_tsc_ap(void); 24.11
25.1 --- a/xen/include/public/io/tpmif.h Fri Mar 03 15:56:03 2006 +0100 25.2 +++ b/xen/include/public/io/tpmif.h Fri Mar 03 15:56:34 2006 +0100 25.3 @@ -21,7 +21,7 @@ 25.4 typedef struct { 25.5 unsigned long addr; /* Machine address of packet. */ 25.6 grant_ref_t ref; /* grant table access reference */ 25.7 - uint16_t id; /* Echoed in response message. */ 25.8 + uint16_t unused; 25.9 uint16_t size; /* Packet size in bytes. */ 25.10 } tpmif_tx_request_t; 25.11
26.1 --- a/xen/include/public/physdev.h Fri Mar 03 15:56:03 2006 +0100 26.2 +++ b/xen/include/public/physdev.h Fri Mar 03 15:56:34 2006 +0100 26.3 @@ -33,8 +33,8 @@ typedef struct physdevop_set_iobitmap { 26.4 26.5 typedef struct physdevop_apic { 26.6 /* IN */ 26.7 - uint32_t apic; 26.8 - uint32_t offset; 26.9 + unsigned long apic_physbase; 26.10 + uint32_t reg; 26.11 /* IN or OUT */ 26.12 uint32_t value; 26.13 } physdevop_apic_t;
27.1 --- a/xen/include/xen/gdbstub.h Fri Mar 03 15:56:03 2006 +0100 27.2 +++ b/xen/include/xen/gdbstub.h Fri Mar 03 15:56:34 2006 +0100 27.3 @@ -21,6 +21,8 @@ 27.4 #ifndef __XEN_GDBSTUB_H__ 27.5 #define __XEN_GDBSTUB_H__ 27.6 27.7 +#ifdef CRASH_DEBUG 27.8 + 27.9 /* value <-> char (de)serialzers for arch specific gdb backends */ 27.10 char hex2char(unsigned long x); 27.11 int char2hex(unsigned char c); 27.12 @@ -84,6 +86,14 @@ void gdb_arch_exit(struct cpu_user_regs 27.13 #define SIGALRM 14 27.14 #define SIGTERM 15 27.15 27.16 +void initialise_gdb(void); 27.17 + 27.18 +#else 27.19 + 27.20 +#define initialise_gdb() ((void)0) 27.21 + 27.22 +#endif 27.23 + 27.24 #endif /* __XEN_GDBSTUB_H__ */ 27.25 27.26 /*