Skip to content

Commit 6fdc037

Browse files
author
Stefan Richter
committed
firewire: core: do not DMA-map stack addresses
The DMA mapping API cannot map on-stack addresses, as explained in Documentation/DMA-mapping.txt. Convert the two cases of on-stack packet payload buffers in firewire-core (payload of lock requests in the bus manager work and in iso resource management) to slab-allocated memory. There are a number on-stack buffers for quadlet write or quadlet read requests in firewire-core and firewire-sbp2. These are harmless; they are copied to/ from card driver internal DMA buffers since quadlet payloads are inlined with packet headers. Signed-off-by: Stefan Richter <stefanr@s5r6.in-berlin.de>
1 parent 0c53dec commit 6fdc037

5 files changed

Lines changed: 26 additions & 20 deletions

File tree

‎drivers/firewire/core-card.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ static void allocate_broadcast_channel(struct fw_card *card, int generation)
196196
{
197197
int channel, bandwidth = 0;
198198

199-
fw_iso_resource_manage(card, generation, 1ULL << 31,
200-
&channel, &bandwidth, true);
199+
fw_iso_resource_manage(card, generation, 1ULL << 31, &channel,
200+
&bandwidth, true, card->bm_transaction_data);
201201
if (channel == 31) {
202202
card->broadcast_channel_allocated = true;
203203
device_for_each_child(card->device, (void *)(long)generation,
@@ -230,7 +230,6 @@ static void fw_card_bm_work(struct work_struct *work)
230230
bool do_reset = false;
231231
bool root_device_is_running;
232232
bool root_device_is_cmc;
233-
__be32 lock_data[2];
234233

235234
spin_lock_irqsave(&card->lock, flags);
236235

@@ -273,22 +272,23 @@ static void fw_card_bm_work(struct work_struct *work)
273272
goto pick_me;
274273
}
275274

276-
lock_data[0] = cpu_to_be32(0x3f);
277-
lock_data[1] = cpu_to_be32(local_id);
275+
card->bm_transaction_data[0] = cpu_to_be32(0x3f);
276+
card->bm_transaction_data[1] = cpu_to_be32(local_id);
278277

279278
spin_unlock_irqrestore(&card->lock, flags);
280279

281280
rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
282281
irm_id, generation, SCODE_100,
283282
CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID,
284-
lock_data, sizeof(lock_data));
283+
card->bm_transaction_data,
284+
sizeof(card->bm_transaction_data));
285285

286286
if (rcode == RCODE_GENERATION)
287287
/* Another bus reset, BM work has been rescheduled. */
288288
goto out;
289289

290290
if (rcode == RCODE_COMPLETE &&
291-
lock_data[0] != cpu_to_be32(0x3f)) {
291+
card->bm_transaction_data[0] != cpu_to_be32(0x3f)) {
292292

293293
/* Somebody else is BM. Only act as IRM. */
294294
if (local_id == irm_id)

‎drivers/firewire/core-cdev.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ struct iso_resource {
125125
int generation;
126126
u64 channels;
127127
s32 bandwidth;
128+
__be32 transaction_data[2];
128129
struct iso_resource_event *e_alloc, *e_dealloc;
129130
};
130131

@@ -1049,7 +1050,8 @@ static void iso_resource_work(struct work_struct *work)
10491050
r->channels, &channel, &bandwidth,
10501051
todo == ISO_RES_ALLOC ||
10511052
todo == ISO_RES_REALLOC ||
1052-
todo == ISO_RES_ALLOC_ONCE);
1053+
todo == ISO_RES_ALLOC_ONCE,
1054+
r->transaction_data);
10531055
/*
10541056
* Is this generation outdated already? As long as this resource sticks
10551057
* in the idr, it will be scheduled again for a newer generation or at

‎drivers/firewire/core-iso.c‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,8 @@ EXPORT_SYMBOL(fw_iso_context_stop);
177177
*/
178178

179179
static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
180-
int bandwidth, bool allocate)
180+
int bandwidth, bool allocate, __be32 data[2])
181181
{
182-
__be32 data[2];
183182
int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
184183

185184
/*
@@ -215,9 +214,9 @@ static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
215214
}
216215

217216
static int manage_channel(struct fw_card *card, int irm_id, int generation,
218-
u32 channels_mask, u64 offset, bool allocate)
217+
u32 channels_mask, u64 offset, bool allocate, __be32 data[2])
219218
{
220-
__be32 data[2], c, all, old;
219+
__be32 c, all, old;
221220
int i, retry = 5;
222221

223222
old = all = allocate ? cpu_to_be32(~0) : 0;
@@ -260,7 +259,7 @@ static int manage_channel(struct fw_card *card, int irm_id, int generation,
260259
}
261260

262261
static void deallocate_channel(struct fw_card *card, int irm_id,
263-
int generation, int channel)
262+
int generation, int channel, __be32 buffer[2])
264263
{
265264
u32 mask;
266265
u64 offset;
@@ -269,7 +268,7 @@ static void deallocate_channel(struct fw_card *card, int irm_id,
269268
offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI :
270269
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO;
271270

272-
manage_channel(card, irm_id, generation, mask, offset, false);
271+
manage_channel(card, irm_id, generation, mask, offset, false, buffer);
273272
}
274273

275274
/**
@@ -298,7 +297,7 @@ static void deallocate_channel(struct fw_card *card, int irm_id,
298297
*/
299298
void fw_iso_resource_manage(struct fw_card *card, int generation,
300299
u64 channels_mask, int *channel, int *bandwidth,
301-
bool allocate)
300+
bool allocate, __be32 buffer[2])
302301
{
303302
u32 channels_hi = channels_mask; /* channels 31...0 */
304303
u32 channels_lo = channels_mask >> 32; /* channels 63...32 */
@@ -310,10 +309,12 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
310309

311310
if (channels_hi)
312311
c = manage_channel(card, irm_id, generation, channels_hi,
313-
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI, allocate);
312+
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI,
313+
allocate, buffer);
314314
if (channels_lo && c < 0) {
315315
c = manage_channel(card, irm_id, generation, channels_lo,
316-
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO, allocate);
316+
CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO,
317+
allocate, buffer);
317318
if (c >= 0)
318319
c += 32;
319320
}
@@ -325,12 +326,13 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
325326
if (*bandwidth == 0)
326327
return;
327328

328-
ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate);
329+
ret = manage_bandwidth(card, irm_id, generation, *bandwidth,
330+
allocate, buffer);
329331
if (ret < 0)
330332
*bandwidth = 0;
331333

332334
if (allocate && ret < 0 && c >= 0) {
333-
deallocate_channel(card, irm_id, generation, c);
335+
deallocate_channel(card, irm_id, generation, c, buffer);
334336
*channel = ret;
335337
}
336338
}

‎drivers/firewire/core.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ void fw_node_event(struct fw_card *card, struct fw_node *node, int event);
120120

121121
int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma);
122122
void fw_iso_resource_manage(struct fw_card *card, int generation,
123-
u64 channels_mask, int *channel, int *bandwidth, bool allocate);
123+
u64 channels_mask, int *channel, int *bandwidth,
124+
bool allocate, __be32 buffer[2]);
124125

125126

126127
/* -topology */

‎include/linux/firewire.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ struct fw_card {
127127
struct delayed_work work;
128128
int bm_retries;
129129
int bm_generation;
130+
__be32 bm_transaction_data[2];
130131

131132
bool broadcast_channel_allocated;
132133
u32 broadcast_channel;

0 commit comments

Comments
 (0)