Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp613414imm; Wed, 19 Sep 2018 04:16:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbNSRSjtUSmW64bdwWgxbjpCUzJkejZXdbaoi12kRMmg8taiavnNe4byZOe56HPFYVe7qh2 X-Received: by 2002:a17:902:b78a:: with SMTP id e10-v6mr34566161pls.79.1537355786862; Wed, 19 Sep 2018 04:16:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537355786; cv=none; d=google.com; s=arc-20160816; b=Z/WAi4NQklZVHHcuTeqQ38rT096HlXlT5S/OHRfCFDYwBaMptzuaQE7cfAOq1anODZ tsmYNU9nZd7cJhUwGW03ze44QAuiM7B1W3qWKuyLoCI9Kmt3Po5FA031XbpD3Uh4vNh5 FnW1TbHl0L9n+ybMJAT9FYWiYo3cj8+xDw2a+gN4ZFAH4d87K+O3bnDeddNSG7HMCxMw 9+6FZfcE/350PrEb5AHbyBYYcPdUE7ebkbtZBSyQZ2K6Ilvm/FUiEa5V4/ulWyKu4LQn pfGiog7j6kUWLZfPAwa8TCREOJM7zGSHGIIQcCESXcaqq5l2qBgCMOvLP+MCZlRk8R48 kmDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=GbNgpQ6RDlxmwwRZtEPUEsghRcDWpe1CwuLjH9t2/LA=; b=PGUc8JnVTr4zSkgPPXsCSc82LU09Z1D8bZ5HwcV9u+gTVrSVNkw2elDA3HIUFfVzdp tlBz/RdjVfMAM3+WBPWWYFCu7lrUuixAryeHtehtsRaQugHmV4JcDODNs5rGXwR1O1tH TIzMxqj6jZt2F/F8Cfa+WG7caNfoPGKnmSPdeGED6HXjrwnW+93Y4rWr2+dJkYAzqnNl JGUQPNqtJCQ2oi0xIiYprLzsOfqnH6AdLPMLzo6fzWitYcbwTp37neagFZl6P95jgCjC 8I7FVZ9KuuNXPYJt26nw5qxDnSRQKrGnsz0lt2LoIyhxey0rkmBoIfDJA+1RwZzfeDgR UqUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s21-v6si20831650pgm.651.2018.09.19.04.16.11; Wed, 19 Sep 2018 04:16:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731378AbeISQwe (ORCPT + 99 others); Wed, 19 Sep 2018 12:52:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731358AbeISQwe (ORCPT ); Wed, 19 Sep 2018 12:52:34 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2B428831D; Wed, 19 Sep 2018 11:15:08 +0000 (UTC) Received: from vitty.brq.redhat.com.redhat.com (unknown [10.43.2.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3B48E5FC24; Wed, 19 Sep 2018 11:15:02 +0000 (UTC) From: Vitaly Kuznetsov To: Ming Lei Cc: Ming Lei , linux-block , linux-mm , Linux FS Devel , "open list\:XFS FILESYSTEM" , Dave Chinner , Linux Kernel Mailing List , Christoph Hellwig , Jens Axboe Subject: Re: block: DMA alignment of IO buffer allocated from slab References: <877ejh3jv0.fsf@vitty.brq.redhat.com> <20180919100256.GD23172@ming.t460p> Date: Wed, 19 Sep 2018 13:15:00 +0200 In-Reply-To: <20180919100256.GD23172@ming.t460p> (Ming Lei's message of "Wed, 19 Sep 2018 18:02:57 +0800") Message-ID: <8736u53fij.fsf@vitty.brq.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 19 Sep 2018 11:15:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Ming Lei writes: > Hi Vitaly, > > On Wed, Sep 19, 2018 at 11:41:07AM +0200, Vitaly Kuznetsov wrote: >> Ming Lei writes: >> >> > Hi Guys, >> > >> > Some storage controllers have DMA alignment limit, which is often set via >> > blk_queue_dma_alignment(), such as 512-byte alignment for IO buffer. >> >> While mostly drivers use 512-byte alignment it is not a rule of thumb, >> 'git grep' tell me we have: >> ide-cd.c with 32-byte alignment >> ps3disk.c and rsxx/dev.c with variable alignment. >> >> What if our block configuration consists of several devices (in raid >> array, for example) with different requirements, e.g. one requiring >> 512-byte alignment and the other requiring 256? > > 512-byte alignment is also 256-byte aligned, and the sector size is 512 byte. > Yes, but it doesn't work the other way around, e.g. what if some device has e.g. PAGE_SIZE alignment requirement (this would likely imply that it's sector size is also not 512 I guess)? > > From the Red Hat BZ, looks I understand this issue is only triggered when > KASAN is enabled, or you have figured out how to reproduce it without > KASAN involved? Yes, any SLUB debug triggers it (e.g. build your kernel with SLUB_DEBUG_ON or slub_debug= options (Red zoning, User tracking, ... - everything will trigger it) > >> >> > >> > 3) If slab can't guarantee to return 512-aligned buffer, how to fix >> > this data corruption issue? >> >> I'm no expert in block layer but in case of complex block device >> configurations when bio submitter can't know all the requirements I see >> no other choice than bouncing. > > I guess that might be the last straw, given the current way without > bouncing works for decades, and seems no one complains before. Not many drivers have alignment requirements and not many filesystems do requests of this kind. Another option would be to give an API to figure out alignment requirements for the whole block stack (returning which alignment would work for _all_ devices in the stack, not just for one of them) and mandating that all users have to use this while allocating buffers. -- Vitaly