Skip to contentSkip to conversation

ALSA: memalloc: Fix pgprot for WC mmap on x86

PATCH New Takashi Iwai 2 participants 2 messages Aug 4, 2021 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: memalloc: Fix pgprot for WC mmap on x86

We have a special handling of WC pages on x86, and it's currently specific to HD-audio. The last forgotten piece was the pgprot setup for the mmap with WC pages.

This patch moves the pgprot setup for WC pages from HD-audio-specific mmap callback to the common helper code. It allows us to remove the superfluous mmap callback in HD-audio and its prepare_mmap redirection.

---
 sound/core/memalloc.c          |  4 ++++
 sound/pci/hda/hda_controller.c | 11 -----------
 sound/pci/hda/hda_controller.h |  2 --
 sound/pci/hda/hda_intel.c      | 12 ------------
 4 files changed, 4 insertions(+), 25 deletions(-)
sound/core/memalloc.c +4 -0
index 58bab2cfdb87..084b2600a423 100644
@@ -407,6 +407,10 @@ static void snd_dma_dev_free(struct snd_dma_buffer *dmab)
 static int snd_dma_dev_mmap(struct snd_dma_buffer *dmab,
 			    struct vm_area_struct *area)
 {
+#ifdef CONFIG_X86
+	if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC)
+		area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
+#endif
 	return dma_mmap_coherent(dmab->dev.dev, area,
 				 dmab->area, dmab->addr, dmab->bytes);
 }
sound/pci/hda/hda_controller.c +0 -11
index ea85c714d1cf..7cd452831fd3 100644
@@ -669,16 +669,6 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
 	return err;
 }
 
-static int azx_pcm_mmap(struct snd_pcm_substream *substream,
-			struct vm_area_struct *area)
-{
-	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
-	struct azx *chip = apcm->chip;
-	if (chip->ops->pcm_mmap_prepare)
-		chip->ops->pcm_mmap_prepare(substream, area);
-	return snd_pcm_lib_default_mmap(substream, area);
-}
-
 static const struct snd_pcm_ops azx_pcm_ops = {
 	.open = azx_pcm_open,
 	.close = azx_pcm_close,
@@ -688,7 +678,6 @@ static const struct snd_pcm_ops azx_pcm_ops = {
 	.trigger = azx_pcm_trigger,
 	.pointer = azx_pcm_pointer,
 	.get_time_info =  azx_get_time_info,
-	.mmap = azx_pcm_mmap,
 };
 
 static void azx_pcm_free(struct snd_pcm *pcm)
sound/pci/hda/hda_controller.h +0 -2
index e4b290de81de..3062f87380b1 100644
@@ -74,8 +74,6 @@ struct azx;
 struct hda_controller_ops {
 	/* Disable msi if supported, PCI only */
 	int (*disable_msi_reset_irq)(struct azx *);
-	void (*pcm_mmap_prepare)(struct snd_pcm_substream *substream,
-				 struct vm_area_struct *area);
 	/* Check if current position is acceptable */
 	int (*position_check)(struct azx *chip, struct azx_dev *azx_dev);
 	/* enable/disable the link power */
sound/pci/hda/hda_intel.c +0 -12
index 9771996e2ef5..3aa432d814a2 100644
@@ -2037,17 +2037,6 @@ static int disable_msi_reset_irq(struct azx *chip)
 	return 0;
 }
 
-static void pcm_mmap_prepare(struct snd_pcm_substream *substream,
-			     struct vm_area_struct *area)
-{
-#ifdef CONFIG_X86
-	struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
-	struct azx *chip = apcm->chip;
-	if (chip->uc_buffer)
-		area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
-#endif
-}
-
 /* Denylist for skipping the whole probe:
  * some HD-audio PCI entries are exposed without any codecs, and such devices
  * should be ignored from the beginning.
@@ -2061,7 +2050,6 @@ static const struct pci_device_id driver_denylist[] = {
 
 static const struct hda_controller_ops pci_hda_ops = {
 	.disable_msi_reset_irq = disable_msi_reset_irq,
-	.pcm_mmap_prepare = pcm_mmap_prepare,
 	.position_check = azx_position_check,
 };
 
Signature · 1 line
2.26.2
#1 lore raw
I love your patch! Yet something to improve:

Hi Takashi,

I love your patch! Yet something to improve:

[auto build test ERROR on sound/for-next]
[also build test ERROR on v5.14-rc4 next-20210803]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Takashi-Iwai/ALSA-memalloc-Fix-pgprot-for-WC-mmap-on-x86/20210804-141649
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git for-next
config: x86_64-kexec (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
        # https://github.com/0day-ci/linux/commit/2221a300a3d8cf7fbf463f6f0726daac3f38bd12
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Takashi-Iwai/ALSA-memalloc-Fix-pgprot-for-WC-mmap-on-x86/20210804-141649
        git checkout 2221a300a3d8cf7fbf463f6f0726daac3f38bd12
        # save the attached .config to linux build tree
        mkdir build_dir
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

sound/core/memalloc.c: In function 'snd_dma_dev_mmap':

>> sound/core/memalloc.c:418:24: error: 'SNDRV_DMA_TYPE_DEV_WC' undeclared (first use in this function); did you mean 'SNDRV_DMA_TYPE_DEV_UC'?
     418 |  if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC)
         |                        ^~~~~~~~~~~~~~~~~~~~~
         |                        SNDRV_DMA_TYPE_DEV_UC

sound/core/memalloc.c:418:24: note: each undeclared identifier is reported only once for each function it appears in

vim +418 sound/core/memalloc.c

413
414 static int snd_dma_dev_mmap(struct snd_dma_buffer *dmab,
415 struct vm_area_struct *area)
416 {
417 #ifdef CONFIG_X86

 > 418		if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_WC)

419 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
420 #endif
421 return dma_mmap_coherent(dmab->dev.dev, area,
422 dmab->area, dmab->addr, dmab->bytes);
423 }
424

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org