Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2980891imm; Sun, 13 May 2018 01:26:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo72F/ad1gTu5jpZxMKc00oNyjNUGSMKXZ5HTaT5kfONCd3qIdHoqHtVCSdZfV56WEjBoU1 X-Received: by 2002:a62:1f03:: with SMTP id f3-v6mr5834275pff.213.1526199988198; Sun, 13 May 2018 01:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526199988; cv=none; d=google.com; s=arc-20160816; b=Os6lDb4cyY99BZmj8UTFeRke7WQHL2Zkh5PPJeFjgsxs+wWKRSafKHbaT5AsdYHnR2 PCUwJy0GVZezCzgVqz0/K5FZbP4kWvNouxQrEaK6xLLzqZBpzqlbrLsYVljoF1LdGWK8 Ow2phHPefAQNIUyiyrHLbgiCDT0ONhMAUntKpcufCePpmAOeDuIsU75GBYfLE5Qy57BG nBtY3UHYsIZv6nDvGoznetZZZYccs/guAor3Qy9lb9amHORMf3dTcCPZF3ZutlXAl96H jBjCsxCYehcKpqvvkWdD89YxbnE4/fCWqVCf/8rRsaW1bH/fXe+Hrfw8OPAdBu0C6h6d CRqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=ZX/DYx8Hf5DFut4VdRYOY6q06vbCRRCABD+qh8Q89go=; b=sG1yIv4hlNNSjJpuc8kGfJGRZ6rIMm2X1nfPB/ASyYZkC2UTsmYBcHllCS4qXi//kD kfdxjIef9D82A4Q8v9MUCbBkzsTm1Qh5JD5XSjrg2171o6i4DIYjHpI+FCXnZoDjB7GJ n/K5Sfzej+lFsqaIuarNoDqXfp6sLWwo4NzDUx/HI6HSzsZfACoKTRZGKBrr72OBccw/ KEOG+EMpaJf/FNrKTzVI66zv+Wp8EOfVT5oARqgw7Uw98TcncRVU5zy9XL5k2h8jGnT6 a/uEl4dSam/4hSvq9UkJkikY+xmakXKx5V07GrpCVn9ci91DcfwD+tobKgRJFzvu/Bx3 xY0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NKDFvIf9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j19-v6si6637455pll.518.2018.05.13.01.26.11; Sun, 13 May 2018 01:26:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NKDFvIf9; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751260AbeEMI0B (ORCPT + 99 others); Sun, 13 May 2018 04:26:01 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:43875 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbeEMIZ7 (ORCPT ); Sun, 13 May 2018 04:25:59 -0400 Received: by mail-oi0-f68.google.com with SMTP id p62-v6so8155901oie.10; Sun, 13 May 2018 01:25:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ZX/DYx8Hf5DFut4VdRYOY6q06vbCRRCABD+qh8Q89go=; b=NKDFvIf98BfsgcIjuBP0Wq7kbVBpLFg3w5geA/pP6ZDGokTpwz8JX9P1etcUbd4gjC EyZpQCJlJkM6CDEIIlPkclNIZoahKt7xqyt3iQct3IIvGYhzzwkg5ne8F1UpPI5TW3oW j17OALHgsWJkpvcmEoBudohAnlXs7NlYXxT3Uzfxr5wwERxSXtexsrREQsggJMe1t7sW 3hoC+ut+VLpOKH/QEqooqe5hQgRCrXiNEWTyqyCiFcdL/DVcyiWyBId48H8wPom9lFIS zl7OivQmfI+HvJ2PmbOvWHeicUWMzqvXRV92fagh+ZtM0XA6qWUdKAh6lcx5hfNRJfK1 99vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ZX/DYx8Hf5DFut4VdRYOY6q06vbCRRCABD+qh8Q89go=; b=fqCwmg/VJMwDW3WpcydPI+Wrh6D2IcOgMu431UfKJD52zz9nM2W7O0YbK97EvHnV8J UY7yzf2FvGvjv5bOqNhBIdSwIskhQ35xjJwa6YYBOcnM6UV0LoU21TVkcHEvsWrHf78t OVElSTSnca221InknAzRKWaUo/84pjRVEHW4DA5TDac1cXk3eEj4/07xz76sXSO9C8C/ nEyAxSBQsMh2StjKgX8GYYGYiRVNd4PYPSUjtZ3f10ZPvmcc116pnac+X7XsgL0gBanG 0dQDqWDrUia9q/T07/9zwtePTS2ql6OhbNVJS6Q64yNB2W2AdH0PnrZjb/4hE7a9t81g Ol8Q== X-Gm-Message-State: ALKqPwdsgpsmmzDEqPDC3QxXBWHNWZ2hDhA4H1Q1xhOcFmvCEfYdjHY0 FWV5c6LmwxXNNwhOyUe+IoVXi+yZRN10282LS24= X-Received: by 2002:aca:d9c5:: with SMTP id q188-v6mr3809138oig.233.1526199959431; Sun, 13 May 2018 01:25:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.74.70.211 with HTTP; Sun, 13 May 2018 01:25:58 -0700 (PDT) In-Reply-To: References: From: Wanpeng Li Date: Sun, 13 May 2018 16:25:58 +0800 Message-ID: Subject: Re: [PATCH 1/2] KVM: X86: Fix CR3 reserve bits To: Liran Alon Cc: Radim Krcmar , Paolo Bonzini , LKML , kvm , Junaid Shahid Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-05-13 15:53 GMT+08:00 Liran Alon : > > ----- kernellwp@gmail.com wrote: > >> From: Wanpeng Li >> >> MSB of CR3 is a reserved bit if the PCIDE bit is not set in CR4. >> It should be checked when PCIDE bit is not set, however commit >> 'd1cd3ce900441 ("KVM: MMU: check guest CR3 reserved bits based on >> its physical address width")' removes the bit 63 checking >> unconditionally. This patch fixes it by checking bit 63 of CR3 >> when PCIDE bit is not set in CR4. >> >> Fixes: d1cd3ce900441 (KVM: MMU: check guest CR3 reserved bits based on >> its physical address width) >> Cc: Paolo Bonzini >> Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 >> Cc: Junaid Shahid >> Signed-off-by: Wanpeng Li >> --- >> arch/x86/kvm/emulate.c | 4 +++- >> arch/x86/kvm/x86.c | 2 +- >> 2 files changed, 4 insertions(+), 2 deletions(-) >> >> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c >> index b3705ae..b21f427 100644 >> --- a/arch/x86/kvm/emulate.c >> +++ b/arch/x86/kvm/emulate.c >> @@ -4189,7 +4189,9 @@ static int check_cr_write(struct >> x86_emulate_ctxt *ctxt) >> maxphyaddr =3D eax & 0xff; >> else >> maxphyaddr =3D 36; >> - rsvd =3D rsvd_bits(maxphyaddr, 62); >> + if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) >> + new_val &=3D ~CR3_PCID_INVD; >> + rsvd =3D rsvd_bits(maxphyaddr, 63); > > I would prefer instead to do this: > if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) > rsvd &=3D ~CR3_PCID_INVD; > It makes more sense as opposed to temporary removing the CR3_PCID_INVD bi= t from new_val. It tries the same way https://git.kernel.org/pub/scm/virt/kvm/kvm.git/commit/?id=3Dc19986fea873f3= c745122bf79013a872a190f212 pointed out. Regards, Wanpeng Li > >> } >> >> if (new_val & rsvd) >> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c >> index 87e4805..9a90668 100644 >> --- a/arch/x86/kvm/x86.c >> +++ b/arch/x86/kvm/x86.c >> @@ -863,7 +863,7 @@ int kvm_set_cr3(struct kvm_vcpu *vcpu, unsigned >> long cr3) >> } >> >> if (is_long_mode(vcpu) && >> - (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 62))) >> + (cr3 & rsvd_bits(cpuid_maxphyaddr(vcpu), 63))) >> return 1; >> else if (is_pae(vcpu) && is_paging(vcpu) && >> !load_pdptrs(vcpu, vcpu->arch.walk_mmu, cr3)) >> -- >> 2.7.4