Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add mmap support and some cleanups to bcm2835 ALSA driver #286

Merged
merged 5 commits into from Apr 26, 2013

Conversation

Projects
None yet
4 participants
@martinezjavier
Copy link
Contributor

commented Apr 26, 2013

Hello,

This series contains the following improvements to the ALSA bcm2835 driver:

  • Use the kernel provided facility to wait for completion instead of an
    ad-hoc implementation using semaphores.
  • Add defined constants to specify the deferred action to be processed by the
    driver workqueue instead of using magic numbers.
  • Include PCM samples write in the deferred operations handled by the workqueue
  • Add mmap support to allow Direct Read/Write transfers.
  • Remove unnecessary log when the driver probe function is called if debug is
    not enabled. Also replace printk() usage by more suitable functions.

and fixes these open issues:

#158 "bcm2835 ALSA driver hardware mixing or mmap?"
raspberrypi/firmware#173 "ALSA is not supporting 16 bits signed audio"
#282 "ALSA boot messages"

The following changes since commit 07b8b7d:

Merge pull request #279 from P33M/rpi-3.6.y (2013-04-22 08:08:49 -0700)

are available in the git repository at:

git://github.com/martinezjavier/linux-rpi.git rpi-3.6.y-dev

Javier Martinez Canillas (5):
ALSA: bcm2835: show card and subdev creation msg only on debug
ALSA: bcm2835: use a completion instead of a semaphore for sync
ALSA: bcm2835: don't use magic numbers on audio start/stop workqueue
ALSA: bcm2835: defer bcm2835 PCM write using the workqueue
ALSA: bcm2835: add memory-mapped I/O mode for audio stream

sound/arm/bcm2835-pcm.c | 69 ++++++++++++++++++++++-------------
sound/arm/bcm2835-vchiq.c | 89 +++++++++++++++++++++++++++++++--------------
sound/arm/bcm2835.c | 34 +++++++++---------
sound/arm/bcm2835.h | 2 +
4 files changed, 124 insertions(+), 70 deletions(-)

Thanks a lot and best regards,
Javier

martinezjavier added some commits Apr 24, 2013

ALSA: bcm2835: don't use magic numbers on audio start/stop workqueue
The bcm2835 driver uses a workqueue to defer PCM playback start
and stop. Commands are passed to the function as magic numbers
so is more readable to use macro constants.

Also, while being there change the generic name "x" to "cmd"
for the var used to pass the start/stop commands.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
ALSA: bcm2835: use a completion instead of a semaphore for sync
The kernel completion interface is a simple synchronization
mechanism that is preferable over semaphores to signal the
occurence of an event.

Semaphores are optimized for the non-contention case since
in most situations they will be available. But the wait for
completion is the opposite case since the code calling down
will wait on most cases.

So, is better to use the completion mechanism that has been
developed for this exact use case instead of semaphores.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
ALSA: bcm2835: show card and subdev creation msg only on debug
On driver probe a message showing that a card and its subdevices
have been created is shown. Probably this message is not needed
unless we have debug enabled on the driver. So, use the driver
audio_info() debug macro instead of just printk().

Also is better to use dev_err() and pr_err() instead KERN_ERR.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
ALSA: bcm2835: add memory-mapped I/O mode for audio stream
ALSA supports two transfers methods for PCM playback: Read/Write
transfer where samples are writtern to the device using standard
read and write functions and Direct Read/Write transfers where
samples can be written directly to a mapped memory area and the
driver is signaled once this has been done.

The bcm2835 driver only supported Read/Write transfer method so
this patch adds mmap support to the driver.

The ARM CPU is not able to directly address the audio device
hardware buffer so audio samples are sent to the device using
a message passing interface (vchiq).

Since hardware buffers can't be directly mapped to user-space
memory, an intermediate buffer (using the PCM indirect API) is
needed to store the audio samples and push them to the device
through videocore.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
ALSA: bcm2835: defer bcm2835 PCM write using the workqueue
Only PCM playback and stop are deferred using a workqueue on
the ALSA bcm2835 driver. The actual writing of PCM samples
is synchronous.

This works well for the read/write transfer method since
the snd_pcm_ops .copy function pointer runs on process context.

But the snd_pcm_ops .ack function pointer used to implement
direct read/write transfer using a memory-mapped I/O, runs
with interrupts disabled. Since the Kernel to VideoCore
interface driver has to be able to sleep, PCM write has to be
deferred to in preparation to add mmap support to the driver.

