mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: 陈华才 <chenhc@lemote.com>
To: "Sergei Shtylyov" <sergei.shtylyov@cogentembedded.com>,
	"Christoph Hellwig" <hch@lst.de>
Cc: "Marek Szyprowski" <m.szyprowski@samsung.com>,
	"Robin Murphy" <robin.murphy@arm.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Fuxin Zhang" <zhangfx@lemote.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	"Ralf Baechle" <ralf@linux-mips.org>,
	"James Hogan" <james.hogan@imgtec.com>,
	linux-mips <linux-mips@linux-mips.org>,
	"James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi <linux-scsi@vger.kernel.org>,
	"Tejun Heo" <tj@kernel.org>,
	linux-ide <linux-ide@vger.kernel.org>,
	stable <stable@vger.kernel.org>
Subject: Re: [PATCH V8 5/5] libata: Align DMA buffer todma_get_cache_alignment()
Date: Wed, 18 Oct 2017 09:06:58 +0800	[thread overview]
Message-ID: <tencent_46A6508471A99D3A2C36B139@qq.com> (raw)
In-Reply-To: <94f55c1e-7553-0fc8-124e-ac6df5ac10ce@cogentembedded.com>

Hi, Sergei,

Without this patch, in non-coherent mode, ata_do_set_mode() return with "no PIO support", and disk detection fails.

Huacai
 
 
------------------ Original ------------------
From:  "Sergei Shtylyov"<sergei.shtylyov@cogentembedded.com>;
Date:  Tue, Oct 17, 2017 05:43 PM
To:  "Huacai Chen"<chenhc@lemote.com>; "Christoph Hellwig"<hch@lst.de>; 
Cc:  "Marek Szyprowski"<m.szyprowski@samsung.com>; "Robin Murphy"<robin.murphy@arm.com>; "Andrew Morton"<akpm@linux-foundation.org>; "Fuxin Zhang"<zhangfx@lemote.com>; "linux-kernel"<linux-kernel@vger.kernel.org>; "Ralf Baechle"<ralf@linux-mips.org>; "James Hogan"<james.hogan@imgtec.com>; "linux-mips"<linux-mips@linux-mips.org>; "James E . J . Bottomley"<jejb@linux.vnet.ibm.com>; "Martin K . Petersen"<martin.petersen@oracle.com>; "linux-scsi"<linux-scsi@vger.kernel.org>; "Tejun Heo"<tj@kernel.org>; "linux-ide"<linux-ide@vger.kernel.org>; "stable"<stable@vger.kernel.org>; 
Subject:  Re: [PATCH V8 5/5] libata: Align DMA buffer todma_get_cache_alignment()

 
On 10/17/2017 11:05 AM, Huacai Chen wrote:

> In non-coherent DMA mode, kernel uses cache flushing operations to
> maintain I/O coherency, so in ata_do_dev_read_id() the DMA buffer
> should be aligned to ARCH_DMA_MINALIGN. Otherwise, If a DMA buffer
> and a kernel structure share a same cache line, and if the kernel
> structure has dirty data, cache_invalidate (no writeback) will cause
> data corruption.
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Huacai Chen <chenhc@lemote.com>
> ---
>   drivers/ata/libata-core.c | 15 +++++++++++++--
>   1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index ee4c1ec..e134955 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -1833,8 +1833,19 @@ static u32 ata_pio_mask_no_iordy(const struct ata_device *adev)
>   unsigned int ata_do_dev_read_id(struct ata_device *dev,
>   					struct ata_taskfile *tf, u16 *id)
>   {
> -	return ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE,
> -				     id, sizeof(id[0]) * ATA_ID_WORDS, 0);
> +	u16 *devid;
> +	int res, size = sizeof(u16) * ATA_ID_WORDS;
> +
> +	if (IS_ALIGNED((unsigned long)id, dma_get_cache_alignment(&dev->tdev)))
> +		res = ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE, id, size, 0);
> +	else {
> +		devid = kmalloc(size, GFP_KERNEL);
> +		res = ata_exec_internal(dev, tf, NULL, DMA_FROM_DEVICE, devid, size, 0);
> +		memcpy(id, devid, size);
> +		kfree(devid);
> +	}
> +
> +	return res;

    This function is called only for the PIO mode commands, so I doubt this is 
necessary...

MBR, Sergei

  reply	other threads:[~2017-10-18  1:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-17  8:05 [PATCH V8 1/5] dma-mapping: Rework dma_get_cache_alignment() Huacai Chen
2017-10-17  8:05 ` [PATCH V8 2/5] MIPS: Implement dma_map_ops::get_cache_alignment() Huacai Chen
2017-10-17  8:05 ` [PATCH V8 3/5] scsi: Align block queue to dma_get_cache_alignment() Huacai Chen
2017-10-19 15:10   ` Christoph Hellwig
2017-10-17  8:05 ` [PATCH V8 4/5] libsas: Align SMP req/resp " Huacai Chen
2017-10-17 11:55   ` Marek Szyprowski
2017-10-18  1:12     ` [PATCH V8 4/5] libsas: Align SMP req/resp todma_get_cache_alignment() 陈华才
2017-10-19 15:12     ` [PATCH V8 4/5] libsas: Align SMP req/resp to dma_get_cache_alignment() Christoph Hellwig
2017-10-20  0:04   ` kbuild test robot
2017-10-17  8:05 ` [PATCH V8 5/5] libata: Align DMA buffer " Huacai Chen
2017-10-17  9:43   ` Sergei Shtylyov
2017-10-18  1:06     ` 陈华才 [this message]
2017-10-18 19:54     ` Alan Cox
2017-10-18 13:03   ` Tejun Heo
2017-10-19  7:52     ` Matt Redfearn
2017-10-20  4:25       ` [PATCH V8 5/5] libata: Align DMA buffer todma_get_cache_alignment() 陈华才
2017-10-18 17:23 ` [PATCH V8 1/5] dma-mapping: Rework dma_get_cache_alignment() Mark Greer
2017-10-19 15:09   ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_46A6508471A99D3A2C36B139@qq.com \
    --to=chenhc@lemote.com \
    --cc=akpm@linux-foundation.org \
    --cc=hch@lst.de \
    --cc=james.hogan@imgtec.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=martin.petersen@oracle.com \
    --cc=ralf@linux-mips.org \
    --cc=robin.murphy@arm.com \
    --cc=sergei.shtylyov@cogentembedded.com \
    --cc=stable@vger.kernel.org \
    --cc=tj@kernel.org \
    --cc=zhangfx@lemote.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®