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 57CBFC636CC for ; Mon, 13 Feb 2023 15:54:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230157AbjBMPyk (ORCPT ); Mon, 13 Feb 2023 10:54:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230437AbjBMPy2 (ORCPT ); Mon, 13 Feb 2023 10:54:28 -0500 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0503A17148 for ; Mon, 13 Feb 2023 07:54:26 -0800 (PST) Received: by mail-ed1-x531.google.com with SMTP id fi26so13523034edb.7 for ; Mon, 13 Feb 2023 07:54:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=KfZZZ7pG5QyK89tWcZZMAGkA5IayYu+p3Tr5HuPXiUQ=; b=AdQ0spNpvZO2a1rdXtFQKQz2a5nIbm1TP0nlRNVEw0a20VQsi4P2TewXf3rcx59UHK JBnJk0T5H9vMttktZQt5rRUgetkcXFJAOSz19WoAM8vq5qge57WOwoka8FiZJrUE1Ja2 GoWqE0CAilTX2E4o4EbrveWM+Z+6PiNYA1pmBDv2EwoB1C50Kqe8TLMM8ZF26zcM8hgS KNa5bJQT5+rg4V6OeKRrl3A8T3Ovdr652BEOONFJJRVMBYpXNInKBRTAODeD6GsbNjNw VzXTm+t87B7XrdydF30bBjZawimeVaBcap2kAM5Ztc5Zq34HK73VQsGIaofC2uzirgpg 6TAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=KfZZZ7pG5QyK89tWcZZMAGkA5IayYu+p3Tr5HuPXiUQ=; b=MOidY9tnQToO4ScsEdFA9KjQwqpsxQciW946OTRPeGnSehEcWGi2cLNB3pSMDZFWKb h02iC6BOAr2vww5BBUKRqlFD017YJlkVkJ8Uu99lGOanGnOO4OP3fiEQSl4PD3P4uSKz mzSLOjJSJfSUaeaFT/mniKfDwqyumrWQOkdrcWfnqRAb4rV1/Imo8MxlL+HgBRajyqyn uXtS/c6QwMTLxC++M/e/2tRrvrfIzAYEe4gPP7SRJs9oCq9T2P15sg9h+5grIjji5JUh aUqtLDr6vXBMFbcEfURZPCLATteTtUnyX5slZWKwLtQ6xRTV6w1Mppa8aUiGxFsOs1F0 mwfA== X-Gm-Message-State: AO0yUKXz1wk+nXArzGUl2tN0rfzJfqUqs711K+BlP47Rq/7Zu/H5eCKI b7LBNbPthk96tILxRv6jmKxE3w== X-Google-Smtp-Source: AK7set85G84Uc4/3S+BRufNyk4XF+mPrWyiWP+4v7igsCC0787RDUVcRHp/X2rzmloeF4VfNmt983Q== X-Received: by 2002:a50:d64e:0:b0:4ab:4ad1:a381 with SMTP id c14-20020a50d64e000000b004ab4ad1a381mr9872423edj.10.1676303665506; Mon, 13 Feb 2023 07:54:25 -0800 (PST) Received: from jade (h-46-59-78-111.A175.priv.bahnhof.se. [46.59.78.111]) by smtp.gmail.com with ESMTPSA id s6-20020a50d486000000b004aab36ad060sm6803430edi.92.2023.02.13.07.54.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 07:54:25 -0800 (PST) Date: Mon, 13 Feb 2023 16:54:23 +0100 From: Jens Wiklander To: Ira Weiny Cc: Sumit Garg , Andrew Morton , Al Viro , Christoph Hellwig , linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, linux-mm@kvack.org, "Fabio M. De Francesco" , John Hubbard , Linus Torvalds Subject: Re: [PATCH v2 2/4] tee: Remove vmalloc page support Message-ID: References: <20230203-get_kernel_pages-v2-0-f1dc4af273f1@intel.com> <20230203-get_kernel_pages-v2-2-f1dc4af273f1@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20230203-get_kernel_pages-v2-2-f1dc4af273f1@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 03, 2023 at 08:06:33PM -0800, 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() > > Remove the vmalloc page support from shm_get_kernel_pages(). Replace > with a warn on once. > > Cc: Al Viro > Cc: "Fabio M. De Francesco" > Cc: Christoph Hellwig > Cc: Linus Torvalds > Reviewed-by: Jens Wiklander > Signed-off-by: Ira Weiny > --- > drivers/tee/tee_shm.c | 36 ++++++++++++------------------------ > 1 file changed, 12 insertions(+), 24 deletions(-) Added to https://git.linaro.org/people/jens.wiklander/linux-tee.git/log/?h=get_kernel_pages-for-v6.4 Thanks, Jens > > 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.39.1