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=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 F1B3BC4338F for ; Fri, 23 Jul 2021 16:18:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D473460E8B for ; Fri, 23 Jul 2021 16:18:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229722AbhGWPho (ORCPT ); Fri, 23 Jul 2021 11:37:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:57716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229693AbhGWPho (ORCPT ); Fri, 23 Jul 2021 11:37:44 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (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 8A84B60E0C; Fri, 23 Jul 2021 16:18:17 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m6xsN-000Wff-FV; Fri, 23 Jul 2021 17:18:15 +0100 Date: Fri, 23 Jul 2021 17:18:00 +0100 Message-ID: <87sg05dmx3.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org, Sean Christopherson , Matthew Wilcox , Paolo Bonzini , Will Deacon , Quentin Perret , James Morse , Suzuki K Poulose , kernel-team@android.com Subject: Re: [PATCH 2/5] KVM: arm64: Avoid mapping size adjustment on permission fault In-Reply-To: References: <20210717095541.1486210-1-maz@kernel.org> <20210717095541.1486210-3-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/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) 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.219.108.64 X-SA-Exim-Rcpt-To: alexandru.elisei@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-mm@kvack.org, seanjc@google.com, willy@infradead.org, pbonzini@redhat.com, will@kernel.org, qperret@google.com, james.morse@arm.com, suzuki.poulose@arm.com, kernel-team@android.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Fri, 23 Jul 2021 16:55:39 +0100, Alexandru Elisei wrote: > > Hi Marc, > > On 7/17/21 10:55 AM, Marc Zyngier wrote: > > Since we only support PMD-sized mappings for THP, getting > > a permission fault on a level that results in a mapping > > being larger than PAGE_SIZE is a sure indication that we have > > already upgraded our mapping to a PMD. > > > > In this case, there is no need to try and parse userspace page > > tables, as the fault information already tells us everything. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/kvm/mmu.c | 11 ++++++++--- > > 1 file changed, 8 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > > index db6314b93e99..c036a480ca27 100644 > > --- a/arch/arm64/kvm/mmu.c > > +++ b/arch/arm64/kvm/mmu.c > > @@ -1088,9 +1088,14 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > > * If we are not forced to use page mapping, check if we are > > * backed by a THP and thus use block mapping if possible. > > */ > > - if (vma_pagesize == PAGE_SIZE && !(force_pte || device)) > > - vma_pagesize = transparent_hugepage_adjust(kvm, memslot, hva, > > - &pfn, &fault_ipa); > > + if (vma_pagesize == PAGE_SIZE && !force_pte) { > > Looks like now it's possible to call transparent_hugepage_adjust() > for devices (if fault_status != FSC_PERM). Commit 2aa53d68cee6 > ("KVM: arm64: Try stage2 block mapping for host device MMIO") makes > a good case for the !device check. Was the check removed > unintentionally? That's what stupid bugs are made of. I must have resolved a rebase conflict the wrong way, and lost this crucial bit. Thanks for spotting this! Now fixed. > > > + if (fault_status == FSC_PERM && fault_granule > PAGE_SIZE) > > + vma_pagesize = fault_granule; > > + else > > + vma_pagesize = transparent_hugepage_adjust(kvm, memslot, > > + hva, &pfn, > > + &fault_ipa); > > + } > > This change makes sense to me - we can only get stage 2 permission > faults on a leaf entry since stage 2 tables don't have the > APTable/XNTable/PXNTable bits. The biggest block mapping size that > we support at stage 2 is PMD size (from > transparent_hugepage_adjust()), therefore if fault_granule is larger > than PAGE_SIZE, then it must be PMD_SIZE. Yup, exactly. Thanks again, M. -- Without deviation from the norm, progress is not possible.