From patchwork Tue Feb 27 11:49:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_K=C3=B6nig?= X-Patchwork-Id: 10244967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4ECA160211 for ; Tue, 27 Feb 2018 11:50:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43457288A9 for ; Tue, 27 Feb 2018 11:50:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30D512890A; Tue, 27 Feb 2018 11:50:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81817288A9 for ; Tue, 27 Feb 2018 11:50:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 33F5E6E63B; Tue, 27 Feb 2018 11:50:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x241.google.com (mail-wr0-x241.google.com [IPv6:2a00:1450:400c:c0c::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id 57A546E638; Tue, 27 Feb 2018 11:50:03 +0000 (UTC) Received: by mail-wr0-x241.google.com with SMTP id v111so12319393wrb.3; Tue, 27 Feb 2018 03:50:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=tARgID4o35BByXE6PvUTyoQC+h9kUFdujv+Ow8lZDDw=; b=IfQ27t24CsgjC0msUUX3upXO8QN6lY0P8Ab90TRtYHXGhNvx1Y8qC7IcQzeP1od0sQ om6tSnhxwA9qANMOZhX0pC7DJOalUY7UcI8QpSfAcm3bwmbYkjK0+cwV5lEDrYRqIPoU HoIEMIhhMYG4aUCUnUw9SfphKtk3T9jbbW/4+fU9fP6U+UA5+8/FpGfNnLwwveHtd0DT udBaNf7kc81PMDMIzYi6m+3Uh/BPaPZye/pqXLRuW5oJfhvc3OEogkyTelrdDZDVfKLv SpLjrQpoDagklHGyXllJcdk+bL7QhTnV/CNhv6O0l3kJlijczdxu+7zDsTO0Zxl/DRSd IJWg== 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:mime-version :content-transfer-encoding; bh=tARgID4o35BByXE6PvUTyoQC+h9kUFdujv+Ow8lZDDw=; b=K1wrNDBVfuN2z+PsmZdUIpbmsnnrv4Cwzt0AeAROYn3VRjVAgxEFA1s7HY7XBLTFD0 VhFTzA+4ESccqLKp3jeQEWobPNfdTMTcM/lvni80PjzHMLJduQuQ0EJ3fjhOvl/zCbwj GtZ+ERQxNnps5r5Td964iZ1f+BPg7aAuclXFHv9/hDJ2IyY2SUrfjbSm0mSd7C4waDvp 7houbSnPItq9td4NepRXWoZC1XmSmM228QHr2SaPWJnTSK0P72SPObXuh25NB5eEBEH1 qB5RgaKdJdhjstDutRrSt/dLWdgNLfMetMsaa78VK2uh/lFWW6j+y311O24QAp8G1gXK hqcA== X-Gm-Message-State: APf1xPDo22bkkqSEM+qXbNFqN6MFDyyyC477WOk3ftvYzMmr8gJWO9bX YuYK3IINX9/yAP/4vICwqGT/rg== X-Google-Smtp-Source: AG47ELsq3KbsKa61d+OrNR822tukFM7jlmMEKoanz2NP1RVy2sSlnEq8ZrXAvv3TylMiMHpeRv3Yxw== X-Received: by 10.223.156.206 with SMTP id h14mr9074492wre.281.1519732201669; Tue, 27 Feb 2018 03:50:01 -0800 (PST) Received: from baker.fritz.box ([2a02:908:1251:8fc0:652a:9b33:8ae4:9f2c]) by smtp.gmail.com with ESMTPSA id k2sm8618568wmf.10.2018.02.27.03.50.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Feb 2018 03:50:01 -0800 (PST) From: "=?UTF-8?q?Christian=20K=C3=B6nig?=" X-Google-Original-From: =?UTF-8?q?Christian=20K=C3=B6nig?= To: dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org Subject: [PATCH 1/5] drm/prime: fix potential race in drm_gem_map_detach Date: Tue, 27 Feb 2018 12:49:56 +0100 Message-Id: <20180227115000.4105-1-christian.koenig@amd.com> X-Mailer: git-send-email 2.14.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Unpin the GEM object only after freeing the sg table. Signed-off-by: Christian König Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_prime.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c index e82a976f0fba..c38dacda6119 100644 --- a/drivers/gpu/drm/drm_prime.c +++ b/drivers/gpu/drm/drm_prime.c @@ -230,26 +230,26 @@ void drm_gem_map_detach(struct dma_buf *dma_buf, struct drm_prime_attachment *prime_attach = attach->priv; struct drm_gem_object *obj = dma_buf->priv; struct drm_device *dev = obj->dev; - struct sg_table *sgt; - if (dev->driver->gem_prime_unpin) - dev->driver->gem_prime_unpin(obj); + if (prime_attach) { + struct sg_table *sgt = prime_attach->sgt; - if (!prime_attach) - return; - - sgt = prime_attach->sgt; - if (sgt) { - if (prime_attach->dir != DMA_NONE) - dma_unmap_sg_attrs(attach->dev, sgt->sgl, sgt->nents, - prime_attach->dir, - DMA_ATTR_SKIP_CPU_SYNC); - sg_free_table(sgt); + if (sgt) { + if (prime_attach->dir != DMA_NONE) + dma_unmap_sg_attrs(attach->dev, sgt->sgl, + sgt->nents, + prime_attach->dir, + DMA_ATTR_SKIP_CPU_SYNC); + sg_free_table(sgt); + } + + kfree(sgt); + kfree(prime_attach); + attach->priv = NULL; } - kfree(sgt); - kfree(prime_attach); - attach->priv = NULL; + if (dev->driver->gem_prime_unpin) + dev->driver->gem_prime_unpin(obj); } EXPORT_SYMBOL(drm_gem_map_detach);