Signed-off-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk>
@popcornmix

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2013

With original driver:

$ sudo espeak "hello from me"
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_direct.c:877:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access
ALSA lib pcm_dmix.c:1030:(snd_pcm_dmix_open) unable to initialize slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

Lots of complaints, but I hear the audio.

With your patch

$ sudo espeak "hello from me"
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

and no audio output. Any idea why? (and why so many warnings).

@popcornmix

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2013

 mplayer  audio/Franz\ Ferdinand\ -\ Take\ Me\ Out.mp3

Works correctly without patch. I've had silence, squawks and a hang with the patch.

@martinezjavier

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2013

weird, I tested with aplay, mpg123, jackd and this Gstreamer pipeline:

$ gst-launch-0.10 -v audiotestsrc ! queue ! audio/x-raw-int, width=16, signed=true ! alsasink

all of them worked for me.

I'll test with mplayer and espeak to see why you are having these issues.

Btw, did you remove the /etc/asound.conf that is adding mmap emulation? You shouldn't use that plug-in since the driver now supports it (in fact it won't work when using).

I'm using this asound.conf:

pcm.!default {
    type hw
    card 0
}

ctl.!default {
    type hw
    card 0
}

But is works when trying with no asound at all too.

@martinezjavier

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2013

When you said with your patch, you mean with the patch-set right? or are you testing each patch separately?

These two patches should be applied together:
ALSA: bcm2835: defer bcm2835 PCM write using the workqueue
ALSA: bcm2835: add memory-mapped I/O mode for audio stream

Since the later won't work without the former. I tried to keep the changes separated to make it easier to review to you, maybe I should squash these two...

@popcornmix

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2013

I was using (I think) the default asound.conf:

pcm.mmap0 {
    type mmap_emul;
    slave {
      pcm "hw:0,0";
    }
}

pcm.!default {
  type plug;
  slave {
    pcm mmap0;
  }
}

It was still largely working. mplayer worked with a wav file, but not mp3. mpg123 worked with mp3 file.
mame worked, flite worked.

I've just tried with your asound and it works in the two cases I'd reported as not working.
Also works without an asound.conf. What do you recommend?

I think we'll get some confusion with people updating kernel on a standard raspbian image (so using mmap_emul), but perhaps that the price of progress. We'll remove mmap_emul in next official image.

(I'm testing the patch as a whole (286.diff).

@asb

This comment has been minimized.

Copy link

commented Apr 26, 2013

We can sort out asound.conf upon upgrade (for those updating via apt-get
anyway).

On 26 April 2013 17:25, popcornmix notifications@github.com wrote:

I was using (I think) the default asound.conf:

pcm.mmap0 {
type mmap_emul;
slave {
pcm "hw:0,0";
}
}

pcm.!default {
type plug;
slave {
pcm mmap0;
}
}

It was still largely working. mplayer worked with a wav file, but not mp3.
mpg123 worked with mp3 file.
mame worked, flite worked.

I've just tried with your asound and it works in the two cases I'd
reported as not working.
Also works without an asound.conf. What do you recommend?

I think we'll get some confusion with people updating kernel on a standard
raspbian image (so using mmap_emul), but perhaps that the price of
progress. We'll remove mmap_emul in next official image.


Reply to this email directly or view it on GitHubhttps://github.com//pull/286#issuecomment-17084783
.

@martinezjavier

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2013

@popcornmix

Yes, if you have mmap emulation on your asound.conf and the driver supports mmap then it will work as long as applications are only using ALSA read/write PCM transfer API (snd_pcm_{writei, readi}) but is not going to work if is using mmap direct r/w API calls (snd_pcm_mmap_{begin, commit, readi, writei})

You can see the difference with aplay:

$ aplay test.wav

works but

$ aplay -M test.wav

does not.

I'm not familiarized with asound mmap emulation plug-in but I guess that when an application is trying to use the ALSA mmap API then the PCM is written twice: one by ALSA when snd_pcm_mmap_commit() is called and another time by libasound mmap emulation plug-in that breaks the buffer in many calls to snd_pcm_writei().

Anyway, as you said the solution is to remove mmap_emul.

I don't know what option is better for raspbian, if an asound.conf without mmap emulation should be shipped or no asound.conf at all.

But as @asb said, this can be sorted out for people updating via apt.

@popcornmix

This comment has been minimized.

Copy link
Collaborator

commented Apr 26, 2013

Yes, new images, and apt-get upgrade users will have no problem.
rpi-update (and kernel compilers) may have a problem. I'll go with "sudo rm /etc/asound.conf" as the advice for now.

Thanks for the PR, it looks good.

popcornmix added a commit that referenced this pull request Apr 26, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

@popcornmix popcornmix merged commit e29067c into raspberrypi:rpi-3.6.y Apr 26, 2013

popcornmix added a commit that referenced this pull request Apr 26, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver
@martinezjavier

This comment has been minimized.

Copy link
Contributor Author

commented Apr 26, 2013

thanks a lot for feedback and testing!

popcornmix added a commit that referenced this pull request Apr 27, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 1, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 1, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 8, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 8, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 12, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 12, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 20, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 26, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver
@popcornmix

This comment has been minimized.

Copy link
Collaborator

commented May 28, 2013

There's a report of a regression from this patch in espeak:
#304

@martinezjavier

This comment has been minimized.

Copy link
Contributor Author

commented May 29, 2013

@popcornmix

Thanks for the notice. I'll take a look at this bug.

Regards

popcornmix added a commit that referenced this pull request Jun 8, 2013

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 10, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 14, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 19, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 22, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 23, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Feb 23, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Mar 7, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Mar 24, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Mar 31, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 1, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 4, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 4, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 5, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 9, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 14, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 14, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 24, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 24, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 27, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Apr 28, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 1, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request May 13, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Jun 7, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix added a commit that referenced this pull request Jun 8, 2014

Merge pull request #286 from martinezjavier/rpi-3.6.y-dev
add mmap support and some cleanups to bcm2835 ALSA driver

popcornmix pushed a commit that referenced this pull request Jun 8, 2014

staging/ozwpan: coding style ether_addr_copy
This fixes the following issues detected by checkpatch.pl:

 WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)
 #220: FILE: drivers/staging/ozwpan/ozcdev.c:220:
 +              memcpy(g_cdev.active_addr, addr, ETH_ALEN);

 WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)
 #286: FILE: drivers/staging/ozwpan/ozcdev.c:286:
 +                      memcpy(addr, g_cdev.active_addr, ETH_ALEN);

 WARNING: Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)
 #176: FILE: drivers/staging/ozwpan/ozpd.c:176:
 +              memcpy(pd->mac_addr, mac_addr, ETH_ALEN);

Signed-off-by: Jerome Pinot <ngc891@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

popcornmix pushed a commit that referenced this pull request Dec 2, 2015

btrfs: fix rcu warning during device replace
The test btrfs/011 triggers a rcu warning
Reviewed-by: Anand Jain <anand.jain@oracle.com>

===============================
[ INFO: suspicious RCU usage. ]
4.4.0-rc1-default+ #286 Tainted: G        W
-------------------------------
fs/btrfs/volumes.c:1977 suspicious rcu_dereference_check() usage!

other info that might help us debug this:

rcu_scheduler_active = 1, debug_locks = 0
4 locks held by btrfs/28786:

0:  (&fs_info->dev_replace.lock_finishing_cancel_unmount){+.+...}, at: [<ffffffffa00bc785>] btrfs_dev_replace_finishing+0x45/0xa00 [btrfs]
1:  (uuid_mutex){+.+.+.}, at: [<ffffffffa00bc84f>] btrfs_dev_replace_finishing+0x10f/0xa00 [btrfs]
2:  (&fs_devs->device_list_mutex){+.+.+.}, at: [<ffffffffa00bc868>] btrfs_dev_replace_finishing+0x128/0xa00 [btrfs]
3:  (&fs_info->chunk_mutex){+.+...}, at: [<ffffffffa00bc87d>] btrfs_dev_replace_finishing+0x13d/0xa00 [btrfs]

stack backtrace:
CPU: 0 PID: 28786 Comm: btrfs Tainted: G        W       4.4.0-rc1-default+ #286
Hardware name: Intel Corporation SandyBridge Platform/To be filled by O.E.M., BIOS ASNBCPT1.86C.0031.B00.1006301607 06/30/2010
0000000000000001 ffff8800a07dfb48 ffffffff8141d47b 0000000000000001
0000000000000001 0000000000000000 ffff8801464a4f00 ffff8800a07dfb78
ffffffff810cd883 ffff880146eb9400 ffff8800a3698600 ffff8800a33fe220
Call Trace:
[<ffffffff8141d47b>] dump_stack+0x4f/0x74
[<ffffffff810cd883>] lockdep_rcu_suspicious+0x103/0x140
[<ffffffffa0071261>] btrfs_rm_dev_replace_remove_srcdev+0x111/0x130 [btrfs]
[<ffffffff810d354d>] ? trace_hardirqs_on+0xd/0x10
[<ffffffff81449536>] ? __percpu_counter_sum+0x66/0x80
[<ffffffffa00bcc15>] btrfs_dev_replace_finishing+0x4d5/0xa00 [btrfs]
[<ffffffffa00bc96e>] ? btrfs_dev_replace_finishing+0x22e/0xa00 [btrfs]
[<ffffffffa00a8795>] ? btrfs_scrub_dev+0x415/0x6d0 [btrfs]
[<ffffffffa003ea69>] ? btrfs_start_transaction+0x9/0x20 [btrfs]
[<ffffffffa00bda79>] btrfs_dev_replace_start+0x339/0x590 [btrfs]
[<ffffffff81196aa5>] ? __might_fault+0x95/0xa0
[<ffffffffa0078638>] btrfs_ioctl_dev_replace+0x118/0x160 [btrfs]
[<ffffffff811409c6>] ? stack_trace_call+0x46/0x70
[<ffffffffa007c914>] ? btrfs_ioctl+0x24/0x1770 [btrfs]
[<ffffffffa007ce43>] btrfs_ioctl+0x553/0x1770 [btrfs]
[<ffffffff811409c6>] ? stack_trace_call+0x46/0x70
[<ffffffff811d6eb1>] ? do_vfs_ioctl+0x21/0x5a0
[<ffffffff811d6f1c>] do_vfs_ioctl+0x8c/0x5a0
[<ffffffff811e3336>] ? __fget_light+0x86/0xb0
[<ffffffff811e3369>] ? __fdget+0x9/0x20
[<ffffffff811d7451>] ? SyS_ioctl+0x21/0x80
[<ffffffff811d7483>] SyS_ioctl+0x53/0x80
[<ffffffff81b1efd7>] entry_SYSCALL_64_fastpath+0x12/0x6f

This is because of unprotected use of rcu_dereference in
btrfs_scratch_superblocks. We can't add rcu locks around the whole
function because we read the superblock.

The fix will use the rcu string buffer directly without the rcu locking.
Thi is safe as the device will not go away in the meantime. We're
holding the device list mutexes.

Restructuring the code to narrow down the rcu section turned out to be
impossible, we need to call filp_open (through update_dev_time) on the
buffer and this could call kmalloc/__might_sleep. We could call kstrdup
with GFP_ATOMIC but it's not absolutely necessary.

Fixes: 12b1c26 (Btrfs: enhance btrfs_scratch_superblock to scratch all superblocks)
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
@alidaf

This comment has been minimized.

Copy link

commented on bad49c2 Feb 17, 2016

Is there an API to help me use this capability? The ALSA API doesn't seem to have anything on this. I have written a peak meter routine but it is based on the Squeezelite mmap, which has shortcomings.

popcornmix pushed a commit that referenced this pull request Mar 26, 2018

net sched actions: return explicit error when tunnel_key mode is not …
…specified

If set/unset mode of the tunnel_key action is not provided, ->init() still
returns 0, and the caller proceeds with bogus 'struct tc_action *' object,
this results in crash:

% tc actions add action tunnel_key src_ip 1.1.1.1 dst_ip 2.2.2.1 id 7 index 1

[   35.805515] general protection fault: 0000 [#1] SMP PTI
[   35.806161] Modules linked in: act_tunnel_key kvm_intel kvm irqbypass
crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64
crypto_simd glue_helper cryptd serio_raw
[   35.808233] CPU: 1 PID: 428 Comm: tc Not tainted 4.16.0-rc4+ #286
[   35.808929] RIP: 0010:tcf_action_init+0x90/0x190
[   35.809457] RSP: 0018:ffffb8edc068b9a0 EFLAGS: 00010206
[   35.810053] RAX: 1320c000000a0003 RBX: 0000000000000001 RCX: 0000000000000000
[   35.810866] RDX: 0000000000000070 RSI: 0000000000007965 RDI: ffffb8edc068b910
[   35.811660] RBP: ffffb8edc068b9d0 R08: 0000000000000000 R09: ffffb8edc068b808
[   35.812463] R10: ffffffffc02bf040 R11: 0000000000000040 R12: ffffb8edc068bb38
[   35.813235] R13: 0000000000000000 R14: 0000000000000000 R15: ffffb8edc068b910
[   35.814006] FS:  00007f3d0d8556c0(0000) GS:ffff91d1dbc40000(0000)
knlGS:0000000000000000
[   35.814881] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   35.815540] CR2: 000000000043f720 CR3: 0000000019248001 CR4: 00000000001606a0
[   35.816457] Call Trace:
[   35.817158]  tc_ctl_action+0x11a/0x220
[   35.817795]  rtnetlink_rcv_msg+0x23d/0x2e0
[   35.818457]  ? __slab_alloc+0x1c/0x30
[   35.819079]  ? __kmalloc_node_track_caller+0xb1/0x2b0
[   35.819544]  ? rtnl_calcit.isra.30+0xe0/0xe0
[   35.820231]  netlink_rcv_skb+0xce/0x100
[   35.820744]  netlink_unicast+0x164/0x220
[   35.821500]  netlink_sendmsg+0x293/0x370
[   35.822040]  sock_sendmsg+0x30/0x40
[   35.822508]  ___sys_sendmsg+0x2c5/0x2e0
[   35.823149]  ? pagecache_get_page+0x27/0x220
[   35.823714]  ? filemap_fault+0xa2/0x640
[   35.824423]  ? page_add_file_rmap+0x108/0x200
[   35.825065]  ? alloc_set_pte+0x2aa/0x530
[   35.825585]  ? finish_fault+0x4e/0x70
[   35.826140]  ? __handle_mm_fault+0xbc1/0x10d0
[   35.826723]  ? __sys_sendmsg+0x41/0x70
[   35.827230]  __sys_sendmsg+0x41/0x70
[   35.827710]  do_syscall_64+0x68/0x120
[   35.828195]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[   35.828859] RIP: 0033:0x7f3d0ca4da67
[   35.829331] RSP: 002b:00007ffc9f284338 EFLAGS: 00000246 ORIG_RAX:
000000000000002e
[   35.830304] RAX: ffffffffffffffda RBX: 00007ffc9f284460 RCX: 00007f3d0ca4da67
[   35.831247] RDX: 0000000000000000 RSI: 00007ffc9f2843b0 RDI: 0000000000000003
[   35.832167] RBP: 000000005aa6a7a9 R08: 0000000000000001 R09: 0000000000000000
[   35.833075] R10: 00000000000005f1 R11: 0000000000000246 R12: 0000000000000000
[   35.833997] R13: 00007ffc9f2884c0 R14: 0000000000000001 R15: 0000000000674640
[   35.834923] Code: 24 30 bb 01 00 00 00 45 31 f6 eb 5e 8b 50 08 83 c2 07 83 e2
fc 83 c2 70 49 8b 07 48 8b 40 70 48 85 c0 74 10 48 89 14 24 4c 89 ff <ff> d0 48
8b 14 24 48 01 c2 49 01 d6 45 85 ed 74 05 41 83 47 2c
[   35.837442] RIP: tcf_action_init+0x90/0x190 RSP: ffffb8edc068b9a0
[   35.838291] ---[ end trace a095c06ee4b97a26 ]---

Fixes: d0f6dd8 ("net/sched: Introduce act_tunnel_key")
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

nathanchance pushed a commit to nathanchance/pi-kernel that referenced this pull request Mar 31, 2018

net sched actions: return explicit error when tunnel_key mode is not …
…specified

[ Upstream commit 51d4740 ]

If set/unset mode of the tunnel_key action is not provided, ->init() still
returns 0, and the caller proceeds with bogus 'struct tc_action *' object,
this results in crash:

% tc actions add action tunnel_key src_ip 1.1.1.1 dst_ip 2.2.2.1 id 7 index 1

