lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 25 Feb 2008 14:04:01 +1300
From:	Eliot Blennerhassett <linux@...ioscience.com>
To:	linux-kernel@...r.kernel.org
Subject: Q: volatile vs barriers to access memory data changed by device DMA

Greetings,

Currently I have a driver that uses "volatile", which I want to remove.
As others have said "volatile is useless"
Heres the relevant source.
http://hg.alsa-project.org/alsa-driver/file/89222d702376/pci/asihpi/hpi6205.c

There's quite a bit written about barriers, but most seems to be assuming SMP 
situation or memory mapped devices. Not much about devices doing DMA.
I.e I have read Documentation/memory-barriers.txt, and some of the threads in 
lkml, but still am unsure.

The "volatile" is applied to structures that are either read or written by 
device DMA.  Certainly the driver in its current state doesn't work without 
volatile qualifier. (BTW the device doesn't use host interrupts)

Now, I want to get rid of the volatile, and replace it with ?some kind of 
barrier?

In the following, am I using the barriers correctly?

Note that structures ("interface") used for dma are allocated with 
dma_alloc_coherent()

1) Reading something updated by DMA
Here the volatile or barrier is needed or the loop gets optimised away.

=== current code
volatile struct bus_master_interface *interface;
while (interface->ack != OK) { 
        delay(a short while)          
        [ after X loops device changes interface->ack by dma ]
};

=== after conversion
struct bus_master_interface *interface;
while (interface->ack != OK) { 
        delay(a short while);
        rmb(); 
        [ after X loops device changes interface->ack by dma ]
};

All I need is for the read of interface->ack in the loop not to be optimised 
away - is rmb() the appropriate incantation to achieve this?

2) Writing to memory, interrupt device
Need command to be in memory for device to read by DMA before device gets 
interrupted.

=== current code ===
volatile struct bus_master_interface *interface;
interface->cmd = command;
iowrite(device_interrupt, 1);
[device reads interface->cmd by dma]

=== after conversion ===
struct bus_master_interface *interface;
interface->cmd = command;
wmb();
iowrite(device_interrupt, 1);
[device reads interface->cmd by dma]

Is the wmb() a guarantee that the command will be in memory visible to the 
device when the driver informs it of a new command?
Is it even needed? I.e. does iowrite() effectively form a barrier?

regards

--
Eliot Blennerhassett
www.audioscience.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