From patchwork Thu Aug 8 00:43:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: dann frazier X-Patchwork-Id: 1143760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 463qP01fctz9sNk; Thu, 8 Aug 2019 10:43:32 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1hvWWZ-00016G-5q; Thu, 08 Aug 2019 00:43:23 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1hvWWW-00015r-TY for kernel-team@lists.ubuntu.com; Thu, 08 Aug 2019 00:43:20 +0000 Received: from mail-ot1-f70.google.com ([209.85.210.70]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1hvWWW-0000mc-GF for kernel-team@lists.ubuntu.com; Thu, 08 Aug 2019 00:43:20 +0000 Received: by mail-ot1-f70.google.com with SMTP id w5so58310883otg.0 for ; Wed, 07 Aug 2019 17:43:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VZ0jMaIcE+l2FEs59NHUKdGqMwZI6y8ZnbEdFsuRGjI=; b=DbYqNUqm8/5Pp4ri9Ss1sZNAfntRtKuQ//veNe3F6DuLNi7Yr76wvi4logm2+lAbDt qm7gd82lQ8X5tRg7E7tdwdFyBe4IdXggG1MPMlQkSaLOhyqpFbP7m1NhF4ryano6oag0 RWuFrSX3gz7uw25eRAIlYIrHt1PpCPyAR1cCHVzT+dLuaqiDIQH29nQ2QRmNb6P1bik8 Tt5qpVwmLubBhOWDmtciBI/V+PXnzz1Pm7IjW3S3hsC+LqU63yXT0NNwYe5S9NUXS5Hf PFEOTK7vxKySfizVUHrOs2VIC0QZ6DJWbJwMeyMIhjgZml1gv9PkvFQx0OMeLmbSQLxC ENbA== X-Gm-Message-State: APjAAAVlYkl9oMtUyuVkRIsARvfg8qN+2FeSgUuxY4CmM9fhl5whBESS 8yEvzJlHAL2VtUc+592Hep4gryGCSXrZ3x6kIDyIKGHr+Xj4aHGHllxIKSEaHMHWRINjWCyESiu x2CmV69Uzs9cAFcoxX5rkbJKQK34Dipe/72X2EtHkhg== X-Received: by 2002:a5d:9643:: with SMTP id d3mr12755186ios.227.1565224999364; Wed, 07 Aug 2019 17:43:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyAXg0TI/a+Yx5qM/CDOm1VauINSRKhgKyUZtQlmh/+52aEtyQrAU2oQPvXjwIxKPfbvEhrsA== X-Received: by 2002:a5d:9643:: with SMTP id d3mr12755162ios.227.1565224999098; Wed, 07 Aug 2019 17:43:19 -0700 (PDT) Received: from xps13.canonical.com (c-71-56-235-36.hsd1.co.comcast.net. [71.56.235.36]) by smtp.gmail.com with ESMTPSA id c81sm143745915iof.28.2019.08.07.17.43.18 for (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 07 Aug 2019 17:43:18 -0700 (PDT) From: dann frazier To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/2][Eoan][SRU Disco] dma-contiguous: do not overwrite align in dma_alloc_contiguous() Date: Wed, 7 Aug 2019 18:43:13 -0600 Message-Id: <20190808004314.16433-2-dann.frazier@canonical.com> X-Mailer: git-send-email 2.23.0.rc1 In-Reply-To: <20190808004314.16433-1-dann.frazier@canonical.com> References: <20190808004314.16433-1-dann.frazier@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Nicolin Chen BugLink: https://bugs.launchpad.net/bugs/1839395 The dma_alloc_contiguous() limits align at CONFIG_CMA_ALIGNMENT for cma_alloc() however it does not restore it for the fallback routine. This will result in a size mismatch between the allocation and free when running into the fallback routines after cma_alloc() fails, if the align is larger than CONFIG_CMA_ALIGNMENT. This patch adds a cma_align to take care of cma_alloc() and prevent the align from being overwritten. Fixes: fdaeec198ada ("dma-contiguous: add dma_{alloc,free}_contiguous() helpers") Reported-by: Dafna Hirschfeld Signed-off-by: Nicolin Chen Signed-off-by: Christoph Hellwig (cherry picked from commit c6622a425acd1d2f3a443cd39b490a8777b622d7) Signed-off-by: dann frazier --- kernel/dma/contiguous.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kernel/dma/contiguous.c b/kernel/dma/contiguous.c index bfc0c17f2a3d4..ea8259f53eda7 100644 --- a/kernel/dma/contiguous.c +++ b/kernel/dma/contiguous.c @@ -243,8 +243,9 @@ struct page *dma_alloc_contiguous(struct device *dev, size_t size, gfp_t gfp) /* CMA can be used only in the context which permits sleeping */ if (cma && gfpflags_allow_blocking(gfp)) { - align = min_t(size_t, align, CONFIG_CMA_ALIGNMENT); - page = cma_alloc(cma, count, align, gfp & __GFP_NOWARN); + size_t cma_align = min_t(size_t, align, CONFIG_CMA_ALIGNMENT); + + page = cma_alloc(cma, count, cma_align, gfp & __GFP_NOWARN); } /* Fallback allocation of normal pages */