From patchwork Thu Jul 29 13:28:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12408729 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 9E412C432BE for ; Thu, 29 Jul 2021 13:34:36 +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 67FE460F42 for ; Thu, 29 Jul 2021 13:34:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 67FE460F42 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=N2hV3Ty3PD+sSiM1/jojwW4idGqvIV7s4YIZmSiBJ8s=; b=x29EjY0NMawqJcA1E4vpWwYo1P 1Mgm792YrmgfECEawaiXxLpWzZZLNNsZ/TKkOittA9fhXkafLRc9/R1DKCIsfk4LMztRtRoFfcxzY xRwDdFBVCcj8m+2A/a8EoJpoznCEJtNmvdBAFzL3s1mo+NnGjPeYmYrg27tfmGhCIXbBkV9NEP92p z9qQL1XZ81wOnFHBDFw6OmnAchyOqDkMETOprADAlN4vyNCnrZTWCkg2mW63yl9gslfpqNlc1B6Ep CEWmODRZYYpRHeOm9Qq9FHI+j4Ykbzd4OinRWRDPTw12l+E6W1/Wk7kRuITCwIQp7kdD3Ja9zPEcI cmD3Z+kQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m969V-004GMB-3l; Thu, 29 Jul 2021 13:32:45 +0000 Received: from mail-ed1-x54a.google.com ([2a00:1450:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m965h-004EeC-1d for linux-arm-kernel@lists.infradead.org; Thu, 29 Jul 2021 13:28:50 +0000 Received: by mail-ed1-x54a.google.com with SMTP id s8-20020a0564020148b02903948b71f25cso2942436edu.4 for ; Thu, 29 Jul 2021 06:28:45 -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=3edu5r5MgiwqKIsFZqWR1OVvbwtz5pLkXdnxfKTgrkE=; b=kiFyFVttc3U28KQ3sfRTofJfHRrKRTa08Tr1wUv7AmJ7kmxQRQqWLqlx2vJLxnRtiB gRP5OSpTMXZ/ELbIz+ZiYYSRyHJQB4gpq308Q//Q+M8a+IkmJK4zXuePNe1iad8R6ja5 eMzYY5Z+oyjxt+f/5LtLu0Hsc68dLxTSalqaiC6MOS51NM7Vok4vOIm5S9qUlX2pNnEf OeA6/wlF2Q8cQRv34+Q8Oe3lAuIlBdBzWJOPvwJcpQE1dOMoCrTw3OPaL+7abgre+E4P F0O7kH46klsMF5HsRReEdQc0jztwb9nOkD0bFWkPhtVneMWJ37S8n/CMDzd2iYeuib5c oFJw== 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=3edu5r5MgiwqKIsFZqWR1OVvbwtz5pLkXdnxfKTgrkE=; b=VWFfFvOyyg8JfGWrKi7orPJNU+Ke4yP4VNqMqnRzSAPFEQFBKWkEE8uJrzl8xlgcMg o9tVYtdlV2xyc0wbJPkZ3FInQDYI9i4cAe06qcVpD72JW0GLjZdzO/Hjuud/5f/zkxAG 0GWAQLHcI0ahK+mS1psF7rmFTpo3DQ3sl3f/JiUOB4Tedc5eBw6F9PXxRO9yEKl/FqA+ DDO3qRRhXd/28OvJC+3C70VsVT3sSZ0BIdSSgHujPdb780czHJvK0luAVcijFC0vF6nk zTJo6iRtoOuYOTLjMDZWoV1VtqHvaluaJYOxQPtucwVKCJrpQSl5MifLYvFyaoUo78o/ 7C7A== X-Gm-Message-State: AOAM530AIKvHr4nm6oB3UZn3BRbN4X4TjpO7w3iIegO3Tmn88LT97fXC 3Mt+KsDmvZ8ujQn+AqD+i2iCJgIW5Znq X-Google-Smtp-Source: ABdhPJwP/AN3fa8sbZcgybFMXXlf8hjA0Q9gZJpOb0OUTytheQm4ssO6cEU1bGXuFiecy7eUiVkRiSSKUJ8i X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a17:906:2bc9:: with SMTP id n9mr4537344ejg.23.1627565323698; Thu, 29 Jul 2021 06:28:43 -0700 (PDT) Date: Thu, 29 Jul 2021 14:28:06 +0100 In-Reply-To: <20210729132818.4091769-1-qperret@google.com> Message-Id: <20210729132818.4091769-10-qperret@google.com> Mime-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 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, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210729_062849_144192_991AC074 X-CRM114-Status: GOOD ( 11.90 ) 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 Reviewed-by: Fuad Tabba --- 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;