Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3688089ybl; Fri, 20 Dec 2019 13:50:06 -0800 (PST) X-Google-Smtp-Source: APXvYqzu6aZvZBUEr2lS9ut/SDxQxaDm+CSZ67uEs9dWFLEHChVvNJ6KroyR9+V93t3p0M8q0eDY X-Received: by 2002:a9d:1d07:: with SMTP id m7mr17520875otm.261.1576878605957; Fri, 20 Dec 2019 13:50:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576878605; cv=none; d=google.com; s=arc-20160816; b=OK73ht6k1v+WWNgZxZbdxuy/0FtnR2BsbixbMjQuzjgm/3e/RoqKY/gbVxu4BcwF8c 39gC0cg8n0fG64vikkWT0xFccQRrXHEkwWTtCmvMBCeuYabixJfhOOctCxNH1e5PFi3e n/dA2+2JORH/SIr42rX8YUCp2dlb+BfBjvxfoTqSOTsvw1Hp/3TCtfgCHIPdn2nTId+m l4OgI8cWdLVK6eGJ8ageuJFXK+lYBF4k5M9iaDYsvSoNXZIWtvrbwll19RqF9J1nQrbr 76VGknXS0702U+aX9boqkSTWRNJKUhrxzsG66JfjhGZQCcVDskDt+P0wcB6NRU3szbIp p7Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SCnpICgEJeNeCv47il/wnhnHnvIZwSGzZQhEEwYiGvo=; b=P+YddpKrbbC0kNbdnYN84HgjToCBM0ZSBJyizP5LHYxnRkuAmAlcw1ArexLwYZ+FlK MluE3CEOKBib5mO3gnaZY3V02eXC0WHgKRybRE6l9FpuZg9aGG8iNQiw5V5iYlxepo5j JCUd6dr2F+0rCC6MV+clc04tDXB4l59N1wNoUn2Vz6y+fJkj+3E9VKoSCrw0vBoW0XYl toBRpnGc04UcgHeqBehBYI3P8FeHodE0fuRqBEi6PibXgd14XQlVFR7ev14VrQO2p5bM u28jHCS/Yx7u3pIMHnoJdOszev4SIPCstzuWiZONbnDS7KECbSf5VlDM2NjSs30YWKnM 3xAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b1buLVrc; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j18si5809984otq.275.2019.12.20.13.49.53; Fri, 20 Dec 2019 13:50:05 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=b1buLVrc; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727565AbfLTVr5 (ORCPT + 99 others); Fri, 20 Dec 2019 16:47:57 -0500 Received: from mail-pg1-f196.google.com ([209.85.215.196]:32872 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727422AbfLTVr5 (ORCPT ); Fri, 20 Dec 2019 16:47:57 -0500 Received: by mail-pg1-f196.google.com with SMTP id 6so5601655pgk.0 for ; Fri, 20 Dec 2019 13:47:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=SCnpICgEJeNeCv47il/wnhnHnvIZwSGzZQhEEwYiGvo=; b=b1buLVrcIi2WUUxWLFoeLQb9FVcK1qgS9/fBzOXy6UhFYggw0shBZ1DqaV/Bsj0d8s 5pT6WYnteJrzsDqr7s+PqHusfKSAa49ZtKdwFSzgdgLcgiKmVUcxeaPkQgqTl7SeCaEu +HRk+myRoT900y/IzJdXsRLKaVx1VPsm5X6CSfrwnFqUSnwDdlosV7JDPSPPiXN5aFtu 2c260ZOjgZENiZ6tICIFwYInxRejB1puQ6hKEmhv4lEJDHqQ94qNwBdI7212s+XohNMn Cz15+VxW7lP2DaBPRMqEHkfta2iiQInxCPhhWPmCFqFAdI4fwSjEsQ+msR6aG3yDu1pA Q4RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=SCnpICgEJeNeCv47il/wnhnHnvIZwSGzZQhEEwYiGvo=; b=WudkYEZ1aYH0TrQvZzAgiPW4AiXlr9UPk3IJMQuLHBFBXJUjP+qF5TWfFORmMFshhd R+Ba+6fBc0JFglgJMJ7A/yvu/iEr/7gS3hyValsERJIJWwVf4oxnP7JRQjerCAkBelcN qQw270e+00vTLQ3+AZ+VTgubv2QzU2pBbPSshh0jxeppGjdH1HL8Ex2gJF2MFAmJ7ZgJ R9HDSihBzi+9BY7dwdypfKWtF8Us3p4k+BD1hrRUBkg4RUTxriJZHKcnBHM7LcIrxxjz J0tEkmk4yB5u2q4XWIjLn6Q27hNQLEnH+2snAUiC7rpMj7pf16P/z0DOupywNvrNGBrT jHgw== X-Gm-Message-State: APjAAAWwge386Kyvx4ULtgujtHXS7ip/IBxbjMIAjbHsfMapvaVLuB4u 8UypqtVHOZXcQCXTPmVKO5A= X-Received: by 2002:a65:5242:: with SMTP id q2mr4224476pgp.74.1576878475976; Fri, 20 Dec 2019 13:47:55 -0800 (PST) Received: from dtor-ws ([2620:15c:202:201:3adc:b08c:7acc:b325]) by smtp.gmail.com with ESMTPSA id z64sm14237771pfz.23.2019.12.20.13.47.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Dec 2019 13:47:54 -0800 (PST) Date: Fri, 20 Dec 2019 13:47:52 -0800 From: Dmitry Torokhov To: Alexey Brodkin Cc: Peter Zijlstra , Will Deacon , Marc Gonzalez , Eugeniy Paltsev , Greg Kroah-Hartman , Vineet Gupta , Rafael Wysocki , LKML , Bjorn Andersson , Russell King , Mark Brown , Tejun Heo , arcml , Robin Murphy , Linux ARM Subject: Re: [RFC PATCH v1] devres: align devres.data strictly only for devm_kmalloc() Message-ID: <20191220214752.GB8314@dtor-ws> References: <74ae22cd-08c1-d846-3e1d-cbc38db87442@free.fr> <20191220140655.GN2827@hirez.programming.kicks-ass.net> <9be1d523-e92c-836b-b79d-37e880d092a0@arm.com> <20191220202346.GT2827@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 20, 2019 at 09:02:24PM +0000, Alexey Brodkin wrote: > Hi Peter, > > > > Well it somehow used to work for quite some time now with the data-buffer > > > being allocated with 4 words offset (which is 16 bytes for 32-bit platform > > > > 3 words, devres_node is 3 words. > > Correct, but 4th word was implicitly there due to the fact > on most of 32-bit arches "long long" is aligned by 2 words. > > > Which is exactly why we had to change it, the odd alignment caused ARC > > to explode. > > I know that better than anybody else as it was my pain & grief :) > > > > and 32 for 64-bit which is still much less than mentioned 128 bytes). > > > Or we just never managed to identify those rare cases when data corruption > > > really happened? > > > > The races are rather rare methinks, you'd have to get a list-op > > concurrently with a DMA. > > > > If you get the list corrupted, I'm thinking the crash is fairly likely, > > albeit really difficuly to debug. > > So that alone IMHO is a good reason to not allow that thing to happen even > in theory. > > > > > No matter which way round you allocate devres and data, by necessity > > > > they're always going to consume the same total amount of memory. > > > > > > So then the next option I guess is to separate meta-data from data buffers > > > completely. Are there any reasons to not do that > > > > Dunno, should work just fine I think. > > > > > other than the hack we're > > > discussing here (meta-data in the beginning of the buffer) used to work OK-ish? > > > > If meta-data at the beginngin used to work, I don't see why meta-data at > > the end wouldn't work equally well. They'd be equally broken. No, not really. With data being ARCH_KMALLOC_MINALIGN and coming after the devres private stuff, given that the another allocation will also be aligned to ARCH_KMALLOC_MINALIGN (because that's what k*alloc will give us) we are guaranteed that DMA will not stomp onto any unrelated data. With devres private coming after data and not having any alignment constraints we may very well clobber it when doing DMA. BTW, I am not sure where the page size restriction you mentioned earlier is coming from. We have been using kmalloc()ed memory as buffers suitable for DMA since forever, and we only need to make sure such data is isolated from other data CPU might be accessing by ARCH_DMA_MINALIGN which is usually L1 cache size. From Documentation/DMA-API-HOWTO.txt: 2) ARCH_DMA_MINALIGN Architectures must ensure that kmalloc'ed buffer is DMA-safe. Drivers and subsystems depend on it. If an architecture isn't fully DMA-coherent (i.e. hardware doesn't ensure that data in the CPU cache is identical to data in main memory), ARCH_DMA_MINALIGN must be set so that the memory allocator makes sure that kmalloc'ed buffer doesn't share a cache line with the others. See arch/arm/include/asm/cache.h as an example. Note that ARCH_DMA_MINALIGN is about DMA memory alignment constraints. You don't need to worry about the architecture data alignment constraints (e.g. the alignment constraints about 64-bit objects). > > Agree. But if we imagine devm allocations are not used for DMA > (which is yet another case of interface usage which was never designed for > but alas this happens left and right) then move of the meta-data to the end of > the buffers solves [mostly my] problem... but given that DMA case we discuss > exists I'm not sure if this move actually worth spending time on. Well, there is a metric ton of devm users that do not allocate memory buffers, but other objects, and for which we do not need to worry about alignment. Thanks. -- Dmitry