Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1175988rwb; Sat, 1 Oct 2022 17:30:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5tBMl86udMkUg6nb1EZGs61sjP9dfBqd+4Rxfd+keleMytjKJ6zh/J+Q5NOEAYyUIpzCwX X-Received: by 2002:a17:906:fd85:b0:77b:b538:6472 with SMTP id xa5-20020a170906fd8500b0077bb5386472mr10987856ejb.48.1664670632537; Sat, 01 Oct 2022 17:30:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664670632; cv=none; d=google.com; s=arc-20160816; b=DJpzd9+HUIeg/YfwTZ13IxB+/Cf3P0qmXnAHZ/Eq7W3zpI+dHbNMosXOEI9Tsn++nc xBmk+Rt1vvxOuQLoOaES3oZKDk6CtQTrlp6XbioHZ+M/8Zy8zHqj28q2DszDcVQXZvLr UghCpHxIyzEG4LLZ3pCc8p5D9QO9G0ea9csU2EG+0YB0wPVH9JqeSZNoQo930bBa5FEe 32RAdCa3hFqRTdNrkN11hyOqSjJ+JcXz5R2FoJamMftwX/mYTv4K2/yzvbKo/PIZR9RT 5uZcq6mGlnwZOHjt3Ji6k316fbHBDrnM5vtXU0iA0I35WWqIHBj1DIsNzvsG+SQP3gWT ZE6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LOfIDy9MSFQjSDIrL0UkxDVym15aIM2xqJjgOVeVF+I=; b=hs4a9rCFqa2WqSeyUWs+dfoZ8Le2ibjC6JmwAcEf1u2xLditCqnIf50ktEnk6E1bEF v0JD/aaEp78YAYfJouXSPqVLrZ27lBh2askr6I6O2jeyvJcMaSwOM5yjFNoaNXhJjSvi OvGbVyWQU0T1zX/ohqSc0YIr2WMJXfCJfy6BaSRgA46HSWEz+Ro8FdHb5PUlZCsVblaT 6sAhYxaAFgNnLUnypa1oZzd423vMfFMSR6mPJFz+VEEqpHz7E1gmb08g0DFEhm//vG8A cd8dEqwITKO8zeQbX8tJ/XnQt+A3oZVCGDcFyAZAhgOqQJU3lQSnz+gWOD/YWaDqModH bF9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cFzwCSwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m5-20020a056402430500b0044e9ca6880bsi6108732edc.364.2022.10.01.17.30.06; Sat, 01 Oct 2022 17:30:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cFzwCSwG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229685AbiJBAXk (ORCPT + 99 others); Sat, 1 Oct 2022 20:23:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiJBAXe (ORCPT ); Sat, 1 Oct 2022 20:23:34 -0400 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9335C53039 for ; Sat, 1 Oct 2022 17:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664670213; x=1696206213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rnaezL/AbXrdYNjWPYKIXI3BC43DB1DUbdzw9KizDgQ=; b=cFzwCSwGUI0st8DwyNrSBo0E6J0O6N67zH7x5XxPRt9gXl3ag2mS8HfD Wf2bS7dYDr0VYRpb2vJFK32EHTNNqaAWr4W4UO5GuYLTegt3CL32UnIhs LtmfrZUK7ubwScrD+VE0LjSwOc1LJVBt5luw9u4XjPCEkxdLDIWUUR5c1 LZSrLUGwlPZCKDOmlTPC7c0O8cOxlLrUkuD7FnkBmdC0hQSqeA1HpGeg5 E94RSZ/bOe1wZS33B2r1H1sWg78cSfxRsywsuFsvlSpvuDBkJxFCeLu2e FuXGg00vz0Isr8Co+j0ZMsp/GsWYAZl1GYDHiyFHERli4Z3OD9PgTW09p A==; X-IronPort-AV: E=McAfee;i="6500,9779,10487"; a="285564523" X-IronPort-AV: E=Sophos;i="5.93,361,1654585200"; d="scan'208";a="285564523" 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:33 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10487"; a="656347042" X-IronPort-AV: E=Sophos;i="5.93,361,1654585200"; d="scan'208";a="656347042" 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:32 -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 3/4] tee: Remove call to get_kernel_pages() Date: Sat, 1 Oct 2022 17:23:25 -0700 Message-Id: <20221002002326.946620-4-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 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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() Because the pages can't be from highmem get_kernel_pages() boils down to a get_page() call. Remove the get_kernel_pages() call and open code the get_page(). In case a kmap page does slip through warn on once for a kmap address. Cc: Jens Wiklander Cc: Al Viro Cc: "Fabio M. De Francesco" Cc: Christoph Hellwig Cc: Linus Torvalds Signed-off-by: Ira Weiny --- drivers/tee/tee_shm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c index 527a6eabc03e..45e6ff1a452e 100644 --- a/drivers/tee/tee_shm.c +++ b/drivers/tee/tee_shm.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "tee_private.h" static void shm_put_kernel_pages(struct page **pages, size_t page_count) @@ -26,9 +27,9 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count, { struct kvec *kiov; size_t n; - int rc; - if (WARN_ON_ONCE(is_vmalloc_addr((void *)start))) + if (WARN_ON_ONCE(is_vmalloc_addr((void *)start) || + is_kmap_addr((void *)start))) return -EINVAL; kiov = kcalloc(page_count, sizeof(*kiov), GFP_KERNEL); @@ -38,12 +39,12 @@ static int shm_get_kernel_pages(unsigned long start, size_t page_count, for (n = 0; n < page_count; n++) { kiov[n].iov_base = (void *)(start + n * PAGE_SIZE); kiov[n].iov_len = PAGE_SIZE; + pages[n] = virt_to_page(kiov[n].iov_base); + get_page(pages[n]); } - - rc = get_kernel_pages(kiov, page_count, 0, pages); kfree(kiov); - return rc; + return page_count; } static void release_registered_pages(struct tee_shm *shm) -- 2.37.2