From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D169FC433FE for ; Sun, 2 Oct 2022 00:23:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229683AbiJBAXj (ORCPT ); Sat, 1 Oct 2022 20:23:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbiJBAXd (ORCPT ); Sat, 1 Oct 2022 20:23:33 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F74853024 for ; Sat, 1 Oct 2022 17:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664670212; x=1696206212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eSTT9RCqaAKsDAKHEpxgRwFsvLUWOLIZHfpn9oZ87V8=; b=PKkmlvFvARDlMFc1wqs+EBfozyiCC3NJ746ywLwREZBjdnIn4w0xl9JB QL4GIE/nuCwMdoQaZLFl5mBmf8hqTzKcTxIAvX5NA+S6wPScD2F6gRQDC mnnHNEnPPrEBG03UzujovnPjcJeL+R+SM3RcyXld8xaTylfd2chVXjivi 9TzMBPpRCBxov/i5gZGqGseD2gzUs9/ICjOUYJY4fcrOKBSIMET0DRWnA iMa0C/xjpRYZ6GaVbbd+TM1G7WEFwYvJJBeS8wAxSbltuvRtHj93bTV8h mJmWibPiJR5fzu/0VgzZdXCOttPDD7pyrWpemHw/X2Q31mSQtfkA/H+Ac g==; X-IronPort-AV: E=McAfee;i="6500,9779,10487"; a="285564521" X-IronPort-AV: E=Sophos;i="5.93,361,1654585200"; d="scan'208";a="285564521" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2022 17:23:32 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10487"; a="656347038" X-IronPort-AV: E=Sophos;i="5.93,361,1654585200"; d="scan'208";a="656347038" Received: from iweiny-desk3.amr.corp.intel.com (HELO localhost) ([10.213.181.73]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Oct 2022 17:23:31 -0700 From: ira.weiny@intel.com To: Jens Wiklander , Sumit Garg , Andrew Morton Cc: Ira Weiny , Al Viro , "Fabio M. De Francesco" , Christoph Hellwig , Linus Torvalds , op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] tee: Remove vmalloc page support Date: Sat, 1 Oct 2022 17:23:24 -0700 Message-Id: <20221002002326.946620-3-ira.weiny@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20221002002326.946620-1-ira.weiny@intel.com> References: <20221002002326.946620-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny The kernel pages used by shm_get_kernel_pages() are allocated using GFP_KERNEL through the following call stack: trusted_instantiate() trusted_payload_alloc() -> GFP_KERNEL tee_shm_register_kernel_buf() register_shm_helper() shm_get_kernel_pages() Where is one of: trusted_key_unseal() trusted_key_get_random() trusted_key_seal() Remove the vmalloc page support from shm_get_kernel_pages(). Replace with a warn on once. Cc: Jens Wiklander Cc: Al Viro Cc: "Fabio M. De Francesco" Cc: Christoph Hellwig Cc: Linus Torvalds Signed-off-by: Ira Weiny --- Jens I went with the suggestion from Linus and Christoph and rejected vmalloc addresses. I did not hear back from you regarding Linus' question if the vmalloc page support was required by an up coming patch set or not. So I assumed it was something out of tree. --- drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 27295bda3e0b..527a6eabc03e 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -24,37 +24,25 @@ static void shm_put_kernel_pages(struct page **pages, size_t page_count) static int shm_get_kernel_pages(unsigned long start, size_t page_count, struct page **pages) { + struct kvec *kiov; size_t n; int rc; - if (is_vmalloc_addr((void *)start)) { - struct page *page; - - for (n = 0; n < page_count; n++) { - page = vmalloc_to_page((void *)(start + PAGE_SIZE * n)); - if (!page) - return -ENOMEM; - - get_page(page); - pages[n] = page; - } - rc = page_count; - } else { - struct kvec *kiov; - - kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); - if (!kiov) - return -ENOMEM; + if (WARN_ON_ONCE(is_vmalloc_addr((void *)start))) + return -EINVAL; - for (n = 0; n < page_count; n++) { - kiov[n].iov_base = (void *)(start + n * PAGE_SIZE); - kiov[n].iov_len = PAGE_SIZE; - } + kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); + if (!kiov) + return -ENOMEM; - rc = get_kernel_pages(kiov, page_count, 0, pages); - kfree(kiov); + for (n = 0; n < page_count; n++) { + kiov[n].iov_base = (void *)(start + n * PAGE_SIZE); + kiov[n].iov_len = PAGE_SIZE; } + rc = get_kernel_pages(kiov, page_count, 0, pages); + kfree(kiov); + return rc; } -- 2.37.2