From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xenproject.org
Cc: Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>,
Ian Jackson <ian.jackson@eu.citrix.com>,
Jan Beulich <jbeulich@suse.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 4/5] libxc/pvh: set default MTRR type to write-back
Date: Thu, 10 May 2018 18:15:04 +0100 [thread overview]
Message-ID: <20180510171505.37309-5-roger.pau@citrix.com> (raw)
In-Reply-To: <20180510171505.37309-1-roger.pau@citrix.com>
And enable MTRR. This allows to provide a sane initial MTRR state for
PVH DomUs. This will have to be expanded when pci-passthrough support
is added to PVH guests, so that MMIO regions of devices are set as
UC.
Note that initial MTRR setup is done by hvmloader for HVM guests,
that's not used by PVH guests.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
----
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Cc: Wei Liu <wei.liu2@citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
---
tools/libxc/xc_dom_x86.c | 44 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/tools/libxc/xc_dom_x86.c b/tools/libxc/xc_dom_x86.c
index e33a28847d..d28ff4d7e9 100644
--- a/tools/libxc/xc_dom_x86.c
+++ b/tools/libxc/xc_dom_x86.c
@@ -53,6 +53,9 @@
#define X86_CR0_PE 0x01
#define X86_CR0_ET 0x10
+#define MTRR_TYPE_WRBACK 6
+#define MTRR_DEF_TYPE_ENABLE (1u << 11)
+
#define SPECIALPAGE_PAGING 0
#define SPECIALPAGE_ACCESS 1
#define SPECIALPAGE_SHARING 2
@@ -931,6 +934,20 @@ static int vcpu_x86_64(struct xc_dom_image *dom)
return rc;
}
+const static void *hvm_get_save_record(const void *ctx, unsigned int type,
+ unsigned int instance)
+{
+ const struct hvm_save_descriptor *header;
+
+ for ( header = ctx;
+ header->typecode != HVM_SAVE_CODE(END);
+ ctx += sizeof(*header) + header->length, header = ctx )
+ if ( header->typecode == type && header->instance == instance )
+ return ctx + sizeof(*header);
+
+ return NULL;
+}
+
static int vcpu_hvm(struct xc_dom_image *dom)
{
struct {
@@ -938,9 +955,12 @@ static int vcpu_hvm(struct xc_dom_image *dom)
HVM_SAVE_TYPE(HEADER) header;
struct hvm_save_descriptor cpu_d;
HVM_SAVE_TYPE(CPU) cpu;
+ struct hvm_save_descriptor mtrr_d;
+ HVM_SAVE_TYPE(MTRR) mtrr;
struct hvm_save_descriptor end_d;
HVM_SAVE_TYPE(END) end;
} bsp_ctx;
+ const HVM_SAVE_TYPE(MTRR) *mtrr_record;
uint8_t *full_ctx = NULL;
int rc;
@@ -1014,6 +1034,30 @@ static int vcpu_hvm(struct xc_dom_image *dom)
if ( dom->start_info_seg.pfn )
bsp_ctx.cpu.rbx = dom->start_info_seg.pfn << PAGE_SHIFT;
+ /* Set the MTRR. */
+ bsp_ctx.mtrr_d.typecode = HVM_SAVE_CODE(MTRR);
+ bsp_ctx.mtrr_d.instance = 0;
+ bsp_ctx.mtrr_d.length = HVM_SAVE_LENGTH(MTRR);
+
+ mtrr_record = hvm_get_save_record(full_ctx, HVM_SAVE_CODE(MTRR), 0);
+ if ( !mtrr_record )
+ {
+ xc_dom_panic(dom->xch, XC_INTERNAL_ERROR,
+ "%s: unable to get MTRR save record", __func__);
+ goto out;
+ }
+
+ memcpy(&bsp_ctx.mtrr, mtrr_record, sizeof(bsp_ctx.mtrr));
+
+ /* TODO: maybe this should be a firmware option instead? */
+ if ( !dom->device_model )
+ /*
+ * Enable MTRR, set default type to WB.
+ * TODO: add MMIO areas as UC when passthrough is supported.
+ */
+ bsp_ctx.mtrr.msr_mtrr_def_type = MTRR_TYPE_WRBACK |
+ MTRR_DEF_TYPE_ENABLE;
+
/* Set the end descriptor. */
bsp_ctx.end_d.typecode = HVM_SAVE_CODE(END);
bsp_ctx.end_d.instance = 0;
--
2.17.0
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-05-10 17:15 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-10 17:15 [PATCH 0/5] PVH MTRR initial state Roger Pau Monne
2018-05-10 17:15 ` [PATCH 1/5] hvm/mtrr: add emacs local variables block with formatting info Roger Pau Monne
2018-05-10 17:15 ` [PATCH 2/5] hvm/mtrr: use the hardware number of variable ranges for Dom0 Roger Pau Monne
2018-05-14 14:14 ` Jan Beulich
2018-05-10 17:15 ` [PATCH 3/5] hvm/mtrr: copy hardware state " Roger Pau Monne
2018-05-14 14:26 ` Jan Beulich
2018-05-14 16:33 ` Roger Pau Monné
2018-05-15 7:52 ` Jan Beulich
2018-05-15 8:35 ` Roger Pau Monné
2018-05-15 8:48 ` Jan Beulich
2018-05-15 9:16 ` Roger Pau Monné
2018-05-15 9:50 ` Jan Beulich
2018-05-10 17:15 ` Roger Pau Monne [this message]
2018-05-14 16:00 ` [PATCH 4/5] libxc/pvh: set default MTRR type to write-back Wei Liu
2018-05-14 16:02 ` Roger Pau Monné
2018-05-14 16:42 ` Wei Liu
2018-05-14 16:50 ` Wei Liu
2018-05-14 16:53 ` Roger Pau Monné
2018-05-15 11:43 ` Wei Liu
2018-05-15 12:22 ` Jan Beulich
2018-05-10 17:15 ` [PATCH 5/5] docs/pvh: document initial MTRR state Roger Pau Monne
2018-05-14 16:03 ` Wei Liu
2018-05-14 16:13 ` Jan Beulich
2018-05-14 16:18 ` Wei Liu
2018-05-15 7:51 ` Jan Beulich
2018-05-15 8:30 ` Wei Liu
2018-05-15 8:30 ` Roger Pau Monné
2018-05-15 8:38 ` Jan Beulich
2018-05-14 16:16 ` Roger Pau Monné
2018-05-14 16:27 ` Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180510171505.37309-5-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=ian.jackson@eu.citrix.com \
--cc=jbeulich@suse.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).