From patchwork Fri Aug 24 10:30:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 145060 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp1119856ljw; Fri, 24 Aug 2018 03:31:27 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYKwjLymTKHyvDSjNbozKF2Soxg8Ekk5Rwk10C9euxBEZOw7AbfhqZNFvIR3y+RLHjJLhF6 X-Received: by 2002:a50:871c:: with SMTP id i28-v6mr1922279edb.13.1535106687650; Fri, 24 Aug 2018 03:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535106687; cv=none; d=google.com; s=arc-20160816; b=BatS/TzUCpz2Gey5WR/TriofUflEaLNMrn/2rNd8xif+HXBDgoo4mbG593YeO+nzXp ffy9+1NPz5DfE4G/kT6sLwBahB95Ysy9BDBTpO40NrqBnDTyLBqdd9X2IJbzZSCSrnHe 76mca+8ZLMNdYufgLhTpb+2nwEhqjV8FL9XDI4+xc6n8irZe+beEqIg+4P0H09WvJtNz 9AM4zb0OhzWy+2W7NxbJJXQhMkIW0dJrQKyeyyZIGE/DCQpFIq5Uc7ZzhLlpxzk10Sc2 NEdwlNcA7QYv8q1ftSBT6t1B+knPc3pzZDePpTDCNKF5fmV3Q6aplPLva6XuJ9J0tuIS Jd9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:dkim-filter:arc-authentication-results; bh=x0bSSshQfKoTbwfWZAYIGIEPfE8CcFK31rFmzE5wcx4=; b=o0inU1IHKNfzsqYXXfThiwgJdnTciX2so6+es2CMRIZCXZXF647cYbNLOQFDLp7Is3 aezBHiAuQjBEhYdf7qDLzTyyHtGOQy28DtbmbE7OPbVixoOczcyKFL/Rc7I8AVa2BVSx +J8BHghlQfIs7bpxf4oO5E61KFIpPlUPZERSfm1Vqg/x2IUzgz86EudZBjkAnaEskDmZ T/pLkeXT87vKEwHbjakprktMUxwppvhyBEiRy3xZWYrAH5LKMiY3iMLcBh0UVXkxG2i5 MBk5Xh4wPODKvMN/Oxot83ObVnvLWuWqpcmC3xMiY8f5AGZ9DevGO3l9rgQpTkcDvXik BeNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=LQ+sP4f5; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id w23-v6si5738505edw.115.2018.08.24.03.31.26; Fri, 24 Aug 2018 03:31:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=LQ+sP4f5; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id C1774C21E39; Fri, 24 Aug 2018 10:31:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 30ED5C21D8A; Fri, 24 Aug 2018 10:31:21 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 0791EC21D8A; Fri, 24 Aug 2018 10:31:19 +0000 (UTC) Received: from conuserg-09.nifty.com (conuserg-09.nifty.com [210.131.2.76]) by lists.denx.de (Postfix) with ESMTPS id C079CC21CB1 for ; Fri, 24 Aug 2018 10:31:18 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id w7OAURhd017730; Fri, 24 Aug 2018 19:30:28 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com w7OAURhd017730 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1535106628; bh=BzYxMauc9uceavQ+D+SfjTLlPClx84cYq3Sm3ZBOaeo=; h=From:To:Cc:Subject:Date:From; b=LQ+sP4f5RurOcX53cXpFw6xXrDOIa40LvXneBBSGo0NoOTstVi9ked3c/rppLh80S aZzY6lwdRQOjtiZ3pO0enrvJox4epaIy/hpL78rU5KkSs4NBUKWal3tDUEwlXcogXn 8Uo4G1XvHKqkBQVhgQbpuFT9eyHvowOJa7DG7umIUepSRQWp1U1pGg3gGVQG/9olJh uvo+dfu7R41rrxQwWnkcDQWkcBi1rvvkdBVvI7BMnchyhfJobCD2wkltLD6ZX4+Y6q JxG5EyyZ1db8Hvu/HC7c3Th2el51+A6EjB1tWjHzmdpHwdjBt38HgCU1dP0dhpRgVS PrKSA0cOqjl4w== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Fri, 24 Aug 2018 19:30:15 +0900 Message-Id: <1535106615-24282-1-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 Cc: Tom Rini , Marek Vasut Subject: [U-Boot] [PATCH] Make kmalloc'ed memory really DMA-safe X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" In Linux, the memory returned by kmalloc() is DMA-capable. However, it is not true in U-Boot. At a glance, kmalloc() in U-Boot returns address aligned with ARCH_DMA_MINALIGN. However, it never pads the allocated memory. This half-way house is completely useless because calling kmalloc() and malloc() in this order causes a cache sharing problem. Change the implementation to call malloc_cache_aligned(), which allocates really DMA-capable memory. Signed-off-by: Masahiro Yamada --- lib/linux_compat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/linux_compat.c b/lib/linux_compat.c index a936a7e..6373b44 100644 --- a/lib/linux_compat.c +++ b/lib/linux_compat.c @@ -1,5 +1,6 @@ #include +#include #include struct p_current cur = { @@ -18,7 +19,7 @@ void *kmalloc(size_t size, int flags) { void *p; - p = memalign(ARCH_DMA_MINALIGN, size); + p = malloc_cache_aligned(size); if (flags & __GFP_ZERO) memset(p, 0, size); @@ -37,5 +38,5 @@ struct kmem_cache *get_mem(int element_sz) void *kmem_cache_alloc(struct kmem_cache *obj, int flag) { - return memalign(ARCH_DMA_MINALIGN, obj->sz); + return malloc_cache_aligned(obj->sz); }