[alsa-devel] 答复: 答复: A bug about cache inconsistency report

Hans Hu(SH-RD) HansHu at zhaoxin.com
Wed Aug 8 11:54:57 CEST 2018


> > >Then the next step would be to fake sg-buffer from this straight
> > >buffer.  Revert the above, and modify sgbuf.c to the following:
> > >- Allocate a large continuous buffer
> > >- Assign each page in this large buffer
> >
> > >If this still works, it's not about vmap, but it just means that
> > >the physically ordered pages do matter -- implicitly showing that
> > >the snooping behavior isn't properly turned on / off on the controller.
> >
> > To fake SG-buffer, I did this test: restore all the codes to the original, then added some codes in snd_malloc_sgbuf_pages() like below, the result is badly niose.
>
> >Not really what I meant.  Rather something like below (totally untested).
>
> [Hans :] I know what you mean now and complete code like below, but the result is still noise.

>OK, so indeed the vmapped address does seem matter.  Interesting.
>What kind of user access does produce the noise?  Does it via aplay mmap mode, too?

>In anyway, if the vmap is a problem, it might be worked around a patch like below (again totally untested and not sure whether it's correct).

[Hans :] As I know, In the hardware layer HDAC’s stream have two data transport path : non-snoop & snoop; In the software layer ALSA-Driver have two data transport path : mmap & not mmap(test shows, it is dependent on wav's format or mmap_flag in aplay.c). When hardware at non-snoop mode, without hardware module's help, software must mark the mem to uncacheable type: when mmap used, the mark action happened at pcm_mmap_prepare(), the not-mmap mode's mark action happened at __mark_pages_wc(). And when at not-mmap mode, the vmapped address directly used in snd_pcm_lib_write_transfer() -> copy_from_user().
Yes, of course, this path combinations(non-snoop + not-mmap) unlikely be used by most music players.

[Hans :] I complete the patch in your last mail like below, not used the vunmap & re-vmap way(it has a little problem). Result is OK now(no noise anymore).

--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
#ifdef CONFIG_X86
+#ifdef CONFIG_SND_DMA_SGBUF
+#include <linux/vmalloc.h>
+#include <linux/sched.h>
+#include <asm/paravirt.h>
+
+static int bad_address(void *p)
+{
+unsigned long dummy;
+
+return probe_kernel_address((unsigned long *)p, dummy);
+}
+
+static pte_t * dump_pte(unsigned long address)
+{
+pgd_t *base = __va(read_cr3() & PHYSICAL_PAGE_MASK);
+pgd_t *pgd = base + pgd_index(address);
+pud_t *pud;
+pmd_t *pmd;
+pte_t *pte;
+
+if (bad_address(pgd))
+goto bad;
+
+if (!pgd_present(*pgd))
+goto bad;
+
+pud = pud_offset(pgd, address);
+if (bad_address(pud))
+goto bad;
+
+if (!pud_present(*pud) || pud_large(*pud))
+goto bad;
+
+pmd = pmd_offset(pud, address);
+if (bad_address(pmd))
+goto bad;
+
+if (!pmd_present(*pmd) || pmd_large(*pmd))
+goto bad;
+
+pte = pte_offset_kernel(pmd, address);
+if (bad_address(pte))
+goto bad;
+
+return pte;
+bad:
+return NULL;
+}
+#endif
 static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool on)
 {
 int pages;
@@ -410,12 +459,28 @@ static void __mark_pages_wc(struct azx *chip, struct snd_dma_buffer *dmab, bool
 #ifdef CONFIG_SND_DMA_SGBUF
 if (dmab->dev.type == SNDRV_DMA_TYPE_DEV_SG) {
 struct snd_sg_buf *sgbuf = dmab->private_data;
+pgprot_t prot;
+int i;
+unsigned long addr;
+pte_t * pte;
 if (chip->driver_type == AZX_DRIVER_CMEDIA)
 return; /* deal with only CORB/RIRB buffers */
-if (on)
+if (on){
 set_pages_array_wc(sgbuf->page_table, sgbuf->pages);
-else
+prot = pgprot_writecombine(PAGE_KERNEL);
+}
+else{
 set_pages_array_wb(sgbuf->page_table, sgbuf->pages);
+prot = PAGE_KERNEL;
+}
+for (i = 0; i < sgbuf->pages; i ++)
+{
+addr = (unsigned long)dmab->area + PAGE_SIZE * i;
+pte = dump_pte(addr);
+if (pte)
+set_pte_at(&init_mm, addr, pte, mk_pte(sgbuf->page_table[i], prot));
+else WARN_ON(1);
+}
 return;
 }
 #endif


保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.


More information about the Alsa-devel mailing list