From mboxrd@z Thu Jan 1 00:00:00 1970 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 A77297FB for ; Wed, 12 Jul 2023 07:07:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 150EAC433C7; Wed, 12 Jul 2023 07:07:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689145629; bh=b7noUKfcalyzf/CV7ybs9JEgNqDnhjOvrl4eBbRhLlM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=HMFU8S0/nqVr7n2XC14ANUpJ5LPC0EAgwGBw06ZdUEBSrY2IsltHOphDIPJrP7iIz NbCy47XWt4tOBp/Bf8eKkMMbKX8PvcpelKckOItgcjfCtrs0EYKSpgHWtv/MSsK4fF 8dWcnY0v12tiXzsOdgAECl/0G8nJ8Uvtg89m4JMcggTdh/gBmNRZl67ED7hwmV3pMT JwixpKCM1Be2unRP8rh9UZFVS4HQQOoBUEoAe5FWcufjoS4gexXXrCf6rRYaL3QSQH iuxTCJWMRdBHMP4Xijkb+7TdUqGMGJX9/tNXU/qxKq6P7SBCJhxLQbJMvJMv2Td9mH Y6L+LS7FN8PsQ== Received: from ip-185-104-136-29.ptr.icomera.net ([185.104.136.29] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qJTwI-00CMIW-Ks; Wed, 12 Jul 2023 08:07:06 +0100 Date: Wed, 12 Jul 2023 08:07:01 +0100 Message-ID: <87jzv5a9re.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Cc: kvmarm@lists.linux.dev, James Morse , Suzuki K Poulose , Zenghui Yu , Reiji Watanabe , stable@vger.kernel.org, Yu Zhao Subject: Re: [PATCH v2] KVM: arm64: Correctly handle page aging notifiers for unaligned memslot In-Reply-To: References: <20230627235405.4069823-1-oliver.upton@linux.dev> <86edlewyh2.wl-maz@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.104.136.29 X-SA-Exim-Rcpt-To: oliver.upton@linux.dev, kvmarm@lists.linux.dev, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, reijiw@google.com, stable@vger.kernel.org, yuzhao@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Hi Oliver., On Tue, 11 Jul 2023 19:04:27 +0100, Oliver Upton wrote: > > Hey Marc, > > On Tue, Jul 11, 2023 at 11:10:01AM +0100, Marc Zyngier wrote: > > On Wed, 28 Jun 2023 00:54:05 +0100, Oliver Upton wrote: > > > +static int stage2_age_walker(const struct kvm_pgtable_visit_ctx *ctx, > > > + enum kvm_pgtable_walk_flags visit) > > > { > > > - kvm_pte_t pte = 0; > > > - stage2_update_leaf_attrs(pgt, addr, 1, 0, KVM_PTE_LEAF_ATTR_LO_S2_AF, > > > - &pte, NULL, 0); > > > + kvm_pte_t new = ctx->old & ~KVM_PTE_LEAF_ATTR_LO_S2_AF; > > > + struct stage2_age_data *data = ctx->arg; > > > + > > > + if (!kvm_pte_valid(ctx->old) || new == ctx->old) > > > + return 0; > > > + > > > + data->young = true; > > > + > > > + if (data->mkold && !stage2_try_set_pte(ctx, new)) > > > + return -EAGAIN; > > > + > > > /* > > > * "But where's the TLBI?!", you scream. > > > * "Over in the core code", I sigh. > > > * > > > * See the '->clear_flush_young()' callback on the KVM mmu notifier. > > > */ > > > - return pte; > > > + return 0; > > > } > > > > > > -bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr) > > > +bool kvm_pgtable_stage2_test_clear_young(struct kvm_pgtable *pgt, u64 addr, > > > + u64 size, bool mkold) > > > { > > > - kvm_pte_t pte = 0; > > > - stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, &pte, NULL, 0); > > > - return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF; > > > + struct stage2_age_data data = { > > > + .mkold = mkold, > > > + }; > > > + struct kvm_pgtable_walker walker = { > > > + .cb = stage2_age_walker, > > > + .arg = &data, > > > + .flags = KVM_PGTABLE_WALK_LEAF, > > > + }; > > > + > > > + WARN_ON(kvm_pgtable_walk(pgt, addr, size, &walker)); > > > > Do we really want a WARN_ON() here? From what I can tell, it can be > > (trivially?) triggered by the previous function returning -EAGAIN if > > the pte update fails in the case of a shared walk. > > I threw the -EAGAIN in there just due to reflexes, we're holding the MMU > write lock at this point so stage2_try_set_pte() will always succeed. A > tad fragile, but wanted to make it trivial to change the locking around > stage2_age_walker() in the future. Right, the notifier takes the write lock, ensuring that there is never a concurrent access. Maybe a small comment above the return would help, as '-EAGAIN' is easily interpreted as "we missed the boat, but we'll take the next one, no big deal". > > The reason I wanted to have a WARN here is because we're unable to > return an error on the MMU notifier and might need some breadcrumbs to > debug any underlying issues in the table walker. I'd really like to keep > it in some form. > > I can either replace stage2_try_set_pte() with a direct WRITE_ONCE() > (eliminating the error path) or leave it as-is. Which do you prefer? With the above nit addressed: Reviewed-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.