From patchwork Thu Jan 12 02:28:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Rutherford X-Patchwork-Id: 9511837 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D640A60573 for ; Thu, 12 Jan 2017 02:29:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C7A3328649 for ; Thu, 12 Jan 2017 02:29:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BACE52868B; Thu, 12 Jan 2017 02:29:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EF9A28649 for ; Thu, 12 Jan 2017 02:29:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751910AbdALC3v (ORCPT ); Wed, 11 Jan 2017 21:29:51 -0500 Received: from mail-pf0-f180.google.com ([209.85.192.180]:35212 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751855AbdALC3t (ORCPT ); Wed, 11 Jan 2017 21:29:49 -0500 Received: by mail-pf0-f180.google.com with SMTP id f144so4114947pfa.2 for ; Wed, 11 Jan 2017 18:29:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=2ALcLdb+dKb3Tl727rBnc0dLdy3EMxbJ30r8m5Si85M=; b=IG1xvBl4pv7d4t9fIsZU6/eyM6AQOEpSVWhjgQrP2YLZxp80oigF/GPZu4SEwdUg9M GzAIHSUcoXnXhLYCWVt/+iiaovBB+1u3vwori4oRZUIJcr9Iq39eOi4s73laVbJwJLmU Zg6IkrdNysjNEF8zPLXxPcQ8XJxu/JvhE+JcupgzdaTtSvsDDnJCN14DtfkhsZn0qgUg nHBmvHUZ2YiBpS15JUPfZDxqZTkFtZKzIA+LO7R8X+W+N2pg4lYj4qsIWX2Zvo9zVPjJ vFjnPNbm+58m2jg7crmIbqCAxEv+U6JKCURGNB9r5sA2i10VZm3SPGQFIgTCn2L/vEcp qI2A== 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; bh=2ALcLdb+dKb3Tl727rBnc0dLdy3EMxbJ30r8m5Si85M=; b=rJGuHlxW6TU3w8VC7ucrm0DwLa1mITvCwUWb8Tmtxwr0nAMRnIMz/G56IZ1H1w1xF+ jpHvl92VWGeaT6STvERCFVA14JPJn/bV43QAIMb/JUd577weDtMQlNFBtJMCrKFS0tPH QRIcuOBSgEya/P3WYHhaD7Z3/5MXGyaxIaJ3HUWZVyTHBDrwMJwLSOZfAOEPcIUmq91W c9KggFZbVQWVLTpvJARk46MQnvK/KfSRnwldWv0DSj/rsomYWUaOmAY1kUyuEpBIDr0R +UKAKgmbz4BktluQsG4GnuhUYa1i9s1uPWrLaqhC18k8LSAmiA0qOKV4gIwlfTg75uhR ajPA== X-Gm-Message-State: AIkVDXKw9o9IXtXtd8Gp+h1HOFn18yvi/A5OoAGiutMsjCHAcBeSymCs1+RZYsNs0W34vdZd X-Received: by 10.84.214.150 with SMTP id j22mr17537716pli.81.1484188182712; Wed, 11 Jan 2017 18:29:42 -0800 (PST) Received: from entropic.kir.corp.google.com ([100.119.30.53]) by smtp.gmail.com with ESMTPSA id 66sm16671740pfx.29.2017.01.11.18.29.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Jan 2017 18:29:42 -0800 (PST) From: Steve Rutherford To: kvm@vger.kernel.org Cc: pbonzini@redhat.com, dvyukov@google.com, rkrcmar@redhat.com, ppandit@redhat.com, kernellwp@gmail.com Subject: [PATCH] KVM: x86: Introduce segmented_write_std Date: Wed, 11 Jan 2017 18:28:29 -0800 Message-Id: <20170112022829.15140-1-srutherford@google.com> X-Mailer: git-send-email 2.11.0.390.gc69c2f50cf-goog Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduces segemented_write_std. Switches from emulated reads/writes to standard read/writes in fxsave, fxrstor, sgdt, and sidt. Reported-by: Dmitry Vyukov Suggested-by: Paolo Bonzini Signed-off-by: Steve Rutherford --- arch/x86/kvm/emulate.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2b8349a2b14b..ad258aa0b302 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -819,6 +819,20 @@ static int segmented_read_std(struct x86_emulate_ctxt *ctxt, return ctxt->ops->read_std(ctxt, linear, data, size, &ctxt->exception); } +static int segmented_write_std(struct x86_emulate_ctxt *ctxt, + struct segmented_address addr, + void *data, + unsigned int size) +{ + int rc; + ulong linear; + + rc = linearize(ctxt, addr, size, true, &linear); + if (rc != X86EMUL_CONTINUE) + return rc; + return ctxt->ops->write_std(ctxt, linear, data, size, &ctxt->exception); +} + /* * Prefetch the remaining bytes of the instruction without crossing page * boundary if they are not in fetch_cache yet. @@ -3686,8 +3700,8 @@ static int emulate_store_desc_ptr(struct x86_emulate_ctxt *ctxt, } /* Disable writeback. */ ctxt->dst.type = OP_NONE; - return segmented_write(ctxt, ctxt->dst.addr.mem, - &desc_ptr, 2 + ctxt->op_bytes); + return segmented_write_std(ctxt, ctxt->dst.addr.mem, + &desc_ptr, 2 + ctxt->op_bytes); } static int em_sgdt(struct x86_emulate_ctxt *ctxt) @@ -3933,7 +3947,7 @@ static int em_fxsave(struct x86_emulate_ctxt *ctxt) else size = offsetof(struct fxregs_state, xmm_space[0]); - return segmented_write(ctxt, ctxt->memop.addr.mem, &fx_state, size); + return segmented_write_std(ctxt, ctxt->memop.addr.mem, &fx_state, size); } static int fxrstor_fixup(struct x86_emulate_ctxt *ctxt, @@ -3975,7 +3989,7 @@ static int em_fxrstor(struct x86_emulate_ctxt *ctxt) if (rc != X86EMUL_CONTINUE) return rc; - rc = segmented_read(ctxt, ctxt->memop.addr.mem, &fx_state, 512); + rc = segmented_read_std(ctxt, ctxt->memop.addr.mem, &fx_state, 512); if (rc != X86EMUL_CONTINUE) return rc;