From patchwork Thu Jan 20 12:59:06 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 79690 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EFD3BB70DA for ; Thu, 20 Jan 2011 23:59:20 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755551Ab1ATM7N (ORCPT ); Thu, 20 Jan 2011 07:59:13 -0500 Received: from mail-fx0-f46.google.com ([209.85.161.46]:49321 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755549Ab1ATM7M (ORCPT ); Thu, 20 Jan 2011 07:59:12 -0500 Received: by fxm20 with SMTP id 20so548392fxm.19 for ; Thu, 20 Jan 2011 04:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-disposition:in-reply-to :user-agent; bh=+YiLFsGaoGobSr7r+GivnJE3o1yiW1vp5CZKLvYT5ak=; b=tymLNAXrR3A4KlM4W3xCGRbLF7JvZld5q+FSYpSLwYs5z8USyN80yTjd/RD+v3Rd/x wzr5z5z02jwNTkYMXybCICE7e9fyzFbM0yueErjLZMzunRJEUwpmdfAMNrVy8oKwhBCL K0zl84uicZYl0OCh4FNOro7NFoqOAweBItkYE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=IwgfSKO+XyDlOCZxiIKad2Q44xpSNi5nPEbDAVJc1b42s4EWwUgA9u6bqMlv4cXVHm 6gmzWYleNdOGqSDCl9Kt5dY95MWQ3gTfR8679zXPa/e3rbyepeqDzZCGwGCgqcd0kFJL ZuFtlmkBona03hse9wC55YG2XakwKMyETnr+Q= Received: by 10.103.239.17 with SMTP id q17mr1162794mur.17.1295528350607; Thu, 20 Jan 2011 04:59:10 -0800 (PST) Received: from htj.dyndns.org ([130.75.117.88]) by mx.google.com with ESMTPS id l3sm599950fan.0.2011.01.20.04.59.08 (version=SSLv3 cipher=RC4-MD5); Thu, 20 Jan 2011 04:59:09 -0800 (PST) Date: Thu, 20 Jan 2011 13:59:06 +0100 From: Tejun Heo To: Jeff Garzik , John Stanley , linux-ide@vger.kernel.org Cc: Hannes Reinecke , Robby Workman , Greg KH , linux-hotplug@vger.kernel.org, stable@kernel.org Subject: [PATCH #upstream-fixes] libata: set queue DMA alignment to sector size for ATAPI too Message-ID: <20110120125906.GH6036@htj.dyndns.org> References: <4D263BF6.6050305@verizon.net> <20110106222927.GA32216@kroah.com> <20110106201327.4020ab64@liberty> <4D2ABEE4.6040408@suse.de> <20110111132545.GA30607@htj.dyndns.org> <4D33BF7A.3070801@verizon.net> <20110117152733.GE27123@htj.dyndns.org> <4D34E4F1.7060600@verizon.net> <20110118150932.GM27123@htj.dyndns.org> <4D374796.1010009@verizon.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4D374796.1010009@verizon.net> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-ide-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ide@vger.kernel.org ata_pio_sectors() expects buffer for each sector to be contained in a single page; otherwise, it ends up overrunning the first page. This is achieved by setting queue DMA alignment. If sector_size is smaller than PAGE_SIZE and all buffers are sector_size aligned, buffer for each sector is always contained in a single page. This wasn't applied to ATAPI devices but IDENTIFY_PACKET is executed as ATA_PROT_PIO and thus uses ata_pio_sectors(). Newer versions of udev issue IDENTIFY_PACKET with unaligned buffer triggering the problem and causing oops. This patch fixes the problem by setting sdev->sector_size to ATA_SECT_SIZE on ATATPI devices and always setting DMA alignment to sector_size. While at it, add a warning for the unlikely but still possible scenario where sector_size is larger than PAGE_SIZE, in which case the alignment wouldn't be enough. Signed-off-by: Tejun Heo Reported-by: John Stanley Tested-by: John Stanley Cc: stable@kernel.org --- drivers/ata/libata-scsi.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ide" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c index 5defc74..600f635 100644 --- a/drivers/ata/libata-scsi.c +++ b/drivers/ata/libata-scsi.c @@ -1099,9 +1099,9 @@ static int ata_scsi_dev_config(struct scsi_device *sdev, struct request_queue *q = sdev->request_queue; void *buf; - /* set the min alignment and padding */ - blk_queue_update_dma_alignment(sdev->request_queue, - ATA_DMA_PAD_SZ - 1); + sdev->sector_size = ATA_SECT_SIZE; + + /* set DMA padding */ blk_queue_update_dma_pad(sdev->request_queue, ATA_DMA_PAD_SZ - 1); @@ -1115,13 +1115,25 @@ static int ata_scsi_dev_config(struct scsi_device *sdev, blk_queue_dma_drain(q, atapi_drain_needed, buf, ATAPI_MAX_DRAIN); } else { - /* ATA devices must be sector aligned */ sdev->sector_size = ata_id_logical_sector_size(dev->id); - blk_queue_update_dma_alignment(sdev->request_queue, - sdev->sector_size - 1); sdev->manage_start_stop = 1; } + /* + * ata_pio_sectors() expects buffer for each sector to not cross + * page boundary. Enforce it by requiring buffers to be sector + * aligned, which works iff sector_size is not larger than + * PAGE_SIZE. ATAPI devices also need the alignment as + * IDENTIFY_PACKET is executed as ATA_PROT_PIO. + */ + if (sdev->sector_size > PAGE_SIZE) + ata_dev_printk(dev, KERN_WARNING, + "sector_size=%u > PAGE_SIZE, PIO may malfunction\n", + sdev->sector_size); + + blk_queue_update_dma_alignment(sdev->request_queue, + sdev->sector_size - 1); + if (dev->flags & ATA_DFLAG_AN) set_bit(SDEV_EVT_MEDIA_CHANGE, sdev->supported_events);