From mboxrd@z Thu Jan 1 00:00:00 1970 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=-6.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=no 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 81341C4338F for ; Wed, 28 Jul 2021 12:17:52 +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 4BCB060F46 for ; Wed, 28 Jul 2021 12:17:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4BCB060F46 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:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=98xI1V5vqVvKoGGfSCTkOVxQ8ye0MYsR1X1fuPwaX1s=; b=dnaK4SDJIpKa7U dvwapNsd4JF/ABQwQUa4352vKvTcOlgGMWyhx075eC0+eN4M/XC8rtYu4YmEEFyK5FysootEOdpet kLWq3c5R2+BG44BjGRw6ztBQqswoZG4k2Jnjehz3vzWGhoI2L80L2/516n3HiCDDRursaUftIa6PE U0R/p67SiI+0OzPuufX1LyRiYzzz86ib6t28bz4hmwIRhKmO6nJY4zlyrn0T3TQ99ZzSosuQVBeTv mL6n1ahU9nSooLtOl2V++nDL0yhU4PQm0TI4WORtpjlTJVFXBjpmNOaoj2ufwIhwZKdVqvOLGCI6E o2UlCj3/Xh2ZWqZRUZCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8iSm-000bg1-VL; Wed, 28 Jul 2021 12:15:05 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8iSi-000bfJ-Px for linux-arm-kernel@lists.infradead.org; Wed, 28 Jul 2021 12:15:02 +0000 Received: by mail-wm1-x334.google.com with SMTP id d131-20020a1c1d890000b02902516717f562so1519300wmd.3 for ; Wed, 28 Jul 2021 05:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=mYbbIZoMD/b/Fq8e37HailMl4O7MY4m6Mt2gCBpEuDQ=; b=fqTrQ4uuHUeFCXJuKjWrrRZAjUSahCTgoWavfLLB4lOMC3ZYN+qMijBsymlR1rNoOv TZENLRhzK4CaipcXK90ge4PAAy3XlMGEgLugd/1FTgGlOw6NaMgGePd5Qq1wb60j8pOC V6T6u5XHmCmvkGD7Yu1lE/8Du+eMRUZUJNr84DGYfrJM5gBPbCL0lf5PgJJ3gU29r2Hn MApOPtQ30W4H8J/wz8oBgYYzwxVUYeroWafjX0hvAUzv7cxlXyTNPNpQ0SCBMhhX059q ahNwTVnKTF2LsmLZh5a2sEQOjMwzLrRA1gNMstiSvYy/TIEcVzg7CYhY0Rks1j+Zj41+ stiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=mYbbIZoMD/b/Fq8e37HailMl4O7MY4m6Mt2gCBpEuDQ=; b=uGgz1+nESSnxBMWvG8CH3KMl1ud7NrOMb3F0v9Rn7epZ4rB53BdLAupGf0ccsMq1n5 44pYGdPlaQaFSPzxQGNYeGC/uGMWrh8KF5F0j9RyLkRNdrT03bFOKRHXq32xLWjgbPEA HTMlLAtGgNSucDVL5Qyn0A8Lu+0Usqu2LglLfIfysj78mTSaiciuea3bNxfRrx2PXasJ 6KHqGL0e/FiIiPjRhW7WYQ2GYOdLDevIejFRcyg0XmkbjQA6ex9HzXcixxOC9nW3hXMg qDe07rsh4keP8K1SB1lcLNaO4nBCyEzdIWI0k7PN6cpW69S67yrL5raCcLZK8whwaGSB igeA== X-Gm-Message-State: AOAM531UFwiQvPUp6NCKAcuZZhxRDamlzfq6av2sX8eicY2m+rhjE9nY mWKjbNMBZJcdGtOE05pclh/AOw== X-Google-Smtp-Source: ABdhPJzgNbqRIxzd4hehDTC+KCWYXXRYwck4YjYrAzMJP5c35Whvluz0sZ3AKraerAUjQbY5ud0c6g== X-Received: by 2002:a7b:c5c7:: with SMTP id n7mr23388587wmk.5.1627474498601; Wed, 28 Jul 2021 05:14:58 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:ff6f:6a8e:935d:3f53]) by smtp.gmail.com with ESMTPSA id w5sm1534611wro.45.2021.07.28.05.14.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jul 2021 05:14:58 -0700 (PDT) Date: Wed, 28 Jul 2021 13:14:54 +0100 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 Subject: Re: [PATCH v2 12/16] KVM: arm64: Mark host bss and rodata section as shared Message-ID: References: <20210726092905.2198501-1-qperret@google.com> <20210726092905.2198501-13-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210726092905.2198501-13-qperret@google.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210728_051500_907018_D62CFAEF X-CRM114-Status: GOOD ( 19.08 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Monday 26 Jul 2021 at 10:29:01 (+0100), Quentin Perret wrote: > +static int finalize_mappings(void) > +{ > + enum kvm_pgtable_prot prot; > + int ret; > + > + /* > + * The host's .bss and .rodata sections are now conceptually owned by > + * the hypervisor, so mark them as 'borrowed' in the host stage-2. We > + * can safely use host_stage2_idmap_locked() at this point since the > + * host stage-2 has not been enabled yet. > + */ > + prot = pkvm_mkstate(KVM_PGTABLE_PROT_RWX, PKVM_PAGE_SHARED_BORROWED); > + ret = host_stage2_idmap_locked(__hyp_pa(__start_rodata), > + __hyp_pa(__end_rodata), prot); > + if (ret) > + return ret; > + > + return host_stage2_idmap_locked(__hyp_pa(__hyp_bss_end), > + __hyp_pa(__bss_stop), prot); > +} > + > void __noreturn __pkvm_init_finalise(void) > { > struct kvm_host_data *host_data = this_cpu_ptr(&kvm_host_data); > @@ -167,6 +199,10 @@ void __noreturn __pkvm_init_finalise(void) > if (ret) > goto out; > > + ret = finalize_mappings(); > + if (ret) > + goto out; While working on v3 of this series it occurred to me that we can actually do vastly better than this. Specifically, the annotation of shared pages currently happens in two places (recreate_hyp_mappings() and finalize_mappings()) with nothing to guarantee they are in sync. At the same time, the annotation of pages owned by the hypervisor is left to the host itself using the __pkvm_mark_hyp hypercall. But clearly, by the point we arrive to finalize_mappings() above, all the information I need is already stored in the hyp pgtable. That is, it should be fairly easy to walk the hyp stage-1, and for each valid mapping create a matching annotation in the host stage-2 to mark the page shared or owned by the hypervisor. I'll have a go at implementing this in v3, which would guarantee consistency across page-tables once the hypervisor is initialized, and also allow to get rid of __pkvm_mark_hyp entirely. But if anybody thinks this is a bad idea in the meantime, please shout! Thanks, Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel