@@ -1049,12 +1049,12 @@ search a specific keyring, so using keyrings in this way is of limited utility.
10491049NOTES ON ACCESSING PAYLOAD CONTENTS
10501050===================================
10511051
1052- The simplest payload is just a number in key->payload.value. In this case,
1053- there's no need to indulge in RCU or locking when accessing the payload.
1052+ The simplest payload is just data stored in key->payload directly. In this
1053+ case, there's no need to indulge in RCU or locking when accessing the payload.
10541054
1055- More complex payload contents must be allocated and a pointer to them set in
1056- key->payload.data. One of the following ways must be selected to access the
1057- data:
1055+ More complex payload contents must be allocated and pointers to them set in the
1056+ key->payload.data[] array. One of the following ways must be selected to
1057+ access the data:
10581058
10591059 (1) Unmodifiable key type.
10601060
@@ -1092,6 +1092,13 @@ data:
10921092 the payload. key->datalen cannot be relied upon to be consistent with the
10931093 payload just dereferenced if the key's semaphore is not held.
10941094
1095+ Note that key->payload.data[0] has a shadow that is marked for __rcu
1096+ usage. This is called key->payload.rcu_data0. The following accessors
1097+ wrap the RCU calls to this element:
1098+
1099+ rcu_assign_keypointer(struct key *key, void *data);
1100+ void *rcu_dereference_key(struct key *key);
1101+
10951102
10961103===================
10971104DEFINING A KEY TYPE
@@ -1143,8 +1150,7 @@ The structure has a number of fields, some of which are mandatory:
11431150
11441151 struct key_preparsed_payload {
11451152 char *description;
1146- void *type_data[2];
1147- void *payload;
1153+ union key_payload payload;
11481154 const void *data;
11491155 size_t datalen;
11501156 size_t quotalen;
@@ -1160,10 +1166,9 @@ The structure has a number of fields, some of which are mandatory:
11601166 attached as a string to the description field. This will be used for the
11611167 key description if the caller of add_key() passes NULL or "".
11621168
1163- The method can attach anything it likes to type_data[] and payload. These
1164- are merely passed along to the instantiate() or update() operations. If
1165- set, the expiry time will be applied to the key if it is instantiated from
1166- this data.
1169+ The method can attach anything it likes to payload. This is merely passed
1170+ along to the instantiate() or update() operations. If set, the expiry
1171+ time will be applied to the key if it is instantiated from this data.
11671172
11681173 The method should return 0 if successful or a negative error code
11691174 otherwise.
@@ -1172,11 +1177,10 @@ The structure has a number of fields, some of which are mandatory:
11721177 (*) void (*free_preparse)(struct key_preparsed_payload *prep);
11731178
11741179 This method is only required if the preparse() method is provided,
1175- otherwise it is unused. It cleans up anything attached to the
1176- description, type_data and payload fields of the key_preparsed_payload
1177- struct as filled in by the preparse() method. It will always be called
1178- after preparse() returns successfully, even if instantiate() or update()
1179- succeed.
1180+ otherwise it is unused. It cleans up anything attached to the description
1181+ and payload fields of the key_preparsed_payload struct as filled in by the
1182+ preparse() method. It will always be called after preparse() returns
1183+ successfully, even if instantiate() or update() succeed.
11801184
11811185
11821186 (*) int (*instantiate)(struct key *key, struct key_preparsed_payload *prep);
@@ -1197,6 +1201,11 @@ The structure has a number of fields, some of which are mandatory:
11971201
11981202 It is safe to sleep in this method.
11991203
1204+ generic_key_instantiate() is provided to simply copy the data from
1205+ prep->payload.data[] to key->payload.data[], with RCU-safe assignment on
1206+ the first element. It will then clear prep->payload.data[] so that the
1207+ free_preparse method doesn't release the data.
1208+
12001209
12011210 (*) int (*update)(struct key *key, const void *data, size_t datalen);
12021211
0 commit comments