From patchwork Thu Jun 1 08:56:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Roman Pen X-Patchwork-Id: 9758891 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 84DDE6038E for ; Thu, 1 Jun 2017 08:57:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7462528389 for ; Thu, 1 Jun 2017 08:57:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68D3A284FF; Thu, 1 Jun 2017 08:57:13 +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_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 93D9628389 for ; Thu, 1 Jun 2017 08:57:12 +0000 (UTC) Received: from localhost ([::1]:36110 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGLup-0001VL-E2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Jun 2017 04:57:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGLtw-0001Sl-GQ for qemu-devel@nongnu.org; Thu, 01 Jun 2017 04:56:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGLtt-0004xW-Ek for qemu-devel@nongnu.org; Thu, 01 Jun 2017 04:56:16 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:38331) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGLtt-0004wo-8p for qemu-devel@nongnu.org; Thu, 01 Jun 2017 04:56:13 -0400 Received: by mail-wm0-x22b.google.com with SMTP id n195so22650233wmg.1 for ; Thu, 01 Jun 2017 01:56:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profitbricks-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GW1ndBIBxEtaXB/xXtFJg5MAu924Npb3jX3A0tRv7bY=; b=IdGRKbO9g7rFV/FOY8fU7WPZrUoo232SfQ7vhuM6lClSEHGV3uLkTCutBz+JtFhY31 RSRBOW6NOj3d7VKvAS6nFB4SKeFFy+dB8RVoS/wr5LdIW0k8E3dc5r75K2YTosadPdwk +TAstpDN98EAgQkZFUEMWLnYU1EdEJWtMUpARzEFgjZ13WDvl3KfTI1svPUXX7zviT1Q ntthYT5t4C27vOozIbnbuDV/NlE1r6YOrpLiIM7YMzbQABCnRWUmC1iQU67r/DPxDfSv GxKcsygaz4anyCEZ+fHn5nIKWDpNy3ql1QHjj+wv9HGKOhQNHQA1mQQVO9h+69J/CcsP rUnw== 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:mime-version :content-transfer-encoding; bh=GW1ndBIBxEtaXB/xXtFJg5MAu924Npb3jX3A0tRv7bY=; b=faDvFVcZsjM0RiiQ2GvBbkE3NGEQqiDY3FqaDDa26IIHgtX6Wbc+1sR2Cl068mP5LN kKn4snxmSD/OBjBD0VhTDSkzSoaenfoS7e6nJNIHtkdoGo+aPvCJYUsAxKE7neqmEWYy VhnT5W1kn3sTEEbrbNH+m31aNp8aQhpZW+yEkyuC/oVCeA5ZWyYJv4kv5dfy7GXIUk7R 1s04amiUrqQ1MWxwQCFkCQCsHYctsa7piWj2Fq/T0M0qPIlGBskJdLylMNbEK2eKQSAk Arc+txHs9umNQj2nHbRP0H18a2+3WwKZvcz3Vrr3Nhc0e+OhdEO5pEVe1XAXLsYznR5A +j8Q== X-Gm-Message-State: AODbwcAkKUiFefFcJtbQgryNOeFq5fA/+tc8P+XEgRyMDnUJRsv7LjPy D2ZhA9KqdqpRRY4h X-Received: by 10.223.174.200 with SMTP id y66mr449698wrc.79.1496307371641; Thu, 01 Jun 2017 01:56:11 -0700 (PDT) Received: from pb.pb.local ([62.217.45.26]) by smtp.gmail.com with ESMTPSA id h73sm38670467wma.10.2017.06.01.01.56.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 01:56:10 -0700 (PDT) From: Roman Pen To: Date: Thu, 1 Jun 2017 10:56:04 +0200 Message-Id: <20170601085604.12980-1-roman.penyaev@profitbricks.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22b Subject: [Qemu-devel] [PATCH 1/1] i386/kvm: do not zero out segment flags if segment is unusable or not present X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Rddadim=20Kr=C4=8Dm=C3=A1=C5=99?= , qemu-devel@nongnu.org, Mikhail Sennikovskii , Roman Pen , Paolo Bonzini , Michael Chapman Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is a fix for the problem [1], where VMCB.CPL was set to 0 and interrupt was taken on userspace stack. The root cause lies in the specific AMD CPU behaviour which manifests itself as unusable segment attributes on SYSRET[2]. Here in this patch flags are not touched even segment is unusable or is not present, therefore CPL (which is stored in DPL field) should not be lost and will be successfully restored on kvm/svm kernel side. Also current patch should not break desired behavior described in this commit: 4cae9c97967a ("target-i386: kvm: clear unusable segments' flags in migration") since present bit will be dropped if segment is unusable or is not present. This is the second part of the whole fix of the corresponding problem [1], first part is related to kvm/svm kernel side and does exactly the same: segment attributes are not zeroed out. [1] Message id: CAJrWOzD6Xq==b-zYCDdFLgSRMPM-NkNuTSDFEtX=7MreT45i7Q@mail.gmail.com [2] Message id: 5d120f358612d73fc909f5bfa47e7bd082db0af0.1429841474.git.luto@kernel.org Signed-off-by: Roman Pen Signed-off-by: Mikhail Sennikovskii Cc: Paolo Bonzini Cc: Rddadim Krčmář Cc: Michael Chapman Cc: qemu-devel@nongnu.org --- target/i386/kvm.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 011d4a55b136..faee904d9d59 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1300,18 +1300,14 @@ static void get_seg(SegmentCache *lhs, const struct kvm_segment *rhs) lhs->selector = rhs->selector; lhs->base = rhs->base; lhs->limit = rhs->limit; - if (rhs->unusable) { - lhs->flags = 0; - } else { - lhs->flags = (rhs->type << DESC_TYPE_SHIFT) | - (rhs->present * DESC_P_MASK) | - (rhs->dpl << DESC_DPL_SHIFT) | - (rhs->db << DESC_B_SHIFT) | - (rhs->s * DESC_S_MASK) | - (rhs->l << DESC_L_SHIFT) | - (rhs->g * DESC_G_MASK) | - (rhs->avl * DESC_AVL_MASK); - } + lhs->flags = (rhs->type << DESC_TYPE_SHIFT) | + ((rhs->present && !rhs->unusable) * DESC_P_MASK) | + (rhs->dpl << DESC_DPL_SHIFT) | + (rhs->db << DESC_B_SHIFT) | + (rhs->s * DESC_S_MASK) | + (rhs->l << DESC_L_SHIFT) | + (rhs->g * DESC_G_MASK) | + (rhs->avl * DESC_AVL_MASK); } static void kvm_getput_reg(__u64 *kvm_reg, target_ulong *qemu_reg, int set)