From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-il1-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 58DA88F7C; Mon, 13 Feb 2023 16:47:08 +0000 (UTC) Received: by mail-il1-f180.google.com with SMTP id h4so2005314ile.5; Mon, 13 Feb 2023 08:47:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=gSXV3eBgQkMCCZdUZh+6ocU34hvWPvob14040D6fecE=; b=fhacIvVc7xfBs/S2rllDhsEA8jtgZBM1vhKpIHyfVXeCOND4D6mvHv7bf/bgZJKWS1 /KzSQ13KoRHD3PbxfR3fLhpT9q3FMKHx1Zm87+3SAaHInpV3tqmEDOljAc84X7JjJYIg fSzb4vFAfmRutK7fJxGwhfUZKw8rFLWPUB3J0hUb2EpPAJJumL/1BpbN1I3yXKz/w1yf rhyH1YtckKn2axZnfOERkuJDmkhjOtKKAMKJTqcoVh2erSwT3u345bYpNxfZFBDb6Na0 h+7NhAMgbjR6FnRUNzfq5kWjVGM8hkB+GFWwaAnrdz3aSwo/sCz3jQDeRpnTH1oVI7vL rDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSXV3eBgQkMCCZdUZh+6ocU34hvWPvob14040D6fecE=; b=sXjVuxcDpBX09YCHpEKvRtEitkRbWYKtsz2TJzXy8v1plqkpnWbxmqcNkC4qrdEmCc uHTnwbbO7TnW1L0Z2JmArvysmbzAXhVelAir/xb8JMCKLR7KxhVKXmxVcHkF3sSTk6Og gdtj8lekTTHDAdphpKyrZ/96dByMrD8hUzVhu7bHqZJ78FrB5F+BhXaC+XYeempDP2rP 7qrnUR3dHG1B1PeqNS5HYuvtKDeP6IbAUp8yLRVUbICLCvmKoM/xZKpVGQkQDHCSP8ip 0crWCjJfdcYu789v7J2zv/s8EvRnT0ZcAUIYng8Z0ReQnmSKomorVrTn6Dyf35Xkz8Lj KX9g== X-Gm-Message-State: AO0yUKXEBwdhIWE6DDMedA7Dq5OYd5QA33M3s1xva00OY1dUahGX56WB gfffTys0ETOut+PSMQq9gzM= X-Google-Smtp-Source: AK7set8BIqvM1v+cY/aL2Q6tJiBHTOHz5e48IASZEKjztVkYEWSohC1qa55WsxW1bZRA2xkb2VqUHA== X-Received: by 2002:a05:6e02:1d84:b0:315:39ce:abd2 with SMTP id h4-20020a056e021d8400b0031539ceabd2mr4730213ila.3.1676306827378; Mon, 13 Feb 2023 08:47:07 -0800 (PST) Received: from localhost (88-115-161-74.elisa-laajakaista.fi. [88.115.161.74]) by smtp.gmail.com with ESMTPSA id q11-20020a056e02106b00b00313b281ecd2sm3954758ilj.70.2023.02.13.08.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:47:07 -0800 (PST) Date: Mon, 13 Feb 2023 18:47:01 +0200 From: Zhi Wang To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , 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 Subject: Re: [RFC PATCH 08/28] arm64: RME: Keep a spare page delegated to the RMM Message-ID: <20230213184701.00005d3b@gmail.com> In-Reply-To: <20230127112932.38045-9-steven.price@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112932.38045-1-steven.price@arm.com> <20230127112932.38045-9-steven.price@arm.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) Precedence: bulk X-Mailing-List: linux-coco@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 27 Jan 2023 11:29:12 +0000 Steven Price wrote: > Pages can only be populated/destroyed on the RMM at the 4KB granule, > this requires creating the full depth of RTTs. However if the pages are > going to be combined into a 4MB huge page the last RTT is only > temporarily needed. Similarly when freeing memory the huge page must be > temporarily split requiring temporary usage of the full depth oF RTTs. > > To avoid needing to perform a temporary allocation and delegation of a > page for this purpose we keep a spare delegated page around. In > particular this avoids the need for memory allocation while destroying > the realm guest. > > Signed-off-by: Steven Price > --- > arch/arm64/include/asm/kvm_rme.h | 3 +++ > arch/arm64/kvm/rme.c | 6 ++++++ > 2 files changed, 9 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h > index 055a22accc08..a6318af3ed11 100644 > --- a/arch/arm64/include/asm/kvm_rme.h > +++ b/arch/arm64/include/asm/kvm_rme.h > @@ -21,6 +21,9 @@ struct realm { > void *rd; > struct realm_params *params; > > + /* A spare already delegated page */ > + phys_addr_t spare_page; > + > unsigned long num_aux; > unsigned int vmid; > unsigned int ia_bits; > diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c > index 9f8c5a91b8fc..0c9d70e4d9e6 100644 > --- a/arch/arm64/kvm/rme.c > +++ b/arch/arm64/kvm/rme.c > @@ -148,6 +148,7 @@ static int realm_create_rd(struct kvm *kvm) > } > > realm->rd = rd; > + realm->spare_page = PHYS_ADDR_MAX; > realm->ia_bits = VTCR_EL2_IPA(kvm->arch.vtcr); > > if (WARN_ON(rmi_rec_aux_count(rd_phys, &realm->num_aux))) { > @@ -357,6 +358,11 @@ void kvm_destroy_realm(struct kvm *kvm) > free_page((unsigned long)realm->rd); > realm->rd = NULL; > } > + if (realm->spare_page != PHYS_ADDR_MAX) { > + if (!WARN_ON(rmi_granule_undelegate(realm->spare_page))) > + free_page((unsigned long)phys_to_virt(realm->spare_page)); Will the page be leaked (not usable for host and realms) if the undelegate failed? If yes, better at least put a comment. > + realm->spare_page = PHYS_ADDR_MAX; > + } > > pgd_sz = kvm_pgd_pages(pgt->ia_bits, pgt->start_level); > for (i = 0; i < pgd_sz; i++) { From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4EAF7C636D4 for ; Mon, 13 Feb 2023 16:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BD7GfBtMvMDurOb3wTx5MsQPRsud+21YkruS15GR+xY=; b=NypKzkYLuNewp2 QS5S58ko6F4IjlBEvPfxMDitMpQ9ow6EjmyVnDPNDde+oa+/hyEt+6CLSzckdJ9z7gg1TSYUhF5lm du1Fr0m+SmQXbddXPiAAKUAW0chs37QrXmGx+0N+4XVvZ5IMbuZ6I87lGKznFivkcpnp0XFeK9Fbn KHoyewVCRiOXkDTQpW3VEVFhIqhPdIObFdKrWhZxTs8xJh9CYZQptQ+rMiJWpVOuCyeuQAYeuqbX4 1XwTRTaKmgj69CwMsCskI/eaMN3qm89xVicDuJmBOAEUHkzK0gdPo2sUjyRQ3p1e7AUUWzIdgZ9/l gjEn8PgjInxoqYO5qJ1Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRbz3-00FYx6-HN; Mon, 13 Feb 2023 16:47:18 +0000 Received: from mail-il1-x132.google.com ([2607:f8b0:4864:20::132]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pRbyv-00FYtL-U7 for linux-arm-kernel@lists.infradead.org; Mon, 13 Feb 2023 16:47:11 +0000 Received: by mail-il1-x132.google.com with SMTP id f10so5424543ilc.7 for ; Mon, 13 Feb 2023 08:47:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=gSXV3eBgQkMCCZdUZh+6ocU34hvWPvob14040D6fecE=; b=fhacIvVc7xfBs/S2rllDhsEA8jtgZBM1vhKpIHyfVXeCOND4D6mvHv7bf/bgZJKWS1 /KzSQ13KoRHD3PbxfR3fLhpT9q3FMKHx1Zm87+3SAaHInpV3tqmEDOljAc84X7JjJYIg fSzb4vFAfmRutK7fJxGwhfUZKw8rFLWPUB3J0hUb2EpPAJJumL/1BpbN1I3yXKz/w1yf rhyH1YtckKn2axZnfOERkuJDmkhjOtKKAMKJTqcoVh2erSwT3u345bYpNxfZFBDb6Na0 h+7NhAMgbjR6FnRUNzfq5kWjVGM8hkB+GFWwaAnrdz3aSwo/sCz3jQDeRpnTH1oVI7vL rDvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gSXV3eBgQkMCCZdUZh+6ocU34hvWPvob14040D6fecE=; b=D0Ki1Tmm2JEZdgGeE5CchYgyRX4u2i8H3sPCf4ggDjmVujlkq5Sq1YlWM+Rd00VQc1 v2eamM+irj0AtqBr+2LxEv2AYf4Qd2t7x6evzPxB+v5JsNnVu9t1cFboujxDww30RLVN X+sA9osTFq15eb+YKDfh7MNty7nW6n5j/c0ZQm53F6XAF2uSTj/GxG12HjlWkBZy1Fsz aAHJ5cZTqNdev81CGSbYfob4/aV8InbZnxUfC6s0+PYwuDHNykc0vSQRFY+WXllpqQSG PShQeryMaefD32apMlkez9UguRCHYULET+5mhm08ptrjNo4dHwPJXgyHaBtwTVB9iDw9 kHxA== X-Gm-Message-State: AO0yUKW69KzgTqtN5Eytdz887IqW1P89q4jsU1x39/kOaltAv2wJUyqb Py4QXf/gDRm1pB5Tm2i20oE= X-Google-Smtp-Source: AK7set8BIqvM1v+cY/aL2Q6tJiBHTOHz5e48IASZEKjztVkYEWSohC1qa55WsxW1bZRA2xkb2VqUHA== X-Received: by 2002:a05:6e02:1d84:b0:315:39ce:abd2 with SMTP id h4-20020a056e021d8400b0031539ceabd2mr4730213ila.3.1676306827378; Mon, 13 Feb 2023 08:47:07 -0800 (PST) Received: from localhost (88-115-161-74.elisa-laajakaista.fi. [88.115.161.74]) by smtp.gmail.com with ESMTPSA id q11-20020a056e02106b00b00313b281ecd2sm3954758ilj.70.2023.02.13.08.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 08:47:07 -0800 (PST) Date: Mon, 13 Feb 2023 18:47:01 +0200 From: Zhi Wang To: Steven Price Cc: kvm@vger.kernel.org, kvmarm@lists.linux.dev, Catalin Marinas , 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 Subject: Re: [RFC PATCH 08/28] arm64: RME: Keep a spare page delegated to the RMM Message-ID: <20230213184701.00005d3b@gmail.com> In-Reply-To: <20230127112932.38045-9-steven.price@arm.com> References: <20230127112248.136810-1-suzuki.poulose@arm.com> <20230127112932.38045-1-steven.price@arm.com> <20230127112932.38045-9-steven.price@arm.com> X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230213_084710_059092_A7926ADA X-CRM114-Status: GOOD ( 21.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, 27 Jan 2023 11:29:12 +0000 Steven Price wrote: > Pages can only be populated/destroyed on the RMM at the 4KB granule, > this requires creating the full depth of RTTs. However if the pages are > going to be combined into a 4MB huge page the last RTT is only > temporarily needed. Similarly when freeing memory the huge page must be > temporarily split requiring temporary usage of the full depth oF RTTs. > > To avoid needing to perform a temporary allocation and delegation of a > page for this purpose we keep a spare delegated page around. In > particular this avoids the need for memory allocation while destroying > the realm guest. > > Signed-off-by: Steven Price > --- > arch/arm64/include/asm/kvm_rme.h | 3 +++ > arch/arm64/kvm/rme.c | 6 ++++++ > 2 files changed, 9 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_rme.h b/arch/arm64/include/asm/kvm_rme.h > index 055a22accc08..a6318af3ed11 100644 > --- a/arch/arm64/include/asm/kvm_rme.h > +++ b/arch/arm64/include/asm/kvm_rme.h > @@ -21,6 +21,9 @@ struct realm { > void *rd; > struct realm_params *params; > > + /* A spare already delegated page */ > + phys_addr_t spare_page; > + > unsigned long num_aux; > unsigned int vmid; > unsigned int ia_bits; > diff --git a/arch/arm64/kvm/rme.c b/arch/arm64/kvm/rme.c > index 9f8c5a91b8fc..0c9d70e4d9e6 100644 > --- a/arch/arm64/kvm/rme.c > +++ b/arch/arm64/kvm/rme.c > @@ -148,6 +148,7 @@ static int realm_create_rd(struct kvm *kvm) > } > > realm->rd = rd; > + realm->spare_page = PHYS_ADDR_MAX; > realm->ia_bits = VTCR_EL2_IPA(kvm->arch.vtcr); > > if (WARN_ON(rmi_rec_aux_count(rd_phys, &realm->num_aux))) { > @@ -357,6 +358,11 @@ void kvm_destroy_realm(struct kvm *kvm) > free_page((unsigned long)realm->rd); > realm->rd = NULL; > } > + if (realm->spare_page != PHYS_ADDR_MAX) { > + if (!WARN_ON(rmi_granule_undelegate(realm->spare_page))) > + free_page((unsigned long)phys_to_virt(realm->spare_page)); Will the page be leaked (not usable for host and realms) if the undelegate failed? If yes, better at least put a comment. > + realm->spare_page = PHYS_ADDR_MAX; > + } > > pgd_sz = kvm_pgd_pages(pgt->ia_bits, pgt->start_level); > for (i = 0; i < pgd_sz; i++) { _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel