From patchwork Mon Dec 2 20:13:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11269887 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6276109A for ; Mon, 2 Dec 2019 20:13:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4A0021835 for ; Mon, 2 Dec 2019 20:13:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TqtI2P+F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbfLBUN0 (ORCPT ); Mon, 2 Dec 2019 15:13:26 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20166 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728099AbfLBUNV (ORCPT ); Mon, 2 Dec 2019 15:13:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575317600; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1fy9n7dcmvJgMCcJNV0TpfIBPUc+H1bj0IMdTlJT67Y=; b=TqtI2P+Fa1oxnOT/+wionTMWgXLs0df7qaJX9auauAp+SZ2jtrOMRpUixWEiVv5Jjm1PW4 oNKGgd0m2nyYMTu65/hXtw0zpIIZrLMlZNI4oH9q4zEStCy7Epmy9gWdKJM2AAKDWOUwbL +imrhyakofO/2vUyxzCTCOtzvOPYui4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-274-LNhikmsIO3yBFeFmnZLXVw-1; Mon, 02 Dec 2019 15:13:18 -0500 Received: by mail-qt1-f200.google.com with SMTP id k27so689414qtu.12 for ; Mon, 02 Dec 2019 12:13:18 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=G46phdLsdELb62aYURKq9FYQ6hJlvcecU9Mkr0WukfA=; b=IUzhoBEwQm9Hh27iedzaGWxAt/e2DpfMmelFj3xpzz078YWZyXLjPP03NSsVocMZ+V j4ofBMEZ88ZH5FeG5mSXKsJThafooLnfqtWVUSyI2Q+Pk62pl5iv3f73xjuSxgRBlFhH qVDnxRv0hx45TMJUBKMkdJ9qCkZ2/G5KFMPfODp+6IQmuPuNvfgo9TDt0qJTvPPZciNB /VTpmT//8KZQYTSrTnNMGnSb2aqoYstX5yB+RYXcK37LNv+CMZzZtT0cJ6tuWfP5nXMi XLJci5QlygeimEov5wt/sU/KYtXoPkJps+QwgPt4Jiq5jw9CHJaef7gpbMxP/ktliQZY /3lg== X-Gm-Message-State: APjAAAW8EnIeuW60sWoCHka4wZx+OQhVwfk/rJHV8orcimxPr9+hbk0l emUIymv4Aj7ZYftiTaj9MfM7myEj3mln536thiod3Qm7t+u8hK89NsoIZ901ipVR6sZ2UJpzTTt NYD4m7FKe529x X-Received: by 2002:a37:8fc7:: with SMTP id r190mr802090qkd.57.1575317598022; Mon, 02 Dec 2019 12:13:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyyXV9FRZwo488kcpWWx8NKtpTc+Mn5z7ZJGiXXUVERX6ZlH3itwmcb06sFXIkKThyWsyuWdw== X-Received: by 2002:a37:8fc7:: with SMTP id r190mr802057qkd.57.1575317597756; Mon, 02 Dec 2019 12:13:17 -0800 (PST) Received: from xz-x1.yyz.redhat.com ([104.156.64.74]) by smtp.gmail.com with ESMTPSA id b6sm342410qtp.5.2019.12.02.12.13.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 12:13:16 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Nitesh Narayan Lal , Paolo Bonzini , Sean Christopherson , peterx@redhat.com, Vitaly Kuznetsov Subject: [PATCH v3 1/5] KVM: X86: Fix kvm_bitmap_or_dest_vcpus() to use irq shorthand Date: Mon, 2 Dec 2019 15:13:10 -0500 Message-Id: <20191202201314.543-2-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191202201314.543-1-peterx@redhat.com> References: <20191202201314.543-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: LNhikmsIO3yBFeFmnZLXVw-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The 3rd parameter of kvm_apic_match_dest() is the irq shorthand, rather than the irq delivery mode. Fixes: 7ee30bc132c683d06a6d9e360e39e483e3990708 Signed-off-by: Peter Xu Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index cf9177b4a07f..1eabe58bb6d5 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1151,7 +1151,7 @@ void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq, if (!kvm_apic_present(vcpu)) continue; if (!kvm_apic_match_dest(vcpu, NULL, - irq->delivery_mode, + irq->shorthand, irq->dest_id, irq->dest_mode)) continue; From patchwork Mon Dec 2 20:13:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11269889 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 61DE6112B for ; Mon, 2 Dec 2019 20:13:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3FD9C21774 for ; Mon, 2 Dec 2019 20:13:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RwaROu+D" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728150AbfLBUNw (ORCPT ); Mon, 2 Dec 2019 15:13:52 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:23075 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728130AbfLBUN0 (ORCPT ); Mon, 2 Dec 2019 15:13:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575317604; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G1gckXauaeL8jMmVmxWpREojol2bGewDKqT8ZgknTb0=; b=RwaROu+DkszlEluMLpSlNTqN/rkLverpnqm81gQSN6DmycHXZEHIgwAZ6av2n7ugoDZdnS lZFvggyzTK/HaznwhKna2zP4AWLgbC/HKrFv0fucNocj50I1g6/84xwAVqv12crFiDoe5q /ivAWBi+sB6TfczPukpfdMAA4e1w1oY= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-195--z28qmF8PTGqiqhv8CAnow-1; Mon, 02 Dec 2019 15:13:23 -0500 Received: by mail-qk1-f197.google.com with SMTP id q13so491782qke.11 for ; Mon, 02 Dec 2019 12:13:23 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=Utq3zcNfSThC/9BbVCBXGvAcYurXVWxw0oLvhkumJ1Q=; b=q/I17J3pBT2dJAQPtsUdQxYDzixRXx9+gk1WJaUjOPfAmpAw9R0S1wlo/liUt0N/kG +kX7cWlLEmad9tJ9yEumedP0cjI8UMkC/4Hh0KgO5qcC4bAz33lIjw158u+nGySOOHMV WfOoic4Ho7JcoIcu9iHTczFZztobtNDbUohDCnMfifl3KgGGWEKN30FqdtCCg0mOhPOP xKdBZPQ+/wZ4CFFQVUhn68gV7jnJKmaUnjaEZiVN6a8ZUoczDti3RgOKZWiIm7ZZ+c0T 5i+HE0pKJBQqeq+qHXNVmDQE4ZGYD8I6UBGLP6kzZnT6awD3Cga5qslE5godIWVqFPMz SKHA== X-Gm-Message-State: APjAAAXs8RTT/FqGPQtkR001UWihVWhAMcT9x7UjwbrC8uf65xwVqakZ d/JxynKNsHEWh3s+sX1W3wd+nbGsN6xSePewJAvTFzWcSKbNyni+nn4P3DhcltVA6tUTzgRIR+v C1Q9Y4+0RRDxb X-Received: by 2002:ac8:1098:: with SMTP id a24mr1392400qtj.62.1575317603056; Mon, 02 Dec 2019 12:13:23 -0800 (PST) X-Google-Smtp-Source: APXvYqw9F5bzoR4DI4qH8h+a0GB9RfB7ylXfBVEuQobgvwjzKT5mNcRRe56CqIEbnF0GkoUXl/xK8A== X-Received: by 2002:ac8:1098:: with SMTP id a24mr1392376qtj.62.1575317602808; Mon, 02 Dec 2019 12:13:22 -0800 (PST) Received: from xz-x1.yyz.redhat.com ([104.156.64.74]) by smtp.gmail.com with ESMTPSA id b6sm342410qtp.5.2019.12.02.12.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 12:13:18 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Nitesh Narayan Lal , Paolo Bonzini , Sean Christopherson , peterx@redhat.com, Vitaly Kuznetsov Subject: [PATCH v3 2/5] KVM: X86: Move irrelevant declarations out of ioapic.h Date: Mon, 2 Dec 2019 15:13:11 -0500 Message-Id: <20191202201314.543-3-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191202201314.543-1-peterx@redhat.com> References: <20191202201314.543-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: -z28qmF8PTGqiqhv8CAnow-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org kvm_apic_match_dest() is declared in both ioapic.h and lapic.h. Removing the declaration in ioapic.h. kvm_apic_compare_prio() is declared in ioapic.h but defined in lapic.c. Moving the declaration to lapic.h. kvm_irq_delivery_to_apic() is declared in ioapic.h but defined in irq_comm.c. Moving the declaration to irq.h. While at it, include irq.h in hyperv.c because it needs to use kvm_irq_delivery_to_apic(). Signed-off-by: Peter Xu Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 1 + arch/x86/kvm/ioapic.h | 6 ------ arch/x86/kvm/irq.h | 3 +++ arch/x86/kvm/lapic.h | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 23ff65504d7e..c7d4640b7b1c 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -33,6 +33,7 @@ #include #include "trace.h" +#include "irq.h" #define KVM_HV_MAX_SPARSE_VCPU_SET_BITS DIV_ROUND_UP(KVM_MAX_VCPUS, 64) diff --git a/arch/x86/kvm/ioapic.h b/arch/x86/kvm/ioapic.h index ea1a4e0297da..2fb2e3c80724 100644 --- a/arch/x86/kvm/ioapic.h +++ b/arch/x86/kvm/ioapic.h @@ -116,9 +116,6 @@ static inline int ioapic_in_kernel(struct kvm *kvm) } void kvm_rtc_eoi_tracking_restore_one(struct kvm_vcpu *vcpu); -bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, - int short_hand, unsigned int dest, int dest_mode); -int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); void kvm_ioapic_update_eoi(struct kvm_vcpu *vcpu, int vector, int trigger_mode); int kvm_ioapic_init(struct kvm *kvm); @@ -126,9 +123,6 @@ void kvm_ioapic_destroy(struct kvm *kvm); int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, int level, bool line_status); void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id); -int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, - struct kvm_lapic_irq *irq, - struct dest_map *dest_map); void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, diff --git a/arch/x86/kvm/irq.h b/arch/x86/kvm/irq.h index 7c6233d37c64..f173ab6b407e 100644 --- a/arch/x86/kvm/irq.h +++ b/arch/x86/kvm/irq.h @@ -113,5 +113,8 @@ int apic_has_pending_timer(struct kvm_vcpu *vcpu); int kvm_setup_default_irq_routing(struct kvm *kvm); int kvm_setup_empty_irq_routing(struct kvm *kvm); +int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, + struct kvm_lapic_irq *irq, + struct dest_map *dest_map); #endif diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 39925afdfcdc..0b9bbadd1f3c 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -83,7 +83,7 @@ int kvm_lapic_reg_read(struct kvm_lapic *apic, u32 offset, int len, void *data); bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, int short_hand, unsigned int dest, int dest_mode); - +int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2); bool __kvm_apic_update_irr(u32 *pir, void *regs, int *max_irr); bool kvm_apic_update_irr(struct kvm_vcpu *vcpu, u32 *pir, int *max_irr); void kvm_apic_update_ppr(struct kvm_vcpu *vcpu); From patchwork Mon Dec 2 20:13:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11269881 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 399C5109A for ; Mon, 2 Dec 2019 20:13:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0EE1421823 for ; Mon, 2 Dec 2019 20:13:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EJDJGtb9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728182AbfLBUNb (ORCPT ); Mon, 2 Dec 2019 15:13:31 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:43149 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728151AbfLBUN2 (ORCPT ); Mon, 2 Dec 2019 15:13:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575317606; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K3f4R1TqR6G7UxbCAAe5fXF8uu/FH0Su8QCoaxdvYGE=; b=EJDJGtb94zLTYbcAoZyhzgV+uTN/AkhbSmcV0fIT+z4X7ll0OPqTYeoXrVQPtQWOcCtI43 pROImFMAQYjEAcd3tmHsLNJ9hsLpM4hk1XLUng8uYN5FxvVY7mmDF3mPV0qMwJJUGXI4h0 JMYajN9izwDqTTslZaBviPnfwkuB7o4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-50-J7zHYdMiOMq21hlYEXBz5A-1; Mon, 02 Dec 2019 15:13:25 -0500 Received: by mail-qk1-f197.google.com with SMTP id j192so507003qke.3 for ; Mon, 02 Dec 2019 12:13:24 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/XU4Dr7ARItxZIxIQIizWVEl4x5hbtpNhm0u7fErCg=; b=hNYjsTUs1RVtbbmKuwPWjbje+RNLMf685QZgYR4OF4/hBsXwylBjYJ+BDMqTkAIpqo Gv13z/nCH14RFXt5x/C7DYLqCAKOaNUozQnjyO0Y+o/asuhCYHUZGoVK0JM+LbRXKa8l c6Sps3WEMIstvB72h8zeBL88UUxXwCJejus4UtF+PcsyK1d9Qnh/oWIjEvpCrBCn/DB9 aezm83Se7aCTDsYNIQYIf9gqh3eE8bzvCrA/jdO3UPjvnSlspxTjzlyaLmjLdMqLSedw Xfis/CTBXz4x7N2aaVlgOGk9OWzh7HlfsM2tqeplo/jUYDoUdDWTVM20Fap9zeaaOwbD XhLA== X-Gm-Message-State: APjAAAVFx5eL+eJF6mONaVHD8JxBLLjHKT7wDXnA187GieCb5Q/Auu5l SpYNl8AhN+GcRtYVO0QDds3Z3sG9oom4k4dO6d4WLWW9X9OPga+x3B80uDucahziWPvFFOsNa0h zjqcqUrxuGfIo X-Received: by 2002:aed:3801:: with SMTP id j1mr1367427qte.48.1575317604513; Mon, 02 Dec 2019 12:13:24 -0800 (PST) X-Google-Smtp-Source: APXvYqw/9mtWQfg77PfrMmvIPQaca1gHr6J7yxGVs8qMBfMOh9LiPmHVcaxxTAuWGFFzLmzJFxdeXg== X-Received: by 2002:aed:3801:: with SMTP id j1mr1367401qte.48.1575317604260; Mon, 02 Dec 2019 12:13:24 -0800 (PST) Received: from xz-x1.yyz.redhat.com ([104.156.64.74]) by smtp.gmail.com with ESMTPSA id b6sm342410qtp.5.2019.12.02.12.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 12:13:23 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Nitesh Narayan Lal , Paolo Bonzini , Sean Christopherson , peterx@redhat.com, Vitaly Kuznetsov Subject: [PATCH v3 3/5] KVM: X86: Use APIC_DEST_* macros properly in kvm_lapic_irq.dest_mode Date: Mon, 2 Dec 2019 15:13:12 -0500 Message-Id: <20191202201314.543-4-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191202201314.543-1-peterx@redhat.com> References: <20191202201314.543-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: J7zHYdMiOMq21hlYEXBz5A-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We were using either APIC_DEST_PHYSICAL|APIC_DEST_LOGICAL or 0|1 to fill in kvm_lapic_irq.dest_mode. It's fine only because in most cases when we check against dest_mode it's against APIC_DEST_PHYSICAL (which equals to 0). However, that's not consistent. We'll have problem when we want to start checking against APIC_DEST_PHYSICAL, which does not equals to 1. This patch firstly introduces kvm_lapic_irq_dest_mode() helper to take any boolean of destination mode and return the APIC_DEST_* macro. Then, it replaces the 0|1 settings of irq.dest_mode with the helper. Signed-off-by: Peter Xu --- arch/x86/include/asm/kvm_host.h | 5 +++++ arch/x86/kvm/ioapic.c | 8 +++++--- arch/x86/kvm/irq_comm.c | 7 ++++--- arch/x86/kvm/x86.c | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b79cd6aa4075..f815c97b1b57 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1022,6 +1022,11 @@ struct kvm_lapic_irq { bool msi_redir_hint; }; +static inline u16 kvm_lapic_irq_dest_mode(bool dest_mode) +{ + return dest_mode ? APIC_DEST_LOGICAL : APIC_DEST_PHYSICAL; +} + struct kvm_x86_ops { int (*cpu_has_kvm_support)(void); /* __init */ int (*disabled_by_bios)(void); /* __init */ diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 9fd2dd89a1c5..901d85237d1c 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -331,7 +331,8 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) irq.vector = e->fields.vector; irq.delivery_mode = e->fields.delivery_mode << 8; irq.dest_id = e->fields.dest_id; - irq.dest_mode = e->fields.dest_mode; + irq.dest_mode = + kvm_lapic_irq_dest_mode(e->fields.dest_mode); bitmap_zero(&vcpu_bitmap, 16); kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, &vcpu_bitmap); @@ -343,7 +344,8 @@ static void ioapic_write_indirect(struct kvm_ioapic *ioapic, u32 val) * keep ioapic_handled_vectors synchronized. */ irq.dest_id = old_dest_id; - irq.dest_mode = old_dest_mode; + irq.dest_mode = + kvm_lapic_irq_dest_mode(e->fields.dest_mode); kvm_bitmap_or_dest_vcpus(ioapic->kvm, &irq, &vcpu_bitmap); } @@ -369,7 +371,7 @@ static int ioapic_service(struct kvm_ioapic *ioapic, int irq, bool line_status) irqe.dest_id = entry->fields.dest_id; irqe.vector = entry->fields.vector; - irqe.dest_mode = entry->fields.dest_mode; + irqe.dest_mode = kvm_lapic_irq_dest_mode(entry->fields.dest_mode); irqe.trig_mode = entry->fields.trig_mode; irqe.delivery_mode = entry->fields.delivery_mode << 8; irqe.level = 1; diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c index 8ecd48d31800..5f59e5ebdbed 100644 --- a/arch/x86/kvm/irq_comm.c +++ b/arch/x86/kvm/irq_comm.c @@ -52,8 +52,8 @@ int kvm_irq_delivery_to_apic(struct kvm *kvm, struct kvm_lapic *src, unsigned long dest_vcpu_bitmap[BITS_TO_LONGS(KVM_MAX_VCPUS)]; unsigned int dest_vcpus = 0; - if (irq->dest_mode == 0 && irq->dest_id == 0xff && - kvm_lowest_prio_delivery(irq)) { + if (irq->dest_mode == APIC_DEST_PHYSICAL && + irq->dest_id == 0xff && kvm_lowest_prio_delivery(irq)) { printk(KERN_INFO "kvm: apic: phys broadcast and lowest prio\n"); irq->delivery_mode = APIC_DM_FIXED; } @@ -114,7 +114,8 @@ void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, irq->dest_id |= MSI_ADDR_EXT_DEST_ID(e->msi.address_hi); irq->vector = (e->msi.data & MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT; - irq->dest_mode = (1 << MSI_ADDR_DEST_MODE_SHIFT) & e->msi.address_lo; + irq->dest_mode = kvm_lapic_irq_dest_mode( + (1 << MSI_ADDR_DEST_MODE_SHIFT) & e->msi.address_lo); irq->trig_mode = (1 << MSI_DATA_TRIGGER_SHIFT) & e->msi.data; irq->delivery_mode = e->msi.data & 0x700; irq->msi_redir_hint = ((e->msi.address_lo diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 3ed167e039e5..3b00d662dc14 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7356,7 +7356,7 @@ static void kvm_pv_kick_cpu_op(struct kvm *kvm, unsigned long flags, int apicid) struct kvm_lapic_irq lapic_irq; lapic_irq.shorthand = 0; - lapic_irq.dest_mode = 0; + lapic_irq.dest_mode = APIC_DEST_PHYSICAL; lapic_irq.level = 0; lapic_irq.dest_id = apicid; lapic_irq.msi_redir_hint = false; From patchwork Mon Dec 2 20:13:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11269883 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A4A96112B for ; Mon, 2 Dec 2019 20:13:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8347221774 for ; Mon, 2 Dec 2019 20:13:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y7xrUui9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728196AbfLBUNd (ORCPT ); Mon, 2 Dec 2019 15:13:33 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:55392 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728172AbfLBUNa (ORCPT ); Mon, 2 Dec 2019 15:13:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575317609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T7L1QC4sZLzLTqoiJLJWCwYXhhugr76FDNW4JXS4WHg=; b=Y7xrUui9TM0Ye+yDvI228IGQ9Wo+lQexUUBBfDqFf/ymtw5xCcKuR/qilXf0jTNGtz3y9v DOsaZvj3OfY2pjb7pGdtPWWZ8HJ+P/b7vg4F0Nv4wd7Z3P7d9+Gc4cOfGFnQeNS7ZI0Dn0 P5aDnotoD0xk4ZSFh4hk6tcQPlknvNY= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-304-MdpHRlVDMgOznfUQD9XKtA-1; Mon, 02 Dec 2019 15:13:26 -0500 Received: by mail-qk1-f200.google.com with SMTP id 143so484979qkg.12 for ; Mon, 02 Dec 2019 12:13:26 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=IdAobF5KxkWmSZeeTAl/kA2XqKFNltZufrBJllpURpA=; b=CQ4T7YfjA2tgLkjkdL2vU1+g7IuzoGnA8olxP25WytV6F8McW+57jO/Gd/OJSyju+u 0mTLHC+h6mXbKtpVythMYZEsqKnQWE4zJsJl4owfL36dGAZp0VTVVpSsw1UTAPqwL7vT G8B7kmdhFVcwRB7/3/gU9i2H4yFefdGwW98YDzB8GYIFnrOr9VZSvg8LDaLHMmy37YyJ IwzsTTPo0GIEu+tqC6+X/TN5hXyrG4Z11wp4M/feuwy3NoRKvlgQAtS1ek2oTnK3eiSy /99MhpH5gXg5UBl5EXCdxQw5zPXFl3ulgKQGQSDgytSqV5wp7Xe/dRfkY4rJFxrjD/Wh o5AQ== X-Gm-Message-State: APjAAAV5/cGJgoh7Ke7Cfifdlvqkk4hv5kR+oWe/x+3htYn+Wk4ibdqk rYwBluoMfTs3WFbmJQ6q6b/ovBTRH8LOcMt+ka7fKwSPFW91ekuYJ5E/0Ze6jft+31r/0ABMXtD op0o5TvCepbRe X-Received: by 2002:a05:620a:102e:: with SMTP id a14mr786093qkk.159.1575317605928; Mon, 02 Dec 2019 12:13:25 -0800 (PST) X-Google-Smtp-Source: APXvYqxEmfH5EcGeAkoaUvzsaIZoBstltQzghSFbzjr38dtpCINdSAr6Gawz4Ylo/zCpRToT4lqTKw== X-Received: by 2002:a05:620a:102e:: with SMTP id a14mr786063qkk.159.1575317605660; Mon, 02 Dec 2019 12:13:25 -0800 (PST) Received: from xz-x1.yyz.redhat.com ([104.156.64.74]) by smtp.gmail.com with ESMTPSA id b6sm342410qtp.5.2019.12.02.12.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 12:13:24 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Nitesh Narayan Lal , Paolo Bonzini , Sean Christopherson , peterx@redhat.com, Vitaly Kuznetsov Subject: [PATCH v3 4/5] KVM: X86: Drop KVM_APIC_SHORT_MASK and KVM_APIC_DEST_MASK Date: Mon, 2 Dec 2019 15:13:13 -0500 Message-Id: <20191202201314.543-5-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191202201314.543-1-peterx@redhat.com> References: <20191202201314.543-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: MdpHRlVDMgOznfUQD9XKtA-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We have both APIC_SHORT_MASK and KVM_APIC_SHORT_MASK defined for the shorthand mask. Similarly, we have both APIC_DEST_MASK and KVM_APIC_DEST_MASK defined for the destination mode mask. Drop the KVM_APIC_* macros and replace the only user of them to use the APIC_DEST_* macros instead. At the meantime, move APIC_SHORT_MASK and APIC_DEST_MASK from lapic.c to lapic.h. Signed-off-by: Peter Xu Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/lapic.c | 3 --- arch/x86/kvm/lapic.h | 5 +++-- arch/x86/kvm/svm.c | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 1eabe58bb6d5..805c18178bbf 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -56,9 +56,6 @@ #define APIC_VERSION (0x14UL | ((KVM_APIC_LVT_NUM - 1) << 16)) #define LAPIC_MMIO_LENGTH (1 << 12) /* followed define is not in apicdef.h */ -#define APIC_SHORT_MASK 0xc0000 -#define APIC_DEST_NOSHORT 0x0 -#define APIC_DEST_MASK 0x800 #define MAX_APIC_VECTOR 256 #define APIC_VECTORS_PER_REG 32 diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 0b9bbadd1f3c..5a9f29ed9a4b 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -10,8 +10,9 @@ #define KVM_APIC_SIPI 1 #define KVM_APIC_LVT_NUM 6 -#define KVM_APIC_SHORT_MASK 0xc0000 -#define KVM_APIC_DEST_MASK 0x800 +#define APIC_SHORT_MASK 0xc0000 +#define APIC_DEST_NOSHORT 0x0 +#define APIC_DEST_MASK 0x800 #define APIC_BUS_CYCLE_NS 1 #define APIC_BUS_FREQUENCY (1000000000ULL / APIC_BUS_CYCLE_NS) diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 362e874297e4..65a27a7e9cb1 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -4519,9 +4519,9 @@ static int avic_incomplete_ipi_interception(struct vcpu_svm *svm) */ kvm_for_each_vcpu(i, vcpu, kvm) { bool m = kvm_apic_match_dest(vcpu, apic, - icrl & KVM_APIC_SHORT_MASK, + icrl & APIC_SHORT_MASK, GET_APIC_DEST_FIELD(icrh), - icrl & KVM_APIC_DEST_MASK); + icrl & APIC_DEST_MASK); if (m && !avic_vcpu_is_running(vcpu)) kvm_vcpu_wake_up(vcpu); From patchwork Mon Dec 2 20:13:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 11269885 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEF41112B for ; Mon, 2 Dec 2019 20:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B864221774 for ; Mon, 2 Dec 2019 20:13:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Am2cIpFR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728190AbfLBUNc (ORCPT ); Mon, 2 Dec 2019 15:13:32 -0500 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:27688 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728183AbfLBUNb (ORCPT ); Mon, 2 Dec 2019 15:13:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575317611; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hGyv0HcV61jwW8d05G9E2IdyBpBV7NLYzlcgkoWtE1A=; b=Am2cIpFRlGu6JRYgXu4lqCvpEj1kgPr0coTSup573TNkb2PgZpEzRlSceLBP6QRIM6bY6Z uP2c3WayJWwDfehwc02/shO+lw2+EJhhKEJd+zz6uw+xZ0lvfH/U0jX9DYO3onehSBqq5j 1P18VVgxrp8uBpKHN0dyuivE9j1usFg= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-232-f467Dvh7NNqsej2Mttk6DA-1; Mon, 02 Dec 2019 15:13:27 -0500 Received: by mail-qv1-f69.google.com with SMTP id l1so528831qvu.13 for ; Mon, 02 Dec 2019 12:13:27 -0800 (PST) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=D/FzhMnEoda/8HIh8/dn3z8Z/X2H7yZOxK6TY6H8n7g=; b=sZUr2fWszBYTDN/mrEq6MxhUmMlR6gK0nURkd+msczvWfEOaaLlCKXBX121moMuCyU MStbEEPd0RI3VFqeOvKtLHqfVbw0ResG0ZhBpIsu0dsBQHRNo0NZXY2kj099VTOUqrFV YOiFX3M4JSrBBmG9lZlo7dpiClI15fzGQ5r7eb6STpr1JC3XYFs7CqcaCbcy0k4a8PwM QL2VYChdwrqbTyVZo2YngwHC/56WdTA6z1M2g8UVRb7fC10gKDboEHxu+9vn6oRdzfxy vDPIvjLaqs9vZhxZMghy7zx6LBu511eq5bU5GIEIpirivtz2OPELbEvChCarrUVYj5fk 5bXA== X-Gm-Message-State: APjAAAVy/YjqAMRPCMt+pN+ffwW2ssI8EbaJntomRInwJTOAsKe7A1Bd PWvrsEdrFXpZ2AAGpzpUa4LlPFzZrnuosNVvlY9SCFDGW9Ui0H48E2pWzvy+OSaEhJi5g9Rez/y 4ROLDHNp8g7jv X-Received: by 2002:ac8:4a8a:: with SMTP id l10mr1303326qtq.198.1575317607412; Mon, 02 Dec 2019 12:13:27 -0800 (PST) X-Google-Smtp-Source: APXvYqyJIT5O2PIq2hBfIXIZv6d47L3iz/6K6nfkU3HOvroWZken45053jQWJDbUYGB3TtnE632I4A== X-Received: by 2002:ac8:4a8a:: with SMTP id l10mr1303310qtq.198.1575317607172; Mon, 02 Dec 2019 12:13:27 -0800 (PST) Received: from xz-x1.yyz.redhat.com ([104.156.64.74]) by smtp.gmail.com with ESMTPSA id b6sm342410qtp.5.2019.12.02.12.13.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 12:13:26 -0800 (PST) From: Peter Xu To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Nitesh Narayan Lal , Paolo Bonzini , Sean Christopherson , peterx@redhat.com, Vitaly Kuznetsov Subject: [PATCH v3 5/5] KVM: X86: Fix callers of kvm_apic_match_dest() to use correct macros Date: Mon, 2 Dec 2019 15:13:14 -0500 Message-Id: <20191202201314.543-6-peterx@redhat.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191202201314.543-1-peterx@redhat.com> References: <20191202201314.543-1-peterx@redhat.com> MIME-Version: 1.0 X-MC-Unique: f467Dvh7NNqsej2Mttk6DA-1 X-Mimecast-Spam-Score: 0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Callers of kvm_apic_match_dest() should always pass in APIC_DEST_* macros for either dest_mode and short_hand parameters. Fix up all the callers of kvm_apic_match_dest() that are not following the rule. Reported-by: Sean Christopherson Reported-by: Vitaly Kuznetsov Signed-off-by: Peter Xu Reviewed-by: Vitaly Kuznetsov --- arch/x86/kvm/ioapic.c | 11 +++++++---- arch/x86/kvm/irq_comm.c | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 901d85237d1c..1082ca8d11e5 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -108,8 +108,9 @@ static void __rtc_irq_eoi_tracking_restore_one(struct kvm_vcpu *vcpu) union kvm_ioapic_redirect_entry *e; e = &ioapic->redirtbl[RTC_GSI]; - if (!kvm_apic_match_dest(vcpu, NULL, 0, e->fields.dest_id, - e->fields.dest_mode)) + if (!kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT, + e->fields.dest_id, + kvm_lapic_irq_dest_mode(e->fields.dest_mode))) return; new_val = kvm_apic_pending_eoi(vcpu, e->fields.vector); @@ -237,6 +238,7 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors) struct dest_map *dest_map = &ioapic->rtc_status.dest_map; union kvm_ioapic_redirect_entry *e; int index; + u16 dm; spin_lock(&ioapic->lock); @@ -250,8 +252,9 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors) if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG || kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || index == RTC_GSI) { - if (kvm_apic_match_dest(vcpu, NULL, 0, - e->fields.dest_id, e->fields.dest_mode) || + dm = kvm_lapic_irq_dest_mode(e->fields.dest_mode); + if (kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT, + e->fields.dest_id, dm) || kvm_apic_pending_eoi(vcpu, e->fields.vector)) __set_bit(e->fields.vector, ioapic_handled_vectors); diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c index 5f59e5ebdbed..e89c2160b39f 100644 --- a/arch/x86/kvm/irq_comm.c +++ b/arch/x86/kvm/irq_comm.c @@ -417,7 +417,8 @@ void kvm_scan_ioapic_routes(struct kvm_vcpu *vcpu, kvm_set_msi_irq(vcpu->kvm, entry, &irq); - if (irq.level && kvm_apic_match_dest(vcpu, NULL, 0, + if (irq.level && + kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT, irq.dest_id, irq.dest_mode)) __set_bit(irq.vector, ioapic_handled_vectors); }