From patchwork Mon Jul 26 09:28:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12398937 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 16072C4338F for ; Mon, 26 Jul 2021 09:33:58 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id D0F9E60F02 for ; Mon, 26 Jul 2021 09:33:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org D0F9E60F02 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:Cc: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=0BpDw4TZoRjOvCshN2+iKfbvsvqVU5NpxJXPWuuZH5w=; b=iO1WJeejCLVxVjBHp9W8TmtmT3 +IKVAPGUpuYPSG+KFxnz3rryRpp5qEmGwkMWPNNAp3nb8pLSgqUXymJEU3hPvUDT4vq859g3LuReD HCw+OUGnJkFCwcZ72fTtOhfzzLNKBjfaCZeY8tVI9pvxLPDkiQ8xDczK22dnBVuOCvyAZrA1cJLJJ KuhoA3WGB6iFpGjiZeye04B3BqD952YWySQv3zV698xfOeGSREkmhrL4m0/H2ODGisZQUGGuIl+zZ 3qd9Q+UZsWuW+648cFzGt5+Q3aqi2F/tTgQssF+dOaPPkqANhMBrPMM0IP+pRHiMerH1r9bzDKi7o g04phnMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7wxw-00ASeN-6J; Mon, 26 Jul 2021 09:32:04 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7wvR-00ARYo-41 for linux-arm-kernel@lists.infradead.org; Mon, 26 Jul 2021 09:29:30 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id js9-20020a0562142aa9b0290310fecb5f78so7949867qvb.0 for ; Mon, 26 Jul 2021 02:29:27 -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=HFQLFqYnlTo1lpqJ7D2ypgfrC23LiNE+ZmEwXkcYw0A=; b=emynXi8zGe9T2RndgYYOenyBOAtMls9A7ba9xIszaaQomvI/LjgYmTFavbkZgJJOTH jtvzzyteKVqko+G94XCfuANCCNBvhNP6T8mqrsBlRt2dIVhBPJQgOhI/dnyTrfGziGRE GcgWV2cqwrrCNSKHbUGrT0Hl1O/yQGv0tUrhtwxijYozBbsYTGsDQ6n+LTmNJwhn3cg8 WcykCVqR8O4yeSvhqiW3Qloa6Dgf7LRz4x2f1knnPA+hmnUz6ZdGf46FMq0Ziiv4b5kW v56uzZXpFd2basc8actTQOWCM+4oWAr9MsHdmrPOv0tj9Oqw6eVBoJowa+i4YfgCPyWT R30w== 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=HFQLFqYnlTo1lpqJ7D2ypgfrC23LiNE+ZmEwXkcYw0A=; b=ttQtTdCkA84OP/aFBz+g3nCv7PiHIwvS0GdXRy288L9FdvNMsa2XK3D7O5XMv3hbCc 11TVH9JgT/3NcpP87Q9DSemTNOHv8hmZs9KR61+PHB78UBh/bOd9VCNF5mvGHUW8jEkz t3qcTn12lN4EDVmtNyu1661Nu/zBzewsEzH4X03kAQ2JSJnNLZ+TMQmhwtxPm/yN5V2J KCL8pQrt3e4OfIgw7hNjRgyihJ3RAh46m/JRZEocS0ar7+DAYmckVVUQCoYeheiy7meU SF69pWsFi5x97YIa4ozDBE64CWlqKkb8L3DP0i0p2x2i5y+cfjoFG2WkNrmBOZ/vxASY vvJQ== X-Gm-Message-State: AOAM531Kv4tqaVDgcmCKYwhR/G3eRqyt1pZqxJh4y4BdOymv8xXC4szk 28WYAUTIYHg+R7wx/9mMjs2XHBl+WCkT X-Google-Smtp-Source: ABdhPJypoUwsNuwCxy8ymHAKoR1zqHYLDOPbF+TzYxseet5jGrMrBQsRY36QeoNA7Ahvpckl3UlgU5nhuRXS X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:23a0:2f14:433:e6cb]) (user=qperret job=sendgmr) by 2002:a05:6214:1021:: with SMTP id k1mr17176909qvr.4.1627291766710; Mon, 26 Jul 2021 02:29:26 -0700 (PDT) Date: Mon, 26 Jul 2021 10:28:56 +0100 In-Reply-To: <20210726092905.2198501-1-qperret@google.com> Message-Id: <20210726092905.2198501-8-qperret@google.com> Mime-Version: 1.0 References: <20210726092905.2198501-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v2 07/16] KVM: arm64: Tolerate re-creating hyp mappings to set software bits From: Quentin Perret To: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210726_022929_209111_32381655 X-CRM114-Status: GOOD ( 12.61 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The current hypervisor stage-1 mapping code doesn't allow changing an existing valid mapping. Relax this condition by allowing changes that only target software bits, as that will soon be needed to annotate shared pages. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/pgtable.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b5ca21b44b6a..93cc9de4d46c 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -375,6 +375,21 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) return 0; } +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) { @@ -384,9 +399,8 @@ static bool hyp_map_walker_try_leaf(u64 addr, u64 end, u32 level, if (!kvm_block_mapping_supported(addr, end, phys, level)) return false; - /* Tolerate KVM recreating the exact same mapping */ new = kvm_init_valid_leaf_pte(phys, data->attr, level); - if (old != new && !WARN_ON(kvm_pte_valid(old))) + if (hyp_pte_needs_update(old, new)) smp_store_release(ptep, new); data->phys += granule;