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.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,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 B0706C433E7 for ; Thu, 3 Sep 2020 04:20:46 +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 7A5F020709 for ; Thu, 3 Sep 2020 04:20:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JdSHeGo3"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZBYRylKm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A5F020709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com 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-Type: Content-Transfer-Encoding:Cc:Reply-To:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=649bxnZFgb1bWMelvs7/ISDyV9Q6JaoYSfraKr971L4=; b=JdSHeGo3AdZ4tO XxhzNkybwHExS1JM53BN5GebzoxVaDQtPtx4lft/Giptlu1BUbyst3kYqeICQj+U3KhwJDnUsfggV WCu2bq+aC0DrkVngkLy5nSa5GDAqmu1taOKUxgS/Fr6UuqekkHPSC5GT668NF9y+5qpvmLcsG1TFK FOF32KCSYRRBOryUGwX7pqvMfn0EMc8BWZbFsF95BxM3my+TRYqapR+49xRoMZ3W0/qtbAD/8EETl vvCYcR12aQEn03h9U1qYRHNDZDhekL9JQ+n3QZ+zQnx93zOuXK2/QVBcx4i4fes48jD6KkLYsvE+u ApKb34jzjLUL820J1L0w==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDgiX-0002bF-Ul; Thu, 03 Sep 2020 04:19:21 +0000 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120] helo=us-smtp-1.mimecast.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kDgiV-0002at-SG for linux-arm-kernel@lists.infradead.org; Thu, 03 Sep 2020 04:19:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599106759; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=584XaVrGi+xJM1XGEDcqtq3l41TaAqFE0T9kaltxvvA=; b=ZBYRylKmYgBN778gOA1igwHnu/tfw4Jn9F1Hfm/mJsv8kP7ekSMQfGf78warAyc7lmTiFd fGFVXQ1lubnAODXHzqCBQypUMMzi1wCFQ34T+LOylIfGeGK6RGhx5zse7ihiEGyQbWjvfp kRp6lO9sS3VRTTKOrlwyAf6F+3c4Dgs= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-99-EZT8GpPAOrWcBqpcSylj_Q-1; Thu, 03 Sep 2020 00:19:17 -0400 X-MC-Unique: EZT8GpPAOrWcBqpcSylj_Q-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 90843107464E; Thu, 3 Sep 2020 04:19:15 +0000 (UTC) Received: from [10.64.54.159] (vpn2-54-159.bne.redhat.com [10.64.54.159]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7810F5C1C4; Thu, 3 Sep 2020 04:19:12 +0000 (UTC) Subject: Re: [PATCH v3 09/21] KVM: arm64: Convert unmap_stage2_range() to generic page-table API To: Will Deacon , kvmarm@lists.cs.columbia.edu References: <20200825093953.26493-1-will@kernel.org> <20200825093953.26493-10-will@kernel.org> From: Gavin Shan Message-ID: Date: Thu, 3 Sep 2020 14:19:09 +1000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20200825093953.26493-10-will@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=gshan@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200903_001919_954722_5D0156D2 X-CRM114-Status: GOOD ( 27.95 ) 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: , Reply-To: Gavin Shan Cc: Suzuki Poulose , Marc Zyngier , Quentin Perret , James Morse , Catalin Marinas , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Will, On 8/25/20 7:39 PM, Will Deacon wrote: > Convert unmap_stage2_range() to use kvm_pgtable_stage2_unmap() instead > of walking the page-table directly. > > Cc: Marc Zyngier > Cc: Quentin Perret > Signed-off-by: Will Deacon > --- > arch/arm64/kvm/mmu.c | 57 +++++++++++++++++++++++++------------------- > 1 file changed, 32 insertions(+), 25 deletions(-) > Reviewed-by: Gavin Shan > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 704b471a48ce..751ce2462765 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -39,6 +39,33 @@ static bool is_iomap(unsigned long flags) > return flags & KVM_S2PTE_FLAG_IS_IOMAP; > } > > +/* > + * Release kvm_mmu_lock periodically if the memory region is large. Otherwise, > + * we may see kernel panics with CONFIG_DETECT_HUNG_TASK, > + * CONFIG_LOCKUP_DETECTOR, CONFIG_LOCKDEP. Additionally, holding the lock too > + * long will also starve other vCPUs. We have to also make sure that the page > + * tables are not freed while we released the lock. > + */ > +#define stage2_apply_range(kvm, addr, end, fn, resched) \ > +({ \ > + int ret; \ > + struct kvm *__kvm = (kvm); \ > + bool __resched = (resched); \ > + u64 next, __addr = (addr), __end = (end); \ > + do { \ > + struct kvm_pgtable *pgt = __kvm->arch.mmu.pgt; \ > + if (!pgt) \ > + break; \ > + next = stage2_pgd_addr_end(__kvm, __addr, __end); \ > + ret = fn(pgt, __addr, next - __addr); \ > + if (ret) \ > + break; \ > + if (__resched && next != __end) \ > + cond_resched_lock(&__kvm->mmu_lock); \ > + } while (__addr = next, __addr != __end); \ > + ret; \ > +}) > + > static bool memslot_is_logging(struct kvm_memory_slot *memslot) > { > return memslot->dirty_bitmap && !(memslot->flags & KVM_MEM_READONLY); > @@ -220,8 +247,8 @@ static inline void kvm_pgd_populate(pgd_t *pgdp, p4d_t *p4dp) > * end up writing old data to disk. > * > * This is why right after unmapping a page/section and invalidating > - * the corresponding TLBs, we call kvm_flush_dcache_p*() to make sure > - * the IO subsystem will never hit in the cache. > + * the corresponding TLBs, we flush to make sure the IO subsystem will > + * never hit in the cache. > * > * This is all avoided on systems that have ARM64_HAS_STAGE2_FWB, as > * we then fully enforce cacheability of RAM, no matter what the guest > @@ -344,32 +371,12 @@ static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 > bool may_block) > { > struct kvm *kvm = mmu->kvm; > - pgd_t *pgd; > - phys_addr_t addr = start, end = start + size; > - phys_addr_t next; > + phys_addr_t end = start + size; > > assert_spin_locked(&kvm->mmu_lock); > WARN_ON(size & ~PAGE_MASK); > - > - pgd = mmu->pgd + stage2_pgd_index(kvm, addr); > - do { > - /* > - * Make sure the page table is still active, as another thread > - * could have possibly freed the page table, while we released > - * the lock. > - */ > - if (!READ_ONCE(mmu->pgd)) > - break; > - next = stage2_pgd_addr_end(kvm, addr, end); > - if (!stage2_pgd_none(kvm, *pgd)) > - unmap_stage2_p4ds(mmu, pgd, addr, next); > - /* > - * If the range is too large, release the kvm->mmu_lock > - * to prevent starvation and lockup detector warnings. > - */ > - if (may_block && next != end) > - cond_resched_lock(&kvm->mmu_lock); > - } while (pgd++, addr = next, addr != end); > + WARN_ON(stage2_apply_range(kvm, start, end, kvm_pgtable_stage2_unmap, > + may_block)); > } > > static void unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 size) > Thanks, Gavin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel