From patchwork Tue Mar 12 00:57:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 10848453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4346E139A for ; Tue, 12 Mar 2019 00:58:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CC262932B for ; Tue, 12 Mar 2019 00:58:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2049C2940F; Tue, 12 Mar 2019 00:58:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6678229411 for ; Tue, 12 Mar 2019 00:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KcDF8moAxvfRySveAPsyvEpyMDIscNF/Kta5k4zeUQ4=; b=gTWZYKbvjd3kyx pvC0As9aDc9qamW8fFwYhF6SOwi+Z3DLxBwsS+w/Sh9vHfsRlCssTOVvSfpF7h1qoIyvy1MiIXUC8 CuWegim5enN+T+9WWj8sG0Jf8tQhWCND9WKfSheDTTAcl8x4yr11TgUlCLzWNh36USz3yEVMAb1PN /NfS/bGtXE86qMbG4JtJNJH3MdRxM2S0ZMQMEukWmUNJEPfmi4/ckN3nfm2tw2O3ftWk0d1PswuGa MC4wSbMCeu+rjCZzKF69yzpZlspRn2ZUbXpBXtb/CivzaIkblNmlRat3LphdzJxvdJSCBOqCyonFM mWvSX+yOPAUJXYyVKelw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h3Vka-00043K-S0; Tue, 12 Mar 2019 00:58:36 +0000 Received: from mail-it1-x149.google.com ([2607:f8b0:4864:20::149]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h3Vk9-0003Uj-SO for linux-arm-kernel@lists.infradead.org; Tue, 12 Mar 2019 00:58:11 +0000 Received: by mail-it1-x149.google.com with SMTP id v12so787145itv.9 for ; Mon, 11 Mar 2019 17:58:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=srduQGUMd+1T0rMo1nAAhODDuDFnWSZKCOfw6uJonls=; b=oedD/eggmV+SIgYB11JrwAoZLhFWdb50S/XNtFqL8BtNX+SDe5Glssl7AopEbDqcNA HCKLJ/V3bjISgT2y2KxWp3VykVnCmF5Y6Eu7pAUj8ZigjSaNi2yJ90jUlcOctuxB1Fbm A3C127QaAa54k+3O0L7KF5QaqVgnfjPJr6a85bI04USgXp04seBuyvB1LjH9V5YVSO4n 9poZ+ZPTh65xeVRUyWd030y18tK6PcucnaLZg/I1TUKe2kC6W9D9AdSqG6CQmwyqYYKV 4olxX5RbFrrKkNYKcwWg7HTaRF8nnkjP+yLqbV7GoSTMRn558HpMjY8QWgCmjB5DLMAj nSOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=srduQGUMd+1T0rMo1nAAhODDuDFnWSZKCOfw6uJonls=; b=DkJnOfY2VOjOh5uoYDDyVuXYqGbwzb68kXDNAsnSAoVgPkGyS4z/agQ9zevGBz4RIo QiYQTrYrjzopy/YgOY6bX8kIJUAO6J2L/wacNggiUI/wnOnKkyaIYmLTBBpitP9KlyMp S51c47E80vFX/EdpO9fS7EUc3qLazuZ/6vBb5F/NerIMO9bIb/VzY2OuDAyZ03pyh+Ku Y8p/N254Mn2Wmoy7a8Z1Jpc8LcT0fJNEHO0Ffh6+hbJlxjH36c4WpxSgJewHuq1SZOCV tTtvxELeGtzp0KZ4O/3GlPrJ9z6Pqfp2DlxdcxDGLB/IioB9mSkGuQuMYjzmzghwJqzb 3MVA== X-Gm-Message-State: APjAAAUZeHgOsP9zY5+3zL/uHs6/tRqcpVJfFgckRzMt5C0OsCYUIU+1 haIACQwvwh5FhjqGDGyLrduSOgLjovA= X-Google-Smtp-Source: APXvYqxqCOwYBxF/7ICjEeopmZPTb2uYLa3V2NjdBJYx9miVxqzRT+/6zNK7zIhloXUYTCZtvdQJhkLhhWk= X-Received: by 2002:a24:e984:: with SMTP id f126mr583102ith.1.1552352287403; Mon, 11 Mar 2019 17:58:07 -0700 (PDT) Date: Mon, 11 Mar 2019 18:57:48 -0600 In-Reply-To: <20190312005749.30166-1-yuzhao@google.com> Message-Id: <20190312005749.30166-3-yuzhao@google.com> Mime-Version: 1.0 References: <20190310011906.254635-1-yuzhao@google.com> <20190312005749.30166-1-yuzhao@google.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928-goog Subject: [PATCH v4 3/4] arm64: mm: call ctor for stage2 pmd page From: Yu Zhao To: Catalin Marinas , Will Deacon , Mark Rutland X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190311_175809_911795_E814CE51 X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Yu Zhao , Ard Biesheuvel , Peter Zijlstra , linux-kernel@vger.kernel.org, Nick Piggin , Jun Yao , linux-mm@kvack.org, "Aneesh Kumar K . V" , Chintan Pandya , Joel Fernandes , "Kirill A . Shutemov" , Andrew Morton , Laura Abbott , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Call pgtable_pmd_page_dtor() for pmd page allocated by mmu_memory_cache_alloc() so kernel won't crash when it's freed through stage2_pmd_free()->pmd_free()->pgtable_pmd_page_dtor(). This is needed if we are going to enable split pmd pt lock. Signed-off-by: Yu Zhao --- arch/arm64/include/asm/stage2_pgtable.h | 15 ++++++++++++--- virt/kvm/arm/mmu.c | 13 +++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm64/include/asm/stage2_pgtable.h b/arch/arm64/include/asm/stage2_pgtable.h index 5412fa40825e..0d9207144257 100644 --- a/arch/arm64/include/asm/stage2_pgtable.h +++ b/arch/arm64/include/asm/stage2_pgtable.h @@ -174,10 +174,19 @@ static inline bool stage2_pud_present(struct kvm *kvm, pud_t pud) return 1; } -static inline void stage2_pud_populate(struct kvm *kvm, pud_t *pud, pmd_t *pmd) +static inline int stage2_pud_populate(struct kvm *kvm, pud_t *pud, pmd_t *pmd) { - if (kvm_stage2_has_pmd(kvm)) - pud_populate(NULL, pud, pmd); + if (!kvm_stage2_has_pmd(kvm)) + return 0; + + /* paired with pgtable_pmd_page_dtor() in pmd_free() below */ + if (!pgtable_pmd_page_ctor(virt_to_page(pmd))) { + free_page((unsigned long)pmd); + return -ENOMEM; + } + + pud_populate(NULL, pud, pmd); + return 0; } static inline pmd_t *stage2_pmd_offset(struct kvm *kvm, diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index e9d28a7ca673..11922d84be83 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -1037,6 +1037,7 @@ static pud_t *stage2_get_pud(struct kvm *kvm, struct kvm_mmu_memory_cache *cache static pmd_t *stage2_get_pmd(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, phys_addr_t addr) { + int ret; pud_t *pud; pmd_t *pmd; @@ -1048,7 +1049,9 @@ static pmd_t *stage2_get_pmd(struct kvm *kvm, struct kvm_mmu_memory_cache *cache if (!cache) return NULL; pmd = mmu_memory_cache_alloc(cache); - stage2_pud_populate(kvm, pud, pmd); + ret = stage2_pud_populate(kvm, pud, pmd); + if (ret) + return ERR_PTR(ret); get_page(virt_to_page(pud)); } @@ -1061,6 +1064,9 @@ static int stage2_set_pmd_huge(struct kvm *kvm, struct kvm_mmu_memory_cache pmd_t *pmd, old_pmd; pmd = stage2_get_pmd(kvm, cache, addr); + if (IS_ERR(pmd)) + return PTR_ERR(pmd); + VM_BUG_ON(!pmd); old_pmd = *pmd; @@ -1198,6 +1204,7 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, phys_addr_t addr, const pte_t *new_pte, unsigned long flags) { + int ret; pud_t *pud; pmd_t *pmd; pte_t *pte, old_pte; @@ -1227,7 +1234,9 @@ static int stage2_set_pte(struct kvm *kvm, struct kvm_mmu_memory_cache *cache, if (!cache) return 0; /* ignore calls from kvm_set_spte_hva */ pmd = mmu_memory_cache_alloc(cache); - stage2_pud_populate(kvm, pud, pmd); + ret = stage2_pud_populate(kvm, pud, pmd); + if (ret) + return ret; get_page(virt_to_page(pud)); }