Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp363796rdb; Fri, 17 Nov 2023 00:30:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IEa6AbKMsX3yt+95Kx7jSvWWKruKG45vLtQaCCpqo4+tCtikvjgm8Iuw5o2I0rWz+yjqjo8 X-Received: by 2002:a17:90b:3a8a:b0:280:cc47:b60d with SMTP id om10-20020a17090b3a8a00b00280cc47b60dmr19308491pjb.14.1700209855144; Fri, 17 Nov 2023 00:30:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700209855; cv=none; d=google.com; s=arc-20160816; b=Rcp8oIzdZXUzp/iUDHcUFgbvbRUIzvPKwMt6cY8XSwdhFw0SJDsOls7dMCn550T38p aWCxQ++B3GLOT9rjoHBs9JwSVvy3cq9Cy3r8in7J/ChtHd1rneIDNPw0yKB5thFs0uFh dbRJaOOqx37+VKK9q6makU9S/lGKXuP4HntVzE7OILbOQ5x49LYKBiAUSMtIZW1UFWs3 fEGXpulLGnlnThBRXPAMGvamKN6lFfKGrkImMtXnrufU862FVsHX44kFHoa9QnETT9r/ UGkLtFn0WcCy0N+aticLNepU4EVnGRNo+elstIZwTP0fs1yGXXdcCNoJUEG/Q6A+39MG XOBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=CE3x8Je1GtPE/cdhBuD5VpOAYsIE+Hb1O7sGDllMALo=; fh=ZS5bARFln86Soy9hohmZKIGg6zMOhjbzdGwSQmqJC8A=; b=aDsOX+Xrr10SkhooSkWkWNBfbhd1a2kFMoU26T0Hj7mw2dtbHZfKfYniD6PSSwWAKE 07HjBwXAI5U9DvXS89uIcM4YYjjrqyKE2FrXtneik9s9tBNfsxQWlXsTuluc+UyRmNWh o0l3jORa5eD9+9LQvKOiEDomwGEoP7171gCMrJVzCkrTZ8SSwdPHUW+lTAN5KHMSkTZ1 NWsmr9+sDRxYvmXIP3Zx/el40zCUf96zeKKh6XeZ0FrHqK+CYApn6U9kDorXU6yiQfGm IRQAo9377lj4KrwCGPi0pFHTwXoapdgTEbr8y5/FQN6NugWAOy0ewwkNKkVPz9obQY4D 94CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LJpC4pKq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id gi9-20020a17090b110900b00279020d1fb0si1407100pjb.129.2023.11.17.00.30.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 00:30:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LJpC4pKq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8586C8082DFF; Fri, 17 Nov 2023 00:30:21 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjKQIaK (ORCPT + 99 others); Fri, 17 Nov 2023 03:30:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjKQIaJ (ORCPT ); Fri, 17 Nov 2023 03:30:09 -0500 Received: from mail-qv1-xf31.google.com (mail-qv1-xf31.google.com [IPv6:2607:f8b0:4864:20::f31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D962A7 for ; Fri, 17 Nov 2023 00:30:03 -0800 (PST) Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-6705379b835so9515336d6.1 for ; Fri, 17 Nov 2023 00:30:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700209802; x=1700814602; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=CE3x8Je1GtPE/cdhBuD5VpOAYsIE+Hb1O7sGDllMALo=; b=LJpC4pKqPLyVhTxISd03YaHPqf/qH0Jzu0Q6JGHXNjY1pDoPNycd5p9zAZNJzWw6Qn ZyjcqwXbQb3HI8tG2eAE8u74CLMCvmzjqFpsxBS4lqIWCV9Kd2/PcT+V00vBYsiH3F/V 2mhpYwQNhgFG1BDnEl4YSf26+jeo2taV/+h+TggOaxe3lIkidnM8eXipg4VlfdSsMBc7 EbZXNYTBKP12r70wFoU3Nk1KrY4P9Ki+biS9LsoGiqdtUB9q5flHIFmFJaopN4etEQ5U u9qq4RLwveVTkNZuXZzCFzQVeMiDHKUt+E1uizRRFR5R2kQxAG5t3AgSXar/62f/YNBX kTSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700209802; x=1700814602; h=content-transfer-encoding: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=CE3x8Je1GtPE/cdhBuD5VpOAYsIE+Hb1O7sGDllMALo=; b=ssLytILsBg3eF7jP2Qk1B0c8naSIn2an8T8Eww8tgrGrpjhtGRS538CDVArRKckzAK NjgfTYb3DC7D6iwcnQ7aVEI5IPdNZes+DeRdzRKqM5yqdglUVL3pP4Gj2o137T+AS6xd kSvr0BBSh2ivC3FNuvYGeemGYXgScm8RllBihi3ceSSV7FPSjwML+Ofp8KebhI264NXc Qecwvp6UPInxv/gf17yBBZw9Wgjh9UPxpvqRfO4FC3PW9frQX6X0RggQm55KNh9O+46i t5VJO8WGJBqaK8lVZs9m1ucH4ZA4kw+guN3M5m2zql8gV2i4zM1CP0yaUASG4tRqTE0p eS/w== X-Gm-Message-State: AOJu0YzYfXmSiiXE/pY66yziE2F66MRBfO4FIULDqvdG5N6tVrZ/cTtB JfXTB6jpRbejRjtE9YhIkHbvAiZsRrZtyHCOBAsBhQ== X-Received: by 2002:a05:6214:5493:b0:66d:138f:95df with SMTP id lg19-20020a056214549300b0066d138f95dfmr11297595qvb.56.1700209802237; Fri, 17 Nov 2023 00:30:02 -0800 (PST) MIME-Version: 1.0 References: <20231114095217.1142360-1-jens.wiklander@linaro.org> <20231114095217.1142360-2-jens.wiklander@linaro.org> In-Reply-To: From: Jens Wiklander Date: Fri, 17 Nov 2023 09:29:51 +0100 Message-ID: Subject: Re: [PATCH v3 1/2] optee: add page list to kernel private shared memory To: Sumit Garg Cc: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org, Jerome Forissier , Shyam Saini Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 00:30:21 -0800 (PST) On Thu, Nov 16, 2023 at 1:28=E2=80=AFPM Sumit Garg = wrote: > > On Tue, 14 Nov 2023 at 15:22, Jens Wiklander = wrote: > > > > Until now has kernel private shared memory allocated as dynamic shared > > memory (not from the static shared memory pool) been returned without a > > list of physical pages on allocations via RPC. To support allocations > > larger than one page add a list of physical pages. > > Although this patch looks like a good cleanup, I can't find an ABI > change here. Wasn't a list of pages returned earlier too? No, because handle_rpc_func_cmd_shm_alloc() didn't take the path where optee_allocate_pages_list() is called. Cheers, Jens > > -Sumit > > > > > Signed-off-by: Jens Wiklander > > --- > > drivers/tee/optee/core.c | 28 +++++++++++++---------- > > drivers/tee/optee/smc_abi.c | 45 +++++++++++++++++-------------------- > > 2 files changed, 37 insertions(+), 36 deletions(-) > > > > diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c > > index 2a258bd3b6b5..38ea2fecfc2e 100644 > > --- a/drivers/tee/optee/core.c > > +++ b/drivers/tee/optee/core.c > > @@ -27,7 +27,10 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool *= pool, struct tee_shm *shm, > > unsigned long start)= ) > > { > > unsigned int order =3D get_order(size); > > + unsigned int nr_pages =3D 1 << order; > > + struct page **pages; > > struct page *page; > > + unsigned int i; > > int rc =3D 0; > > > > /* > > @@ -42,30 +45,29 @@ int optee_pool_op_alloc_helper(struct tee_shm_pool = *pool, struct tee_shm *shm, > > shm->paddr =3D page_to_phys(page); > > shm->size =3D PAGE_SIZE << order; > > > > - if (shm_register) { > > - unsigned int nr_pages =3D 1 << order, i; > > - struct page **pages; > > + pages =3D kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL); > > + if (!pages) { > > + rc =3D -ENOMEM; > > + goto err; > > + } > > > > - pages =3D kcalloc(nr_pages, sizeof(*pages), GFP_KERNEL)= ; > > - if (!pages) { > > - rc =3D -ENOMEM; > > - goto err; > > - } > > + for (i =3D 0; i < nr_pages; i++) > > + pages[i] =3D page + i; > > > > - for (i =3D 0; i < nr_pages; i++) > > - pages[i] =3D page + i; > > + shm->pages =3D pages; > > + shm->num_pages =3D nr_pages; > > > > + if (shm_register) { > > rc =3D shm_register(shm->ctx, shm, pages, nr_pages, > > (unsigned long)shm->kaddr); > > - kfree(pages); > > if (rc) > > goto err; > > } > > > > return 0; > > - > > err: > > free_pages((unsigned long)shm->kaddr, order); > > + shm->kaddr =3D NULL; > > return rc; > > } > > > > @@ -77,6 +79,8 @@ void optee_pool_op_free_helper(struct tee_shm_pool *p= ool, struct tee_shm *shm, > > shm_unregister(shm->ctx, shm); > > free_pages((unsigned long)shm->kaddr, get_order(shm->size)); > > shm->kaddr =3D NULL; > > + kfree(shm->pages); > > + shm->pages =3D NULL; > > } > > > > static void optee_bus_scan(struct work_struct *work) > > diff --git a/drivers/tee/optee/smc_abi.c b/drivers/tee/optee/smc_abi.c > > index d5b28fd35d66..b69410c7cc0a 100644 > > --- a/drivers/tee/optee/smc_abi.c > > +++ b/drivers/tee/optee/smc_abi.c > > @@ -678,10 +678,11 @@ static void handle_rpc_func_cmd_shm_alloc(struct = tee_context *ctx, > > struct optee_msg_arg *arg, > > struct optee_call_ctx *call_c= tx) > > { > > - phys_addr_t pa; > > struct tee_shm *shm; > > size_t sz; > > size_t n; > > + struct page **pages; > > + size_t page_count; > > > > arg->ret_origin =3D TEEC_ORIGIN_COMMS; > > > > @@ -716,32 +717,23 @@ static void handle_rpc_func_cmd_shm_alloc(struct = tee_context *ctx, > > return; > > } > > > > - if (tee_shm_get_pa(shm, 0, &pa)) { > > - arg->ret =3D TEEC_ERROR_BAD_PARAMETERS; > > - goto bad; > > - } > > - > > - sz =3D tee_shm_get_size(shm); > > - > > - if (tee_shm_is_dynamic(shm)) { > > - struct page **pages; > > + /* > > + * If there are pages it's dynamically allocated shared memory = (not > > + * from the reserved shared memory pool) and needs to be > > + * registered. > > + */ > > + pages =3D tee_shm_get_pages(shm, &page_count); > > + if (pages) { > > u64 *pages_list; > > - size_t page_num; > > - > > - pages =3D tee_shm_get_pages(shm, &page_num); > > - if (!pages || !page_num) { > > - arg->ret =3D TEEC_ERROR_OUT_OF_MEMORY; > > - goto bad; > > - } > > > > - pages_list =3D optee_allocate_pages_list(page_num); > > + pages_list =3D optee_allocate_pages_list(page_count); > > if (!pages_list) { > > arg->ret =3D TEEC_ERROR_OUT_OF_MEMORY; > > goto bad; > > } > > > > call_ctx->pages_list =3D pages_list; > > - call_ctx->num_entries =3D page_num; > > + call_ctx->num_entries =3D page_count; > > > > arg->params[0].attr =3D OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT= | > > OPTEE_MSG_ATTR_NONCONTIG; > > @@ -752,17 +744,22 @@ static void handle_rpc_func_cmd_shm_alloc(struct = tee_context *ctx, > > arg->params[0].u.tmem.buf_ptr =3D virt_to_phys(pages_li= st) | > > (tee_shm_get_page_offset(shm) & > > (OPTEE_MSG_NONCONTIG_PAGE_SIZE - 1)); > > - arg->params[0].u.tmem.size =3D tee_shm_get_size(shm); > > - arg->params[0].u.tmem.shm_ref =3D (unsigned long)shm; > > > > - optee_fill_pages_list(pages_list, pages, page_num, > > + optee_fill_pages_list(pages_list, pages, page_count, > > tee_shm_get_page_offset(shm)); > > } else { > > + phys_addr_t pa; > > + > > + if (tee_shm_get_pa(shm, 0, &pa)) { > > + arg->ret =3D TEEC_ERROR_BAD_PARAMETERS; > > + goto bad; > > + } > > + > > arg->params[0].attr =3D OPTEE_MSG_ATTR_TYPE_TMEM_OUTPUT= ; > > arg->params[0].u.tmem.buf_ptr =3D pa; > > - arg->params[0].u.tmem.size =3D sz; > > - arg->params[0].u.tmem.shm_ref =3D (unsigned long)shm; > > } > > + arg->params[0].u.tmem.size =3D tee_shm_get_size(shm); > > + arg->params[0].u.tmem.shm_ref =3D (unsigned long)shm; > > > > arg->ret =3D TEEC_SUCCESS; > > return; > > -- > > 2.34.1 > >