From patchwork Tue Dec 15 22:05:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 344031 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4264530jai; Tue, 15 Dec 2020 14:05:26 -0800 (PST) X-Received: by 2002:a17:90a:46c2:: with SMTP id x2mr679216pjg.15.1608069926132; Tue, 15 Dec 2020 14:05:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608069926; cv=none; d=google.com; s=arc-20160816; b=MwbjLQhdW0QgaPP0fBMxPSKRdpXWe7RKOs9J2RfWNIHEl0nOK2hTFuN7hPSrjmZsm6 tTdxwANacFTEdu5NpwHtdjV3uWmdatWhxBGB59wPSoeidroo0SyErzki0hJZt7wjP/un 8S2t+RJ9BENFS/1RFg3Al10k4yRbP0jbXX/k6ewQolQ1fcoEM2RhvFyG6k5gb3E460Ky EuN3J5fPMSw55+acWUfldRJ+WSrtR2G80K5lfLG6rWsSiuoPRO1Z5gOlOP+qP8V8t85i KFRZZR3QZKRseJTpvJFiFFQA3xTrblCFLXz78Xdfe6xozbAHuFGemnInEKO0I1i4Dc63 ugvw== 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=LiPm55vRmQB/yBtMc9dWDosG+dFYU20xJIv1RC7Tiqgor51ROpve66niCJ8he/IwWk 02bU2/XxQhJk+ZNe4dZLZMtE12K461VIlflJPhm7xuod6zLcGuO3OahosR5ckRJys8cX 5XGokW8tj1LEXgxMnBvwDEl+DfyeuvmvtLaUfuJnWjviTiHbpAIn8Ey4YFll8GS+E5ij 7WCySyC688dYwWzS8+i+GlXImtaMyIQglEuVsXrE7NjdF8HEfxpuaxibvesTVqTKcOB/ O2JQ5pfBR85Mr6tHR7fUgDpdFVi7bLIN1f3vhsDNo9hUUOiw8uv3Y2WRobusQTF9vSvD /vGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rOu3z9tr; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id v31sor55670pga.36.2020.12.15.14.05.25 for (Google Transport Security); Tue, 15 Dec 2020 14:05:26 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rOu3z9tr; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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=rOu3z9tr+Uz2Jq7hQygYWUdSEXOtqllnYQZVQ7JZLP52v4jZtyPKuSCT0emQd928OS UXnG68BiLFVU5IQzQhttHl4AmSfyq4yDqbxhYhiij0OuDGBNjOHsxUQJOL2bjrjqpAA3 uWLxYS3XwS/5mzazbiFvZa8vT/fuF5R7qmq50x7vmbOV2O0fmGldMo5W7lynABBr46/z bUU18S0qjd5J8Cj4Jmtk47WRhH5lFCVNVOcfyk1aUkZnOwqy1g+wjd+OoHh/xSMjOz4o YI4ePM8sxnDoE3XI1Dkz0kH4YFQI6OJrdUOOEzkWr32/V/3WusqocYedGiK/BTdQyysH iD8A== 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=k8sjUZZhoKzU7GZUks/T6hBD0LGYGROEF9KUp0Ly7ziIlwV2/2Fzgkt3BGCw9HRweX fbHtI3wrZTYb/hBHLRX7nsybyXKTJqmn8BdcGGLBzLZHhPCTg4+nDpuSwXK/cZGqN5bb 4h5MEnfzAIu/TVgm8/hFyG1Nk6hZKCPuRdiUhXaW37948yxoeLsWm3cBUPRKY8tqFUxp rEngaBiiiKO64sWmEXncfEanYD+7C1Q27lcBtlqmcjGCObknEg858z8akEv2t2GzjcQV joEAl9nrKT4kyVlrbDWOXVICq3M7HM/Lp9Bytedq3iGolWTuDCvv3HjMosiSfvfiwMCG hY6A== X-Gm-Message-State: AOAM531vPbDejuFWOi8Vw/dVa0vxifiRhUQdRm7e9q5IZ229JcG7mhgO UVP7N0YpiLOd3LM9OOK7MlL2TtD7 X-Google-Smtp-Source: ABdhPJy/bv/dpSXnrXAIXAKPU25FtDrutI9TAwJhbjpo2R/NbvcsZmowxwswu/mRJpZaOEHPVHm+Fg== X-Received: by 2002:a63:4e4c:: with SMTP id o12mr30386525pgl.348.1608069925721; Tue, 15 Dec 2020 14:05:25 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id x15sm84146pfa.80.2020.12.15.14.05.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 14:05:24 -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: [RFC][PATCH 1/3] dma-buf: system_heap: Make sure to return an error if we abort Date: Tue, 15 Dec 2020 22:05:19 +0000 Message-Id: <20201215220521.118318-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 Tue Dec 15 22:05:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 344032 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4264537jai; Tue, 15 Dec 2020 14:05:27 -0800 (PST) X-Received: by 2002:a65:46c1:: with SMTP id n1mr30651970pgr.352.1608069927646; Tue, 15 Dec 2020 14:05:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608069927; cv=none; d=google.com; s=arc-20160816; b=BBahpxv0HyIvNXfhsy/Wpl12DIjLsqR/8lUIbzKSrnegYmz9QoARlPuSwN9ThrXYF0 nrQWc/sAJmShEjHRje0bNeRR05A7jMlhM62AyvPnUlyG5r+J5jOo6p0s23Szmd1bakyW AeTYSsMm/+lb3hfZd1Trh5cvFiEc0PzeKL+QRYKYJw/+do2v9iY6pwOQoAE8TD2cZc2s 80juK0eIAlR8wf/jf6JNvQVqgL4efYRQr4Ap35Dmj/uYGQtHOUyeI7UCkl77miy61NGt hl28sOJ/G/efYO5Gbw44K97oicKCJJQQsdYbCHFqD5A20mpoibytlCbhHF2XYgVVDzcf ZZMg== 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=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=e9zaDgVBRGgJdBpHTWZRtwDwcTRP8wpvEhNcSZgG5Q1o43QEQEYGZsOsAZt8VzJN5h nLCR4fGQAVxDfLjFRSFdjDi/EnyExbXMssLEZMSzVs7Zevn2yHL2dCMb+i0MCPLYQ0FW ruEffQMGWzTs3DBg33OaSSrhRptSgW9X+34U/o4RsQfpRXSxHavcsKE7MQRMPpbMNmYL EA4jBmNWItyvx3S+aZcEy2ymctUSf97U0ZluWEXcjfNZd22pp3jEmI3TzYXDGbpZ4YE7 KwzXNDSxvnLdDnFnJzgQAwIwnBlC/i5L1Yf0C2zOhbTt9wKS8SINLJWK7NUFhSRceovY JDjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2xXtJcd; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id ms2sor82503pjb.21.2020.12.15.14.05.27 for (Google Transport Security); Tue, 15 Dec 2020 14:05:27 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=p2xXtJcd; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=p2xXtJcd1aUEKVCpL/yh2zHAnUKUnnWwn3KT6xcvB1fmMbzbubeWxt0UWpAi+SHPkn Da0r6htfgSPk5GT5zFUAvAj9HKR9J/Xch76+SmRleDTarKBdtiMk2hQKTvM2ii03hq0R KNe5XFm+uN9nHsrs/7fQbU9hUvdU3DtCbiAiwhRgzj3BW22qCPr9aYCowWWF0o7lmeHN +uogQn6HoNI5bOkFqfS5YsBABPcVWeaO+cM8PfuMoVcYTBSXwRPkxCrLVmsuC5+LeIz8 GzNv13iEIXL2wrU8aqMcQJHQ4KKslM/A9tB8ab472EDm6JX7WFfZA7OLoEMeqNJ/NIEp iClw== 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=Lf3OWtQTMarfh+qKkUU+h4c6HMQ0ofK4k7yhmGxtgVU=; b=SzuVGsL6tefQrLGBW+dEDkA3x8Ob5k4DCIAzOcE9rQyQ/Y5qjWcqCs2o/VE3ogpYjv v+Vz5L/T1UXOxqIAbBjatXsdi+CoiNWQlTl1dCgynalefEahJd25mbwoYhnPXnCumgZg ox+TNwsX7gGlFULHVoT1Z1WTy1rk6wKwCnOFldqigN0fPeOoK82dh6DfmpcCnGs06Ffe fvmqQj1VmxjiYSBmdaCWYF8g6BoRI+orUjutDyAlFgb49AmP3jUZSySVcTJlFRcMbNiJ Evt0OknmFAQ1Q4fVYmplXwQepzYtXyNDazxKy4WQzm9EBdma75dSsPzYTrgyzazVbqFi f4hg== X-Gm-Message-State: AOAM532N2by2/XYEsTBaCiGBYPqCkTGnPc9FG63HbuHnCktrXvn4ODlb lOD7avo66gmEjB6FKk1sJAIcr7Mr X-Google-Smtp-Source: ABdhPJyZFB1G/FH9A4ea1yRVC9wsxNuo+mlDEpj4WlbhDeCAewfVGAqiU5A0MycX/M2qOvrL95WZ2A== X-Received: by 2002:a17:90b:50e:: with SMTP id r14mr679493pjz.90.1608069927363; Tue, 15 Dec 2020 14:05:27 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id x15sm84146pfa.80.2020.12.15.14.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 14:05:26 -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: [RFC][PATCH 2/3] dma-buf: heaps: Add a WARN_ON should the vmap_cnt go negative Date: Tue, 15 Dec 2020 22:05:20 +0000 Message-Id: <20201215220521.118318-2-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215220521.118318-1-john.stultz@linaro.org> References: <20201215220521.118318-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 5e7c3436310c..877353e8014f 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -231,6 +231,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 Tue Dec 15 22:05:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 344033 Delivered-To: patches@linaro.org Received: by 2002:a02:85a7:0:0:0:0:0 with SMTP id d36csp4264542jai; Tue, 15 Dec 2020 14:05:29 -0800 (PST) X-Received: by 2002:a63:e402:: with SMTP id a2mr4254342pgi.168.1608069929358; Tue, 15 Dec 2020 14:05:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608069929; cv=none; d=google.com; s=arc-20160816; b=emS/nUV39uu7KwDCfEY09icq8LttFX91b6DLv1DzCR5qkzGaHbkjcaFhvtIp7qTDWe +O1cACgkE0gQyzglYd0cXQyx8dZPdkhxNvOwcSuxZHhAGIDfweVdftZz58MY82747Nlu FrNPzrVwypP7dR9fGVilC7EekeS4CcAZFALBz/kw+aklL18Y4udpCff2sWzcneoXzB0k W820pN1VgzU0qx5BdC5qsmPgS8ex8yu1zsbeqqfN3dGEvmGFHDtuJgTVfQXaM9R8dm3A o5kZZXxAn+ARlqQNNu8DCxnWwrd0t6XhzypS0JR3Zj7TM7jNKeDw+jFpwJBkUnLYyRWL ichA== 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=kl8PmZ90JFms2rGnBVhby1dPAjXSFRIkuqNGt+DZeDI=; b=Gah0JVtw206laWUNQjyGktiFdDVAK4BLFoVA+xxFyQPmWlQIoT9OORoEjkMAQ2l6me hRwgpTlKQNyY+9EmQ5cdmRf6SfH/m30EXZShFahuafMysGw62CEG9+1dNQCYmHuLLLH/ l1yiUxGIYld0DZ3PlQuifrBXUfmMrPauaEFvh833KRc7yIV2ZlEdrkhhnAQjk3TyDdkV MOqhxj+eDKe/HdPouA+FmJRIWr6BlyMxwAbtuCJzlf2vBpkK5PxpOjYNshsEGNn2iPp7 fMypmewOqZUqfPLKqgL+SG97yigf1slkVaSiTxL+J7wWwGLWzSqvLk2ENYNUP0elKDIt afGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gtbakvDS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id u13sor76025pjn.32.2020.12.15.14.05.29 for (Google Transport Security); Tue, 15 Dec 2020 14:05:29 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gtbakvDS; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 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=kl8PmZ90JFms2rGnBVhby1dPAjXSFRIkuqNGt+DZeDI=; b=gtbakvDS5+hfUPYPisnKHKkpzI2vWtDWjMabBbr36nuJ4SnxstOs4PQOYUvf1rubas UVc6Zd9/Ftn/AKJedeTpl1JX9Mp7tQoHFxWL23lR9Nu+v0DciCOGdKgzjdW8OPgxDWq0 xU+zTjyuHUFkUFK7I3bWOz3PS1qYYCD3N5Zr3007xPpjcCgfSPvN67Wqp/5b6Ba19o0f L/NefZfbRy72TRZVYW/8uTjFQlc6ZnwEviOb5C3p0YeTjceCA8NGB6Ub3pMtd+S3Zr8G UmeZkBEWCcQRxb1om3207cWH5j2y88+4Mvy5bgKq5ARNmW3yFFAW265HlZSGKGP+868t jAGw== 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=kl8PmZ90JFms2rGnBVhby1dPAjXSFRIkuqNGt+DZeDI=; b=mgvGpnstDqkI3NQ7CwHuchaG1X0s76QlcNtIvziKXE0CB4eqmJamvjsOLhkiDH0FDe DVtFuMYIepONoH1o0MiXkl4xZJaB3cFcey+hDr0TshPK9Kt87OVj9rmy7NQ1Ubxcv9yV lyByQvSr/aS8eya7dDOQA8uq4sKkI5feP+BPsMDqPUnYmti/ZhIaBCxslwBgnGpwAPHi siAiWxYVGCFVtUWivFGVeX+JnaHKNJiWWJgeGj3voygqd22tv96JFmHgszSDmZ68kjUg 0oCzZPXN6j/S3Ksnd3/bgs8YmXTEyBFEly2SCA9w8PJr9CLqe73bD+m5XqYVVpq1yA7E lXDw== X-Gm-Message-State: AOAM530DmSZpRq5QPA7vkQeGcmN47JeWsexCttTiSWFk9K7vtvrUHB+x +jTPXh/oaZ+w1enjLGi6MTzNE5qX X-Google-Smtp-Source: ABdhPJz5+eYpmQKEiyL/MUZSD6KzHvL6MBIgXZn3boaKbi6B/hgxQFMNg76pr/UYudpPO0p2PS22oQ== X-Received: by 2002:a17:90a:1b82:: with SMTP id w2mr653081pjc.127.1608069928998; Tue, 15 Dec 2020 14:05:28 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:692:26ff:feda:3a81]) by smtp.gmail.com with ESMTPSA id x15sm84146pfa.80.2020.12.15.14.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Dec 2020 14:05:28 -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: [RFC][PATCH 3/3] dma-buf: heaps: Rework heep allocation hooks to return struct dma_buf instead of fd Date: Tue, 15 Dec 2020 22:05:21 +0000 Message-Id: <20201215220521.118318-3-john.stultz@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201215220521.118318-1-john.stultz@linaro.org> References: <20201215220521.118318-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 877353e8014f..0c7d6430605f 100644 --- a/drivers/dma-buf/heaps/cma_heap.c +++ b/drivers/dma-buf/heaps/cma_heap.c @@ -268,10 +268,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; @@ -286,7 +286,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); @@ -345,15 +345,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); @@ -362,7 +354,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); }; /**