From patchwork Thu Jan 7 21:15:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 358296 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp812960jai; Thu, 7 Jan 2021 13:15:29 -0800 (PST) X-Received: by 2002:a63:5309:: with SMTP id h9mr3691964pgb.19.1610054129133; Thu, 07 Jan 2021 13:15:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610054129; cv=none; d=google.com; s=arc-20160816; b=tKUBnMFx0JZSDiQg8SLOR0WNvX17fULhTj900zJezp7XFF3GycSxVqTz5FyhH41Wyi CTEP8tv2zwh62CxMgV2qOD+vyOf5xUJVTTrQE+tiEeaaJ6cLZDbEX51j5fCtuglDBxuq gO8BXvuK+ARgZAdDZVyHvGR3qmComgPQaUNNFSzxsSkyDj8RgTtqZ4a/Xh5PojgbgO84 +TcUXl61vUyCEHh/nRzhAsBR6u01xp1golAMv9t08aJLiyrjBDXFpQu2NFcdw8o+r3as yguG14kR3VduK4YpU7QYtEALlqm6kih63U20PZ/s/1QCkXuL1bPadR0LTUFRKyYV7z1/ jDQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=/gCsWuNpJqoaKmXUbqD2yoFjbhOP/NQNls4IpQYcF/Q=; b=FTAn6tX6wkcmEQ0QKuyAi3ulA9SuRWNhXJltKYYDPl9lyUMuSaNZ5QsUALNRiLU8++ 9CGZGQ50ivKYEm1GtYXqHE1IQRcTT8gAyn9od/l/RjduT8dBS8lOYpRIgL7OZpY+UcqU FACcuKuknkC6BpoevKCH28zhVaAwPD4PuloBb7pdEc3m/6x6HjKZvXNS0djYseQKcagv VeX+ylZHhnO91Pvg6TSYmhSTEcp+v0P1luiFdrn1wmcwJe8ply9no/1ZTPo/SuPfsSyd fHxlBm72uKw7Q/KsSBH9rCtc/rlWkbXQS9lJR7/b+KhufDwZ8Ka5NmQCMevnNhoIRefC 2btQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K8BGJ9oH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id m29sor3718592pgb.74.2021.01.07.13.15.29 for (Google Transport Security); Thu, 07 Jan 2021 13:15:29 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K8BGJ9oH; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/gCsWuNpJqoaKmXUbqD2yoFjbhOP/NQNls4IpQYcF/Q=; b=K8BGJ9oHdqpLDSsv4ZzOKEHEpyQXmBiqo3CQDjAFOiubf8uMAXb8rE+2Q+8w+MuenT r39dpZHy1UjTwLvLcHtkgKqx7m1yH/VZCVvUsyblpu4gsHE8oyEh27knqvqkNx99hfd/ OdLjIgReRKvwFliH9XDPaVNHEjCr8ivL1CuAOS5SsvSCJwjtqzf9bEeTilTgDDB91z1d d8gKjlz+Dsl9OtsTbJ+dMP1JwATb4Hb+DNbBTib+6EpAlAhzwgHklh5i6ggogkXvBu0w Sl0lvmy8kDpa3UVvGMnYPvuuD5pjaQCOY4j8xR9yncAL6VXY3VpNQLEDm0Rk5MWF1r7S 80MQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/gCsWuNpJqoaKmXUbqD2yoFjbhOP/NQNls4IpQYcF/Q=; b=IOv3Ofxr1w8Q0RMoN73tUTpXowOYRHKrE+SYmyjkewrg+yPrcpnuo75XNXtl8vV49A REPdLT/MbyhYdFKQi/Ypy81Vqzunvrb4KCYDKHgvfBNLP73zG0TjvMmQRsLstE3EuU7P i2FESCKRdW2Ey5I4zcFgB1n8WR3tq1+x3jVf6niR5h6s/I3xGPcFU1mfWW5XFY42avRV r57hA9gQFELiuykYlUxzWBQpSjKqTrrTt96pgxK+sS8HjJoFBvU+T+zciB2c0vq1WKrG vdKAlyK7PFl7xKepCtrxxLf51hchET1q3OIX8QTSwZv6AvhyjL4Xjw02dxhkgF9GMaUx UiuA== X-Gm-Message-State: AOAM532pWw+J+qFUeYXdHMZZPQQEudMyT0atdRqQ3rghMi3k46E3Y7/q n37x6eQQH1Ggbg3T2i7UGKI5fNru X-Google-Smtp-Source: ABdhPJw+uBkf603u8DBtRcPFLax4GUhUMXlfkuBYTBlYX9IqNd80YY3GhmwaHOU9hi8B00BuqmRrDQ== X-Received: by 2002:a65:6249:: with SMTP id q9mr3744816pgv.82.1610054128730; Thu, 07 Jan 2021 13:15:28 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id b6sm6574055pfd.43.2021.01.07.13.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 13:15:27 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH 1/3] dma-buf: system_heap: Make sure to return an error if we abort Date: Thu, 7 Jan 2021 21:15:23 +0000 Message-Id: <20210107211525.75951-1-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 If we abort from the allocation due to a fatal_signal_pending(), be sure we report an error so any return code paths don't trip over the fact that the allocation didn't succeed. Cc: Sumit Semwal Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Chris Goldsworthy Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Suggested-by: Suren Baghdasaryan Signed-off-by: John Stultz --- drivers/dma-buf/heaps/system_heap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.17.1 diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 17e0e9a68baf..405351aad2a8 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -363,8 +363,10 @@ static int system_heap_allocate(struct dma_heap *heap, * Avoid trying to allocate memory if the process * has been killed by SIGKILL */ - if (fatal_signal_pending(current)) + if (fatal_signal_pending(current)) { + ret = -EINTR; goto free_buffer; + } page = alloc_largest_available(size_remaining, max_order); if (!page) From patchwork Thu Jan 7 21:15:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 358297 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp812981jai; Thu, 7 Jan 2021 13:15:31 -0800 (PST) X-Received: by 2002:a65:5244:: with SMTP id q4mr3757309pgp.50.1610054131372; Thu, 07 Jan 2021 13:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610054131; cv=none; d=google.com; s=arc-20160816; b=tYYN1kuSlCA6wFy6UHsh7uBAN2VT6p0zh8ddbvu9t2vt3A1dzuCYhXJNtZ+vrVGpIU 6gX2/nn2IgLIjVQgVFPbytJUihAqdsLDbUdLxm4qywp+XZWNfW0KgUWlrjz3Ztm2jq8N STfNvcqzK0tpy7lVfqBfRcsQJdtPsvxGea+qMPB3CR39aRT9bjOK/lB+6MxTyMmkiHTq npWUSNGGQgKbkX6UOEndswdTTOi/aXN5ETy8u5bWl2JUxMMsln0q8N1aZoLMwnFiXzty a0sYULIEFlrB+WBjg5n0Txi0T17JCl+3tWPqMCnOf57gs5pCCDc9FHNsf5/d90e4qXCx CmjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=+HPHLTIbnqvyYqZakEN0yW6023R2vX5SvJvHEGRsu88=; b=asRy932HT705wl7auqiZreOm/Tf6xZMTwgSgKPXXz2b/5tRqnGqbfDJJrZ6Ff9sHGo jbig1s+6VdDXR8EOmFUpIDkp+RPcdk0HVIUgFZfcPglopR/7F4an7Rd0aQjGvnEYQGox +6fkO+E+YU+s+26PsWUPoDABHosNbJoa78VbWY992DHx0dqfI6qdhNawU2qOZZQS6WVC cqosmc4kMEwWhNVoh38kKnsclmHvBpgrqQanM57UFRT96R6zhqPcT82TNBavlbaJHiNp /f3Dg/52bwy4kUcpw6518eNQhZfJ22fNA2JROGcm+TTUdcybPD9xql22Z7107F8JrxRy OcAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHSZgqcz; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id c9sor3260944pfj.15.2021.01.07.13.15.31 for (Google Transport Security); Thu, 07 Jan 2021 13:15:31 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cHSZgqcz; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+HPHLTIbnqvyYqZakEN0yW6023R2vX5SvJvHEGRsu88=; b=cHSZgqczj464Vf520gWeFxP2skBA26Gc4qDuq1k8SZeOGcfiiKTsmZsKBzVJdyquDP AwP7iEXEk3FUyf7L5lc4NpelRvFLZEqi6kU8c4hrfifAl04y8vtm7TNoDnKC63HO5SWh lvZZyVDoTP+zd7oHSx0sgJu/5FP0Do/q4vTVgiaLwFYflQVgzzvQt/kR9/i31MISy4tq LbZLvEw+G5rucP4QbGOC20BkR+d3pP9e1EqPfafczaD7SUTW8Q7US+QdpxgtZQPx7nXU sKm0TId7I+tNjCMRk2+nJ9OV9f/iHF9+aoyoW0ijSIp6Kfox+9TUooajqLsw5KAD6xDw p5Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+HPHLTIbnqvyYqZakEN0yW6023R2vX5SvJvHEGRsu88=; b=Y1XlYiV3mpzOJKWqWwhI65FnVvXx2Q35kYBIMw9vPuWPmU6R88yXSfQAbk7g39HTXH 1ENxz2NVIWUKAmyiDayweHWOmiBjNHgoK/twufbdANU1ApVmc7E0aaMDCWJ4S+tdWvpY Xo3b8MstcWKUZm0uq4TFiGo5SjmN9g3CjB5XHLEajMQHtWv4xDPiCkCClxnwLtIqKFHQ OJS0h1iylgnnqcaLxjBhHZIF92kgVpGqtfb9puIkwXFY9nbLR+qXR4intPbIQuWTsO7Y zEZC4jNvubtp6Iwlf38U6yGHgQagImbmfX2uenXFohM0eDdqA1yNCXr+oXfbHsby35Vq Zygg== X-Gm-Message-State: AOAM530sw0OO/VfPewoxvFhkR5C3ErOXz1bmmGdamQOXX7dJ3F7QAHuD ZoCVDfvag05uSaTdOcU1kuuQOFFf X-Google-Smtp-Source: ABdhPJy9pko8exsJmRsYgHZWzS6HB4ShY5PboCyRW7n6CbWSr9ryNiq7i9X3M83nJXNVn5LYJ0D45Q== X-Received: by 2002:aa7:97bc:0:b029:19e:18c7:76b with SMTP id d28-20020aa797bc0000b029019e18c7076bmr501704pfq.23.1610054131037; Thu, 07 Jan 2021 13:15:31 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id b6sm6574055pfd.43.2021.01.07.13.15.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 13:15:30 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] dma-buf: heaps: Add a WARN_ON should the vmap_cnt go negative Date: Thu, 7 Jan 2021 21:15:24 +0000 Message-Id: <20210107211525.75951-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210107211525.75951-1-john.stultz@linaro.org> References: <20210107211525.75951-1-john.stultz@linaro.org> MIME-Version: 1.0 We shouldn't vunmap more then we vmap, but if we do, make sure we complain loudly. Cc: Sumit Semwal Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Chris Goldsworthy Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Suggested-by: Suren Baghdasaryan Signed-off-by: John Stultz --- drivers/dma-buf/heaps/cma_heap.c | 1 + drivers/dma-buf/heaps/system_heap.c | 1 + 2 files changed, 2 insertions(+) -- 2.17.1 diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 364fc2f3e499..0c76cbc3fb11 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -232,6 +232,7 @@ static void cma_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) struct cma_heap_buffer *buffer = dmabuf->priv; mutex_lock(&buffer->lock); + WARN_ON(buffer->vmap_cnt == 0); if (!--buffer->vmap_cnt) { vunmap(buffer->vaddr); buffer->vaddr = NULL; diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 405351aad2a8..2321c91891f6 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -273,6 +273,7 @@ static void system_heap_vunmap(struct dma_buf *dmabuf, struct dma_buf_map *map) struct system_heap_buffer *buffer = dmabuf->priv; mutex_lock(&buffer->lock); + WARN_ON(buffer->vmap_cnt == 0); if (!--buffer->vmap_cnt) { vunmap(buffer->vaddr); buffer->vaddr = NULL; From patchwork Thu Jan 7 21:15:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 358298 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp812999jai; Thu, 7 Jan 2021 13:15:33 -0800 (PST) X-Received: by 2002:a63:2352:: with SMTP id u18mr3682729pgm.385.1610054132990; Thu, 07 Jan 2021 13:15:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610054132; cv=none; d=google.com; s=arc-20160816; b=MlBxt8s2+7hIqHuU1QnpDekarRHlU6WnteMXl+Zxz7adCXV6LVRPhWQroPhlWaWqE+ aYvHLNC7Fj+yJI+DraKrDfFvzIinF7hu9pZ/Jz0pS0cS29iV64tvGrm+vcvGyzrlQMP+ 35YqXQvfpbdTVemFVXQ358QRieZaLsmHlZnXggcizeXBUzJzlmeVJW7hVR8SkzKtnS6Y gSqkHF62lBewt2Rmz5fH24gjbNnUAddYxbOaBhHmtafS9BSxZRkRjc0xYFPuDmxHnbt+ 1VdXTD4/nmUiFpmhqD4H7StwXu4YLiifulCL9w/Ym1SGFuD50jiDu9CnqqclVVCpoKVW cCUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=njrcSIJAkGY2OvZcMcUOB/aiSRsE8gSP15fU7c5jB6I=; b=jRp/wy/KQu8MIXXNRfRRIr+Sanzohqca2RctbgBfxHPaTP2LrQ3rVVL4UCL+I4lGMv /Sol7nhr2pwlDRAewN1QDweIhkyBBM2NuyFQSTWketd/NlDEkFjWzgG62a6SOl/HhVxu eQdgM/txij/I9TN3P2yQit5OlhVYivOXGduFj+ok9Zc5EGquAV4/X1Cp3NMYzpq8ND6x 9Qs8QUZJr4NYZdbohPf7OCm6a2rS51jY/OrAiGj8QiEmJpBCWJazMkoF7mqC/4kGcK2q 74qBcWOKP6Wy7PCuy5hF+YaPEQ9X3AA+xDMTxMoUJHbCW/3Z/ie2PR4ny4j2MLq5aKKd rKLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S3kadN9N; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id y4sor3280719pfr.54.2021.01.07.13.15.32 for (Google Transport Security); Thu, 07 Jan 2021 13:15:32 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S3kadN9N; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=njrcSIJAkGY2OvZcMcUOB/aiSRsE8gSP15fU7c5jB6I=; b=S3kadN9Nd3eJwxluh3P/NQ7i6yJ3iFEioWoVaqyB/bZBLo/xMbdx87OKNpbHiY7dGj 4ZrHeVUJkAGpssYpJVVRC4eKet8jVvhjl3Vo/qRstu0C3FbSIBKdXSwkeKajIal9Cvnm QQJmu+t49heDmdwEa0QklfX2n0M28+01N4UWhtpEHSrelW7kz7zZQprMRaqi8QWMv+UP CdE+a77alvo9VGxRRgQhzamyWjHWnYeaaAEnCCyhcZ5CLgOAX8r8YBB+sF0mV41A7qur pZ4yug/6pl/Fx6PBjUbsH2K5hIrWQD0rHI1l0ELVDOOftJZjPcfFOnojtZI5MMeKRzPA IG+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=njrcSIJAkGY2OvZcMcUOB/aiSRsE8gSP15fU7c5jB6I=; b=XDIIDSPhm8eCpYITXUOGFynAS0rnksRVS8UrKg8lwNBrkbL8VgDD+IEaKhQ/l2TN6K Y/I0vQlig6cwPqdE6fZPsvqn5PfdxabM6L0LwH54rWQrcag+0ZKF7ILytwvxfx7rRUwO OeEV2OctYHztWH7cVQJwedi/Sh/Q+4yzAi1YTyDbSa8f4Azo6dWdw2WPYsivnwX7VRxh KoA1dD6nIzrr3U4Kgzzh+tMm+iNGjy1f4/Neod8IsQ2WYB+51ASBQiXM3cNNcIu9r1Ib zN8x880GBV2omD964wx2oQ6pfQek3lGA02iTL6Muum+LhftxQ7zmCsxpb7vdKN8Qdxey NP8Q== X-Gm-Message-State: AOAM533cjem6Hkm8WEp0N8nu6ZMjAl3uN3PhjiQGzavSWFI15qscGp7h P+P7rmxuUZQYgxvVewUipJkXWkr3 X-Google-Smtp-Source: ABdhPJwQof8Twnqw2nby4Kyyai2XBfyKyBoMmx2rspsxPT2kGDpWq9k2NH3i2fJiY/P1cArkpcSccA== X-Received: by 2002:a05:6a00:16c5:b029:19b:696:28a0 with SMTP id l5-20020a056a0016c5b029019b069628a0mr513757pfc.9.1610054132669; Thu, 07 Jan 2021 13:15:32 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id b6sm6574055pfd.43.2021.01.07.13.15.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 13:15:31 -0800 (PST) From: John Stultz To: lkml Cc: John Stultz , Sumit Semwal , Liam Mark , Laura Abbott , Brian Starkey , Hridya Valsaraju , Suren Baghdasaryan , Sandeep Patil , Daniel Mentz , Chris Goldsworthy , =?utf-8?q?=C3=98rjan_Eide?= , Robin Murphy , Ezequiel Garcia , Simon Ser , James Jones , linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH 3/3] dma-buf: heaps: Rework heep allocation hooks to return struct dma_buf instead of fd Date: Thu, 7 Jan 2021 21:15:25 +0000 Message-Id: <20210107211525.75951-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210107211525.75951-1-john.stultz@linaro.org> References: <20210107211525.75951-1-john.stultz@linaro.org> MIME-Version: 1.0 Every heap needs to create a dmabuf and then export it to a fd via dma_buf_fd(), so to consolidate things a bit, have the heaps just return a struct dmabuf * and let the top level dma_heap_buffer_alloc() call handle creating the fd via dma_buf_fd(). Cc: Sumit Semwal Cc: Liam Mark Cc: Laura Abbott Cc: Brian Starkey Cc: Hridya Valsaraju Cc: Suren Baghdasaryan Cc: Sandeep Patil Cc: Daniel Mentz Cc: Chris Goldsworthy Cc: Ørjan Eide Cc: Robin Murphy Cc: Ezequiel Garcia Cc: Simon Ser Cc: James Jones Cc: linux-media@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/dma-buf/dma-heap.c | 14 +++++++++++++- drivers/dma-buf/heaps/cma_heap.c | 22 +++++++--------------- drivers/dma-buf/heaps/system_heap.c | 21 +++++++-------------- include/linux/dma-heap.h | 12 ++++++------ 4 files changed, 33 insertions(+), 36 deletions(-) -- 2.17.1 diff --git a/drivers/dma-buf/dma-heap.c b/drivers/dma-buf/dma-heap.c index afd22c9dbdcf..6b5db954569f 100644 --- a/drivers/dma-buf/dma-heap.c +++ b/drivers/dma-buf/dma-heap.c @@ -52,6 +52,9 @@ static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, unsigned int fd_flags, unsigned int heap_flags) { + struct dma_buf *dmabuf; + int fd; + /* * Allocations from all heaps have to begin * and end on page boundaries. @@ -60,7 +63,16 @@ static int dma_heap_buffer_alloc(struct dma_heap *heap, size_t len, if (!len) return -EINVAL; - return heap->ops->allocate(heap, len, fd_flags, heap_flags); + dmabuf = heap->ops->allocate(heap, len, fd_flags, heap_flags); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + + fd = dma_buf_fd(dmabuf, fd_flags); + if (fd < 0) { + dma_buf_put(dmabuf); + /* just return, as put will call release and that will free */ + } + return fd; } static int dma_heap_open(struct inode *inode, struct file *file) diff --git a/drivers/dma-buf/heaps/cma_heap.c b/drivers/dma-buf/heaps/cma_heap.c index 0c76cbc3fb11..985c41ffd85b 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -272,10 +272,10 @@ static const struct dma_buf_ops cma_heap_buf_ops = { .release = cma_heap_dma_buf_release, }; -static int cma_heap_allocate(struct dma_heap *heap, - unsigned long len, - unsigned long fd_flags, - unsigned long heap_flags) +static struct dma_buf *cma_heap_allocate(struct dma_heap *heap, + unsigned long len, + unsigned long fd_flags, + unsigned long heap_flags) { struct cma_heap *cma_heap = dma_heap_get_drvdata(heap); struct cma_heap_buffer *buffer; @@ -290,7 +290,7 @@ static int cma_heap_allocate(struct dma_heap *heap, buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) - return -ENOMEM; + return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&buffer->attachments); mutex_init(&buffer->lock); @@ -349,15 +349,7 @@ static int cma_heap_allocate(struct dma_heap *heap, ret = PTR_ERR(dmabuf); goto free_pages; } - - ret = dma_buf_fd(dmabuf, fd_flags); - if (ret < 0) { - dma_buf_put(dmabuf); - /* just return, as put will call release and that will free */ - return ret; - } - - return ret; + return dmabuf; free_pages: kfree(buffer->pages); @@ -366,7 +358,7 @@ static int cma_heap_allocate(struct dma_heap *heap, free_buffer: kfree(buffer); - return ret; + return ERR_PTR(ret); } static const struct dma_heap_ops cma_heap_ops = { diff --git a/drivers/dma-buf/heaps/system_heap.c b/drivers/dma-buf/heaps/system_heap.c index 2321c91891f6..7b154424aeb3 100644 --- a/drivers/dma-buf/heaps/system_heap.c +++ b/drivers/dma-buf/heaps/system_heap.c @@ -332,10 +332,10 @@ static struct page *alloc_largest_available(unsigned long size, return NULL; } -static int system_heap_allocate(struct dma_heap *heap, - unsigned long len, - unsigned long fd_flags, - unsigned long heap_flags) +static struct dma_buf *system_heap_allocate(struct dma_heap *heap, + unsigned long len, + unsigned long fd_flags, + unsigned long heap_flags) { struct system_heap_buffer *buffer; DEFINE_DMA_BUF_EXPORT_INFO(exp_info); @@ -350,7 +350,7 @@ static int system_heap_allocate(struct dma_heap *heap, buffer = kzalloc(sizeof(*buffer), GFP_KERNEL); if (!buffer) - return -ENOMEM; + return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&buffer->attachments); mutex_init(&buffer->lock); @@ -400,14 +400,7 @@ static int system_heap_allocate(struct dma_heap *heap, ret = PTR_ERR(dmabuf); goto free_pages; } - - ret = dma_buf_fd(dmabuf, fd_flags); - if (ret < 0) { - dma_buf_put(dmabuf); - /* just return, as put will call release and that will free */ - return ret; - } - return ret; + return dmabuf; free_pages: for_each_sgtable_sg(table, sg, i) { @@ -421,7 +414,7 @@ static int system_heap_allocate(struct dma_heap *heap, __free_pages(page, compound_order(page)); kfree(buffer); - return ret; + return ERR_PTR(ret); } static const struct dma_heap_ops system_heap_ops = { diff --git a/include/linux/dma-heap.h b/include/linux/dma-heap.h index 454e354d1ffb..5bc5c946af58 100644 --- a/include/linux/dma-heap.h +++ b/include/linux/dma-heap.h @@ -16,15 +16,15 @@ struct dma_heap; /** * struct dma_heap_ops - ops to operate on a given heap - * @allocate: allocate dmabuf and return fd + * @allocate: allocate dmabuf and return struct dma_buf ptr * - * allocate returns dmabuf fd on success, -errno on error. + * allocate returns dmabuf on success, ERR_PTR(-errno) on error. */ struct dma_heap_ops { - int (*allocate)(struct dma_heap *heap, - unsigned long len, - unsigned long fd_flags, - unsigned long heap_flags); + struct dma_buf *(*allocate)(struct dma_heap *heap, + unsigned long len, + unsigned long fd_flags, + unsigned long heap_flags); }; /**