Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp423320img; Wed, 20 Mar 2019 03:36:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVfNo56o8By9Deask8B8AoL0wjETMFSKbKU8pQxz0sczTN1eKlgkl+Ytz1tQgtLUQfbybl X-Received: by 2002:aa7:9211:: with SMTP id 17mr6880710pfo.220.1553078177378; Wed, 20 Mar 2019 03:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553078177; cv=none; d=google.com; s=arc-20160816; b=rpm+Tm4M4oKPIl5gq9Do1UFPzBG52MCxm6zNWHtfCJSZ8J3bY088n+lasBlO/XuKqo IDR7dBMR/xsKr1v4RYYlBm9IzeDK6/IaKFWZQWg8TxMIkxGDjDBgPammV1knXc8No7jP Kj5vBQTtynB/2RzL4BTdNC+GodZMVu7yLqaA+gOz7gAPc6H5op7Ct4Oz7Jugq6a+pQtv mTSXdu0dx2ThYElnVz6UgMImS+80uWfTbhdz6O5HF30oMfMspSIiOO1kanb2wAGmzfMm WOKhAIMz3zkXxurQEdbmmnBQjfTwhKhqJqDxM7K7OepzOGnzkv3HMfO1Dexj/ioeUXyU 8zzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=JgGAYIR/v+XSPCp9t2PCVKXKxH8260Kw3pG0n4LNfbA=; b=0QFH+/xxaLxGMP3cwdyO+oLMsgioFGogcuSmV1inuw2AOGrz2nwCQ5QU2WXQmQRuJM xtBhaB0PnEBrg4kI2XsNqnBr7eFnv7LQwl5jtsQupkprinF7jDPCClaVAwkBlLjodAS/ cqXFpB+O1knCCp2/gmqxRvipXuHBZXw0c3XuI1xo73qFFumEz4x++kls2flbovv3fZ7Z T5wYSKZJnhLzrnt+HVyZxoLiZiBvWJtjp/rlAlkYFzsBdz9uz98oZukxiTV8PD4+sXJH P9VG0Pm4IAHr9ZO1XV33ucd3QD0ZdibVgvnAMDedj4dc5EkOf5HN7ULO9Olp3krjtobt Zc1w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x2si1346119pgg.187.2019.03.20.03.35.59; Wed, 20 Mar 2019 03:36:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727661AbfCTKfT (ORCPT + 99 others); Wed, 20 Mar 2019 06:35:19 -0400 Received: from foss.arm.com ([217.140.101.70]:37778 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbfCTKfT (ORCPT ); Wed, 20 Mar 2019 06:35:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 66DEF80D; Wed, 20 Mar 2019 03:35:18 -0700 (PDT) Received: from why.wild-wind.fr.eu.org (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7F8953F71A; Wed, 20 Mar 2019 03:35:15 -0700 (PDT) Date: Wed, 20 Mar 2019 10:35:11 +0000 From: Marc Zyngier To: Suzuki K Poulose Cc: , , , , , , , , , , , , , Subject: Re: [PATCH] kvm: arm: Fix handling of stage2 huge mappings Message-ID: <20190320103511.11d777b9@why.wild-wind.fr.eu.org> In-Reply-To: <4daf0783-fc50-3346-0732-1e3f53c8ccbc@arm.com> References: <25971fd5-3774-3389-a82a-04707480c1e0@huawei.com> <1553004668-23296-1-git-send-email-suzuki.poulose@arm.com> <86d0mmynaz.wl-marc.zyngier@arm.com> <5e7e40b4-7983-4440-179a-6f107cee5994@arm.com> <20190320101126.11ff63af@why.wild-wind.fr.eu.org> <4daf0783-fc50-3346-0732-1e3f53c8ccbc@arm.com> Organization: ARM Ltd X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 20 Mar 2019 10:23:39 +0000 Suzuki K Poulose wrote: Hi Suzuki, > Marc, > > On 20/03/2019 10:11, Marc Zyngier wrote: > > On Wed, 20 Mar 2019 09:44:38 +0000 > > Suzuki K Poulose wrote: > > > >> Hi Marc, > >> > >> On 20/03/2019 08:15, Marc Zyngier wrote: > >>> Hi Suzuki, > >>> > >>> On Tue, 19 Mar 2019 14:11:08 +0000, > >>> Suzuki K Poulose wrote: > >>>> > >>>> We rely on the mmu_notifier call backs to handle the split/merge > >>>> of huge pages and thus we are guaranteed that, while creating a > >>>> block mapping, either the entire block is unmapped at stage2 or it > >>>> is missing permission. > >>>> > >>>> However, we miss a case where the block mapping is split for dirty > >>>> logging case and then could later be made block mapping, if we cancel the > >>>> dirty logging. This not only creates inconsistent TLB entries for > >>>> the pages in the the block, but also leakes the table pages for > >>>> PMD level. > >>>> > >>>> Handle this corner case for the huge mappings at stage2 by > >>>> unmapping the non-huge mapping for the block. This could potentially > >>>> release the upper level table. So we need to restart the table walk > >>>> once we unmap the range. > >>>> > >>>> Fixes : ad361f093c1e31d ("KVM: ARM: Support hugetlbfs backed huge pages") > >>>> Reported-by: Zheng Xiang > >>>> Cc: Zheng Xiang > >>>> Cc: Zhengui Yu > >>>> Cc: Marc Zyngier > >>>> Cc: Christoffer Dall > >>>> Signed-off-by: Suzuki K Poulose ... > > > >>>> + if (!pmd_thp_or_huge(old_pmd)) { > >>>> + unmap_stage2_range(kvm, addr & S2_PMD_MASK, S2_PMD_SIZE); > >>>> + goto retry; > >>> > > >>>> + if (!stage2_pud_huge(kvm, old_pud)) { > >>>> + unmap_stage2_range(kvm, addr & S2_PUD_MASK, S2_PUD_SIZE); > >>> > > >> We should really get rid of the S2_P{U/M}D_* definitions, as they are > >> always the same as the host. The only thing that changes is the PGD size > >> which varies according to the IPA and the concatenation. > >> > > Also what do you think about using P{M,U}D_* instead of S2_P{M,U}D_* > above ? I could make that change with the respin. Given that this is a fix, I'd like it to be as small as obvious as possible, making it easier to backport. I'm happy to take another patch for 5.2 that will drop the whole S2_P* if we still think that this should be the case (though what I'd really like is to have architectural levels instead of these arbitrary definitions). Thanks, M. -- Without deviation from the norm, progress is not possible.