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 8BDE7C4332F for ; Wed, 2 Nov 2022 02:24:04 +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:In-Reply-To:MIME-Version:References: 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=v3I7KrXk1KOHS3LvMX5+1nmDRHt14Ls+T6WnDt3O6A4=; b=idJh26redyPDZv U1ehs8xSHwdguv3YCjjib6FZZkGnytC/mOrblBuWQWgvqSbl6I/06+q2Vr6+EAp8iq0MheV3UCGe+ OKBWtD/4MYMy69vwG3WNETtR/fEV5x+6o/MdT+JWfQVCIySK49QV8yQNtqQ2SexZ8iQ2m5orA+bSO rrRrA3CyrojIqb+FOfOpJgGqpPVsSErsvlYiYRulLD82qLLhvxp4qZLAxu2NqEqJs++HkUcjS7BSF XMxzmkT9ms5aGzmsTc7bkABdiW+AdwiXPWxMdmTHoKrDo6Q4UYTq1fMV/ghUEHoChyZl08yxfyi9r m9owaXTZKgZWJj4ay+FQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oq3PA-0080Xw-Lw; Wed, 02 Nov 2022 02:23:00 +0000 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oq3P7-0080Wd-Os for linux-arm-kernel@lists.infradead.org; Wed, 02 Nov 2022 02:22:59 +0000 Received: by mail-pj1-x1030.google.com with SMTP id f5-20020a17090a4a8500b002131bb59d61so2391396pjh.1 for ; Tue, 01 Nov 2022 19:22:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; 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=7hSoZw8Zf9r0JK1yTid31zGLxatTQtFs42RwqoR9MRo=; b=Ng8PDPyEJvjQ2XkFaT8iC0xWn/YVIPJElzDnHLSa154sCHubjiCFseuLTA29wtVn2R zait5QjnAJ7IvjC8W30t65jJV7whAbjXACGhtTzRPXwLi9fs3sLug/C0i5q2bBLEdHU7 QCCXf1Vrag0ZU5y7uoj1xIONqFP8JUhvdbk4IWnOjpXmaRPf1mEZOMHjBGBLnCLx5msL QuzVoREpWdXwzrlPMjzQjmg9Sy8KtoWtFBEPDuBOY6vI9VmMKEa24XfIS/Zm6bxh/01i JRkg+az9LgxXdG0j84QZqfSgj5uEzZwv7njrg9bOyYQrJR5e3TJEGcUPHm4UiS1dtLik QqEw== 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=7hSoZw8Zf9r0JK1yTid31zGLxatTQtFs42RwqoR9MRo=; b=3G6LJ9W93FPeztSwlU/ikOHEIoPM3VaNCsucWy2fD1PpAquFngNcpGrkiTqKtqMCe5 GIzeitbmGrtkjfPa0dVrtgQ8px92+plk0Xktr5+x1ZnHhe0Lm4WwuQGWXaf/LXC1eBft MG7VFIaNW21vwA0dEb51t3Ar770d98k37kkMvwCGh0TfmLSmfPxZzNe5d4zQG1le3c9W prUln1NQNNEvMTXkj6r2A/a7VJ6Qa8Y4k0yqIQ6SEHx8GfVUoPHpL83MAC0FxT7y4es7 XjDhDrZhUgIIAy/C0Jd/CtSXr2XHekWflD7A8MnH9LXkK6T3VN8rp+50P3y3RMF/3wfR dxDQ== X-Gm-Message-State: ACrzQf0MMrEKm/c36dSvNdoMNn+MV5tl8hqeXHXW66Q1TxWRC1/iTS1d oI7BkwCX2N1NbXxvizx+upniHA== X-Google-Smtp-Source: AMsMyM4uWuLDXQgmDx+QR9W8VuKqSULuJ9Jeb7bJvEMPgTDunHhgg4PsCO+bVvZF+LmVAno5DuHQKQ== X-Received: by 2002:a17:902:d2c5:b0:186:afd7:56d3 with SMTP id n5-20020a170902d2c500b00186afd756d3mr22234372plc.142.1667355773730; Tue, 01 Nov 2022 19:22:53 -0700 (PDT) Received: from google.com (220.181.82.34.bc.googleusercontent.com. [34.82.181.220]) by smtp.gmail.com with ESMTPSA id p4-20020a622904000000b0056da2ad6503sm3485182pfp.39.2022.11.01.19.22.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Nov 2022 19:22:53 -0700 (PDT) Date: Tue, 1 Nov 2022 19:22:49 -0700 From: Ricardo Koller To: Oliver Upton Cc: Marc Zyngier , James Morse , Alexandru Elisei , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Reiji Watanabe , David Matlack , Quentin Perret , Ben Gardon , Gavin Shan , Peter Xu , Will Deacon , Sean Christopherson , kvmarm@lists.linux.dev Subject: Re: [PATCH v3 12/15] KVM: arm64: Make block->table PTE changes parallel-aware Message-ID: References: <20221027221752.1683510-1-oliver.upton@linux.dev> <20221027222247.1685023-1-oliver.upton@linux.dev> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20221027222247.1685023-1-oliver.upton@linux.dev> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221101_192257_834570_90E50FD0 X-CRM114-Status: GOOD ( 35.37 ) 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 Thu, Oct 27, 2022 at 10:22:47PM +0000, Oliver Upton wrote: > In order to service stage-2 faults in parallel, stage-2 table walkers > must take exclusive ownership of the PTE being worked on. An additional > requirement of the architecture is that software must perform a > 'break-before-make' operation when changing the block size used for > mapping memory. > > Roll these two concepts together into helpers for performing a > 'break-before-make' sequence. Use a special PTE value to indicate a PTE > has been locked by a software walker. Additionally, use an atomic > compare-exchange to 'break' the PTE when the stage-2 page tables are > possibly shared with another software walker. Elide the DSB + TLBI if > the evicted PTE was invalid (and thus not subject to break-before-make). > > All of the atomics do nothing for now, as the stage-2 walker isn't fully > ready to perform parallel walks. > > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/hyp/pgtable.c | 82 +++++++++++++++++++++++++++++++++--- > 1 file changed, 76 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 4c579b3beabf..1df858c21b2e 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -49,6 +49,12 @@ > #define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2) > #define KVM_MAX_OWNER_ID 1 > > +/* > + * Used to indicate a pte for which a 'break-before-make' sequence is in > + * progress. > + */ > +#define KVM_INVALID_PTE_LOCKED BIT(10) > + > struct kvm_pgtable_walk_data { > struct kvm_pgtable_walker *walker; > > @@ -674,6 +680,11 @@ static bool stage2_pte_is_counted(kvm_pte_t pte) > return !!pte; > } > > +static bool stage2_pte_is_locked(kvm_pte_t pte) > +{ > + return !kvm_pte_valid(pte) && (pte & KVM_INVALID_PTE_LOCKED); > +} > + > static bool stage2_try_set_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t new) > { > if (!kvm_pgtable_walk_shared(ctx)) { > @@ -684,6 +695,64 @@ static bool stage2_try_set_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_ > return cmpxchg(ctx->ptep, ctx->old, new) == ctx->old; > } > > +/** > + * stage2_try_break_pte() - Invalidates a pte according to the > + * 'break-before-make' requirements of the > + * architecture. > + * > + * @ctx: context of the visited pte. > + * @data: stage-2 map data > + * > + * Returns: true if the pte was successfully broken. > + * > + * If the removed pte was valid, performs the necessary serialization and TLB > + * invalidation for the old value. For counted ptes, drops the reference count > + * on the containing table page. > + */ > +static bool stage2_try_break_pte(const struct kvm_pgtable_visit_ctx *ctx, > + struct stage2_map_data *data) Would it be possible to pass "kvm_s2_mmu *mmu" directly (instead of "stage2_map_data *data")? so this function can be reused by other walkers. Another option would be to stash "struct kvm_s2_mmu" in "struct kvm_pgtable_visit_ctx". > +{ > + struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; > + > + if (stage2_pte_is_locked(ctx->old)) { > + /* > + * Should never occur if this walker has exclusive access to the > + * page tables. > + */ > + WARN_ON(!kvm_pgtable_walk_shared(ctx)); > + return false; > + } > + > + if (!stage2_try_set_pte(ctx, KVM_INVALID_PTE_LOCKED)) > + return false; > + > + /* > + * Perform the appropriate TLB invalidation based on the evicted pte > + * value (if any). > + */ > + if (kvm_pte_table(ctx->old, ctx->level)) > + kvm_call_hyp(__kvm_tlb_flush_vmid, data->mmu); > + else if (kvm_pte_valid(ctx->old)) > + kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, data->mmu, ctx->addr, ctx->level); > + > + if (stage2_pte_is_counted(ctx->old)) > + mm_ops->put_page(ctx->ptep); > + > + return true; > +} > + > +static void stage2_make_pte(const struct kvm_pgtable_visit_ctx *ctx, kvm_pte_t new) > +{ > + struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; > + > + WARN_ON(!stage2_pte_is_locked(*ctx->ptep)); > + > + if (stage2_pte_is_counted(new)) > + mm_ops->get_page(ctx->ptep); > + > + smp_store_release(ctx->ptep, new); > +} > + > static void stage2_put_pte(const struct kvm_pgtable_visit_ctx *ctx, struct kvm_s2_mmu *mmu, > struct kvm_pgtable_mm_ops *mm_ops) > { > @@ -795,7 +864,7 @@ static int stage2_map_walk_leaf(const struct kvm_pgtable_visit_ctx *ctx, > struct stage2_map_data *data) > { > struct kvm_pgtable_mm_ops *mm_ops = ctx->mm_ops; > - kvm_pte_t *childp; > + kvm_pte_t *childp, new; > int ret; > > ret = stage2_map_walker_try_leaf(ctx, data); > @@ -812,17 +881,18 @@ static int stage2_map_walk_leaf(const struct kvm_pgtable_visit_ctx *ctx, > if (!childp) > return -ENOMEM; > > + if (!stage2_try_break_pte(ctx, data)) { > + mm_ops->put_page(childp); > + return -EAGAIN; > + } > + > /* > * If we've run into an existing block mapping then replace it with > * a table. Accesses beyond 'end' that fall within the new table > * will be mapped lazily. > */ > - if (stage2_pte_is_counted(ctx->old)) > - stage2_put_pte(ctx, data->mmu, mm_ops); > - > new = kvm_init_table_pte(childp, mm_ops); > - mm_ops->get_page(ctx->ptep); > - smp_store_release(ctx->ptep, new); > + stage2_make_pte(ctx, new); > > return 0; > } > -- > 2.38.1.273.g43a17bfeac-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel