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 11B49C433EF for ; Fri, 10 Dec 2021 14:35:57 +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=vJklvhgR3lx1KK+Sxhm6L07rGC3c62nrXMZCYkOvq6Y=; b=be7SYKYWyBUsr6 VeRzt6/eR+FDg7RJiXKcrz4B5Jf3ZdSvg8w9dYzdNrxc0DFKFySA+vWq0J505IKfKbgui8mOJAJnk vhPwk+R7575u+PUids/j1LBGH5cjlbZkbhmsvKfQa+bUpTdlUx2HmZbdTLE4Ls2KeZg9vVbnOD7SW mJ26zcU8m8Fjj7qsKYdd9yOPIzHaPKEOcd9u/bHmzXRNyUve7fq3vYdHewlaY/sRwHa1twF7cFA+K mygUTYD+4YvdFs2HkebMcv/jt8OXlD5dB065P54SYwt3afbKHGEw2ffy53Wq0HD39aQeRYu1bi8AR /dcNs2J9qvDT1xB4Apdg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvgyg-002Dpu-5q; Fri, 10 Dec 2021 14:34:26 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mvgyc-002Doi-FE for linux-arm-kernel@lists.infradead.org; Fri, 10 Dec 2021 14:34:24 +0000 Received: by mail-wr1-x436.google.com with SMTP id t18so15213698wrg.11 for ; Fri, 10 Dec 2021 06:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=2GRxg5k+GfsTEG/HHuVw87NAnSnT8iO/e9MJjPT+e+o=; b=L1Ulimte4Z0H1umx57noMXuSMT9z2pNYcjaEcRkOmHyohqLlZ+Jry54jxw02IUiQ6b hZIeoWT+jE63R1PqJaesjr0s292gCWiojZhiGY8yrz8EvqzDidcmdx/BscgF2d0Gsw/c z+BcffbPwxmOIHinccz2yA5mfDkPrGDPikdswIP0JX2bHiTzy136GaNEbksFDzmHWkjA mM/uKKrvrs0+ilM7xZ5243GOYfYAZCPRIWdDiVy71XqKOxGNran1gLigBpqsktzZZZJL NTFLY8vXktAMnsiiuZwJXRS+33761Fln7pNz4LY9Gq37455yUWc28PC2BiTuyxFi8OeG LAYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=2GRxg5k+GfsTEG/HHuVw87NAnSnT8iO/e9MJjPT+e+o=; b=FjwuxO4Qyx3vaZinAwLNatocHFDh65zzAlw9WV4dGbcei2erFWBNaz3Hh+LBXCNYOe laBj9BpvtZCgAXDsv3VVZKLkBJcPgseriOK5OwHsJ6Hr/qOoOpD/MsQIk0YufVWCxQxk lbHTG8RNWkDDzhA28b6wneiSp21BK/R/ZoSoGKSzCoC+fFTmx4PlGZbFErAFzEvcTK2d Gc9ZLofbio45JpeMCnyiV8bx0GjZw7TTfcIhKj2cpaQiZQZaiWajeC3/rv9qBKFXWoFe 6MRJQHKSmRUHwn9AAzDqz+57RMH0pqsNcsnZ8Fw5PeX0tXcwqotiFKgbTYZdw2qP/f9A TfNg== X-Gm-Message-State: AOAM5319S+n7CGX9J9FfWaAoQqxGITXfgOwKy/abikBDSgcmB97JY/7D CswMd3VR25kB6GUKUGNj7ngOnA== X-Google-Smtp-Source: ABdhPJxiJpf2C0a+T3mNrYtnyB6jDvTMU3ozNfVS8W1q01Qvfry0eiftJK86AH/NRJNix5u8rcTx0A== X-Received: by 2002:a5d:514a:: with SMTP id u10mr14460951wrt.321.1639146860456; Fri, 10 Dec 2021 06:34:20 -0800 (PST) Received: from google.com ([2a00:79e0:d:210:76c1:fb36:1e22:8677]) by smtp.gmail.com with ESMTPSA id z8sm2918950wrh.54.2021.12.10.06.34.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Dec 2021 06:34:20 -0800 (PST) Date: Fri, 10 Dec 2021 14:34:16 +0000 From: Quentin Perret To: Will Deacon Cc: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com Subject: Re: [PATCH v3 03/15] KVM: arm64: Refcount hyp stage-1 pgtable pages Message-ID: References: <20211201170411.1561936-1-qperret@google.com> <20211201170411.1561936-4-qperret@google.com> <20211209102924.GC1833@willie-the-truck> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211209102924.GC1833@willie-the-truck> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211210_063422_559019_DF477ADE X-CRM114-Status: GOOD ( 21.00 ) 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 Thursday 09 Dec 2021 at 10:29:24 (+0000), Will Deacon wrote: > On Wed, Dec 01, 2021 at 05:03:57PM +0000, Quentin Perret wrote: > > To prepare the ground for allowing hyp stage-1 mappings to be removed at > > run-time, update the KVM page-table code to maintain a correct refcount > > using the ->{get,put}_page() function callbacks. > > > > Signed-off-by: Quentin Perret > > --- > > arch/arm64/kvm/hyp/pgtable.c | 17 ++++++++++++++--- > > 1 file changed, 14 insertions(+), 3 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index f8ceebe4982e..768a58835153 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -408,8 +408,10 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, > > return false; > > > > new = kvm_init_valid_leaf_pte(phys, data->attr, level); > > - if (hyp_pte_needs_update(old, new)) > > + if (hyp_pte_needs_update(old, new)) { > > smp_store_release(ptep, new); > > + data->mm_ops->get_page(ptep); > > In the case where we're just updating software bits for a valid pte, doesn't > this result in us taking a spurious reference to the page? Ahem, yes, that is the case. I ended up with the below diff to fix it, which I intend to fold in the next version: diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 6ad4cb2d6947..e2047d3f05a2 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -383,21 +383,6 @@ enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte) return prot; } -static bool hyp_pte_needs_update(kvm_pte_t old, kvm_pte_t new) -{ - /* - * Tolerate KVM recreating the exact same mapping, or changing software - * bits if the existing mapping was valid. - */ - if (old == new) - return false; - - if (!kvm_pte_valid(old)) - return true; - - return !WARN_ON((old ^ new) & ~KVM_PTE_LEAF_ATTR_HI_SW); -} - static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, struct hyp_map_data *data) { @@ -407,13 +392,16 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, if (!kvm_block_mapping_supported(addr, end, phys, level)) return false; + data->phys += granule; new = kvm_init_valid_leaf_pte(phys, data->attr, level); - if (hyp_pte_needs_update(old, new)) { - smp_store_release(ptep, new); + if (old == new) + return true; + else if (!kvm_pte_valid(old)) data->mm_ops->get_page(ptep); - } + else if (WARN_ON((old ^ new) & ~KVM_PTE_LEAF_ATTR_HI_SW)) + return false; - data->phys += granule; + smp_store_release(ptep, new); return true; } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel