Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp5220253imm; Tue, 26 Jun 2018 07:49:27 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdvdB2fJ/cFvfSXMuWu84cPlMT9AMDW2hzrd6T/SWDvdI0fPG+p89w02eAo0D3Rvc+fcXJX X-Received: by 2002:a62:6303:: with SMTP id x3-v6mr1868218pfb.91.1530024566946; Tue, 26 Jun 2018 07:49:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530024566; cv=none; d=google.com; s=arc-20160816; b=Yg/lxhU7mBaTtAscpIBgUFTf7o1rZzSg1OcOaGM71OdtqV1hxeRbopneDs/c5xXy7D 2iq9lHylBYm0NyF+b9hZI6LRM+I2ovMCAnN+xmkE9a4sXDrexaPqIpLrgT2NKCs491wj 9I9yxS9HMQtNUXlrRw24MpfDWQiakd9B9QKY9UFGzyCjE9RVy9cVBqIKAlxvWCfWSOTb RWB9ZK9rSLkn2kaP8p0ismz+zg+YrFvfIDbizEy5zptcZVmFvp4VXzRrKCpGFE5jjrK9 8Fesfyv6K/3IWdaCdV1y+jM31E0EzKmkDX8i38EasqrGoZWRjwG/KT9fDhyStISFwV8W bfWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=2U9rvwDx6JMg3KiL9O7Ake0rzvHKTv+dyfDsH8Z04PI=; b=PAsxpgrKEItzDWBnRkhlcxqzqQRhKa5UFWuCY5i5oR9P/bpFJz8cBi55zSQsxl7OFT z5A+7l3F3vqOZlWRSzLYv48n/X61Y4J00QPp8l++cM3W5ajW7k023T+jTYS5geOk9AkQ OkkyHe+ZankbJHXFIXdKlIY3Unn/sPoxf/6lIiK07YNwVIOIgHMdqXYPy8tk4FoXkjvh mgAJ4mbZ8dbAs5AEOKkMveQjBJtBw07y9fHq0mhwi1pTcNKmU2EP5Kkopq0aFkRB2U1k lp7IuSvZG/9rJXxFhcU/SXJDX6IhJ/MdmFFSiSS5qBM2p3AXHXvC5J8vjUGYO2Rb5tty apNA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y21-v6si1621931pfm.1.2018.06.26.07.49.11; Tue, 26 Jun 2018 07:49: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936115AbeFZObx (ORCPT + 99 others); Tue, 26 Jun 2018 10:31:53 -0400 Received: from mail.netline.ch ([148.251.143.178]:52561 "EHLO netline-mail3.netline.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935535AbeFZObw (ORCPT ); Tue, 26 Jun 2018 10:31:52 -0400 Received: from localhost (localhost [127.0.0.1]) by netline-mail3.netline.ch (Postfix) with ESMTP id B9E2D2A604F; Tue, 26 Jun 2018 16:31:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at netline-mail3.netline.ch Received: from netline-mail3.netline.ch ([127.0.0.1]) by localhost (netline-mail3.netline.ch [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 8_XT_7TIJPtH; Tue, 26 Jun 2018 16:31:49 +0200 (CEST) Received: from kaveri (252.228.127.176.dynamic.wline.res.cust.swisscom.ch [176.127.228.252]) by netline-mail3.netline.ch (Postfix) with ESMTPSA id 5E4B02A604C; Tue, 26 Jun 2018 16:31:48 +0200 (CEST) Received: from daenzer by kaveri with local (Exim 4.91) (envelope-from ) id 1fXp0V-0003jL-Gd; Tue, 26 Jun 2018 16:31:47 +0200 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= To: Sumit Semwal Cc: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, amd-gfx@lists.freedesktop.org Subject: [PATCH] dma-buf: Move BUG_ON from _add_shared_fence to _add_shared_inplace Date: Tue, 26 Jun 2018 16:31:47 +0200 Message-Id: <20180626143147.14296-1-michel@daenzer.net> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michel Dänzer Fixes the BUG_ON spuriously triggering under the following circumstances: * ttm_eu_reserve_buffers processes a list containing multiple BOs using the same reservation object, so it calls reservation_object_reserve_shared with that reservation object once for each such BO. * In reservation_object_reserve_shared, old->shared_count == old->shared_max - 1, so obj->staged is freed in preparation of an in-place update. * ttm_eu_fence_buffer_objects calls reservation_object_add_shared_fence once for each of the BOs above, always with the same fence. * The first call adds the fence in the remaining free slot, after which old->shared_count == old->shared_max. In the next call to reservation_object_add_shared_fence, the BUG_ON triggers. However, nothing bad would happen in reservation_object_add_shared_inplace, since the fence is already in the reservation object. Prevent this by moving the BUG_ON to where an overflow would actually happen (e.g. if a buggy caller didn't call reservation_object_reserve_shared before). Cc: stable@vger.kernel.org Signed-off-by: Michel Dänzer --- drivers/dma-buf/reservation.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/dma-buf/reservation.c b/drivers/dma-buf/reservation.c index 314eb1071cce..532545b9488e 100644 --- a/drivers/dma-buf/reservation.c +++ b/drivers/dma-buf/reservation.c @@ -141,6 +141,7 @@ reservation_object_add_shared_inplace(struct reservation_object *obj, if (signaled) { RCU_INIT_POINTER(fobj->shared[signaled_idx], fence); } else { + BUG_ON(fobj->shared_count >= fobj->shared_max); RCU_INIT_POINTER(fobj->shared[fobj->shared_count], fence); fobj->shared_count++; } @@ -230,10 +231,9 @@ void reservation_object_add_shared_fence(struct reservation_object *obj, old = reservation_object_get_list(obj); obj->staged = NULL; - if (!fobj) { - BUG_ON(old->shared_count >= old->shared_max); + if (!fobj) reservation_object_add_shared_inplace(obj, old, fence); - } else + else reservation_object_add_shared_replace(obj, old, fobj, fence); } EXPORT_SYMBOL(reservation_object_add_shared_fence); -- 2.18.0