[   35.805515] general protection fault: 0000 [raspberrypi#1] SMP PTI
[   35.806161] Modules linked in: act_tunnel_key kvm_intel kvm irqbypass
crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64
crypto_simd glue_helper cryptd serio_raw
[   35.808233] CPU: 1 PID: 428 Comm: tc Not tainted 4.16.0-rc4+ raspberrypi#286
[   35.808929] RIP: 0010:tcf_action_init+0x90/0x190
[   35.809457] RSP: 0018:ffffb8edc068b9a0 EFLAGS: 00010206
[   35.810053] RAX: 1320c000000a0003 RBX: 0000000000000001 RCX: 0000000000000000
[   35.810866] RDX: 0000000000000070 RSI: 0000000000007965 RDI: ffffb8edc068b910
[   35.811660] RBP: ffffb8edc068b9d0 R08: 0000000000000000 R09: ffffb8edc068b808
[   35.812463] R10: ffffffffc02bf040 R11: 0000000000000040 R12: ffffb8edc068bb38
[   35.813235] R13: 0000000000000000 R14: 0000000000000000 R15: ffffb8edc068b910
[   35.814006] FS:  00007f3d0d8556c0(0000) GS:ffff91d1dbc40000(0000)
knlGS:0000000000000000
[   35.814881] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   35.815540] CR2: 000000000043f720 CR3: 0000000019248001 CR4: 00000000001606a0
[   35.816457] Call Trace:
[   35.817158]  tc_ctl_action+0x11a/0x220
[   35.817795]  rtnetlink_rcv_msg+0x23d/0x2e0
[   35.818457]  ? __slab_alloc+0x1c/0x30
[   35.819079]  ? __kmalloc_node_track_caller+0xb1/0x2b0
[   35.819544]  ? rtnl_calcit.isra.30+0xe0/0xe0
[   35.820231]  netlink_rcv_skb+0xce/0x100
[   35.820744]  netlink_unicast+0x164/0x220
[   35.821500]  netlink_sendmsg+0x293/0x370
[   35.822040]  sock_sendmsg+0x30/0x40
[   35.822508]  ___sys_sendmsg+0x2c5/0x2e0
[   35.823149]  ? pagecache_get_page+0x27/0x220
[   35.823714]  ? filemap_fault+0xa2/0x640
[   35.824423]  ? page_add_file_rmap+0x108/0x200
[   35.825065]  ? alloc_set_pte+0x2aa/0x530
[   35.825585]  ? finish_fault+0x4e/0x70
[   35.826140]  ? __handle_mm_fault+0xbc1/0x10d0
[   35.826723]  ? __sys_sendmsg+0x41/0x70
[   35.827230]  __sys_sendmsg+0x41/0x70
[   35.827710]  do_syscall_64+0x68/0x120
[   35.828195]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[   35.828859] RIP: 0033:0x7f3d0ca4da67
[   35.829331] RSP: 002b:00007ffc9f284338 EFLAGS: 00000246 ORIG_RAX:
000000000000002e
[   35.830304] RAX: ffffffffffffffda RBX: 00007ffc9f284460 RCX: 00007f3d0ca4da67
[   35.831247] RDX: 0000000000000000 RSI: 00007ffc9f2843b0 RDI: 0000000000000003
[   35.832167] RBP: 000000005aa6a7a9 R08: 0000000000000001 R09: 0000000000000000
[   35.833075] R10: 00000000000005f1 R11: 0000000000000246 R12: 0000000000000000
[   35.833997] R13: 00007ffc9f2884c0 R14: 0000000000000001 R15: 0000000000674640
[   35.834923] Code: 24 30 bb 01 00 00 00 45 31 f6 eb 5e 8b 50 08 83 c2 07 83 e2
fc 83 c2 70 49 8b 07 48 8b 40 70 48 85 c0 74 10 48 89 14 24 4c 89 ff <ff> d0 48
8b 14 24 48 01 c2 49 01 d6 45 85 ed 74 05 41 83 47 2c
[   35.837442] RIP: tcf_action_init+0x90/0x190 RSP: ffffb8edc068b9a0
[   35.838291] ---[ end trace a095c06ee4b97a26 ]---

Fixes: d0f6dd8 ("net/sched: Introduce act_tunnel_key")
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

popcornmix pushed a commit that referenced this pull request Apr 3, 2018

net sched actions: return explicit error when tunnel_key mode is not …
…specified

[ Upstream commit 51d4740 ]

If set/unset mode of the tunnel_key action is not provided, ->init() still
returns 0, and the caller proceeds with bogus 'struct tc_action *' object,
this results in crash:

% tc actions add action tunnel_key src_ip 1.1.1.1 dst_ip 2.2.2.1 id 7 index 1

