Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp3360506pxu; Mon, 19 Oct 2020 10:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwFhoGF6682YFCQwcQKJk2b3DIuJRpelTf3KPEZPc9IF8Rmz2ZEaRXm8S04IRyCUzaPDplV X-Received: by 2002:a17:907:42d6:: with SMTP id ng6mr826726ejb.464.1603127207484; Mon, 19 Oct 2020 10:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603127207; cv=none; d=google.com; s=arc-20160816; b=SR8QhBTFr0qhPntB7zV9Cfp5t7baFNqa2HgK76aLKZDOJEvwElca1B3UUeMv/QKhAa GuNI9wMHSn+YaOiRewO4jzkHIOalkjLO5n7SBNnIDy8/PB8wqBvYVvUlOJbuCDbpyWs1 kTnm1K2EuMB/+4/ER744+N1aXC4BReUic9PJEWi+XL6O/Zd+uoW2MO80lwktD98K2K6k SOvAZY85qKUHyxU2HURvnInNOrEXsjrJCF/6kSl7hM5118jEU97FPqQYjWgWIbBtPLAj of2vLa16t3d6hH1/b34EtT+admZJDsz/wRjZebahskSfEYeq6zNnD35DaGj9LtETtSA6 OhAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=8T33BC/57dNGym7wEnyJvGdAxGs0P1jblpQACkcYHg0=; b=rZMfxOv0XyW98r/0MXcAFWCAMZaMIM6BvusOGo0fTwc1hEvI35F2p+ne+EyTvL760J qG7GLpKhuG5jbGTX30hu1jiqyeQlyIwWxN1wy3N7WC2xWbhPxLfMPVtiEXBUuKmiHQ/I Zyb38GfggAjVq+26PwV26mONUwLnlqHUU4SlBvECmrVT418VcGO9VpI62ETC+O6RxHx1 wKzXz3xp2NgcvZ/E15HkZXnzyG54ne1YlkwMYqDv1RfO/Nj2ntuJHWbubRlba81bkVOe S3593B01ozFwBa7/Inp1xQXgMH63swQWAQX9Le7rd39kZAWXuuw4URZwuRnawglJgaQ0 oGQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vx77HTj2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ml19si374102ejb.348.2020.10.19.10.06.25; Mon, 19 Oct 2020 10:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Vx77HTj2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730791AbgJSRF3 (ORCPT + 99 others); Mon, 19 Oct 2020 13:05:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:47679 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730186AbgJSRF3 (ORCPT ); Mon, 19 Oct 2020 13:05:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603127128; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=8T33BC/57dNGym7wEnyJvGdAxGs0P1jblpQACkcYHg0=; b=Vx77HTj209UFaNIorTCS3L80vHRioPTsxMZ0hboyd5Rdfei4OwGJO9g02aFRqZIOISIzk9 7HVZmRvXiuoh0Omg0WUrLfHra12FQeBOkGBeopW8LO2riRUkcpnuF92kiKRhnE6/G8LGug ZjBKOUn0nmaS/NcHbl7XtLoHLLFyiaQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-162-tOZTp_APOFifK1536HR7MQ-1; Mon, 19 Oct 2020 13:05:26 -0400 X-MC-Unique: tOZTp_APOFifK1536HR7MQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52903D6883; Mon, 19 Oct 2020 17:05:25 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E78F5C22A; Mon, 19 Oct 2020 17:05:19 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Alexander Graf , Aaron Lewis , Peter Xu , Sean Christopherson Subject: [PATCH] KVM: VMX: Forbid userspace MSR filters for x2APIC Date: Mon, 19 Oct 2020 13:05:19 -0400 Message-Id: <20201019170519.1855564-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allowing userspace to intercept reads to x2APIC MSRs when APICV is fully enabled for the guest simply can't work. But more in general, if the LAPIC is in-kernel, allowing accessed by userspace would be very confusing. If userspace wants to intercept x2APIC MSRs, then it should first disable in-kernel APIC. We could in principle allow userspace to intercept reads and writes to TPR, and writes to EOI and SELF_IPI, but while that could be made it work, it would still be silly. Cc: Alexander Graf Cc: Aaron Lewis Cc: Peter Xu Cc: Sean Christopherson Signed-off-by: Paolo Bonzini --- arch/x86/kvm/x86.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index c4015a43cc8a..0faf733538f4 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -5246,6 +5246,13 @@ static int kvm_add_msr_filter(struct kvm *kvm, struct kvm_msr_filter_range *user return r; } +static bool range_overlaps_x2apic(struct kvm_msr_filter_range *range) +{ + u32 start = range->base; + u32 end = start + range->nmsrs; + return start <= 0x8ff && end > 0x800; +} + static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp) { struct kvm_msr_filter __user *user_msr_filter = argp; @@ -5257,6 +5264,16 @@ static int kvm_vm_ioctl_set_msr_filter(struct kvm *kvm, void __user *argp) if (copy_from_user(&filter, user_msr_filter, sizeof(filter))) return -EFAULT; + /* + * In principle it would be possible to trap x2apic ranges + * if !lapic_in_kernel. This however would be complicated + * because KVM_X86_SET_MSR_FILTER can be called before + * KVM_CREATE_IRQCHIP or KVM_ENABLE_CAP. + */ + for (i = 0; i < ARRAY_SIZE(filter.ranges); i++) + if (range_overlaps_x2apic(&filter.ranges[i])) + return -EINVAL; + kvm_clear_msr_filter(kvm); default_allow = !(filter.flags & KVM_MSR_FILTER_DEFAULT_DENY); -- 2.26.2