Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3235106lqo; Wed, 15 May 2024 04:01:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXrd8eWqGonzM7TDGvy95uc7OxbVPdVMY15KUAGc15bMgNPAjJq+YK1Fp/3YnRgmA+1M2BnltMwvKSSo637+L8lQjK0/m4u+pxiqei7Kw== X-Google-Smtp-Source: AGHT+IExFq9BeIXc5oPJ0LkgtdADAK0AMV40yHTwkU+BITBGgPAoCLxlLv2OLeoxORxNhb6TrFLf X-Received: by 2002:a50:d503:0:b0:56e:215b:75c2 with SMTP id 4fb4d7f45d1cf-5734d5c137amr10576145a12.17.1715770882216; Wed, 15 May 2024 04:01:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715770882; cv=pass; d=google.com; s=arc-20160816; b=D50BImoR30aqswuKf2USl8dofLIApfLjgms5EwvzIb1LswRREkfiwwFQW1BfWJ64GY HCgl3Cgt6UUcCgyQbLoQld1UBCIVF1IBdkj4ERPbOLukKAxHf8qzbtRhtAnRV75VlIf0 vMa4BVRWtUhVS2a+8hBPwBjzqAbpCX/0rrzILzLeVN/oxxXqEwwqGGgEgWPaxTpOqvI5 FXUqEk8HI/pI9SsT6mcLEoMeHQXUeIBc3nJLY9/Ewc5kLYJfcBRmOkRRcmwy2KqBFBhi ybsC5Zq7wKVO8OxzIDKIhN3wE8mflpOnh2uQtFpA3TX/+ywfEw0PdYN5mIIr+ZDe3z/D JHdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=Esw6GsoBImGvz3jyC+ulDXwXr2EXwZkbEN0gXA1A0NI=; fh=0PvXTblvcOsrMPT3yEGqxR5sUU4n6OEeMAbaOpzry54=; b=u41SaP8ONlau+tdlOlaU6zwWpirPyiHDb2YBPnNQytEJdue8P5wNr1Ost9FlV5VOgL +K2dH6Jasi3qq7OmuOqvJ0hagWFbrUenIW6CS1hhcIwN7xuaAHugd1npVesYTDTankMz ftcPnDqQfwRfpt9RkNhOYABkvUsM2c4tmlFenRMLuPLMBXSQzuGe7pQjZ5Nn/XI0uu5d 8Uu4OmYW4UNBFgNKrruf62jH2LXlb3tpq2YxgRETOb4sa3EyNdO/BPDoZ2qJglMO8V7a 6XoJd+cjVjeKwhxGM0xTFZtOvfgKaYk++nkRVrrq5Hq4BSwBmxzM8VIF3+EnG9uwhJuB zUKg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-179785-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beacac8si7262285a12.67.2024.05.15.04.01.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 04:01:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179785-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-179785-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179785-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id EF6511F24152 for ; Wed, 15 May 2024 11:01:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 029696D1B2; Wed, 15 May 2024 11:01:08 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6AC5B6166E; Wed, 15 May 2024 11:01:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715770867; cv=none; b=U+es19TjtnsbD95AZaBVIz5qPe1/+hrwGvZ5MkClahcQb1xrfKn/WTZ4uv0Lk/BLGI9KInPmcHTrYPGptrTcpsToPAh423advDErUj3PZ/ySnDzveRFbj3kgNnH4zOAEMABLGrBCz1tHm604KQ8Wrm9wl1BcpIiF97U19/zrZ0k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715770867; c=relaxed/simple; bh=qpg84gYPLFPNjhtRges7kVRAYlORPDiwFGtGDMreZmg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oJUNBKFvwluWjEqAYCjBkG6hY5WJO5RkqRYv/HET59YbH7JgJl+LMgsWWfS7eHmyDZz1WvCyltVDk/h5o2nUCvYooV/sNSII9l8SSAUXnyYEO8Q2MgP5ZrAMhRILkXLAFvn22XdvMPh793LnSU79Q/fNt2X1aF9VOIOREswNgjA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ECA0BC116B1; Wed, 15 May 2024 11:01:03 +0000 (UTC) Date: Wed, 15 May 2024 12:01:01 +0100 From: Catalin Marinas To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Marc Zyngier , Will Deacon , James Morse , Oliver Upton , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Joey Gouly , Alexandru Elisei , Christoffer Dall , Fuad Tabba , linux-coco@lists.linux.dev, Ganapatrao Kulkarni Subject: Re: [PATCH v2 12/14] arm64: realm: Support nonsecure ITS emulation shared Message-ID: References: <20240412084213.1733764-1-steven.price@arm.com> <20240412084213.1733764-13-steven.price@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240412084213.1733764-13-steven.price@arm.com> On Fri, Apr 12, 2024 at 09:42:11AM +0100, Steven Price wrote: > @@ -198,6 +201,33 @@ static DEFINE_IDA(its_vpeid_ida); > #define gic_data_rdist_rd_base() (gic_data_rdist()->rd_base) > #define gic_data_rdist_vlpi_base() (gic_data_rdist_rd_base() + SZ_128K) > > +static struct page *its_alloc_shared_pages_node(int node, gfp_t gfp, > + unsigned int order) > +{ > + struct page *page; > + > + if (node == NUMA_NO_NODE) > + page = alloc_pages(gfp, order); > + else > + page = alloc_pages_node(node, gfp, order); I think you can just call alloc_pages_node() in both cases. This function takes care of the NUMA_NO_NODE case itself. > + > + if (page) > + set_memory_decrypted((unsigned long)page_address(page), > + 1 << order); > + return page; > +} > + > +static struct page *its_alloc_shared_pages(gfp_t gfp, unsigned int order) > +{ > + return its_alloc_shared_pages_node(NUMA_NO_NODE, gfp, order); > +} > + > +static void its_free_shared_pages(void *addr, unsigned int order) > +{ > + set_memory_encrypted((unsigned long)addr, 1 << order); > + free_pages((unsigned long)addr, order); > +} More of a nitpick on the naming: Are these functions used by the host as well? The 'shared' part of the name does not make much sense, so maybe just call them its_alloc_page() etc. > @@ -3432,7 +3468,16 @@ static struct its_device *its_create_device(struct its_node *its, u32 dev_id, > nr_ites = max(2, nvecs); > sz = nr_ites * (FIELD_GET(GITS_TYPER_ITT_ENTRY_SIZE, its->typer) + 1); > sz = max(sz, ITS_ITT_ALIGN) + ITS_ITT_ALIGN - 1; > - itt = kzalloc_node(sz, GFP_KERNEL, its->numa_node); > + itt_order = get_order(sz); > + page = its_alloc_shared_pages_node(its->numa_node, > + GFP_KERNEL | __GFP_ZERO, > + itt_order); How much do we waste by going for a full page always if this is going to be used on the host? > + if (!page) > + return NULL; > + itt = (void *)page_address(page); page_address() has the void * type already. -- Catalin