[   35.805515] general protection fault: 0000 [#1] SMP PTI
[   35.806161] Modules linked in: act_tunnel_key kvm_intel kvm irqbypass
crct10dif_pclmul crc32_pclmul ghash_clmulni_intel pcbc aesni_intel aes_x86_64
crypto_simd glue_helper cryptd serio_raw
[   35.808233] CPU: 1 PID: 428 Comm: tc Not tainted 4.16.0-rc4+ #286
[   35.808929] RIP: 0010:tcf_action_init+0x90/0x190
[   35.809457] RSP: 0018:ffffb8edc068b9a0 EFLAGS: 00010206
[   35.810053] RAX: 1320c000000a0003 RBX: 0000000000000001 RCX: 0000000000000000
[   35.810866] RDX: 0000000000000070 RSI: 0000000000007965 RDI: ffffb8edc068b910
[   35.811660] RBP: ffffb8edc068b9d0 R08: 0000000000000000 R09: ffffb8edc068b808
[   35.812463] R10: ffffffffc02bf040 R11: 0000000000000040 R12: ffffb8edc068bb38
[   35.813235] R13: 0000000000000000 R14: 0000000000000000 R15: ffffb8edc068b910
[   35.814006] FS:  00007f3d0d8556c0(0000) GS:ffff91d1dbc40000(0000)
knlGS:0000000000000000
[   35.814881] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   35.815540] CR2: 000000000043f720 CR3: 0000000019248001 CR4: 00000000001606a0
[   35.816457] Call Trace:
[   35.817158]  tc_ctl_action+0x11a/0x220
[   35.817795]  rtnetlink_rcv_msg+0x23d/0x2e0
[   35.818457]  ? __slab_alloc+0x1c/0x30
[   35.819079]  ? __kmalloc_node_track_caller+0xb1/0x2b0
[   35.819544]  ? rtnl_calcit.isra.30+0xe0/0xe0
[   35.820231]  netlink_rcv_skb+0xce/0x100
[   35.820744]  netlink_unicast+0x164/0x220
[   35.821500]  netlink_sendmsg+0x293/0x370
[   35.822040]  sock_sendmsg+0x30/0x40
[   35.822508]  ___sys_sendmsg+0x2c5/0x2e0
[   35.823149]  ? pagecache_get_page+0x27/0x220
[   35.823714]  ? filemap_fault+0xa2/0x640
[   35.824423]  ? page_add_file_rmap+0x108/0x200
[   35.825065]  ? alloc_set_pte+0x2aa/0x530
[   35.825585]  ? finish_fault+0x4e/0x70
[   35.826140]  ? __handle_mm_fault+0xbc1/0x10d0
[   35.826723]  ? __sys_sendmsg+0x41/0x70
[   35.827230]  __sys_sendmsg+0x41/0x70
[   35.827710]  do_syscall_64+0x68/0x120
[   35.828195]  entry_SYSCALL_64_after_hwframe+0x3d/0xa2
[   35.828859] RIP: 0033:0x7f3d0ca4da67
[   35.829331] RSP: 002b:00007ffc9f284338 EFLAGS: 00000246 ORIG_RAX:
000000000000002e
[   35.830304] RAX: ffffffffffffffda RBX: 00007ffc9f284460 RCX: 00007f3d0ca4da67
[   35.831247] RDX: 0000000000000000 RSI: 00007ffc9f2843b0 RDI: 0000000000000003
[   35.832167] RBP: 000000005aa6a7a9 R08: 0000000000000001 R09: 0000000000000000
[   35.833075] R10: 00000000000005f1 R11: 0000000000000246 R12: 0000000000000000
[   35.833997] R13: 00007ffc9f2884c0 R14: 0000000000000001 R15: 0000000000674640
[   35.834923] Code: 24 30 bb 01 00 00 00 45 31 f6 eb 5e 8b 50 08 83 c2 07 83 e2
fc 83 c2 70 49 8b 07 48 8b 40 70 48 85 c0 74 10 48 89 14 24 4c 89 ff <ff> d0 48
8b 14 24 48 01 c2 49 01 d6 45 85 ed 74 05 41 83 47 2c
[   35.837442] RIP: tcf_action_init+0x90/0x190 RSP: ffffb8edc068b9a0
[   35.838291] ---[ end trace a095c06ee4b97a26 ]---

Fixes: d0f6dd8 ("net/sched: Introduce act_tunnel_key")
Signed-off-by: Roman Mashak <mrv@mojatatu.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.