xen-vtx-unstable
changeset 6522:81576d3d1ca8
Merge.
line diff
2.1 --- a/Config.mk Thu Aug 18 10:40:02 2005 -0800 2.2 +++ b/Config.mk Fri Aug 19 10:19:28 2005 -0800 2.3 @@ -35,3 +35,11 @@ CFLAGS += $(foreach i, $(EXTRA_INCLUDES) 2.4 2.5 # Choose the best mirror to download linux kernel 2.6 KERNEL_REPO = http://www.kernel.org 2.7 + 2.8 +# ACM_USE_SECURITY_POLICY is set to security policy of Xen 2.9 +# Supported models are: 2.10 +# ACM_NULL_POLICY (ACM will not be built with this policy) 2.11 +# ACM_CHINESE_WALL_POLICY 2.12 +# ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY 2.13 +# ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY 2.14 +ACM_USE_SECURITY_POLICY ?= ACM_NULL_POLICY
8.1 --- a/docs/misc/shype4xen_readme.txt Thu Aug 18 10:40:02 2005 -0800 8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 8.3 @@ -1,588 +0,0 @@ 8.4 -Copyright: IBM Corporation (C) 8.5 -20 June 2005 8.6 -Author: Reiner Sailer 8.7 - 8.8 -This document is a very short introduction into the sHype access control 8.9 -security architecture implementation and how it is perceived by users. It 8.10 -is a very preliminary draft for the courageous ones to get "their feet wet" 8.11 -and to be able to give feedback (via the xen-devel/xense-devel mailing lists). 8.12 - 8.13 -Install: 8.14 - 8.15 -cd into xeno-unstable.bk 8.16 -(use --dry-run option if you want to test the patch only) 8.17 -patch -p1 -g0 < *tools.diff 8.18 -patch -p1 -g0 < *xen.diff 8.19 - 8.20 -(no rejects, probably some line offsets) 8.21 - 8.22 -make uninstall; make mrproper; make; ./install.sh should install the default 8.23 -sHype into Xen (rebuild your initrd images if necessary). Reboot. 8.24 - 8.25 -Debug output: there are two triggers for debug output: 8.26 -a) General sHype debug: 8.27 - xeno-unstable.bk/xen/include/public/acm.h 8.28 - undefine ACM_DEBUG to switch this debug off 8.29 - 8.30 -b) sHype enforcement hook trace: This prints a small trace for each enforcement 8.31 -hook that is executed. The trigger is in 8.32 - xeno-unstable.bk/xen/include/acm/acm_hooks.h 8.33 - undefine ACM_TRACE_MODE to switch this debug off 8.34 - 8.35 -1. The default NULL policy 8.36 -*************************** 8.37 -When you apply the patches and startup xen, you should at first not notice any 8.38 -difference because the default policy is the "NULL" policy, which as the name 8.39 -implies does not enforce anything. 8.40 - 8.41 -To display the currently enforced policy, use the policy tool under xeno- 8.42 -unstable.bk/tools/policy: policy_tool getpolicy. You should see output like the 8.43 -one below. 8.44 - 8.45 -[root@laptop policy]#./policy_tool getpolicy 8.46 - 8.47 -Policy dump: 8.48 -============ 8.49 -Magic = 1debc. 8.50 -PolVer = aaaa0000. 8.51 -Len = 14. 8.52 -Primary = NULL policy (c=0, off=14). 8.53 -Secondary = NULL policy (c=0, off=14). 8.54 -No primary policy (NULL). 8.55 -No secondary policy (NULL). 8.56 - 8.57 -Policy dump End. 8.58 - 8.59 -Since this is a dump of a binary policy, it's not pretty. The important parts 8.60 -are the "Primary" and "Secondary" policy fields set to "NULL policy". sHype 8.61 -currently allows to set two independent policies; thus the two SSID-REF parts 8.62 -shown in 'xm list'. Right here: primary policy only means this policy is 8.63 -checked first, the secondary policy is checked if the primary results in 8.64 -"permitted access". The result of the combined policy is "permitted" if both 8.65 -policies return permitted (NULL policy always returns permitted). The result is 8.66 -"denied" if at least one of the policies returns "denied". Look into xeno- 8.67 -unstable.bk/xen/include/acm/acm_hooks.h for the general hook structure 8.68 -integrating the policy decisions (if you like, you won't need it for the rest 8.69 -of the Readme file). 8.70 - 8.71 -2. Setting Chinese Wall and Simple Type Enforcement policies: 8.72 -************************************************************* 8.73 - 8.74 -We'll get fast to the point. However, in order to understand what we are doing, 8.75 -we must at least understand the purpose of the policies that we are going to 8.76 -enforce. The two policies presented here are just examples and the 8.77 -implementation encourages adding new policies easily. 8.78 - 8.79 -2.1. Chinese Wall policy: "decides whether a domain can be started based on 8.80 -this domain's ssidref and the ssidrefs of the currently running domains". 8.81 -Generally, the Chinese wall policy allows specifying certain types (or classes 8.82 -or categories, whatever the preferred word) that conflict; we usually assign a 8.83 -type to a workload and the set of types of those workloads running in a domain 8.84 -make up the type set for this domain. Each domain is assigned a set of types 8.85 -through its SSID-REF (we register Chinese Wall as primary policy, so the 8.86 -ssidref used for determining the Chinese Wall types is the one annotated with 8.87 -"p:" in xm list) since each SSID-REF points at a set of types. We'll see how 8.88 -SSIDREFs are represented in Xen later when we will look at the policy. (A good 8.89 -read for Chinese Wall is: Brewer/Nash The Chinese Wall Security Policy 1989.) 8.90 - 8.91 -So let's assume the Chinese Wall policy we are running distinguishes 10 types: 8.92 -t0 ... t9. Let us assume further that each SSID-REF points to a set that 8.93 -includes exactly one type (attached to domains that run workloads of a single 8.94 -type). SSID-REF 0 points to {t0}, ssidref 1 points to {t1} ... 9 points to 8.95 -{t9}. [This is actually the example policy we are going to push into xen later] 8.96 - 8.97 -Now the Chinese Wall policy allows you to define "Conflict type sets" and it 8.98 -guarantees that of any conflict set at most one type is "running" at any time. 8.99 -As an example, we have defined 2 conflict set: {t2, t3} and {t0, t5, t6}. 8.100 -Specifying these conflict sets, sHype ensures that at most one type of each set 8.101 -is running (either t2 or t3 but not both; either t0 or t5 or t6 but not 8.102 -multiple of them). 8.103 - 8.104 -The effect is that administrators can define which workload types cannot run 8.105 -simultaneously on a single Xen system. This is useful to limit the covert 8.106 -timing channels between such payloads or to ensure that payloads don't 8.107 -interfere with each other through existing resource dependencies. 8.108 - 8.109 -2.2. Simple Type Enforcement (ste) policy: "decides whether two domains can 8.110 -share data, e.g., setup event channels or grant tables to each other, based on 8.111 -the two domains' ssidref. This, as the name says, is a simple policy. Think of 8.112 -each type as of a single color. Each domain has one or more colors, i.e., the 8.113 -domains ssid for the ste policy points to a set that has set one or multiple 8.114 -types. Let us assume in our example policy we differentiate 5 colors (types) 8.115 -and define 5 different ssids referenced by ssidref=0..4. Each ssid shall have 8.116 -exactly one type set, i.e., describes a uni-color. Only ssid(0) has all types 8.117 -set, i.e., has all defined colors. 8.118 - 8.119 -Sharing is enforced by the ste policy by requiring that two domains that want 8.120 -to establish an event channel or grant pages to each other must have a common 8.121 -color. Currently all domains communicate through DOM0 by default; i.e., Domain0 8.122 -will necessarily have all colors to be able to create domains (thus, we will 8.123 -assign ssidref(0) to Domain0 in our example below. 8.124 - 8.125 -More complex mandatory access control policies governing sharing will follow; 8.126 -such policies are more sophisticated than the "color" scheme above by allowing 8.127 -more flexible (and complex :_) access control decisions than "share a color" or 8.128 -"don't share a color" and will be able to express finer-grained policies. 8.129 - 8.130 - 8.131 -2.3 Binary Policy: 8.132 -In the future, we will have a policy tool that takes as input a more humane 8.133 -policy description, using types such as development, home-banking, donated- 8.134 -Grid, CorpA-Payload ... and translates the respective policy into what we see 8.135 -today as the binary policy using 1s and 0s and sets of them. For now, we must 8.136 -live with the binary policy when working with sHype. 8.137 - 8.138 - 8.139 -2.4 Exemplary use of a real sHype policy on Xen. To activate a real policy, 8.140 -edit the file (yes, this will soon be a compile option): 8.141 - xeno-unstable.bk/xen/include/public/acm.h 8.142 - Change: #define ACM_USE_SECURITY_POLICY ACM_NULL_POLICY 8.143 - To : #define ACM_USE_SECURITY_POLICY ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY 8.144 - cd xeno-unstable.bk 8.145 - make mrproper 8.146 - make uninstall (manually remove /etc/xen.old if necessary) 8.147 - make 8.148 - ./install.sh (recreate your kernel initrd's if necessary) 8.149 - Reboot into new xen.gz 8.150 - 8.151 -After booting, check out 'xm dmesg'; should show somewhere in the middle: 8.152 - 8.153 -(XEN) acm_init: Enforcing Primary CHINESE WALL policy, Secondary SIMPLE TYPE 8.154 -ENFORCEMENT policy. 8.155 - 8.156 -Even though you can activate those policies in any combination and also 8.157 -independently, the policy tool currently only supports setting the policy for 8.158 -the above combination. 8.159 - 8.160 -Now look at the minimal startup policy with: 8.161 - xeno-unstable.bk/tools/policytool getpolicy 8.162 - 8.163 -You should see something like: 8.164 - 8.165 -[root@laptop policy]# ./policy_tool getpolicy 8.166 - 8.167 -Policy dump: 8.168 -============ 8.169 -Magic = 1debc. 8.170 -PolVer = aaaa0000. 8.171 -Len = 36. 8.172 -Primary = CHINESE WALL policy (c=1, off=14). 8.173 -Secondary = SIMPLE TYPE ENFORCEMENT policy (c=2, off=2c). 8.174 - 8.175 - 8.176 -Chinese Wall policy: 8.177 -==================== 8.178 -Max Types = 1. 8.179 -Max Ssidrefs = 1. 8.180 -Max ConfSets = 1. 8.181 -Ssidrefs Off = 10. 8.182 -Conflicts Off = 12. 8.183 -Runing T. Off = 14. 8.184 -C. Agg. Off = 16. 8.185 - 8.186 -SSID To CHWALL-Type matrix: 8.187 - 8.188 - ssidref 0: 00 8.189 - 8.190 -Confict Sets: 8.191 - 8.192 - c-set 0: 00 8.193 - 8.194 -Running 8.195 -Types: 00 8.196 - 8.197 -Conflict 8.198 -Aggregate Set: 00 8.199 - 8.200 - 8.201 -Simple Type Enforcement policy: 8.202 -=============================== 8.203 -Max Types = 1. 8.204 -Max Ssidrefs = 1. 8.205 -Ssidrefs Off = 8. 8.206 - 8.207 -SSID To STE-Type matrix: 8.208 - 8.209 - ssidref 0: 01 8.210 - 8.211 - 8.212 -Policy dump End. 8.213 - 8.214 -This is a minimal policy (of little use), except it will disable starting any 8.215 -domain that does not have ssidref set to 0x0. The Chinese Wall policy has 8.216 -nothing to enforce and the ste policy only knows one type, which is set for the 8.217 -only defined ssidref. 8.218 - 8.219 -The item that defines the ssidref in a domain configuration is: 8.220 - 8.221 -ssidref = 0x12345678 8.222 - 8.223 -Where ssidref is interpreted as a 32bit number, where the lower 16bits become 8.224 -the ssidref for the primary policy and the higher 16bits become the ssidref for 8.225 -the secondary policy. sHype currently supports two policies but this is an 8.226 -implementation decision and can be extended if necessary. 8.227 - 8.228 -This reference defines the security information of a domain. The meaning of the 8.229 -SSID-REF depends on the policy, so we explain it when we explain the real 8.230 -policies. 8.231 - 8.232 - 8.233 -Setting a new Security Policy: 8.234 -****************************** 8.235 -The policy tool with all its current limitations has one usable example policy 8.236 -compiled-in. Please try at this time to use the setpolicy command: 8.237 - xeno-unstable.bk/tools/policy/policy_tool setpolicy 8.238 - 8.239 -You should see a dump of the policy you are setting. It should say at the very 8.240 -end: 8.241 - 8.242 -Policy successfully set. 8.243 - 8.244 -Now try to dump the currently enforced policy, which is the policy we have just 8.245 -set and the dynamic security state information of this policy 8.246 -(<<< ... some additional explanations) 8.247 - 8.248 -[root@laptop policy]# ./policy_tool getpolicy 8.249 - 8.250 -Policy dump: 8.251 -============ 8.252 -Magic = 1debc. 8.253 -PolVer = aaaa0000. 8.254 -Len = 112. 8.255 -Primary = CHINESE WALL policy (c=1, off=14). 8.256 -Secondary = SIMPLE TYPE ENFORCEMENT policy (c=2, off=d8). 8.257 - 8.258 - 8.259 -Chinese Wall policy: 8.260 -==================== 8.261 -Max Types = a. 8.262 -Max Ssidrefs = 5. 8.263 -Max ConfSets = 2. 8.264 -Ssidrefs Off = 10. 8.265 -Conflicts Off = 74. 8.266 -Runing T. Off = 9c. 8.267 -C. Agg. Off = b0. 8.268 - 8.269 -SSID To CHWALL-Type matrix: 8.270 - 8.271 - ssidref 0: 01 00 00 00 00 00 00 00 00 00 <<< type0 is set for ssidref0 8.272 - ssidref 1: 00 01 00 00 00 00 00 00 00 00 8.273 - ssidref 2: 00 00 01 00 00 00 00 00 00 00 8.274 - ssidref 3: 00 00 00 01 00 00 00 00 00 00 8.275 - ssidref 4: 00 00 00 00 01 00 00 00 00 00 <<< type4 is set for ssidref4 8.276 - <<< types 5-9 are unused 8.277 -Confict Sets: 8.278 - 8.279 - c-set 0: 00 00 01 01 00 00 00 00 00 00 <<< type2 and type3 never run together 8.280 - c-set 1: 01 00 00 00 00 01 01 00 00 00 <<< only one of types 0, 5 or 6 8.281 - <<< can run simultaneously 8.282 -Running 8.283 -Types: 01 00 00 00 00 00 00 00 00 00 <<< ref-count for types of running domains 8.284 - 8.285 -Conflict 8.286 -Aggregate Set: 00 00 00 00 00 01 01 00 00 00 <<< aggregated set of types that 8.287 - <<< cannot run because they 8.288 - <<< are in conflict set 1 and 8.289 - <<< (domain 0 is running w t0) 8.290 - 8.291 - 8.292 -Simple Type Enforcement policy: 8.293 -=============================== 8.294 -Max Types = 5. 8.295 -Max Ssidrefs = 5. 8.296 -Ssidrefs Off = 8. 8.297 - 8.298 -SSID To STE-Type matrix: 8.299 - 8.300 - ssidref 0: 01 01 01 01 01 <<< ssidref0 points to a set that 8.301 - <<< has all types set (colors) 8.302 - ssidref 1: 00 01 00 00 00 <<< ssidref1 has color1 set 8.303 - ssidref 2: 00 00 01 00 00 <<< ... 8.304 - ssidref 3: 00 00 00 01 00 8.305 - ssidref 4: 00 00 00 00 01 8.306 - 8.307 - 8.308 -Policy dump End. 8.309 - 8.310 - 8.311 -This is a small example policy with which we will demonstrate the enforcement. 8.312 - 8.313 -Starting Domains with policy enforcement 8.314 -======================================== 8.315 -Now let us play with this policy. 8.316 - 8.317 -Define 3 or 4 domain configurations. I use the following config using a ramdisk 8.318 -only and about 8MBytes of memory for each DomU (test purposes): 8.319 - 8.320 -#-------configuration xmsec1------------------------- 8.321 -kernel = "/boot/vmlinuz-2.6.11-xenU" 8.322 -ramdisk="/boot/U1_ramdisk.img" 8.323 -#security reference identifier 8.324 -ssidref= 0x00010001 8.325 -memory = 10 8.326 -name = "xmsec1" 8.327 -cpu = -1 # leave to Xen to pick 8.328 -# Number of network interfaces. Default is 1. 8.329 -nics=1 8.330 -dhcp="dhcp" 8.331 -#----------------------------------------------------- 8.332 - 8.333 -xmsec2 and xmsec3 look the same except for the name and the ssidref line. Use 8.334 -your domain config file and add "ssidref = 0x00010001" to the first (xmsec1), 8.335 -"ssidref= 0x00020002" to the second (call it xmsec2), and "ssidref=0x00030003" 8.336 -to the third (we will call this one xmsec3). 8.337 - 8.338 -First start xmsec1: xm create -c xmsec1 (succeeds) 8.339 - 8.340 -Then 8.341 -[root@laptop policy]# xm list 8.342 -Name Id Mem(MB) CPU State Time(s) Console 8.343 -Domain-0 0 620 0 r---- 42.3 s:00/p:00 8.344 -xmnosec 1 9 0 -b--- 0.3 9601 s:00/p:05 8.345 -xmsec1 2 9 0 -b--- 0.2 9602 s:01/p:01 8.346 - 8.347 -Shows a new domain xmsec1 running with primary (here: chinese wall) ssidref 1 8.348 -and secondary (here: simple type enforcement) ssidref 1. The ssidrefs are 8.349 -independent and can differ for a domain. 8.350 - 8.351 -[root@laptop policy]# ./policy_tool getpolicy 8.352 - 8.353 -Policy dump: 8.354 -============ 8.355 -Magic = 1debc. 8.356 -PolVer = aaaa0000. 8.357 -Len = 112. 8.358 -Primary = CHINESE WALL policy (c=1, off=14). 8.359 -Secondary = SIMPLE TYPE ENFORCEMENT policy (c=2, off=d8). 8.360 - 8.361 - 8.362 -Chinese Wall policy: 8.363 -==================== 8.364 -Max Types = a. 8.365 -Max Ssidrefs = 5. 8.366 -Max ConfSets = 2. 8.367 -Ssidrefs Off = 10. 8.368 -Conflicts Off = 74. 8.369 -Runing T. Off = 9c. 8.370 -C. Agg. Off = b0. 8.371 - 8.372 -SSID To CHWALL-Type matrix: 8.373 - 8.374 - ssidref 0: 01 00 00 00 00 00 00 00 00 00 8.375 - ssidref 1: 00 01 00 00 00 00 00 00 00 00 8.376 - ssidref 2: 00 00 01 00 00 00 00 00 00 00 8.377 - ssidref 3: 00 00 00 01 00 00 00 00 00 00 8.378 - ssidref 4: 00 00 00 00 01 00 00 00 00 00 8.379 - 8.380 -Confict Sets: 8.381 - 8.382 - c-set 0: 00 00 01 01 00 00 00 00 00 00 8.383 - c-set 1: 01 00 00 00 00 01 01 00 00 00 <<< t1 is not part of any c-set 8.384 - 8.385 -Running 8.386 -Types: 01 01 00 00 00 00 00 00 00 00 <<< xmsec1 has ssidref 1->type1 8.387 - ^^ <<< ref-count at position 1 incr 8.388 -Conflict 8.389 -Aggregate Set: 00 00 00 00 00 01 01 00 00 00 <<< domain 1 was allowed to 8.390 - <<< start since type 1 was not 8.391 - <<< in conflict with running 8.392 - <<< types 8.393 - 8.394 -Simple Type Enforcement policy: 8.395 -=============================== 8.396 -Max Types = 5. 8.397 -Max Ssidrefs = 5. 8.398 -Ssidrefs Off = 8. 8.399 - 8.400 -SSID To STE-Type matrix: 8.401 - 8.402 - ssidref 0: 01 01 01 01 01 <<< the ste policy does not maintain; we 8.403 - ssidref 1: 00 01 00 00 00 <-- <<< see that domain xmsec1 has ste 8.404 - ssidref 2: 00 00 01 00 00 <<< ssidref1->type1 and has this type in 8.405 - ssidref 3: 00 00 00 01 00 <<< common with dom0 8.406 - ssidref 4: 00 00 00 00 01 8.407 - 8.408 - 8.409 -Policy dump End. 8.410 - 8.411 -Look at sHype output in xen dmesg: 8.412 - 8.413 -[root@laptop xen]# xm dmesg 8.414 -. 8.415 -. 8.416 -[somewhere near the very end] 8.417 -(XEN) chwall_init_domain_ssid: determined chwall_ssidref to 1. 8.418 -(XEN) ste_init_domain_ssid. 8.419 -(XEN) ste_init_domain_ssid: determined ste_ssidref to 1. 8.420 -(XEN) acm_init_domain_ssid: Instantiated individual ssid for domain 0x01. 8.421 -(XEN) chwall_post_domain_create. 8.422 -(XEN) ste_pre_eventchannel_interdomain. 8.423 -(XEN) ste_pre_eventchannel_interdomain: (evtchn 0 --> 1) common type #01. 8.424 -(XEN) shype_authorize_domops. 8.425 -(XEN) ste_pre_eventchannel_interdomain. 8.426 -(XEN) ste_pre_eventchannel_interdomain: (evtchn 0 --> 1) common type #01. 8.427 -(XEN) ste_pre_eventchannel_interdomain. 8.428 -(XEN) ste_pre_eventchannel_interdomain: (evtchn 0 --> 1) common type #01. 8.429 - 8.430 - 8.431 -You can see that the chinese wall policy does not complain and that the ste 8.432 -policy makes three access control decisions for three event-channels setup 8.433 -between domain 0 and the new domain 1. Each time, the two domains share the 8.434 -type1 and setting up the eventchannel is permitted. 8.435 - 8.436 - 8.437 -Starting up a second domain xmsec2: 8.438 - 8.439 -[root@laptop xen]# xm create -c xmsec2 8.440 -Using config file "xmsec2". 8.441 -Started domain xmsec2, console on port 9602 8.442 -************ REMOTE CONSOLE: CTRL-] TO QUIT ******** 8.443 -Linux version 2.6.11-xenU (root@laptop.home.org) (gcc version 3.4.2 20041017 8.444 -(Red Hat 3.4.2-6.fc3)) #1 Wed Mar 30 13:14:31 EST 2005 8.445 -. 8.446 -. 8.447 -. 8.448 -[root@laptop policy]# xm list 8.449 -Name Id Mem(MB) CPU State Time(s) Console 8.450 -Domain-0 0 620 0 r---- 71.7 s:00/p:00 8.451 -xmsec1 1 9 0 -b--- 0.3 9601 s:01/p:01 8.452 -xmsec2 2 7 0 -b--- 0.3 9602 s:02/p:02 << our domain runs both policies with ssidref 2 8.453 - 8.454 - 8.455 -[root@laptop policy]# ./policy_tool getpolicy 8.456 - 8.457 -Policy dump: 8.458 -============ 8.459 -Magic = 1debc. 8.460 -PolVer = aaaa0000. 8.461 -Len = 112. 8.462 -Primary = CHINESE WALL policy (c=1, off=14). 8.463 -Secondary = SIMPLE TYPE ENFORCEMENT policy (c=2, off=d8). 8.464 - 8.465 - 8.466 -Chinese Wall policy: 8.467 -==================== 8.468 -Max Types = a. 8.469 -Max Ssidrefs = 5. 8.470 -Max ConfSets = 2. 8.471 -Ssidrefs Off = 10. 8.472 -Conflicts Off = 74. 8.473 -Runing T. Off = 9c. 8.474 -C. Agg. Off = b0. 8.475 - 8.476 -SSID To CHWALL-Type matrix: 8.477 - 8.478 - ssidref 0: 01 00 00 00 00 00 00 00 00 00 8.479 - ssidref 1: 00 01 00 00 00 00 00 00 00 00 8.480 - ssidref 2: 00 00 01 00 00 00 00 00 00 00 <<< our domain has type 2 set 8.481 - ssidref 3: 00 00 00 01 00 00 00 00 00 00 8.482 - ssidref 4: 00 00 00 00 01 00 00 00 00 00 8.483 - 8.484 -Confict Sets: 8.485 - 8.486 - c-set 0: 00 00 01 01 00 00 00 00 00 00 <<< t2 is in c-set0 with type 3 8.487 - c-set 1: 01 00 00 00 00 01 01 00 00 00 8.488 - 8.489 -Running 8.490 -Types: 01 01 01 00 00 00 00 00 00 00 <<< t2 is running since the 8.491 - ^^ <<< current aggregate conflict 8.492 - <<< set (see above) does not 8.493 - <<< include type 2 8.494 -Conflict 8.495 -Aggregate Set: 00 00 00 01 00 01 01 00 00 00 <<< type 3 is added to the 8.496 - <<< conflict aggregate 8.497 - 8.498 - 8.499 -Simple Type Enforcement policy: 8.500 -=============================== 8.501 -Max Types = 5. 8.502 -Max Ssidrefs = 5. 8.503 -Ssidrefs Off = 8. 8.504 - 8.505 -SSID To STE-Type matrix: 8.506 - 8.507 - ssidref 0: 01 01 01 01 01 8.508 - ssidref 1: 00 01 00 00 00 8.509 - ssidref 2: 00 00 01 00 00 8.510 - ssidref 3: 00 00 00 01 00 8.511 - ssidref 4: 00 00 00 00 01 8.512 - 8.513 - 8.514 -Policy dump End. 8.515 - 8.516 - 8.517 -The sHype xen dmesg output looks similar to the one above when starting the 8.518 -first domain. 8.519 - 8.520 -Now we start xmsec3 and it has ssidref3. Thus, it tries to run as type3 which 8.521 -conflicts with running type2 (from xmsec2). As expected, creating this domain 8.522 -fails for security policy enforcement reasons. 8.523 - 8.524 -[root@laptop xen]# xm create -c xmsec3 8.525 -Using config file "xmsec3". 8.526 -Error: Error creating domain: (22, 'Invalid argument') 8.527 -[root@laptop xen]# 8.528 - 8.529 -[root@laptop xen]# xm dmesg 8.530 -. 8.531 -. 8.532 -[somewhere near the very end] 8.533 -(XEN) chwall_pre_domain_create. 8.534 -(XEN) chwall_pre_domain_create: CHINESE WALL CONFLICT in type 03. 8.535 - 8.536 -xmsec3 ssidref3 points to type3, which is in the current conflict aggregate 8.537 -set. This domain cannot start until domain xmsec2 is destroyed, at which time 8.538 -the aggregate conflict set is reduced and type3 is excluded from it. Then, 8.539 -xmsec3 can start. Of course, afterwards, xmsec2 cannot be restarted. Try it. 8.540 - 8.541 -3. Policy tool 8.542 -************** 8.543 -toos/policy/policy_tool.c 8.544 - 8.545 -a) ./policy_tool getpolicy 8.546 - prints the currently enforced policy 8.547 - (see for example section 1.) 8.548 - 8.549 -b) ./policy_tool setpolicy 8.550 - sets a predefined and hardcoded security 8.551 - policy (the one described in section 2.) 8.552 - 8.553 -c) ./policy_tool dumpstats 8.554 - prints some status information about the caching 8.555 - of access control decisions (number of cache hits 8.556 - and number of policy evaluations for grant_table 8.557 - and event channels). 8.558 - 8.559 -d) ./policy_tool loadpolicy <binary_policy_file> 8.560 - sets the policy defined in the <binary_policy_file> 8.561 - please use the policy_processor that is posted to this 8.562 - mailing list to create such a binary policy from an XML 8.563 - policy description 8.564 - 8.565 -4. Policy interface: 8.566 -******************** 8.567 -The Policy interface is working in "network-byte-order" (big endian). The reason for this 8.568 -is that policy files/management should be portable and independent of the platforms. 8.569 - 8.570 -Our policy interface enables managers to create a single binary policy file in a trusted 8.571 -environment and distributed it to multiple systems for enforcement. 8.572 - 8.573 -5. Booting with a binary policy: 8.574 -******************************** 8.575 -The grub configuration file can be adapted to boot the hypervisor with an 8.576 -already active policy. To do this, a binary policy file - this can be 8.577 -the same file as used by the policy_tool - should be placed into the boot 8.578 -partition. The following entry from the grub configuration file shows how 8.579 -a binary policy can be added to the system during boot time. Note that the 8.580 -binary policy must be of the same type that the hypervisor was compiled 8.581 -for. The policy module line should also only be added as the last module 8.582 -line if XEN was compiled with the access control module (ACM). 8.583 - 8.584 -title XEN0 3.0 Devel 8.585 - kernel /xen.gz dom0_mem=400000 8.586 - module /vmlinuz-2.6.12-xen0 root=/dev/hda2 ro console=tty0 8.587 - module /initrd-2.6.12-xen0.img 8.588 - module /xen_sample_policy.bin 8.589 - 8.590 - 8.591 -====================end-of file=======================================
9.1 --- a/docs/src/user.tex Thu Aug 18 10:40:02 2005 -0800 9.2 +++ b/docs/src/user.tex Fri Aug 19 10:19:28 2005 -0800 9.3 @@ -1763,7 +1763,7 @@ editing \path{grub.conf}. 9.4 physical address in the memory map will be ignored. This parameter 9.5 may be specified with a B, K, M or G suffix, representing bytes, 9.6 kilobytes, megabytes and gigabytes respectively. The 9.7 - default unit, if no suffix is specified, is bytes. 9.8 + default unit, if no suffix is specified, is kilobytes. 9.9 9.10 \item [dom0\_mem=xxx ] 9.11 Set the amount of memory to be allocated to domain0. In Xen 3.x the parameter
45.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile Thu Aug 18 10:40:02 2005 -0800 45.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/Makefile Fri Aug 19 10:19:28 2005 -0800 45.3 @@ -14,8 +14,7 @@ obj-y := process.o signal.o entry.o trap 45.4 45.5 c-obj-y := semaphore.o vm86.o \ 45.6 ptrace.o sys_i386.o \ 45.7 - i387.o dmi_scan.o bootflag.o \ 45.8 - doublefault.o 45.9 + i387.o dmi_scan.o bootflag.o 45.10 s-obj-y := 45.11 45.12 obj-y += cpu/ 45.13 @@ -85,7 +84,7 @@ SYSCFLAGS_vsyscall-syms.o = -r 45.14 $(obj)/vsyscall-sysenter.o FORCE 45.15 $(call if_changed,syscall) 45.16 45.17 -c-link := init_task.o 45.18 +c-link := 45.19 s-link := vsyscall-int80.o vsyscall-sysenter.o vsyscall-sigreturn.o vsyscall.lds.o syscall_table.o 45.20 45.21 $(patsubst %.o,$(obj)/%.c,$(c-obj-y) $(c-obj-m) $(c-link)) $(patsubst %.o,$(obj)/%.S,$(s-obj-y) $(s-link)):
46.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c Thu Aug 18 10:40:02 2005 -0800 46.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/cpu/common.c Fri Aug 19 10:19:28 2005 -0800 46.3 @@ -569,7 +569,7 @@ void __init cpu_gdt_init(struct Xgt_desc 46.4 for (va = gdt_descr->address, f = 0; 46.5 va < gdt_descr->address + gdt_descr->size; 46.6 va += PAGE_SIZE, f++) { 46.7 - frames[f] = virt_to_machine(va) >> PAGE_SHIFT; 46.8 + frames[f] = virt_to_mfn(va); 46.9 make_page_readonly((void *)va); 46.10 } 46.11 if (HYPERVISOR_set_gdt(frames, gdt_descr->size / 8))
48.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S Thu Aug 18 10:40:02 2005 -0800 48.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/head.S Fri Aug 19 10:19:28 2005 -0800 48.3 @@ -136,9 +136,6 @@ cpu_gdt_descr: 48.4 ENTRY(empty_zero_page) 48.5 48.6 .org 0x2000 48.7 -ENTRY(swapper_pg_dir) 48.8 - 48.9 -.org 0x3000 48.10 ENTRY(cpu_gdt_table) 48.11 .quad 0x0000000000000000 /* NULL descriptor */ 48.12 .quad 0x0000000000000000 /* 0x0b reserved */ 48.13 @@ -190,10 +187,10 @@ ENTRY(cpu_gdt_table) 48.14 .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */ 48.15 .fill GDT_ENTRIES-32,8,0 48.16 48.17 -.org 0x4000 48.18 +.org 0x3000 48.19 ENTRY(default_ldt) 48.20 48.21 -.org 0x5000 48.22 +.org 0x4000 48.23 /* 48.24 * Real beginning of normal "text" segment 48.25 */
50.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 50.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/init_task.c Fri Aug 19 10:19:28 2005 -0800 50.3 @@ -0,0 +1,49 @@ 50.4 +#include <linux/mm.h> 50.5 +#include <linux/module.h> 50.6 +#include <linux/sched.h> 50.7 +#include <linux/init.h> 50.8 +#include <linux/init_task.h> 50.9 +#include <linux/fs.h> 50.10 +#include <linux/mqueue.h> 50.11 + 50.12 +#include <asm/uaccess.h> 50.13 +#include <asm/pgtable.h> 50.14 +#include <asm/desc.h> 50.15 + 50.16 +static struct fs_struct init_fs = INIT_FS; 50.17 +static struct files_struct init_files = INIT_FILES; 50.18 +static struct signal_struct init_signals = INIT_SIGNALS(init_signals); 50.19 +static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand); 50.20 + 50.21 +#define swapper_pg_dir ((pgd_t *)NULL) 50.22 +struct mm_struct init_mm = INIT_MM(init_mm); 50.23 +#undef swapper_pg_dir 50.24 + 50.25 +EXPORT_SYMBOL(init_mm); 50.26 + 50.27 +/* 50.28 + * Initial thread structure. 50.29 + * 50.30 + * We need to make sure that this is THREAD_SIZE aligned due to the 50.31 + * way process stacks are handled. This is done by having a special 50.32 + * "init_task" linker map entry.. 50.33 + */ 50.34 +union thread_union init_thread_union 50.35 + __attribute__((__section__(".data.init_task"))) = 50.36 + { INIT_THREAD_INFO(init_task) }; 50.37 + 50.38 +/* 50.39 + * Initial task structure. 50.40 + * 50.41 + * All other task structs will be allocated on slabs in fork.c 50.42 + */ 50.43 +struct task_struct init_task = INIT_TASK(init_task); 50.44 + 50.45 +EXPORT_SYMBOL(init_task); 50.46 + 50.47 +/* 50.48 + * per-CPU TSS segments. Threads are completely 'soft' on Linux, 50.49 + * no more per-task TSS's. 50.50 + */ 50.51 +DEFINE_PER_CPU(struct tss_struct, init_tss) ____cacheline_maxaligned_in_smp = INIT_TSS; 50.52 +
51.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/ioport.c Thu Aug 18 10:40:02 2005 -0800 51.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/ioport.c Fri Aug 19 10:19:28 2005 -0800 51.3 @@ -80,7 +80,7 @@ asmlinkage long sys_ioperm(unsigned long 51.4 t->io_bitmap_ptr = bitmap; 51.5 51.6 op.cmd = PHYSDEVOP_SET_IOBITMAP; 51.7 - op.u.set_iobitmap.bitmap = (unsigned long)bitmap; 51.8 + op.u.set_iobitmap.bitmap = (char *)bitmap; 51.9 op.u.set_iobitmap.nr_ports = IO_BITMAP_BITS; 51.10 HYPERVISOR_physdev_op(&op); 51.11 }
53.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/ldt.c Thu Aug 18 10:40:02 2005 -0800 53.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/ldt.c Fri Aug 19 10:19:28 2005 -0800 53.3 @@ -198,7 +198,7 @@ static int write_ldt(void __user * ptr, 53.4 { 53.5 struct mm_struct * mm = current->mm; 53.6 __u32 entry_1, entry_2, *lp; 53.7 - unsigned long mach_lp; 53.8 + maddr_t mach_lp; 53.9 int error; 53.10 struct user_desc ldt_info; 53.11 53.12 @@ -245,7 +245,8 @@ static int write_ldt(void __user * ptr, 53.13 53.14 /* Install the new entry ... */ 53.15 install: 53.16 - error = HYPERVISOR_update_descriptor(mach_lp, entry_1, entry_2); 53.17 + error = HYPERVISOR_update_descriptor( 53.18 + mach_lp, (u64)entry_1 | ((u64)entry_2<<32)); 53.19 53.20 out_unlock: 53.21 up(&mm->context.sem);
56.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c Thu Aug 18 10:40:02 2005 -0800 56.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/process.c Fri Aug 19 10:19:28 2005 -0800 56.3 @@ -115,20 +115,12 @@ void xen_idle(void) 56.4 /* We don't actually take CPU down, just spin without interrupts. */ 56.5 static inline void play_dead(void) 56.6 { 56.7 - /* Ack it */ 56.8 - __get_cpu_var(cpu_state) = CPU_DEAD; 56.9 - 56.10 - /* We shouldn't have to disable interrupts while dead, but 56.11 - * some interrupts just don't seem to go away, and this makes 56.12 - * it "work" for testing purposes. */ 56.13 /* Death loop */ 56.14 while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE) 56.15 HYPERVISOR_yield(); 56.16 56.17 - local_irq_disable(); 56.18 __flush_tlb_all(); 56.19 cpu_set(smp_processor_id(), cpu_online_map); 56.20 - local_irq_enable(); 56.21 } 56.22 #else 56.23 static inline void play_dead(void) 56.24 @@ -156,12 +148,19 @@ void cpu_idle (void) 56.25 rmb(); 56.26 56.27 if (cpu_is_offline(cpu)) { 56.28 + local_irq_disable(); 56.29 + /* Ack it. From this point on until 56.30 + we get woken up, we're not allowed 56.31 + to take any locks. In particular, 56.32 + don't printk. */ 56.33 + __get_cpu_var(cpu_state) = CPU_DEAD; 56.34 #if defined(CONFIG_XEN) && defined(CONFIG_HOTPLUG_CPU) 56.35 /* Tell hypervisor to take vcpu down. */ 56.36 HYPERVISOR_vcpu_down(cpu); 56.37 #endif 56.38 play_dead(); 56.39 - } 56.40 + local_irq_enable(); 56.41 + } 56.42 56.43 __get_cpu_var(irq_stat).idle_timestamp = jiffies; 56.44 xen_idle(); 56.45 @@ -523,16 +522,15 @@ struct task_struct fastcall * __switch_t 56.46 * Load the per-thread Thread-Local Storage descriptor. 56.47 * This is load_TLS(next, cpu) with multicalls. 56.48 */ 56.49 -#define C(i) do { \ 56.50 - if (unlikely(next->tls_array[i].a != prev->tls_array[i].a || \ 56.51 - next->tls_array[i].b != prev->tls_array[i].b)) { \ 56.52 - mcl->op = __HYPERVISOR_update_descriptor; \ 56.53 - mcl->args[0] = virt_to_machine(&get_cpu_gdt_table(cpu) \ 56.54 - [GDT_ENTRY_TLS_MIN + i]); \ 56.55 - mcl->args[1] = ((u32 *)&next->tls_array[i])[0]; \ 56.56 - mcl->args[2] = ((u32 *)&next->tls_array[i])[1]; \ 56.57 - mcl++; \ 56.58 - } \ 56.59 +#define C(i) do { \ 56.60 + if (unlikely(next->tls_array[i].a != prev->tls_array[i].a || \ 56.61 + next->tls_array[i].b != prev->tls_array[i].b)) { \ 56.62 + mcl->op = __HYPERVISOR_update_descriptor; \ 56.63 + *(u64 *)&mcl->args[0] = virt_to_machine( \ 56.64 + &get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i]);\ 56.65 + *(u64 *)&mcl->args[2] = *(u64 *)&next->tls_array[i]; \ 56.66 + mcl++; \ 56.67 + } \ 56.68 } while (0) 56.69 C(0); C(1); C(2); 56.70 #undef C 56.71 @@ -549,7 +547,7 @@ struct task_struct fastcall * __switch_t 56.72 iobmp_op.cmd = 56.73 PHYSDEVOP_SET_IOBITMAP; 56.74 iobmp_op.u.set_iobitmap.bitmap = 56.75 - (unsigned long)next->io_bitmap_ptr; 56.76 + (char *)next->io_bitmap_ptr; 56.77 iobmp_op.u.set_iobitmap.nr_ports = 56.78 next->io_bitmap_ptr ? IO_BITMAP_BITS : 0; 56.79 mcl->op = __HYPERVISOR_physdev_op; 56.80 @@ -791,3 +789,10 @@ unsigned long arch_align_stack(unsigned 56.81 sp -= get_random_int() % 8192; 56.82 return sp & ~0xf; 56.83 } 56.84 + 56.85 + 56.86 +#ifndef CONFIG_X86_SMP 56.87 +void _restore_vcpu(void) 56.88 +{ 56.89 +} 56.90 +#endif
57.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c Thu Aug 18 10:40:02 2005 -0800 57.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/setup.c Fri Aug 19 10:19:28 2005 -0800 57.3 @@ -1604,11 +1604,10 @@ void __init setup_arch(char **cmdline_p) 57.4 for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ ) 57.5 { 57.6 pfn_to_mfn_frame_list[j] = 57.7 - virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT; 57.8 + virt_to_mfn(&phys_to_machine_mapping[i]); 57.9 } 57.10 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list = 57.11 - virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT; 57.12 - 57.13 + virt_to_mfn(pfn_to_mfn_frame_list); 57.14 57.15 /* 57.16 * NOTE: at this point the bootmem allocator is fully available.
59.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c Thu Aug 18 10:40:02 2005 -0800 59.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/smpboot.c Fri Aug 19 10:19:28 2005 -0800 59.3 @@ -904,7 +904,7 @@ static int __init do_boot_cpu(int apicid 59.4 for (va = cpu_gdt_descr[cpu].address, f = 0; 59.5 va < cpu_gdt_descr[cpu].address + cpu_gdt_descr[cpu].size; 59.6 va += PAGE_SIZE, f++) { 59.7 - ctxt.gdt_frames[f] = virt_to_machine(va) >> PAGE_SHIFT; 59.8 + ctxt.gdt_frames[f] = virt_to_mfn(va); 59.9 make_page_readonly((void *)va); 59.10 } 59.11 ctxt.gdt_ents = cpu_gdt_descr[cpu].size / 8; 59.12 @@ -920,7 +920,7 @@ static int __init do_boot_cpu(int apicid 59.13 ctxt.failsafe_callback_cs = __KERNEL_CS; 59.14 ctxt.failsafe_callback_eip = (unsigned long)failsafe_callback; 59.15 59.16 - ctxt.ctrlreg[3] = (unsigned long)virt_to_machine(swapper_pg_dir); 59.17 + ctxt.ctrlreg[3] = virt_to_mfn(swapper_pg_dir) << PAGE_SHIFT; 59.18 59.19 boot_error = HYPERVISOR_boot_vcpu(cpu, &ctxt); 59.20 printk("boot error: %ld\n", boot_error); 59.21 @@ -1616,3 +1616,21 @@ void smp_resume(void) 59.22 smp_intr_init(); 59.23 local_setup_timer_irq(); 59.24 } 59.25 + 59.26 +DECLARE_PER_CPU(int, timer_irq); 59.27 + 59.28 +void _restore_vcpu(void) 59.29 +{ 59.30 + int cpu = smp_processor_id(); 59.31 + extern atomic_t vcpus_rebooting; 59.32 + 59.33 + /* We are the first thing the vcpu runs when it comes back, 59.34 + and we are supposed to restore the IPIs and timer 59.35 + interrupts etc. When we return, the vcpu's idle loop will 59.36 + start up again. */ 59.37 + _bind_virq_to_irq(VIRQ_TIMER, cpu, per_cpu(timer_irq, cpu)); 59.38 + _bind_virq_to_irq(VIRQ_DEBUG, cpu, per_cpu(ldebug_irq, cpu)); 59.39 + _bind_ipi_to_irq(RESCHEDULE_VECTOR, cpu, per_cpu(resched_irq, cpu) ); 59.40 + _bind_ipi_to_irq(CALL_FUNCTION_VECTOR, cpu, per_cpu(callfunc_irq, cpu) ); 59.41 + atomic_dec(&vcpus_rebooting); 59.42 +}
60.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c Thu Aug 18 10:40:02 2005 -0800 60.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/swiotlb.c Fri Aug 19 10:19:28 2005 -0800 60.3 @@ -94,9 +94,6 @@ setup_io_tlb_npages(char *str) 60.4 iotlb_nslabs = simple_strtoul(str, &str, 0) << 60.5 (20 - IO_TLB_SHIFT); 60.6 iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE); 60.7 - /* Round up to power of two (xen_create_contiguous_region). */ 60.8 - while (iotlb_nslabs & (iotlb_nslabs-1)) 60.9 - iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1); 60.10 } 60.11 if (*str == ',') 60.12 ++str; 60.13 @@ -123,9 +120,6 @@ swiotlb_init_with_default_size (size_t d 60.14 if (!iotlb_nslabs) { 60.15 iotlb_nslabs = (default_size >> IO_TLB_SHIFT); 60.16 iotlb_nslabs = ALIGN(iotlb_nslabs, IO_TLB_SEGSIZE); 60.17 - /* Round up to power of two (xen_create_contiguous_region). */ 60.18 - while (iotlb_nslabs & (iotlb_nslabs-1)) 60.19 - iotlb_nslabs += iotlb_nslabs & ~(iotlb_nslabs-1); 60.20 } 60.21 60.22 bytes = iotlb_nslabs * (1UL << IO_TLB_SHIFT); 60.23 @@ -135,10 +129,14 @@ swiotlb_init_with_default_size (size_t d 60.24 */ 60.25 iotlb_virt_start = alloc_bootmem_low_pages(bytes); 60.26 if (!iotlb_virt_start) 60.27 - panic("Cannot allocate SWIOTLB buffer"); 60.28 + panic("Cannot allocate SWIOTLB buffer!\n" 60.29 + "Use dom0_mem Xen boot parameter to reserve\n" 60.30 + "some DMA memory (e.g., dom0_mem=-128M).\n"); 60.31 60.32 - xen_create_contiguous_region( 60.33 - (unsigned long)iotlb_virt_start, get_order(bytes)); 60.34 + for (i = 0; i < iotlb_nslabs; i += IO_TLB_SEGSIZE) 60.35 + xen_create_contiguous_region( 60.36 + (unsigned long)iotlb_virt_start + (i << IO_TLB_SHIFT), 60.37 + get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT)); 60.38 60.39 iotlb_virt_end = iotlb_virt_start + bytes; 60.40
61.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c Thu Aug 18 10:40:02 2005 -0800 61.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/kernel/time.c Fri Aug 19 10:19:28 2005 -0800 61.3 @@ -745,7 +745,7 @@ static void __init hpet_time_init(void) 61.4 #endif 61.5 61.6 /* Dynamically-mapped IRQ. */ 61.7 -static DEFINE_PER_CPU(int, timer_irq); 61.8 +DEFINE_PER_CPU(int, timer_irq); 61.9 61.10 static struct irqaction irq_timer = { 61.11 timer_interrupt, SA_INTERRUPT, CPU_MASK_NONE, "timer0",
66.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Thu Aug 18 10:40:02 2005 -0800 66.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/init.c Fri Aug 19 10:19:28 2005 -0800 66.3 @@ -342,11 +342,15 @@ unsigned long long __PAGE_KERNEL_EXEC = 66.4 extern void __init remap_numa_kva(void); 66.5 #endif 66.6 66.7 +pgd_t *swapper_pg_dir; 66.8 + 66.9 static void __init pagetable_init (void) 66.10 { 66.11 unsigned long vaddr; 66.12 - pgd_t *pgd_base = swapper_pg_dir; 66.13 - pgd_t *old_pgd = (pgd_t *)xen_start_info.pt_base; 66.14 + pgd_t *pgd_base = (pgd_t *)xen_start_info.pt_base; 66.15 + 66.16 + swapper_pg_dir = pgd_base; 66.17 + init_mm.pgd = pgd_base; 66.18 66.19 #ifdef CONFIG_X86_PAE 66.20 int i; 66.21 @@ -367,44 +371,6 @@ static void __init pagetable_init (void) 66.22 __PAGE_KERNEL_EXEC |= _PAGE_GLOBAL; 66.23 } 66.24 66.25 - /* 66.26 - * Switch to proper mm_init page directory. Initialise from the current 66.27 - * page directory, write-protect the new page directory, then switch to 66.28 - * it. We clean up by write-enabling and then freeing the old page dir. 66.29 - */ 66.30 -#ifndef CONFIG_X86_PAE 66.31 - memcpy(pgd_base, old_pgd, PTRS_PER_PGD_NO_HV*sizeof(pgd_t)); 66.32 - make_page_readonly(pgd_base); 66.33 - xen_pgd_pin(__pa(pgd_base)); 66.34 - load_cr3(pgd_base); 66.35 - xen_pgd_unpin(__pa(old_pgd)); 66.36 - make_page_writable(old_pgd); 66.37 - __flush_tlb_all(); 66.38 - free_bootmem(__pa(old_pgd), PAGE_SIZE); 66.39 -#else 66.40 - { 66.41 - pud_t *old_pud = pud_offset(old_pgd+3, PAGE_OFFSET); 66.42 - pmd_t *old_pmd = pmd_offset(old_pud, PAGE_OFFSET); 66.43 - pmd_t *new_pmd = alloc_bootmem_low_pages(PAGE_SIZE); 66.44 - 66.45 - memcpy(new_pmd, old_pmd, PAGE_SIZE); 66.46 - memcpy(pgd_base, old_pgd, PTRS_PER_PGD_NO_HV*sizeof(pgd_t)); 66.47 - set_pgd(&pgd_base[3], __pgd(__pa(new_pmd) | _PAGE_PRESENT)); 66.48 - 66.49 - make_page_readonly(new_pmd); 66.50 - make_page_readonly(pgd_base); 66.51 - xen_pgd_pin(__pa(pgd_base)); 66.52 - load_cr3(pgd_base); 66.53 - xen_pgd_unpin(__pa(old_pgd)); 66.54 - make_page_writable(old_pgd); 66.55 - make_page_writable(old_pmd); 66.56 - __flush_tlb_all(); 66.57 - 66.58 - free_bootmem(__pa(old_pgd), PAGE_SIZE); 66.59 - free_bootmem(__pa(old_pmd), PAGE_SIZE); 66.60 - } 66.61 -#endif 66.62 - 66.63 init_mm.context.pinned = 1; 66.64 kernel_physical_mapping_init(pgd_base); 66.65 remap_numa_kva();
67.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c Thu Aug 18 10:40:02 2005 -0800 67.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/ioremap.c Fri Aug 19 10:19:28 2005 -0800 67.3 @@ -306,7 +306,7 @@ static int direct_remap_area_pte_fn(pte_ 67.4 { 67.5 mmu_update_t **v = (mmu_update_t **)data; 67.6 67.7 - (*v)->ptr = ((physaddr_t)pfn_to_mfn(page_to_pfn(pte_page)) << 67.8 + (*v)->ptr = ((maddr_t)pfn_to_mfn(page_to_pfn(pte_page)) << 67.9 PAGE_SHIFT) | ((unsigned long)pte & ~PAGE_MASK); 67.10 (*v)++; 67.11
68.1 --- a/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c Thu Aug 18 10:40:02 2005 -0800 68.2 +++ b/linux-2.6-xen-sparse/arch/xen/i386/mm/pgtable.c Fri Aug 19 10:19:28 2005 -0800 68.3 @@ -170,7 +170,7 @@ void set_pmd_pfn(unsigned long vaddr, un 68.4 __flush_tlb_one(vaddr); 68.5 } 68.6 68.7 -void __set_fixmap (enum fixed_addresses idx, unsigned long phys, pgprot_t flags) 68.8 +void __set_fixmap (enum fixed_addresses idx, maddr_t phys, pgprot_t flags) 68.9 { 68.10 unsigned long address = __fix_to_virt(idx); 68.11
70.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c Thu Aug 18 10:40:02 2005 -0800 70.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/evtchn.c Fri Aug 19 10:19:28 2005 -0800 70.3 @@ -144,7 +144,7 @@ asmlinkage void evtchn_do_upcall(struct 70.4 vcpu_info_t *vcpu_info = &s->vcpu_data[cpu]; 70.5 70.6 vcpu_info->evtchn_upcall_pending = 0; 70.7 - 70.8 + 70.9 /* NB. No need for a barrier here -- XCHG is a barrier on x86. */ 70.10 l1 = xchg(&vcpu_info->evtchn_pending_sel, 0); 70.11 while ( l1 != 0 ) 70.12 @@ -158,9 +158,9 @@ asmlinkage void evtchn_do_upcall(struct 70.13 l2 &= ~(1 << l2i); 70.14 70.15 port = (l1i << 5) + l2i; 70.16 - if ( (irq = evtchn_to_irq[port]) != -1 ) 70.17 + if ( (irq = evtchn_to_irq[port]) != -1 ) { 70.18 do_IRQ(irq, regs); 70.19 - else 70.20 + } else 70.21 evtchn_device_upcall(port); 70.22 } 70.23 } 70.24 @@ -245,6 +245,74 @@ void unbind_virq_from_irq(int virq) 70.25 spin_unlock(&irq_mapping_update_lock); 70.26 } 70.27 70.28 +/* This is only used when a vcpu from an xm save. The ipi is expected 70.29 + to have been bound before we suspended, and so all of the xenolinux 70.30 + state is set up; we only need to restore the Xen side of things. 70.31 + The irq number has to be the same, but the evtchn number can 70.32 + change. */ 70.33 +void _bind_ipi_to_irq(int ipi, int vcpu, int irq) 70.34 +{ 70.35 + evtchn_op_t op; 70.36 + int evtchn; 70.37 + 70.38 + spin_lock(&irq_mapping_update_lock); 70.39 + 70.40 + op.cmd = EVTCHNOP_bind_ipi; 70.41 + if ( HYPERVISOR_event_channel_op(&op) != 0 ) 70.42 + panic("Failed to bind virtual IPI %d on cpu %d\n", ipi, vcpu); 70.43 + evtchn = op.u.bind_ipi.port; 70.44 + 70.45 + printk("<0>IPI %d, old evtchn %d, evtchn %d.\n", 70.46 + ipi, per_cpu(ipi_to_evtchn, vcpu)[ipi], 70.47 + evtchn); 70.48 + 70.49 + evtchn_to_irq[irq_to_evtchn[irq]] = -1; 70.50 + irq_to_evtchn[irq] = -1; 70.51 + 70.52 + evtchn_to_irq[evtchn] = irq; 70.53 + irq_to_evtchn[irq] = evtchn; 70.54 + 70.55 + printk("<0>evtchn_to_irq[%d] = %d.\n", evtchn, 70.56 + evtchn_to_irq[evtchn]); 70.57 + per_cpu(ipi_to_evtchn, vcpu)[ipi] = evtchn; 70.58 + 70.59 + bind_evtchn_to_cpu(evtchn, vcpu); 70.60 + 70.61 + spin_unlock(&irq_mapping_update_lock); 70.62 + 70.63 + clear_bit(evtchn, (unsigned long *)HYPERVISOR_shared_info->evtchn_mask); 70.64 + clear_bit(evtchn, (unsigned long *)HYPERVISOR_shared_info->evtchn_pending); 70.65 +} 70.66 + 70.67 +void _bind_virq_to_irq(int virq, int cpu, int irq) 70.68 +{ 70.69 + evtchn_op_t op; 70.70 + int evtchn; 70.71 + 70.72 + spin_lock(&irq_mapping_update_lock); 70.73 + 70.74 + op.cmd = EVTCHNOP_bind_virq; 70.75 + op.u.bind_virq.virq = virq; 70.76 + if ( HYPERVISOR_event_channel_op(&op) != 0 ) 70.77 + panic("Failed to bind virtual IRQ %d\n", virq); 70.78 + evtchn = op.u.bind_virq.port; 70.79 + 70.80 + evtchn_to_irq[irq_to_evtchn[irq]] = -1; 70.81 + irq_to_evtchn[irq] = -1; 70.82 + 70.83 + evtchn_to_irq[evtchn] = irq; 70.84 + irq_to_evtchn[irq] = evtchn; 70.85 + 70.86 + per_cpu(virq_to_irq, cpu)[virq] = irq; 70.87 + 70.88 + bind_evtchn_to_cpu(evtchn, cpu); 70.89 + 70.90 + spin_unlock(&irq_mapping_update_lock); 70.91 + 70.92 + clear_bit(evtchn, (unsigned long *)HYPERVISOR_shared_info->evtchn_mask); 70.93 + clear_bit(evtchn, (unsigned long *)HYPERVISOR_shared_info->evtchn_pending); 70.94 +} 70.95 + 70.96 int bind_ipi_to_irq(int ipi) 70.97 { 70.98 evtchn_op_t op;
72.1 --- a/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c Thu Aug 18 10:40:02 2005 -0800 72.2 +++ b/linux-2.6-xen-sparse/arch/xen/kernel/reboot.c Fri Aug 19 10:19:28 2005 -0800 72.3 @@ -16,6 +16,8 @@ 72.4 #include <asm-xen/queues.h> 72.5 #include <asm-xen/xenbus.h> 72.6 #include <asm-xen/ctrl_if.h> 72.7 +#include <linux/cpu.h> 72.8 +#include <linux/kthread.h> 72.9 72.10 #define SHUTDOWN_INVALID -1 72.11 #define SHUTDOWN_POWEROFF 0 72.12 @@ -58,20 +60,74 @@ EXPORT_SYMBOL(machine_power_off); 72.13 /* Ignore multiple shutdown requests. */ 72.14 static int shutting_down = SHUTDOWN_INVALID; 72.15 72.16 -static void __do_suspend(void) 72.17 +#ifndef CONFIG_HOTPLUG_CPU 72.18 +#define cpu_down(x) (-EOPNOTSUPP) 72.19 +#define cpu_up(x) (-EOPNOTSUPP) 72.20 +#endif 72.21 + 72.22 +static void save_vcpu_context(int vcpu, vcpu_guest_context_t *ctxt) 72.23 +{ 72.24 + int r; 72.25 + int gdt_pages; 72.26 + r = HYPERVISOR_vcpu_pickle(vcpu, ctxt); 72.27 + if (r != 0) 72.28 + panic("pickling vcpu %d -> %d!\n", vcpu, r); 72.29 + 72.30 + /* Translate from machine to physical addresses where necessary, 72.31 + so that they can be translated to our new machine address space 72.32 + after resume. libxc is responsible for doing this to vcpu0, 72.33 + but we do it to the others. */ 72.34 + gdt_pages = (ctxt->gdt_ents + 511) / 512; 72.35 + ctxt->ctrlreg[3] = machine_to_phys(ctxt->ctrlreg[3]); 72.36 + for (r = 0; r < gdt_pages; r++) 72.37 + ctxt->gdt_frames[r] = mfn_to_pfn(ctxt->gdt_frames[r]); 72.38 +} 72.39 + 72.40 +void _restore_vcpu(int cpu); 72.41 + 72.42 +atomic_t vcpus_rebooting; 72.43 + 72.44 +static int restore_vcpu_context(int vcpu, vcpu_guest_context_t *ctxt) 72.45 +{ 72.46 + int r; 72.47 + int gdt_pages = (ctxt->gdt_ents + 511) / 512; 72.48 + 72.49 + /* This is kind of a hack, and implicitly relies on the fact that 72.50 + the vcpu stops in a place where all of the call clobbered 72.51 + registers are already dead. */ 72.52 + ctxt->user_regs.esp -= 4; 72.53 + ((unsigned long *)ctxt->user_regs.esp)[0] = ctxt->user_regs.eip; 72.54 + ctxt->user_regs.eip = (unsigned long)_restore_vcpu; 72.55 + 72.56 + /* De-canonicalise. libxc handles this for vcpu 0, but we need 72.57 + to do it for the other vcpus. */ 72.58 + ctxt->ctrlreg[3] = phys_to_machine(ctxt->ctrlreg[3]); 72.59 + for (r = 0; r < gdt_pages; r++) 72.60 + ctxt->gdt_frames[r] = pfn_to_mfn(ctxt->gdt_frames[r]); 72.61 + 72.62 + atomic_set(&vcpus_rebooting, 1); 72.63 + r = HYPERVISOR_boot_vcpu(vcpu, ctxt); 72.64 + if (r != 0) { 72.65 + printk(KERN_EMERG "Failed to reboot vcpu %d (%d)\n", vcpu, r); 72.66 + return -1; 72.67 + } 72.68 + 72.69 + /* Make sure we wait for the new vcpu to come up before trying to do 72.70 + anything with it or starting the next one. */ 72.71 + while (atomic_read(&vcpus_rebooting)) 72.72 + barrier(); 72.73 + 72.74 + return 0; 72.75 +} 72.76 + 72.77 +static int __do_suspend(void *ignore) 72.78 { 72.79 int i, j; 72.80 suspend_record_t *suspend_record; 72.81 + static vcpu_guest_context_t suspended_cpu_records[NR_CPUS]; 72.82 72.83 /* Hmmm... a cleaner interface to suspend/resume blkdevs would be nice. */ 72.84 /* XXX SMH: yes it would :-( */ 72.85 -#ifdef CONFIG_XEN_BLKDEV_FRONTEND 72.86 - extern void blkdev_suspend(void); 72.87 - extern void blkdev_resume(void); 72.88 -#else 72.89 -#define blkdev_suspend() do{}while(0) 72.90 -#define blkdev_resume() do{}while(0) 72.91 -#endif 72.92 72.93 #ifdef CONFIG_XEN_NETDEV_FRONTEND 72.94 extern void netif_suspend(void); 72.95 @@ -104,14 +160,64 @@ static void __do_suspend(void) 72.96 extern unsigned long max_pfn; 72.97 extern unsigned int *pfn_to_mfn_frame_list; 72.98 72.99 + cpumask_t prev_online_cpus, prev_present_cpus; 72.100 + int err = 0; 72.101 + 72.102 + BUG_ON(smp_processor_id() != 0); 72.103 + BUG_ON(in_interrupt()); 72.104 + 72.105 +#if defined(CONFIG_SMP) && !defined(CONFIG_HOTPLUG_CPU) 72.106 + if (num_online_cpus() > 1) { 72.107 + printk(KERN_WARNING "Can't suspend SMP guests without CONFIG_HOTPLUG_CPU\n"); 72.108 + return -EOPNOTSUPP; 72.109 + } 72.110 +#endif 72.111 + 72.112 suspend_record = (suspend_record_t *)__get_free_page(GFP_KERNEL); 72.113 if ( suspend_record == NULL ) 72.114 goto out; 72.115 72.116 + /* Take all of the other cpus offline. We need to be careful not 72.117 + to get preempted between the final test for num_online_cpus() 72.118 + == 1 and disabling interrupts, since otherwise userspace could 72.119 + bring another cpu online, and then we'd be stuffed. At the 72.120 + same time, cpu_down can reschedule, so we need to enable 72.121 + preemption while doing that. This kind of sucks, but should be 72.122 + correct. */ 72.123 + /* (We don't need to worry about other cpus bringing stuff up, 72.124 + since by the time num_online_cpus() == 1, there aren't any 72.125 + other cpus) */ 72.126 + cpus_clear(prev_online_cpus); 72.127 + preempt_disable(); 72.128 + while (num_online_cpus() > 1) { 72.129 + preempt_enable(); 72.130 + for_each_online_cpu(i) { 72.131 + if (i == 0) 72.132 + continue; 72.133 + err = cpu_down(i); 72.134 + if (err != 0) { 72.135 + printk(KERN_CRIT "Failed to take all CPUs down: %d.\n", err); 72.136 + goto out_reenable_cpus; 72.137 + } 72.138 + cpu_set(i, prev_online_cpus); 72.139 + } 72.140 + preempt_disable(); 72.141 + } 72.142 + 72.143 suspend_record->nr_pfns = max_pfn; /* final number of pfns */ 72.144 72.145 __cli(); 72.146 72.147 + preempt_enable(); 72.148 + 72.149 + cpus_clear(prev_present_cpus); 72.150 + for_each_present_cpu(i) { 72.151 + if (i == 0) 72.152 + continue; 72.153 + save_vcpu_context(i, &suspended_cpu_records[i]); 72.154 + cpu_set(i, prev_present_cpus); 72.155 + } 72.156 + 72.157 #ifdef __i386__ 72.158 mm_pin_all(); 72.159 kmem_cache_shrink(pgd_cache); 72.160 @@ -119,8 +225,6 @@ static void __do_suspend(void) 72.161 72.162 netif_suspend(); 72.163 72.164 - blkdev_suspend(); 72.165 - 72.166 time_suspend(); 72.167 72.168 #ifdef CONFIG_SMP 72.169 @@ -141,7 +245,9 @@ static void __do_suspend(void) 72.170 memcpy(&suspend_record->resume_info, &xen_start_info, 72.171 sizeof(xen_start_info)); 72.172 72.173 - HYPERVISOR_suspend(virt_to_machine(suspend_record) >> PAGE_SHIFT); 72.174 + /* We'll stop somewhere inside this hypercall. When it returns, 72.175 + we'll start resuming after the restore. */ 72.176 + HYPERVISOR_suspend(virt_to_mfn(suspend_record)); 72.177 72.178 shutting_down = SHUTDOWN_INVALID; 72.179 72.180 @@ -157,10 +263,10 @@ static void __do_suspend(void) 72.181 for ( i=0, j=0; i < max_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ ) 72.182 { 72.183 pfn_to_mfn_frame_list[j] = 72.184 - virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT; 72.185 + virt_to_mfn(&phys_to_machine_mapping[i]); 72.186 } 72.187 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list = 72.188 - virt_to_machine(pfn_to_mfn_frame_list) >> PAGE_SHIFT; 72.189 + virt_to_mfn(pfn_to_mfn_frame_list); 72.190 72.191 gnttab_resume(); 72.192 72.193 @@ -176,17 +282,30 @@ static void __do_suspend(void) 72.194 72.195 time_resume(); 72.196 72.197 - blkdev_resume(); 72.198 - 72.199 netif_resume(); 72.200 72.201 usbif_resume(); 72.202 72.203 + for_each_cpu_mask(i, prev_present_cpus) { 72.204 + restore_vcpu_context(i, &suspended_cpu_records[i]); 72.205 + } 72.206 + 72.207 __sti(); 72.208 72.209 + out_reenable_cpus: 72.210 + for_each_cpu_mask(i, prev_online_cpus) { 72.211 + j = cpu_up(i); 72.212 + if (j != 0) { 72.213 + printk(KERN_CRIT "Failed to bring cpu %d back up (%d).\n", 72.214 + i, j); 72.215 + err = j; 72.216 + } 72.217 + } 72.218 + 72.219 out: 72.220 if ( suspend_record != NULL ) 72.221 free_page((unsigned long)suspend_record); 72.222 + return err; 72.223 } 72.224 72.225 static int shutdown_process(void *__unused) 72.226 @@ -233,6 +352,18 @@ static int shutdown_process(void *__unus 72.227 return 0; 72.228 } 72.229 72.230 +static struct task_struct *kthread_create_on_cpu(int (*f)(void *arg), 72.231 + void *arg, 72.232 + const char *name, 72.233 + int cpu) 72.234 +{ 72.235 + struct task_struct *p; 72.236 + p = kthread_create(f, arg, name); 72.237 + kthread_bind(p, cpu); 72.238 + wake_up_process(p); 72.239 + return p; 72.240 +} 72.241 + 72.242 static void __shutdown_handler(void *unused) 72.243 { 72.244 int err; 72.245 @@ -245,7 +376,7 @@ static void __shutdown_handler(void *unu 72.246 } 72.247 else 72.248 { 72.249 - __do_suspend(); 72.250 + kthread_create_on_cpu(__do_suspend, NULL, "suspender", 0); 72.251 } 72.252 } 72.253
86.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c Thu Aug 18 10:40:02 2005 -0800 86.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/process.c Fri Aug 19 10:19:28 2005 -0800 86.3 @@ -453,8 +453,8 @@ struct task_struct *__switch_to(struct t 86.4 #define C(i) do { \ 86.5 if (unlikely(next->tls_array[i] != prev->tls_array[i])) { \ 86.6 mcl->op = __HYPERVISOR_update_descriptor; \ 86.7 - mcl->args[0] = virt_to_machine(&get_cpu_gdt_table(cpu) \ 86.8 - [GDT_ENTRY_TLS_MIN + i]); \ 86.9 + mcl->args[0] = virt_to_machine( \ 86.10 + &get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i]);\ 86.11 mcl->args[1] = next->tls_array[i]; \ 86.12 mcl++; \ 86.13 } \ 86.14 @@ -474,7 +474,7 @@ struct task_struct *__switch_to(struct t 86.15 iobmp_op.cmd = 86.16 PHYSDEVOP_SET_IOBITMAP; 86.17 iobmp_op.u.set_iobitmap.bitmap = 86.18 - (unsigned long)next->io_bitmap_ptr; 86.19 + (char *)next->io_bitmap_ptr; 86.20 iobmp_op.u.set_iobitmap.nr_ports = 86.21 next->io_bitmap_ptr ? IO_BITMAP_BITS : 0; 86.22 mcl->op = __HYPERVISOR_physdev_op; 86.23 @@ -743,3 +743,9 @@ unsigned long arch_align_stack(unsigned 86.24 sp -= get_random_int() % 8192; 86.25 return sp & ~0xf; 86.26 } 86.27 + 86.28 +#ifndef CONFIG_SMP 86.29 +void _restore_vcpu(void) 86.30 +{ 86.31 +} 86.32 +#endif
87.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c Thu Aug 18 10:40:02 2005 -0800 87.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup.c Fri Aug 19 10:19:28 2005 -0800 87.3 @@ -795,7 +795,7 @@ void __init setup_arch(char **cmdline_p) 87.4 for ( i=0, j=0; i < end_pfn; i+=(PAGE_SIZE/sizeof(unsigned long)), j++ ) 87.5 { 87.6 pfn_to_mfn_frame_list[j] = 87.7 - virt_to_machine(&phys_to_machine_mapping[i]) >> PAGE_SHIFT; 87.8 + virt_to_mfn(&phys_to_machine_mapping[i]); 87.9 } 87.10 87.11 }
88.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c Thu Aug 18 10:40:02 2005 -0800 88.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/setup64.c Fri Aug 19 10:19:28 2005 -0800 88.3 @@ -139,7 +139,7 @@ void __init cpu_gdt_init(struct desc_ptr 88.4 for (va = gdt_descr->address, f = 0; 88.5 va < gdt_descr->address + gdt_descr->size; 88.6 va += PAGE_SIZE, f++) { 88.7 - frames[f] = virt_to_machine(va) >> PAGE_SHIFT; 88.8 + frames[f] = virt_to_mfn(va); 88.9 make_page_readonly((void *)va); 88.10 } 88.11 if (HYPERVISOR_set_gdt(frames, gdt_descr->size / 88.12 @@ -280,19 +280,16 @@ void __init cpu_init (void) 88.13 if (cpu) { 88.14 memcpy(cpu_gdt_table[cpu], cpu_gdt_table[0], GDT_SIZE); 88.15 } 88.16 -#endif 88.17 88.18 cpu_gdt_descr[cpu].size = GDT_SIZE; 88.19 cpu_gdt_descr[cpu].address = (unsigned long)cpu_gdt_table[cpu]; 88.20 88.21 - cpu_gdt_init(&cpu_gdt_descr[cpu]); 88.22 - 88.23 -#ifndef CONFIG_XEN 88.24 memcpy(me->thread.tls_array, cpu_gdt_table[cpu], GDT_ENTRY_TLS_ENTRIES * 8); 88.25 - 88.26 #else 88.27 memcpy(me->thread.tls_array, &get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN], 88.28 GDT_ENTRY_TLS_ENTRIES * 8); 88.29 + 88.30 + cpu_gdt_init(&cpu_gdt_descr[cpu]); 88.31 #endif 88.32 88.33 /*
90.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c Thu Aug 18 10:40:02 2005 -0800 90.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/kernel/smpboot.c Fri Aug 19 10:19:28 2005 -0800 90.3 @@ -780,7 +780,7 @@ static int __cpuinit do_boot_cpu(int cpu 90.4 for (va = cpu_gdt_descr[cpu].address, f = 0; 90.5 va < cpu_gdt_descr[cpu].address + cpu_gdt_descr[cpu].size; 90.6 va += PAGE_SIZE, f++) { 90.7 - ctxt.gdt_frames[f] = virt_to_machine(va) >> PAGE_SHIFT; 90.8 + ctxt.gdt_frames[f] = virt_to_mfn(va); 90.9 make_page_readonly((void *)va); 90.10 } 90.11 ctxt.gdt_ents = GDT_ENTRIES; 90.12 @@ -795,7 +795,7 @@ static int __cpuinit do_boot_cpu(int cpu 90.13 ctxt.failsafe_callback_eip = (unsigned long)failsafe_callback; 90.14 ctxt.syscall_callback_eip = (unsigned long)system_call; 90.15 90.16 - ctxt.ctrlreg[3] = (unsigned long)virt_to_machine(init_level4_pgt); 90.17 + ctxt.ctrlreg[3] = virt_to_mfn(init_level4_pgt) << PAGE_SHIFT; 90.18 90.19 boot_error = HYPERVISOR_boot_vcpu(cpu, &ctxt); 90.20 90.21 @@ -1286,4 +1286,10 @@ void smp_resume(void) 90.22 smp_intr_init(); 90.23 local_setup_timer_irq(); 90.24 } 90.25 + 90.26 +void _restore_vcpu(void) 90.27 +{ 90.28 + /* XXX need to write this */ 90.29 +} 90.30 + 90.31 #endif
94.1 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c Thu Aug 18 10:40:02 2005 -0800 94.2 +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/init.c Fri Aug 19 10:19:28 2005 -0800 94.3 @@ -742,7 +742,7 @@ void __init paging_init(void) 94.4 set_fixmap(FIX_ISAMAP_BEGIN - i, i * PAGE_SIZE); 94.5 else 94.6 __set_fixmap(FIX_ISAMAP_BEGIN - i, 94.7 - virt_to_machine(empty_zero_page), 94.8 + virt_to_mfn(empty_zero_page) << PAGE_SHIFT, 94.9 PAGE_KERNEL_RO); 94.10 } 94.11 #endif
98.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/Makefile Thu Aug 18 10:40:02 2005 -0800 98.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/Makefile Fri Aug 19 10:19:28 2005 -0800 98.3 @@ -1,2 +1,2 @@ 98.4 98.5 -obj-y := blkback.o control.o interface.o vbd.o 98.6 +obj-y := blkback.o xenbus.o interface.o vbd.o
99.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Thu Aug 18 10:40:02 2005 -0800 99.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c Fri Aug 19 10:19:28 2005 -0800 99.3 @@ -104,7 +104,6 @@ static inline domid_t ID_TO_DOM(unsigned 99.4 #endif 99.5 99.6 static int do_block_io_op(blkif_t *blkif, int max_to_do); 99.7 -static void dispatch_probe(blkif_t *blkif, blkif_request_t *req); 99.8 static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req); 99.9 static void make_response(blkif_t *blkif, unsigned long id, 99.10 unsigned short op, int st); 99.11 @@ -349,10 +348,6 @@ static int do_block_io_op(blkif_t *blkif 99.12 dispatch_rw_block_io(blkif, req); 99.13 break; 99.14 99.15 - case BLKIF_OP_PROBE: 99.16 - dispatch_probe(blkif, req); 99.17 - break; 99.18 - 99.19 default: 99.20 DPRINTK("error: unknown block io operation [%d]\n", 99.21 req->operation); 99.22 @@ -365,66 +360,6 @@ static int do_block_io_op(blkif_t *blkif 99.23 return more_to_do; 99.24 } 99.25 99.26 -static void dispatch_probe(blkif_t *blkif, blkif_request_t *req) 99.27 -{ 99.28 - int rsp = BLKIF_RSP_ERROR; 99.29 - int pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)]; 99.30 - 99.31 - /* We expect one buffer only. */ 99.32 - if ( unlikely(req->nr_segments != 1) ) 99.33 - goto out; 99.34 - 99.35 - /* Make sure the buffer is page-sized. */ 99.36 - if ( (blkif_first_sect(req->frame_and_sects[0]) != 0) || 99.37 - (blkif_last_sect(req->frame_and_sects[0]) != ((PAGE_SIZE/512)-1)) ) 99.38 - goto out; 99.39 - 99.40 -#ifdef CONFIG_XEN_BLKDEV_GRANT 99.41 - { 99.42 - struct gnttab_map_grant_ref map; 99.43 - 99.44 - map.host_addr = MMAP_VADDR(pending_idx, 0); 99.45 - map.flags = GNTMAP_host_map; 99.46 - map.ref = blkif_gref_from_fas(req->frame_and_sects[0]); 99.47 - map.dom = blkif->domid; 99.48 - 99.49 - if ( unlikely(HYPERVISOR_grant_table_op( 99.50 - GNTTABOP_map_grant_ref, &map, 1))) 99.51 - BUG(); 99.52 - 99.53 - if ( map.handle < 0 ) 99.54 - goto out; 99.55 - 99.56 - pending_handle(pending_idx, 0) = map.handle; 99.57 - } 99.58 -#else /* else CONFIG_XEN_BLKDEV_GRANT */ 99.59 - 99.60 -#ifdef CONFIG_XEN_BLKDEV_TAP_BE 99.61 - /* Grab the real frontend out of the probe message. */ 99.62 - if (req->frame_and_sects[1] == BLKTAP_COOKIE) 99.63 - blkif->is_blktap = 1; 99.64 -#endif 99.65 - 99.66 - 99.67 - if ( HYPERVISOR_update_va_mapping_otherdomain( 99.68 - MMAP_VADDR(pending_idx, 0), 99.69 - pfn_pte_ma(req->frame_and_sects[0] >> PAGE_SHIFT, PAGE_KERNEL), 99.70 -#ifdef CONFIG_XEN_BLKDEV_TAP_BE 99.71 - 0, (blkif->is_blktap ? ID_TO_DOM(req->id) : blkif->domid) ) ) 99.72 -#else 99.73 - 0, blkif->domid) ) 99.74 -#endif 99.75 - goto out; 99.76 -#endif /* endif CONFIG_XEN_BLKDEV_GRANT */ 99.77 - 99.78 - rsp = vbd_probe(blkif, (vdisk_t *)MMAP_VADDR(pending_idx, 0), 99.79 - PAGE_SIZE / sizeof(vdisk_t)); 99.80 - 99.81 - out: 99.82 - fast_flush_area(pending_idx, 1); 99.83 - make_response(blkif, req->id, req->operation, rsp); 99.84 -} 99.85 - 99.86 static void dispatch_rw_block_io(blkif_t *blkif, blkif_request_t *req) 99.87 { 99.88 extern void ll_rw_block(int rw, int nr, struct buffer_head * bhs[]); 99.89 @@ -460,7 +395,7 @@ static void dispatch_rw_block_io(blkif_t 99.90 goto bad_descriptor; 99.91 } 99.92 99.93 - preq.dev = req->device; 99.94 + preq.dev = req->handle; 99.95 preq.sector_number = req->sector_number; 99.96 preq.nr_sects = 0; 99.97 99.98 @@ -730,8 +665,8 @@ static int __init blkif_init(void) 99.99 0, SLAB_HWCACHE_ALIGN, NULL, NULL); 99.100 #endif 99.101 99.102 - blkif_ctrlif_init(); 99.103 - 99.104 + blkif_xenbus_init(); 99.105 + 99.106 #ifdef CONFIG_XEN_BLKDEV_GRANT 99.107 memset( pending_grant_handles, BLKBACK_INVALID_HANDLE, MMAP_PAGES ); 99.108 printk(KERN_ALERT "Blkif backend is using grant tables.\n");
100.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Thu Aug 18 10:40:02 2005 -0800 100.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/common.h Fri Aug 19 10:19:28 2005 -0800 100.3 @@ -13,7 +13,6 @@ 100.4 #include <asm/io.h> 100.5 #include <asm/setup.h> 100.6 #include <asm/pgalloc.h> 100.7 -#include <asm-xen/ctrl_if.h> 100.8 #include <asm-xen/evtchn.h> 100.9 #include <asm-xen/hypervisor.h> 100.10 #include <asm-xen/xen-public/io/blkif.h> 100.11 @@ -47,6 +46,7 @@ typedef struct blkif_st { 100.12 /* Physical parameters of the comms window. */ 100.13 unsigned long shmem_frame; 100.14 unsigned int evtchn; 100.15 + unsigned int remote_evtchn; 100.16 /* Comms information. */ 100.17 blkif_back_ring_t blk_ring; 100.18 /* VBDs attached to this interface. */ 100.19 @@ -71,7 +71,7 @@ typedef struct blkif_st { 100.20 struct work_struct work; 100.21 #ifdef CONFIG_XEN_BLKDEV_GRANT 100.22 u16 shmem_handle; 100.23 - memory_t shmem_vaddr; 100.24 + unsigned long shmem_vaddr; 100.25 grant_ref_t shmem_ref; 100.26 #endif 100.27 } blkif_t; 100.28 @@ -81,17 +81,29 @@ void blkif_destroy(blkif_be_destroy_t *d 100.29 void blkif_connect(blkif_be_connect_t *connect); 100.30 int blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id); 100.31 void blkif_disconnect_complete(blkif_t *blkif); 100.32 -blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle); 100.33 +blkif_t *blkif_find(domid_t domid); 100.34 +void free_blkif(blkif_t *blkif); 100.35 +int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn); 100.36 + 100.37 #define blkif_get(_b) (atomic_inc(&(_b)->refcnt)) 100.38 #define blkif_put(_b) \ 100.39 do { \ 100.40 if ( atomic_dec_and_test(&(_b)->refcnt) ) \ 100.41 - blkif_disconnect_complete(_b); \ 100.42 + free_blkif(_b); \ 100.43 } while (0) 100.44 100.45 -void vbd_create(blkif_be_vbd_create_t *create); 100.46 +struct vbd; 100.47 +void vbd_free(blkif_t *blkif, struct vbd *vbd); 100.48 + 100.49 +/* Creates inactive vbd. */ 100.50 +struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t vdevice, blkif_pdev_t pdevice, int readonly); 100.51 +int vbd_is_active(struct vbd *vbd); 100.52 +void vbd_activate(blkif_t *blkif, struct vbd *vbd); 100.53 + 100.54 +unsigned long vbd_size(struct vbd *vbd); 100.55 +unsigned int vbd_info(struct vbd *vbd); 100.56 +unsigned long vbd_secsize(struct vbd *vbd); 100.57 void vbd_destroy(blkif_be_vbd_destroy_t *delete); 100.58 -int vbd_probe(blkif_t *blkif, vdisk_t *vbd_info, int max_vbds); 100.59 void destroy_all_vbds(blkif_t *blkif); 100.60 100.61 struct phys_req { 100.62 @@ -104,10 +116,11 @@ struct phys_req { 100.63 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation); 100.64 100.65 void blkif_interface_init(void); 100.66 -void blkif_ctrlif_init(void); 100.67 100.68 void blkif_deschedule(blkif_t *blkif); 100.69 100.70 +void blkif_xenbus_init(void); 100.71 + 100.72 irqreturn_t blkif_be_int(int irq, void *dev_id, struct pt_regs *regs); 100.73 100.74 #endif /* __BLKIF__BACKEND__COMMON_H__ */
101.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/control.c Thu Aug 18 10:40:02 2005 -0800 101.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 101.3 @@ -1,61 +0,0 @@ 101.4 -/****************************************************************************** 101.5 - * arch/xen/drivers/blkif/backend/control.c 101.6 - * 101.7 - * Routines for interfacing with the control plane. 101.8 - * 101.9 - * Copyright (c) 2004, Keir Fraser 101.10 - */ 101.11 - 101.12 -#include "common.h" 101.13 - 101.14 -static void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id) 101.15 -{ 101.16 - DPRINTK("Received blkif backend message, subtype=%d\n", msg->subtype); 101.17 - 101.18 - switch ( msg->subtype ) 101.19 - { 101.20 - case CMSG_BLKIF_BE_CREATE: 101.21 - blkif_create((blkif_be_create_t *)&msg->msg[0]); 101.22 - break; 101.23 - case CMSG_BLKIF_BE_DESTROY: 101.24 - blkif_destroy((blkif_be_destroy_t *)&msg->msg[0]); 101.25 - break; 101.26 - case CMSG_BLKIF_BE_CONNECT: 101.27 - blkif_connect((blkif_be_connect_t *)&msg->msg[0]); 101.28 - break; 101.29 - case CMSG_BLKIF_BE_DISCONNECT: 101.30 - if ( !blkif_disconnect((blkif_be_disconnect_t *)&msg->msg[0],msg->id) ) 101.31 - return; /* Sending the response is deferred until later. */ 101.32 - break; 101.33 - case CMSG_BLKIF_BE_VBD_CREATE: 101.34 - vbd_create((blkif_be_vbd_create_t *)&msg->msg[0]); 101.35 - break; 101.36 - case CMSG_BLKIF_BE_VBD_DESTROY: 101.37 - vbd_destroy((blkif_be_vbd_destroy_t *)&msg->msg[0]); 101.38 - break; 101.39 - default: 101.40 - DPRINTK("Parse error while reading message subtype %d, len %d\n", 101.41 - msg->subtype, msg->length); 101.42 - msg->length = 0; 101.43 - break; 101.44 - } 101.45 - 101.46 - ctrl_if_send_response(msg); 101.47 -} 101.48 - 101.49 -void blkif_ctrlif_init(void) 101.50 -{ 101.51 - ctrl_msg_t cmsg; 101.52 - blkif_be_driver_status_t st; 101.53 - 101.54 - (void)ctrl_if_register_receiver(CMSG_BLKIF_BE, blkif_ctrlif_rx, 101.55 - CALLBACK_IN_BLOCKING_CONTEXT); 101.56 - 101.57 - /* Send a driver-UP notification to the domain controller. */ 101.58 - cmsg.type = CMSG_BLKIF_BE; 101.59 - cmsg.subtype = CMSG_BLKIF_BE_DRIVER_STATUS; 101.60 - cmsg.length = sizeof(blkif_be_driver_status_t); 101.61 - st.status = BLKIF_DRIVER_STATUS_UP; 101.62 - memcpy(cmsg.msg, &st, sizeof(st)); 101.63 - ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE); 101.64 -}
102.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Thu Aug 18 10:40:02 2005 -0800 102.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/interface.c Fri Aug 19 10:19:28 2005 -0800 102.3 @@ -7,24 +7,135 @@ 102.4 */ 102.5 102.6 #include "common.h" 102.7 +#include <asm-xen/ctrl_if.h> 102.8 +#include <asm-xen/evtchn.h> 102.9 102.10 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 102.11 #define VMALLOC_VMADDR(x) ((unsigned long)(x)) 102.12 #endif 102.13 102.14 #define BLKIF_HASHSZ 1024 102.15 -#define BLKIF_HASH(_d,_h) (((int)(_d)^(int)(_h))&(BLKIF_HASHSZ-1)) 102.16 +#define BLKIF_HASH(_d) (((int)(_d))&(BLKIF_HASHSZ-1)) 102.17 102.18 static kmem_cache_t *blkif_cachep; 102.19 static blkif_t *blkif_hash[BLKIF_HASHSZ]; 102.20 102.21 -blkif_t *blkif_find_by_handle(domid_t domid, unsigned int handle) 102.22 +blkif_t *blkif_find(domid_t domid) 102.23 +{ 102.24 + blkif_t *blkif = blkif_hash[BLKIF_HASH(domid)]; 102.25 + 102.26 + while (blkif) { 102.27 + if (blkif->domid == domid) { 102.28 + blkif_get(blkif); 102.29 + return blkif; 102.30 + } 102.31 + blkif = blkif->hash_next; 102.32 + } 102.33 + 102.34 + blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL); 102.35 + if (!blkif) 102.36 + return ERR_PTR(-ENOMEM); 102.37 + 102.38 + memset(blkif, 0, sizeof(*blkif)); 102.39 + blkif->domid = domid; 102.40 + blkif->status = DISCONNECTED; 102.41 + spin_lock_init(&blkif->vbd_lock); 102.42 + spin_lock_init(&blkif->blk_ring_lock); 102.43 + atomic_set(&blkif->refcnt, 1); 102.44 + 102.45 + blkif->hash_next = blkif_hash[BLKIF_HASH(domid)]; 102.46 + blkif_hash[BLKIF_HASH(domid)] = blkif; 102.47 + return blkif; 102.48 +} 102.49 + 102.50 +#ifndef CONFIG_XEN_BLKDEV_GRANT 102.51 +static int map_frontend_page(blkif_t *blkif, unsigned long localaddr, 102.52 + unsigned long shared_page) 102.53 +{ 102.54 + return direct_remap_area_pages(&init_mm, localaddr, 102.55 + shared_page<<PAGE_SHIFT, PAGE_SIZE, 102.56 + __pgprot(_KERNPG_TABLE), blkif->domid); 102.57 +} 102.58 + 102.59 +static void unmap_frontend_page(blkif_t *blkif) 102.60 +{ 102.61 +} 102.62 +#else 102.63 +static int map_frontend_page(blkif_t *blkif, unsigned long localaddr, 102.64 + unsigned long shared_page) 102.65 { 102.66 - blkif_t *blkif = blkif_hash[BLKIF_HASH(domid, handle)]; 102.67 - while ( (blkif != NULL) && 102.68 - ((blkif->domid != domid) || (blkif->handle != handle)) ) 102.69 - blkif = blkif->hash_next; 102.70 - return blkif; 102.71 + struct gnttab_map_grant_ref op; 102.72 + op.host_addr = localaddr; 102.73 + op.flags = GNTMAP_host_map; 102.74 + op.ref = shared_page; 102.75 + op.dom = blkif->domid; 102.76 + 102.77 + BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) ); 102.78 + 102.79 + if (op.handle < 0) { 102.80 + DPRINTK(" Grant table operation failure !\n"); 102.81 + return op.handle; 102.82 + } 102.83 + 102.84 + blkif->shmem_ref = shared_page; 102.85 + blkif->shmem_handle = op.handle; 102.86 + blkif->shmem_vaddr = localaddr; 102.87 + return 0; 102.88 +} 102.89 + 102.90 +static void unmap_frontend_page(blkif_t *blkif) 102.91 +{ 102.92 + struct gnttab_unmap_grant_ref op; 102.93 + 102.94 + op.host_addr = blkif->shmem_vaddr; 102.95 + op.handle = blkif->shmem_handle; 102.96 + op.dev_bus_addr = 0; 102.97 + BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); 102.98 +} 102.99 +#endif /* CONFIG_XEN_BLKDEV_GRANT */ 102.100 + 102.101 +int blkif_map(blkif_t *blkif, unsigned long shared_page, unsigned int evtchn) 102.102 +{ 102.103 + struct vm_struct *vma; 102.104 + blkif_sring_t *sring; 102.105 + evtchn_op_t op = { .cmd = EVTCHNOP_bind_interdomain }; 102.106 + int err; 102.107 + 102.108 + BUG_ON(blkif->remote_evtchn); 102.109 + 102.110 + if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL ) 102.111 + return -ENOMEM; 102.112 + 102.113 + err = map_frontend_page(blkif, VMALLOC_VMADDR(vma->addr), shared_page); 102.114 + if (err) { 102.115 + vfree(vma->addr); 102.116 + return err; 102.117 + } 102.118 + 102.119 + op.u.bind_interdomain.dom1 = DOMID_SELF; 102.120 + op.u.bind_interdomain.dom2 = blkif->domid; 102.121 + op.u.bind_interdomain.port1 = 0; 102.122 + op.u.bind_interdomain.port2 = evtchn; 102.123 + err = HYPERVISOR_event_channel_op(&op); 102.124 + if (err) { 102.125 + unmap_frontend_page(blkif); 102.126 + vfree(vma->addr); 102.127 + return err; 102.128 + } 102.129 + 102.130 + blkif->evtchn = op.u.bind_interdomain.port1; 102.131 + blkif->remote_evtchn = evtchn; 102.132 + 102.133 + sring = (blkif_sring_t *)vma->addr; 102.134 + SHARED_RING_INIT(sring); 102.135 + BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE); 102.136 + 102.137 + bind_evtchn_to_irqhandler(blkif->evtchn, blkif_be_int, 0, "blkif-backend", 102.138 + blkif); 102.139 + blkif->status = CONNECTED; 102.140 + blkif->shmem_frame = shared_page; 102.141 + 102.142 + return 0; 102.143 } 102.144 102.145 static void __blkif_disconnect_complete(void *arg) 102.146 @@ -32,21 +143,13 @@ static void __blkif_disconnect_complete( 102.147 blkif_t *blkif = (blkif_t *)arg; 102.148 ctrl_msg_t cmsg; 102.149 blkif_be_disconnect_t disc; 102.150 -#ifdef CONFIG_XEN_BLKDEV_GRANT 102.151 - struct gnttab_unmap_grant_ref op; 102.152 -#endif 102.153 102.154 /* 102.155 * These can't be done in blkif_disconnect() because at that point there 102.156 * may be outstanding requests at the disc whose asynchronous responses 102.157 * must still be notified to the remote driver. 102.158 */ 102.159 -#ifdef CONFIG_XEN_BLKDEV_GRANT 102.160 - op.host_addr = blkif->shmem_vaddr; 102.161 - op.handle = blkif->shmem_handle; 102.162 - op.dev_bus_addr = 0; 102.163 - BUG_ON(HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1)); 102.164 -#endif 102.165 + unmap_frontend_page(blkif); 102.166 vfree(blkif->blk_ring.sring); 102.167 102.168 /* Construct the deferred response message. */ 102.169 @@ -81,200 +184,35 @@ void blkif_disconnect_complete(blkif_t * 102.170 schedule_work(&blkif->work); 102.171 } 102.172 102.173 -void blkif_create(blkif_be_create_t *create) 102.174 +void free_blkif(blkif_t *blkif) 102.175 { 102.176 - domid_t domid = create->domid; 102.177 - unsigned int handle = create->blkif_handle; 102.178 - blkif_t **pblkif, *blkif; 102.179 - 102.180 - if ( (blkif = kmem_cache_alloc(blkif_cachep, GFP_KERNEL)) == NULL ) 102.181 - { 102.182 - DPRINTK("Could not create blkif: out of memory\n"); 102.183 - create->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; 102.184 - return; 102.185 - } 102.186 + blkif_t **pblkif; 102.187 + evtchn_op_t op = { .cmd = EVTCHNOP_close }; 102.188 102.189 - memset(blkif, 0, sizeof(*blkif)); 102.190 - blkif->domid = domid; 102.191 - blkif->handle = handle; 102.192 - blkif->status = DISCONNECTED; 102.193 - spin_lock_init(&blkif->vbd_lock); 102.194 - spin_lock_init(&blkif->blk_ring_lock); 102.195 - atomic_set(&blkif->refcnt, 0); 102.196 + op.u.close.port = blkif->evtchn; 102.197 + op.u.close.dom = DOMID_SELF; 102.198 + HYPERVISOR_event_channel_op(&op); 102.199 + op.u.close.port = blkif->remote_evtchn; 102.200 + op.u.close.dom = blkif->domid; 102.201 + HYPERVISOR_event_channel_op(&op); 102.202 102.203 - pblkif = &blkif_hash[BLKIF_HASH(domid, handle)]; 102.204 - while ( *pblkif != NULL ) 102.205 - { 102.206 - if ( ((*pblkif)->domid == domid) && ((*pblkif)->handle == handle) ) 102.207 - { 102.208 - DPRINTK("Could not create blkif: already exists\n"); 102.209 - create->status = BLKIF_BE_STATUS_INTERFACE_EXISTS; 102.210 - kmem_cache_free(blkif_cachep, blkif); 102.211 - return; 102.212 - } 102.213 - pblkif = &(*pblkif)->hash_next; 102.214 + if (blkif->evtchn) 102.215 + unbind_evtchn_from_irqhandler(blkif->evtchn, blkif); 102.216 + 102.217 + if (blkif->blk_ring.sring) { 102.218 + unmap_frontend_page(blkif); 102.219 + vfree(blkif->blk_ring.sring); 102.220 } 102.221 102.222 - blkif->hash_next = *pblkif; 102.223 - *pblkif = blkif; 102.224 - 102.225 - DPRINTK("Successfully created blkif\n"); 102.226 - create->status = BLKIF_BE_STATUS_OKAY; 102.227 -} 102.228 - 102.229 -void blkif_destroy(blkif_be_destroy_t *destroy) 102.230 -{ 102.231 - domid_t domid = destroy->domid; 102.232 - unsigned int handle = destroy->blkif_handle; 102.233 - blkif_t **pblkif, *blkif; 102.234 - 102.235 - pblkif = &blkif_hash[BLKIF_HASH(domid, handle)]; 102.236 - while ( (blkif = *pblkif) != NULL ) 102.237 + pblkif = &blkif_hash[BLKIF_HASH(blkif->domid)]; 102.238 + while ( *pblkif != blkif ) 102.239 { 102.240 - if ( (blkif->domid == domid) && (blkif->handle == handle) ) 102.241 - { 102.242 - if ( blkif->status != DISCONNECTED ) 102.243 - goto still_connected; 102.244 - goto destroy; 102.245 - } 102.246 - pblkif = &blkif->hash_next; 102.247 + BUG_ON(!*pblkif); 102.248 + pblkif = &(*pblkif)->hash_next; 102.249 } 102.250 - 102.251 - destroy->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; 102.252 - return; 102.253 - 102.254 - still_connected: 102.255 - destroy->status = BLKIF_BE_STATUS_INTERFACE_CONNECTED; 102.256 - return; 102.257 - 102.258 - destroy: 102.259 *pblkif = blkif->hash_next; 102.260 destroy_all_vbds(blkif); 102.261 kmem_cache_free(blkif_cachep, blkif); 102.262 - destroy->status = BLKIF_BE_STATUS_OKAY; 102.263 -} 102.264 - 102.265 -void blkif_connect(blkif_be_connect_t *connect) 102.266 -{ 102.267 - domid_t domid = connect->domid; 102.268 - unsigned int handle = connect->blkif_handle; 102.269 - unsigned int evtchn = connect->evtchn; 102.270 - unsigned long shmem_frame = connect->shmem_frame; 102.271 - struct vm_struct *vma; 102.272 -#ifdef CONFIG_XEN_BLKDEV_GRANT 102.273 - int ref = connect->shmem_ref; 102.274 -#else 102.275 - pgprot_t prot; 102.276 - int error; 102.277 -#endif 102.278 - blkif_t *blkif; 102.279 - blkif_sring_t *sring; 102.280 - 102.281 - blkif = blkif_find_by_handle(domid, handle); 102.282 - if ( unlikely(blkif == NULL) ) 102.283 - { 102.284 - DPRINTK("blkif_connect attempted for non-existent blkif (%u,%u)\n", 102.285 - connect->domid, connect->blkif_handle); 102.286 - connect->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; 102.287 - return; 102.288 - } 102.289 - 102.290 - if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL ) 102.291 - { 102.292 - connect->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; 102.293 - return; 102.294 - } 102.295 - 102.296 -#ifndef CONFIG_XEN_BLKDEV_GRANT 102.297 - prot = __pgprot(_KERNPG_TABLE); 102.298 - error = direct_remap_area_pages(&init_mm, VMALLOC_VMADDR(vma->addr), 102.299 - shmem_frame<<PAGE_SHIFT, PAGE_SIZE, 102.300 - prot, domid); 102.301 - if ( error != 0 ) 102.302 - { 102.303 - if ( error == -ENOMEM ) 102.304 - connect->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; 102.305 - else if ( error == -EFAULT ) 102.306 - connect->status = BLKIF_BE_STATUS_MAPPING_ERROR; 102.307 - else 102.308 - connect->status = BLKIF_BE_STATUS_ERROR; 102.309 - vfree(vma->addr); 102.310 - return; 102.311 - } 102.312 -#else 102.313 - { /* Map: Use the Grant table reference */ 102.314 - struct gnttab_map_grant_ref op; 102.315 - op.host_addr = VMALLOC_VMADDR(vma->addr); 102.316 - op.flags = GNTMAP_host_map; 102.317 - op.ref = ref; 102.318 - op.dom = domid; 102.319 - 102.320 - BUG_ON( HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1) ); 102.321 - 102.322 - handle = op.handle; 102.323 - 102.324 - if (op.handle < 0) { 102.325 - DPRINTK(" Grant table operation failure !\n"); 102.326 - connect->status = BLKIF_BE_STATUS_MAPPING_ERROR; 102.327 - vfree(vma->addr); 102.328 - return; 102.329 - } 102.330 - 102.331 - blkif->shmem_ref = ref; 102.332 - blkif->shmem_handle = handle; 102.333 - blkif->shmem_vaddr = VMALLOC_VMADDR(vma->addr); 102.334 - } 102.335 -#endif 102.336 - 102.337 - if ( blkif->status != DISCONNECTED ) 102.338 - { 102.339 - connect->status = BLKIF_BE_STATUS_INTERFACE_CONNECTED; 102.340 - vfree(vma->addr); 102.341 - return; 102.342 - } 102.343 - sring = (blkif_sring_t *)vma->addr; 102.344 - SHARED_RING_INIT(sring); 102.345 - BACK_RING_INIT(&blkif->blk_ring, sring, PAGE_SIZE); 102.346 - 102.347 - blkif->evtchn = evtchn; 102.348 - blkif->shmem_frame = shmem_frame; 102.349 - blkif->status = CONNECTED; 102.350 - blkif_get(blkif); 102.351 - 102.352 - bind_evtchn_to_irqhandler( 102.353 - blkif->evtchn, blkif_be_int, 0, "blkif-backend", blkif); 102.354 - 102.355 - connect->status = BLKIF_BE_STATUS_OKAY; 102.356 -} 102.357 - 102.358 -int blkif_disconnect(blkif_be_disconnect_t *disconnect, u8 rsp_id) 102.359 -{ 102.360 - domid_t domid = disconnect->domid; 102.361 - unsigned int handle = disconnect->blkif_handle; 102.362 - blkif_t *blkif; 102.363 - 102.364 - blkif = blkif_find_by_handle(domid, handle); 102.365 - if ( unlikely(blkif == NULL) ) 102.366 - { 102.367 - DPRINTK("blkif_disconnect attempted for non-existent blkif" 102.368 - " (%u,%u)\n", disconnect->domid, disconnect->blkif_handle); 102.369 - disconnect->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; 102.370 - return 1; /* Caller will send response error message. */ 102.371 - } 102.372 - 102.373 - if ( blkif->status == CONNECTED ) 102.374 - { 102.375 - blkif->status = DISCONNECTING; 102.376 - blkif->disconnect_rspid = rsp_id; 102.377 - wmb(); /* Let other CPUs see the status change. */ 102.378 - unbind_evtchn_from_irqhandler(blkif->evtchn, blkif); 102.379 - blkif_deschedule(blkif); 102.380 - blkif_put(blkif); 102.381 - return 0; /* Caller should not send response message. */ 102.382 - } 102.383 - 102.384 - disconnect->status = BLKIF_BE_STATUS_OKAY; 102.385 - return 1; 102.386 } 102.387 102.388 void __init blkif_interface_init(void)
103.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Thu Aug 18 10:40:02 2005 -0800 103.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/vbd.c Fri Aug 19 10:19:28 2005 -0800 103.3 @@ -11,13 +11,16 @@ 103.4 */ 103.5 103.6 #include "common.h" 103.7 +#include <asm-xen/xenbus.h> 103.8 103.9 struct vbd { 103.10 - blkif_vdev_t vdevice; /* what the domain refers to this vbd as */ 103.11 + blkif_vdev_t handle; /* what the domain refers to this vbd as */ 103.12 unsigned char readonly; /* Non-zero -> read-only */ 103.13 unsigned char type; /* VDISK_xxx */ 103.14 blkif_pdev_t pdevice; /* phys device that this vbd maps to */ 103.15 struct block_device *bdev; 103.16 + 103.17 + int active; 103.18 rb_node_t rb; /* for linking into R-B tree lookup struct */ 103.19 }; 103.20 103.21 @@ -33,57 +36,45 @@ static inline dev_t vbd_map_devnum(blkif 103.22 #define bdev_hardsect_size(_b) 512 103.23 #endif 103.24 103.25 -void vbd_create(blkif_be_vbd_create_t *create) 103.26 +unsigned long vbd_size(struct vbd *vbd) 103.27 +{ 103.28 + return vbd_sz(vbd); 103.29 +} 103.30 + 103.31 +unsigned int vbd_info(struct vbd *vbd) 103.32 +{ 103.33 + return vbd->type | (vbd->readonly?VDISK_READONLY:0); 103.34 +} 103.35 + 103.36 +unsigned long vbd_secsize(struct vbd *vbd) 103.37 +{ 103.38 + return bdev_hardsect_size(vbd->bdev); 103.39 +} 103.40 + 103.41 +int vbd_is_active(struct vbd *vbd) 103.42 +{ 103.43 + return vbd->active; 103.44 +} 103.45 + 103.46 +struct vbd *vbd_create(blkif_t *blkif, blkif_vdev_t handle, 103.47 + blkif_pdev_t pdevice, int readonly) 103.48 { 103.49 struct vbd *vbd; 103.50 - rb_node_t **rb_p, *rb_parent = NULL; 103.51 - blkif_t *blkif; 103.52 - blkif_vdev_t vdevice = create->vdevice; 103.53 - 103.54 - blkif = blkif_find_by_handle(create->domid, create->blkif_handle); 103.55 - if ( unlikely(blkif == NULL) ) 103.56 - { 103.57 - DPRINTK("vbd_create attempted for non-existent blkif (%u,%u)\n", 103.58 - create->domid, create->blkif_handle); 103.59 - create->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; 103.60 - return; 103.61 - } 103.62 - 103.63 - rb_p = &blkif->vbd_rb.rb_node; 103.64 - while ( *rb_p != NULL ) 103.65 - { 103.66 - rb_parent = *rb_p; 103.67 - vbd = rb_entry(rb_parent, struct vbd, rb); 103.68 - if ( vdevice < vbd->vdevice ) 103.69 - { 103.70 - rb_p = &rb_parent->rb_left; 103.71 - } 103.72 - else if ( vdevice > vbd->vdevice ) 103.73 - { 103.74 - rb_p = &rb_parent->rb_right; 103.75 - } 103.76 - else 103.77 - { 103.78 - DPRINTK("vbd_create attempted for already existing vbd\n"); 103.79 - create->status = BLKIF_BE_STATUS_VBD_EXISTS; 103.80 - return; 103.81 - } 103.82 - } 103.83 103.84 if ( unlikely((vbd = kmalloc(sizeof(struct vbd), GFP_KERNEL)) == NULL) ) 103.85 { 103.86 DPRINTK("vbd_create: out of memory\n"); 103.87 - create->status = BLKIF_BE_STATUS_OUT_OF_MEMORY; 103.88 - return; 103.89 + return ERR_PTR(-ENOMEM); 103.90 } 103.91 103.92 - vbd->vdevice = vdevice; 103.93 - vbd->readonly = create->readonly; 103.94 + vbd->handle = handle; 103.95 + vbd->readonly = readonly; 103.96 vbd->type = 0; 103.97 + vbd->active = 0; 103.98 103.99 - /* Mask to 16-bit for compatibility with old tools */ 103.100 - vbd->pdevice = create->pdevice & 0xffff; 103.101 + vbd->pdevice = pdevice; 103.102 103.103 + /* FIXME: Who frees vbd on failure? --RR */ 103.104 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 103.105 vbd->bdev = open_by_devnum( 103.106 vbd_map_devnum(vbd->pdevice), 103.107 @@ -91,16 +82,14 @@ void vbd_create(blkif_be_vbd_create_t *c 103.108 if ( IS_ERR(vbd->bdev) ) 103.109 { 103.110 DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 103.111 - create->status = BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND; 103.112 - return; 103.113 + return ERR_PTR(-ENOENT); 103.114 } 103.115 103.116 if ( (vbd->bdev->bd_disk == NULL) ) 103.117 { 103.118 DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 103.119 - create->status = BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND; 103.120 bdev_put(vbd->bdev); 103.121 - return; 103.122 + return ERR_PTR(-ENOENT); 103.123 } 103.124 103.125 if ( vbd->bdev->bd_disk->flags & GENHD_FL_CD ) 103.126 @@ -112,62 +101,64 @@ void vbd_create(blkif_be_vbd_create_t *c 103.127 if ( (blk_size[MAJOR(vbd->pdevice)] == NULL) || (vbd_sz(vbd) == 0) ) 103.128 { 103.129 DPRINTK("vbd_creat: device %08x doesn't exist.\n", vbd->pdevice); 103.130 - create->status = BLKIF_BE_STATUS_PHYSDEV_NOT_FOUND; 103.131 - return; 103.132 + return ERR_PTR(-ENOENT); 103.133 } 103.134 #endif 103.135 103.136 + DPRINTK("Successful creation of handle=%04x (dom=%u)\n", 103.137 + handle, blkif->domid); 103.138 + return vbd; 103.139 +} 103.140 + 103.141 +void vbd_activate(blkif_t *blkif, struct vbd *vbd) 103.142 +{ 103.143 + rb_node_t **rb_p, *rb_parent = NULL; 103.144 + struct vbd *i; 103.145 + BUG_ON(vbd_is_active(vbd)); 103.146 + 103.147 + /* Find where to put it. */ 103.148 + rb_p = &blkif->vbd_rb.rb_node; 103.149 + while ( *rb_p != NULL ) 103.150 + { 103.151 + rb_parent = *rb_p; 103.152 + i = rb_entry(rb_parent, struct vbd, rb); 103.153 + if ( vbd->handle < i->handle ) 103.154 + { 103.155 + rb_p = &rb_parent->rb_left; 103.156 + } 103.157 + else if ( vbd->handle > i->handle ) 103.158 + { 103.159 + rb_p = &rb_parent->rb_right; 103.160 + } 103.161 + else 103.162 + { 103.163 + /* We never create two of same vbd, so not possible. */ 103.164 + BUG(); 103.165 + } 103.166 + } 103.167 + 103.168 + /* Now we're active. */ 103.169 + vbd->active = 1; 103.170 + blkif_get(blkif); 103.171 + 103.172 spin_lock(&blkif->vbd_lock); 103.173 rb_link_node(&vbd->rb, rb_parent, rb_p); 103.174 rb_insert_color(&vbd->rb, &blkif->vbd_rb); 103.175 spin_unlock(&blkif->vbd_lock); 103.176 - 103.177 - DPRINTK("Successful creation of vdev=%04x (dom=%u)\n", 103.178 - vdevice, create->domid); 103.179 - create->status = BLKIF_BE_STATUS_OKAY; 103.180 } 103.181 103.182 - 103.183 -void vbd_destroy(blkif_be_vbd_destroy_t *destroy) 103.184 +void vbd_free(blkif_t *blkif, struct vbd *vbd) 103.185 { 103.186 - blkif_t *blkif; 103.187 - struct vbd *vbd; 103.188 - rb_node_t *rb; 103.189 - blkif_vdev_t vdevice = destroy->vdevice; 103.190 - 103.191 - blkif = blkif_find_by_handle(destroy->domid, destroy->blkif_handle); 103.192 - if ( unlikely(blkif == NULL) ) 103.193 - { 103.194 - DPRINTK("vbd_destroy attempted for non-existent blkif (%u,%u)\n", 103.195 - destroy->domid, destroy->blkif_handle); 103.196 - destroy->status = BLKIF_BE_STATUS_INTERFACE_NOT_FOUND; 103.197 - return; 103.198 + if (vbd_is_active(vbd)) { 103.199 + spin_lock(&blkif->vbd_lock); 103.200 + rb_erase(&vbd->rb, &blkif->vbd_rb); 103.201 + spin_unlock(&blkif->vbd_lock); 103.202 + blkif_put(blkif); 103.203 } 103.204 - 103.205 - rb = blkif->vbd_rb.rb_node; 103.206 - while ( rb != NULL ) 103.207 - { 103.208 - vbd = rb_entry(rb, struct vbd, rb); 103.209 - if ( vdevice < vbd->vdevice ) 103.210 - rb = rb->rb_left; 103.211 - else if ( vdevice > vbd->vdevice ) 103.212 - rb = rb->rb_right; 103.213 - else 103.214 - goto found; 103.215 - } 103.216 - 103.217 - destroy->status = BLKIF_BE_STATUS_VBD_NOT_FOUND; 103.218 - return; 103.219 - 103.220 - found: 103.221 - spin_lock(&blkif->vbd_lock); 103.222 - rb_erase(rb, &blkif->vbd_rb); 103.223 - spin_unlock(&blkif->vbd_lock); 103.224 bdev_put(vbd->bdev); 103.225 kfree(vbd); 103.226 } 103.227 103.228 - 103.229 void destroy_all_vbds(blkif_t *blkif) 103.230 { 103.231 struct vbd *vbd; 103.232 @@ -183,74 +174,12 @@ void destroy_all_vbds(blkif_t *blkif) 103.233 bdev_put(vbd->bdev); 103.234 kfree(vbd); 103.235 spin_lock(&blkif->vbd_lock); 103.236 + blkif_put(blkif); 103.237 } 103.238 103.239 spin_unlock(&blkif->vbd_lock); 103.240 } 103.241 103.242 - 103.243 -static void vbd_probe_single( 103.244 - blkif_t *blkif, vdisk_t *vbd_info, struct vbd *vbd) 103.245 -{ 103.246 - vbd_info->device = vbd->vdevice; 103.247 - vbd_info->info = vbd->type | (vbd->readonly ? VDISK_READONLY : 0); 103.248 - vbd_info->capacity = vbd_sz(vbd); 103.249 - vbd_info->sector_size = bdev_hardsect_size(vbd->bdev); 103.250 -} 103.251 - 103.252 - 103.253 -int vbd_probe(blkif_t *blkif, vdisk_t *vbd_info, int max_vbds) 103.254 -{ 103.255 - int rc = 0, nr_vbds = 0; 103.256 - rb_node_t *rb; 103.257 - 103.258 - spin_lock(&blkif->vbd_lock); 103.259 - 103.260 - if ( (rb = blkif->vbd_rb.rb_node) == NULL ) 103.261 - goto out; 103.262 - 103.263 - new_subtree: 103.264 - /* STEP 1. Find least node (it'll be left-most). */ 103.265 - while ( rb->rb_left != NULL ) 103.266 - rb = rb->rb_left; 103.267 - 103.268 - for ( ; ; ) 103.269 - { 103.270 - /* STEP 2. Dealt with left subtree. Now process current node. */ 103.271 - vbd_probe_single(blkif, &vbd_info[nr_vbds], 103.272 - rb_entry(rb, struct vbd, rb)); 103.273 - if ( ++nr_vbds == max_vbds ) 103.274 - goto out; 103.275 - 103.276 - /* STEP 3. Process right subtree, if any. */ 103.277 - if ( rb->rb_right != NULL ) 103.278 - { 103.279 - rb = rb->rb_right; 103.280 - goto new_subtree; 103.281 - } 103.282 - 103.283 - /* STEP 4. Done both subtrees. Head back through ancesstors. */ 103.284 - for ( ; ; ) 103.285 - { 103.286 - /* We're done when we get back to the root node. */ 103.287 - if ( rb->rb_parent == NULL ) 103.288 - goto out; 103.289 - /* If we are left of parent, then parent is next to process. */ 103.290 - if ( rb->rb_parent->rb_left == rb ) 103.291 - break; 103.292 - /* If we are right of parent, then we climb to grandparent. */ 103.293 - rb = rb->rb_parent; 103.294 - } 103.295 - 103.296 - rb = rb->rb_parent; 103.297 - } 103.298 - 103.299 - out: 103.300 - spin_unlock(&blkif->vbd_lock); 103.301 - return (rc == 0) ? nr_vbds : rc; 103.302 -} 103.303 - 103.304 - 103.305 int vbd_translate(struct phys_req *req, blkif_t *blkif, int operation) 103.306 { 103.307 struct vbd *vbd; 103.308 @@ -264,9 +193,9 @@ int vbd_translate(struct phys_req *req, 103.309 while ( rb != NULL ) 103.310 { 103.311 vbd = rb_entry(rb, struct vbd, rb); 103.312 - if ( req->dev < vbd->vdevice ) 103.313 + if ( req->dev < vbd->handle ) 103.314 rb = rb->rb_left; 103.315 - else if ( req->dev > vbd->vdevice ) 103.316 + else if ( req->dev > vbd->handle ) 103.317 rb = rb->rb_right; 103.318 else 103.319 goto found;
104.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 104.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkback/xenbus.c Fri Aug 19 10:19:28 2005 -0800 104.3 @@ -0,0 +1,308 @@ 104.4 +/* Xenbus code for blkif backend 104.5 + Copyright (C) 2005 Rusty Russell <rusty@rustcorp.com.au> 104.6 + 104.7 + This program is free software; you can redistribute it and/or modify 104.8 + it under the terms of the GNU General Public License as published by 104.9 + the Free Software Foundation; either version 2 of the License, or 104.10 + (at your option) any later version. 104.11 + 104.12 + This program is distributed in the hope that it will be useful, 104.13 + but WITHOUT ANY WARRANTY; without even the implied warranty of 104.14 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 104.15 + GNU General Public License for more details. 104.16 + 104.17 + You should have received a copy of the GNU General Public License 104.18 + along with this program; if not, write to the Free Software 104.19 + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 104.20 +*/ 104.21 +#include <stdarg.h> 104.22 +#include <linux/module.h> 104.23 +#include <asm-xen/xenbus.h> 104.24 +#include "common.h" 104.25 + 104.26 +struct backend_info 104.27 +{ 104.28 + struct xenbus_device *dev; 104.29 + 104.30 + /* our communications channel */ 104.31 + blkif_t *blkif; 104.32 + struct vbd *vbd; 104.33 + 104.34 + long int frontend_id; 104.35 + long int pdev; 104.36 + long int readonly; 104.37 + 104.38 + /* watch back end for changes */ 104.39 + struct xenbus_watch backend_watch; 104.40 + 104.41 + /* watch front end for changes */ 104.42 + struct xenbus_watch watch; 104.43 + char *frontpath; 104.44 +}; 104.45 + 104.46 +static int blkback_remove(struct xenbus_device *dev) 104.47 +{ 104.48 + struct backend_info *be = dev->data; 104.49 + 104.50 + if (be->watch.node) 104.51 + unregister_xenbus_watch(&be->watch); 104.52 + unregister_xenbus_watch(&be->backend_watch); 104.53 + if (be->vbd) 104.54 + vbd_free(be->blkif, be->vbd); 104.55 + if (be->blkif) 104.56 + blkif_put(be->blkif); 104.57 + if (be->frontpath) 104.58 + kfree(be->frontpath); 104.59 + kfree(be); 104.60 + return 0; 104.61 +} 104.62 + 104.63 +/* Front end tells us frame. */ 104.64 +static void frontend_changed(struct xenbus_watch *watch, const char *node) 104.65 +{ 104.66 + unsigned long sharedmfn; 104.67 + unsigned int evtchn; 104.68 + int err; 104.69 + struct backend_info *be 104.70 + = container_of(watch, struct backend_info, watch); 104.71 + 104.72 + /* If other end is gone, delete ourself. */ 104.73 + if (!xenbus_exists(be->frontpath, "")) { 104.74 + xenbus_rm(be->dev->nodename, ""); 104.75 + device_unregister(&be->dev->dev); 104.76 + return; 104.77 + } 104.78 + if (vbd_is_active(be->vbd)) 104.79 + return; 104.80 + 104.81 +#ifndef CONFIG_XEN_BLKDEV_GRANT 104.82 + err = xenbus_gather(be->frontpath, "shared-frame", "%lu", &sharedmfn, 104.83 + "event-channel", "%u", &evtchn, NULL); 104.84 + if (err) { 104.85 + xenbus_dev_error(be->dev, err, 104.86 + "reading %s/shared-frame and event-channel", 104.87 + be->frontpath); 104.88 + return; 104.89 + } 104.90 +#else 104.91 + err = xenbus_gather(be->frontpath, "grant-id", "%lu", &sharedmfn, 104.92 + "event-channel", "%u", &evtchn, NULL); 104.93 + if (err) { 104.94 + xenbus_dev_error(be->dev, err, 104.95 + "reading %s/grant-id and event-channel", 104.96 + be->frontpath); 104.97 + return; 104.98 + } 104.99 +#endif 104.100 + 104.101 + /* Domains must use same shared frame for all vbds. */ 104.102 + if (be->blkif->status == CONNECTED && 104.103 + (evtchn != be->blkif->remote_evtchn || 104.104 + sharedmfn != be->blkif->shmem_frame)) { 104.105 + xenbus_dev_error(be->dev, err, 104.106 + "Shared frame/evtchn %li/%u not same as" 104.107 + " old %li/%u", 104.108 + sharedmfn, evtchn, 104.109 + be->blkif->shmem_frame, 104.110 + be->blkif->remote_evtchn); 104.111 + return; 104.112 + } 104.113 + 104.114 + /* Supply the information about the device the frontend needs */ 104.115 + err = xenbus_transaction_start(be->dev->nodename); 104.116 + if (err) { 104.117 + xenbus_dev_error(be->dev, err, "starting transaction"); 104.118 + return; 104.119 + } 104.120 + 104.121 + err = xenbus_printf(be->dev->nodename, "sectors", "%lu", 104.122 + vbd_size(be->vbd)); 104.123 + if (err) { 104.124 + xenbus_dev_error(be->dev, err, "writing %s/sectors", 104.125 + be->dev->nodename); 104.126 + goto abort; 104.127 + } 104.128 + 104.129 + /* FIXME: use a typename instead */ 104.130 + err = xenbus_printf(be->dev->nodename, "info", "%u", 104.131 + vbd_info(be->vbd)); 104.132 + if (err) { 104.133 + xenbus_dev_error(be->dev, err, "writing %s/info", 104.134 + be->dev->nodename); 104.135 + goto abort; 104.136 + } 104.137 + err = xenbus_printf(be->dev->nodename, "sector-size", "%lu", 104.138 + vbd_secsize(be->vbd)); 104.139 + if (err) { 104.140 + xenbus_dev_error(be->dev, err, "writing %s/sector-size", 104.141 + be->dev->nodename); 104.142 + goto abort; 104.143 + } 104.144 + 104.145 + /* First vbd? We need to map the shared frame, irq etc. */ 104.146 + if (be->blkif->status != CONNECTED) { 104.147 + err = blkif_map(be->blkif, sharedmfn, evtchn); 104.148 + if (err) { 104.149 + xenbus_dev_error(be->dev, err, 104.150 + "mapping shared-frame %lu port %u", 104.151 + sharedmfn, evtchn); 104.152 + goto abort; 104.153 + } 104.154 + } 104.155 + 104.156 + /* We're ready, activate. */ 104.157 + vbd_activate(be->blkif, be->vbd); 104.158 + 104.159 + xenbus_transaction_end(0); 104.160 + xenbus_dev_ok(be->dev); 104.161 + 104.162 + return; 104.163 + 104.164 +abort: 104.165 + xenbus_transaction_end(1); 104.166 +} 104.167 + 104.168 +/* 104.169 + Setup supplies physical device. 104.170 + We provide event channel and device details to front end. 104.171 + Frontend supplies shared frame and event channel. 104.172 + */ 104.173 +static void backend_changed(struct xenbus_watch *watch, const char *node) 104.174 +{ 104.175 + int err; 104.176 + char *p; 104.177 + char *frontend; 104.178 + long int handle, pdev; 104.179 + struct backend_info *be 104.180 + = container_of(watch, struct backend_info, backend_watch); 104.181 + struct xenbus_device *dev = be->dev; 104.182 + 104.183 + frontend = NULL; 104.184 + err = xenbus_gather(dev->nodename, 104.185 + "frontend-id", "%li", &be->frontend_id, 104.186 + "frontend", NULL, &frontend, 104.187 + NULL); 104.188 + if (err == -ENOENT || err == -ERANGE || 104.189 + strlen(frontend) == 0 || !xenbus_exists(frontend, "")) { 104.190 + if (frontend) 104.191 + kfree(frontend); 104.192 + /* If we can't get a frontend path and a frontend-id, 104.193 + * then our bus-id is no longer valid and we need to 104.194 + * destroy the backend device. 104.195 + */ 104.196 + goto device_fail; 104.197 + } 104.198 + 104.199 + if (!be->frontpath || strcmp(frontend, be->frontpath)) { 104.200 + if (be->watch.node) 104.201 + unregister_xenbus_watch(&be->watch); 104.202 + if (be->frontpath) 104.203 + kfree(be->frontpath); 104.204 + be->frontpath = frontend; 104.205 + be->watch.node = be->frontpath; 104.206 + be->watch.callback = frontend_changed; 104.207 + err = register_xenbus_watch(&be->watch); 104.208 + if (err) { 104.209 + be->watch.node = NULL; 104.210 + goto device_fail; 104.211 + } 104.212 + } else 104.213 + kfree(frontend); 104.214 + 104.215 + err = xenbus_scanf(dev->nodename, "physical-device", "%li", &pdev); 104.216 + if (err == -ENOENT || err == -ERANGE) 104.217 + goto out; 104.218 + if (err < 0) { 104.219 + xenbus_dev_error(dev, err, "Reading physical-device"); 104.220 + goto device_fail; 104.221 + } 104.222 + if (be->pdev && be->pdev != pdev) { 104.223 + printk(KERN_WARNING 104.224 + "changing physical-device not supported\n"); 104.225 + goto device_fail; 104.226 + } 104.227 + be->pdev = pdev; 104.228 + 104.229 + /* If there's a read-only node, we're read only. */ 104.230 + p = xenbus_read(dev->nodename, "read-only", NULL); 104.231 + if (!IS_ERR(p)) { 104.232 + be->readonly = 1; 104.233 + kfree(p); 104.234 + } 104.235 + 104.236 + if (be->blkif == NULL) { 104.237 + /* Front end dir is a number, which is used as the handle. */ 104.238 + p = strrchr(be->frontpath, '/') + 1; 104.239 + handle = simple_strtoul(p, NULL, 0); 104.240 + 104.241 + be->blkif = blkif_find(be->frontend_id); 104.242 + if (IS_ERR(be->blkif)) { 104.243 + err = PTR_ERR(be->blkif); 104.244 + be->blkif = NULL; 104.245 + goto device_fail; 104.246 + } 104.247 + 104.248 + be->vbd = vbd_create(be->blkif, handle, be->pdev, 104.249 + be->readonly); 104.250 + if (IS_ERR(be->vbd)) { 104.251 + err = PTR_ERR(be->vbd); 104.252 + be->vbd = NULL; 104.253 + goto device_fail; 104.254 + } 104.255 + 104.256 + frontend_changed(&be->watch, be->frontpath); 104.257 + } 104.258 + 104.259 + return; 104.260 + 104.261 + device_fail: 104.262 + device_unregister(&be->dev->dev); 104.263 + out: 104.264 + return; 104.265 +} 104.266 + 104.267 +static int blkback_probe(struct xenbus_device *dev, 104.268 + const struct xenbus_device_id *id) 104.269 +{ 104.270 + struct backend_info *be; 104.271 + int err; 104.272 + 104.273 + be = kmalloc(sizeof(*be), GFP_KERNEL); 104.274 + if (!be) 104.275 + return -ENOMEM; 104.276 + 104.277 + memset(be, 0, sizeof(*be)); 104.278 + 104.279 + be->dev = dev; 104.280 + be->backend_watch.node = dev->nodename; 104.281 + be->backend_watch.callback = backend_changed; 104.282 + err = register_xenbus_watch(&be->backend_watch); 104.283 + if (err) 104.284 + goto free_be; 104.285 + 104.286 + dev->data = be; 104.287 + 104.288 + backend_changed(&be->backend_watch, dev->nodename); 104.289 + return err; 104.290 + free_be: 104.291 + kfree(be); 104.292 + return err; 104.293 +} 104.294 + 104.295 +static struct xenbus_device_id blkback_ids[] = { 104.296 + { "vbd" }, 104.297 + { "" } 104.298 +}; 104.299 + 104.300 +static struct xenbus_driver blkback = { 104.301 + .name = "vbd", 104.302 + .owner = THIS_MODULE, 104.303 + .ids = blkback_ids, 104.304 + .probe = blkback_probe, 104.305 + .remove = blkback_remove, 104.306 +}; 104.307 + 104.308 +void blkif_xenbus_init(void) 104.309 +{ 104.310 + xenbus_register_backend(&blkback); 104.311 +}
105.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Thu Aug 18 10:40:02 2005 -0800 105.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/blkfront.c Fri Aug 19 10:19:28 2005 -0800 105.3 @@ -53,8 +53,8 @@ 105.4 #include <linux/sched.h> 105.5 #include <linux/interrupt.h> 105.6 #include <scsi/scsi.h> 105.7 -#include <asm-xen/ctrl_if.h> 105.8 #include <asm-xen/evtchn.h> 105.9 +#include <asm-xen/xenbus.h> 105.10 #ifdef CONFIG_XEN_BLKDEV_GRANT 105.11 #include <asm-xen/xen-public/grant_table.h> 105.12 #include <asm-xen/gnttab.h> 105.13 @@ -65,22 +65,14 @@ typedef unsigned char byte; /* from linu 105.14 /* Control whether runtime update of vbds is enabled. */ 105.15 #define ENABLE_VBD_UPDATE 1 105.16 105.17 -#if ENABLE_VBD_UPDATE 105.18 -static void vbd_update(void); 105.19 -#else 105.20 -static void vbd_update(void){}; 105.21 -#endif 105.22 - 105.23 #define BLKIF_STATE_CLOSED 0 105.24 #define BLKIF_STATE_DISCONNECTED 1 105.25 #define BLKIF_STATE_CONNECTED 2 105.26 105.27 -static int blkif_handle = 0; 105.28 static unsigned int blkif_state = BLKIF_STATE_CLOSED; 105.29 static unsigned int blkif_evtchn = 0; 105.30 - 105.31 -static int blkif_control_rsp_valid; 105.32 -static blkif_response_t blkif_control_rsp; 105.33 +static unsigned int blkif_vbds = 0; 105.34 +static unsigned int blkif_vbds_connected = 0; 105.35 105.36 static blkif_front_ring_t blk_ring; 105.37 105.38 @@ -92,6 +84,7 @@ static grant_ref_t gref_head, gref_termi 105.39 #define MAXIMUM_OUTSTANDING_BLOCK_REQS \ 105.40 (BLKIF_MAX_SEGMENTS_PER_REQUEST * BLKIF_RING_SIZE) 105.41 #define GRANTREF_INVALID (1<<15) 105.42 +static int shmem_ref; 105.43 #endif 105.44 105.45 static struct blk_shadow { 105.46 @@ -105,7 +98,7 @@ static int recovery = 0; /* Recovery in 105.47 105.48 static void kick_pending_request_queues(void); 105.49 105.50 -int __init xlblk_init(void); 105.51 +static int __init xlblk_init(void); 105.52 105.53 static void blkif_completion(struct blk_shadow *s); 105.54 105.55 @@ -179,19 +172,6 @@ static inline void flush_requests(void) 105.56 105.57 module_init(xlblk_init); 105.58 105.59 -#if ENABLE_VBD_UPDATE 105.60 -static void update_vbds_task(void *unused) 105.61 -{ 105.62 - xlvbd_update_vbds(); 105.63 -} 105.64 - 105.65 -static void vbd_update(void) 105.66 -{ 105.67 - static DECLARE_WORK(update_tq, update_vbds_task, NULL); 105.68 - schedule_work(&update_tq); 105.69 -} 105.70 -#endif /* ENABLE_VBD_UPDATE */ 105.71 - 105.72 static struct xlbd_disk_info *head_waiting = NULL; 105.73 static void kick_pending_request_queues(void) 105.74 { 105.75 @@ -221,16 +201,7 @@ int blkif_open(struct inode *inode, stru 105.76 105.77 int blkif_release(struct inode *inode, struct file *filep) 105.78 { 105.79 - struct gendisk *gd = inode->i_bdev->bd_disk; 105.80 - struct xlbd_disk_info *di = (struct xlbd_disk_info *)gd->private_data; 105.81 - 105.82 - /* 105.83 - * When usage drops to zero it may allow more VBD updates to occur. 105.84 - * Update of usage count is protected by a per-device semaphore. 105.85 - */ 105.86 - if ( --di->mi->usage == 0 ) 105.87 - vbd_update(); 105.88 - 105.89 + /* FIXME: This is where we can actually free up majors, etc. --RR */ 105.90 return 0; 105.91 } 105.92 105.93 @@ -301,7 +272,7 @@ static int blkif_queue_request(struct re 105.94 ring_req->operation = rq_data_dir(req) ? BLKIF_OP_WRITE : 105.95 BLKIF_OP_READ; 105.96 ring_req->sector_number = (blkif_sector_t)req->sector; 105.97 - ring_req->device = di->xd_device; 105.98 + ring_req->handle = di->handle; 105.99 105.100 ring_req->nr_segments = 0; 105.101 rq_for_each_bio(bio, req) 105.102 @@ -446,10 +417,6 @@ static irqreturn_t blkif_int(int irq, vo 105.103 end_that_request_last(req); 105.104 105.105 break; 105.106 - case BLKIF_OP_PROBE: 105.107 - memcpy(&blkif_control_rsp, bret, sizeof(*bret)); 105.108 - blkif_control_rsp_valid = 1; 105.109 - break; 105.110 default: 105.111 BUG(); 105.112 } 105.113 @@ -483,28 +450,6 @@ static int nr_pending; 105.114 #define blkif_io_lock io_request_lock 105.115 105.116 /*============================================================================*/ 105.117 -#if ENABLE_VBD_UPDATE 105.118 - 105.119 -/* 105.120 - * blkif_update_int/update-vbds_task - handle VBD update events. 105.121 - * Schedule a task for keventd to run, which will update the VBDs and perform 105.122 - * the corresponding updates to our view of VBD state. 105.123 - */ 105.124 -static void update_vbds_task(void *unused) 105.125 -{ 105.126 - xlvbd_update_vbds(); 105.127 -} 105.128 - 105.129 -static void vbd_update(void) 105.130 -{ 105.131 - static struct tq_struct update_tq; 105.132 - update_tq.routine = update_vbds_task; 105.133 - schedule_task(&update_tq); 105.134 -} 105.135 - 105.136 -#endif /* ENABLE_VBD_UPDATE */ 105.137 -/*============================================================================*/ 105.138 - 105.139 static void kick_pending_request_queues(void) 105.140 { 105.141 /* We kick pending request queues if the ring is reasonably empty. */ 105.142 @@ -757,7 +702,8 @@ static int blkif_queue_request(unsigned 105.143 char * buffer, 105.144 unsigned long sector_number, 105.145 unsigned short nr_sectors, 105.146 - kdev_t device) 105.147 + kdev_t device, 105.148 + blkif_vdev_t handle) 105.149 { 105.150 unsigned long buffer_ma = virt_to_bus(buffer); 105.151 unsigned long xid; 105.152 @@ -871,7 +817,7 @@ static int blkif_queue_request(unsigned 105.153 req->id = xid; 105.154 req->operation = operation; 105.155 req->sector_number = (blkif_sector_t)sector_number; 105.156 - req->device = device; 105.157 + req->handle = handle; 105.158 req->nr_segments = 1; 105.159 #ifdef CONFIG_XEN_BLKDEV_GRANT 105.160 /* install a grant reference. */ 105.161 @@ -1047,108 +993,10 @@ static void blkif_int(int irq, void *dev 105.162 105.163 /***************************** COMMON CODE *******************************/ 105.164 105.165 -#ifdef CONFIG_XEN_BLKDEV_GRANT 105.166 -void blkif_control_probe_send(blkif_request_t *req, blkif_response_t *rsp, 105.167 - unsigned long address) 105.168 -{ 105.169 - int ref = gnttab_claim_grant_reference(&gref_head, gref_terminal); 105.170 - ASSERT( ref != -ENOSPC ); 105.171 - 105.172 - gnttab_grant_foreign_access_ref( ref, rdomid, address >> PAGE_SHIFT, 0 ); 105.173 - 105.174 - req->frame_and_sects[0] = blkif_fas_from_gref(ref, 0, (PAGE_SIZE/512)-1); 105.175 - 105.176 - blkif_control_send(req, rsp); 105.177 -} 105.178 -#endif 105.179 - 105.180 -void blkif_control_send(blkif_request_t *req, blkif_response_t *rsp) 105.181 -{ 105.182 - unsigned long flags, id; 105.183 - blkif_request_t *req_d; 105.184 - 105.185 - retry: 105.186 - while ( RING_FULL(&blk_ring) ) 105.187 - { 105.188 - set_current_state(TASK_INTERRUPTIBLE); 105.189 - schedule_timeout(1); 105.190 - } 105.191 - 105.192 - spin_lock_irqsave(&blkif_io_lock, flags); 105.193 - if ( RING_FULL(&blk_ring) ) 105.194 - { 105.195 - spin_unlock_irqrestore(&blkif_io_lock, flags); 105.196 - goto retry; 105.197 - } 105.198 - 105.199 - DISABLE_SCATTERGATHER(); 105.200 - req_d = RING_GET_REQUEST(&blk_ring, blk_ring.req_prod_pvt); 105.201 - *req_d = *req; 105.202 - 105.203 - id = GET_ID_FROM_FREELIST(); 105.204 - req_d->id = id; 105.205 - blk_shadow[id].request = (unsigned long)req; 105.206 - 105.207 - pickle_request(&blk_shadow[id], req); 105.208 - 105.209 - blk_ring.req_prod_pvt++; 105.210 - flush_requests(); 105.211 - 105.212 - spin_unlock_irqrestore(&blkif_io_lock, flags); 105.213 - 105.214 - while ( !blkif_control_rsp_valid ) 105.215 - { 105.216 - set_current_state(TASK_INTERRUPTIBLE); 105.217 - schedule_timeout(1); 105.218 - } 105.219 - 105.220 - memcpy(rsp, &blkif_control_rsp, sizeof(*rsp)); 105.221 - blkif_control_rsp_valid = 0; 105.222 -} 105.223 - 105.224 - 105.225 -/* Send a driver status notification to the domain controller. */ 105.226 -static void send_driver_status(int ok) 105.227 -{ 105.228 - ctrl_msg_t cmsg = { 105.229 - .type = CMSG_BLKIF_FE, 105.230 - .subtype = CMSG_BLKIF_FE_DRIVER_STATUS, 105.231 - .length = sizeof(blkif_fe_driver_status_t), 105.232 - }; 105.233 - blkif_fe_driver_status_t *msg = (void*)cmsg.msg; 105.234 - 105.235 - msg->status = (ok ? BLKIF_DRIVER_STATUS_UP : BLKIF_DRIVER_STATUS_DOWN); 105.236 - 105.237 - ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE); 105.238 -} 105.239 - 105.240 -/* Tell the controller to bring up the interface. */ 105.241 -static void blkif_send_interface_connect(void) 105.242 -{ 105.243 - ctrl_msg_t cmsg = { 105.244 - .type = CMSG_BLKIF_FE, 105.245 - .subtype = CMSG_BLKIF_FE_INTERFACE_CONNECT, 105.246 - .length = sizeof(blkif_fe_interface_connect_t), 105.247 - }; 105.248 - blkif_fe_interface_connect_t *msg = (void*)cmsg.msg; 105.249 - 105.250 - msg->handle = 0; 105.251 - msg->shmem_frame = (virt_to_machine(blk_ring.sring) >> PAGE_SHIFT); 105.252 - 105.253 -#ifdef CONFIG_XEN_BLKDEV_GRANT 105.254 - msg->shmem_ref = gnttab_claim_grant_reference( &gref_head, gref_terminal ); 105.255 - ASSERT( msg->shmem_ref != -ENOSPC ); 105.256 - gnttab_grant_foreign_access_ref ( msg->shmem_ref , rdomid, msg->shmem_frame, 0 ); 105.257 -#endif 105.258 - 105.259 - ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE); 105.260 -} 105.261 - 105.262 static void blkif_free(void) 105.263 { 105.264 /* Prevent new requests being issued until we fix things up. */ 105.265 spin_lock_irq(&blkif_io_lock); 105.266 - recovery = 1; 105.267 blkif_state = BLKIF_STATE_DISCONNECTED; 105.268 spin_unlock_irq(&blkif_io_lock); 105.269 105.270 @@ -1162,31 +1010,6 @@ static void blkif_free(void) 105.271 blkif_evtchn = 0; 105.272 } 105.273 105.274 -static void blkif_close(void) 105.275 -{ 105.276 -} 105.277 - 105.278 -/* Move from CLOSED to DISCONNECTED state. */ 105.279 -static void blkif_disconnect(void) 105.280 -{ 105.281 - blkif_sring_t *sring; 105.282 - 105.283 - if ( blk_ring.sring != NULL ) 105.284 - free_page((unsigned long)blk_ring.sring); 105.285 - 105.286 - sring = (blkif_sring_t *)__get_free_page(GFP_KERNEL); 105.287 - SHARED_RING_INIT(sring); 105.288 - FRONT_RING_INIT(&blk_ring, sring, PAGE_SIZE); 105.289 - blkif_state = BLKIF_STATE_DISCONNECTED; 105.290 - blkif_send_interface_connect(); 105.291 -} 105.292 - 105.293 -static void blkif_reset(void) 105.294 -{ 105.295 - blkif_free(); 105.296 - blkif_disconnect(); 105.297 -} 105.298 - 105.299 static void blkif_recover(void) 105.300 { 105.301 int i; 105.302 @@ -1257,11 +1080,14 @@ static void blkif_recover(void) 105.303 blkif_state = BLKIF_STATE_CONNECTED; 105.304 } 105.305 105.306 -static void blkif_connect(blkif_fe_interface_status_t *status) 105.307 +static void blkif_connect(u16 evtchn, domid_t domid) 105.308 { 105.309 int err = 0; 105.310 105.311 - blkif_evtchn = status->evtchn; 105.312 + blkif_evtchn = evtchn; 105.313 +#ifdef CONFIG_XEN_BLKDEV_GRANT 105.314 + rdomid = domid; 105.315 +#endif 105.316 105.317 err = bind_evtchn_to_irqhandler( 105.318 blkif_evtchn, blkif_int, SA_SAMPLE_RANDOM, "blkif", NULL); 105.319 @@ -1270,142 +1096,318 @@ static void blkif_connect(blkif_fe_inter 105.320 WPRINTK("bind_evtchn_to_irqhandler failed (err=%d)\n", err); 105.321 return; 105.322 } 105.323 - 105.324 - if ( recovery ) 105.325 - { 105.326 - blkif_recover(); 105.327 - } 105.328 - else 105.329 - { 105.330 - /* Transition to connected in case we need to do 105.331 - * a partition probe on a whole disk. */ 105.332 - blkif_state = BLKIF_STATE_CONNECTED; 105.333 - 105.334 - /* Probe for discs attached to the interface. */ 105.335 - xlvbd_init(); 105.336 - } 105.337 - 105.338 - /* Kick pending requests. */ 105.339 - spin_lock_irq(&blkif_io_lock); 105.340 - kick_pending_request_queues(); 105.341 - spin_unlock_irq(&blkif_io_lock); 105.342 -} 105.343 - 105.344 -static void unexpected(blkif_fe_interface_status_t *status) 105.345 -{ 105.346 - DPRINTK(" Unexpected blkif status %u in state %u\n", 105.347 - status->status, blkif_state); 105.348 -} 105.349 - 105.350 -static void blkif_status(blkif_fe_interface_status_t *status) 105.351 -{ 105.352 -#ifdef CONFIG_XEN_BLKDEV_GRANT 105.353 - rdomid = status->domid; /* need to set rdomid early */ 105.354 -#endif 105.355 - 105.356 - if ( status->handle != blkif_handle ) 105.357 - { 105.358 - WPRINTK(" Invalid blkif: handle=%u\n", status->handle); 105.359 - unexpected(status); 105.360 - return; 105.361 - } 105.362 - 105.363 - switch ( status->status ) 105.364 - { 105.365 - case BLKIF_INTERFACE_STATUS_CLOSED: 105.366 - switch ( blkif_state ) 105.367 - { 105.368 - case BLKIF_STATE_CLOSED: 105.369 - unexpected(status); 105.370 - break; 105.371 - case BLKIF_STATE_DISCONNECTED: 105.372 - case BLKIF_STATE_CONNECTED: 105.373 - unexpected(status); 105.374 - blkif_close(); 105.375 - break; 105.376 - } 105.377 - break; 105.378 - 105.379 - case BLKIF_INTERFACE_STATUS_DISCONNECTED: 105.380 - switch ( blkif_state ) 105.381 - { 105.382 - case BLKIF_STATE_CLOSED: 105.383 - blkif_disconnect(); 105.384 - break; 105.385 - case BLKIF_STATE_DISCONNECTED: 105.386 - case BLKIF_STATE_CONNECTED: 105.387 - /* unexpected(status); */ /* occurs during suspend/resume */ 105.388 - blkif_reset(); 105.389 - break; 105.390 - } 105.391 - break; 105.392 - 105.393 - case BLKIF_INTERFACE_STATUS_CONNECTED: 105.394 - switch ( blkif_state ) 105.395 - { 105.396 - case BLKIF_STATE_CLOSED: 105.397 - unexpected(status); 105.398 - blkif_disconnect(); 105.399 - blkif_connect(status); 105.400 - break; 105.401 - case BLKIF_STATE_DISCONNECTED: 105.402 - blkif_connect(status); 105.403 - break; 105.404 - case BLKIF_STATE_CONNECTED: 105.405 - unexpected(status); 105.406 - blkif_connect(status); 105.407 - break; 105.408 - } 105.409 - break; 105.410 - 105.411 - case BLKIF_INTERFACE_STATUS_CHANGED: 105.412 - switch ( blkif_state ) 105.413 - { 105.414 - case BLKIF_STATE_CLOSED: 105.415 - case BLKIF_STATE_DISCONNECTED: 105.416 - unexpected(status); 105.417 - break; 105.418 - case BLKIF_STATE_CONNECTED: 105.419 - vbd_update(); 105.420 - break; 105.421 - } 105.422 - break; 105.423 - 105.424 - default: 105.425 - WPRINTK(" Invalid blkif status: %d\n", status->status); 105.426 - break; 105.427 - } 105.428 } 105.429 105.430 105.431 -static void blkif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id) 105.432 +static struct xenbus_device_id blkfront_ids[] = { 105.433 + { "vbd" }, 105.434 + { "" } 105.435 +}; 105.436 + 105.437 +struct blkfront_info 105.438 +{ 105.439 + /* We watch the backend */ 105.440 + struct xenbus_watch watch; 105.441 + int vdevice; 105.442 + u16 handle; 105.443 + int connected; 105.444 + struct xenbus_device *dev; 105.445 + char *backend; 105.446 +}; 105.447 + 105.448 +static void watch_for_status(struct xenbus_watch *watch, const char *node) 105.449 { 105.450 - switch ( msg->subtype ) 105.451 - { 105.452 - case CMSG_BLKIF_FE_INTERFACE_STATUS: 105.453 - blkif_status((blkif_fe_interface_status_t *) 105.454 - &msg->msg[0]); 105.455 - break; 105.456 - default: 105.457 - msg->length = 0; 105.458 - break; 105.459 - } 105.460 + struct blkfront_info *info; 105.461 + unsigned int binfo; 105.462 + unsigned long sectors, sector_size; 105.463 + int err; 105.464 + 105.465 + info = container_of(watch, struct blkfront_info, watch); 105.466 + node += strlen(watch->node); 105.467 + 105.468 + /* FIXME: clean up when error on the other end. */ 105.469 + if (info->connected) 105.470 + return; 105.471 + 105.472 + err = xenbus_gather(watch->node, 105.473 + "sectors", "%lu", §ors, 105.474 + "info", "%u", &binfo, 105.475 + "sector-size", "%lu", §or_size, 105.476 + NULL); 105.477 + 105.478 + if (err) 105.479 + xenbus_dev_error(info->dev, err, "reading backend fields"); 105.480 + else { 105.481 + xlvbd_add(sectors, info->vdevice, info->handle, binfo, 105.482 + sector_size); 105.483 + info->connected = 1; 105.484 + 105.485 + /* First to connect? blkif is now connected. */ 105.486 + if (blkif_vbds_connected++ == 0) 105.487 + blkif_state = BLKIF_STATE_CONNECTED; 105.488 + 105.489 + xenbus_dev_ok(info->dev); 105.490 105.491 - ctrl_if_send_response(msg); 105.492 + /* Kick pending requests. */ 105.493 + spin_lock_irq(&blkif_io_lock); 105.494 + kick_pending_request_queues(); 105.495 + spin_unlock_irq(&blkif_io_lock); 105.496 + } 105.497 +} 105.498 + 105.499 +static int setup_blkring(struct xenbus_device *dev, unsigned int backend_id) 105.500 +{ 105.501 + blkif_sring_t *sring; 105.502 + evtchn_op_t op = { .cmd = EVTCHNOP_alloc_unbound }; 105.503 + int err; 105.504 + 105.505 + sring = (void *)__get_free_page(GFP_KERNEL); 105.506 + if (!sring) { 105.507 + xenbus_dev_error(dev, -ENOMEM, "allocating shared ring"); 105.508 + return -ENOMEM; 105.509 + } 105.510 + SHARED_RING_INIT(sring); 105.511 + FRONT_RING_INIT(&blk_ring, sring, PAGE_SIZE); 105.512 + 105.513 +#ifdef CONFIG_XEN_BLKDEV_GRANT 105.514 + shmem_ref = gnttab_claim_grant_reference(&gref_head, 105.515 + gref_terminal); 105.516 + ASSERT(shmem_ref != -ENOSPC); 105.517 + gnttab_grant_foreign_access_ref(shmem_ref, 105.518 + backend_id, 105.519 + virt_to_mfn(blk_ring.sring), 105.520 + 0); 105.521 +#endif 105.522 + 105.523 + op.u.alloc_unbound.dom = backend_id; 105.524 + err = HYPERVISOR_event_channel_op(&op); 105.525 + if (err) { 105.526 + free_page((unsigned long)blk_ring.sring); 105.527 + blk_ring.sring = 0; 105.528 + xenbus_dev_error(dev, err, "allocating event channel"); 105.529 + return err; 105.530 + } 105.531 + blkif_connect(op.u.alloc_unbound.port, backend_id); 105.532 + return 0; 105.533 } 105.534 105.535 -int wait_for_blkif(void) 105.536 +/* Common code used when first setting up, and when resuming. */ 105.537 +static int talk_to_backend(struct xenbus_device *dev, 105.538 + struct blkfront_info *info) 105.539 +{ 105.540 + char *backend; 105.541 + const char *message; 105.542 + int err, backend_id; 105.543 + 105.544 + backend = xenbus_read(dev->nodename, "backend", NULL); 105.545 + if (IS_ERR(backend)) { 105.546 + err = PTR_ERR(backend); 105.547 + if (err == -ENOENT) 105.548 + goto out; 105.549 + xenbus_dev_error(dev, err, "reading %s/backend", 105.550 + dev->nodename); 105.551 + goto out; 105.552 + } 105.553 + if (strlen(backend) == 0) { 105.554 + err = -ENOENT; 105.555 + goto free_backend; 105.556 + } 105.557 + 105.558 + /* FIXME: This driver can't handle backends on different 105.559 + * domains. Check and fail gracefully. */ 105.560 + err = xenbus_scanf(dev->nodename, "backend-id", "%i", &backend_id); 105.561 + if (err == -ENOENT) 105.562 + goto free_backend; 105.563 + if (err < 0) { 105.564 + xenbus_dev_error(dev, err, "reading %s/backend-id", 105.565 + dev->nodename); 105.566 + goto free_backend; 105.567 + } 105.568 + 105.569 + /* First device? We create shared ring, alloc event channel. */ 105.570 + if (blkif_vbds == 0) { 105.571 + err = setup_blkring(dev, backend_id); 105.572 + if (err) 105.573 + goto free_backend; 105.574 + } 105.575 + 105.576 + err = xenbus_transaction_start(dev->nodename); 105.577 + if (err) { 105.578 + xenbus_dev_error(dev, err, "starting transaction"); 105.579 + goto destroy_blkring; 105.580 + } 105.581 + 105.582 +#ifdef CONFIG_XEN_BLKDEV_GRANT 105.583 + err = xenbus_printf(dev->nodename, "grant-id","%u", shmem_ref); 105.584 + if (err) { 105.585 + message = "writing grant-id"; 105.586 + goto abort_transaction; 105.587 + } 105.588 +#else 105.589 + err = xenbus_printf(dev->nodename, "shared-frame", "%lu", 105.590 + virt_to_mfn(blk_ring.sring)); 105.591 + if (err) { 105.592 + message = "writing shared-frame"; 105.593 + goto abort_transaction; 105.594 + } 105.595 +#endif 105.596 + err = xenbus_printf(dev->nodename, 105.597 + "event-channel", "%u", blkif_evtchn); 105.598 + if (err) { 105.599 + message = "writing event-channel"; 105.600 + goto abort_transaction; 105.601 + } 105.602 + 105.603 + info->watch.node = info->backend = backend; 105.604 + info->watch.callback = watch_for_status; 105.605 + 105.606 + err = register_xenbus_watch(&info->watch); 105.607 + if (err) { 105.608 + message = "registering watch on backend"; 105.609 + goto abort_transaction; 105.610 + } 105.611 + 105.612 + err = xenbus_transaction_end(0); 105.613 + if (err) { 105.614 + xenbus_dev_error(dev, err, "completing transaction"); 105.615 + goto destroy_blkring; 105.616 + } 105.617 + return 0; 105.618 + 105.619 +abort_transaction: 105.620 + xenbus_transaction_end(1); 105.621 + /* Have to do this *outside* transaction. */ 105.622 + xenbus_dev_error(dev, err, "%s", message); 105.623 +destroy_blkring: 105.624 + if (blkif_vbds == 0) 105.625 + blkif_free(); 105.626 +free_backend: 105.627 + kfree(backend); 105.628 +out: 105.629 + printk("%s:%u = %i\n", __FILE__, __LINE__, err); 105.630 + return err; 105.631 +} 105.632 + 105.633 +/* Setup supplies the backend dir, virtual device. 105.634 + 105.635 + We place an event channel and shared frame entries. 105.636 + We watch backend to wait if it's ok. */ 105.637 +static int blkfront_probe(struct xenbus_device *dev, 105.638 + const struct xenbus_device_id *id) 105.639 +{ 105.640 + int err; 105.641 + struct blkfront_info *info; 105.642 + int vdevice; 105.643 + 105.644 + /* FIXME: Use dynamic device id if this is not set. */ 105.645 + err = xenbus_scanf(dev->nodename, "virtual-device", "%i", &vdevice); 105.646 + if (err == -ENOENT) 105.647 + return err; 105.648 + if (err < 0) { 105.649 + xenbus_dev_error(dev, err, "reading virtual-device"); 105.650 + return err; 105.651 + } 105.652 + 105.653 + info = kmalloc(sizeof(*info), GFP_KERNEL); 105.654 + if (!info) { 105.655 + xenbus_dev_error(dev, err, "allocating info structure"); 105.656 + return err; 105.657 + } 105.658 + info->dev = dev; 105.659 + info->vdevice = vdevice; 105.660 + info->connected = 0; 105.661 + /* Front end dir is a number, which is used as the id. */ 105.662 + info->handle = simple_strtoul(strrchr(dev->nodename,'/')+1, NULL, 0); 105.663 + dev->data = info; 105.664 + 105.665 + err = talk_to_backend(dev, info); 105.666 + if (err) { 105.667 + kfree(info); 105.668 + return err; 105.669 + } 105.670 + 105.671 + /* Call once in case entries already there. */ 105.672 + watch_for_status(&info->watch, info->watch.node); 105.673 + blkif_vbds++; 105.674 + return 0; 105.675 +} 105.676 + 105.677 +static int blkfront_remove(struct xenbus_device *dev) 105.678 +{ 105.679 + struct blkfront_info *info = dev->data; 105.680 + 105.681 + if (info->backend) 105.682 + unregister_xenbus_watch(&info->watch); 105.683 + 105.684 + if (info->connected) { 105.685 + xlvbd_del(info->handle); 105.686 + blkif_vbds_connected--; 105.687 + } 105.688 + kfree(info->backend); 105.689 + kfree(info); 105.690 + 105.691 + if (--blkif_vbds == 0) 105.692 + blkif_free(); 105.693 + 105.694 + return 0; 105.695 +} 105.696 + 105.697 +static int blkfront_suspend(struct xenbus_device *dev) 105.698 +{ 105.699 + struct blkfront_info *info = dev->data; 105.700 + 105.701 + unregister_xenbus_watch(&info->watch); 105.702 + kfree(info->backend); 105.703 + info->backend = NULL; 105.704 + 105.705 + if (--blkif_vbds == 0) { 105.706 + recovery = 1; 105.707 + blkif_free(); 105.708 + } 105.709 + 105.710 + return 0; 105.711 +} 105.712 + 105.713 +static int blkfront_resume(struct xenbus_device *dev) 105.714 +{ 105.715 + struct blkfront_info *info = dev->data; 105.716 + int err; 105.717 + 105.718 + /* FIXME: Check geometry hasn't changed here... */ 105.719 + err = talk_to_backend(dev, info); 105.720 + if (!err) { 105.721 + if (blkif_vbds++ == 0) 105.722 + blkif_recover(); 105.723 + } 105.724 + return err; 105.725 +} 105.726 + 105.727 +static struct xenbus_driver blkfront = { 105.728 + .name = "vbd", 105.729 + .owner = THIS_MODULE, 105.730 + .ids = blkfront_ids, 105.731 + .probe = blkfront_probe, 105.732 + .remove = blkfront_remove, 105.733 + .resume = blkfront_resume, 105.734 + .suspend = blkfront_suspend, 105.735 +}; 105.736 + 105.737 +static void __init init_blk_xenbus(void) 105.738 +{ 105.739 + xenbus_register_device(&blkfront); 105.740 +} 105.741 + 105.742 +static int wait_for_blkif(void) 105.743 { 105.744 int err = 0; 105.745 int i; 105.746 - send_driver_status(1); 105.747 105.748 /* 105.749 * We should read 'nr_interfaces' from response message and wait 105.750 * for notifications before proceeding. For now we assume that we 105.751 * will be notified of exactly one interface. 105.752 */ 105.753 - for ( i=0; (blkif_state != BLKIF_STATE_CONNECTED) && (i < 10*HZ); i++ ) 105.754 + for ( i=0; blkif_state != BLKIF_STATE_CONNECTED && (i < 10*HZ); i++ ) 105.755 { 105.756 set_current_state(TASK_INTERRUPTIBLE); 105.757 schedule_timeout(1); 105.758 @@ -1419,7 +1421,7 @@ int wait_for_blkif(void) 105.759 return err; 105.760 } 105.761 105.762 -int __init xlblk_init(void) 105.763 +static int __init xlblk_init(void) 105.764 { 105.765 int i; 105.766 105.767 @@ -1443,29 +1445,13 @@ int __init xlblk_init(void) 105.768 blk_shadow[i].req.id = i+1; 105.769 blk_shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; 105.770 105.771 - (void)ctrl_if_register_receiver(CMSG_BLKIF_FE, blkif_ctrlif_rx, 105.772 - CALLBACK_IN_BLOCKING_CONTEXT); 105.773 + init_blk_xenbus(); 105.774 105.775 wait_for_blkif(); 105.776 105.777 return 0; 105.778 } 105.779 105.780 -void blkdev_suspend(void) 105.781 -{ 105.782 -} 105.783 - 105.784 -void blkdev_resume(void) 105.785 -{ 105.786 -#ifdef CONFIG_XEN_BLKDEV_GRANT 105.787 - int i, j; 105.788 - for ( i = 0; i < BLK_RING_SIZE; i++ ) 105.789 - for ( j = 0; j < BLKIF_MAX_SEGMENTS_PER_REQUEST; j++ ) 105.790 - blk_shadow[i].req.frame_and_sects[j] |= GRANTREF_INVALID; 105.791 -#endif 105.792 - send_driver_status(1); 105.793 -} 105.794 - 105.795 static void blkif_completion(struct blk_shadow *s) 105.796 { 105.797 int i;
106.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Thu Aug 18 10:40:02 2005 -0800 106.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/block.h Fri Aug 19 10:19:28 2005 -0800 106.3 @@ -100,6 +100,7 @@ struct xlbd_major_info { 106.4 106.5 struct xlbd_disk_info { 106.6 int xd_device; 106.7 + blkif_vdev_t handle; 106.8 struct xlbd_major_info *mi; 106.9 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) 106.10 struct xlbd_disk_info *next_waiting; 106.11 @@ -119,17 +120,10 @@ extern int blkif_ioctl(struct inode *ino 106.12 unsigned command, unsigned long argument); 106.13 extern int blkif_check(dev_t dev); 106.14 extern int blkif_revalidate(dev_t dev); 106.15 -extern void blkif_control_send(blkif_request_t *req, blkif_response_t *rsp); 106.16 -#ifdef CONFIG_XEN_BLKDEV_GRANT 106.17 -extern void blkif_control_probe_send( 106.18 - blkif_request_t *req, blkif_response_t *rsp, unsigned long address); 106.19 -#endif 106.20 extern void do_blkif_request (request_queue_t *rq); 106.21 106.22 -extern void xlvbd_update_vbds(void); 106.23 - 106.24 /* Virtual block-device subsystem. */ 106.25 -extern int xlvbd_init(void); 106.26 -extern void xlvbd_cleanup(void); 106.27 - 106.28 +int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle, 106.29 + u16 info, u16 sector_size); 106.30 +void xlvbd_del(blkif_vdev_t handle); 106.31 #endif /* __XEN_DRIVERS_BLOCK_H__ */
107.1 --- a/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Thu Aug 18 10:40:02 2005 -0800 107.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blkfront/vbd.c Fri Aug 19 10:19:28 2005 -0800 107.3 @@ -46,8 +46,9 @@ 107.4 struct lvdisk 107.5 { 107.6 blkif_sector_t capacity; /* 0: Size in terms of 512-byte sectors. */ 107.7 - blkif_vdev_t device; /* 8: Device number (opaque 16 bit value). */ 107.8 - u16 info; 107.9 + blkif_vdev_t handle; /* 8: Device number (opaque 16 bit value). */ 107.10 + u16 info; 107.11 + dev_t dev; 107.12 struct list_head list; 107.13 }; 107.14 107.15 @@ -85,7 +86,7 @@ static struct xlbd_major_info *major_inf 107.16 107.17 /* Information about our VBDs. */ 107.18 #define MAX_VBDS 64 107.19 -struct list_head vbds_list; 107.20 +static LIST_HEAD(vbds_list); 107.21 107.22 #define MAJOR_XEN(dev) ((dev)>>8) 107.23 #define MINOR_XEN(dev) ((dev) & 0xff) 107.24 @@ -118,49 +119,6 @@ static void xlvbd_device_free(struct lvd 107.25 kfree(disk); 107.26 } 107.27 107.28 -static vdisk_t *xlvbd_probe(int *ret) 107.29 -{ 107.30 - blkif_response_t rsp; 107.31 - blkif_request_t req; 107.32 - vdisk_t *disk_info = NULL; 107.33 - unsigned long buf; 107.34 - int nr; 107.35 - 107.36 - buf = __get_free_page(GFP_KERNEL); 107.37 - if ((void *)buf == NULL) 107.38 - goto out; 107.39 - 107.40 - memset(&req, 0, sizeof(req)); 107.41 - req.operation = BLKIF_OP_PROBE; 107.42 - req.nr_segments = 1; 107.43 -#ifdef CONFIG_XEN_BLKDEV_GRANT 107.44 - blkif_control_probe_send(&req, &rsp, 107.45 - (unsigned long)(virt_to_machine(buf))); 107.46 -#else 107.47 - req.frame_and_sects[0] = blkif_fas(virt_to_machine(buf), 0, (PAGE_SIZE/512)-1); 107.48 - 107.49 - blkif_control_send(&req, &rsp); 107.50 -#endif 107.51 - if ( rsp.status <= 0 ) { 107.52 - WPRINTK("Could not probe disks (%d)\n", rsp.status); 107.53 - goto out; 107.54 - } 107.55 - nr = rsp.status; 107.56 - if ( nr > MAX_VBDS ) 107.57 - nr = MAX_VBDS; 107.58 - 107.59 - disk_info = kmalloc(nr * sizeof(vdisk_t), GFP_KERNEL); 107.60 - if (disk_info != NULL) 107.61 - memcpy(disk_info, (void *) buf, nr * sizeof(vdisk_t)); 107.62 - 107.63 - if (ret != NULL) 107.64 - *ret = nr; 107.65 - 107.66 -out: 107.67 - free_page(buf); 107.68 - return disk_info; 107.69 -} 107.70 - 107.71 static struct xlbd_major_info *xlbd_alloc_major_info( 107.72 int major, int minor, int index) 107.73 { 107.74 @@ -189,6 +147,7 @@ static struct xlbd_major_info *xlbd_allo 107.75 break; 107.76 } 107.77 107.78 + printk("Registering block device major %i\n", ptr->major); 107.79 if (register_blkdev(ptr->major, ptr->type->devname)) { 107.80 WPRINTK("can't get major %d with name %s\n", 107.81 ptr->major, ptr->type->devname); 107.82 @@ -231,7 +190,7 @@ static struct xlbd_major_info *xlbd_get_ 107.83 xlbd_alloc_major_info(major, minor, index)); 107.84 } 107.85 107.86 -static int xlvbd_init_blk_queue(struct gendisk *gd, vdisk_t *disk) 107.87 +static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) 107.88 { 107.89 request_queue_t *rq; 107.90 107.91 @@ -242,7 +201,7 @@ static int xlvbd_init_blk_queue(struct g 107.92 elevator_init(rq, "noop"); 107.93 107.94 /* Hard sector size and max sectors impersonate the equiv. hardware. */ 107.95 - blk_queue_hardsect_size(rq, disk->sector_size); 107.96 + blk_queue_hardsect_size(rq, sector_size); 107.97 blk_queue_max_sectors(rq, 512); 107.98 107.99 /* Each segment in a request is up to an aligned page in size. */ 107.100 @@ -261,8 +220,9 @@ static int xlvbd_init_blk_queue(struct g 107.101 return 0; 107.102 } 107.103 107.104 -struct gendisk *xlvbd_alloc_gendisk( 107.105 - struct xlbd_major_info *mi, int minor, vdisk_t *disk) 107.106 +static struct gendisk *xlvbd_alloc_gendisk( 107.107 + struct xlbd_major_info *mi, int minor, blkif_sector_t capacity, 107.108 + int device, blkif_vdev_t handle, u16 info, u16 sector_size) 107.109 { 107.110 struct gendisk *gd; 107.111 struct xlbd_disk_info *di; 107.112 @@ -273,7 +233,8 @@ struct gendisk *xlvbd_alloc_gendisk( 107.113 return NULL; 107.114 memset(di, 0, sizeof(*di)); 107.115 di->mi = mi; 107.116 - di->xd_device = disk->device; 107.117 + di->xd_device = device; 107.118 + di->handle = handle; 107.119 107.120 if ((minor & ((1 << mi->type->partn_shift) - 1)) == 0) 107.121 nr_minors = 1 << mi->type->partn_shift; 107.122 @@ -296,22 +257,22 @@ struct gendisk *xlvbd_alloc_gendisk( 107.123 gd->first_minor = minor; 107.124 gd->fops = &xlvbd_block_fops; 107.125 gd->private_data = di; 107.126 - set_capacity(gd, disk->capacity); 107.127 + set_capacity(gd, capacity); 107.128 107.129 - if (xlvbd_init_blk_queue(gd, disk)) { 107.130 + if (xlvbd_init_blk_queue(gd, sector_size)) { 107.131 del_gendisk(gd); 107.132 goto out; 107.133 } 107.134 107.135 di->rq = gd->queue; 107.136 107.137 - if (disk->info & VDISK_READONLY) 107.138 + if (info & VDISK_READONLY) 107.139 set_disk_ro(gd, 1); 107.140 107.141 - if (disk->info & VDISK_REMOVABLE) 107.142 + if (info & VDISK_REMOVABLE) 107.143 gd->flags |= GENHD_FL_REMOVABLE; 107.144 107.145 - if (disk->info & VDISK_CDROM) 107.146 + if (info & VDISK_CDROM) 107.147 gd->flags |= GENHD_FL_CD; 107.148 107.149 add_disk(gd); 107.150 @@ -323,38 +284,36 @@ out: 107.151 return NULL; 107.152 } 107.153 107.154 -static int xlvbd_device_add(struct list_head *list, vdisk_t *disk) 107.155 +int xlvbd_add(blkif_sector_t capacity, int device, blkif_vdev_t handle, 107.156 + u16 info, u16 sector_size) 107.157 { 107.158 struct lvdisk *new; 107.159 - int minor; 107.160 - dev_t device; 107.161 struct block_device *bd; 107.162 struct gendisk *gd; 107.163 struct xlbd_major_info *mi; 107.164 107.165 - mi = xlbd_get_major_info(disk->device); 107.166 + mi = xlbd_get_major_info(device); 107.167 if (mi == NULL) 107.168 return -EPERM; 107.169 107.170 new = xlvbd_device_alloc(); 107.171 if (new == NULL) 107.172 - return -1; 107.173 - new->capacity = disk->capacity; 107.174 - new->device = disk->device; 107.175 - new->info = disk->info; 107.176 - 107.177 - minor = MINOR_XEN(disk->device); 107.178 - device = MKDEV(mi->major, minor); 107.179 - 107.180 - bd = bdget(device); 107.181 + return -ENOMEM; 107.182 + new->capacity = capacity; 107.183 + new->info = info; 107.184 + new->handle = handle; 107.185 + new->dev = MKDEV(MAJOR_XEN(device), MINOR_XEN(device)); 107.186 + 107.187 + bd = bdget(new->dev); 107.188 if (bd == NULL) 107.189 goto out; 107.190 107.191 - gd = xlvbd_alloc_gendisk(mi, minor, disk); 107.192 + gd = xlvbd_alloc_gendisk(mi, MINOR_XEN(device), capacity, device, handle, 107.193 + info, sector_size); 107.194 if (gd == NULL) 107.195 goto out_bd; 107.196 107.197 - list_add(&new->list, list); 107.198 + list_add(&new->list, &vbds_list); 107.199 out_bd: 107.200 bdput(bd); 107.201 out: 107.202 @@ -363,27 +322,26 @@ out: 107.203 107.204 static int xlvbd_device_del(struct lvdisk *disk) 107.205 { 107.206 - dev_t device; 107.207 struct block_device *bd; 107.208 struct gendisk *gd; 107.209 struct xlbd_disk_info *di; 107.210 int ret = 0, unused; 107.211 request_queue_t *rq; 107.212 107.213 - device = MKDEV(MAJOR_XEN(disk->device), MINOR_XEN(disk->device)); 107.214 - 107.215 - bd = bdget(device); 107.216 + bd = bdget(disk->dev); 107.217 if (bd == NULL) 107.218 return -1; 107.219 107.220 - gd = get_gendisk(device, &unused); 107.221 + gd = get_gendisk(disk->dev, &unused); 107.222 di = gd->private_data; 107.223 107.224 +#if 0 /* This is wrong: hda and hdb share same major, for example. */ 107.225 if (di->mi->usage != 0) { 107.226 - WPRINTK("disk removal failed: used [dev=%x]\n", device); 107.227 + WPRINTK("disk removal failed: used [dev=%x]\n", disk->dev); 107.228 ret = -1; 107.229 goto out; 107.230 } 107.231 +#endif 107.232 107.233 rq = gd->queue; 107.234 del_gendisk(gd); 107.235 @@ -391,110 +349,19 @@ static int xlvbd_device_del(struct lvdis 107.236 blk_cleanup_queue(rq); 107.237 107.238 xlvbd_device_free(disk); 107.239 -out: 107.240 bdput(bd); 107.241 return ret; 107.242 } 107.243 107.244 -static int xlvbd_device_update(struct lvdisk *ldisk, vdisk_t *disk) 107.245 +void xlvbd_del(blkif_vdev_t handle) 107.246 { 107.247 - dev_t device; 107.248 - struct block_device *bd; 107.249 - struct gendisk *gd; 107.250 - int unused; 107.251 - 107.252 - if ((ldisk->capacity == disk->capacity) && (ldisk->info == disk->info)) 107.253 - return 0; 107.254 - 107.255 - device = MKDEV(MAJOR_XEN(ldisk->device), MINOR_XEN(ldisk->device)); 107.256 - 107.257 - bd = bdget(device); 107.258 - if (bd == NULL) 107.259 - return -1; 107.260 - 107.261 - gd = get_gendisk(device, &unused); 107.262 - set_capacity(gd, disk->capacity); 107.263 - ldisk->capacity = disk->capacity; 107.264 - 107.265 - bdput(bd); 107.266 - 107.267 - return 0; 107.268 -} 107.269 - 107.270 -void xlvbd_refresh(void) 107.271 -{ 107.272 - vdisk_t *newdisks; 107.273 - struct list_head *tmp, *tmp2; 107.274 - struct lvdisk *disk; 107.275 - int i, nr; 107.276 + struct lvdisk *i; 107.277 107.278 - newdisks = xlvbd_probe(&nr); 107.279 - if (newdisks == NULL) { 107.280 - WPRINTK("failed to probe\n"); 107.281 - return; 107.282 - } 107.283 - 107.284 - i = 0; 107.285 - list_for_each_safe(tmp, tmp2, &vbds_list) { 107.286 - disk = list_entry(tmp, struct lvdisk, list); 107.287 - 107.288 - for (i = 0; i < nr; i++) { 107.289 - if ( !newdisks[i].device ) 107.290 - continue; 107.291 - if ( disk->device == newdisks[i].device ) { 107.292 - xlvbd_device_update(disk, &newdisks[i]); 107.293 - newdisks[i].device = 0; 107.294 - break; 107.295 - } 107.296 - } 107.297 - if (i == nr) { 107.298 - xlvbd_device_del(disk); 107.299 - newdisks[i].device = 0; 107.300 - } 107.301 - } 107.302 - for (i = 0; i < nr; i++) 107.303 - if ( newdisks[i].device ) 107.304 - xlvbd_device_add(&vbds_list, &newdisks[i]); 107.305 - kfree(newdisks); 107.306 + list_for_each_entry(i, &vbds_list, list) { 107.307 + if (i->handle == handle) { 107.308 + xlvbd_device_del(i); 107.309 + return; 107.310 + } 107.311 + } 107.312 + BUG(); 107.313 } 107.314 - 107.315 -/* 107.316 - * xlvbd_update_vbds - reprobes the VBD status and performs updates driver 107.317 - * state. The VBDs need to be updated in this way when the domain is 107.318 - * initialised and also each time we receive an XLBLK_UPDATE event. 107.319 - */ 107.320 -void xlvbd_update_vbds(void) 107.321 -{ 107.322 - xlvbd_refresh(); 107.323 -} 107.324 - 107.325 -/* 107.326 - * Set up all the linux device goop for the virtual block devices 107.327 - * (vbd's) that we know about. Note that although from the backend 107.328 - * driver's p.o.v. VBDs are addressed simply an opaque 16-bit device 107.329 - * number, the domain creation tools conventionally allocate these 107.330 - * numbers to correspond to those used by 'real' linux -- this is just 107.331 - * for convenience as it means e.g. that the same /etc/fstab can be 107.332 - * used when booting with or without Xen. 107.333 - */ 107.334 -int xlvbd_init(void) 107.335 -{ 107.336 - int i, nr; 107.337 - vdisk_t *disks; 107.338 - 107.339 - INIT_LIST_HEAD(&vbds_list); 107.340 - 107.341 - memset(major_info, 0, sizeof(major_info)); 107.342 - 107.343 - disks = xlvbd_probe(&nr); 107.344 - if (disks == NULL) { 107.345 - WPRINTK("failed to probe\n"); 107.346 - return -1; 107.347 - } 107.348 - 107.349 - for (i = 0; i < nr; i++) 107.350 - xlvbd_device_add(&vbds_list, &disks[i]); 107.351 - 107.352 - kfree(disks); 107.353 - return 0; 107.354 -}
109.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h Thu Aug 18 10:40:02 2005 -0800 109.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.h Fri Aug 19 10:19:28 2005 -0800 109.3 @@ -87,7 +87,7 @@ typedef struct blkif_st { 109.4 struct work_struct work; 109.5 #ifdef CONFIG_XEN_BLKDEV_GRANT 109.6 u16 shmem_handle; 109.7 - memory_t shmem_vaddr; 109.8 + unsigned long shmem_vaddr; 109.9 grant_ref_t shmem_ref; 109.10 #endif 109.11 } blkif_t;
110.1 --- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c Thu Aug 18 10:40:02 2005 -0800 110.2 +++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap_controlmsg.c Fri Aug 19 10:19:28 2005 -0800 110.3 @@ -320,7 +320,7 @@ static void blkif_ptbe_send_interface_co 110.4 }; 110.5 blkif_fe_interface_connect_t *msg = (void*)cmsg.msg; 110.6 msg->handle = 0; 110.7 - msg->shmem_frame = virt_to_machine(blktap_be_ring.sring) >> PAGE_SHIFT; 110.8 + msg->shmem_frame = virt_to_mfn(blktap_be_ring.sring); 110.9 110.10 ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE); 110.11 }
113.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h Thu Aug 18 10:40:02 2005 -0800 113.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h Fri Aug 19 10:19:28 2005 -0800 113.3 @@ -49,13 +49,13 @@ typedef struct netif_st { 113.4 unsigned long tx_shmem_frame; 113.5 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 113.6 u16 tx_shmem_handle; 113.7 - memory_t tx_shmem_vaddr; 113.8 + unsigned long tx_shmem_vaddr; 113.9 grant_ref_t tx_shmem_ref; 113.10 #endif 113.11 unsigned long rx_shmem_frame; 113.12 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 113.13 u16 rx_shmem_handle; 113.14 - memory_t rx_shmem_vaddr; 113.15 + unsigned long rx_shmem_vaddr; 113.16 grant_ref_t rx_shmem_ref; 113.17 #endif 113.18 unsigned int evtchn;
115.1 --- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Thu Aug 18 10:40:02 2005 -0800 115.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Fri Aug 19 10:19:28 2005 -0800 115.3 @@ -43,7 +43,7 @@ static void make_tx_response(netif_t *ne 115.4 static int make_rx_response(netif_t *netif, 115.5 u16 id, 115.6 s8 st, 115.7 - memory_t addr, 115.8 + unsigned long addr, 115.9 u16 size, 115.10 u16 csum_valid); 115.11 115.12 @@ -251,7 +251,7 @@ static void net_rx_action(unsigned long 115.13 #else 115.14 struct mmuext_op *mmuext; 115.15 #endif 115.16 - unsigned long vdata, mdata, new_mfn; 115.17 + unsigned long vdata, old_mfn, new_mfn; 115.18 struct sk_buff_head rxq; 115.19 struct sk_buff *skb; 115.20 u16 notify_list[NETIF_RX_RING_SIZE]; 115.21 @@ -271,7 +271,7 @@ static void net_rx_action(unsigned long 115.22 { 115.23 netif = netdev_priv(skb->dev); 115.24 vdata = (unsigned long)skb->data; 115.25 - mdata = virt_to_machine(vdata); 115.26 + old_mfn = virt_to_mfn(vdata); 115.27 115.28 /* Memory squeeze? Back off for an arbitrary while. */ 115.29 if ( (new_mfn = alloc_mfn()) == 0 ) 115.30 @@ -293,7 +293,7 @@ static void net_rx_action(unsigned long 115.31 mcl++; 115.32 115.33 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 115.34 - gop->mfn = mdata >> PAGE_SHIFT; 115.35 + gop->mfn = old_mfn; 115.36 gop->domid = netif->domid; 115.37 gop->handle = netif->rx->ring[ 115.38 MASK_NETIF_RX_IDX(netif->rx_resp_prod_copy)].req.gref; 115.39 @@ -308,7 +308,7 @@ static void net_rx_action(unsigned long 115.40 mcl++; 115.41 115.42 mmuext->cmd = MMUEXT_REASSIGN_PAGE; 115.43 - mmuext->mfn = mdata >> PAGE_SHIFT; 115.44 + mmuext->mfn = old_mfn; 115.45 mmuext++; 115.46 #endif 115.47 mmu->ptr = (new_mfn << PAGE_SHIFT) | MMU_MACHPHYS_UPDATE; 115.48 @@ -318,7 +318,7 @@ static void net_rx_action(unsigned long 115.49 __skb_queue_tail(&rxq, skb); 115.50 115.51 #ifdef DEBUG_GRANT 115.52 - dump_packet('a', mdata, vdata); 115.53 + dump_packet('a', old_mfn, vdata); 115.54 #endif 115.55 /* Filled the batch queue? */ 115.56 if ( (mcl - rx_mcl) == ARRAY_SIZE(rx_mcl) ) 115.57 @@ -345,10 +345,8 @@ static void net_rx_action(unsigned long 115.58 115.59 mcl = rx_mcl; 115.60 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 115.61 - if (unlikely(HYPERVISOR_grant_table_op(GNTTABOP_donate, 115.62 - grant_rx_op, gop - grant_rx_op))) { 115.63 - BUG(); 115.64 - } 115.65 + BUG_ON(HYPERVISOR_grant_table_op( 115.66 + GNTTABOP_donate, grant_rx_op, gop - grant_rx_op)); 115.67 gop = grant_rx_op; 115.68 #else 115.69 mmuext = rx_mmuext; 115.70 @@ -361,10 +359,9 @@ static void net_rx_action(unsigned long 115.71 /* Rederive the machine addresses. */ 115.72 new_mfn = mcl[0].args[1] >> PAGE_SHIFT; 115.73 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 115.74 - mdata = (unsigned long)skb->data & ~PAGE_MASK; 115.75 + old_mfn = 0; /* XXX Fix this so we can free_mfn() on error! */ 115.76 #else 115.77 - mdata = ((mmuext[0].mfn << PAGE_SHIFT) | 115.78 - ((unsigned long)skb->data & ~PAGE_MASK)); 115.79 + old_mfn = mmuext[0].mfn; 115.80 #endif 115.81 atomic_set(&(skb_shinfo(skb)->dataref), 1); 115.82 skb_shinfo(skb)->nr_frags = 0; 115.83 @@ -379,18 +376,20 @@ static void net_rx_action(unsigned long 115.84 /* Check the reassignment error code. */ 115.85 status = NETIF_RSP_OKAY; 115.86 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 115.87 - BUG_ON(gop->status != 0); 115.88 + BUG_ON(gop->status != 0); /* XXX */ 115.89 #else 115.90 if ( unlikely(mcl[1].result != 0) ) 115.91 { 115.92 DPRINTK("Failed MMU update transferring to DOM%u\n", netif->domid); 115.93 - free_mfn(mdata >> PAGE_SHIFT); 115.94 + free_mfn(old_mfn); 115.95 status = NETIF_RSP_ERROR; 115.96 } 115.97 #endif 115.98 evtchn = netif->evtchn; 115.99 id = netif->rx->ring[MASK_NETIF_RX_IDX(netif->rx_resp_prod)].req.id; 115.100 - if ( make_rx_response(netif, id, status, mdata, 115.101 + if ( make_rx_response(netif, id, status, 115.102 + (old_mfn << PAGE_SHIFT) | /* XXX */ 115.103 + ((unsigned long)skb->data & ~PAGE_MASK), 115.104 size, skb->proto_csum_valid) && 115.105 (rx_notify[evtchn] == 0) ) 115.106 { 115.107 @@ -888,7 +887,7 @@ static void make_tx_response(netif_t *ne 115.108 static int make_rx_response(netif_t *netif, 115.109 u16 id, 115.110 s8 st, 115.111 - memory_t addr, 115.112 + unsigned long addr, 115.113 u16 size, 115.114 u16 csum_valid) 115.115 {
116.1 --- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Thu Aug 18 10:40:02 2005 -0800 116.2 +++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c Fri Aug 19 10:19:28 2005 -0800 116.3 @@ -448,11 +448,10 @@ static void network_alloc_rx_buffers(str 116.4 } 116.5 grant_rx_ref[id] = ref; 116.6 gnttab_grant_foreign_transfer_ref(ref, rdomid, 116.7 - virt_to_machine( 116.8 - skb->head) >> PAGE_SHIFT); 116.9 + virt_to_mfn(skb->head)); 116.10 np->rx->ring[MASK_NETIF_RX_IDX(req_prod + i)].req.gref = ref; 116.11 #endif 116.12 - rx_pfn_array[i] = virt_to_machine(skb->head) >> PAGE_SHIFT; 116.13 + rx_pfn_array[i] = virt_to_mfn(skb->head); 116.14 116.15 /* Remove this page from pseudo phys map before passing back to Xen. */ 116.16 phys_to_machine_mapping[__pa(skb->head) >> PAGE_SHIFT] 116.17 @@ -543,13 +542,14 @@ static int network_start_xmit(struct sk_ 116.18 printk(KERN_ALERT "#### netfront can't claim tx grant reference\n"); 116.19 BUG(); 116.20 } 116.21 - mfn = virt_to_machine(skb->data) >> PAGE_SHIFT; 116.22 + mfn = virt_to_mfn(skb->data); 116.23 gnttab_grant_foreign_access_ref(ref, rdomid, mfn, GNTMAP_readonly); 116.24 - tx->addr = (ref << PAGE_SHIFT) | ((unsigned long)skb->data & ~PAGE_MASK); 116.25 + tx->addr = ref << PAGE_SHIFT; 116.26 grant_tx_ref[id] = ref; 116.27 #else 116.28 - tx->addr = virt_to_machine(skb->data); 116.29 + tx->addr = virt_to_mfn(skb->data) << PAGE_SHIFT; 116.30 #endif 116.31 + tx->addr |= (unsigned long)skb->data & ~PAGE_MASK; 116.32 tx->size = skb->len; 116.33 tx->csum_blank = (skb->ip_summed == CHECKSUM_HW); 116.34 116.35 @@ -720,7 +720,7 @@ static int netif_poll(struct net_device 116.36 while ((skb = __skb_dequeue(&rxq)) != NULL) { 116.37 #ifdef GRANT_DEBUG 116.38 printk(KERN_ALERT "#### rx_poll dequeue vdata=%p mfn=%lu\n", 116.39 - skb->data, virt_to_machine(skb->data)>>PAGE_SHIFT); 116.40 + skb->data, virt_to_mfn(skb->data)); 116.41 dump_packet('d', skb->data, (unsigned long)skb->data); 116.42 #endif 116.43 /* 116.44 @@ -854,18 +854,23 @@ static void network_connect(struct net_d 116.45 * interface has been down. 116.46 */ 116.47 for (requeue_idx = 0, i = 1; i <= NETIF_TX_RING_SIZE; i++) { 116.48 - if ((unsigned long)np->tx_skbs[i] >= __PAGE_OFFSET) { 116.49 - struct sk_buff *skb = np->tx_skbs[i]; 116.50 - 116.51 - tx = &np->tx->ring[requeue_idx++].req; 116.52 - 116.53 - tx->id = i; 116.54 - tx->addr = virt_to_machine(skb->data); 116.55 - tx->size = skb->len; 116.56 - 116.57 - np->stats.tx_bytes += skb->len; 116.58 - np->stats.tx_packets++; 116.59 - } 116.60 + if ((unsigned long)np->tx_skbs[i] >= __PAGE_OFFSET) { 116.61 + struct sk_buff *skb = np->tx_skbs[i]; 116.62 + 116.63 + tx = &np->tx->ring[requeue_idx++].req; 116.64 + 116.65 + tx->id = i; 116.66 +#ifdef CONFIG_XEN_NETDEV_GRANT_TX 116.67 + tx->addr = 0; /*(ref << PAGE_SHIFT) |*/ 116.68 +#else 116.69 + tx->addr = virt_to_mfn(skb->data) << PAGE_SHIFT; 116.70 +#endif 116.71 + tx->addr |= (unsigned long)skb->data & ~PAGE_MASK; 116.72 + tx->size = skb->len; 116.73 + 116.74 + np->stats.tx_bytes += skb->len; 116.75 + np->stats.tx_packets++; 116.76 + } 116.77 } 116.78 wmb(); 116.79 np->tx->req_prod = requeue_idx; 116.80 @@ -922,7 +927,7 @@ static void send_interface_connect(struc 116.81 netif_fe_interface_connect_t *msg = (void*)cmsg.msg; 116.82 116.83 msg->handle = np->handle; 116.84 - msg->tx_shmem_frame = (virt_to_machine(np->tx) >> PAGE_SHIFT); 116.85 + msg->tx_shmem_frame = virt_to_mfn(np->tx); 116.86 #ifdef CONFIG_XEN_NETDEV_GRANT_TX 116.87 msg->tx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_tx_head, 116.88 gref_tx_terminal); 116.89 @@ -934,7 +939,7 @@ static void send_interface_connect(struc 116.90 msg->tx_shmem_frame, 0); 116.91 #endif 116.92 116.93 - msg->rx_shmem_frame = (virt_to_machine(np->rx) >> PAGE_SHIFT); 116.94 + msg->rx_shmem_frame = virt_to_mfn(np->rx); 116.95 #ifdef CONFIG_XEN_NETDEV_GRANT_RX 116.96 msg->rx_shmem_ref = (u32)gnttab_claim_grant_reference(&gref_rx_head, 116.97 gref_rx_terminal);
120.1 --- a/linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c Thu Aug 18 10:40:02 2005 -0800 120.2 +++ b/linux-2.6-xen-sparse/drivers/xen/usbback/usbback.c Fri Aug 19 10:19:28 2005 -0800 120.3 @@ -657,8 +657,8 @@ static void dispatch_usb_io(usbif_priv_t 120.4 phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] = 120.5 FOREIGN_FRAME((buffer_mach + offset) >> PAGE_SHIFT); 120.6 120.7 - ASSERT(virt_to_machine(MMAP_VADDR(pending_idx, i)) 120.8 - == buffer_mach + i << PAGE_SHIFT); 120.9 + ASSERT(virt_to_mfn(MMAP_VADDR(pending_idx, i)) 120.10 + == ((buffer_mach >> PAGE_SHIFT) + i)); 120.11 } 120.12 120.13 if ( req->pipe_type == 0 && req->num_iso > 0 ) /* Maybe schedule ISO... */
121.1 --- a/linux-2.6-xen-sparse/drivers/xen/usbfront/usbfront.c Thu Aug 18 10:40:02 2005 -0800 121.2 +++ b/linux-2.6-xen-sparse/drivers/xen/usbfront/usbfront.c Fri Aug 19 10:19:28 2005 -0800 121.3 @@ -195,7 +195,7 @@ static int xhci_construct_isoc(usbif_req 121.4 } 121.5 121.6 urb_priv->schedule = schedule; 121.7 - req->iso_schedule = virt_to_machine(schedule); 121.8 + req->iso_schedule = virt_to_mfn(schedule) << PAGE_SHIFT; 121.9 121.10 return 0; 121.11 } 121.12 @@ -212,7 +212,7 @@ static int xhci_queue_req(struct urb *ur 121.13 #if DEBUG 121.14 printk(KERN_DEBUG 121.15 "usbif = %p, req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n", 121.16 - usbif, usbif->req_prod, virt_to_machine(&usbif->req_prod), 121.17 + usbif, usbif->req_prod, virt_to_mfn(&usbif->req_prod), 121.18 usbif->resp_prod, xhci->usb_resp_cons); 121.19 #endif 121.20 121.21 @@ -232,7 +232,7 @@ static int xhci_queue_req(struct urb *ur 121.22 req->operation = USBIF_OP_IO; 121.23 req->port = 0; /* We don't care what the port is. */ 121.24 req->id = (unsigned long) urb->hcpriv; 121.25 - req->transfer_buffer = virt_to_machine(urb->transfer_buffer); 121.26 + req->transfer_buffer = virt_to_mfn(urb->transfer_buffer) << PAGE_SHIFT; 121.27 req->devnum = usb_pipedevice(urb->pipe); 121.28 req->direction = usb_pipein(urb->pipe); 121.29 req->speed = usb_pipeslow(urb->pipe); 121.30 @@ -280,7 +280,7 @@ static inline usbif_request_t *xhci_queu 121.31 printk(KERN_DEBUG 121.32 "queuing probe: req_prod = %d (@ 0x%lx), resp_prod = %d, " 121.33 "resp_cons = %d\n", usbif->req_prod, 121.34 - virt_to_machine(&usbif->req_prod), 121.35 + virt_to_mfn(&usbif->req_prod), 121.36 usbif->resp_prod, xhci->usb_resp_cons); 121.37 #endif 121.38 121.39 @@ -1555,7 +1555,7 @@ static void usbif_status_change(usbif_fe 121.40 cmsg.type = CMSG_USBIF_FE; 121.41 cmsg.subtype = CMSG_USBIF_FE_INTERFACE_CONNECT; 121.42 cmsg.length = sizeof(usbif_fe_interface_connect_t); 121.43 - up.shmem_frame = virt_to_machine(sring) >> PAGE_SHIFT; 121.44 + up.shmem_frame = virt_to_mfn(sring); 121.45 memcpy(cmsg.msg, &up, sizeof(up)); 121.46 121.47 /* Tell the controller to bring up the interface. */ 121.48 @@ -1599,7 +1599,7 @@ static void usbif_status_change(usbif_fe 121.49 121.50 DPRINTK(KERN_INFO __FILE__ 121.51 ": USB XHCI: SHM at %p (0x%lx), EVTCHN %d\n", 121.52 - xhci->usb_ring.sring, virt_to_machine(xhci->usbif), 121.53 + xhci->usb_ring.sring, virt_to_mfn(xhci->usbif), 121.54 xhci->evtchn); 121.55 121.56 xhci->state = USBIF_STATE_CONNECTED;
124.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c Thu Aug 18 10:40:02 2005 -0800 124.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_comms.c Fri Aug 19 10:19:28 2005 -0800 124.3 @@ -48,13 +48,12 @@ DECLARE_WAIT_QUEUE_HEAD(xb_waitq); 124.4 124.5 static inline struct ringbuf_head *outbuf(void) 124.6 { 124.7 - return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT); 124.8 + return mfn_to_virt(xen_start_info.store_mfn); 124.9 } 124.10 124.11 static inline struct ringbuf_head *inbuf(void) 124.12 { 124.13 - return machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT) 124.14 - + PAGE_SIZE/2; 124.15 + return mfn_to_virt(xen_start_info.store_mfn) + PAGE_SIZE/2; 124.16 } 124.17 124.18 static irqreturn_t wake_waiting(int irq, void *unused, struct pt_regs *regs) 124.19 @@ -219,8 +218,7 @@ int xb_init_comms(void) 124.20 } 124.21 124.22 /* FIXME zero out page -- domain builder should probably do this*/ 124.23 - memset(machine_to_virt(xen_start_info.store_mfn << PAGE_SHIFT), 124.24 - 0, PAGE_SIZE); 124.25 + memset(mfn_to_virt(xen_start_info.store_mfn), 0, PAGE_SIZE); 124.26 124.27 return 0; 124.28 }
126.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Thu Aug 18 10:40:02 2005 -0800 126.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c Fri Aug 19 10:19:28 2005 -0800 126.3 @@ -48,15 +48,7 @@ static const struct xenbus_device_id * 126.4 match_device(const struct xenbus_device_id *arr, struct xenbus_device *dev) 126.5 { 126.6 for (; !streq(arr->devicetype, ""); arr++) { 126.7 - if (!streq(arr->devicetype, dev->devicetype)) 126.8 - continue; 126.9 - 126.10 - /* If they don't care what subtype, it's a match. */ 126.11 - if (streq(arr->subtype, "")) 126.12 - return arr; 126.13 - 126.14 - /* If they care, device must have (same) subtype. */ 126.15 - if (dev->subtype && streq(arr->subtype, dev->subtype)) 126.16 + if (streq(arr->devicetype, dev->devicetype)) 126.17 return arr; 126.18 } 126.19 return NULL; 126.20 @@ -72,10 +64,102 @@ static int xenbus_match(struct device *_ 126.21 return match_device(drv->ids, to_xenbus_device(_dev)) != NULL; 126.22 } 126.23 126.24 +struct xen_bus_type 126.25 +{ 126.26 + char *root; 126.27 + unsigned int levels; 126.28 + int (*get_bus_id)(char bus_id[BUS_ID_SIZE], const char *nodename); 126.29 + int (*probe)(const char *type, const char *dir); 126.30 + struct bus_type bus; 126.31 + struct device dev; 126.32 +}; 126.33 + 126.34 +/* device/<type>/<id> => <type>-<id> */ 126.35 +static int frontend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename) 126.36 +{ 126.37 + nodename = strchr(nodename, '/'); 126.38 + if (!nodename || strlen(nodename + 1) >= BUS_ID_SIZE) { 126.39 + printk(KERN_WARNING "XENBUS: bad frontend %s\n", nodename); 126.40 + return -EINVAL; 126.41 + } 126.42 + 126.43 + strlcpy(bus_id, nodename + 1, BUS_ID_SIZE); 126.44 + if (!strchr(bus_id, '/')) { 126.45 + printk(KERN_WARNING "XENBUS: bus_id %s no slash\n", bus_id); 126.46 + return -EINVAL; 126.47 + } 126.48 + *strchr(bus_id, '/') = '-'; 126.49 + return 0; 126.50 +} 126.51 + 126.52 /* Bus type for frontend drivers. */ 126.53 -static struct bus_type xenbus_type = { 126.54 - .name = "xenbus", 126.55 - .match = xenbus_match, 126.56 +static int xenbus_probe_frontend(const char *type, const char *name); 126.57 +static struct xen_bus_type xenbus_frontend = { 126.58 + .root = "device", 126.59 + .levels = 2, /* device/type/<id> */ 126.60 + .get_bus_id = frontend_bus_id, 126.61 + .probe = xenbus_probe_frontend, 126.62 + .bus = { 126.63 + .name = "xen", 126.64 + .match = xenbus_match, 126.65 + }, 126.66 + .dev = { 126.67 + .bus_id = "xen", 126.68 + }, 126.69 +}; 126.70 + 126.71 +/* backend/<type>/<fe-uuid>/<id> => <type>-<fe-domid>-<id> */ 126.72 +static int backend_bus_id(char bus_id[BUS_ID_SIZE], const char *nodename) 126.73 +{ 126.74 + int domid, err; 126.75 + const char *devid, *type, *frontend; 126.76 + unsigned int typelen; 126.77 + 126.78 + type = strchr(nodename, '/'); 126.79 + if (!type) 126.80 + return -EINVAL; 126.81 + type++; 126.82 + typelen = strcspn(type, "/"); 126.83 + if (!typelen || type[typelen] != '/') 126.84 + return -EINVAL; 126.85 + 126.86 + devid = strrchr(nodename, '/') + 1; 126.87 + 126.88 + err = xenbus_gather(nodename, "frontend-id", "%i", &domid, 126.89 + "frontend", NULL, &frontend, 126.90 + NULL); 126.91 + if (err) 126.92 + return err; 126.93 + if (strlen(frontend) == 0) 126.94 + err = -ERANGE; 126.95 + 126.96 + if (!err && !xenbus_exists(frontend, "")) 126.97 + err = -ENOENT; 126.98 + 126.99 + if (err) { 126.100 + kfree(frontend); 126.101 + return err; 126.102 + } 126.103 + 126.104 + if (snprintf(bus_id, BUS_ID_SIZE, 126.105 + "%.*s-%i-%s", typelen, type, domid, devid) >= BUS_ID_SIZE) 126.106 + return -ENOSPC; 126.107 + return 0; 126.108 +} 126.109 + 126.110 +static int xenbus_probe_backend(const char *type, const char *uuid); 126.111 +static struct xen_bus_type xenbus_backend = { 126.112 + .root = "backend", 126.113 + .levels = 3, /* backend/type/<frontend>/<id> */ 126.114 + .get_bus_id = backend_bus_id, 126.115 + .probe = xenbus_probe_backend, 126.116 + .bus = { 126.117 + .name = "xen-backend", 126.118 + .match = xenbus_match, 126.119 + }, 126.120 + .dev = { 126.121 + .bus_id = "xen-backend", 126.122 + }, 126.123 }; 126.124 126.125 static int xenbus_dev_probe(struct device *_dev) 126.126 @@ -104,12 +188,13 @@ static int xenbus_dev_remove(struct devi 126.127 return drv->remove(dev); 126.128 } 126.129 126.130 -int xenbus_register_driver(struct xenbus_driver *drv) 126.131 +static int xenbus_register_driver(struct xenbus_driver *drv, 126.132 + struct xen_bus_type *bus) 126.133 { 126.134 int err; 126.135 126.136 drv->driver.name = drv->name; 126.137 - drv->driver.bus = &xenbus_type; 126.138 + drv->driver.bus = &bus->bus; 126.139 drv->driver.owner = drv->owner; 126.140 drv->driver.probe = xenbus_dev_probe; 126.141 drv->driver.remove = xenbus_dev_remove; 126.142 @@ -120,6 +205,16 @@ int xenbus_register_driver(struct xenbus 126.143 return err; 126.144 } 126.145 126.146 +int xenbus_register_device(struct xenbus_driver *drv) 126.147 +{ 126.148 + return xenbus_register_driver(drv, &xenbus_frontend); 126.149 +} 126.150 + 126.151 +int xenbus_register_backend(struct xenbus_driver *drv) 126.152 +{ 126.153 + return xenbus_register_driver(drv, &xenbus_backend); 126.154 +} 126.155 + 126.156 void xenbus_unregister_driver(struct xenbus_driver *drv) 126.157 { 126.158 down(&xenbus_lock); 126.159 @@ -130,52 +225,98 @@ void xenbus_unregister_driver(struct xen 126.160 struct xb_find_info 126.161 { 126.162 struct xenbus_device *dev; 126.163 - const char *busid; 126.164 + const char *nodename; 126.165 }; 126.166 126.167 static int cmp_dev(struct device *dev, void *data) 126.168 { 126.169 + struct xenbus_device *xendev = to_xenbus_device(dev); 126.170 struct xb_find_info *info = data; 126.171 126.172 - if (streq(dev->bus_id, info->busid)) { 126.173 - info->dev = container_of(get_device(dev), 126.174 - struct xenbus_device, dev); 126.175 + if (streq(xendev->nodename, info->nodename)) { 126.176 + info->dev = xendev; 126.177 + get_device(dev); 126.178 return 1; 126.179 } 126.180 return 0; 126.181 } 126.182 126.183 -/* FIXME: device_find is fixed in 2.6.13-rc2 according to Greg KH --RR */ 126.184 -struct xenbus_device *xenbus_device_find(const char *busid) 126.185 +struct xenbus_device *xenbus_device_find(const char *nodename, 126.186 + struct bus_type *bus) 126.187 { 126.188 - struct xb_find_info info = { .dev = NULL, .busid = busid }; 126.189 + struct xb_find_info info = { .dev = NULL, .nodename = nodename }; 126.190 126.191 - bus_for_each_dev(&xenbus_type, NULL, &info, cmp_dev); 126.192 + bus_for_each_dev(bus, NULL, &info, cmp_dev); 126.193 return info.dev; 126.194 } 126.195 126.196 +static int cleanup_dev(struct device *dev, void *data) 126.197 +{ 126.198 + struct xenbus_device *xendev = to_xenbus_device(dev); 126.199 + struct xb_find_info *info = data; 126.200 + int len = strlen(info->nodename); 126.201 + 126.202 + if (!strncmp(xendev->nodename, info->nodename, len)) { 126.203 + info->dev = xendev; 126.204 + get_device(dev); 126.205 + return 1; 126.206 + } 126.207 + return 0; 126.208 +} 126.209 + 126.210 +static void xenbus_cleanup_devices(const char *path, struct bus_type *bus) 126.211 +{ 126.212 + struct xb_find_info info = { .nodename = path }; 126.213 + 126.214 + do { 126.215 + info.dev = NULL; 126.216 + bus_for_each_dev(bus, NULL, &info, cleanup_dev); 126.217 + if (info.dev) { 126.218 + device_unregister(&info.dev->dev); 126.219 + put_device(&info.dev->dev); 126.220 + } 126.221 + } while (info.dev); 126.222 +} 126.223 126.224 static void xenbus_release_device(struct device *dev) 126.225 { 126.226 if (dev) { 126.227 struct xenbus_device *xendev = to_xenbus_device(dev); 126.228 126.229 - kfree(xendev->subtype); 126.230 kfree(xendev); 126.231 } 126.232 } 126.233 -/* devices/<typename>/<name> */ 126.234 -static int xenbus_probe_device(const char *dirpath, const char *devicetype, 126.235 - const char *name) 126.236 + 126.237 +/* Simplified asprintf. */ 126.238 +static char *kasprintf(const char *fmt, ...) 126.239 +{ 126.240 + va_list ap; 126.241 + unsigned int len; 126.242 + char *p, dummy[1]; 126.243 + 126.244 + va_start(ap, fmt); 126.245 + /* FIXME: vsnprintf has a bug, NULL should work */ 126.246 + len = vsnprintf(dummy, 0, fmt, ap); 126.247 + va_end(ap); 126.248 + 126.249 + p = kmalloc(len + 1, GFP_KERNEL); 126.250 + if (!p) 126.251 + return NULL; 126.252 + va_start(ap, fmt); 126.253 + vsprintf(p, fmt, ap); 126.254 + va_end(ap); 126.255 + return p; 126.256 +} 126.257 + 126.258 +static int xenbus_probe_node(struct xen_bus_type *bus, 126.259 + const char *type, 126.260 + const char *nodename) 126.261 { 126.262 int err; 126.263 struct xenbus_device *xendev; 126.264 unsigned int stringlen; 126.265 126.266 - /* Nodename: /device/<typename>/<name>/ */ 126.267 - stringlen = strlen(dirpath) + strlen(devicetype) + strlen(name) + 3; 126.268 - /* Typename */ 126.269 - stringlen += strlen(devicetype) + 1; 126.270 + stringlen = strlen(nodename) + 1 + strlen(type) + 1; 126.271 xendev = kmalloc(sizeof(*xendev) + stringlen, GFP_KERNEL); 126.272 if (!xendev) 126.273 return -ENOMEM; 126.274 @@ -183,38 +324,103 @@ static int xenbus_probe_device(const cha 126.275 126.276 /* Copy the strings into the extra space. */ 126.277 xendev->nodename = (char *)(xendev + 1); 126.278 - sprintf(xendev->nodename, "%s/%s/%s", dirpath, devicetype, name); 126.279 + strcpy(xendev->nodename, nodename); 126.280 xendev->devicetype = xendev->nodename + strlen(xendev->nodename) + 1; 126.281 - strcpy(xendev->devicetype, devicetype); 126.282 + strcpy(xendev->devicetype, type); 126.283 126.284 - /* FIXME: look for "subtype" field. */ 126.285 - snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s-%s", devicetype, name); 126.286 - xendev->dev.bus = &xenbus_type; 126.287 + xendev->dev.parent = &bus->dev; 126.288 + xendev->dev.bus = &bus->bus; 126.289 xendev->dev.release = xenbus_release_device; 126.290 126.291 + err = bus->get_bus_id(xendev->dev.bus_id, xendev->nodename); 126.292 + if (err) { 126.293 + kfree(xendev); 126.294 + return err; 126.295 + } 126.296 + 126.297 /* Register with generic device framework. */ 126.298 err = device_register(&xendev->dev); 126.299 if (err) { 126.300 - printk("XENBUS: Registering device %s: error %i\n", 126.301 - xendev->dev.bus_id, err); 126.302 + printk("XENBUS: Registering %s device %s: error %i\n", 126.303 + bus->bus.name, xendev->dev.bus_id, err); 126.304 kfree(xendev); 126.305 } 126.306 return err; 126.307 } 126.308 126.309 -static int xenbus_probe_device_type(const char *dirpath, const char *typename) 126.310 +/* device/<typename>/<name> */ 126.311 +static int xenbus_probe_frontend(const char *type, const char *name) 126.312 +{ 126.313 + char *nodename; 126.314 + int err; 126.315 + 126.316 + nodename = kasprintf("%s/%s/%s", xenbus_frontend.root, type, name); 126.317 + if (!nodename) 126.318 + return -ENOMEM; 126.319 + 126.320 + err = xenbus_probe_node(&xenbus_frontend, type, nodename); 126.321 + kfree(nodename); 126.322 + return err; 126.323 +} 126.324 + 126.325 +/* backend/<typename>/<frontend-uuid>/<name> */ 126.326 +static int xenbus_probe_backend_unit(const char *dir, 126.327 + const char *type, 126.328 + const char *name) 126.329 +{ 126.330 + char *nodename; 126.331 + int err; 126.332 + 126.333 + nodename = kasprintf("%s/%s", dir, name); 126.334 + if (!nodename) 126.335 + return -ENOMEM; 126.336 + 126.337 + err = xenbus_probe_node(&xenbus_backend, type, nodename); 126.338 + kfree(nodename); 126.339 + return err; 126.340 +} 126.341 + 126.342 +/* backend/<typename>/<frontend-uuid> */ 126.343 +static int xenbus_probe_backend(const char *type, const char *uuid) 126.344 +{ 126.345 + char *nodename; 126.346 + int err = 0; 126.347 + char **dir; 126.348 + unsigned int i, dir_n = 0; 126.349 + 126.350 + nodename = kasprintf("%s/%s/%s", xenbus_backend.root, type, uuid); 126.351 + if (!nodename) 126.352 + return -ENOMEM; 126.353 + 126.354 + dir = xenbus_directory(nodename, "", &dir_n); 126.355 + if (IS_ERR(dir)) { 126.356 + kfree(nodename); 126.357 + return PTR_ERR(dir); 126.358 + } 126.359 + 126.360 + for (i = 0; i < dir_n; i++) { 126.361 + err = xenbus_probe_backend_unit(nodename, type, dir[i]); 126.362 + if (err) 126.363 + break; 126.364 + } 126.365 + kfree(dir); 126.366 + kfree(nodename); 126.367 + return err; 126.368 +} 126.369 + 126.370 +static int xenbus_probe_device_type(struct xen_bus_type *bus, const char *type) 126.371 { 126.372 int err = 0; 126.373 char **dir; 126.374 unsigned int dir_n = 0; 126.375 int i; 126.376 126.377 - dir = xenbus_directory(dirpath, typename, &dir_n); 126.378 + dir = xenbus_directory(bus->root, type, &dir_n); 126.379 if (IS_ERR(dir)) 126.380 return PTR_ERR(dir); 126.381 126.382 for (i = 0; i < dir_n; i++) { 126.383 - err = xenbus_probe_device(dirpath, typename, dir[i]); 126.384 + err = bus->probe(type, dir[i]); 126.385 if (err) 126.386 break; 126.387 } 126.388 @@ -222,18 +428,18 @@ static int xenbus_probe_device_type(cons 126.389 return err; 126.390 } 126.391 126.392 -static int xenbus_probe_devices(const char *path) 126.393 +static int xenbus_probe_devices(struct xen_bus_type *bus) 126.394 { 126.395 int err = 0; 126.396 char **dir; 126.397 unsigned int i, dir_n; 126.398 126.399 - dir = xenbus_directory(path, "", &dir_n); 126.400 + dir = xenbus_directory(bus->root, "", &dir_n); 126.401 if (IS_ERR(dir)) 126.402 return PTR_ERR(dir); 126.403 126.404 for (i = 0; i < dir_n; i++) { 126.405 - err = xenbus_probe_device_type(path, dir[i]); 126.406 + err = xenbus_probe_device_type(bus, dir[i]); 126.407 if (err) 126.408 break; 126.409 } 126.410 @@ -251,58 +457,117 @@ static unsigned int char_count(const cha 126.411 return ret; 126.412 } 126.413 126.414 -static void dev_changed(struct xenbus_watch *watch, const char *node) 126.415 +static int strsep_len(const char *str, char c, unsigned int len) 126.416 { 126.417 - char busid[BUS_ID_SIZE]; 126.418 - int exists; 126.419 - struct xenbus_device *dev; 126.420 - char *p; 126.421 + unsigned int i; 126.422 + 126.423 + for (i = 0; str[i]; i++) 126.424 + if (str[i] == c) { 126.425 + if (len == 0) 126.426 + return i; 126.427 + len--; 126.428 + } 126.429 + return (len == 0) ? i : -ERANGE; 126.430 +} 126.431 126.432 - /* Node is of form device/<type>/<identifier>[/...] */ 126.433 - if (char_count(node, '/') != 2) 126.434 - return; 126.435 +static void dev_changed(const char *node, struct xen_bus_type *bus) 126.436 +{ 126.437 + int exists, rootlen; 126.438 + struct xenbus_device *dev; 126.439 + char type[BUS_ID_SIZE]; 126.440 + const char *p, *root; 126.441 126.442 - /* Created or deleted? */ 126.443 - exists = xenbus_exists(node, ""); 126.444 + if (char_count(node, '/') < 2) 126.445 + return; 126.446 126.447 - p = strchr(node, '/') + 1; 126.448 - if (strlen(p) + 1 > BUS_ID_SIZE) { 126.449 - printk("Device for node %s is too big!\n", node); 126.450 + exists = xenbus_exists(node, ""); 126.451 + if (!exists) { 126.452 + xenbus_cleanup_devices(node, &bus->bus); 126.453 return; 126.454 } 126.455 - /* Bus ID is name with / changed to - */ 126.456 - strcpy(busid, p); 126.457 - *strchr(busid, '/') = '-'; 126.458 + 126.459 + /* backend/<type>/... or device/<type>/... */ 126.460 + p = strchr(node, '/') + 1; 126.461 + snprintf(type, BUS_ID_SIZE, "%.*s", strcspn(p, "/"), p); 126.462 + type[BUS_ID_SIZE-1] = '\0'; 126.463 + 126.464 + rootlen = strsep_len(node, '/', bus->levels); 126.465 + if (rootlen < 0) 126.466 + return; 126.467 + root = kasprintf("%.*s", rootlen, node); 126.468 + if (!root) 126.469 + return; 126.470 126.471 - dev = xenbus_device_find(busid); 126.472 - printk("xenbus: device %s %s\n", busid, dev ? "exists" : "new"); 126.473 - if (dev && !exists) { 126.474 - printk("xenbus: Unregistering device %s\n", busid); 126.475 - /* FIXME: free? */ 126.476 - device_unregister(&dev->dev); 126.477 - } else if (!dev && exists) { 126.478 - printk("xenbus: Adding device %s\n", busid); 126.479 - /* Hack bus id back into two strings. */ 126.480 - *strrchr(busid, '-') = '\0'; 126.481 - xenbus_probe_device("device", busid, busid+strlen(busid)+1); 126.482 - } else 126.483 - printk("xenbus: strange, %s already %s\n", busid, 126.484 - exists ? "exists" : "gone"); 126.485 - if (dev) 126.486 + dev = xenbus_device_find(root, &bus->bus); 126.487 + if (!dev) 126.488 + xenbus_probe_node(bus, type, root); 126.489 + else 126.490 put_device(&dev->dev); 126.491 + 126.492 + kfree(root); 126.493 +} 126.494 + 126.495 +static void frontend_changed(struct xenbus_watch *watch, const char *node) 126.496 +{ 126.497 + dev_changed(node, &xenbus_frontend); 126.498 +} 126.499 + 126.500 +static void backend_changed(struct xenbus_watch *watch, const char *node) 126.501 +{ 126.502 + dev_changed(node, &xenbus_backend); 126.503 } 126.504 126.505 /* We watch for devices appearing and vanishing. */ 126.506 -static struct xenbus_watch dev_watch = { 126.507 - /* FIXME: Ideally we'd only watch for changes 2 levels deep... */ 126.508 +static struct xenbus_watch fe_watch = { 126.509 .node = "device", 126.510 - .callback = dev_changed, 126.511 + .callback = frontend_changed, 126.512 +}; 126.513 + 126.514 +static struct xenbus_watch be_watch = { 126.515 + .node = "backend", 126.516 + .callback = backend_changed, 126.517 }; 126.518 126.519 +static int suspend_dev(struct device *dev, void *data) 126.520 +{ 126.521 + int err = 0; 126.522 + struct xenbus_driver *drv; 126.523 + struct xenbus_device *xdev; 126.524 + 126.525 + if (dev->driver == NULL) 126.526 + return 0; 126.527 + drv = to_xenbus_driver(dev->driver); 126.528 + xdev = container_of(dev, struct xenbus_device, dev); 126.529 + if (drv->suspend) 126.530 + err = drv->suspend(xdev); 126.531 + if (err) 126.532 + printk("xenbus: suspend %s failed: %i\n", dev->bus_id, err); 126.533 + return 0; 126.534 +} 126.535 + 126.536 +static int resume_dev(struct device *dev, void *data) 126.537 +{ 126.538 + int err = 0; 126.539 + struct xenbus_driver *drv; 126.540 + struct xenbus_device *xdev; 126.541 + 126.542 + if (dev->driver == NULL) 126.543 + return 0; 126.544 + drv = to_xenbus_driver(dev->driver); 126.545 + xdev = container_of(dev, struct xenbus_device, dev); 126.546 + if (drv->resume) 126.547 + err = drv->resume(xdev); 126.548 + if (err) 126.549 + printk("xenbus: resume %s failed: %i\n", dev->bus_id, err); 126.550 + return 0; 126.551 +} 126.552 + 126.553 void xenbus_suspend(void) 126.554 { 126.555 /* We keep lock, so no comms can happen as page moves. */ 126.556 down(&xenbus_lock); 126.557 + bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, suspend_dev); 126.558 + bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, suspend_dev); 126.559 xb_suspend_comms(); 126.560 } 126.561 126.562 @@ -310,6 +575,8 @@ void xenbus_resume(void) 126.563 { 126.564 xb_init_comms(); 126.565 reregister_xenbus_watches(); 126.566 + bus_for_each_dev(&xenbus_frontend.bus, NULL, NULL, resume_dev); 126.567 + bus_for_each_dev(&xenbus_backend.bus, NULL, NULL, resume_dev); 126.568 up(&xenbus_lock); 126.569 } 126.570 126.571 @@ -354,30 +621,23 @@ int do_xenbus_probe(void *unused) 126.572 } 126.573 126.574 down(&xenbus_lock); 126.575 - err = notifier_call_chain(&xenstore_chain, 0, 0); 126.576 - up(&xenbus_lock); 126.577 - 126.578 - if (err == NOTIFY_BAD) { 126.579 - printk("%s: calling xenstore notify chain failed\n", 126.580 - __FUNCTION__); 126.581 - return -EINVAL; 126.582 - } 126.583 - 126.584 - err = 0; 126.585 - 126.586 - down(&xenbus_lock); 126.587 /* Enumerate devices in xenstore. */ 126.588 - xenbus_probe_devices("device"); 126.589 + xenbus_probe_devices(&xenbus_frontend); 126.590 + xenbus_probe_devices(&xenbus_backend); 126.591 /* Watch for changes. */ 126.592 - register_xenbus_watch(&dev_watch); 126.593 + register_xenbus_watch(&fe_watch); 126.594 + register_xenbus_watch(&be_watch); 126.595 up(&xenbus_lock); 126.596 return 0; 126.597 } 126.598 126.599 static int __init xenbus_probe_init(void) 126.600 { 126.601 - bus_register(&xenbus_type); 126.602 - 126.603 + bus_register(&xenbus_frontend.bus); 126.604 + bus_register(&xenbus_backend.bus); 126.605 + device_register(&xenbus_frontend.dev); 126.606 + device_register(&xenbus_backend.dev); 126.607 + 126.608 if (!xen_start_info.store_evtchn) 126.609 return 0; 126.610
127.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Thu Aug 18 10:40:02 2005 -0800 127.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c Fri Aug 19 10:19:28 2005 -0800 127.3 @@ -187,6 +187,7 @@ static char *join(const char *dir, const 127.4 static char buffer[4096]; 127.5 127.6 BUG_ON(down_trylock(&xenbus_lock) == 0); 127.7 + /* XXX FIXME: might not be correct if name == "" */ 127.8 BUG_ON(strlen(dir) + strlen("/") + strlen(name) + 1 > sizeof(buffer)); 127.9 127.10 strcpy(buffer, dir); 127.11 @@ -399,9 +400,12 @@ int xenbus_gather(const char *dir, ...) 127.12 ret = PTR_ERR(p); 127.13 break; 127.14 } 127.15 - if (sscanf(p, fmt, result) == 0) 127.16 - ret = -EINVAL; 127.17 - kfree(p); 127.18 + if (fmt) { 127.19 + if (sscanf(p, fmt, result) == 0) 127.20 + ret = -EINVAL; 127.21 + kfree(p); 127.22 + } else 127.23 + *(char **)result = p; 127.24 } 127.25 va_end(ap); 127.26 return ret;
129.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h Thu Aug 18 10:40:02 2005 -0800 129.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/desc.h Fri Aug 19 10:19:28 2005 -0800 129.3 @@ -93,7 +93,7 @@ static inline void set_ldt_desc(unsigned 129.4 129.5 static inline void load_TLS(struct thread_struct *t, unsigned int cpu) 129.6 { 129.7 -#define C(i) HYPERVISOR_update_descriptor(virt_to_machine(&get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i]), ((u32 *)&t->tls_array[i])[0], ((u32 *)&t->tls_array[i])[1]) 129.8 +#define C(i) HYPERVISOR_update_descriptor(virt_to_machine(&get_cpu_gdt_table(cpu)[GDT_ENTRY_TLS_MIN + i]), *(u64 *)&t->tls_array[i]) 129.9 C(0); C(1); C(2); 129.10 #undef C 129.11 }
131.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/fixmap.h Thu Aug 18 10:40:02 2005 -0800 131.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/fixmap.h Fri Aug 19 10:19:28 2005 -0800 131.3 @@ -102,8 +102,8 @@ enum fixed_addresses { 131.4 __end_of_fixed_addresses 131.5 }; 131.6 131.7 -extern void __set_fixmap (enum fixed_addresses idx, 131.8 - unsigned long phys, pgprot_t flags); 131.9 +extern void __set_fixmap( 131.10 + enum fixed_addresses idx, maddr_t phys, pgprot_t flags); 131.11 131.12 #define set_fixmap(idx, phys) \ 131.13 __set_fixmap(idx, phys, PAGE_KERNEL)
132.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h Thu Aug 18 10:40:02 2005 -0800 132.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/hypercall.h Fri Aug 19 10:19:28 2005 -0800 132.3 @@ -163,7 +163,7 @@ HYPERVISOR_yield( 132.4 TRAP_INSTR 132.5 : "=a" (ret), "=b" (ign) 132.6 : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_yield) 132.7 - : "memory" ); 132.8 + : "memory", "ecx" ); 132.9 132.10 return ret; 132.11 } 132.12 @@ -178,7 +178,7 @@ HYPERVISOR_block( 132.13 TRAP_INSTR 132.14 : "=a" (ret), "=b" (ign1) 132.15 : "0" (__HYPERVISOR_sched_op), "1" (SCHEDOP_block) 132.16 - : "memory" ); 132.17 + : "memory", "ecx" ); 132.18 132.19 return ret; 132.20 } 132.21 @@ -194,7 +194,7 @@ HYPERVISOR_shutdown( 132.22 : "=a" (ret), "=b" (ign1) 132.23 : "0" (__HYPERVISOR_sched_op), 132.24 "1" (SCHEDOP_shutdown | (SHUTDOWN_poweroff << SCHEDOP_reasonshift)) 132.25 - : "memory" ); 132.26 + : "memory", "ecx" ); 132.27 132.28 return ret; 132.29 } 132.30 @@ -210,7 +210,7 @@ HYPERVISOR_reboot( 132.31 : "=a" (ret), "=b" (ign1) 132.32 : "0" (__HYPERVISOR_sched_op), 132.33 "1" (SCHEDOP_shutdown | (SHUTDOWN_reboot << SCHEDOP_reasonshift)) 132.34 - : "memory" ); 132.35 + : "memory", "ecx" ); 132.36 132.37 return ret; 132.38 } 132.39 @@ -228,7 +228,7 @@ HYPERVISOR_suspend( 132.40 : "=a" (ret), "=b" (ign1), "=S" (ign2) 132.41 : "0" (__HYPERVISOR_sched_op), 132.42 "b" (SCHEDOP_shutdown | (SHUTDOWN_suspend << SCHEDOP_reasonshift)), 132.43 - "S" (srec) : "memory"); 132.44 + "S" (srec) : "memory", "ecx"); 132.45 132.46 return ret; 132.47 } 132.48 @@ -244,7 +244,7 @@ HYPERVISOR_crash( 132.49 : "=a" (ret), "=b" (ign1) 132.50 : "0" (__HYPERVISOR_sched_op), 132.51 "1" (SCHEDOP_shutdown | (SHUTDOWN_crash << SCHEDOP_reasonshift)) 132.52 - : "memory" ); 132.53 + : "memory", "ecx" ); 132.54 132.55 return ret; 132.56 } 132.57 @@ -316,16 +316,17 @@ HYPERVISOR_get_debugreg( 132.58 132.59 static inline int 132.60 HYPERVISOR_update_descriptor( 132.61 - unsigned long ma, unsigned long word1, unsigned long word2) 132.62 + u64 ma, u64 desc) 132.63 { 132.64 int ret; 132.65 - unsigned long ign1, ign2, ign3; 132.66 + unsigned long ign1, ign2, ign3, ign4; 132.67 132.68 __asm__ __volatile__ ( 132.69 TRAP_INSTR 132.70 - : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3) 132.71 - : "0" (__HYPERVISOR_update_descriptor), "1" (ma), "2" (word1), 132.72 - "3" (word2) 132.73 + : "=a" (ret), "=b" (ign1), "=c" (ign2), "=d" (ign3), "=S" (ign4) 132.74 + : "0" (__HYPERVISOR_update_descriptor), 132.75 + "1" ((unsigned long)ma), "2" ((unsigned long)(ma>>32)), 132.76 + "3" ((unsigned long)desc), "4" ((unsigned long)(desc>>32)) 132.77 : "memory" ); 132.78 132.79 return ret; 132.80 @@ -529,12 +530,15 @@ HYPERVISOR_vcpu_down( 132.81 { 132.82 int ret; 132.83 unsigned long ign1; 132.84 + /* Yes, I really do want to clobber edx here: when we resume a 132.85 + vcpu after unpickling a multi-processor domain, it returns 132.86 + here, but clobbers all of the call clobbered registers. */ 132.87 __asm__ __volatile__ ( 132.88 TRAP_INSTR 132.89 : "=a" (ret), "=b" (ign1) 132.90 : "0" (__HYPERVISOR_sched_op), 132.91 "1" (SCHEDOP_vcpu_down | (vcpu << SCHEDOP_vcpushift)) 132.92 - : "memory" ); 132.93 + : "memory", "ecx", "edx" ); 132.94 132.95 return ret; 132.96 } 132.97 @@ -550,8 +554,26 @@ HYPERVISOR_vcpu_up( 132.98 : "=a" (ret), "=b" (ign1) 132.99 : "0" (__HYPERVISOR_sched_op), 132.100 "1" (SCHEDOP_vcpu_up | (vcpu << SCHEDOP_vcpushift)) 132.101 + : "memory", "ecx" ); 132.102 + 132.103 + return ret; 132.104 +} 132.105 + 132.106 +static inline int 132.107 +HYPERVISOR_vcpu_pickle( 132.108 + int vcpu, vcpu_guest_context_t *ctxt) 132.109 +{ 132.110 + int ret; 132.111 + unsigned long ign1, ign2; 132.112 + __asm__ __volatile__ ( 132.113 + TRAP_INSTR 132.114 + : "=a" (ret), "=b" (ign1), "=c" (ign2) 132.115 + : "0" (__HYPERVISOR_sched_op), 132.116 + "1" (SCHEDOP_vcpu_pickle | (vcpu << SCHEDOP_vcpushift)), 132.117 + "2" (ctxt) 132.118 : "memory" ); 132.119 132.120 return ret; 132.121 } 132.122 + 132.123 #endif /* __HYPERCALL_H__ */
136.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h Thu Aug 18 10:40:02 2005 -0800 136.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/page.h Fri Aug 19 10:19:28 2005 -0800 136.3 @@ -63,20 +63,25 @@ 136.4 extern unsigned int *phys_to_machine_mapping; 136.5 #define pfn_to_mfn(_pfn) ((unsigned long)(phys_to_machine_mapping[(_pfn)])) 136.6 #define mfn_to_pfn(_mfn) ((unsigned long)(machine_to_phys_mapping[(_mfn)])) 136.7 + 136.8 +/* Definitions for machine and pseudophysical addresses. */ 136.9 #ifdef CONFIG_X86_PAE 136.10 -typedef unsigned long long physaddr_t; 136.11 +typedef unsigned long long paddr_t; 136.12 +typedef unsigned long long maddr_t; 136.13 #else 136.14 -typedef unsigned long physaddr_t; 136.15 +typedef unsigned long paddr_t; 136.16 +typedef unsigned long maddr_t; 136.17 #endif 136.18 -static inline physaddr_t phys_to_machine(physaddr_t phys) 136.19 + 136.20 +static inline maddr_t phys_to_machine(paddr_t phys) 136.21 { 136.22 - physaddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT); 136.23 + maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT); 136.24 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK); 136.25 return machine; 136.26 } 136.27 -static inline physaddr_t machine_to_phys(physaddr_t machine) 136.28 +static inline paddr_t machine_to_phys(maddr_t machine) 136.29 { 136.30 - physaddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT); 136.31 + paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT); 136.32 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); 136.33 return phys; 136.34 } 136.35 @@ -233,8 +238,10 @@ extern int sysctl_legacy_va_layout; 136.36 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 136.37 136.38 /* VIRT <-> MACHINE conversion */ 136.39 -#define virt_to_machine(_a) (phys_to_machine(__pa(_a))) 136.40 -#define machine_to_virt(_m) (__va(machine_to_phys(_m))) 136.41 +#define virt_to_machine(v) (phys_to_machine(__pa(v))) 136.42 +#define machine_to_virt(m) (__va(machine_to_phys(m))) 136.43 +#define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT)) 136.44 +#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT)) 136.45 136.46 #endif /* __KERNEL__ */ 136.47
141.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable.h Thu Aug 18 10:40:02 2005 -0800 141.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-i386/pgtable.h Fri Aug 19 10:19:28 2005 -0800 141.3 @@ -32,7 +32,7 @@ 141.4 */ 141.5 #define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 141.6 extern unsigned long empty_zero_page[1024]; 141.7 -extern pgd_t swapper_pg_dir[1024]; 141.8 +extern pgd_t *swapper_pg_dir; 141.9 extern kmem_cache_t *pgd_cache; 141.10 extern kmem_cache_t *pmd_cache; 141.11 extern spinlock_t pgd_lock; 141.12 @@ -450,7 +450,7 @@ void make_pages_writable(void *va, unsig 141.13 #define arbitrary_virt_to_machine(__va) \ 141.14 ({ \ 141.15 pte_t *__pte = virt_to_ptep(__va); \ 141.16 - unsigned long __pa = (*(unsigned long *)__pte) & PAGE_MASK; \ 141.17 + maddr_t __pa = (maddr_t)pte_mfn(*__pte) << PAGE_SHIFT; \ 141.18 __pa | ((unsigned long)(__va) & (PAGE_SIZE-1)); \ 141.19 }) 141.20
146.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h Thu Aug 18 10:40:02 2005 -0800 146.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/hypercall.h Fri Aug 19 10:19:28 2005 -0800 146.3 @@ -502,4 +502,21 @@ HYPERVISOR_set_segment_base( 146.4 return ret; 146.5 } 146.6 146.7 +static inline int 146.8 +HYPERVISOR_vcpu_pickle( 146.9 + int vcpu, vcpu_guest_context_t *ctxt) 146.10 +{ 146.11 + int ret; 146.12 + unsigned long ign1, ign2; 146.13 + __asm__ __volatile__ ( 146.14 + TRAP_INSTR 146.15 + : "=a" (ret), "=b" (ign1), "=c" (ign2) 146.16 + : "0" (__HYPERVISOR_sched_op), 146.17 + "1" (SCHEDOP_vcpu_pickle | (vcpu << SCHEDOP_vcpushift)), 146.18 + "2" (ctxt) 146.19 + : __syscall_clobber ); 146.20 + 146.21 + return ret; 146.22 +} 146.23 + 146.24 #endif /* __HYPERCALL_H__ */
149.1 --- a/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h Thu Aug 18 10:40:02 2005 -0800 149.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/asm-x86_64/page.h Fri Aug 19 10:19:28 2005 -0800 149.3 @@ -65,16 +65,21 @@ void copy_page(void *, void *); 149.4 extern u32 *phys_to_machine_mapping; 149.5 #define pfn_to_mfn(_pfn) ((unsigned long) phys_to_machine_mapping[(unsigned int)(_pfn)]) 149.6 #define mfn_to_pfn(_mfn) ((unsigned long) machine_to_phys_mapping[(unsigned int)(_mfn)]) 149.7 -static inline unsigned long phys_to_machine(unsigned long phys) 149.8 + 149.9 +/* Definitions for machine and pseudophysical addresses. */ 149.10 +typedef unsigned long paddr_t; 149.11 +typedef unsigned long maddr_t; 149.12 + 149.13 +static inline maddr_t phys_to_machine(paddr_t phys) 149.14 { 149.15 - unsigned long machine = pfn_to_mfn(phys >> PAGE_SHIFT); 149.16 + maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT); 149.17 machine = (machine << PAGE_SHIFT) | (phys & ~PAGE_MASK); 149.18 return machine; 149.19 } 149.20 149.21 -static inline unsigned long machine_to_phys(unsigned long machine) 149.22 +static inline paddr_t machine_to_phys(maddr_t machine) 149.23 { 149.24 - unsigned long phys = mfn_to_pfn(machine >> PAGE_SHIFT); 149.25 + paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT); 149.26 phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK); 149.27 return phys; 149.28 } 149.29 @@ -211,8 +216,10 @@ extern __inline__ int get_order(unsigned 149.30 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 149.31 149.32 /* VIRT <-> MACHINE conversion */ 149.33 -#define virt_to_machine(_a) (phys_to_machine(__pa(_a))) 149.34 -#define machine_to_virt(_m) (__va(machine_to_phys(_m))) 149.35 +#define virt_to_machine(v) (phys_to_machine(__pa(v))) 149.36 +#define machine_to_virt(m) (__va(machine_to_phys(m))) 149.37 +#define virt_to_mfn(v) (pfn_to_mfn(__pa(v) >> PAGE_SHIFT)) 149.38 +#define mfn_to_virt(m) (__va(mfn_to_pfn(m) << PAGE_SHIFT)) 149.39 149.40 #define VM_DATA_DEFAULT_FLAGS \ 149.41 (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0 ) | \
158.1 --- a/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Thu Aug 18 10:40:02 2005 -0800 158.2 +++ b/linux-2.6-xen-sparse/include/asm-xen/xenbus.h Fri Aug 19 10:19:28 2005 -0800 158.3 @@ -37,7 +37,6 @@ 158.4 /* A xenbus device. */ 158.5 struct xenbus_device { 158.6 char *devicetype; 158.7 - char *subtype; 158.8 char *nodename; 158.9 struct device dev; 158.10 int has_error; 158.11 @@ -53,7 +52,6 @@ struct xenbus_device_id 158.12 { 158.13 /* .../device/<device_type>/<identifier> */ 158.14 char devicetype[32]; /* General class of device. */ 158.15 - char subtype[32]; /* Contents of "subtype" for this device */ 158.16 }; 158.17 158.18 /* A xenbus driver. */ 158.19 @@ -61,9 +59,11 @@ struct xenbus_driver { 158.20 char *name; 158.21 struct module *owner; 158.22 const struct xenbus_device_id *ids; 158.23 - int (*probe) (struct xenbus_device * dev, 158.24 - const struct xenbus_device_id * id); 158.25 - int (*remove) (struct xenbus_device * dev); 158.26 + int (*probe)(struct xenbus_device *dev, 158.27 + const struct xenbus_device_id *id); 158.28 + int (*remove)(struct xenbus_device *dev); 158.29 + int (*suspend)(struct xenbus_device *dev); 158.30 + int (*resume)(struct xenbus_device *dev); 158.31 struct device_driver driver; 158.32 }; 158.33 158.34 @@ -72,7 +72,8 @@ static inline struct xenbus_driver *to_x 158.35 return container_of(drv, struct xenbus_driver, driver); 158.36 } 158.37 158.38 -int xenbus_register_driver(struct xenbus_driver *drv); 158.39 +int xenbus_register_device(struct xenbus_driver *drv); 158.40 +int xenbus_register_backend(struct xenbus_driver *drv); 158.41 void xenbus_unregister_driver(struct xenbus_driver *drv); 158.42 158.43 /* Caller must hold this lock to call these functions: it's also held
167.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 167.2 +++ b/patches/linux-2.6.12/workaround_double_br_del_if.patch Fri Aug 19 10:19:28 2005 -0800 167.3 @@ -0,0 +1,11 @@ 167.4 +--- linux-2.6.12/net/bridge/br_if.c 2005-06-17 14:48:29.000000000 -0500 167.5 ++++ linux-2.6.12-xen0-smp/net/bridge/br_if.c 2005-08-18 15:17:27.302615846 -0500 167.6 +@@ -382,7 +382,7 @@ 167.7 + { 167.8 + struct net_bridge_port *p = dev->br_port; 167.9 + 167.10 +- if (!p || p->br != br) 167.11 ++ if (!p || p->br != br || p->state == BR_STATE_DISABLED) 167.12 + return -EINVAL; 167.13 + 167.14 + br_sysfs_removeif(p);
174.1 --- a/tools/debugger/libxendebug/xendebug.c Thu Aug 18 10:40:02 2005 -0800 174.2 +++ b/tools/debugger/libxendebug/xendebug.c Fri Aug 19 10:19:28 2005 -0800 174.3 @@ -40,7 +40,7 @@ typedef int boolean; 174.4 typedef struct bwcpoint /* break/watch/catch point */ 174.5 { 174.6 struct list_head list; 174.7 - memory_t address; 174.8 + unsigned long address; 174.9 u32 domain; 174.10 u8 old_value; /* old value for software bkpt */ 174.11 } bwcpoint_t, *bwcpoint_p; 174.12 @@ -311,7 +311,7 @@ xendebug_continue(int xc_handle, 174.13 /* access to one page */ 174.14 static int 174.15 xendebug_memory_page (domain_context_p ctxt, int xc_handle, u32 vcpu, 174.16 - int protection, memory_t address, int length, u8 *buffer) 174.17 + int protection, unsigned long address, int length, u8 *buffer) 174.18 { 174.19 vcpu_guest_context_t *vcpu_ctxt = &ctxt->context[vcpu]; 174.20 unsigned long pde, page; 174.21 @@ -407,7 +407,7 @@ xendebug_memory_page (domain_context_p c 174.22 /* divide a memory operation into accesses to individual pages */ 174.23 static int 174.24 xendebug_memory_op (domain_context_p ctxt, int xc_handle, u32 vcpu, 174.25 - int protection, memory_t address, int length, u8 *buffer) 174.26 + int protection, unsigned long address, int length, u8 *buffer) 174.27 { 174.28 int remain; /* number of bytes to touch past this page */ 174.29 int bytes = 0; 174.30 @@ -431,7 +431,7 @@ int 174.31 xendebug_read_memory(int xc_handle, 174.32 u32 domid, 174.33 u32 vcpu, 174.34 - memory_t address, 174.35 + unsigned long address, 174.36 u32 length, 174.37 u8 *data) 174.38 { 174.39 @@ -451,7 +451,7 @@ int 174.40 xendebug_write_memory(int xc_handle, 174.41 u32 domid, 174.42 u32 vcpu, 174.43 - memory_t address, 174.44 + unsigned long address, 174.45 u32 length, 174.46 u8 *data) 174.47 { 174.48 @@ -471,7 +471,7 @@ int 174.49 xendebug_insert_memory_breakpoint(int xc_handle, 174.50 u32 domid, 174.51 u32 vcpu, 174.52 - memory_t address, 174.53 + unsigned long address, 174.54 u32 length) 174.55 { 174.56 bwcpoint_p bkpt; 174.57 @@ -517,7 +517,7 @@ int 174.58 xendebug_remove_memory_breakpoint(int xc_handle, 174.59 u32 domid, 174.60 u32 vcpu, 174.61 - memory_t address, 174.62 + unsigned long address, 174.63 u32 length) 174.64 { 174.65 bwcpoint_p bkpt = NULL;
175.1 --- a/tools/debugger/libxendebug/xendebug.h Thu Aug 18 10:40:02 2005 -0800 175.2 +++ b/tools/debugger/libxendebug/xendebug.h Fri Aug 19 10:19:28 2005 -0800 175.3 @@ -45,7 +45,7 @@ int xendebug_continue(int xc_handle, 175.4 int xendebug_read_memory(int xc_handle, 175.5 u32 domid, 175.6 u32 vcpu, 175.7 - memory_t address, 175.8 + unsigned long address, 175.9 u32 length, 175.10 u8 *data); 175.11 175.12 @@ -53,7 +53,7 @@ int xendebug_read_memory(int xc_handle, 175.13 int xendebug_write_memory(int xc_handle, 175.14 u32 domid, 175.15 u32 vcpu, 175.16 - memory_t address, 175.17 + unsigned long address, 175.18 u32 length, 175.19 u8 *data); 175.20 175.21 @@ -61,13 +61,13 @@ int xendebug_write_memory(int xc_handle, 175.22 int xendebug_insert_memory_breakpoint(int xc_handle, 175.23 u32 domid, 175.24 u32 vcpu, 175.25 - memory_t address, 175.26 + unsigned long address, 175.27 u32 length); 175.28 175.29 int xendebug_remove_memory_breakpoint(int xc_handle, 175.30 u32 domid, 175.31 u32 vcpu, 175.32 - memory_t address, 175.33 + unsigned long address, 175.34 u32 length); 175.35 175.36 int xendebug_query_domain_stop(int xc_handle,
187.1 --- a/tools/debugger/pdb/linux-2.6-module/debug.c Thu Aug 18 10:40:02 2005 -0800 187.2 +++ b/tools/debugger/pdb/linux-2.6-module/debug.c Fri Aug 19 10:19:28 2005 -0800 187.3 @@ -26,7 +26,7 @@ static int pdb_page_fault_fn (struct pt_ 187.4 typedef struct bwcpoint /* break/watch/catch point */ 187.5 { 187.6 struct list_head list; 187.7 - memory_t address; 187.8 + unsigned long address; 187.9 int length; 187.10 187.11 u8 type; /* BWC_??? */ 187.12 @@ -109,7 +109,7 @@ pdb_bwc_print_list (void) 187.13 } 187.14 187.15 bwcpoint_p 187.16 -pdb_search_watchpoint (u32 process, memory_t address) 187.17 +pdb_search_watchpoint (u32 process, unsigned long address) 187.18 { 187.19 bwcpoint_p bwc_watch = (bwcpoint_p) 0; 187.20 bwcpoint_p bwc_entry = (bwcpoint_p) 0; 187.21 @@ -364,7 +364,7 @@ pdb_step (struct task_struct *target) 187.22 187.23 int 187.24 pdb_insert_memory_breakpoint (struct task_struct *target, 187.25 - memory_t address, u32 length) 187.26 + unsigned long address, u32 length) 187.27 { 187.28 int rc = 0; 187.29 bwcpoint_p bkpt; 187.30 @@ -399,7 +399,7 @@ pdb_insert_memory_breakpoint (struct tas 187.31 187.32 int 187.33 pdb_remove_memory_breakpoint (struct task_struct *target, 187.34 - memory_t address, u32 length) 187.35 + unsigned long address, u32 length) 187.36 { 187.37 int rc = 0; 187.38 bwcpoint_p bkpt = NULL; 187.39 @@ -760,7 +760,7 @@ pdb_int3_fn (struct pt_regs *regs, long 187.40 { 187.41 pdb_response_t resp; 187.42 bwcpoint_p bkpt = NULL; 187.43 - memory_t address = regs->eip - 1; 187.44 + unsigned long address = regs->eip - 1; 187.45 187.46 struct list_head *entry; 187.47 list_for_each(entry, &bwcpoint_list)
188.1 --- a/tools/debugger/pdb/linux-2.6-module/module.c Thu Aug 18 10:40:02 2005 -0800 188.2 +++ b/tools/debugger/pdb/linux-2.6-module/module.c Fri Aug 19 10:19:28 2005 -0800 188.3 @@ -199,7 +199,7 @@ pdb_interrupt (int irq, void *dev_id, st 188.4 } 188.5 188.6 static void 188.7 -pdb_send_connection_status(int status, memory_t ring) 188.8 +pdb_send_connection_status(int status, unsigned long ring) 188.9 { 188.10 ctrl_msg_t cmsg = 188.11 {
189.1 --- a/tools/debugger/pdb/linux-2.6-module/pdb_debug.h Thu Aug 18 10:40:02 2005 -0800 189.2 +++ b/tools/debugger/pdb/linux-2.6-module/pdb_debug.h Fri Aug 19 10:19:28 2005 -0800 189.3 @@ -18,9 +18,9 @@ int pdb_continue (struct task_struct *ta 189.4 int pdb_step (struct task_struct *target); 189.5 189.6 int pdb_insert_memory_breakpoint (struct task_struct *target, 189.7 - memory_t address, u32 length); 189.8 + unsigned long address, u32 length); 189.9 int pdb_remove_memory_breakpoint (struct task_struct *target, 189.10 - memory_t address, u32 length); 189.11 + unsigned long address, u32 length); 189.12 int pdb_insert_watchpoint (struct task_struct *target, 189.13 pdb_op_watchpt_p watchpt); 189.14 int pdb_remove_watchpoint (struct task_struct *target,
197.1 --- a/tools/debugger/pdb/pdb_caml_domain.c Thu Aug 18 10:40:02 2005 -0800 197.2 +++ b/tools/debugger/pdb/pdb_caml_domain.c Fri Aug 19 10:19:28 2005 -0800 197.3 @@ -203,7 +203,7 @@ dom_read_memory (value context, value ad 197.4 context_t ctx; 197.5 int loop; 197.6 char *buffer; 197.7 - memory_t my_address = Int32_val(address); 197.8 + unsigned long my_address = Int32_val(address); 197.9 u32 my_length = Int_val(length); 197.10 197.11 printf ("(pdb) read memory\n"); 197.12 @@ -259,7 +259,7 @@ dom_write_memory (value context, value a 197.13 context_t ctx; 197.14 197.15 char buffer[4096]; /* a big buffer */ 197.16 - memory_t my_address; 197.17 + unsigned long my_address; 197.18 u32 length = 0; 197.19 197.20 printf ("(pdb) write memory\n"); 197.21 @@ -279,7 +279,7 @@ dom_write_memory (value context, value a 197.22 } 197.23 buffer[length++] = Int_val(Field(node, 0)); 197.24 197.25 - my_address = (memory_t) Int32_val(address); 197.26 + my_address = (unsigned long) Int32_val(address); 197.27 197.28 if ( xendebug_write_memory(xc_handle, ctx.domain, ctx.vcpu, 197.29 my_address, length, buffer) ) 197.30 @@ -344,7 +344,7 @@ dom_insert_memory_breakpoint (value cont 197.31 CAMLparam3(context, address, length); 197.32 197.33 context_t ctx; 197.34 - memory_t my_address = (memory_t) Int32_val(address); 197.35 + unsigned long my_address = (unsigned long) Int32_val(address); 197.36 int my_length = Int_val(length); 197.37 197.38 decode_context(&ctx, context); 197.39 @@ -373,7 +373,7 @@ dom_remove_memory_breakpoint (value cont 197.40 197.41 context_t ctx; 197.42 197.43 - memory_t my_address = (memory_t) Int32_val(address); 197.44 + unsigned long my_address = (unsigned long) Int32_val(address); 197.45 int my_length = Int_val(length); 197.46 197.47 printf ("(pdb) remove memory breakpoint 0x%lx %d\n",
198.1 --- a/tools/debugger/pdb/pdb_caml_process.c Thu Aug 18 10:40:02 2005 -0800 198.2 +++ b/tools/debugger/pdb/pdb_caml_process.c Fri Aug 19 10:19:28 2005 -0800 198.3 @@ -495,7 +495,7 @@ proc_insert_memory_breakpoint (value con 198.4 198.5 req.operation = PDB_OPCODE_SET_BKPT; 198.6 req.process = ctx.process; 198.7 - req.u.bkpt.address = (memory_t) Int32_val(address); 198.8 + req.u.bkpt.address = (unsigned long) Int32_val(address); 198.9 req.u.bkpt.length = Int_val(length); 198.10 198.11 send_request(ctx.ring, ctx.evtchn, &req); 198.12 @@ -518,7 +518,7 @@ proc_remove_memory_breakpoint (value con 198.13 198.14 req.operation = PDB_OPCODE_CLR_BKPT; 198.15 req.process = ctx.process; 198.16 - req.u.bkpt.address = (memory_t) Int32_val(address); 198.17 + req.u.bkpt.address = (unsigned long) Int32_val(address); 198.18 req.u.bkpt.length = Int_val(length); 198.19 198.20 send_request(ctx.ring, ctx.evtchn, &req); 198.21 @@ -542,7 +542,7 @@ proc_insert_watchpoint (value context, v 198.22 req.operation = PDB_OPCODE_SET_WATCHPT; 198.23 req.process = ctx.process; 198.24 req.u.watchpt.type = Int_val(kind); 198.25 - req.u.watchpt.address = (memory_t) Int32_val(address); 198.26 + req.u.watchpt.address = (unsigned long) Int32_val(address); 198.27 req.u.watchpt.length = Int_val(length); 198.28 198.29 send_request(ctx.ring, ctx.evtchn, &req); 198.30 @@ -566,7 +566,7 @@ proc_remove_watchpoint (value context, v 198.31 req.operation = PDB_OPCODE_CLR_WATCHPT; 198.32 req.process = ctx.process; 198.33 req.u.watchpt.type = Int_val(kind); 198.34 - req.u.watchpt.address = (memory_t) Int32_val(address); 198.35 + req.u.watchpt.address = (unsigned long) Int32_val(address); 198.36 req.u.watchpt.length = Int_val(length); 198.37 198.38 send_request(ctx.ring, ctx.evtchn, &req);
199.1 --- a/tools/debugger/pdb/pdb_caml_xcs.c Thu Aug 18 10:40:02 2005 -0800 199.2 +++ b/tools/debugger/pdb/pdb_caml_xcs.c Fri Aug 19 10:19:28 2005 -0800 199.3 @@ -50,7 +50,7 @@ xcs_initialize_ring (value domain, value 199.4 { 199.5 CAMLparam2(domain, ring); 199.6 int my_domain = Int_val(domain); 199.7 - memory_t my_ring = Int32_val(ring); 199.8 + unsigned long my_ring = Int32_val(ring); 199.9 199.10 pdb_front_ring_t *front_ring; 199.11 pdb_sring_t *sring;
219.1 --- a/tools/libxc/xc.h Thu Aug 18 10:40:02 2005 -0800 219.2 +++ b/tools/libxc/xc.h Fri Aug 19 10:19:28 2005 -0800 219.3 @@ -515,25 +515,25 @@ int xc_grant_interface_open(void); 219.4 */ 219.5 int xc_grant_interface_close(int xc_handle); 219.6 219.7 -int xc_gnttab_map_grant_ref(int xc_handle, 219.8 - memory_t host_virt_addr, 219.9 - u32 dom, 219.10 - u16 ref, 219.11 - u16 flags, 219.12 - s16 *handle, 219.13 - memory_t *dev_bus_addr); 219.14 +int xc_gnttab_map_grant_ref(int xc_handle, 219.15 + u64 host_virt_addr, 219.16 + u32 dom, 219.17 + u16 ref, 219.18 + u16 flags, 219.19 + s16 *handle, 219.20 + u64 *dev_bus_addr); 219.21 219.22 -int xc_gnttab_unmap_grant_ref(int xc_handle, 219.23 - memory_t host_virt_addr, 219.24 - memory_t dev_bus_addr, 219.25 - u16 handle, 219.26 - s16 *status); 219.27 +int xc_gnttab_unmap_grant_ref(int xc_handle, 219.28 + u64 host_virt_addr, 219.29 + u64 dev_bus_addr, 219.30 + u16 handle, 219.31 + s16 *status); 219.32 219.33 int xc_gnttab_setup_table(int xc_handle, 219.34 u32 dom, 219.35 u16 nr_frames, 219.36 s16 *status, 219.37 - memory_t **frame_list); 219.38 + unsigned long **frame_list); 219.39 219.40 /* Grant debug builds only: */ 219.41 int xc_gnttab_dump_table(int xc_handle,
222.1 --- a/tools/libxc/xc_gnttab.c Thu Aug 18 10:40:02 2005 -0800 222.2 +++ b/tools/libxc/xc_gnttab.c Fri Aug 19 10:19:28 2005 -0800 222.3 @@ -40,12 +40,12 @@ do_gnttab_op(int xc_handle, 222.4 222.5 222.6 int xc_gnttab_map_grant_ref(int xc_handle, 222.7 - memory_t host_virt_addr, 222.8 + u64 host_virt_addr, 222.9 u32 dom, 222.10 u16 ref, 222.11 u16 flags, 222.12 s16 *handle, 222.13 - memory_t *dev_bus_addr) 222.14 + u64 *dev_bus_addr) 222.15 { 222.16 struct gnttab_map_grant_ref op; 222.17 int rc; 222.18 @@ -67,8 +67,8 @@ int xc_gnttab_map_grant_ref(int 222.19 222.20 222.21 int xc_gnttab_unmap_grant_ref(int xc_handle, 222.22 - memory_t host_virt_addr, 222.23 - memory_t dev_bus_addr, 222.24 + u64 host_virt_addr, 222.25 + u64 dev_bus_addr, 222.26 u16 handle, 222.27 s16 *status) 222.28 { 222.29 @@ -92,7 +92,7 @@ int xc_gnttab_setup_table(int xc_ 222.30 u32 dom, 222.31 u16 nr_frames, 222.32 s16 *status, 222.33 - memory_t **frame_list) 222.34 + unsigned long **frame_list) 222.35 { 222.36 struct gnttab_setup_table op; 222.37 int rc, i;
232.1 --- a/tools/misc/policyprocessor/Makefile Thu Aug 18 10:40:02 2005 -0800 232.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 232.3 @@ -1,42 +0,0 @@ 232.4 -XEN_ROOT = ../../.. 232.5 -include $(XEN_ROOT)/tools/Rules.mk 232.6 - 232.7 -CFLAGS += -static 232.8 -CFLAGS += -Wall 232.9 -CFLAGS += -Werror 232.10 -CFLAGS += -O3 232.11 -CFLAGS += -fno-strict-aliasing 232.12 -CFLAGS += -I. 232.13 - 232.14 -all: build 232.15 - 232.16 -build: mk-symlinks 232.17 - $(MAKE) xml_to_bin 232.18 - 232.19 -default: all 232.20 - 232.21 -install: all 232.22 - 232.23 -xml_to_bin : make_include XmlToBin.java XmlToBinInterface.java SsidsEntry.java SecurityLabel.java myHandler.java 232.24 - javac XmlToBin.java 232.25 - 232.26 -make_include : c2j_include 232.27 - ./c2j_include 232.28 - 232.29 -c2j_include: c2j_include.c 232.30 - $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< 232.31 - 232.32 -clean: 232.33 - rm -rf *.class xen c2j_include policy_version.java *.bin 232.34 - 232.35 - 232.36 -LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 232.37 -mk-symlinks: 232.38 - [ -e xen/linux ] || mkdir -p xen/linux 232.39 - [ -e xen/io ] || mkdir -p xen/io 232.40 - ( cd xen >/dev/null ; \ 232.41 - ln -sf ../$(XEN_ROOT)/xen/include/public/*.h . ) 232.42 - ( cd xen/io >/dev/null ; \ 232.43 - ln -sf ../../$(XEN_ROOT)/xen/include/public/io/*.h . ) 232.44 - ( cd xen/linux >/dev/null ; \ 232.45 - ln -sf ../../$(LINUX_ROOT)/include/asm-xen/linux-public/*.h . )
233.1 --- a/tools/misc/policyprocessor/SecurityLabel.java Thu Aug 18 10:40:02 2005 -0800 233.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 233.3 @@ -1,34 +0,0 @@ 233.4 -/** 233.5 - * (C) Copyright IBM Corp. 2005 233.6 - * 233.7 - * $Id: SecurityLabel.java,v 1.2 2005/06/17 20:00:04 rvaldez Exp $ 233.8 - * 233.9 - * Author: Ray Valdez 233.10 - * 233.11 - * This program is free software; you can redistribute it and/or 233.12 - * modify it under the terms of the GNU General Public License as 233.13 - * published by the Free Software Foundation, version 2 of the 233.14 - * License. 233.15 - * 233.16 - * SecurityLabel Class. 233.17 - * 233.18 - * <p> 233.19 - * 233.20 - * Keeps track of types. 233.21 - * 233.22 - * <p> 233.23 - * 233.24 - * 233.25 - */ 233.26 -import java.util.*; 233.27 -public class SecurityLabel 233.28 -{ 233.29 - Vector ids; 233.30 - Vector vlans; 233.31 - Vector slots; 233.32 - Vector steTypes; 233.33 - int steSsidPosition; 233.34 - Vector chwIDs; 233.35 - Vector chwTypes; 233.36 - int chwSsidPosition; 233.37 -}
234.1 --- a/tools/misc/policyprocessor/SecurityPolicySpec.xsd Thu Aug 18 10:40:02 2005 -0800 234.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 234.3 @@ -1,115 +0,0 @@ 234.4 -<?xml version="1.0" encoding="UTF-8"?> 234.5 -<!-- Author: Ray Valdez, rvaldez@us.ibm.com --> 234.6 -<!-- xml schema definition for xen xml policies --> 234.7 -<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 234.8 -targetNamespace="http://www.ibm.com" 234.9 -xmlns="http://www.ibm.com" 234.10 -elementFormDefault="qualified"> 234.11 - 234.12 -<xsd:element name="TE" type="xsd:string" /> 234.13 -<xsd:element name="ChWall" type="xsd:string" /> 234.14 - 234.15 -<xsd:element name="Definition"> 234.16 - <xsd:complexType> 234.17 - <xsd:sequence> 234.18 - 234.19 - <!-- simple type enforcement --> 234.20 - <xsd:element name="Types" minOccurs ="0" maxOccurs="1"> 234.21 - <xsd:complexType> 234.22 - <xsd:sequence> 234.23 - <xsd:element ref="TE" minOccurs ="1" maxOccurs ="unbounded"/> 234.24 - </xsd:sequence> 234.25 - </xsd:complexType> 234.26 - </xsd:element> 234.27 - 234.28 - <!-- chinese wall --> 234.29 - <!-- type definition --> 234.30 - <xsd:element name="ChWallTypes" minOccurs ="0" maxOccurs="1"> 234.31 - <xsd:complexType> 234.32 - <xsd:sequence> 234.33 - <xsd:element ref="ChWall" minOccurs ="1" maxOccurs ="unbounded"/> 234.34 - 234.35 - </xsd:sequence> 234.36 - </xsd:complexType> 234.37 - </xsd:element> 234.38 - 234.39 - <!-- conflict set --> 234.40 - <xsd:element name="ConflictSet" minOccurs ="0" maxOccurs="unbounded"> 234.41 - <xsd:complexType> 234.42 - <xsd:sequence> 234.43 - <xsd:element ref="ChWall" minOccurs ="2" maxOccurs ="unbounded"/> 234.44 - </xsd:sequence> 234.45 - </xsd:complexType> 234.46 - </xsd:element> 234.47 - 234.48 - </xsd:sequence> 234.49 - </xsd:complexType> 234.50 -</xsd:element> 234.51 - 234.52 -<xsd:element name="Policy"> 234.53 - <xsd:complexType> 234.54 - <xsd:sequence> 234.55 - 234.56 - <xsd:element name="PolicyHeader"> 234.57 - <xsd:complexType> 234.58 - <xsd:all> 234.59 - <xsd:element name = "Name" type="xsd:string"/> 234.60 - <xsd:element name = "DateTime" type="xsd:dateTime"/> 234.61 - <xsd:element name = "Tag" minOccurs ="1" maxOccurs ="1" type="xsd:string"/> 234.62 - <xsd:element name = "TypeDefinition"> 234.63 - <xsd:complexType> 234.64 - <xsd:all> 234.65 - <xsd:element name = "url" type="xsd:string"/> 234.66 - <xsd:element name = "hash" minOccurs ="0" maxOccurs ="1" type="xsd:string"/> 234.67 - </xsd:all> 234.68 - </xsd:complexType> 234.69 - </xsd:element> 234.70 - 234.71 - </xsd:all> 234.72 - </xsd:complexType> 234.73 - </xsd:element> 234.74 - 234.75 - <xsd:element name="VM" minOccurs ="1" maxOccurs="unbounded"> 234.76 - <xsd:complexType> 234.77 - <xsd:sequence> 234.78 - <xsd:element name="id" type="xsd:integer"/> 234.79 - <xsd:element ref="TE" minOccurs="0" maxOccurs="unbounded" /> 234.80 - <xsd:element ref="ChWall" minOccurs ="0" maxOccurs="unbounded"/> 234.81 - </xsd:sequence> 234.82 - </xsd:complexType> 234.83 - </xsd:element> 234.84 - 234.85 - <xsd:element name="Vlan" minOccurs ="0" maxOccurs="unbounded"> 234.86 - <xsd:complexType> 234.87 - <xsd:sequence> 234.88 - <xsd:element name="vid" type="xsd:integer"/> 234.89 - <xsd:element ref="TE" minOccurs="1" maxOccurs="unbounded" /> 234.90 - </xsd:sequence> 234.91 - </xsd:complexType> 234.92 - </xsd:element> 234.93 - 234.94 - <xsd:element name="Slot" minOccurs ="0" maxOccurs="unbounded"> 234.95 - <xsd:complexType> 234.96 - <xsd:sequence> 234.97 - <xsd:element name="bus" type="xsd:integer"/> 234.98 - <xsd:element name="slot" type="xsd:integer"/> 234.99 - <xsd:element ref="TE" minOccurs="1" maxOccurs="unbounded" /> 234.100 - </xsd:sequence> 234.101 - </xsd:complexType> 234.102 - </xsd:element> 234.103 - 234.104 - 234.105 - </xsd:sequence> 234.106 - </xsd:complexType> 234.107 -</xsd:element> 234.108 - 234.109 -<!-- root element --> 234.110 -<xsd:element name="SecurityPolicySpec"> 234.111 - <xsd:complexType> 234.112 - <xsd:choice> 234.113 - <xsd:element ref="Definition" minOccurs ="1" maxOccurs="unbounded"/> 234.114 - <xsd:element ref="Policy" minOccurs ="1" maxOccurs="unbounded"/> 234.115 - </xsd:choice> 234.116 - </xsd:complexType> 234.117 -</xsd:element> 234.118 -</xsd:schema>
235.1 --- a/tools/misc/policyprocessor/SsidsEntry.java Thu Aug 18 10:40:02 2005 -0800 235.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 235.3 @@ -1,29 +0,0 @@ 235.4 -/** 235.5 - * (C) Copyright IBM Corp. 2005 235.6 - * 235.7 - * $Id: SsidsEntry.java,v 1.2 2005/06/17 20:02:40 rvaldez Exp $ 235.8 - * 235.9 - * Author: Ray Valdez 235.10 - * 235.11 - * This program is free software; you can redistribute it and/or 235.12 - * modify it under the terms of the GNU General Public License as 235.13 - * published by the Free Software Foundation, version 2 of the 235.14 - * License. 235.15 - * 235.16 - * SsidsEntry Class. 235.17 - * <p> 235.18 - * 235.19 - * Holds ssid information. 235.20 - * 235.21 - * <p> 235.22 - * 235.23 - * 235.24 - */ 235.25 -public class SsidsEntry 235.26 - { 235.27 - int id; /* used for partition and vlan */ 235.28 - int bus; /* used for slots */ 235.29 - int slot; 235.30 - int ste = 0xffffffff; 235.31 - int chw = 0xffffffff; 235.32 - }
236.1 --- a/tools/misc/policyprocessor/XmlToBin.java Thu Aug 18 10:40:02 2005 -0800 236.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 236.3 @@ -1,1570 +0,0 @@ 236.4 -/** 236.5 - * (C) Copyright IBM Corp. 2005 236.6 - * 236.7 - * $Id: XmlToBin.java,v 1.3 2005/06/20 21:07:37 rvaldez Exp $ 236.8 - * 236.9 - * Author: Ray Valdez 236.10 - * 236.11 - * Contributors: 236.12 - * Reiner Sailer - adjust type-lengths 236.13 - * 236.14 - * This program is free software; you can redistribute it and/or 236.15 - * modify it under the terms of the GNU General Public License as 236.16 - * published by the Free Software Foundation, version 2 of the 236.17 - * License. 236.18 - * 236.19 - * XmlToBin Class. 236.20 - * <p> 236.21 - * 236.22 - * Translates a xml representation of a SHYPE policy into a binary 236.23 - * format. The class processes an xml policy file based on elment tags 236.24 - * defined in a schema definition files: SecurityPolicySpec.xsd. 236.25 - * 236.26 - * XmlToBin Command line Options: 236.27 - * 236.28 - * -i inputFile: name of policyfile (.xml) 236.29 - * -o outputFile: name of binary policy file (Big Endian) 236.30 - * -xssid SsidFile: xen ssids to types text file 236.31 - * -xssidconf SsidConf: xen conflict ssids to types text file 236.32 - * -debug turn on debug messages 236.33 - * -help help. This printout 236.34 - * 236.35 - * <p> 236.36 - * 236.37 - * 236.38 - */ 236.39 -import java.util.*; 236.40 -import java.io.*; 236.41 -import java.io.IOException; 236.42 -import java.io.FileNotFoundException; 236.43 -import org.w3c.dom.Document; 236.44 -import org.w3c.dom.Element; 236.45 -import org.w3c.dom.Node; 236.46 -import org.w3c.dom.Attr; 236.47 -import org.w3c.dom.NodeList; 236.48 -import org.w3c.dom.NamedNodeMap; 236.49 -import org.xml.sax.*; 236.50 -import javax.xml.parsers.*; 236.51 -import org.xml.sax.helpers.*; 236.52 - 236.53 -public class XmlToBin 236.54 - implements XmlToBinInterface 236.55 -{ 236.56 - class SlotInfo { 236.57 - String bus; 236.58 - String slot; 236.59 - } 236.60 - 236.61 - boolean LittleEndian = false; 236.62 - boolean debug = false; 236.63 - 236.64 - static final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage"; 236.65 - 236.66 - static final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema"; 236.67 - 236.68 - public static void printUsage() 236.69 - { 236.70 - System.out.println("XmlToBin Command line Options: "); 236.71 - System.out.println("\t-i\t\tinputFile:\tname of policyfile (.xml)"); 236.72 - System.out.println("\t-o\t\toutputFile:\tname of binary policy file (Big Endian)"); 236.73 - System.out.println("\t-xssid\t\tSsidFile:\tXen ssids to named types text file"); 236.74 - System.out.println("\t-xssidconf\tSsidConfFile:\tXen conflict ssids to named types text file"); 236.75 - System.out.println("\t-debug\t\t\t\tturn on debug messages"); 236.76 - System.out.println("\t-help\t\t\t\thelp. This printout"); 236.77 - return; 236.78 - } 236.79 - 236.80 - public void printDebug(String message) 236.81 - { 236.82 - if (debug) 236.83 - System.out.println(message); 236.84 - } 236.85 - 236.86 - public void writeBinPolicy(byte[] binPolicy, String outputFileName) 236.87 - throws Exception 236.88 - { 236.89 - if (debug) 236.90 - printHex(binPolicy,binPolicy.length); 236.91 - 236.92 - DataOutputStream writeObj = new DataOutputStream( 236.93 - new FileOutputStream(outputFileName)); 236.94 - 236.95 - writeObj.write(binPolicy); 236.96 - writeObj.flush(); 236.97 - writeObj.close(); 236.98 - System.out.println(" wBP:: wrote outputfile: " + outputFileName); 236.99 - 236.100 - return; 236.101 - } 236.102 - 236.103 - public void writeXenTypeVectorFile(Vector list, String outputFileName) 236.104 - throws Exception 236.105 - { 236.106 - PrintWriter out; 236.107 - 236.108 - if (0 == list.size()) 236.109 - { 236.110 - printDebug(" wSTF : size of input is zero when writing :" + outputFileName); 236.111 - return; 236.112 - } 236.113 - out = new PrintWriter( 236.114 - new BufferedWriter( 236.115 - new FileWriter(outputFileName))); 236.116 - 236.117 - 236.118 - for (int i = 0; i < list.size(); i++) 236.119 - { 236.120 - Vector ee = (Vector) list.elementAt(i); 236.121 - out.println(i + " " +ee.toString()); 236.122 - } 236.123 - out.close(); 236.124 - 236.125 - return; 236.126 - } 236.127 - 236.128 - public void writeXenTypeFile(Vector list, String outputFileName, boolean slabel) 236.129 - throws Exception 236.130 - { 236.131 - Vector entry; 236.132 - String strTypes = ""; 236.133 - SecurityLabel ee; 236.134 - PrintWriter out; 236.135 - 236.136 - if (0 == list.size()) 236.137 - { 236.138 - printDebug(" wSTF : size of input is zero when writing :" + outputFileName); 236.139 - return; 236.140 - } 236.141 - out = new PrintWriter( 236.142 - new BufferedWriter( 236.143 - new FileWriter(outputFileName))); 236.144 - 236.145 - for (int i = 0; i < list.size(); i++) 236.146 - { 236.147 - ee = (SecurityLabel) list.elementAt(i); 236.148 - 236.149 - if (slabel) 236.150 - { 236.151 - entry = ee.steTypes; 236.152 - } else { 236.153 - 236.154 - entry = ee.chwTypes; 236.155 - } 236.156 - if (null == entry) continue; 236.157 - 236.158 - Enumeration e = entry.elements(); 236.159 - while (e.hasMoreElements()) 236.160 - { 236.161 - String typeName = (String) e.nextElement(); 236.162 - strTypes = strTypes + " " + typeName; 236.163 - } 236.164 - printDebug(" WXTF:: ssid : "+i +" :"+strTypes); 236.165 - out.println(i +" "+strTypes); 236.166 - strTypes = ""; 236.167 - } 236.168 - out.close(); 236.169 - 236.170 - return; 236.171 - } 236.172 - 236.173 - public void setDebug(boolean value) 236.174 - { 236.175 - debug=value; 236.176 - } 236.177 - 236.178 - public void setEndian(boolean value) 236.179 - { 236.180 - LittleEndian = value; 236.181 - } 236.182 - 236.183 - public byte[] generateVlanSsids(Vector bagOfSsids) 236.184 - throws Exception 236.185 - { 236.186 - /** 236.187 - typedef struct { 236.188 - u16 vlan; 236.189 - u16 ssid_ste; 236.190 - } acm_vlan_entry_t; 236.191 - **/ 236.192 - 236.193 - Hashtable vlanSsid = new Hashtable(); 236.194 - printDebug(" gVS::Size of bagOfSsids: "+ bagOfSsids.size()); 236.195 - 236.196 - /* Get the number of partitions */ 236.197 - for (int i = 0; i < bagOfSsids.size(); i++) 236.198 - { 236.199 - SecurityLabel entry = (SecurityLabel) bagOfSsids.elementAt(i); 236.200 - 236.201 - if (null == entry.vlans) 236.202 - continue; 236.203 - 236.204 - Enumeration e = entry.vlans.elements(); 236.205 - while (e.hasMoreElements()) 236.206 - { 236.207 - String id = (String) e.nextElement(); 236.208 - printDebug(" gVS:: vlan: " + id + "has ste ssid: " + entry.steSsidPosition); 236.209 - if (-1 == entry.steSsidPosition) 236.210 - continue; 236.211 - 236.212 - /* Only use ste for vlan */ 236.213 - SsidsEntry ssidsObj = new SsidsEntry(); 236.214 - 236.215 - ssidsObj.id = Integer.parseInt(id); 236.216 - ssidsObj.ste = entry.steSsidPosition; 236.217 - 236.218 - if (vlanSsid.contains(id)) 236.219 - printDebug(" gVS:: Error already in the Hash part:" + ssidsObj.id); 236.220 - else 236.221 - vlanSsid.put(id, ssidsObj); 236.222 - printDebug(" gVS:: added part: " + id + "has ste ssid: " + entry.steSsidPosition); 236.223 - } 236.224 - } 236.225 - 236.226 - /* allocate array */ 236.227 - int numOfVlan = vlanSsid.size(); 236.228 - int totalSize = (numOfVlan * vlanEntrySz); 236.229 - 236.230 - if (0 == numOfVlan) 236.231 - { 236.232 - printDebug(" gVS:: vlan: binary ==> zero"); 236.233 - return new byte[0]; 236.234 - } 236.235 - 236.236 - byte[] vlanArray = new byte[totalSize]; 236.237 - 236.238 - int index = 0; 236.239 - 236.240 - Enumeration e = vlanSsid.elements(); 236.241 - while (e.hasMoreElements()) 236.242 - { 236.243 - SsidsEntry entry = (SsidsEntry) e.nextElement(); 236.244 - printDebug(" gVS:: part: " + entry.id + " ste ssid: " + entry.ste); 236.245 - 236.246 - /* Write id */ 236.247 - writeShortToStream(vlanArray,(short)entry.id,index); 236.248 - index = index + u16Size; 236.249 - 236.250 - /* write ste ssid */ 236.251 - writeShortToStream(vlanArray,(short) entry.ste,index); 236.252 - index = index + u16Size; 236.253 - } 236.254 - 236.255 - printDebug(" gVS:: vlan: num of vlans " + numOfVlan); 236.256 - printDebug(" gVS:: vlan: binary ==> Length "+ vlanArray.length); 236.257 - 236.258 - if (debug) 236.259 - printHex(vlanArray,vlanArray.length); 236.260 - printDebug("\n"); 236.261 - 236.262 - return vlanArray; 236.263 - } 236.264 - 236.265 - public byte[] generateSlotSsids(Vector bagOfSsids) 236.266 - throws Exception 236.267 - { 236.268 - /** 236.269 - typedef struct { 236.270 - u16 slot_max; 236.271 - u16 slot_offset; 236.272 - } acm_slot_buffer_t; 236.273 - 236.274 - typedef struct { 236.275 - u16 bus; 236.276 - u16 slot; 236.277 - u16 ssid_ste; 236.278 - } acm_slot_entry_t; 236.279 - **/ 236.280 - Hashtable slotSsid = new Hashtable(); 236.281 - printDebug(" gSS::Size of bagOfSsids: "+ bagOfSsids.size()); 236.282 - 236.283 - /* Find the number of VMs */ 236.284 - for (int i = 0; i < bagOfSsids.size(); i++) 236.285 - { 236.286 - SecurityLabel entry = (SecurityLabel) bagOfSsids.elementAt(i); 236.287 - 236.288 - if (null == entry.slots) 236.289 - continue; 236.290 - 236.291 - Enumeration e = entry.slots.elements(); 236.292 - while (e.hasMoreElements()) 236.293 - { 236.294 - SlotInfo item = (SlotInfo) e.nextElement(); 236.295 - printDebug(" gSS:: bus slot: " + item.bus + " "+ item.slot + " " + entry.steSsidPosition); 236.296 - if (-1 == entry.steSsidPosition) 236.297 - continue; 236.298 - 236.299 - SsidsEntry ssidsObj = new SsidsEntry(); 236.300 - 236.301 - String id = item.bus +" "+item.slot; 236.302 - ssidsObj.bus = Integer.parseInt(item.bus); 236.303 - ssidsObj.slot = Integer.parseInt(item.slot); 236.304 - /* set ste ssid */ 236.305 - ssidsObj.ste = entry.steSsidPosition; 236.306 - 236.307 - if (slotSsid.contains(id)) 236.308 - printDebug(" gSS:: Error already in the Hash part:" + id); 236.309 - else 236.310 - slotSsid.put(id, ssidsObj); 236.311 - 236.312 - printDebug(" gSS:: added slot: " + id + "has ste ssid: " + entry.steSsidPosition); 236.313 - } 236.314 - } 236.315 - 236.316 - /* allocate array */ 236.317 - int numOfSlot = slotSsid.size(); 236.318 - 236.319 - if (0 == numOfSlot) 236.320 - { 236.321 - printDebug(" gVS:: slot: binary ==> zero"); 236.322 - return new byte[0]; 236.323 - } 236.324 - 236.325 - int totalSize = (numOfSlot * slotEntrySz); 236.326 - 236.327 - byte[] slotArray = new byte[totalSize]; 236.328 - 236.329 - int index = 0; 236.330 - 236.331 - Enumeration e = slotSsid.elements(); 236.332 - while (e.hasMoreElements()) 236.333 - { 236.334 - SsidsEntry entry = (SsidsEntry) e.nextElement(); 236.335 - System.out.println(" gSS:: bus slot: " + entry.bus + " " + entry.slot + " ste ssid: " + entry.ste); 236.336 - 236.337 - /* Write bus */ 236.338 - writeShortToStream(slotArray,(short)entry.bus,index); 236.339 - index = index + u16Size; 236.340 - 236.341 - /* Write slot */ 236.342 - writeShortToStream(slotArray,(short)entry.slot,index); 236.343 - index = index + u16Size; 236.344 - 236.345 - /* Write ste ssid */ 236.346 - writeShortToStream(slotArray,(short) entry.ste,index); 236.347 - index = index + u16Size; 236.348 - 236.349 - } 236.350 - 236.351 - printDebug(" gSS:: slot: num of vlans " + numOfSlot); 236.352 - printDebug(" gSS:: slot: binary ==> Length "+ slotArray.length); 236.353 - 236.354 - if (debug) 236.355 - printHex(slotArray,slotArray.length); 236.356 - printDebug("\n"); 236.357 - 236.358 - return slotArray; 236.359 - 236.360 - } 236.361 - 236.362 - public byte[] generatePartSsids(Vector bagOfSsids, Vector bagOfChwSsids) 236.363 - throws Exception 236.364 - { 236.365 - /** 236.366 - typedef struct { 236.367 - u16 id; 236.368 - u16 ssid_ste; 236.369 - u16 ssid_chwall; 236.370 - } acm_partition_entry_t; 236.371 - 236.372 - **/ 236.373 - Hashtable partSsid = new Hashtable(); 236.374 - printDebug(" gPS::Size of bagOfSsids: "+ bagOfSsids.size()); 236.375 - 236.376 - /* Find the number of VMs */ 236.377 - for (int i = 0; i < bagOfSsids.size(); i++) 236.378 - { 236.379 - SecurityLabel entry = (SecurityLabel) bagOfSsids.elementAt(i); 236.380 - 236.381 - if (null == entry.ids) 236.382 - continue; 236.383 - 236.384 - Enumeration e = entry.ids.elements(); 236.385 - while (e.hasMoreElements()) 236.386 - { 236.387 - String id = (String) e.nextElement(); 236.388 - printDebug(" gPS:: part: " + id + "has ste ssid: " + entry.steSsidPosition); 236.389 - if (-1 == entry.steSsidPosition) 236.390 - continue; 236.391 - 236.392 - SsidsEntry ssidsObj = new SsidsEntry(); 236.393 - 236.394 - ssidsObj.id = Integer.parseInt(id); 236.395 - ssidsObj.ste = entry.steSsidPosition; 236.396 - 236.397 - if (partSsid.contains(id)) 236.398 - printDebug(" gPS:: Error already in the Hash part:" + ssidsObj.id); 236.399 - else 236.400 - partSsid.put(id, ssidsObj); 236.401 - printDebug(" gPS:: added part: " + id + "has ste ssid: " + entry.steSsidPosition); 236.402 - } 236.403 - 236.404 - } 236.405 - 236.406 - for (int i = 0; i < bagOfChwSsids.size(); i++) 236.407 - { 236.408 - SecurityLabel entry = (SecurityLabel) bagOfChwSsids.elementAt(i); 236.409 - 236.410 - Enumeration e = entry.chwIDs.elements(); 236.411 - while (e.hasMoreElements()) 236.412 - { 236.413 - String id = (String) e.nextElement(); 236.414 - printDebug(" gPS:: part: " + id + "has chw ssid: " + entry.chwSsidPosition); 236.415 - if (partSsid.containsKey(id)) 236.416 - { 236.417 - SsidsEntry item = (SsidsEntry) partSsid.get(id); 236.418 - item.chw = entry.chwSsidPosition; 236.419 - printDebug(" gPS:: added :" + item.id +" chw: " + item.chw); 236.420 - } 236.421 - else 236.422 - { 236.423 - printDebug(" gPS:: creating :" + id +" chw: " + entry.chwSsidPosition); 236.424 - SsidsEntry ssidsObj = new SsidsEntry(); 236.425 - ssidsObj.id = Integer.parseInt(id); 236.426 - ssidsObj.chw = entry.chwSsidPosition; 236.427 - partSsid.put(id, ssidsObj); 236.428 - 236.429 - } 236.430 - } 236.431 - } 236.432 - 236.433 - /* Allocate array */ 236.434 - int numOfPar = partSsid.size(); 236.435 - int totalSize = (numOfPar * partitionEntrySz); 236.436 - 236.437 - if (0 == numOfPar) 236.438 - { 236.439 - printDebug(" gPS:: part: binary ==> zero"); 236.440 - return new byte[0]; 236.441 - } 236.442 - 236.443 - byte[] partArray = new byte[totalSize]; 236.444 - 236.445 - int index = 0; 236.446 - 236.447 - Enumeration e = partSsid.elements(); 236.448 - while (e.hasMoreElements()) 236.449 - { 236.450 - SsidsEntry entry = (SsidsEntry) e.nextElement(); 236.451 - printDebug(" gPS:: part: " + entry.id + " ste ssid: " + entry.ste + " chw ssid: "+ entry.chw); 236.452 - 236.453 - /* Write id */ 236.454 - writeShortToStream(partArray,(short)entry.id,index); 236.455 - index = index + u16Size; 236.456 - 236.457 - /* Write ste ssid */ 236.458 - writeShortToStream(partArray,(short) entry.ste,index); 236.459 - index = index + u16Size; 236.460 - 236.461 - /* Write chw ssid */ 236.462 - writeShortToStream(partArray,(short) entry.chw,index); 236.463 - index = index + u16Size; 236.464 - } 236.465 - 236.466 - printDebug(" gPS:: part: num of partitions " + numOfPar); 236.467 - printDebug(" gPS:: part: binary ==> Length " + partArray.length); 236.468 - 236.469 - if (debug) 236.470 - printHex(partArray,partArray.length); 236.471 - printDebug("\n"); 236.472 - 236.473 - return partArray; 236.474 - } 236.475 - 236.476 - public byte[] GenBinaryPolicyBuffer(byte[] chwPolicy, byte[] stePolicy, byte [] partMap, byte[] vlanMap, byte[] slotMap) 236.477 - { 236.478 - byte[] binBuffer; 236.479 - short chwSize =0; 236.480 - short steSize =0; 236.481 - int index = 0; 236.482 - 236.483 - /* Builds data structure acm_policy_buffer_t */ 236.484 - /* Get number of colorTypes */ 236.485 - if (null != chwPolicy) 236.486 - chwSize = (short) chwPolicy.length; 236.487 - 236.488 - if (null != stePolicy) 236.489 - steSize = (short) stePolicy.length; 236.490 - 236.491 - int totalDataSize = chwSize + steSize + resourceOffsetSz + 3 *(2 * u16Size); 236.492 - 236.493 - /* Add vlan and slot */ 236.494 - totalDataSize = totalDataSize +partMap.length + vlanMap.length + slotMap.length; 236.495 - binBuffer = new byte[binaryBufferHeaderSz +totalDataSize]; 236.496 - 236.497 - 236.498 - try { 236.499 - index = 0; 236.500 - /* fill in General Policy Version */ 236.501 - writeIntToStream(binBuffer, ACM_POLICY_VERSION, index); 236.502 - index += u32Size; 236.503 - 236.504 - /* Write magic */ 236.505 - writeIntToStream(binBuffer, ACM_MAGIC, index); 236.506 - index += u32Size; 236.507 - 236.508 - /* write len */ 236.509 - writeIntToStream(binBuffer, binBuffer.length, index); 236.510 - index += u32Size; 236.511 - 236.512 - } catch (IOException ee) { 236.513 - System.out.println(" GBPB:: got exception : " + ee); 236.514 - return null; 236.515 - } 236.516 - 236.517 - int offset, address; 236.518 - address = index; 236.519 - 236.520 - if (null != partMap) 236.521 - offset = binaryBufferHeaderSz + resourceOffsetSz; 236.522 - else 236.523 - offset = binaryBufferHeaderSz; 236.524 - 236.525 - try { 236.526 - int skip = 0; 236.527 - 236.528 - /* init with NULL policy setting */ 236.529 - writeIntToStream(binBuffer, ACM_NULL_POLICY, index); 236.530 - writeIntToStream(binBuffer, 0, index + u32Size); 236.531 - writeIntToStream(binBuffer, ACM_NULL_POLICY, index + 2*u32Size); 236.532 - writeIntToStream(binBuffer, 0, index + 3*u32Size); 236.533 - 236.534 - index = address; 236.535 - if (null != chwPolicy) { 236.536 - 236.537 - /* Write policy name */ 236.538 - writeIntToStream(binBuffer, ACM_CHINESE_WALL_POLICY, index); 236.539 - index += u32Size; 236.540 - 236.541 - /* Write offset */ 236.542 - writeIntToStream(binBuffer, offset, index); 236.543 - index += u32Size; 236.544 - 236.545 - /* Write payload. No need increment index */ 236.546 - address = offset; 236.547 - System.arraycopy(chwPolicy, 0, binBuffer,address, chwPolicy.length); 236.548 - address = address + chwPolicy.length; 236.549 - } else 236.550 - skip += 2*u32Size; 236.551 - 236.552 - if (null != stePolicy) 236.553 - { 236.554 - /* Write policy name */ 236.555 - writeIntToStream(binBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index); 236.556 - index += u32Size; 236.557 - 236.558 - /* Write offset */ 236.559 - writeIntToStream(binBuffer, address, index); 236.560 - index += u32Size; 236.561 - 236.562 - /* Copy array */ 236.563 - System.arraycopy(stePolicy, 0, binBuffer,address, stePolicy.length); 236.564 - /* Update address */ 236.565 - address = address + stePolicy.length; 236.566 - } else 236.567 - skip += 2*u32Size; 236.568 - 236.569 - /* Skip writing policy name and offset for each null policy*/ 236.570 - index += skip; 236.571 - 236.572 - int size; 236.573 - /* Assumes that you will always have a partition defined in policy */ 236.574 - if ( 0 < partMap.length) { 236.575 - writeIntToStream(binBuffer, address, index); 236.576 - index = address; 236.577 - 236.578 - /* Compute num of VMs */ 236.579 - size = partMap.length / (3 * u16Size); 236.580 - 236.581 - writeShortToStream(binBuffer, (short)size,index); 236.582 - index = index + u16Size; 236.583 - 236.584 - /* part, vlan and slot: each one consists of two entries */ 236.585 - offset = 3 * (2 * u16Size); 236.586 - writeShortToStream(binBuffer, (short) offset,index); 236.587 - 236.588 - /* Write partition array at offset */ 236.589 - System.arraycopy(partMap, 0, binBuffer,(offset + address), partMap.length); 236.590 - index = index + u16Size; 236.591 - offset = offset + partMap.length; 236.592 - } 236.593 - 236.594 - if ( 0 < vlanMap.length) { 236.595 - size = vlanMap.length / (2 * u16Size); 236.596 - writeShortToStream(binBuffer, (short) size,index); 236.597 - index = index + u16Size; 236.598 - 236.599 - writeShortToStream(binBuffer, (short) offset,index); 236.600 - index = index + u16Size; 236.601 - System.arraycopy(vlanMap, 0, binBuffer,(offset + address), vlanMap.length); 236.602 - } else { 236.603 - /* Write vlan max */ 236.604 - writeShortToStream(binBuffer, (short) 0,index); 236.605 - index = index + u16Size; 236.606 - 236.607 - /* Write vlan offset */ 236.608 - writeShortToStream(binBuffer, (short) 0,index); 236.609 - index = index + u16Size; 236.610 - } 236.611 - 236.612 - offset = offset + vlanMap.length; 236.613 - if ( 0 < slotMap.length) { 236.614 - size = slotMap.length / (3 * u16Size); 236.615 - writeShortToStream(binBuffer, (short) size,index); 236.616 - index = index + u16Size; 236.617 - 236.618 - writeShortToStream(binBuffer, (short) offset,index); 236.619 - index = index + u16Size; 236.620 - System.arraycopy(slotMap, 0, binBuffer,(offset + address), slotMap.length); 236.621 - } 236.622 - } catch (IOException ee) { 236.623 - System.out.println(" GBPB:: got exception : " + ee); 236.624 - return null; 236.625 - } 236.626 - 236.627 - printDebug(" GBP:: Binary Policy ==> length " + binBuffer.length); 236.628 - if (debug) 236.629 - printHex(binBuffer,binBuffer.length); 236.630 - 236.631 - return binBuffer; 236.632 - } 236.633 - 236.634 - public byte[] generateChwBuffer(Vector Ssids, Vector ConflictSsids, Vector ColorTypes) 236.635 - { 236.636 - byte[] chwBuffer; 236.637 - int index = 0; 236.638 - int position = 0; 236.639 - 236.640 - /* Get number of rTypes */ 236.641 - int maxTypes = ColorTypes.size(); 236.642 - 236.643 - /* Get number of SSids entry */ 236.644 - int maxSsids = Ssids.size(); 236.645 - 236.646 - /* Get number of conflict sets */ 236.647 - int maxConflict = ConflictSsids.size(); 236.648 - 236.649 - 236.650 - if (maxTypes * maxSsids == 0) 236.651 - return null; 236.652 - /* 236.653 - data structure acm_chwall_policy_buffer 236.654 - se XmlToBinInterface.java 236.655 - */ 236.656 - int totalBytes = chwHeaderSize + u16Size *(maxTypes * (maxSsids + maxConflict)); 236.657 - 236.658 - chwBuffer = new byte[ totalBytes ]; 236.659 - int address = chwHeaderSize + (u16Size * maxTypes * maxSsids ); 236.660 - 236.661 - printDebug(" gCB:: chwall totalbytes : "+totalBytes); 236.662 - 236.663 - try { 236.664 - index = 0; 236.665 - /* fill in General Policy Version */ 236.666 - writeIntToStream(chwBuffer, ACM_CHWALL_VERSION, index); 236.667 - index += u32Size; 236.668 - 236.669 - writeIntToStream(chwBuffer, ACM_CHINESE_WALL_POLICY, index); 236.670 - index += u32Size; 236.671 - 236.672 - writeIntToStream(chwBuffer, maxTypes, index); 236.673 - index += u32Size; 236.674 - 236.675 - writeIntToStream(chwBuffer, maxSsids, index); 236.676 - index += u32Size; 236.677 - 236.678 - writeIntToStream(chwBuffer, maxConflict, index); 236.679 - index += u32Size; 236.680 - 236.681 - /* Write chwall_ssid_offset */ 236.682 - writeIntToStream(chwBuffer, chwHeaderSize, index); 236.683 - index += u32Size; 236.684 - 236.685 - /* Write chwall_conflict_sets_offset */ 236.686 - writeIntToStream(chwBuffer, address, index); 236.687 - index += u32Size; 236.688 - 236.689 - /* Write chwall_running_types_offset */ 236.690 - writeIntToStream(chwBuffer, 0, index); 236.691 - index += u32Size; 236.692 - 236.693 - /* Write chwall_conflict_aggregate_offset */ 236.694 - writeIntToStream(chwBuffer, 0, index); 236.695 - index += u32Size; 236.696 - 236.697 - } catch (IOException ee) { 236.698 - System.out.println(" gCB:: got exception : " + ee); 236.699 - return null; 236.700 - } 236.701 - int markPos = 0; 236.702 - 236.703 - /* Create the SSids entry */ 236.704 - for (int i = 0; i < maxSsids; i++) 236.705 - { 236.706 - SecurityLabel ssidEntry = (SecurityLabel) Ssids.elementAt(i); 236.707 - /* Get chwall types */ 236.708 - ssidEntry.chwSsidPosition = i; 236.709 - Enumeration e = ssidEntry.chwTypes.elements(); 236.710 - while (e.hasMoreElements()) 236.711 - { 236.712 - String typeName = (String) e.nextElement(); 236.713 - printDebug(" gCB:: Ssid "+ i+ ": has type : " + typeName); 236.714 - position = ColorTypes.indexOf(typeName); 236.715 - 236.716 - if (position < 0) 236.717 - { 236.718 - System.out.println (" gCB:: Error type : " + typeName + " not found in ColorTypes"); 236.719 - return null; 236.720 - } 236.721 - printDebug(" GCB:: type : " + typeName + " found in ColorTypes at position: " + position); 236.722 - markPos = ((i * maxTypes + position) * u16Size) + index; 236.723 - 236.724 - try { 236.725 - writeShortToStream(chwBuffer,markSymbol,markPos); 236.726 - } catch (IOException ee) { 236.727 - System.out.println(" gCB:: got exception : "); 236.728 - return null; 236.729 - } 236.730 - } 236.731 - } 236.732 - 236.733 - if (debug) 236.734 - printHex(chwBuffer,chwBuffer.length); 236.735 - 236.736 - /* Add conflict set */ 236.737 - index = address; 236.738 - for (int i = 0; i < maxConflict; i++) 236.739 - { 236.740 - /* Get ste types */ 236.741 - Vector entry = (Vector) ConflictSsids.elementAt(i); 236.742 - Enumeration e = entry.elements(); 236.743 - while (e.hasMoreElements()) 236.744 - { 236.745 - String typeName = (String) e.nextElement(); 236.746 - printDebug (" GCB:: conflict Ssid "+ i+ ": has type : " + typeName); 236.747 - position = ColorTypes.indexOf(typeName); 236.748 - 236.749 - if (position < 0) 236.750 - { 236.751 - System.out.println (" GCB:: Error type : " + typeName + " not found in ColorTypes"); 236.752 - return null; 236.753 - } 236.754 - printDebug(" GCB:: type : " + typeName + " found in ColorTypes at position: " + position); 236.755 - markPos = ((i * maxTypes + position) * u16Size) + index; 236.756 - 236.757 - try { 236.758 - writeShortToStream(chwBuffer,markSymbol,markPos); 236.759 - } catch (IOException ee) { 236.760 - System.out.println(" GCB:: got exception : "); 236.761 - return null; 236.762 - } 236.763 - } 236.764 - 236.765 - } 236.766 - printDebug(" gSB:: chw binary ==> Length " + chwBuffer.length); 236.767 - if (debug) 236.768 - printHex(chwBuffer,chwBuffer.length); 236.769 - printDebug("\n"); 236.770 - 236.771 - return chwBuffer; 236.772 - } 236.773 - 236.774 -/********************************************************************** 236.775 - Generate byte representation of policy using type information 236.776 - <p> 236.777 - @param Ssids Vector 236.778 - @param ColorTypes Vector 236.779 - <p> 236.780 - @return bytes represenation of simple type enforcement policy 236.781 -**********************************************************************/ 236.782 - public byte[] generateSteBuffer(Vector Ssids, Vector ColorTypes) 236.783 - { 236.784 - byte[] steBuffer; 236.785 - int index = 0; 236.786 - int position = 0; 236.787 - 236.788 - /* Get number of colorTypes */ 236.789 - int numColorTypes = ColorTypes.size(); 236.790 - 236.791 - /* Get number of SSids entry */ 236.792 - int numSsids = Ssids.size(); 236.793 - 236.794 - if (numColorTypes * numSsids == 0) 236.795 - return null; 236.796 - 236.797 - /* data structure: acm_ste_policy_buffer 236.798 - * see XmlToBinInterface.java 236.799 - * total bytes: steHeaderSize * 2B + colorTypes(size) * Ssids(size) 236.800 - * 236.801 - */ 236.802 - steBuffer = new byte[ steHeaderSize + (numColorTypes * numSsids) * 2]; 236.803 - 236.804 - try { 236.805 - 236.806 - index = 0; 236.807 - writeIntToStream(steBuffer, ACM_STE_VERSION, index); 236.808 - index += u32Size; 236.809 - 236.810 - writeIntToStream(steBuffer, ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, index); 236.811 - index += u32Size; 236.812 - 236.813 - writeIntToStream(steBuffer, numColorTypes, index); 236.814 - index += u32Size; 236.815 - 236.816 - writeIntToStream(steBuffer, numSsids, index); 236.817 - index += u32Size; 236.818 - 236.819 - writeIntToStream(steBuffer, steHeaderSize, index); 236.820 - index += u32Size; 236.821 - 236.822 - 236.823 - } catch (IOException ee) { 236.824 - System.out.println(" gSB:: got exception : " + ee); 236.825 - return null; 236.826 - } 236.827 - int markPos = 0; 236.828 - for (int i = 0; i < numSsids; i++) 236.829 - { 236.830 - 236.831 - SecurityLabel ssidEntry = (SecurityLabel) Ssids.elementAt(i); 236.832 - ssidEntry.steSsidPosition = i; 236.833 - /* Get ste types */ 236.834 - Enumeration e = ssidEntry.steTypes.elements(); 236.835 - while (e.hasMoreElements()) 236.836 - { 236.837 - String typeName = (String) e.nextElement(); 236.838 - printDebug (" gSB:: Ssid "+ i+ ": has type : " + typeName); 236.839 - position = ColorTypes.indexOf(typeName); 236.840 - 236.841 - if (position < 0) 236.842 - { 236.843 - printDebug(" gSB:: Error type : " + typeName + " not found in ColorTypes"); 236.844 - return null; 236.845 - } 236.846 - printDebug(" gSB:: type : " + typeName + " found in ColorTypes at position: " + position); 236.847 - markPos = ((i * numColorTypes + position) * u16Size) + index; 236.848 - 236.849 - try { 236.850 - writeShortToStream(steBuffer,markSymbol,markPos); 236.851 - } catch (IOException ee) 236.852 - { 236.853 - System.out.println(" gSB:: got exception : "); 236.854 - return null; 236.855 - } 236.856 - } 236.857 - 236.858 - } 236.859 - 236.860 - printDebug(" gSB:: ste binary ==> Length " + steBuffer.length); 236.861 - if (debug) 236.862 - printHex(steBuffer,steBuffer.length); 236.863 - printDebug("\n"); 236.864 - 236.865 - return steBuffer; 236.866 - } 236.867 - 236.868 - public static void printHex(byte [] dataArray, int length) 236.869 - { 236.870 - char[] hexChars = {'0', '1', '2', '3', '4', '5', '6', '7', 236.871 - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; 236.872 - int hexIndex; 236.873 - int value; 236.874 - int arraylength; 236.875 - 236.876 - arraylength = length; 236.877 - 236.878 - if (dataArray == null) 236.879 - { 236.880 - System.err.print("printHex: input byte array is null"); 236.881 - } 236.882 - 236.883 - if (length > dataArray.length || length < 0) 236.884 - arraylength = dataArray.length; 236.885 - 236.886 - System.out.print("\n\t"); 236.887 - 236.888 - int i; 236.889 - for(i = 0; i < arraylength; ) 236.890 - { 236.891 - value = dataArray[i] & 0xFF; 236.892 - hexIndex = (value >>> 4); 236.893 - System.out.print(hexChars[hexIndex]); 236.894 - hexIndex = (value & 0x0F); 236.895 - System.out.print(hexChars[hexIndex]); 236.896 - 236.897 - i++; 236.898 - /* if done, print a final newline */ 236.899 - if (i == arraylength) { 236.900 - if (arraylength < dataArray.length) { 236.901 - System.out.print("..."); 236.902 - } 236.903 - System.out.println(); 236.904 - } 236.905 - else if ((i % 24) == 0) { 236.906 - System.out.print("\n\t"); 236.907 - } 236.908 - else if ((i % 4) == 0) { 236.909 - System.out.print(" "); 236.910 - } 236.911 - } 236.912 - 236.913 - return; 236.914 - } 236.915 - 236.916 - 236.917 - private void writeShortToStream(byte[] stream, short value, int index) 236.918 - throws IOException 236.919 - { 236.920 - int littleEndian = 0; 236.921 - int byteVal; 236.922 - 236.923 - if (index + 2 > stream.length) 236.924 - { 236.925 - throw new IOException("Writing beyond stream length: " + 236.926 - stream.length + " writing at locations from: " + index + " to " + (index + 4)); 236.927 - } 236.928 - 236.929 - if (!LittleEndian) 236.930 - { 236.931 - 236.932 - byteVal = value >> 8; 236.933 - stream[index ] = (byte) byteVal; 236.934 - 236.935 - byteVal = value; 236.936 - stream[index + 1] = (byte) byteVal; 236.937 - } else { 236.938 - stream[index] = (byte) ((value & 0x00ff) ); 236.939 - stream[index + 1] = (byte) ((value & 0xff00) >> 8); 236.940 - } 236.941 - return; 236.942 - } 236.943 - 236.944 - private void writeIntToStream(byte[] stream, int value, int index) 236.945 - throws IOException 236.946 - { 236.947 - int littleEndian = 0; 236.948 - int byteVal; 236.949 - 236.950 - if (4 > stream.length) 236.951 - { 236.952 - throw new IOException("writeIntToStream: stream length less than 4 bytes " + 236.953 - stream.length); 236.954 - } 236.955 - 236.956 - /* Do not Write beyond range */ 236.957 - if (index + 4 > stream.length) 236.958 - { 236.959 - throw new IOException("writeIntToStream: writing beyond stream length: " + 236.960 - stream.length + " writing at locations from: " + index + " to " + (index + 4)); 236.961 - } 236.962 - if (!LittleEndian) 236.963 - { 236.964 - byteVal = value >>> 24; 236.965 - stream[index] = (byte) byteVal; 236.966 - 236.967 - byteVal = value >> 16; 236.968 - stream[index + 1] = (byte) byteVal; 236.969 - 236.970 - byteVal = value >> 8; 236.971 - stream[index + 2] = (byte) byteVal; 236.972 - 236.973 - byteVal = value; 236.974 - stream[index + 3] = (byte) byteVal; 236.975 - } else { 236.976 - stream[index] = (byte) value; 236.977 - stream[index + 1] = (byte) ((value & 0x0000ff00) >> 8); 236.978 - stream[index + 2] = (byte) ((value & 0x00ff0000) >> 16); 236.979 - stream[index + 3] = (byte) ( value >>> 24); 236.980 - } 236.981 - return; 236.982 - } 236.983 - 236.984 - public Document getDomTree(String xmlFileName) 236.985 - throws Exception, SAXException, ParserConfigurationException 236.986 - { 236.987 - javax.xml.parsers.DocumentBuilderFactory dbf = 236.988 - javax.xml.parsers.DocumentBuilderFactory.newInstance(); 236.989 - 236.990 - /* Turn on namespace aware and validation */ 236.991 - dbf.setNamespaceAware(true); 236.992 - dbf.setValidating(true); 236.993 - dbf.setAttribute(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA); 236.994 - 236.995 - /* Checks that the document is well-formed */ 236.996 - javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); 236.997 - 236.998 - myHandler errHandler= new myHandler(); 236.999 - db.setErrorHandler(errHandler); 236.1000 - Document doc = db.parse(xmlFileName); 236.1001 - 236.1002 - /* Checks for validation errors */ 236.1003 - if (errHandler.isValid) 236.1004 - printDebug(" gDT:: Xml file: " + xmlFileName + " is valid"); 236.1005 - else 236.1006 - throw new Exception("Xml file: " + xmlFileName + " is NOT valid"); 236.1007 - 236.1008 - return doc; 236.1009 - } 236.1010 - 236.1011 - public void processDomTree( 236.1012 - Document doc, 236.1013 - Vector bagOfSsids, 236.1014 - Vector bagOfTypes, 236.1015 - Vector bagOfChwSsids, 236.1016 - Vector bagOfChwTypes, 236.1017 - Vector bagOfConflictSsids) 236.1018 - throws Exception, SAXException, ParserConfigurationException 236.1019 - { 236.1020 - boolean found; 236.1021 - 236.1022 - /* print the root Element */ 236.1023 - Element root = doc.getDocumentElement(); 236.1024 - printDebug ("\n pDT:: Document Element: Name = " + root.getNodeName() + ",Value = " + root.getNodeValue()); 236.1025 - 236.1026 - /* Go through the list of the root Element's Attributes */ 236.1027 - NamedNodeMap nnm = root.getAttributes(); 236.1028 - printDebug (" pDT:: # of Attributes: " + nnm.getLength()); 236.1029 - for (int i = 0; i < nnm.getLength(); i++) 236.1030 - { 236.1031 - Node n = nnm.item (i); 236.1032 - printDebug (" pDT:: Attribute: Name = " + n.getNodeName() + ", Value = " 236.1033 - + n.getNodeValue()); 236.1034 - } 236.1035 - 236.1036 - /* Retrieve the policy definition */ 236.1037 - NodeList elementList = root.getElementsByTagName ("url"); 236.1038 - String definitionFileName = elementList.item(0).getFirstChild().getNodeValue(); 236.1039 - 236.1040 - String definitionHash = null; 236.1041 - 236.1042 - /* Note that SecurityPolicySpec.xsd allows for 0 hash value! */ 236.1043 - elementList = root.getElementsByTagName ("hash"); 236.1044 - if (0 != elementList.getLength()) 236.1045 - definitionHash = elementList.item(0).getFirstChild().getNodeValue(); 236.1046 - 236.1047 - Document definitionDoc = pGetDomDefinition(definitionFileName,definitionHash); 236.1048 - pGetTypes(definitionDoc,bagOfTypes, bagOfChwTypes, bagOfConflictSsids); 236.1049 - 236.1050 - 236.1051 - /* Get VM security information */ 236.1052 - elementList = root.getElementsByTagName ("VM"); 236.1053 - printDebug ("\n pDT:: partition length of NodeList:" + elementList.getLength()); 236.1054 - /* Add default Ssid to Ste and Chw bags */ 236.1055 - SecurityLabel defEntry = new SecurityLabel(); 236.1056 - 236.1057 - defEntry.chwTypes = new Vector(); 236.1058 - defEntry.steTypes = new Vector(); 236.1059 - defEntry.chwIDs = new Vector(); 236.1060 - defEntry.ids = new Vector(); 236.1061 - 236.1062 - defEntry.steSsidPosition =0; 236.1063 - defEntry.chwSsidPosition =0; 236.1064 - bagOfChwSsids.add(defEntry); 236.1065 - bagOfSsids.add(defEntry); 236.1066 - 236.1067 - for (int x = 0; x < elementList.getLength(); x++) 236.1068 - { 236.1069 - found = false; 236.1070 - 236.1071 - Node node = elementList.item (x); 236.1072 - 236.1073 - if (node.getNodeType() == Node.ELEMENT_NODE) 236.1074 - { 236.1075 - printDebug (" pDT:: child: " + x + " is an element node" ); 236.1076 - Element e1 = (Element) node; 236.1077 - 236.1078 - /* Get id */ 236.1079 - NodeList elist = e1.getElementsByTagName ("id"); 236.1080 - String idStr = elist.item(0).getFirstChild().getNodeValue(); 236.1081 - printDebug (" pDT:: id:" + idStr); 236.1082 - 236.1083 - /* Get TE */ 236.1084 - Vector colorTypes = new Vector(); 236.1085 - pConflictEntries(e1, "TE", bagOfTypes, colorTypes); 236.1086 - 236.1087 - Enumeration e = bagOfSsids.elements(); 236.1088 - while (e.hasMoreElements()) 236.1089 - { 236.1090 - SecurityLabel elem = (SecurityLabel) e.nextElement(); 236.1091 - if ( elem.steTypes.size() == colorTypes.size() && elem.steTypes.containsAll(colorTypes)) 236.1092 - { 236.1093 - found = true; 236.1094 - elem.ids.add(idStr); 236.1095 - } 236.1096 - 236.1097 - } 236.1098 - if (!found && (0 < colorTypes.size())) 236.1099 - { 236.1100 - SecurityLabel entry = new SecurityLabel(); 236.1101 - entry.steTypes = colorTypes; 236.1102 - entry.ids = new Vector(); 236.1103 - entry.ids.add(idStr); 236.1104 - bagOfSsids.add(entry); 236.1105 - } 236.1106 - 236.1107 - /* Get Chinese wall type */ 236.1108 - Vector chwTypes = new Vector(); 236.1109 - pConflictEntries(e1, "ChWall", bagOfChwTypes, chwTypes); 236.1110 - 236.1111 - found = false; 236.1112 - e = bagOfChwSsids.elements(); 236.1113 - 236.1114 - while (e.hasMoreElements()) 236.1115 - { 236.1116 - SecurityLabel elem = (SecurityLabel) e.nextElement(); 236.1117 - if ( elem.chwTypes.size() == chwTypes.size() && elem.chwTypes.containsAll(chwTypes)) 236.1118 - { 236.1119 - found = true; 236.1120 - elem.chwIDs.add(idStr); 236.1121 - } 236.1122 - 236.1123 - } 236.1124 - 236.1125 - if (!found && (0 < chwTypes.size())) 236.1126 - { 236.1127 - SecurityLabel entry = new SecurityLabel(); 236.1128 - entry.chwTypes = chwTypes; 236.1129 - entry.chwIDs = new Vector(); 236.1130 - entry.chwIDs.add(idStr); 236.1131 - bagOfChwSsids.add(entry); 236.1132 - } 236.1133 - } 236.1134 - } 236.1135 - return; 236.1136 - } 236.1137 - 236.1138 - public Document pGetDomDefinition( 236.1139 - String definitionFileName, 236.1140 - String definitionHash) 236.1141 - throws Exception, SAXException, ParserConfigurationException 236.1142 - { 236.1143 - printDebug("\n pGDD:: definition file name: " + definitionFileName); 236.1144 - printDebug("\n pGDD:: definition file hash: " + definitionHash); 236.1145 - 236.1146 - Document doc = getDomTree(definitionFileName); 236.1147 - return doc; 236.1148 - } 236.1149 - 236.1150 - public void pGetTypes( 236.1151 - Document defDoc, 236.1152 - Vector bagOfTypes, 236.1153 - Vector bagOfChwTypes, 236.1154 - Vector bagOfConflictSsids) 236.1155 - throws Exception 236.1156 - { 236.1157 - 236.1158 - 236.1159 - if (null == defDoc) 236.1160 - throw new Exception(" pGT:: definition file DOM is null "); 236.1161 - 236.1162 - Element root = defDoc.getDocumentElement(); 236.1163 - 236.1164 - /* Get list of TE types */ 236.1165 - NodeList elementList = root.getElementsByTagName ("Types"); 236.1166 - printDebug ("\n pGT:: Types length of NodeList:" + elementList.getLength()); 236.1167 - Element e1 = (Element) elementList.item (0); 236.1168 - pGetEntries(e1,"TE",bagOfTypes); 236.1169 - 236.1170 - /* Get list of Chinese types */ 236.1171 - elementList = root.getElementsByTagName ("ChWallTypes"); 236.1172 - printDebug ("\n pGT:: ChwTypes length of NodeList:" + elementList.getLength()); 236.1173 - if (0 == elementList.getLength()) 236.1174 - { 236.1175 - printDebug ("\n pGT:: ChWallTypes has zero length: :" + elementList.getLength()); 236.1176 - } else { 236.1177 - e1 = (Element) elementList.item (0); 236.1178 - pGetEntries(e1,"ChWall",bagOfChwTypes); 236.1179 - } 236.1180 - printDebug (" pGT:: Total number of unique chw types: " + bagOfChwTypes.size()); 236.1181 - 236.1182 - /* Get Chinese type conflict sets */ 236.1183 - elementList = root.getElementsByTagName ("ConflictSet"); 236.1184 - printDebug ("\n pGT:: Conflict sets length of NodeList:" + elementList.getLength()); 236.1185 - for (int x = 0; x < elementList.getLength(); x++) 236.1186 - { 236.1187 - Vector conflictEntry = new Vector(); 236.1188 - e1 = (Element) elementList.item (x); 236.1189 - printDebug ("\n pGT:: Conflict sets : " + x); 236.1190 - 236.1191 - pConflictEntries(e1, "ChWall", bagOfChwTypes, conflictEntry); 236.1192 - 236.1193 - if (conflictEntry.size() > 0) 236.1194 - { 236.1195 - boolean found = false; 236.1196 - Enumeration e = bagOfConflictSsids.elements(); 236.1197 - 236.1198 - while (e.hasMoreElements()) 236.1199 - { 236.1200 - Vector elem = (Vector) e.nextElement(); 236.1201 - if (elem.size() == conflictEntry.size() && elem.containsAll(conflictEntry)) 236.1202 - { 236.1203 - found = true; 236.1204 - } 236.1205 - 236.1206 - } 236.1207 - if (!found) 236.1208 - { 236.1209 - bagOfConflictSsids.add(conflictEntry); 236.1210 - } 236.1211 - } 236.1212 - } 236.1213 - 236.1214 - } 236.1215 - 236.1216 - public void pGetEntries(Element doc, String tag, Vector typeBag) 236.1217 - throws Exception 236.1218 - { 236.1219 - 236.1220 - if (null == doc) 236.1221 - throw new Exception(" pGE:: Element doc is null"); 236.1222 - 236.1223 - if (null == typeBag) 236.1224 - throw new Exception(" pGE:: typeBag is null"); 236.1225 - 236.1226 - NodeList elist = doc.getElementsByTagName (tag); 236.1227 - for (int j = 0; j < elist.getLength(); j++) 236.1228 - { 236.1229 - Node knode = elist.item (j); 236.1230 - Node childNode = knode.getFirstChild(); 236.1231 - String value = childNode.getNodeValue(); 236.1232 - 236.1233 - printDebug (" pGT:: "+ tag +" type: " + value); 236.1234 - 236.1235 - /* Check if value is known */ 236.1236 - if (!typeBag.contains(value)) 236.1237 - typeBag.addElement(value); 236.1238 - } 236.1239 - } 236.1240 - 236.1241 - public void pConflictEntries(Element doc, String tag, Vector typeBag, Vector conflictEntry) 236.1242 - throws Exception 236.1243 - { 236.1244 - 236.1245 - if (null == doc) 236.1246 - throw new Exception(" pGE:: Element doc is null"); 236.1247 - 236.1248 - if (null == typeBag) 236.1249 - throw new Exception(" pGE:: typeBag is null"); 236.1250 - 236.1251 - if (null == conflictEntry) 236.1252 - throw new Exception(" pGE:: typeBag is null"); 236.1253 - 236.1254 - 236.1255 - NodeList elist = doc.getElementsByTagName (tag); 236.1256 - 236.1257 - for (int j = 0; j < elist.getLength(); j++) 236.1258 - { 236.1259 - Node knode = elist.item (j); 236.1260 - Node childNode = knode.getFirstChild(); 236.1261 - String value = childNode.getNodeValue(); 236.1262 - 236.1263 - printDebug (" pGE:: "+ tag +" type: " + value); 236.1264 - 236.1265 - /* Check if value is known */ 236.1266 - if (!typeBag.contains(value)) 236.1267 - throw new Exception(" pCE:: found undefined type set " + value); 236.1268 - 236.1269 - if (!conflictEntry.contains(value)) 236.1270 - conflictEntry.addElement(value); 236.1271 - 236.1272 - } 236.1273 - } 236.1274 - 236.1275 - public void processDomTreeVlanSlot( 236.1276 - Document doc, 236.1277 - Vector bagOfSsids, 236.1278 - Vector bagOfTypes) 236.1279 - throws Exception 236.1280 - { 236.1281 - boolean found; 236.1282 - 236.1283 - printDebug(" pDTVS::Size of bagOfSsids: "+ bagOfSsids.size()); 236.1284 - Element root = doc.getDocumentElement(); 236.1285 - 236.1286 - NodeList elementList = root.getElementsByTagName ("Vlan"); 236.1287 - printDebug("\n pDTVS:: Vlan length of NodeList:" + elementList.getLength()); 236.1288 - 236.1289 - for (int x = 0; x < elementList.getLength(); x++) 236.1290 - { 236.1291 - found = false; 236.1292 - 236.1293 - Node node = elementList.item (x); 236.1294 - 236.1295 - if (node.getNodeType() == Node.ELEMENT_NODE) 236.1296 - { 236.1297 - printDebug(" pDTVS:: child: " + x + " is an element node" ); 236.1298 - Element e1 = (Element) node; 236.1299 - 236.1300 - /* Get vid */ 236.1301 - NodeList elist = e1.getElementsByTagName ("vid"); 236.1302 - String idStr = elist.item(0).getFirstChild().getNodeValue(); 236.1303 - printDebug (" pDTVS:: vid:" + idStr); 236.1304 - 236.1305 - /* Get TE */ 236.1306 - elist = e1.getElementsByTagName ("TE"); 236.1307 - printDebug (" pDTVS:: Total ste types: " + elist.getLength()); 236.1308 - 236.1309 - Vector colorTypes = new Vector(); 236.1310 - for (int j = 0; j < elist.getLength(); j++) 236.1311 - { 236.1312 - Node knode = elist.item (j); 236.1313 - Node childNode = knode.getFirstChild(); 236.1314 - String value = childNode.getNodeValue(); 236.1315 - 236.1316 - printDebug (" pDT:: My color is: " + value); 236.1317 - if (!bagOfTypes.contains(value)) 236.1318 - { 236.1319 - throw new IOException("pDT:: Vlan: " + idStr+ " has unknown type : "+ value); 236.1320 - } 236.1321 - 236.1322 - if (!colorTypes.contains(value)) 236.1323 - colorTypes.addElement(value); 236.1324 - } 236.1325 - Enumeration e = bagOfSsids.elements(); 236.1326 - while (e.hasMoreElements()) 236.1327 - { 236.1328 - SecurityLabel elem = (SecurityLabel) e.nextElement(); 236.1329 - if ( elem.steTypes.size() == colorTypes.size() && elem.steTypes.containsAll(colorTypes)) 236.1330 - { 236.1331 - found = true; 236.1332 - if (null == elem.vlans) 236.1333 - elem.vlans = new Vector(); 236.1334 - elem.vlans.add(idStr); 236.1335 - } 236.1336 - 236.1337 - } 236.1338 - if (!found && (0 < colorTypes.size())) 236.1339 - { 236.1340 - SecurityLabel entry = new SecurityLabel(); 236.1341 - entry.steTypes = colorTypes; 236.1342 - entry.vlans = new Vector(); 236.1343 - entry.vlans.add(idStr); 236.1344 - bagOfSsids.add(entry); 236.1345 - } 236.1346 - 236.1347 - } 236.1348 - } 236.1349 - printDebug(" pDTVS::After slot Size of bagOfSsids: "+ bagOfSsids.size()); 236.1350 - 236.1351 - elementList = root.getElementsByTagName ("Slot"); 236.1352 - printDebug ("\n pDTVS:: Slot length of NodeList:" + elementList.getLength()); 236.1353 - 236.1354 - for (int x = 0; x < elementList.getLength(); x++) 236.1355 - { 236.1356 - found = false; 236.1357 - 236.1358 - Node node = elementList.item (x); 236.1359 - 236.1360 - if (node.getNodeType() == Node.ELEMENT_NODE) 236.1361 - { 236.1362 - printDebug(" pDT:: child: " + x + " is an element node" ); 236.1363 - Element e1 = (Element) node; 236.1364 - 236.1365 - 236.1366 - /* Get slot and bus */ 236.1367 - SlotInfo item = new SlotInfo(); 236.1368 - 236.1369 - NodeList elist = e1.getElementsByTagName ("bus"); 236.1370 - item.bus = elist.item(0).getFirstChild().getNodeValue(); 236.1371 - elist = e1.getElementsByTagName ("slot"); 236.1372 - item.slot = elist.item(0).getFirstChild().getNodeValue(); 236.1373 - printDebug (" pDT:: bus and slot:" + item.bus + " "+ item.slot); 236.1374 - 236.1375 - /* Get TE */ 236.1376 - elist = e1.getElementsByTagName ("TE"); 236.1377 - printDebug (" pDT:: Total ste types: " + elist.getLength()); 236.1378 - 236.1379 - Vector colorTypes = new Vector(); 236.1380 - for (int j = 0; j < elist.getLength(); j++) 236.1381 - { 236.1382 - Node knode = elist.item (j); 236.1383 - Node childNode = knode.getFirstChild(); 236.1384 - String value = childNode.getNodeValue(); 236.1385 - 236.1386 - printDebug (" pDT:: My color is: " + value); 236.1387 - if (!bagOfTypes.contains(value)) 236.1388 - { 236.1389 - throw new IOException("pDT:: bus: " + item.bus + " slot: "+ item.slot + " has unknown type : "+ value); 236.1390 - } 236.1391 - 236.1392 - if (!colorTypes.contains(value)) 236.1393 - colorTypes.addElement(value); 236.1394 - } 236.1395 - 236.1396 - Enumeration e = bagOfSsids.elements(); 236.1397 - while (e.hasMoreElements()) 236.1398 - { 236.1399 - SecurityLabel elem = (SecurityLabel) e.nextElement(); 236.1400 - if ( elem.steTypes.size() == colorTypes.size() && elem.steTypes.containsAll(colorTypes)) 236.1401 - { 236.1402 - found = true; 236.1403 - if (null == elem.slots) 236.1404 - elem.slots = new Vector(); 236.1405 - elem.slots.add(item); 236.1406 - 236.1407 - } 236.1408 - 236.1409 - } 236.1410 - 236.1411 - if (!found && (0 < colorTypes.size())) 236.1412 - { 236.1413 - SecurityLabel entry = new SecurityLabel(); 236.1414 - entry.steTypes = colorTypes; 236.1415 - entry.slots = new Vector(); 236.1416 - entry.slots.add(item); 236.1417 - bagOfSsids.add(entry); 236.1418 - } 236.1419 - 236.1420 - } 236.1421 - } 236.1422 - return; 236.1423 - } 236.1424 - 236.1425 - public static void main (String[] args) 236.1426 - { 236.1427 - String xmlFileName = null; /* policy file */ 236.1428 - String outputFileName = null; /* binary policy file */ 236.1429 - String xenSsidOutputFileName = null; /* outputfile ssid to named types */ 236.1430 - /* outputfile conflicts ssid to named types */ 236.1431 - String xenSsidConfOutputFileName = null; 236.1432 - 236.1433 - XmlToBin genObj = new XmlToBin(); 236.1434 - 236.1435 - policy_version active_policy = new policy_version(); 236.1436 - 236.1437 - if ((active_policy.ACM_POLICY_VERSION != ACM_POLICY_VERSION) || 236.1438 - (active_policy.ACM_CHWALL_VERSION != ACM_CHWALL_VERSION) || 236.1439 - (active_policy.ACM_STE_VERSION != ACM_STE_VERSION)) { 236.1440 - System.out.println("ACM policy versions differ."); 236.1441 - System.out.println("Please verify that data structures are correct"); 236.1442 - System.out.println("and then adjust the version numbers in XmlToBinInterface.java."); 236.1443 - return; 236.1444 - } 236.1445 - 236.1446 - 236.1447 - for (int i = 0 ; i < args.length ; i++) { 236.1448 - 236.1449 - if ( args[i].equals("-help")) { 236.1450 - printUsage(); 236.1451 - System.exit(1); 236.1452 - 236.1453 - } else if ( args[i].equals("-i")) { 236.1454 - i++; 236.1455 - if (i < args.length) { 236.1456 - xmlFileName = args[i]; 236.1457 - } else { 236.1458 - System.out.println("-i argument needs parameter"); 236.1459 - System.exit(1); 236.1460 - } 236.1461 - 236.1462 - } else if ( args[i].equals("-o")) { 236.1463 - i++; 236.1464 - if (i < args.length) { 236.1465 - outputFileName = args[i]; 236.1466 - } else { 236.1467 - System.out.println("-o argument needs parameter"); 236.1468 - System.exit(1); 236.1469 - } 236.1470 - 236.1471 - } else if ( args[i].equals("-xssid")) { 236.1472 - i++; 236.1473 - if (i < args.length) { 236.1474 - xenSsidOutputFileName = args[i]; 236.1475 - } else { 236.1476 - System.out.println("-xssid argument needs parameter"); 236.1477 - System.exit(1); 236.1478 - } 236.1479 - 236.1480 - } else if ( args[i].equals("-xssidconf")) { 236.1481 - i++; 236.1482 - if (i < args.length) { 236.1483 - xenSsidConfOutputFileName = args[i]; 236.1484 - } else { 236.1485 - System.out.println("-xssidconf argument needs parameter"); 236.1486 - System.exit(1); 236.1487 - } 236.1488 - } else if ( args[i].equals("-debug")) { /* turn on debug msg */ 236.1489 - genObj.setDebug(true); 236.1490 - } else { 236.1491 - System.out.println("bad command line argument: " + args[i]); 236.1492 - printUsage(); 236.1493 - System.exit(1); 236.1494 - } 236.1495 - 236.1496 - } 236.1497 - 236.1498 - if (xmlFileName == null) 236.1499 - { 236.1500 - System.out.println("Need to specify input file -i option"); 236.1501 - printUsage(); 236.1502 - System.exit(1); 236.1503 - } 236.1504 - 236.1505 - 236.1506 - try 236.1507 - { 236.1508 - /* Parse and validate */ 236.1509 - Document doc = genObj.getDomTree(xmlFileName); 236.1510 - 236.1511 - /* Vectors to hold sets of types */ 236.1512 - Vector bagOfSsids = new Vector(); 236.1513 - Vector bagOfTypes = new Vector(); 236.1514 - Vector bagOfChwSsids = new Vector(); 236.1515 - Vector bagOfChwTypes = new Vector(); 236.1516 - Vector bagOfConflictSsids = new Vector(); 236.1517 - 236.1518 - Vector vlanMapSsids = new Vector(); 236.1519 - Vector slotMapSsids = new Vector(); 236.1520 - 236.1521 - genObj.processDomTree(doc, bagOfSsids, bagOfTypes, bagOfChwSsids, bagOfChwTypes, bagOfConflictSsids); 236.1522 - 236.1523 - genObj.processDomTreeVlanSlot(doc, bagOfSsids, bagOfTypes); 236.1524 - 236.1525 - /* Get binary representation of policies */ 236.1526 - byte[] stePolicy = genObj.generateSteBuffer(bagOfSsids, bagOfTypes); 236.1527 - byte[] chwPolicy = genObj.generateChwBuffer(bagOfChwSsids, bagOfConflictSsids,bagOfChwTypes); 236.1528 - 236.1529 - byte[] binPolicy = null; 236.1530 - byte[] binaryPartionSsid = null; 236.1531 - byte[] binaryVlanSsid = null; 236.1532 - byte[] binarySlotSsid = null; 236.1533 - 236.1534 - /* Get binary representation of partition to ssid mapping */ 236.1535 - binaryPartionSsid = genObj.generatePartSsids(bagOfSsids,bagOfChwSsids); 236.1536 - 236.1537 - /* Get binary representation of vlan to ssid mapping */ 236.1538 - binaryVlanSsid = genObj.generateVlanSsids(bagOfSsids); 236.1539 - 236.1540 - /* Get binary representation of slot to ssid mapping */ 236.1541 - binarySlotSsid = genObj.generateSlotSsids(bagOfSsids); 236.1542 - 236.1543 - /* Generate binary representation: policy, partition, slot and vlan */ 236.1544 - binPolicy = genObj.GenBinaryPolicyBuffer(chwPolicy,stePolicy, binaryPartionSsid, binaryVlanSsid, binarySlotSsid); 236.1545 - 236.1546 - 236.1547 - /* Write binary policy into file */ 236.1548 - if (null != outputFileName) 236.1549 - { 236.1550 - genObj.writeBinPolicy(binPolicy, outputFileName); 236.1551 - } else { 236.1552 - System.out.println (" No binary policy generated, outputFileName: " + outputFileName); 236.1553 - } 236.1554 - 236.1555 - /* Print total number of types */ 236.1556 - System.out.println (" Total number of unique ste types: " + bagOfTypes.size()); 236.1557 - System.out.println (" Total number of Ssids : " + bagOfSsids.size()); 236.1558 - System.out.println (" Total number of unique chw types: " + bagOfChwTypes.size()); 236.1559 - System.out.println (" Total number of conflict ssids : " + bagOfConflictSsids.size()); 236.1560 - System.out.println (" Total number of chw Ssids : " + bagOfChwSsids.size()); 236.1561 - 236.1562 - if (null != xenSsidOutputFileName) 236.1563 - genObj.writeXenTypeFile(bagOfSsids, xenSsidOutputFileName, true); 236.1564 - 236.1565 - if (null != xenSsidConfOutputFileName) 236.1566 - genObj.writeXenTypeFile(bagOfChwSsids, xenSsidConfOutputFileName, false); 236.1567 - } 236.1568 - catch (Exception e) 236.1569 - { 236.1570 - e.printStackTrace(); 236.1571 - } 236.1572 - } 236.1573 -}
237.1 --- a/tools/misc/policyprocessor/XmlToBinInterface.java Thu Aug 18 10:40:02 2005 -0800 237.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 237.3 @@ -1,138 +0,0 @@ 237.4 -/** 237.5 - * (C) Copyright IBM Corp. 2005 237.6 - * 237.7 - * $Id: XmlToBinInterface.java,v 1.3 2005/06/20 21:07:37 rvaldez Exp $ 237.8 - * 237.9 - * Author: Ray Valdez 237.10 - * 237.11 - * This program is free software; you can redistribute it and/or 237.12 - * modify it under the terms of the GNU General Public License as 237.13 - * published by the Free Software Foundation, version 2 of the 237.14 - * License. 237.15 - * 237.16 - * XmlToBinInterface Class. 237.17 - * <p> 237.18 - * 237.19 - * Defines constants used by XmToBin. 237.20 - * 237.21 - * <p> 237.22 - * 237.23 - * policy binary structures 237.24 - * 237.25 - * struct acm_policy_buffer { 237.26 - * u32 policy_version; * ACM_POLICY_VERSION * 237.27 - * u32 magic; 237.28 - * u32 len; 237.29 - * u32 primary_policy_code; 237.30 - * u32 primary_buffer_offset; 237.31 - * u32 secondary_policy_code; 237.32 - * u32 secondary_buffer_offset; 237.33 - * +u32 resource offset (not used yet in Xen) 237.34 - * }; 237.35 - * 237.36 - * 237.37 - * struct acm_ste_policy_buffer { 237.38 - * u32 policy_version; * ACM_STE_VERSION * 237.39 - * u32 policy_code; 237.40 - * u32 ste_max_types; 237.41 - * u32 ste_max_ssidrefs; 237.42 - * u32 ste_ssid_offset; 237.43 - * }; 237.44 - * 237.45 - * struct acm_chwall_policy_buffer { 237.46 - * u32 policy_version; * ACM_CHWALL_VERSION * 237.47 - * u32 policy_code; 237.48 - * u32 chwall_max_types; 237.49 - * u32 chwall_max_ssidrefs; 237.50 - * u32 chwall_max_conflictsets; 237.51 - * u32 chwall_ssid_offset; 237.52 - * u32 chwall_conflict_sets_offset; 237.53 - * u32 chwall_running_types_offset; 237.54 - * u32 chwall_conflict_aggregate_offset; 237.55 - * }; 237.56 - * 237.57 - * typedef struct { 237.58 - * u16 partition_max; 237.59 - * u16 partition_offset; 237.60 - * u16 vlan_max; 237.61 - * u16 vlan_offset; 237.62 - * u16 slot_max; 237.63 - * u16 slot_offset; 237.64 - * } acm_resource_buffer_t; 237.65 - * 237.66 - * typedef struct { 237.67 - * u16 id; 237.68 - * u16 ssid_ste; 237.69 - * u16 ssid_chwall; 237.70 - * } acm_partition_entry_t; 237.71 - * 237.72 - * typedef struct { 237.73 - * u16 vlan; 237.74 - * u16 ssid_ste; 237.75 - * } acm_vlan_entry_t; 237.76 - * 237.77 - * typedef struct { 237.78 - * u16 bus; 237.79 - * u16 slot; 237.80 - * u16 ssid_ste; 237.81 - * } acm_slot_entry_t; 237.82 - * 237.83 - * 237.84 - * 237.85 - */ 237.86 -public interface XmlToBinInterface 237.87 -{ 237.88 - /* policy code (uint16) */ 237.89 - final int policyCodeSize = 2; 237.90 - 237.91 - /* max_types (uint16) */ 237.92 - final int maxTypesSize = 2; 237.93 - 237.94 - /* max_ssidrefs (uint16) */ 237.95 - final int maxSsidrefSize = 2; 237.96 - 237.97 - /* ssid_offset (uint32) */ 237.98 - final int ssidOffsetSize = 2; 237.99 - 237.100 - final short markSymbol = 0x0001; 237.101 - 237.102 - final int u32Size = 4; 237.103 - final int u16Size = 2; 237.104 - 237.105 - /* num of bytes for acm_ste_policy_buffer_t */ 237.106 - final int steHeaderSize = (5 * u32Size); 237.107 - 237.108 - /* byte for acm_chinese_wall_policy_buffer_t */ 237.109 - final int chwHeaderSize = (9 * u32Size); 237.110 - 237.111 - final int primaryPolicyCodeSize = u32Size; 237.112 - final int primaryBufferOffsetSize = u32Size ; 237.113 - 237.114 - final int secondaryPolicyCodeSz = u32Size; 237.115 - final int secondaryBufferOffsetSz = u32Size; 237.116 - final int resourceOffsetSz = u32Size; 237.117 - 237.118 - final short partitionBufferSz = (2 * u16Size); 237.119 - final short partitionEntrySz = (3 * u16Size); 237.120 - 237.121 - final short slotBufferSz = (2 * u16Size); 237.122 - final short slotEntrySz = (3 * u16Size); 237.123 - 237.124 - final short vlanBufferSz = (2 * u16Size); 237.125 - final short vlanEntrySz = (2 * u16Size); 237.126 - 237.127 - final int binaryBufferHeaderSz = (8 * u32Size); /* 8th not used in Xen */ 237.128 - 237.129 - /* copied directly from acm.h */ 237.130 - final int ACM_MAGIC = 0x0001debc; 237.131 - final int ACM_NULL_POLICY = 0; 237.132 - final int ACM_CHINESE_WALL_POLICY = 1; 237.133 - final int ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY = 2; 237.134 - final int ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY = 3; 237.135 - final int ACM_EMPTY_POLICY = 4; 237.136 - 237.137 - /* version for compatibility check */ 237.138 - final int ACM_POLICY_VERSION = 1; 237.139 - final int ACM_STE_VERSION = 1; 237.140 - final int ACM_CHWALL_VERSION = 1; 237.141 -}
238.1 --- a/tools/misc/policyprocessor/c2j_include.c Thu Aug 18 10:40:02 2005 -0800 238.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 238.3 @@ -1,57 +0,0 @@ 238.4 -/**************************************************************** 238.5 - * c2j_include.c 238.6 - * 238.7 - * Copyright (C) 2005 IBM Corporation 238.8 - * 238.9 - * Authors: 238.10 - * Reiner Sailer <sailer@watson.ibm.com> 238.11 - * 238.12 - * This program is free software; you can redistribute it and/or 238.13 - * modify it under the terms of the GNU General Public License as 238.14 - * published by the Free Software Foundation, version 2 of the 238.15 - * License. 238.16 - * 238.17 - * This tool makes some constants from acm.h available to the 238.18 - * java policyprocessor for version checking. 238.19 - */ 238.20 -#include <stdio.h> 238.21 -#include <errno.h> 238.22 -#include <stdlib.h> 238.23 -#include <stdint.h> 238.24 - 238.25 -typedef uint8_t u8; 238.26 -typedef uint16_t u16; 238.27 -typedef uint32_t u32; 238.28 -typedef uint64_t u64; 238.29 -typedef int8_t s8; 238.30 -typedef int16_t s16; 238.31 -typedef int32_t s32; 238.32 -typedef int64_t s64; 238.33 - 238.34 -#include <xen/acm.h> 238.35 - 238.36 -char *filename = "policy_version.java"; 238.37 - 238.38 -int main(int argc, char **argv) 238.39 -{ 238.40 - 238.41 - FILE *fd; 238.42 - if ((fd = fopen(filename, "w")) <= 0) 238.43 - { 238.44 - printf("File %s not found.\n", filename); 238.45 - exit(-ENOENT); 238.46 - } 238.47 - 238.48 - fprintf(fd, "/*\n * This file was automatically generated\n"); 238.49 - fprintf(fd, " * Do not change it manually!\n */\n"); 238.50 - fprintf(fd, "public class policy_version {\n"); 238.51 - fprintf(fd, " final int ACM_POLICY_VERSION = %x;\n", 238.52 - ACM_POLICY_VERSION); 238.53 - fprintf(fd, " final int ACM_CHWALL_VERSION = %x;\n", 238.54 - ACM_CHWALL_VERSION); 238.55 - fprintf(fd, " final int ACM_STE_VERSION = %x;\n", 238.56 - ACM_STE_VERSION); 238.57 - fprintf(fd, "}\n"); 238.58 - fclose(fd); 238.59 - return 0; 238.60 -}
239.1 --- a/tools/misc/policyprocessor/myHandler.java Thu Aug 18 10:40:02 2005 -0800 239.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 239.3 @@ -1,47 +0,0 @@ 239.4 -/** 239.5 - * (C) Copyright IBM Corp. 2005 239.6 - * 239.7 - * $Id: myHandler.java,v 1.2 2005/06/17 20:00:04 rvaldez Exp $ 239.8 - * 239.9 - * Author: Ray Valdez 239.10 - * 239.11 - * This program is free software; you can redistribute it and/or 239.12 - * modify it under the terms of the GNU General Public License as 239.13 - * published by the Free Software Foundation, version 2 of the 239.14 - * License. 239.15 - * 239.16 - * myHandler Class. 239.17 - * 239.18 - * <p> 239.19 - * 239.20 - * A dummy class used for detecting XML validating/parsing errors. 239.21 - * 239.22 - * <p> 239.23 - * 239.24 - * 239.25 - */ 239.26 -import org.xml.sax.helpers.*; 239.27 -import org.xml.sax.SAXParseException; 239.28 - 239.29 -class myHandler extends DefaultHandler 239.30 -{ 239.31 - public boolean isValid = true; 239.32 - 239.33 - /* Notification of a recoverable error. */ 239.34 - public void error(SAXParseException se) 239.35 - { 239.36 - isValid = false; 239.37 - } 239.38 - 239.39 - /* Notification of a non-recoverable error. */ 239.40 - public void fatalError(SAXParseException se) 239.41 - { 239.42 - isValid = false; 239.43 - } 239.44 - 239.45 - /* Notification of a warning. */ 239.46 - public void warning(SAXParseException se) 239.47 - { 239.48 - isValid = false; 239.49 - } 239.50 -}
240.1 --- a/tools/misc/policyprocessor/readme.install Thu Aug 18 10:40:02 2005 -0800 240.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 240.3 @@ -1,33 +0,0 @@ 240.4 -# Author: Ray Valdez, rvaldez@us.ibm.com 240.5 -# Version: 1.0 240.6 -# 240.7 -# install readme 240.8 -# 240.9 -PREREQUISITES: 240.10 - 240.11 -Prior to installation of the policy processor tool (XmlToBin) you must have... 240.12 - 240.13 - 1. Java version 1.4.2 240.14 - 2. xmlParserAPIs.jar and xercesImpl.jar 240.15 - 240.16 -The above can be obtained from the Sun Developer Network web site at 240.17 -http://java.sun.com/j2se/1.4.2/download.html. 240.18 - 240.19 -XmlParserAPIs and xercesImpl jars can be obtained from 240.20 -http://www.apache.org/dist/xml/xerces-j (Xerces-J-bin.2.6.2.tar.gz, 240.21 -for example). 240.22 - 240.23 -The tool has been tested with J2SE v1.4.2_08 JRE on Linux (32-bit 240.24 -INTEL). 240.25 - 240.26 -INSTALLATION 240.27 - 240.28 -1. Set PATH to include $HOME_JAVA/bin and $HOME_JAVA/jre/bin 240.29 - where $HOME_JAVA is your java installation directory 240.30 - 240.31 -2. Compile XmlToBin: 240.32 - javac XmlToBin.java 240.33 - 240.34 -USAGE 240.35 - 240.36 - See readme.xen
241.1 --- a/tools/misc/policyprocessor/readme.xen Thu Aug 18 10:40:02 2005 -0800 241.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 241.3 @@ -1,65 +0,0 @@ 241.4 -# Author: Ray Valdez, rvaldez@us.ibm.com 241.5 -# Version: 1.0 241.6 -# 241.7 -# This readme describes the policy processor tool for sHype. 241.8 -# 241.9 - 241.10 -Java program: 241.11 - 241.12 - java XmlToBin -i [file.xml] -o <file.bin> -xssid <SsidFile> -xssidconf <SsidConf> 241.13 - 241.14 - Command line options: 241.15 - 241.16 - -i inputFile: name of policyfile (.xml) 241.17 - -o outputFile: name of binary policy file (Big Endian) 241.18 - -xssid SsidFile: xen ssids to named types text file 241.19 - -xssidconf SsidConf: xen conflict ssids to types text file 241.20 - -debug turn on debug messages 241.21 - -help help. This printout 241.22 - 241.23 -Where: 241.24 - 241.25 -file.xml is the (input) xml policy file to be parsed and validated. 241.26 -The syntax for file.xml is defined in the SecurityPolicySpec.xsd file. 241.27 -file.bin is the (output) binary policy file generated by XmlToBin. 241.28 -This binary policy can be activated in sHype. The binary policy file 241.29 -is laid out in network byte order (i.e., big endian). The SsidFile 241.30 -file contains the mapping of type enforcement (TE) ssids to the "named 241.31 -types". Similarly, the SsidConf file contains the mapping of Chinese 241.32 -Wall (ChWall) ssids to conflict named types. The ssidFile and SsidConf 241.33 -files are used by Xen. 241.34 - 241.35 -Xml Schema and policy: 241.36 - 241.37 -The SecurityPolicySpec.xsd defines the syntax of a policy file. It 241.38 -declares the tags that are used by XmlToBin to generate the binary 241.39 -policy file. The tags that XmlToBin keys on are TE, ChWall, id, vid, 241.40 -etc. The xml files that describe a policy are simple. Semantic 241.41 -checking of a policy is performed mostly by XmlToBin. A type, for 241.42 -example, is a string. No fixed values are defined for types in Xml. 241.43 - 241.44 -A policy consists of two Xml files: definition and policy. The 241.45 -definition Xml declares the types that are permitted in the policy 241.46 -Xml. The policy Xml contains the assignment of labels to 241.47 -subject/object (e.g., vm). This Xml file contains an explicit 241.48 -reference to the definition Xml (e.g., <url>xen_sample_def.xml</url>). 241.49 -The policy Xml is the one provided as a command line argument. 241.50 - 241.51 - 241.52 -Files: 241.53 - 241.54 -*.java - policy processor source 241.55 -xen_sample_policy.xml - sample xml policy file 241.56 -xen_sample_def.xml - sample user defined types 241.57 -SecurityPolicySpec.xsd - schema definition file 241.58 - 241.59 - 241.60 -To generate the sample binary policy: 241.61 - 241.62 -export CLASSPATH=$XERCES_HOME/xercesImpl.jar:$XERCES_HOME/xmlParserAPIs.jar:. 241.63 - 241.64 -java XmlToBin -i xen_sample_policy.xml -o xen_sample_policy.bin 241.65 - 241.66 -where $XERCES_HOME is the installation directory of the Apache Xerces-J 241.67 - 241.68 -
242.1 --- a/tools/misc/policyprocessor/xen_sample_def.xml Thu Aug 18 10:40:02 2005 -0800 242.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 242.3 @@ -1,46 +0,0 @@ 242.4 -<?xml version="1.0"?> 242.5 -<!-- Author: Ray Valdez, rvaldez@us.ibm.com --> 242.6 -<!-- example policy type definition --> 242.7 -<SecurityPolicySpec 242.8 -xmlns="http://www.ibm.com" 242.9 -xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 242.10 -xsi:schemaLocation="http://www.ibm.com SecurityPolicySpec.xsd"> 242.11 - 242.12 -<Definition> 242.13 -<!-- an example of a simple type enforcement type definition --> 242.14 - <Types> 242.15 - <TE>LOCAL-management</TE> 242.16 - <TE>R-Company-development</TE> 242.17 - <TE>S-Company-order</TE> 242.18 - <TE>T-Company-advertising</TE> 242.19 - <TE>U-Company-computing</TE> 242.20 - <!-- TE nondevelopment --> 242.21 - </Types> 242.22 - 242.23 -<!-- an example of a chinese wall type definition along with conflict sets--> 242.24 - <ChWallTypes> 242.25 - <ChWall>Q-Company</ChWall> 242.26 - <ChWall>R-Company</ChWall> 242.27 - <ChWall>S-Company</ChWall> 242.28 - <ChWall>T-Company</ChWall> 242.29 - <ChWall>U-Company</ChWall> 242.30 - <ChWall>V-Company</ChWall> 242.31 - <ChWall>W-Company</ChWall> 242.32 - <ChWall>X-Company</ChWall> 242.33 - <ChWall>Y-Company</ChWall> 242.34 - <ChWall>Z-Company</ChWall> 242.35 - </ChWallTypes> 242.36 - 242.37 - <ConflictSet> 242.38 - <ChWall>T-Company</ChWall> 242.39 - <ChWall>S-Company</ChWall> 242.40 - </ConflictSet> 242.41 - 242.42 - <ConflictSet> 242.43 - <ChWall>R-Company</ChWall> 242.44 - <ChWall>V-Company</ChWall> 242.45 - <ChWall>W-Company</ChWall> 242.46 - </ConflictSet> 242.47 - 242.48 -</Definition> 242.49 -</SecurityPolicySpec>
243.1 --- a/tools/misc/policyprocessor/xen_sample_policy.xml Thu Aug 18 10:40:02 2005 -0800 243.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 243.3 @@ -1,58 +0,0 @@ 243.4 -<?xml version="1.0"?> 243.5 -<!-- Author: Ray Valdez, rvaldez@us.ibm.com --> 243.6 -<!-- example xen policy file --> 243.7 - 243.8 -<SecurityPolicySpec 243.9 -xmlns="http://www.ibm.com" 243.10 -xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 243.11 -xsi:schemaLocation="http://www.ibm.com SecurityPolicySpec.xsd"> 243.12 -<Policy> 243.13 - <PolicyHeader> 243.14 - <Name>xen sample policy</Name> 243.15 - <DateTime>2005-05-20T16:56:00</DateTime> 243.16 - <Tag>foobar</Tag> 243.17 - <TypeDefinition> 243.18 - <url>xen_sample_def.xml</url> 243.19 - <hash>abcdef123456abcdef</hash> 243.20 - </TypeDefinition> 243.21 - </PolicyHeader> 243.22 - 243.23 - <VM> 243.24 - <id> 0 </id> 243.25 - <TE>LOCAL-management</TE> 243.26 - <TE>R-Company-development</TE> 243.27 - <TE>S-Company-order</TE> 243.28 - <TE>T-Company-advertising</TE> 243.29 - <TE>U-Company-computing</TE> 243.30 - <ChWall>Q-Company</ChWall> 243.31 - </VM> 243.32 - 243.33 - <VM> 243.34 - <id> 1 </id> 243.35 - <TE>R-Company-development</TE> 243.36 - <ChWall>R-Company</ChWall> 243.37 - </VM> 243.38 - 243.39 - <VM> 243.40 - <id> 2 </id> 243.41 - <TE>S-Company-order</TE> 243.42 - <ChWall>S-Company</ChWall> 243.43 - 243.44 - </VM> 243.45 - 243.46 - <VM> 243.47 - <id> 3 </id> 243.48 - <TE>T-Company-advertising</TE> 243.49 - <ChWall>T-Company</ChWall> 243.50 - </VM> 243.51 - 243.52 - 243.53 - <VM> 243.54 - <id> 4 </id> 243.55 - <TE>U-Company-computing</TE> 243.56 - <ChWall>U-Company</ChWall> 243.57 - </VM> 243.58 - 243.59 - 243.60 -</Policy> 243.61 -</SecurityPolicySpec>
248.1 --- a/tools/python/xen/lowlevel/xu/xu.c Thu Aug 18 10:40:02 2005 -0800 248.2 +++ b/tools/python/xen/lowlevel/xu/xu.c Fri Aug 19 10:19:28 2005 -0800 248.3 @@ -844,7 +844,7 @@ static PyObject *xu_message_new(PyObject 248.4 case TYPE(CMSG_BLKIF_BE, CMSG_BLKIF_BE_CONNECT): 248.5 P2C(blkif_be_connect_t, domid, u32); 248.6 P2C(blkif_be_connect_t, blkif_handle, u32); 248.7 - P2C(blkif_be_connect_t, shmem_frame, memory_t); 248.8 + P2C(blkif_be_connect_t, shmem_frame, unsigned long); 248.9 P2C(blkif_be_connect_t, shmem_ref, u32); 248.10 P2C(blkif_be_connect_t, evtchn, u16); 248.11 break; 248.12 @@ -906,9 +906,9 @@ static PyObject *xu_message_new(PyObject 248.13 case TYPE(CMSG_NETIF_BE, CMSG_NETIF_BE_CONNECT): 248.14 P2C(netif_be_connect_t, domid, u32); 248.15 P2C(netif_be_connect_t, netif_handle, u32); 248.16 - P2C(netif_be_connect_t, tx_shmem_frame, memory_t); 248.17 + P2C(netif_be_connect_t, tx_shmem_frame, unsigned long); 248.18 P2C(netif_be_connect_t, tx_shmem_ref, u32); 248.19 - P2C(netif_be_connect_t, rx_shmem_frame, memory_t); 248.20 + P2C(netif_be_connect_t, rx_shmem_frame, unsigned long); 248.21 P2C(netif_be_connect_t, rx_shmem_ref, u32); 248.22 P2C(netif_be_connect_t, evtchn, u16); 248.23 break; 248.24 @@ -942,7 +942,7 @@ static PyObject *xu_message_new(PyObject 248.25 P2C(usbif_fe_driver_status_changed_t, status, u32); 248.26 break; 248.27 case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_CONNECT): 248.28 - P2C(usbif_fe_interface_connect_t, shmem_frame, memory_t); 248.29 + P2C(usbif_fe_interface_connect_t, shmem_frame, unsigned long); 248.30 break; 248.31 case TYPE(CMSG_USBIF_FE, CMSG_USBIF_FE_INTERFACE_DISCONNECT): 248.32 break; 248.33 @@ -956,7 +956,7 @@ static PyObject *xu_message_new(PyObject 248.34 break; 248.35 case TYPE(CMSG_USBIF_BE, CMSG_USBIF_BE_CONNECT): 248.36 P2C(usbif_be_connect_t, domid, domid_t); 248.37 - P2C(usbif_be_connect_t, shmem_frame, memory_t); 248.38 + P2C(usbif_be_connect_t, shmem_frame, unsigned long); 248.39 P2C(usbif_be_connect_t, evtchn, u32); 248.40 P2C(usbif_be_connect_t, bandwidth, u32); 248.41 P2C(usbif_be_connect_t, status, u32);
279.1 --- a/tools/python/xen/xend/XendDomainInfo.py Thu Aug 18 10:40:02 2005 -0800 279.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Fri Aug 19 10:19:28 2005 -0800 279.3 @@ -36,8 +36,10 @@ from xen.xend.server import controller 279.4 from xen.xend.server import SrvDaemon; xend = SrvDaemon.instance() 279.5 from xen.xend.server import messages 279.6 from xen.xend.server.channel import EventChannel, channelFactory 279.7 +from xen.util.blkif import blkdev_name_to_number, expand_dev_name 279.8 279.9 from xen.xend import sxp 279.10 +from xen.xend import Blkctl 279.11 from xen.xend.PrettyPrint import prettyprintstring 279.12 from xen.xend.XendBootloader import bootloader 279.13 from xen.xend.XendLogging import log 279.14 @@ -380,6 +382,39 @@ class XendDomainInfo: 279.15 return ctrl 279.16 279.17 def createDevice(self, type, devconfig, change=False): 279.18 + if type == 'vbd': 279.19 + 279.20 + backdom = domain_exists(sxp.child_value(devconfig, 'backend', '0')) 279.21 + 279.22 + devnum = blkdev_name_to_number(sxp.child_value(devconfig, 'dev')) 279.23 + 279.24 + # create backend db 279.25 + backdb = backdom.db.addChild("/backend/%s/%s/%d" % 279.26 + (type, self.uuid, devnum)) 279.27 + 279.28 + # create frontend db 279.29 + db = self.db.addChild("/device/%s/%d" % (type, devnum)) 279.30 + 279.31 + db['virtual-device'] = "%i" % devnum 279.32 + #db['backend'] = sxp.child_value(devconfig, 'backend', '0') 279.33 + db['backend'] = backdb.getPath() 279.34 + db['backend-id'] = "%i" % int(sxp.child_value(devconfig, 279.35 + 'backend', '0')) 279.36 + 279.37 + backdb['frontend'] = db.getPath() 279.38 + (type, params) = string.split(sxp.child_value(devconfig, 'uname'), ':', 1) 279.39 + node = Blkctl.block('bind', type, params) 279.40 + backdb['frontend-id'] = "%i" % self.id 279.41 + backdb['physical-device'] = "%li" % blkdev_name_to_number(node) 279.42 + backdb.saveDB(save=True) 279.43 + 279.44 + # Ok, super gross, this really doesn't belong in the frontend db... 279.45 + db['type'] = type 279.46 + db['node'] = node 279.47 + db['params'] = params 279.48 + db.saveDB(save=True) 279.49 + 279.50 + return 279.51 ctrl = self.findDeviceController(type) 279.52 return ctrl.createDevice(devconfig, recreate=self.recreate, 279.53 change=change) 279.54 @@ -671,6 +706,16 @@ class XendDomainInfo: 279.55 for ctrl in self.getDeviceControllers(): 279.56 if ctrl.isDestroyed(): continue 279.57 ctrl.destroyController(reboot=reboot) 279.58 + ddb = self.db.addChild("/device") 279.59 + for type in ddb.keys(): 279.60 + if type == 'vbd': 279.61 + typedb = ddb.addChild(type) 279.62 + for dev in typedb.keys(): 279.63 + devdb = typedb.addChild(str(dev)) 279.64 + Blkctl.block('unbind', devdb['type'].getData(), 279.65 + devdb['node'].getData()) 279.66 + typedb[dev].delete() 279.67 + typedb.saveDB(save=True) 279.68 279.69 def show(self): 279.70 """Print virtual machine info. 279.71 @@ -926,6 +971,7 @@ class XendDomainInfo: 279.72 at creation time, for example when it uses NFS root. 279.73 279.74 """ 279.75 + return 279.76 blkif = self.getDeviceController("vbd", error=False) 279.77 if not blkif: 279.78 blkif = self.createDeviceController("vbd")
301.1 --- a/tools/python/xen/xend/server/event.py Thu Aug 18 10:40:02 2005 -0800 301.2 +++ b/tools/python/xen/xend/server/event.py Fri Aug 19 10:19:28 2005 -0800 301.3 @@ -50,7 +50,7 @@ class EventProtocol(protocol.Protocol): 301.4 def dataReceived(self, data): 301.5 try: 301.6 self.parser.input(data) 301.7 - if self.parser.ready(): 301.8 + while(self.parser.ready()): 301.9 val = self.parser.get_val() 301.10 res = self.dispatch(val) 301.11 self.send_result(res)
306.1 --- a/tools/python/xen/xend/server/relocate.py Thu Aug 18 10:40:02 2005 -0800 306.2 +++ b/tools/python/xen/xend/server/relocate.py Fri Aug 19 10:19:28 2005 -0800 306.3 @@ -42,7 +42,7 @@ class RelocationProtocol(protocol.Protoc 306.4 def dataReceived(self, data): 306.5 try: 306.6 self.parser.input(data) 306.7 - if self.parser.ready(): 306.8 + while(self.parser.ready()): 306.9 val = self.parser.get_val() 306.10 res = self.dispatch(val) 306.11 self.send_result(res)
321.1 --- a/tools/security/Makefile Thu Aug 18 10:40:02 2005 -0800 321.2 +++ b/tools/security/Makefile Fri Aug 19 10:19:28 2005 -0800 321.3 @@ -2,28 +2,72 @@ XEN_ROOT = ../.. 321.4 include $(XEN_ROOT)/tools/Rules.mk 321.5 321.6 SRCS = secpol_tool.c 321.7 -CFLAGS += -static 321.8 CFLAGS += -Wall 321.9 CFLAGS += -Werror 321.10 CFLAGS += -O3 321.11 CFLAGS += -fno-strict-aliasing 321.12 -CFLAGS += -I. 321.13 +CFLAGS += -I. -I/usr/include/libxml2 321.14 +CFLAGS_XML2BIN += $(shell xml2-config --cflags --libs ) 321.15 +#if above does not work, try -L/usr/lib -lxml2 -lz -lpthread -lm 321.16 +XML2VERSION = $(shell xml2-config --version ) 321.17 +VALIDATE_SCHEMA=$(shell if [[ $(XML2VERSION) < 2.6.20 ]]; then echo ""; else echo "-DVALIDATE_SCHEMA"; fi; ) 321.18 321.19 +ifeq ($(ACM_USE_SECURITY_POLICY),ACM_NULL_POLICY) 321.20 +POLICY=null 321.21 +endif 321.22 +ifeq ($(ACM_USE_SECURITY_POLICY),ACM_CHINESE_WALL_POLICY) 321.23 +POLICY=chwall 321.24 +endif 321.25 +ifeq ($(ACM_USE_SECURITY_POLICY),ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) 321.26 +POLICY=ste 321.27 +endif 321.28 +ifeq ($(ACM_USE_SECURITY_POLICY),ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY) 321.29 +POLICY=chwall_ste 321.30 +endif 321.31 +POLICYFILE=./policies/$(POLICY)/$(POLICY).bin 321.32 + 321.33 +ifneq ($(ACM_USE_SECURITY_POLICY), ACM_NULL_POLICY) 321.34 all: build 321.35 + 321.36 +install:all 321.37 + 321.38 +default:all 321.39 +else 321.40 +all: 321.41 + 321.42 +install: 321.43 + 321.44 +default: 321.45 +endif 321.46 + 321.47 build: mk-symlinks 321.48 $(MAKE) secpol_tool 321.49 - 321.50 -default: all 321.51 + $(MAKE) secpol_xml2bin 321.52 + chmod 700 ./setlabel.sh 321.53 + chmod 700 ./updategrub.sh 321.54 321.55 -install: all 321.56 - 321.57 -secpol_tool : secpol_tool.c 321.58 +secpol_tool : secpol_tool.c secpol_compat.h 321.59 $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< 321.60 321.61 +secpol_xml2bin : secpol_xml2bin.c secpol_xml2bin.h secpol_compat.h 321.62 + $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_XML2BIN) $(VALIDATE_SCHEMA) -o $@ $< 321.63 + 321.64 clean: 321.65 - rm -rf secpol_tool xen 321.66 + rm -rf secpol_tool secpol_xml2bin xen 321.67 + 321.68 +policy_clean: 321.69 + rm -rf policies/*/*.bin policies/*/*.map 321.70 + 321.71 +mrproper: clean policy_clean 321.72 321.73 321.74 +$(POLICYFILE) : build 321.75 + @./secpol_xml2bin $(POLICY) > /dev/null 321.76 + 321.77 +boot_install: $(POLICYFILE) 321.78 + @cp $(POLICYFILE) /boot 321.79 + @./updategrub.sh $(POLICY) $(PWD)/$(XEN_ROOT) 321.80 + 321.81 LINUX_ROOT := $(XEN_ROOT)/linux-2.6-xen-sparse 321.82 mk-symlinks: 321.83 [ -e xen/linux ] || mkdir -p xen/linux
322.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 322.2 +++ b/tools/security/example.txt Fri Aug 19 10:19:28 2005 -0800 322.3 @@ -0,0 +1,269 @@ 322.4 +## 322.5 +# example.txt <description to the xen access control architecture> 322.6 +# 322.7 +# Author: 322.8 +# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com> 322.9 +# 322.10 +# 322.11 +# This file introduces into the tools to manage policies 322.12 +# and to label domains and resources. 322.13 +## 322.14 + 322.15 +We will show how to install and use the chwall_ste policy. 322.16 +Other policies work similarly. Feedback welcome! 322.17 + 322.18 + 322.19 + 322.20 +1. Using secpol_xml2bin to translate the chwall_ste policy: 322.21 +=========================================================== 322.22 + 322.23 +#tools/security/secpol_xml2bin chwall_ste 322.24 + 322.25 +Successful execution should print: 322.26 + 322.27 + [root@laptopxn security]# ./secpol_xml2bin chwall_ste 322.28 + Validating label file policies/chwall_ste/chwall_ste-security_label_template.xml... 322.29 + XML Schema policies/security_policy.xsd valid. 322.30 + Validating policy file policies/chwall_ste/chwall_ste-security_policy.xml... 322.31 + XML Schema policies/security_policy.xsd valid. 322.32 + Creating ssid mappings ... 322.33 + Creating label mappings ... 322.34 + Max chwall labels: 7 322.35 + Max chwall-types: 4 322.36 + Max chwall-ssids: 5 322.37 + Max ste labels: 14 322.38 + Max ste-types: 6 322.39 + Max ste-ssids: 10 322.40 + 322.41 +The tool looks in directory policies/chwall_ste for 322.42 +the label and policy files. 322.43 + 322.44 +The default policy directory structure under tools/security looks like: 322.45 + 322.46 +policies 322.47 +|-- security_policy.xsd 322.48 +|-- chwall 322.49 +| |-- chwall-security_label_template.xml 322.50 +| `-- chwall-security_policy.xml 322.51 +|-- chwall_ste 322.52 +| |-- chwall_ste-security_label_template.xml 322.53 +| `-- chwall_ste-security_policy.xml 322.54 +|-- null 322.55 +| |-- null-security_label_template.xml 322.56 +| `-- null-security_policy.xml 322.57 +`-- ste 322.58 + |-- ste-security_label_template.xml 322.59 + `-- ste-security_policy.xml 322.60 + 322.61 +policies/security_policy.xsd contains the schema against which both the 322.62 +label-template and the policy files must validate during translation. 322.63 + 322.64 +policies/chwall_ste/chwall_ste-security_policy.xml defines the 322.65 +policies and the types known to the policies. 322.66 + 322.67 +policies/chwall_ste/chwall_ste-security_label_template.xml contains 322.68 +label definitions that group chwall and ste types together and make 322.69 +them easier to use for users 322.70 + 322.71 +After executing the above secpol_xml2bin command, you will find 2 new 322.72 +files in the policies/chwall_ste sub-directory: 322.73 + 322.74 +policies/chwall_ste/chwall_ste.map ... this file includes the mapping 322.75 +of names from the xml files into their binary code representation. 322.76 + 322.77 +policies/chwall_ste/chwall_ste.bin ... this is the binary policy file, 322.78 +the result of parsing the xml files and using the mapping to extract a 322.79 +binary version that can be loaded into the hypervisor. 322.80 + 322.81 + 322.82 + 322.83 +2. Loading and activating the policy: 322.84 +===================================== 322.85 + 322.86 +We assume that xen is already configured to use the chwall_ste policy; 322.87 +please refer to install.txt for instructions. 322.88 + 322.89 +To activate the policy from the command line (assuming that the 322.90 +currently established policy is the minimal boot-policy that is 322.91 +hard-coded into the hypervisor: 322.92 + 322.93 +# ./secpol_tool loadpolicy policies/chwall_ste/chwall_ste.bin 322.94 + 322.95 +To activate the policy at next reboot: 322.96 + 322.97 +# cp policies/chwall_ste/chwall_ste.bin /boot 322.98 + 322.99 +Add a module line to your /boot/grub/grub.conf Xen entry. 322.100 +My boot entry with chwall_ste enabled looks like this: 322.101 + 322.102 + title Xen (2.6.12) 322.103 + root (hd0,5) 322.104 + kernel /boot/xen.gz dom0_mem=1200000 console=vga 322.105 + module /boot/vmlinuz-2.6.12-xen0 ro root=/dev/hda6 rhgb 322.106 + module /boot/initrd-2.6.12-xen0.img 322.107 + module /boot/chwall_ste.bin 322.108 + 322.109 +This tells the grub boot-loader to load the binary policy, which 322.110 +the hypervisor will recognize. The hypervisor will then establish 322.111 +this binary policy during boot instead of the minimal policy that 322.112 +is hardcoded as default. 322.113 + 322.114 +If you have any trouble here, maks sure you have the access control 322.115 +framework enabled (see: install.txt). 322.116 + 322.117 + 322.118 + 322.119 +3. Labeling domains: 322.120 +==================== 322.121 + 322.122 +a) Labeling Domain0: 322.123 + 322.124 +The chwall_ste-security_label_template.xml file includes an attribute 322.125 +"bootstrap", which is set to the label name that will be assigned to 322.126 +Dom0 (this label will be mapped to ssidref 1/1, the default for Dom0). 322.127 + 322.128 +b) Labeling User Domains: 322.129 + 322.130 +Use the script tools/security/setlabel.sh to choose a label and to 322.131 +assign labels to user domains. 322.132 + 322.133 +To show available labels for the chwall_ste policy: 322.134 + 322.135 +#tools/security/setlabel.sh -l 322.136 + 322.137 +lists all available labels. For the default chwall_ste it should print 322.138 +the following: 322.139 + 322.140 + [root@laptopxn security]# ./setlabel.sh -l chwall_ste 322.141 + The following labels are available: 322.142 + dom_SystemManagement 322.143 + dom_HomeBanking 322.144 + dom_Fun 322.145 + dom_BoincClient 322.146 + dom_StorageDomain 322.147 + dom_NetworkDomain 322.148 + 322.149 +You need to have compiled the policy beforehand so that a .map file 322.150 +exists. Setlabel.sh uses the mapping file created throughout the 322.151 +policy translation to translate a user-friendly label string into a 322.152 +ssidref-number that is eventually used by the Xen hypervisor. 322.153 + 322.154 +We distinguish two kinds of labels: a) VM labels (for domains) and RES 322.155 +Labels (for resources). We are currently working on support for 322.156 +resource labeling but will focus here on VM labels. 322.157 + 322.158 +Setlabel.sh only prints VM labels (which we have prefixed with "dom_") 322.159 +since only those are used at this time. 322.160 + 322.161 +If you would like to assign the dom_HomeBanking label to one of your 322.162 +user domains (which you hopefully keep clean), look at an example 322.163 +domain configuration homebanking.xm: 322.164 + 322.165 + #------HOMEBANKING--------- 322.166 + kernel = "/boot/vmlinuz-2.6.12-xenU" 322.167 + ramdisk="/boot/U1_ramdisk.img" 322.168 + memory = 65 322.169 + name = "test34" 322.170 + cpu = -1 # leave to Xen to pick 322.171 + # Number of network interfaces. Default is 1. 322.172 + nics=1 322.173 + dhcp="dhcp" 322.174 + #------------------------- 322.175 + 322.176 +Now we label this domain 322.177 + 322.178 +[root@laptopxn security]# ./setlabel.sh homebanking.xm dom_HomeBanking chwall_ste 322.179 +Mapped label 'dom_HomeBanking' to ssidref '0x00020002'. 322.180 + 322.181 +The domain configuration my look now like: 322.182 + 322.183 + [root@laptopxn security]# cat homebanking.xm 322.184 + #------HOMEBANKING--------- 322.185 + kernel = "/boot/vmlinuz-2.6.12-xenU" 322.186 + ramdisk="/boot/U1_ramdisk.img" 322.187 + memory = 65 322.188 + name = "test34" 322.189 + cpu = -1 # leave to Xen to pick 322.190 + # Number of network interfaces. Default is 1. 322.191 + nics=1 322.192 + dhcp="dhcp" 322.193 + #------------------------- 322.194 + #ACM_POLICY=chwall_ste-security_policy.xml 322.195 + #ACM_LABEL=dom_HomeBanking 322.196 + ssidref = 0x00020002 322.197 + 322.198 +You can see 3 new entries, two of which are comments. The only value 322.199 +that the hypervisor cares about is the ssidref that will reference 322.200 +those types assigned to this label. You can look them up in the 322.201 +xml label-template file for the chwall_ste policy. 322.202 + 322.203 +This script will eventually move into the domain management and will 322.204 +be called when the domain is instantiated. For now, the setlabel 322.205 +script must be run on domains whenever the policy files change since 322.206 +the mapping between label names and ssidrefs can change in this case. 322.207 + 322.208 + 322.209 +4. Starting a labeled domain 322.210 +============================ 322.211 + 322.212 +Now, start the domain: 322.213 + #xm create -c homebanking.xm 322.214 + 322.215 + 322.216 +If you label another domain configuration as dom_Fun and try to start 322.217 +it afterwards, its start will fail. Why? 322.218 + 322.219 +Because the running homebanking domain has the chinese wall type 322.220 +"cw_Sensitive". The new domain dom_Fun has the chinese wall label 322.221 +"cw_Distrusted". This domain is not allowed to run simultaneously 322.222 +because of the defined conflict set 322.223 + 322.224 + <conflictset name="Protection1"> 322.225 + <type>cw_Sensitive</type> 322.226 + <type>cw_Distrusted</type> 322.227 + </conflictset> 322.228 + 322.229 +(in policies/chwall_ste/chwall_ste-security_policy.xml), which says 322.230 +that only one of the types cw_sensitive and cw_Distrusted can run at a 322.231 +time. 322.232 + 322.233 +If you save or shutdown the HomeBanking domain, you will be able to 322.234 +start the "Fun" domain. You can look into the Xen log to see if a 322.235 +domain was denied to start because of the access control framework 322.236 +with the command 'xm dmesg'. 322.237 + 322.238 +It is important (and usually non-trivial) to define the labels in a 322.239 +way that the semantics of the labels are enforced and supported by the 322.240 +types and the conflict sets. 322.241 + 322.242 +Note: While the chinese wall policy enforcement is complete, the type 322.243 +enforcement is currently enforced in the Xen hypervisor 322.244 +only. Therefore, only point-to-point sharing with regard to the type 322.245 +enforcement is currently controlled. We are working on enhancements to 322.246 +Dom0 that enforce types also for network traffic that is routed 322.247 +through Dom0 and on the enforcement of resource labeling when binding 322.248 +resources to domains (e.g., enforcing types between domains and 322.249 +hardware resources, such as disk partitions). 322.250 + 322.251 + 322.252 +4. Adding your own policies 322.253 +=========================== 322.254 + 322.255 +Writing your own policy (e.g. "mypolicy") requires the following: 322.256 + 322.257 +a) the policy definition (types etc.) file 322.258 +b) the label template definition (labels etc.) file 322.259 + 322.260 +If your policy name is "mypolicy", you need to create a 322.261 +subdirectory mypolicy in tools/security/policies. 322.262 + 322.263 +Then you create 322.264 +tools/security/policies/mypolicy/mypolicy-security_policy.xml and 322.265 +tools/security/policies/mypolicy/mypolicy-security_label_template.xml. 322.266 + 322.267 +You need to keep to the schema as defined in 322.268 +tools/security/security_policy.xsd since the translation tool 322.269 +secpol_xml2bin is written against this schema. 322.270 + 322.271 +If you keep to the security policy schema, then you can use all the 322.272 +tools described above. Refer to install.txt to install it.
323.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 323.2 +++ b/tools/security/install.txt Fri Aug 19 10:19:28 2005 -0800 323.3 @@ -0,0 +1,67 @@ 323.4 +## 323.5 +# install.txt <description to the xen access control architecture> 323.6 +# 323.7 +# Author: 323.8 +# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com> 323.9 +# 323.10 +# 323.11 +# This file shows how to activate and install the access control 323.12 +# framework. 323.13 +## 323.14 + 323.15 + 323.16 +INSTALLING A SECURITY POLICY IN XEN 323.17 +=================================== 323.18 + 323.19 +By default, the access control architecture is disabled in Xen. To 323.20 +enable the access control architecture in Xen follow the steps below. 323.21 +This description assumes that you want to install the Chinese Wall and 323.22 +Simple Type Enforcement policy. Some file names need to be replaced 323.23 +below to activate the Chinese Wall OR the Type Enforcement policy 323.24 +exclusively (chwall_ste --> {chwall, ste}). 323.25 + 323.26 +1. enable access control in Xen 323.27 + # cd "xen_root" 323.28 + # edit/xemacs/vi Config.mk 323.29 + 323.30 + change the line: 323.31 + ACM_USE_SECURITY_POLICY ?= ACM_NULL_POLICY 323.32 + 323.33 + to: 323.34 + ACM_USE_SECURITY_POLICY ?= ACM_CHINESE_WALL_AND_SIMPLE_TYPE_ENFORCEMENT_POLICY 323.35 + 323.36 + # make all 323.37 + # ./install.sh 323.38 + 323.39 +2. compile the policy from xml to a binary format that can be loaded 323.40 + into the hypervisor for enforcement 323.41 + # cd tools/security 323.42 + # make 323.43 + 323.44 + manual steps (alternative to make boot_install): 323.45 + #./secpol_xml2bin chwall_ste 323.46 + #cp policies/chwall_ste/chwall_ste.bin /boot 323.47 + #edit /boot/grub/grub.conf 323.48 + add the follwoing line to your xen boot entry: 323.49 + "module chwall_ste.bin" 323.50 + 323.51 + alternatively, you can try our automatic translation and 323.52 + installation of the policy: 323.53 + # make boot_install 323.54 + 323.55 + [we try hard to do the right thing to the right boot entry but 323.56 + please verify boot entry in /boot/grub/grub.conf afterwards; 323.57 + your xen boot entry should have an additional module line 323.58 + specifying a chwall_ste.bin file with the correct directory 323.59 + (e.g. "/" or "/boot").] 323.60 + 323.61 + 323.62 +3. reboot into the newly compiled hypervisor 323.63 + 323.64 + after boot 323.65 + #xm dmesg should show an entry about the policy being loaded 323.66 + during the boot process 323.67 + 323.68 + #tools/security/secpol_tool getpolicy 323.69 + should print the new chwall_ste binary policy representation 323.70 +
324.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 324.2 +++ b/tools/security/policies/chwall/chwall-security_label_template.xml Fri Aug 19 10:19:28 2005 -0800 324.3 @@ -0,0 +1,76 @@ 324.4 +<?xml version="1.0"?> 324.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 324.6 +<!-- This file defines the security labels, which can --> 324.7 +<!-- be attached to Domains and resources. Based on --> 324.8 +<!-- these labels, the access control module decides --> 324.9 +<!-- about sharing between Domains and about access --> 324.10 +<!-- of Domains to real resources. --> 324.11 + 324.12 +<SecurityLabelTemplate 324.13 + xmlns="http://www.ibm.com" 324.14 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 324.15 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 324.16 + <LabelHeader> 324.17 + <Name>chwall-security_label_template</Name> 324.18 + <Date>2005-08-10</Date> 324.19 + <PolicyName> 324.20 + <Url>chwall-security_policy.xml</Url> 324.21 + <Reference>abcdef123456abcdef</Reference> 324.22 + </PolicyName> 324.23 + </LabelHeader> 324.24 + 324.25 + <SubjectLabels bootstrap="dom_SystemManagement"> 324.26 + <!-- single ste typed domains --> 324.27 + <!-- ACM enforces that only domains with --> 324.28 + <!-- the same type can share information --> 324.29 + <!-- --> 324.30 + <!-- Bootstrap label is assigned to Dom0 --> 324.31 + <VirtualMachineLabel> 324.32 + <Name>dom_HomeBanking</Name> 324.33 + <ChineseWallTypes> 324.34 + <Type>cw_Sensitive</Type> 324.35 + </ChineseWallTypes> 324.36 + </VirtualMachineLabel> 324.37 + 324.38 + <VirtualMachineLabel> 324.39 + <Name>dom_Fun</Name> 324.40 + <ChineseWallTypes> 324.41 + <Type>cw_Distrusted</Type> 324.42 + </ChineseWallTypes> 324.43 + </VirtualMachineLabel> 324.44 + 324.45 + <VirtualMachineLabel> 324.46 + <!-- donating some cycles to seti@home --> 324.47 + <Name>dom_BoincClient</Name> 324.48 + <ChineseWallTypes> 324.49 + <Type>cw_Isolated</Type> 324.50 + </ChineseWallTypes> 324.51 + </VirtualMachineLabel> 324.52 + 324.53 + <!-- Domains with multiple ste types services; such domains --> 324.54 + <!-- must keep the types inside their domain safely confined. --> 324.55 + <VirtualMachineLabel> 324.56 + <Name>dom_SystemManagement</Name> 324.57 + <ChineseWallTypes> 324.58 + <Type>cw_SystemManagement</Type> 324.59 + </ChineseWallTypes> 324.60 + </VirtualMachineLabel> 324.61 + 324.62 + <VirtualMachineLabel> 324.63 + <!-- serves persistent storage to other domains --> 324.64 + <Name>dom_StorageDomain</Name> 324.65 + <ChineseWallTypes> 324.66 + <Type>cw_SystemManagement</Type> 324.67 + </ChineseWallTypes> 324.68 + </VirtualMachineLabel> 324.69 + 324.70 + <VirtualMachineLabel> 324.71 + <!-- serves network access to other domains --> 324.72 + <Name>dom_NetworkDomain</Name> 324.73 + <ChineseWallTypes> 324.74 + <Type>cw_SystemManagement</Type> 324.75 + </ChineseWallTypes> 324.76 + </VirtualMachineLabel> 324.77 + </SubjectLabels> 324.78 +</SecurityLabelTemplate> 324.79 +
325.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 325.2 +++ b/tools/security/policies/chwall/chwall-security_policy.xml Fri Aug 19 10:19:28 2005 -0800 325.3 @@ -0,0 +1,36 @@ 325.4 +<?xml version="1.0" encoding="UTF-8"?> 325.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 325.6 +<!-- This file defines the security policies, which --> 325.7 +<!-- can be enforced by the Xen Access Control Module. --> 325.8 +<!-- Currently: Chinese Wall and Simple Type Enforcement--> 325.9 +<SecurityPolicyDefinition xmlns="http://www.ibm.com" 325.10 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 325.11 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 325.12 +<PolicyHeader> 325.13 + <Name>chwall-security_policy</Name> 325.14 + <Date>2005-08-10</Date> 325.15 +</PolicyHeader> 325.16 +<!-- --> 325.17 +<!-- example of a chinese wall type definition --> 325.18 +<!-- along with its conflict sets --> 325.19 +<!-- (typse in a confict set are exclusive, i.e. --> 325.20 +<!-- once a Domain with one type of a set is --> 325.21 +<!-- running, no other Domain with another type --> 325.22 +<!-- of the same conflict set can start.) --> 325.23 + <ChineseWall priority="PrimaryPolicyComponent"> 325.24 + <ChineseWallTypes> 325.25 + <Type>cw_SystemManagement</Type> 325.26 + <Type>cw_Sensitive</Type> 325.27 + <Type>cw_Isolated</Type> 325.28 + <Type>cw_Distrusted</Type> 325.29 + </ChineseWallTypes> 325.30 + 325.31 + <ConflictSets> 325.32 + <Conflict name="Protection1"> 325.33 + <Type>cw_Sensitive</Type> 325.34 + <Type>cw_Distrusted</Type> 325.35 + </Conflict> 325.36 + </ConflictSets> 325.37 + </ChineseWall> 325.38 +</SecurityPolicyDefinition> 325.39 +
326.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 326.2 +++ b/tools/security/policies/chwall_ste/chwall_ste-security_label_template.xml Fri Aug 19 10:19:28 2005 -0800 326.3 @@ -0,0 +1,167 @@ 326.4 +<?xml version="1.0"?> 326.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 326.6 +<!-- This file defines the security labels, which can --> 326.7 +<!-- be attached to Domains and resources. Based on --> 326.8 +<!-- these labels, the access control module decides --> 326.9 +<!-- about sharing between Domains and about access --> 326.10 +<!-- of Domains to real resources. --> 326.11 + 326.12 +<SecurityLabelTemplate 326.13 + xmlns="http://www.ibm.com" 326.14 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 326.15 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 326.16 + <LabelHeader> 326.17 + <Name>chwall_ste-security_label_template</Name> 326.18 + <Date>2005-08-10</Date> 326.19 + <PolicyName> 326.20 + <Url>chwall_ste-security_policy.xml</Url> 326.21 + <Reference>abcdef123456abcdef</Reference> 326.22 + </PolicyName> 326.23 + </LabelHeader> 326.24 + 326.25 + <SubjectLabels bootstrap="dom_SystemManagement"> 326.26 + <!-- single ste typed domains --> 326.27 + <!-- ACM enforces that only domains with --> 326.28 + <!-- the same type can share information --> 326.29 + <!-- --> 326.30 + <!-- Bootstrap label is assigned to Dom0 --> 326.31 + <VirtualMachineLabel> 326.32 + <Name>dom_HomeBanking</Name> 326.33 + <SimpleTypeEnforcementTypes> 326.34 + <Type>ste_PersonalFinances</Type> 326.35 + </SimpleTypeEnforcementTypes> 326.36 + 326.37 + <ChineseWallTypes> 326.38 + <Type>cw_Sensitive</Type> 326.39 + </ChineseWallTypes> 326.40 + </VirtualMachineLabel> 326.41 + 326.42 + <VirtualMachineLabel> 326.43 + <Name>dom_Fun</Name> 326.44 + <SimpleTypeEnforcementTypes> 326.45 + <Type>ste_InternetInsecure</Type> 326.46 + </SimpleTypeEnforcementTypes> 326.47 + 326.48 + <ChineseWallTypes> 326.49 + <Type>cw_Distrusted</Type> 326.50 + </ChineseWallTypes> 326.51 + </VirtualMachineLabel> 326.52 + 326.53 + <VirtualMachineLabel> 326.54 + <!-- donating some cycles to seti@home --> 326.55 + <Name>dom_BoincClient</Name> 326.56 + <SimpleTypeEnforcementTypes> 326.57 + <Type>ste_DonatedCycles</Type> 326.58 + </SimpleTypeEnforcementTypes> 326.59 + 326.60 + <ChineseWallTypes> 326.61 + <Type>cw_Isolated</Type> 326.62 + </ChineseWallTypes> 326.63 + </VirtualMachineLabel> 326.64 + 326.65 + <!-- Domains with multiple ste types services; such domains --> 326.66 + <!-- must keep the types inside their domain safely confined. --> 326.67 + <VirtualMachineLabel> 326.68 + <Name>dom_SystemManagement</Name> 326.69 + <SimpleTypeEnforcementTypes> 326.70 + <!-- since dom0 needs access to every domain and --> 326.71 + <!-- resource right now ... --> 326.72 + <Type>ste_SystemManagement</Type> 326.73 + <Type>ste_PersonalFinances</Type> 326.74 + <Type>ste_InternetInsecure</Type> 326.75 + <Type>ste_DonatedCycles</Type> 326.76 + <Type>ste_PersistentStorageA</Type> 326.77 + <Type>ste_NetworkAdapter0</Type> 326.78 + </SimpleTypeEnforcementTypes> 326.79 + 326.80 + <ChineseWallTypes> 326.81 + <Type>cw_SystemManagement</Type> 326.82 + </ChineseWallTypes> 326.83 + </VirtualMachineLabel> 326.84 + 326.85 + <VirtualMachineLabel> 326.86 + <!-- serves persistent storage to other domains --> 326.87 + <Name>dom_StorageDomain</Name> 326.88 + <SimpleTypeEnforcementTypes> 326.89 + <!-- access right to the resource (hard drive a) --> 326.90 + <Type>ste_PersistentStorageA</Type> 326.91 + <!-- can serve following types --> 326.92 + <Type>ste_PersonalFinances</Type> 326.93 + <Type>ste_InternetInsecure</Type> 326.94 + </SimpleTypeEnforcementTypes> 326.95 + 326.96 + <ChineseWallTypes> 326.97 + <Type>cw_SystemManagement</Type> 326.98 + </ChineseWallTypes> 326.99 + </VirtualMachineLabel> 326.100 + 326.101 + <VirtualMachineLabel> 326.102 + <!-- serves network access to other domains --> 326.103 + <Name>dom_NetworkDomain</Name> 326.104 + <SimpleTypeEnforcementTypes> 326.105 + <!-- access right to the resource (ethernet card) --> 326.106 + <Type>ste_NetworkAdapter0</Type> 326.107 + <!-- can serve following types --> 326.108 + <Type>ste_PersonalFinances</Type> 326.109 + <Type>ste_InternetInsecure</Type> 326.110 + <Type>ste_DonatedCycles</Type> 326.111 + </SimpleTypeEnforcementTypes> 326.112 + 326.113 + <ChineseWallTypes> 326.114 + <Type>cw_SystemManagement</Type> 326.115 + </ChineseWallTypes> 326.116 + </VirtualMachineLabel> 326.117 + </SubjectLabels> 326.118 + 326.119 + <ObjectLabels> 326.120 + <ResourceLabel> 326.121 + <Name>res_ManagementResource</Name> 326.122 + <SimpleTypeEnforcementTypes> 326.123 + <Type>ste_SystemManagement</Type> 326.124 + </SimpleTypeEnforcementTypes> 326.125 + </ResourceLabel> 326.126 + 326.127 + <ResourceLabel> 326.128 + <Name>res_HardDrive (hda)</Name> 326.129 + <SimpleTypeEnforcementTypes> 326.130 + <Type>ste_PersistentStorageA</Type> 326.131 + </SimpleTypeEnforcementTypes> 326.132 + </ResourceLabel> 326.133 + 326.134 + <ResourceLabel> 326.135 + <Name>res_LogicalDiskPartition1 (hda1)</Name> 326.136 + <SimpleTypeEnforcementTypes> 326.137 + <Type>ste_PersonalFinances</Type> 326.138 + </SimpleTypeEnforcementTypes> 326.139 + </ResourceLabel> 326.140 + 326.141 + <ResourceLabel> 326.142 + <Name>res_LogicalDiskPartition2 (hda2)</Name> 326.143 + <SimpleTypeEnforcementTypes> 326.144 + <Type>ste_InternetInsecure</Type> 326.145 + </SimpleTypeEnforcementTypes> 326.146 + </ResourceLabel> 326.147 + 326.148 + <ResourceLabel> 326.149 + <Name>res_EthernetCard</Name> 326.150 + <SimpleTypeEnforcementTypes> 326.151 + <Type>ste_NetworkAdapter0</Type> 326.152 + </SimpleTypeEnforcementTypes> 326.153 + </ResourceLabel> 326.154 + 326.155 + <ResourceLabel> 326.156 + <Name>res_SecurityToken</Name> 326.157 + <SimpleTypeEnforcementTypes> 326.158 + <Type>ste_PersonalFinances</Type> 326.159 + </SimpleTypeEnforcementTypes> 326.160 + </ResourceLabel> 326.161 + 326.162 + <ResourceLabel> 326.163 + <Name>res_GraphicsAdapter</Name> 326.164 + <SimpleTypeEnforcementTypes> 326.165 + <Type>ste_SystemManagement</Type> 326.166 + </SimpleTypeEnforcementTypes> 326.167 + </ResourceLabel> 326.168 + </ObjectLabels> 326.169 +</SecurityLabelTemplate> 326.170 +
327.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 327.2 +++ b/tools/security/policies/chwall_ste/chwall_ste-security_policy.xml Fri Aug 19 10:19:28 2005 -0800 327.3 @@ -0,0 +1,49 @@ 327.4 +<?xml version="1.0" encoding="UTF-8"?> 327.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 327.6 +<!-- This file defines the security policies, which --> 327.7 +<!-- can be enforced by the Xen Access Control Module. --> 327.8 +<!-- Currently: Chinese Wall and Simple Type Enforcement--> 327.9 +<SecurityPolicyDefinition xmlns="http://www.ibm.com" 327.10 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 327.11 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 327.12 +<PolicyHeader> 327.13 + <Name>chwall_ste-security_policy</Name> 327.14 + <Date>2005-08-10</Date> 327.15 +</PolicyHeader> 327.16 +<!-- --> 327.17 +<!-- example of a simple type enforcement policy definition --> 327.18 +<!-- --> 327.19 + <SimpleTypeEnforcement> 327.20 + <SimpleTypeEnforcementTypes> 327.21 + <Type>ste_SystemManagement</Type> <!-- machine/security management --> 327.22 + <Type>ste_PersonalFinances</Type> <!-- personal finances --> 327.23 + <Type>ste_InternetInsecure</Type> <!-- games, active X, etc. --> 327.24 + <Type>ste_DonatedCycles</Type> <!-- donation to BOINC/seti@home --> 327.25 + <Type>ste_PersistentStorageA</Type> <!-- domain managing the harddrive A--> 327.26 + <Type>ste_NetworkAdapter0</Type> <!-- type of the domain managing ethernet adapter 0--> 327.27 + </SimpleTypeEnforcementTypes> 327.28 + </SimpleTypeEnforcement> 327.29 +<!-- --> 327.30 +<!-- example of a chinese wall type definition --> 327.31 +<!-- along with its conflict sets --> 327.32 +<!-- (typse in a confict set are exclusive, i.e. --> 327.33 +<!-- once a Domain with one type of a set is --> 327.34 +<!-- running, no other Domain with another type --> 327.35 +<!-- of the same conflict set can start.) --> 327.36 + <ChineseWall priority="PrimaryPolicyComponent"> 327.37 + <ChineseWallTypes> 327.38 + <Type>cw_SystemManagement</Type> 327.39 + <Type>cw_Sensitive</Type> 327.40 + <Type>cw_Isolated</Type> 327.41 + <Type>cw_Distrusted</Type> 327.42 + </ChineseWallTypes> 327.43 + 327.44 + <ConflictSets> 327.45 + <Conflict name="Protection1"> 327.46 + <Type>cw_Sensitive</Type> 327.47 + <Type>cw_Distrusted</Type> 327.48 + </Conflict> 327.49 + </ConflictSets> 327.50 + </ChineseWall> 327.51 +</SecurityPolicyDefinition> 327.52 +
328.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 328.2 +++ b/tools/security/policies/null/null-security_label_template.xml Fri Aug 19 10:19:28 2005 -0800 328.3 @@ -0,0 +1,24 @@ 328.4 +<?xml version="1.0"?> 328.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 328.6 +<!-- This file defines the security labels, which can --> 328.7 +<!-- be attached to Domains and resources. Based on --> 328.8 +<!-- these labels, the access control module decides --> 328.9 +<!-- about sharing between Domains and about access --> 328.10 +<!-- of Domains to real resources. --> 328.11 + 328.12 +<SecurityLabelTemplate 328.13 + xmlns="http://www.ibm.com" 328.14 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 328.15 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 328.16 + <LabelHeader> 328.17 + <Name>null-security_label_template</Name> 328.18 + 328.19 + <Date>2005-08-10</Date> 328.20 + <PolicyName> 328.21 + <Url>null-security_policy.xml</Url> 328.22 + 328.23 + <Reference>abcdef123456abcdef</Reference> 328.24 + </PolicyName> 328.25 + </LabelHeader> 328.26 +</SecurityLabelTemplate> 328.27 +
329.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 329.2 +++ b/tools/security/policies/null/null-security_policy.xml Fri Aug 19 10:19:28 2005 -0800 329.3 @@ -0,0 +1,14 @@ 329.4 +<?xml version="1.0" encoding="UTF-8"?> 329.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 329.6 +<!-- This file defines the security policies, which --> 329.7 +<!-- can be enforced by the Xen Access Control Module. --> 329.8 +<!-- Currently: Chinese Wall and Simple Type Enforcement--> 329.9 +<SecurityPolicyDefinition xmlns="http://www.ibm.com" 329.10 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 329.11 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 329.12 +<PolicyHeader> 329.13 + <Name>null-security_policy</Name> 329.14 + <Date>2005-08-10</Date> 329.15 +</PolicyHeader> 329.16 +</SecurityPolicyDefinition> 329.17 +
330.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 330.2 +++ b/tools/security/policies/security_policy.xsd Fri Aug 19 10:19:28 2005 -0800 330.3 @@ -0,0 +1,138 @@ 330.4 +<?xml version="1.0" encoding="UTF-8"?> 330.5 +<!-- Author: Ray Valdez, Reiner Sailer {rvaldez,sailer}@us.ibm.com --> 330.6 +<!-- This file defines the schema, which is used to define --> 330.7 +<!-- the security policy and the security labels in Xe. --> 330.8 + 330.9 +<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ibm.com" xmlns="http://www.ibm.com" elementFormDefault="qualified"> 330.10 + <xsd:element name="SecurityPolicyDefinition"> 330.11 + <xsd:complexType> 330.12 + <xsd:sequence> 330.13 + <xsd:element ref="PolicyHeader" minOccurs="0" maxOccurs="1"></xsd:element> 330.14 + <xsd:element ref="SimpleTypeEnforcement" minOccurs="0" maxOccurs="1"></xsd:element> 330.15 + <xsd:element ref="ChineseWall" minOccurs="0" maxOccurs="1"></xsd:element> 330.16 + </xsd:sequence> 330.17 + </xsd:complexType> 330.18 + </xsd:element> 330.19 + <xsd:element name="SecurityLabelTemplate"> 330.20 + <xsd:complexType> 330.21 + <xsd:sequence> 330.22 + <xsd:element ref="LabelHeader" minOccurs="1" maxOccurs="1"></xsd:element> 330.23 + <xsd:element name="SubjectLabels" minOccurs="0" maxOccurs="1"> 330.24 + <xsd:complexType> 330.25 + <xsd:sequence> 330.26 + <xsd:element ref="VirtualMachineLabel" minOccurs="1" maxOccurs="unbounded"></xsd:element> 330.27 + </xsd:sequence> 330.28 + <xsd:attribute name="bootstrap" type="xsd:string" use="required"></xsd:attribute> 330.29 + </xsd:complexType> 330.30 + </xsd:element> 330.31 + <xsd:element name="ObjectLabels" minOccurs="0" maxOccurs="1"> 330.32 + <xsd:complexType> 330.33 + <xsd:sequence> 330.34 + <xsd:element ref="ResourceLabel" minOccurs="1" maxOccurs="unbounded"></xsd:element> 330.35 + </xsd:sequence> 330.36 + </xsd:complexType> 330.37 + </xsd:element> 330.38 + </xsd:sequence> 330.39 + </xsd:complexType> 330.40 + </xsd:element> 330.41 + <xsd:element name="PolicyHeader"> 330.42 + <xsd:complexType> 330.43 + <xsd:sequence> 330.44 + <xsd:element ref="Name" minOccurs="1" maxOccurs="1" /> 330.45 + <xsd:element ref="Date" minOccurs="1" maxOccurs="1" /> 330.46 + </xsd:sequence> 330.47 + </xsd:complexType> 330.48 + </xsd:element> 330.49 + <xsd:element name="LabelHeader"> 330.50 + <xsd:complexType> 330.51 + <xsd:sequence> 330.52 + <xsd:element ref="Name"></xsd:element> 330.53 + <xsd:element ref="Date" minOccurs="1" maxOccurs="1"></xsd:element> 330.54 + <xsd:element ref="PolicyName" minOccurs="1" maxOccurs="1"></xsd:element> 330.55 + </xsd:sequence> 330.56 + </xsd:complexType> 330.57 + </xsd:element> 330.58 + <xsd:element name="SimpleTypeEnforcement"> 330.59 + <xsd:complexType> 330.60 + <xsd:sequence> 330.61 + <xsd:element ref="SimpleTypeEnforcementTypes" /> 330.62 + </xsd:sequence> 330.63 + <xsd:attribute name="priority" type="PolicyOrder" use="optional"></xsd:attribute> 330.64 + </xsd:complexType> 330.65 + </xsd:element> 330.66 + <xsd:element name="ChineseWall"> 330.67 + <xsd:complexType> 330.68 + <xsd:sequence> 330.69 + <xsd:element ref="ChineseWallTypes" /> 330.70 + <xsd:element ref="ConflictSets" /> 330.71 + </xsd:sequence> 330.72 + <xsd:attribute name="priority" type="PolicyOrder" use="optional"></xsd:attribute> 330.73 + </xsd:complexType> 330.74 + </xsd:element> 330.75 + <xsd:element name="ChineseWallTypes"> 330.76 + <xsd:complexType> 330.77 + <xsd:sequence> 330.78 + <xsd:element maxOccurs="unbounded" minOccurs="1" ref="Type" /> 330.79 + </xsd:sequence> 330.80 + </xsd:complexType> 330.81 + </xsd:element> 330.82 + <xsd:element name="ConflictSets"> 330.83 + <xsd:complexType> 330.84 + <xsd:sequence> 330.85 + <xsd:element maxOccurs="unbounded" minOccurs="1" ref="Conflict" /> 330.86 + </xsd:sequence> 330.87 + </xsd:complexType> 330.88 + </xsd:element> 330.89 + <xsd:element name="SimpleTypeEnforcementTypes"> 330.90 + <xsd:complexType> 330.91 + <xsd:sequence> 330.92 + <xsd:element maxOccurs="unbounded" minOccurs="1" ref="Type" /> 330.93 + </xsd:sequence> 330.94 + </xsd:complexType> 330.95 + </xsd:element> 330.96 + <xsd:element name="Conflict"> 330.97 + <xsd:complexType> 330.98 + <xsd:sequence> 330.99 + <xsd:element maxOccurs="unbounded" minOccurs="1" ref="Type" /> 330.100 + </xsd:sequence> 330.101 + <xsd:attribute name="name" type="xsd:string" use="optional"></xsd:attribute> 330.102 + </xsd:complexType> 330.103 + </xsd:element> 330.104 + <xsd:element name="VirtualMachineLabel"> 330.105 + <xsd:complexType> 330.106 + <xsd:sequence> 330.107 + <xsd:element ref="Name"></xsd:element> 330.108 + <xsd:element ref="SimpleTypeEnforcementTypes" minOccurs="0" maxOccurs="unbounded" /> 330.109 + <xsd:element ref="ChineseWallTypes" minOccurs="0" maxOccurs="unbounded" /> 330.110 + </xsd:sequence> 330.111 + </xsd:complexType> 330.112 + </xsd:element> 330.113 + <xsd:element name="ResourceLabel"> 330.114 + <xsd:complexType> 330.115 + <xsd:sequence> 330.116 + <xsd:element ref="Name"></xsd:element> 330.117 + <xsd:element ref="SimpleTypeEnforcementTypes" minOccurs="0" maxOccurs="unbounded" /> 330.118 + </xsd:sequence> 330.119 + </xsd:complexType> 330.120 + </xsd:element> 330.121 + <xsd:element name="PolicyName"> 330.122 + <xsd:complexType> 330.123 + <xsd:sequence> 330.124 + <xsd:element ref="Url" /> 330.125 + <xsd:element ref="Reference" /> 330.126 + </xsd:sequence> 330.127 + </xsd:complexType> 330.128 + </xsd:element> 330.129 + <xsd:element name="Date" type="xsd:string" /> 330.130 + <xsd:element name="Name" type="xsd:string" /> 330.131 + <xsd:element name="Type" type="xsd:string" /> 330.132 + <xsd:element name="Reference" type="xsd:string" /> 330.133 + <xsd:element name="Url"></xsd:element> 330.134 + 330.135 + <xsd:simpleType name="PolicyOrder"> 330.136 + <xsd:restriction base="xsd:string"> 330.137 + <xsd:enumeration value="PrimaryPolicyComponent"></xsd:enumeration> 330.138 + </xsd:restriction> 330.139 + </xsd:simpleType> 330.140 + 330.141 +</xsd:schema>
331.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 331.2 +++ b/tools/security/policies/ste/ste-security_label_template.xml Fri Aug 19 10:19:28 2005 -0800 331.3 @@ -0,0 +1,143 @@ 331.4 +<?xml version="1.0"?> 331.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 331.6 +<!-- This file defines the security labels, which can --> 331.7 +<!-- be attached to Domains and resources. Based on --> 331.8 +<!-- these labels, the access control module decides --> 331.9 +<!-- about sharing between Domains and about access --> 331.10 +<!-- of Domains to real resources. --> 331.11 + 331.12 +<SecurityLabelTemplate 331.13 + xmlns="http://www.ibm.com" 331.14 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 331.15 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 331.16 + <LabelHeader> 331.17 + <Name>ste-security_label_template</Name> 331.18 + <Date>2005-08-10</Date> 331.19 + <PolicyName> 331.20 + <Url>ste-security_policy.xml</Url> 331.21 + <Reference>abcdef123456abcdef</Reference> 331.22 + </PolicyName> 331.23 + </LabelHeader> 331.24 + 331.25 + <SubjectLabels bootstrap="dom_SystemManagement"> 331.26 + <!-- single ste typed domains --> 331.27 + <!-- ACM enforces that only domains with --> 331.28 + <!-- the same type can share information --> 331.29 + <!-- --> 331.30 + <!-- Bootstrap label is assigned to Dom0 --> 331.31 + <VirtualMachineLabel> 331.32 + <Name>dom_HomeBanking</Name> 331.33 + <SimpleTypeEnforcementTypes> 331.34 + <Type>ste_PersonalFinances</Type> 331.35 + </SimpleTypeEnforcementTypes> 331.36 + </VirtualMachineLabel> 331.37 + 331.38 + <VirtualMachineLabel> 331.39 + <Name>dom_Fun</Name> 331.40 + <SimpleTypeEnforcementTypes> 331.41 + <Type>ste_InternetInsecure</Type> 331.42 + </SimpleTypeEnforcementTypes> 331.43 + </VirtualMachineLabel> 331.44 + 331.45 + <VirtualMachineLabel> 331.46 + <!-- donating some cycles to seti@home --> 331.47 + <Name>dom_BoincClient</Name> 331.48 + <SimpleTypeEnforcementTypes> 331.49 + <Type>ste_DonatedCycles</Type> 331.50 + </SimpleTypeEnforcementTypes> 331.51 + </VirtualMachineLabel> 331.52 + 331.53 + <!-- Domains with multiple ste types services; such domains --> 331.54 + <!-- must keep the types inside their domain safely confined. --> 331.55 + <VirtualMachineLabel> 331.56 + <Name>dom_SystemManagement</Name> 331.57 + <SimpleTypeEnforcementTypes> 331.58 + <!-- since dom0 needs access to every domain and --> 331.59 + <!-- resource right now ... --> 331.60 + <Type>ste_SystemManagement</Type> 331.61 + <Type>ste_PersonalFinances</Type> 331.62 + <Type>ste_InternetInsecure</Type> 331.63 + <Type>ste_DonatedCycles</Type> 331.64 + <Type>ste_PersistentStorageA</Type> 331.65 + <Type>ste_NetworkAdapter0</Type> 331.66 + </SimpleTypeEnforcementTypes> 331.67 + </VirtualMachineLabel> 331.68 + 331.69 + <VirtualMachineLabel> 331.70 + <!-- serves persistent storage to other domains --> 331.71 + <Name>dom_StorageDomain</Name> 331.72 + <SimpleTypeEnforcementTypes> 331.73 + <!-- access right to the resource (hard drive a) --> 331.74 + <Type>ste_PersistentStorageA</Type> 331.75 + <!-- can serve following types --> 331.76 + <Type>ste_PersonalFinances</Type> 331.77 + <Type>ste_InternetInsecure</Type> 331.78 + </SimpleTypeEnforcementTypes> 331.79 + </VirtualMachineLabel> 331.80 + 331.81 + <VirtualMachineLabel> 331.82 + <!-- serves network access to other domains --> 331.83 + <Name>dom_NetworkDomain</Name> 331.84 + <SimpleTypeEnforcementTypes> 331.85 + <!-- access right to the resource (ethernet card) --> 331.86 + <Type>ste_NetworkAdapter0</Type> 331.87 + <!-- can serve following types --> 331.88 + <Type>ste_PersonalFinances</Type> 331.89 + <Type>ste_InternetInsecure</Type> 331.90 + <Type>ste_DonatedCycles</Type> 331.91 + </SimpleTypeEnforcementTypes> 331.92 + </VirtualMachineLabel> 331.93 + </SubjectLabels> 331.94 + 331.95 + <ObjectLabels> 331.96 + <ResourceLabel> 331.97 + <Name>res_ManagementResource</Name> 331.98 + <SimpleTypeEnforcementTypes> 331.99 + <Type>ste_SystemManagement</Type> 331.100 + </SimpleTypeEnforcementTypes> 331.101 + </ResourceLabel> 331.102 + 331.103 + <ResourceLabel> 331.104 + <Name>res_HardDrive (hda)</Name> 331.105 + <SimpleTypeEnforcementTypes> 331.106 + <Type>ste_PersistentStorageA</Type> 331.107 + </SimpleTypeEnforcementTypes> 331.108 + </ResourceLabel> 331.109 + 331.110 + <ResourceLabel> 331.111 + <Name>res_LogicalDiskPartition1 (hda1)</Name> 331.112 + <SimpleTypeEnforcementTypes> 331.113 + <Type>ste_PersonalFinances</Type> 331.114 + </SimpleTypeEnforcementTypes> 331.115 + </ResourceLabel> 331.116 + 331.117 + <ResourceLabel> 331.118 + <Name>res_LogicalDiskPartition2 (hda2)</Name> 331.119 + <SimpleTypeEnforcementTypes> 331.120 + <Type>ste_InternetInsecure</Type> 331.121 + </SimpleTypeEnforcementTypes> 331.122 + </ResourceLabel> 331.123 + 331.124 + <ResourceLabel> 331.125 + <Name>res_EthernetCard</Name> 331.126 + <SimpleTypeEnforcementTypes> 331.127 + <Type>ste_NetworkAdapter0</Type> 331.128 + </SimpleTypeEnforcementTypes> 331.129 + </ResourceLabel> 331.130 + 331.131 + <ResourceLabel> 331.132 + <Name>res_SecurityToken</Name> 331.133 + <SimpleTypeEnforcementTypes> 331.134 + <Type>ste_PersonalFinances</Type> 331.135 + </SimpleTypeEnforcementTypes> 331.136 + </ResourceLabel> 331.137 + 331.138 + <ResourceLabel> 331.139 + <Name>res_GraphicsAdapter</Name> 331.140 + <SimpleTypeEnforcementTypes> 331.141 + <Type>ste_SystemManagement</Type> 331.142 + </SimpleTypeEnforcementTypes> 331.143 + </ResourceLabel> 331.144 + </ObjectLabels> 331.145 +</SecurityLabelTemplate> 331.146 +
332.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 332.2 +++ b/tools/security/policies/ste/ste-security_policy.xml Fri Aug 19 10:19:28 2005 -0800 332.3 @@ -0,0 +1,27 @@ 332.4 +<?xml version="1.0" encoding="UTF-8"?> 332.5 +<!-- Author: Reiner Sailer, Ray Valdez {sailer,rvaldez}@us.ibm.com --> 332.6 +<!-- This file defines the security policies, which --> 332.7 +<!-- can be enforced by the Xen Access Control Module. --> 332.8 +<!-- Currently: Chinese Wall and Simple Type Enforcement--> 332.9 +<SecurityPolicyDefinition xmlns="http://www.ibm.com" 332.10 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 332.11 + xsi:schemaLocation="http://www.ibm.com security_policy.xsd"> 332.12 +<PolicyHeader> 332.13 + <Name>ste-security_policy</Name> 332.14 + <Date>2005-08-10</Date> 332.15 +</PolicyHeader> 332.16 +<!-- --> 332.17 +<!-- example of a simple type enforcement policy definition --> 332.18 +<!-- --> 332.19 + <SimpleTypeEnforcement> 332.20 + <SimpleTypeEnforcementTypes> 332.21 + <Type>ste_SystemManagement</Type> <!-- machine/security management --> 332.22 + <Type>ste_PersonalFinances</Type> <!-- personal finances --> 332.23 + <Type>ste_InternetInsecure</Type> <!-- games, active X, etc. --> 332.24 + <Type>ste_DonatedCycles</Type> <!-- donation to BOINC/seti@home --> 332.25 + <Type>ste_PersistentStorageA</Type> <!-- domain managing the harddrive A--> 332.26 + <Type>ste_NetworkAdapter0</Type> <!-- type of the domain managing ethernet adapter 0--> 332.27 + </SimpleTypeEnforcementTypes> 332.28 + </SimpleTypeEnforcement> 332.29 +</SecurityPolicyDefinition> 332.30 +
333.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 333.2 +++ b/tools/security/policy.txt Fri Aug 19 10:19:28 2005 -0800 333.3 @@ -0,0 +1,405 @@ 333.4 +## 333.5 +# policy.txt <description to the Xen access control architecture> 333.6 +# 333.7 +# Author: 333.8 +# Reiner Sailer 08/15/2005 <sailer@watson.ibm.com> 333.9 +# 333.10 +# 333.11 +# This file gives an overview of the security policies currently 333.12 +# provided and also gives some reasoning about how to assign 333.13 +# labels to domains. 333.14 +## 333.15 + 333.16 +Xen access control policies 333.17 + 333.18 + 333.19 +General explanation of supported security policies: 333.20 +===================================================== 333.21 + 333.22 +We have implemented the mandatory access control architecture of our 333.23 +hypervisor security architecture (sHype) for the Xen hypervisor. It 333.24 +controls communication (in Xen: event channels, grant tables) between 333.25 +Virtual Machines (from here on called domains) and through this the 333.26 +virtual block devices, networking, and shared memory are implemented 333.27 +on top of these communication means. While we have implemented the 333.28 +described policies and access control architecture for other 333.29 +hypervisor systems, we will describe below specifically its 333.30 +implementation and use in the Xen hypervisor. The policy enforcement 333.31 +is called mandatory regarding user domains since the policy it is 333.32 +given by the security administration and enforced independently of the 333.33 +user domains by the Xen hypervisor in cooperation with the domain 333.34 +management. 333.35 + 333.36 +The access control architecture consists of three parts: 333.37 + 333.38 +i) The access control policy determines the "command set" of the ACM 333.39 +and the hooks with which they can be configured to constrain the 333.40 +sharing of virtual resources. The current access control architecture 333.41 +implemented for Xen supports two policies: Chinese Wall and Simple 333.42 +Type Enforcement, which we describe in turn below. 333.43 + 333.44 + 333.45 +ii) The actually enforced policy instantiation uses the policy 333.46 +language (i) to configure the Xen access control in a way that suits 333.47 +the specific application (home desktop environment, company desktop, 333.48 +Web server system, etc.). We have defined an exemplary policy 333.49 +instantiation for Chinese Wall (chwall policy) and Simple Type 333.50 +Enforcement (ste policy) for a desktop system. We offer these policies 333.51 +in combination since they are controlling orthogonal events. 333.52 + 333.53 + 333.54 +iii) The access control module (ACM) and related hooks are part of the 333.55 +core hypervisor and their controls cannot be bypassed by domains. The 333.56 +ACM and hooks are the active security components. We refer to 333.57 +publications that describe how access control is enforced in the Xen 333.58 +hypervisor using the ACM (access decision) and the hooks (decision 333.59 +enforcement) inserted into the setup of event channels and grant 333.60 +tables, and into domain operations (create, destroy, save, restore, 333.61 +migrate). These controls decide based on the active policy 333.62 +configuration (see i. and ii.) if the operation proceeds of if the 333.63 +operation is aborted (denied). 333.64 + 333.65 + 333.66 +In general, security policy instantiations in the Xen access control 333.67 +framework are defined by two files: 333.68 + 333.69 +a) a single "policy-name"-security_policy.xml file that defines the 333.70 +types known to the ACM and policy rules based on these types 333.71 + 333.72 +b) a single "policy-name"-security_label_template.xml file that 333.73 +defines labels based on known types 333.74 + 333.75 +Every security policy has its own sub-directory under 333.76 +"Xen-root"/tools/security/policies in order to simplify their 333.77 +management and the security policy tools. We will describe those files 333.78 +for our example policy (Chinese Wall and Simple Type Enforcement) in 333.79 +more detail as we go along. Eventually, we will move towards a system 333.80 +installation where the policies will reside under /etc. 333.81 + 333.82 + 333.83 +CHINESE WALL 333.84 +============ 333.85 + 333.86 +The Chinese Wall policy enables the user to define "which workloads 333.87 +(domain payloads) cannot run on a single physical system at the same 333.88 +time". Why would we want to prevent workloads from running at the same 333.89 +time on the same system? This supports requirements that can (but 333.90 +don't have to) be rooted in the measure of trust into the isolation of 333.91 +different domains that share the same hardware. Since the access 333.92 +control architecture aims at high performance and non-intrusive 333.93 +implementation, it currently does not address covert (timing) channels 333.94 +and aims at medium assurance. Users can apply the Chinese Wall policy 333.95 +to guarantee an air-gap between very sensitive payloads both regarding 333.96 +covert information channels and regarding resource starvation. 333.97 + 333.98 +To enable the CW control, each domain is labeled with a set of Chinese 333.99 +Wall types and CW Conflict Sets are defined which include those CW 333.100 +types that cannot run simultaneously on the same hardware. This 333.101 +interpretation of conflict sets is the only policy rule for the Chines 333.102 +Wall policy. 333.103 + 333.104 +This is enforced by controlling the start of domains according to 333.105 +their assigned CW worload types. Domains with Chinese Wall types that 333.106 +appear in a common conflict set are running mutually exclusive on a 333.107 +platform, i.e., once a domain with one of the cw-types of a conflict 333.108 +set is running, no domain with another cw-type of the same conflict 333.109 +set can start until the first domain is destroyed, paused, or migrated 333.110 +away from the physical system (this assumes that such a partition can 333.111 +no longer be observed). The idea is to assign cw-types according to 333.112 +the type of payload that a domain runs and to use the Chinese Wall 333.113 +policy to ensure that payload types can be differentiated by the 333.114 +hypervisor and can be prevented from being executed on the same system 333.115 +at the same time. Using the flexible CW policy maintains system 333.116 +consolidation and workload-balancing while introducing guaranteed 333.117 +constraints where necessary. 333.118 + 333.119 + 333.120 +Example of a Chinese Wall Policy Instantiation 333.121 +---------------------------------------------- 333.122 + 333.123 +The file chwall-security_policy.xml defines the Chinese Wall types as 333.124 +well as the conflict sets for our example policy (you find it in the 333.125 +directory "xen_root"/tools/security/policies/chwall). 333.126 + 333.127 +It defines four Chinese Wall types (prefixed with cw_) with the 333.128 +following meaning: 333.129 + 333.130 +* cw_SystemsManagement is a type identifying workloads for systems 333.131 +management, e.g., domain management, device management, or hypervisor 333.132 +management. 333.133 + 333.134 +* cw_Sensitive is identifying workloads that are critical to the user 333.135