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 X-Spam-Level: X-Spam-Status: No, score=-11.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C482FC433E7 for ; Wed, 2 Sep 2020 11:31:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E0332065E for ; Wed, 2 Sep 2020 11:31:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="xV0snsDA"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="1SIc18CI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E0332065E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=ChKt8GK96STpDcaJ8+95lcTr2Ror0x2dJ1yClSuVJXY=; b=xV0snsDAjePuNtIeGkLnyluIu ZZ7YhZSrvWx0rnc/lxz23dD3Hr6a/eJXGDT99Z3Gy50tRy+Unj1hIVzIXNZMemoIwapwvOiEXl8ST m8CFyZYWK2usNFgU/nQGmMzzGiYajKGMP8nhPWOokbH/Qp+5XxFQ8aUp0+Twj32wWMoMziPEAXDfj eLCwf271KM7d28NsdMt071OY4dxT10dh+Dk08W8lr5w+UCx6+FhRrih3t6w0B/qzvqLkoiKy3G6XS P9bq/wJqQxmp0vNJ0HycE3xQ3e5Tz85iqGaOMi6AoSrA38b7uzWmVI+plZIl0kyNXTen8bHleeMjO joCc/9X7A==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDQyA-00049s-Pp; Wed, 02 Sep 2020 11:30:26 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDQy7-00049H-8t for linux-arm-kernel@lists.infradead.org; Wed, 02 Sep 2020 11:30:24 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 11F992065E; Wed, 2 Sep 2020 11:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599046222; bh=/QphwwPl0pPHSe5XcEimALyTKTsr0FajRgwf964VZls=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=1SIc18CIsgpbgZoEScseMXlZJgmz34vuIlKGYIk7GKuvGWBkLqI2QOmKfqmmS7qbe jdN9PaSxE3+OwIXS6Op+VlZtRlK+UPpyV5ZgzxgNeeX7mQVMBcdq9uza7dATQ55Lwl nUj6fZxOi9w8vKg5xgYUB23cj4ms4HjnyzB6Tnz0= Date: Wed, 2 Sep 2020 12:30:17 +0100 From: Will Deacon To: Gavin Shan Subject: Re: [PATCH v3 05/21] KVM: arm64: Add support for creating kernel-agnostic stage-2 page tables Message-ID: <20200902113014.GA5838@willie-the-truck> References: <20200825093953.26493-1-will@kernel.org> <20200825093953.26493-6-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200902_073023_773742_DC248D51 X-CRM114-Status: GOOD ( 26.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Suzuki Poulose , Marc Zyngier , Quentin Perret , James Morse , Catalin Marinas , kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org 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 Wed, Sep 02, 2020 at 04:40:03PM +1000, Gavin Shan wrote: > On 8/25/20 7:39 PM, Will Deacon wrote: > > Introduce alloc() and free() functions to the generic page-table code > > for guest stage-2 page-tables and plumb these into the existing KVM > > page-table allocator. Subsequent patches will convert other operations > > within the KVM allocator over to the generic code. > > > > Cc: Marc Zyngier > > Cc: Quentin Perret > > Signed-off-by: Will Deacon > > --- > > arch/arm64/include/asm/kvm_host.h | 1 + > > arch/arm64/include/asm/kvm_pgtable.h | 18 +++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 51 ++++++++++++++++++++++++++ > > arch/arm64/kvm/mmu.c | 55 +++++++++++++++------------- > > 4 files changed, 99 insertions(+), 26 deletions(-) > > > > With the following one question resolved: > > Reviewed-by: Gavin Shan Thanks! > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index fabd72b0c8a4..4607e9ca60a2 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > @@ -668,47 +668,49 @@ int create_hyp_exec_mappings(phys_addr_t phys_addr, size_t size, > > * @kvm: The pointer to the KVM structure > > * @mmu: The pointer to the s2 MMU structure > > * > > - * Allocates only the stage-2 HW PGD level table(s) of size defined by > > - * stage2_pgd_size(mmu->kvm). > > - * > > + * Allocates only the stage-2 HW PGD level table(s). > > * Note we don't need locking here as this is only called when the VM is > > * created, which can only be done once. > > */ > > int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu) > > { > > - phys_addr_t pgd_phys; > > - pgd_t *pgd; > > - int cpu; > > + int cpu, err; > > + struct kvm_pgtable *pgt; > > - if (mmu->pgd != NULL) { > > + if (mmu->pgt != NULL) { > > kvm_err("kvm_arch already initialized?\n"); > > return -EINVAL; > > } > > - /* Allocate the HW PGD, making sure that each page gets its own refcount */ > > - pgd = alloc_pages_exact(stage2_pgd_size(kvm), GFP_KERNEL | __GFP_ZERO); > > - if (!pgd) > > + pgt = kzalloc(sizeof(*pgt), GFP_KERNEL); > > + if (!pgt) > > return -ENOMEM; > > - pgd_phys = virt_to_phys(pgd); > > - if (WARN_ON(pgd_phys & ~kvm_vttbr_baddr_mask(kvm))) > > - return -EINVAL; > > + err = kvm_pgtable_stage2_init(pgt, kvm); > > + if (err) > > + goto out_free_pgtable; > > mmu->last_vcpu_ran = alloc_percpu(typeof(*mmu->last_vcpu_ran)); > > if (!mmu->last_vcpu_ran) { > > - free_pages_exact(pgd, stage2_pgd_size(kvm)); > > - return -ENOMEM; > > + err = -ENOMEM; > > + goto out_destroy_pgtable; > > } > > for_each_possible_cpu(cpu) > > *per_cpu_ptr(mmu->last_vcpu_ran, cpu) = -1; > > mmu->kvm = kvm; > > - mmu->pgd = pgd; > > - mmu->pgd_phys = pgd_phys; > > + mmu->pgt = pgt; > > + mmu->pgd_phys = __pa(pgt->pgd); > > + mmu->pgd = (void *)pgt->pgd; > > mmu->vmid.vmid_gen = 0; > > - > > return 0; > > + > > +out_destroy_pgtable: > > + kvm_pgtable_stage2_destroy(pgt); > > +out_free_pgtable: > > + kfree(pgt); > > + return err; > > } > > > > kvm_pgtable_stage2_destroy() might not needed here because > the stage2 page pgtable is empty so far. However, it should > be rare to hit the case. If I'm correct, what we need to do > is just freeing the PGDs. Right, but kvm_pgtable_stage2_destroy() also frees the PGDs because it knows how many pages there are and they were allocated by kvm_pgtable_stage2_init(). Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel