Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3883728pxv; Mon, 19 Jul 2021 11:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw062omwF8E18+jxZiUSgUiBaxFRKLDRrrTLXGxr/IJDBj7sitTQ64+WQj1Fj9r2Vy5VujT X-Received: by 2002:a05:6402:b4e:: with SMTP id bx14mr35933369edb.158.1626717841801; Mon, 19 Jul 2021 11:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626717841; cv=none; d=google.com; s=arc-20160816; b=iGcSPpfK5RCM2kpPmn1djJVXW4mdEXHV+siJmN7cE+RmWkYk9+6/IcgG6RutMinSfe +eo/K5ise+AqrhlmiY89ZL9xnGAOD3UKYABTRZYmcWz5yRPXjZc9iMgYw4aVvANl0Ywv nqJp5G2SudTlKuZNesdLaN4BUmIJ7Ma/bgY1bFjGxoBEJ28IKoVHHvddLvFgoC2tzaxa 1TACX+d412KRVPQRpqPCuNPgiCYPOgPzynvkObo4wOq940Avc4qJ1MMK5/D1pXn8pTuO HS0rEUsSfuVywwa+2eMthWS0/1/bMPlIJ0rQyIDuW+YlxrXFqwCJgYrti9B8opn5jWTr gddw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=lqk2jkzthWLyzhPPwl9UElGn40y2Dt6x0oKXE1RM9g8=; b=DVdI6/Z43g7ibheNOpGm5nLVkHpGqfGe8gQlWJG23EvNzmyukq03rqKuET8zEW3stP T4dvUbdQuKtREl4WLkV11T/KSafx0+sHnsJSss3nDcPxzahxjMkynOX/L/iACTcT6shq 9g6O2E1sAC4+jEu/xNsk+IqDxoZx0JMsGevoUcuLiX6+7iyF+AG3rMt3mUr/+6FU0ARZ +E8G5dwm9KpqAhtf/wsFs7FpFFTyCq0sJXcPJvPvfSXnZYA3wXC+wo9JxyXZjH8c93JT iaKGjsRLREsTVIeQjnwolodvX5lF43Nhv+CMHNHhRkAXV8DIy1RK+ozeIV7vRYZEftEi cIJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jI3en6+L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l26si22271585edq.393.2021.07.19.11.03.38; Mon, 19 Jul 2021 11:04:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jI3en6+L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376760AbhGSRQD (ORCPT + 99 others); Mon, 19 Jul 2021 13:16:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347301AbhGSPjZ (ORCPT ); Mon, 19 Jul 2021 11:39:25 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECCC9C0533A0 for ; Mon, 19 Jul 2021 08:30:43 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id c12so4639522wrt.3 for ; Mon, 19 Jul 2021 08:57:03 -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=lqk2jkzthWLyzhPPwl9UElGn40y2Dt6x0oKXE1RM9g8=; b=jI3en6+L35OGQjtiyLEBUmVWVLufhxwq/1aOfwuDJV44bcq1jbW0DRpXwwWlYvSdMk e4Xm3XmGv35SIVRFvfDV0Fdm1m0G59WRs/JZYelzbtxZfeEOv0+E2rKlGbQ1frzNzc76 fXzvmTXp+dnZBCwUIz5YNwPAkhnsQdXVRzQKoZsBp43fwvrYi9RgXPvTk1n7ltpWSPVQ IZp88OIXUDGh7cL1PTzzyxgcCC1TNFv7J2WYENBPUFn78VP+iJbtcr9SZZkNqNjdndnk FQG0OmlrWdFs0XoRXmu2H2p3Dl+9wpibmflX0a+iE/KQ2XvTufMt3nNZvVUNv9GRNHov 34sw== 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=lqk2jkzthWLyzhPPwl9UElGn40y2Dt6x0oKXE1RM9g8=; b=Y1XBrNGCQR0abYOiqUzr/21hPVRhUfnmqE3gan2HkGovcGO9BKTFMj1RAiqC9x2ZPb Hck39rMDhSJJDToO33IxL8PmJuhXLK2SoYPca0UviYrPe/obyv+sZN9G+w2wLyATaG7M KzVXO2ZjIxgQPIIANO1Lf9kbs0cKiRM/U0ZLhlk3FGIetHcexHJMFYVfo0d8l+GgSUUq SghQLa+kHwJBOgr/Mh3WOY/UGskajQEQb6Gs9ZH4N4WyHGsOmUKVivDl640OT3T/7wwu ILtp18/l/8PpsloXRZNfmOpzGq88TX01PUcsZgd9BhqK46kmqwOHaAhutQ+eCsaRv3ma fT2A== X-Gm-Message-State: AOAM530EJhDcg9gitbwdOf5c+eAZ7xMOqoiSBYVkgvJDekhJEsgjUs+y JaR8NVOhOywnA99hD/C9XZKspg== X-Received: by 2002:adf:a41e:: with SMTP id d30mr30429082wra.10.1626710221588; Mon, 19 Jul 2021 08:57:01 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:83e0:11ac:c870:2b97]) by smtp.gmail.com with ESMTPSA id w16sm6652930wru.58.2021.07.19.08.57.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jul 2021 08:57:01 -0700 (PDT) Date: Mon, 19 Jul 2021 16:56:57 +0100 From: Quentin Perret To: Marc Zyngier Cc: james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, 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 09/14] KVM: arm64: Mark host bss and rodata section as shared Message-ID: References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-10-qperret@google.com> <87eebujqjv.wl-maz@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eebujqjv.wl-maz@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 19 Jul 2021 at 16:01:40 (+0100), Marc Zyngier wrote: > On Mon, 19 Jul 2021 11:47:30 +0100, > Quentin Perret wrote: > > +static int finalize_mappings(void) > > +{ > > + enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_RWX; > > + 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 |= KVM_PGTABLE_STATE_SHARED | KVM_PGTABLE_STATE_BORROWED; > > + ret = host_stage2_idmap_locked(__hyp_pa(__start_rodata), > > + __hyp_pa(__end_rodata), prot); > > Do we really want to map the rodata section as RWX? I know, feels odd, but for now I think so. The host is obviously welcome to restrict things in its stage-1, but for stage-2, this is just 'memory' so far, the host is allowed to patch it if it wants too. Eventually, yes, I think we should make it RO in the host stage-2, but maybe that's for another series? > > + if (ret) > > + return ret; > > + > > + return host_stage2_idmap_locked(__hyp_pa(__hyp_bss_end), > > + __hyp_pa(__bss_stop), prot); > > If the 'locked' state implies SHARED+BORROWED, maybe consider moving > the ORRing of the prot into host_stage2_idmap_locked()? Ah no, sorry for the confusion, but 'locked' means that we already hold the pgtable lock. That is not actually true here, but this is a special case as only the current CPU can be messing with it at this point in time so taking the lock would just be wasted cycles. > > +} > > + > > 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; > > + > > pkvm_pgtable_mm_ops = (struct kvm_pgtable_mm_ops) { > > .zalloc_page = hyp_zalloc_hyp_page, > > .phys_to_virt = hyp_phys_to_virt, Thanks, Quentin