From patchwork Mon Dec 30 13:22:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Garg X-Patchwork-Id: 182612 Delivered-To: patch@linaro.org Received: by 2002:a92:815a:0:0:0:0:0 with SMTP id e87csp6337342ild; Mon, 30 Dec 2019 05:23:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzgwFwNtmuCju9PQXTfQ0TE44NBXLuGuMGmtKYLERnAkaoGmqBjLkRPlk7hy1meoJzUMXns X-Received: by 2002:a9d:6758:: with SMTP id w24mr9865413otm.155.1577712206405; Mon, 30 Dec 2019 05:23:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577712206; cv=none; d=google.com; s=arc-20160816; b=oUwBR0jslpVBsb+DcNScphhT4/mVPvA3ueMN20TovZq73f+uq+diikmt053HXGAIe9 FXw/gSOCD5Rb9F3/SfN6N6+rVYXi3lWc3toCGlRy+XO/35WBqkW9SKpbKq/ylsc4NPps f1Fz6IBUJMGv2QKK4taQDNxxYuht5tVZlwEdO/nk5c8bq6trDA5GI5Bau/yGnux5lIrC VRsrpQZ/ZiTcb2XFmEkZMH/R3MlCZpbdaxkuEAw5MBwzolQjDxKs752BoZrrPuSbpHQA ILl835sCaWWl84rMms6vlZuciCjbekI9yY9LZUgJ4YCHMXPKbmyHYyPhcYUVpe4z2rhO erIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=yQ0XqDfWaNn49iz4/YwQRuqIfvGGfSfCl8SQr3BmSiU=; b=XA+wl5m7sNtgP2WyFbFdljGET2C5d+cNpxn0RgH0EVajeH8cj6rCE5UkJmz10uaWkw zDyyels4Nb/I5AGj7O6R5NJxfktdgs1d3pWd33AhNUufU/KXCr21cM8V2PoD0SGPLcRG VrW94FMMj5Z2llfD792SNMDyXV6x2h+Vday6eT3hWj7Ab03QyJBzu+SxoITGivdKGptZ nD6ueKrMKD3QNmbpKmpokfsFX97fmKjbwTxogBJFTnX97fdrXTfXbx/TdIX/GqEQ1oSg mOzbFMwZ8PyreDIzZdLMd0ocpTQgvXHsxz1ts7QAim1Fzvhi9pQjJ8EjYLwhx742rQZZ gpSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bp88UjzG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p22si23304060ota.43.2019.12.30.05.23.25; Mon, 30 Dec 2019 05:23:26 -0800 (PST) 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; dkim=pass header.i=@linaro.org header.s=google header.b=bp88UjzG; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727469AbfL3NXZ (ORCPT + 27 others); Mon, 30 Dec 2019 08:23:25 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:37464 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727397AbfL3NXY (ORCPT ); Mon, 30 Dec 2019 08:23:24 -0500 Received: by mail-pl1-f193.google.com with SMTP id c23so14626665plz.4 for ; Mon, 30 Dec 2019 05:23:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=yQ0XqDfWaNn49iz4/YwQRuqIfvGGfSfCl8SQr3BmSiU=; b=bp88UjzGfmaxyhcgYeMQu9JQs7CyINU4KpCz69ZBA33EFcfqZ3bBwj77b4A7xjVT8K G/JSWwJ5LwpT06V9/HnGaBgF1/ghxNFTznc0Hk4Tq0Ys5Yk2M5KzCXm/5q6146+PEf3x 48LNLkIOF/CEDytxMux57yf6pF+12ar2314Ma1OicGl49NyYaIL7W4fqGaZvZPmVULld 0/erZk2bCZpJ0ytPR0APcu70Pkced0wzqPMQOkum1ptJdlHWIXfbHbk/bCmzBkKgOPDe wKTqM3gg8cvhasgGiO4YNXA8ZSiGj1nFESlUmDUxMkoVbDEvIy6Fl9DumrmMUDOof6MV lu9A== 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; bh=yQ0XqDfWaNn49iz4/YwQRuqIfvGGfSfCl8SQr3BmSiU=; b=toHPYikiNsPPhd+ArSswVPW52ZsZGy6p74iWqXcshJntroUUrqlzRxHUPhskb+Ir+m 71xUjBNx1AlSlCSdGfKxfHW9s5MW/BnMXNzpWD03C5dmJ1dE7UcpbtTV5FQL2Q+WbLZi a6nV6o+3rZoj7PmNncAqV/w+XmfljdbvOZ80chC1vpLKstHMwlPpgolpvwTxU11Vz/rh rZAOWRUvBdvtYoevx6rjS2/nRZnJA1oXhEKHNjf6GFKUr/DxJA000TQkjWxy6Udp4bI0 Vtht294rH3sd4eoOkabSEyh6WO0FDq1peko4ogor30aE6PnnbB+xdhxBeM2pfz7n9PB8 Aohg== X-Gm-Message-State: APjAAAUCbXWt5x8sRKb3fnx/BvXvX2nTyWO3Y6FWnXf8c4Uf/a1w7uNv pYY2Vo6aE9yWBmqLhagcybTETA== X-Received: by 2002:a17:90a:3244:: with SMTP id k62mr47006483pjb.43.1577712203838; Mon, 30 Dec 2019 05:23:23 -0800 (PST) Received: from localhost.localdomain ([45.114.75.108]) by smtp.gmail.com with ESMTPSA id o19sm25133156pjr.2.2019.12.30.05.23.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Dec 2019 05:23:22 -0800 (PST) From: Sumit Garg To: jens.wiklander@linaro.org Cc: tee-dev@lists.linaro.org, Volodymyr_Babchuk@epam.com, jerome@forissier.org, etienne.carriere@linaro.org, vincent.t.cao@intel.com, linux-kernel@vger.kernel.org, Sumit Garg Subject: [PATCH v2] optee: Fix multi page dynamic shm pool alloc Date: Mon, 30 Dec 2019 18:52:40 +0530 Message-Id: <1577712160-7445-1-git-send-email-sumit.garg@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org optee_shm_register() expected pages to be passed as an array of page pointers rather than as an array of contiguous pages. So fix that via correctly passing pages as per expectation. Fixes: a249dd200d03 ("tee: optee: Fix dynamic shm pool allocations") Reported-by: Vincent Cao Signed-off-by: Sumit Garg Tested-by: Vincent Cao --- Changes in v2: - Fix memory leak for "pages" pointer. drivers/tee/optee/shm_pool.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) -- 2.7.4 diff --git a/drivers/tee/optee/shm_pool.c b/drivers/tee/optee/shm_pool.c index 0332a53..d767eeb 100644 --- a/drivers/tee/optee/shm_pool.c +++ b/drivers/tee/optee/shm_pool.c @@ -28,9 +28,22 @@ static int pool_op_alloc(struct tee_shm_pool_mgr *poolm, shm->size = PAGE_SIZE << order; if (shm->flags & TEE_SHM_DMA_BUF) { + unsigned int nr_pages = 1 << order, i; + struct page **pages; + + pages = kcalloc(nr_pages, sizeof(pages), GFP_KERNEL); + if (!pages) + return -ENOMEM; + + for (i = 0; i < nr_pages; i++) { + pages[i] = page; + page++; + } + shm->flags |= TEE_SHM_REGISTER; - rc = optee_shm_register(shm->ctx, shm, &page, 1 << order, + rc = optee_shm_register(shm->ctx, shm, pages, nr_pages, (unsigned long)shm->kaddr); + kfree(pages); } return rc;