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 D23B4C61DA4 for ; Mon, 6 Feb 2023 06:17:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229518AbjBFGRV (ORCPT ); Mon, 6 Feb 2023 01:17:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjBFGRT (ORCPT ); Mon, 6 Feb 2023 01:17:19 -0500 Received: from mail-vs1-xe30.google.com (mail-vs1-xe30.google.com [IPv6:2607:f8b0:4864:20::e30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED31014EB7 for ; Sun, 5 Feb 2023 22:17:18 -0800 (PST) Received: by mail-vs1-xe30.google.com with SMTP id a24so11612113vsl.2 for ; Sun, 05 Feb 2023 22:17:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+xiDdTXHz9kIw5NyDNxaV9yiFmJDYKUg0WvCnptXTRs=; b=nLyqU/ylxVYAnUf1Vo8aIMOpW9ExvPm8ofwBiIWCzOvtnKdtDAPg4P7rggeEiTFkoX hSyeeM04zvkrX2x0fGp3hFnVVjeU2YE0nYv6yaSMtHAKyObnjqoR7IINadZ6zvMGLn2B mxPkB918/T7FKCm6ZPV7GI2CJM1TPnCKP/v16iWw73B+tq/+kvNj/3wi1wCnUh+oIVD/ 61FrPqItSs/IWJJLKWNcERkGvR5hNTD6Vj0Yd2pHLa/7tQYd8gBmiYhDctEddZqBUTzz MGw5H9tz90jLwltcLdc0HNcNIZIMtP7SDTsdE7oNZzETGW851TLUuRQ478V2JR4ksSoE Iqzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+xiDdTXHz9kIw5NyDNxaV9yiFmJDYKUg0WvCnptXTRs=; b=ftRrW73ypWBs18XtfPizQXNmo8z2eYSQa4zp/EOHSPUygcME6VnnOdCuaagrtEgkib qB881jhqG1Epgyr7hmnWolPwPn1oRRdvNgFjGxhWmqq8GFar2aEdvxlzgKva4D+MALM7 RoO0RWuEjcwXAUq58B5Vb/z7gducPQ/wqBH9YU40eVHMNwkhi/pEd4sgdEDbjMQFXb5l MknnmoIMo1T14fsurAQV8zFrMGXeXV4kXlEPgPwvcCJlCF48F+66zVrFeWP3Zl+Hg1OA fWn8kE0aWND4+fq9c75Ky1LMHH4ygwP7IK9QY9ufRAPUkaLwh7bi+fncalkKlK8Amtp3 MVhg== X-Gm-Message-State: AO0yUKU974BeI/zTZbjQEp8kbu54qt34NxZyTlrv/p+GLSITSeDZGyqE UNvj4gpH1xIC11aE7ZW+rXNgC8DR0cbcM//MfibUtg== X-Google-Smtp-Source: AK7set8XMWe0KVmVR29XsCEVIh/R7FQFNTjo1vzmArB0lCeKTRvncByylG3QSkXNpTQc8KyXg0qXmPpbFmn5IjdNNF8= X-Received: by 2002:a67:ebc1:0:b0:3d0:d172:3a02 with SMTP id y1-20020a67ebc1000000b003d0d1723a02mr2755109vso.41.1675664238071; Sun, 05 Feb 2023 22:17:18 -0800 (PST) MIME-Version: 1.0 References: <20230203-get_kernel_pages-v2-0-f1dc4af273f1@intel.com> <20230203-get_kernel_pages-v2-3-f1dc4af273f1@intel.com> In-Reply-To: <20230203-get_kernel_pages-v2-3-f1dc4af273f1@intel.com> From: Sumit Garg Date: Mon, 6 Feb 2023 11:47:07 +0530 Message-ID: Subject: Re: [PATCH v2 3/4] tee: Remove call to get_kernel_pages() To: Ira Weiny Cc: Andrew Morton , Al Viro , Christoph Hellwig , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, linux-mm@kvack.org, Jens Wiklander , "Fabio M. De Francesco" , John Hubbard , Linus Torvalds Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 4 Feb 2023 at 09:36, Ira Weiny wrote: > > 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 highmem page does slip through warn on once for a kmap'ed > address. > > Cc: Jens Wiklander > Cc: Al Viro > Cc: "Fabio M. De Francesco" > Cc: Christoph Hellwig > Cc: Linus Torvalds > Signed-off-by: Ira Weiny > > --- > Changes from v1: > Al/Christoph: Remove kiov altogether > --- > drivers/tee/tee_shm.c | 21 ++++++++------------- > 1 file changed, 8 insertions(+), 13 deletions(-) > Reviewed-by: Sumit Garg -Sumit > diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c > index 527a6eabc03e..b1c6231defad 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) > @@ -24,26 +25,20 @@ 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; > + struct page *page; > 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); > - if (!kiov) > - return -ENOMEM; > - > + page = virt_to_page(start); > for (n = 0; n < page_count; n++) { > - kiov[n].iov_base = (void *)(start + n * PAGE_SIZE); > - kiov[n].iov_len = PAGE_SIZE; > + pages[n] = page + n; > + 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.39.1