From patchwork Fri Mar 19 10:01:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12150623 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.0 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, 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 4AAC0C433DB for ; Fri, 19 Mar 2021 10:18:15 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 3688264EF6 for ; Fri, 19 Mar 2021 10:18:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3688264EF6 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; 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=SqxffOBDg63eTWpaJd0yP478V8Wtxv8+xcbPdjxLouo=; b=ENa/y4+64RIEvS ApnCcFbPKX3xQXYGs8OmVshDgV9T4rDbWR9iVfUawCTHfKX+/1+f68AaboJ9wQNBb4IjB/B+QMehZ sYFAI/EqPXLrHNjeySm9XcV5/ijrq/YH20p6ckj1reYK1jR0P43/hzmJDnFoWu0aKdzbbm1WTqu0L NGQN3y2EqMYSVQBUhcWHnq61bG+UeBcD9XalOA3tufuAJnYdjB+OHwFs55zRFutOk0PmMe5TOb9aO MqtumPkVj6e1Zemf2DNFw5MeLCzP2FHNCMSMms2N/1hX1kEJwwkHumsE/t2FXhOOGePTlVK1C3cLm AgGYOst+hJIXTVT31UvQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lNCBL-0075be-F2; Fri, 19 Mar 2021 10:16:39 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lNByA-0070Vn-7y for linux-arm-kernel@lists.infradead.org; Fri, 19 Mar 2021 10:03:07 +0000 Received: by mail-wm1-x349.google.com with SMTP id b20so7000319wmj.3 for ; Fri, 19 Mar 2021 03:03:00 -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=n6oA03qLjjcwBcDPSDV80wKa+1IBsnhq2bkZWDiODR0=; b=TBtrGf5J9GSkUt3b2QMHJgjotxPiRgZJPd7t0Rl9i8F+OSnh0QlipR4VWyCkBIBE1/ w9n80rWnVXqQOCU+0BPNn93dUIAuOiwEl2SSrONUZWjNuUoC48DwYVV4Vc+pka17RdJw YwmYzsL/FA1poINK+D45uXb7866EOkTqngIueW545/vd60y59pVB5ZY8OJKdD/6QdQtQ Zu4vGCwDv3N/+AtOwtettFL0mhuTkxWJdfksr/cQjWHTNgy959u6NYrmBz4cD2xUxXh2 BxJpKQ/VN+NwtBQpqQ3eJ8xZshcVIw5cHOeZbiN/Wsffafzm+SDb4bZYqzX2kBVYdqWD ITXg== 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=n6oA03qLjjcwBcDPSDV80wKa+1IBsnhq2bkZWDiODR0=; b=O17/OFv2GoyvGaXbZMu5FHSl3CJXmCImOwqWrsNHprY/IlmYgw6GGlS00hCpicXK+W s3ujdA6PpH+/ofd1tt47aDIuhXPiJttaDo7u1+Krxm4NBZLnkhTOcrtn8yJ8L+bVTGG1 204I+SLJVLsCaxTKqbJeXXsj0X5C1/z8o1CwSiEl/TSIxP4f5zYVrTsK/vlsFcrjkz5S 9Js//kRMlKFAnV5gQiXZPxAAIAREaFt+bBx0BrokZNgvT4dlQqy87qjnLvqNW9ECcs04 BFP4mAFgdrBoPAYpKgvMfgX46m0HmXiGTPDkE9q5tnoAFD1hIc2vF9r/n5gtOK9v8Cxs gKoA== X-Gm-Message-State: AOAM532KY8eNjPQppCoDDxNS525i6IUixaODPcpPMoUGWnXqh5p3Rckk 6kykSR6++Xng0l1BM+swPWwohFH7zNLY X-Google-Smtp-Source: ABdhPJwV6AcbNU8vjqv/vxj6ZmaNuK9vPiNcReyF8MlFlNm0j8dC0O+RJqRpgMWskICkLeA+1c+B+RkdnB4S X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a1c:4e12:: with SMTP id g18mr2881922wmh.56.1616148180533; Fri, 19 Mar 2021 03:03:00 -0700 (PDT) Date: Fri, 19 Mar 2021 10:01:41 +0000 In-Reply-To: <20210319100146.1149909-1-qperret@google.com> Message-Id: <20210319100146.1149909-34-qperret@google.com> Mime-Version: 1.0 References: <20210319100146.1149909-1-qperret@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v6 33/38] KVM: arm64: Introduce KVM_PGTABLE_S2_IDMAP stage 2 flag From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210319_100305_428011_96C84CA6 X-CRM114-Status: GOOD ( 11.20 ) 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 Introduce a new stage 2 configuration flag to specify that all mappings in a given page-table will be identity-mapped, as will be the case for the host. This allows to introduce sanity checks in the map path and to avoid programming errors. Suggested-by: Will Deacon Signed-off-by: Quentin Perret Acked-by: Will Deacon --- arch/arm64/include/asm/kvm_pgtable.h | 2 ++ arch/arm64/kvm/hyp/pgtable.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 55452f4831d2..c3674c47d48c 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -60,9 +60,11 @@ struct kvm_pgtable_mm_ops { * enum kvm_pgtable_stage2_flags - Stage-2 page-table flags. * @KVM_PGTABLE_S2_NOFWB: Don't enforce Normal-WB even if the CPUs have * ARM64_HAS_STAGE2_FWB. + * @KVM_PGTABLE_S2_IDMAP: Only use identity mappings. */ enum kvm_pgtable_stage2_flags { KVM_PGTABLE_S2_NOFWB = BIT(0), + KVM_PGTABLE_S2_IDMAP = BIT(1), }; /** diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index b22b4860630c..c37c1dc4feaf 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -760,6 +760,9 @@ int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, .arg = &map_data, }; + if (WARN_ON((pgt->flags & KVM_PGTABLE_S2_IDMAP) && (addr != phys))) + return -EINVAL; + ret = stage2_set_prot_attr(pgt, prot, &map_data.attr); if (ret) return ret;