Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1189936imm; Fri, 22 Jun 2018 11:54:11 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIChGpBpupFZEiCZHANXU7rVH8UN3uRcOQDJYS/NkpXDS2JbHe3e01M6RsOcs1ZpwAVkGld X-Received: by 2002:a62:4653:: with SMTP id t80-v6mr2949797pfa.58.1529693650976; Fri, 22 Jun 2018 11:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529693650; cv=none; d=google.com; s=arc-20160816; b=g5vbIykQKTwg9lzOgkZYwjPawMF67whhbtIhDNPZaldup7hrw9MfRkrUiZXRoS2sJi H0zGiINg7wSPKQhs8O938fn38dk2gVgeSizID/IU9+YMCONEpJ00obRzFpGmL0YeQzwt WOd6xFmljsUUeQj3ZV+9EEHq7Xo/nsSbl4G55fVDfwJy/4SG9RcUw2ODRmSb10mztAX4 rvxg5oV/u/fQxal0rUiGEBG8wkmh8gsQ4xOhjVSsEB6C3tiOvqq7Bv++6qhWTA85PNWp J2mwTleH46JtId6Nb28WuZoPhxf6gSmDN7sqQFApxpawQRRyeirIzTQu3plqQm/jvFAr pX8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :arc-authentication-results; bh=Pyr4jy/Aitrbf1uRxAX4BLpch3ZSEHALesrZy6WFs8k=; b=0g4QelNYdNCKK7LoU1buW7pHZYZ0F5Tg5jRkSRRLBAy2qHxq9K2B/Ux6BtDcCt3aUr oI3kYmyw3BtP5vi8D3qkKxCJXdCbcQodxKCbfiurF0aVa1agzQ8pjufjHBvxFLIup0Wu 5lpyrCgxcBUbkQZ0r5UgI11akgh9TlIVuJa5EPuBxoIoWSjg54Ue0QS6V9jUwNQ4OIsM 1whsC9pe0qEowTZvDOnj8esffATq9B7oymOMVIx1KoXTXEH50au8nQX2QBfzq+cDvST0 24KkcLd038mbNQGqyfKHyU5VbyMdSMSnkbahIHE/dFp5aAGtO9KA6BB1y2bU+fRM/hB0 H6eA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3-v6si7824762plb.27.2018.06.22.11.53.55; Fri, 22 Jun 2018 11:54:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934266AbeFVSwo (ORCPT + 99 others); Fri, 22 Jun 2018 14:52:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49912 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934079AbeFVSwl (ORCPT ); Fri, 22 Jun 2018 14:52:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E1AF8D753; Fri, 22 Jun 2018 18:52:41 +0000 (UTC) Received: from flask (unknown [10.43.2.80]) by smtp.corp.redhat.com (Postfix) with SMTP id 2B3E62156889; Fri, 22 Jun 2018 18:52:39 +0000 (UTC) Received: by flask (sSMTP sendmail emulation); Fri, 22 Jun 2018 20:52:38 +0200 Date: Fri, 22 Jun 2018 20:52:38 +0200 From: Radim =?utf-8?B?S3LEjW3DocWZ?= To: Borislav Petkov Cc: KVM , Joerg Roedel , Tom Lendacky , Tony Luck , Yazen Ghannam , LKML Subject: Re: [PATCH 2/3] x86/kvm: Implement MSR_HWCR support Message-ID: <20180622185237.GC5549@flask> References: <20180622095101.32587-1-bp@alien8.de> <20180622095101.32587-3-bp@alien8.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180622095101.32587-3-bp@alien8.de> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 18:52:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 22 Jun 2018 18:52:41 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'rkrcmar@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-06-22 11:51+0200, Borislav Petkov: > From: Borislav Petkov > > The hardware configuration register has some useful bits which can be > used by guests. Implement McStatusWrEn which can be used by guests when > injecting MCEs with the in-kernel mce-inject module. > > For that, we need to set bit 18 - McStatusWrEn - first, before writing > the MCi_STATUS registers (otherwise we #GP). > > Add the required machinery to do so. > > Signed-off-by: Borislav Petkov > --- > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -2146,6 +2146,30 @@ static void kvmclock_sync_fn(struct work_struct *work) > KVMCLOCK_SYNC_PERIOD); > } > > +/* > + * On AMD, HWCR[McStatusWrEn] controls whether setting MCi_STATUS results in #GP. > + */ > +static bool __set_mci_status(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > +{ > + if (guest_cpuid_is_amd(vcpu)) { > + struct msr_data tmp; > + > + tmp.index = MSR_K7_HWCR; > + > + if (kvm_x86_ops->get_msr(vcpu, &tmp)) > + return false; > + > + /* McStatusWrEn enabled? */ > + if (tmp.data & BIT_ULL(18)) > + return true; > + } > + > + if (!msr_info->host_initiated && msr_info->data != 0) > + return false; msr_info->host_initiated is always going to return true, so it would be better to put it outside of __set_mci_status. Maybe we could just write the whole logic inline, otherwise I'd call it something like mci_status_is_writeable. > static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > { > u64 mcg_cap = vcpu->arch.mcg_cap; > @@ -2176,9 +2200,13 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > if ((offset & 0x3) == 0 && > data != 0 && (data | (1 << 10)) != ~(u64)0) > return -1; > - if (!msr_info->host_initiated && > - (offset & 0x3) == 1 && data != 0) > - return -1; > + > + /* MCi_STATUS */ > + if ((offset & 0x3) == 1) { > + if (!__set_mci_status(vcpu, msr_info)) > + return -1; > + } if (!msr_info->host_initiated && (offset & 0x3) == 1 && data != 0) { struct msr_data tmp = {.index = MSR_K7_HWCR}; if (!guest_cpuid_is_amd(vcpu) || !kvm_x86_ops->get_msr(vcpu, &tmp) || !(tmp.data & BIT_ULL(18))) return -1; } > + > vcpu->arch.mce_banks[offset] = data; > break; > } > -- > 2.17.0.582.gccdcbd54c >