From patchwork Mon Aug 9 15:24:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12426813 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 7D036C4338F for ; Mon, 9 Aug 2021 15:30:49 +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 3970660F93 for ; Mon, 9 Aug 2021 15:30:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3970660F93 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=y7mTmRiK+rZ6tgD08SRNynvl94DVnDi32KqjMeaukyM=; b=2GE+yxnil3uWeNcbqqTqi9cQqy 1BTkvZA431E12wkokI0A2Jj5ZzD+FWagFzNhCu92KcegUF1jdEgnCA9aejIomWJJZ3t7v+AqpEfvX aKmzIgtH1VCdRVxFufh0eFENKH4Mss0votbYGJ8CQ3wl7I8DGIyEyQrD1YwRSTVGcLDDalbojLb9B dYHc5GrFdRueonhFAphjfCmrV3ZsRsL54vQNKigQ4uaWE5ThGFUkMUGxmT0u0oY38kSRCsDKfOgzp ljAaARI+RqD7+fLuW845MsaHA7IEsPjQ6shTKO2PmxeUwlm3cQCGylaLOX+1eShui7W44+W2ZjU+7 0eHgtKOA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD7Cq-0019h9-HN; Mon, 09 Aug 2021 15:28:49 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD79M-0017v4-IO for linux-arm-kernel@lists.infradead.org; Mon, 09 Aug 2021 15:25:13 +0000 Received: by mail-qv1-xf49.google.com with SMTP id z25-20020a0ca9590000b029033ba243ffa1so12621397qva.0 for ; Mon, 09 Aug 2021 08:25:11 -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=WndYnCDMOQzlPd71DewOIEPIaBhgx4ZmPbtWCPoDRhI=; b=XGuSt0YhxsImBr6msmOACUEnWDe5RjoMRsWfC6joinmJxH/ccrEqwcaqr0K9ea4kDM PLHmWbi+Lhh8yLHGdXomBavPSRAVZMAL8cyJlzE7Ayf/3/45f4IoNaWo2Hb4qacFglSJ +BJ8TUJOkcwkRMUt0arMJGnO1cL6VjSD/1EiVvMtauBxIazQsTDmLji32PyBKfkGscqY O+JEUiGOAV/z1LTCyODiwmScRaa//NHIuIiu2LpdEoVb3iH/ax0Akw30emloxQ5Y3LWh H7zcq+JTl/1swFcTt7/katDOOq5zfZrHT4eTqWSmVRKgGfAImEknabYM4aLPjNb8p8J4 d1wA== 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=WndYnCDMOQzlPd71DewOIEPIaBhgx4ZmPbtWCPoDRhI=; b=H2VrTQz+NOFZxyKoN/EEbNc9836dQ2UQddthEyJIuhSuzjulNiWCQHa4+41hLt6cjG WVhGH91ur3gJhkU/W2161DN9mGHfjnTqp9h1K9Li+b9HK0KA3Lpx3pIRuLSen3T/H2CH 5QDyejOJg24pP5JhjO6+to6U1sOXtxcBJqvEwWLkqXaKYiQ1kFmjtIiwaBtsOGAZfnDl gPzjPpSeTjA84Cy7shJ6N1yH2S9ajl23ZilwzYccLF7+4VAnEA4esc2UPCcy0SAAMwOY T3zLg+tB4HUys/7woIEivasj8GeK+muwZOj4dAhJfedKzOr2TVvDmZ/96moi0wWzNYv6 VIfw== X-Gm-Message-State: AOAM531CDzQX1yQDigc2zbSR3ubCzi08Gj5yCH077FuhP7RYeJT2CLj9 JIsZXwnm81mFdl066hcaMRB65bp54SV2 X-Google-Smtp-Source: ABdhPJxKbzxXq3vACntXFb3WeX5U2azY/J4P0m64KOuxC+yq1GUbq1EaY8YQtx4SiagyVZzS09eoTaGzaXW+ X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:b0e8:d460:758b:a0ae]) (user=qperret job=sendgmr) by 2002:a05:6214:10c4:: with SMTP id r4mr24444934qvs.58.1628522711297; Mon, 09 Aug 2021 08:25:11 -0700 (PDT) Date: Mon, 9 Aug 2021 16:24:36 +0100 In-Reply-To: <20210809152448.1810400-1-qperret@google.com> Message-Id: <20210809152448.1810400-10-qperret@google.com> Mime-Version: 1.0 References: <20210809152448.1810400-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 09/21] 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, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210809_082512_654941_F5AA0E41 X-CRM114-Status: GOOD ( 12.87 ) 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. Reviewed-by: Fuad Tabba 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 1ee1168ac32d..2689fcb7901d 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -362,6 +362,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) { @@ -371,9 +386,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;