From nobody Tue Feb 10 01:35:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1584893749; cv=none; d=zohomail.com; s=zohoarc; b=dvbXtmyCNziQsVzYElgA/NEpdlA3jEbGQhWi2p8NQ2FLpRR6f3M8lc3sdRQpNLwRozcPGcSXr/GA71/7c70zOvNLW+oDHXP+ueaVnBTbWWeHr6vKNrPuhHB3kOo/O2HAk4ohXbPXjTF76c2Yya52iOu1incuT3o+kXl3/mAiCBU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584893749; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TybNu2rCzFG07xtaWl2F3gEjV/PJvOR+RO+xDc2RAv8=; b=SFLSSh+QQJIq/+qc5gFBT6YtQzr+Fl3JWu0PSR3P4RckQP4Qs5gpiIPHs5f0+ousPfwnKp7JHabB+Bu4N80sCfCqoUf/ylIzPH82BtfPff+7NfSKDBm66R8MPWNnZicZtGKEDVrfY3R6J3mP5vqWojxQdIJgQcALfANnoLDY2sk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158489374935177.3397882241261; Sun, 22 Mar 2020 09:15:49 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3F9-0004Vp-Rv; Sun, 22 Mar 2020 16:14:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1jG3F8-0004VU-Ev for xen-devel@lists.xenproject.org; Sun, 22 Mar 2020 16:14:30 +0000 Received: from mail-ed1-f68.google.com (unknown [209.85.208.68]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 32c8a036-6c58-11ea-bec1-bc764e2007e4; Sun, 22 Mar 2020 16:14:25 +0000 (UTC) Received: by mail-ed1-f68.google.com with SMTP id v6so13483074edw.8 for ; Sun, 22 Mar 2020 09:14:25 -0700 (PDT) Received: from ufe34d9ed68d054.ant.amazon.com (54-240-197-235.amazon.com. [54.240.197.235]) by smtp.gmail.com with ESMTPSA id v13sm106693edj.62.2020.03.22.09.14.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Mar 2020 09:14:24 -0700 (PDT) X-Inumbo-ID: 32c8a036-6c58-11ea-bec1-bc764e2007e4 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=cet1saYnXR3xpuceaO1waHWT2/fXAf5BKcn7eA9qmok=; b=WY6ih+wcyK8i5ZEXGEP0xL9BxQELgzOPy5Q/pHgC63Bh9cTNUBVXm1X2HcLAh7j7Nx MIdVFgI+C/6xjq7dRhvDFGaskJKDIEbmMapirL7Ygcr0MVOMSLPojFqeGx0plWdGTbJX B8eAujld7OipW0BIyr8Y7XwGKcHQ2r4o5YyigDCn3IjOlQIT+/gTD3ZkgfSNjJw79Ia8 Zo7g2vq8k95wxZnncru7cNDYKK52duhBzrNtuiY6DvxPQ1qAjmyeUrT1F/y/zhqNsttH jtbVYprxKCbX4ZvKa7LIZfpfgFRtE/7MlnPjKUze6KRwqU3eFoh/1c7WNL3AtnGYoPsC cohA== X-Gm-Message-State: ANhLgQ3xlqkKxoSZI5FA6P+V++SwjmJ5eHRruFip024pa2nnnRZd3Axz 0WbtBToakqlyZ6IjaRuX4Olk/exAUEXlbQ== X-Google-Smtp-Source: ADFU+vsk6Azdlr3rrvuls90J5/2jHFaGwH3lfZkR+aiUc+YzczbWZMS7DvH+AugordRalegvssB9aw== X-Received: by 2002:a17:906:7d87:: with SMTP id v7mr16943567ejo.301.1584893664660; Sun, 22 Mar 2020 09:14:24 -0700 (PDT) From: julien@xen.org To: xen-devel@lists.xenproject.org Date: Sun, 22 Mar 2020 16:14:02 +0000 Message-Id: <20200322161418.31606-2-julien@xen.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200322161418.31606-1-julien@xen.org> References: <20200322161418.31606-1-julien@xen.org> Subject: [Xen-devel] [PATCH 01/17] xen/x86: Introduce helpers to generate/convert the CR3 from/to a MFN/GFN X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: julien@xen.org, Wei Liu , Andrew Cooper , Julien Grall , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Julien Grall Introduce handy helpers to generate/convert the CR3 from/to a MFN/GFN. Note that we are using cr3_pa() rather than xen_cr3_to_pfn() because the latter does not ignore the top 12-bits. Take the opportunity to use the new helpers when possible. Signed-off-by: Julien Grall --- xen/arch/x86/domain.c | 4 ++-- xen/arch/x86/mm.c | 2 +- xen/include/asm-x86/mm.h | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index caf2ecad7e..15750ce210 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -1096,7 +1096,7 @@ int arch_set_info_guest( set_bit(_VPF_in_reset, &v->pause_flags); =20 if ( !compat ) - cr3_mfn =3D _mfn(xen_cr3_to_pfn(c.nat->ctrlreg[3])); + cr3_mfn =3D cr3_to_mfn(c.nat->ctrlreg[3]); else cr3_mfn =3D _mfn(compat_cr3_to_pfn(c.cmp->ctrlreg[3])); cr3_page =3D get_page_from_mfn(cr3_mfn, d); @@ -1142,7 +1142,7 @@ int arch_set_info_guest( v->arch.guest_table =3D pagetable_from_page(cr3_page); if ( c.nat->ctrlreg[1] ) { - cr3_mfn =3D _mfn(xen_cr3_to_pfn(c.nat->ctrlreg[1])); + cr3_mfn =3D cr3_to_mfn(c.nat->ctrlreg[1]); cr3_page =3D get_page_from_mfn(cr3_mfn, d); =20 if ( !cr3_page ) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 62507ca651..069a61deb8 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -509,7 +509,7 @@ void make_cr3(struct vcpu *v, mfn_t mfn) { struct domain *d =3D v->domain; =20 - v->arch.cr3 =3D mfn_x(mfn) << PAGE_SHIFT; + v->arch.cr3 =3D mfn_to_cr3(mfn); if ( is_pv_domain(d) && d->arch.pv.pcid ) v->arch.cr3 |=3D get_pcid_bits(v, false); } diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index a06b2fb81f..9764362a38 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -524,6 +524,26 @@ extern struct rangeset *mmio_ro_ranges; #define compat_pfn_to_cr3(pfn) (((unsigned)(pfn) << 12) | ((unsigned)(pfn)= >> 20)) #define compat_cr3_to_pfn(cr3) (((unsigned)(cr3) >> 12) | ((unsigned)(cr3)= << 20)) =20 +static inline unsigned long mfn_to_cr3(mfn_t mfn) +{ + return xen_pfn_to_cr3(mfn_x(mfn)); +} + +static inline mfn_t cr3_to_mfn(unsigned long cr3) +{ + return maddr_to_mfn(cr3_pa(cr3)); +} + +static inline unsigned long gfn_to_cr3(gfn_t gfn) +{ + return xen_pfn_to_cr3(gfn_x(gfn)); +} + +static inline gfn_t cr3_to_gfn(unsigned long cr3) +{ + return gaddr_to_gfn(cr3_pa(cr3)); +} + #ifdef MEMORY_GUARD void memguard_guard_range(void *p, unsigned long l); void memguard_unguard_range(void *p, unsigned long l); --=20 2.17.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel