Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5188004ybl; Tue, 27 Aug 2019 00:25:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYvrO0C5HBIimU7bnWbB0l+WMGNed59eJGEg2UadLoMKNiZ+TZNcirNdFevH1Wa5k2ClhN X-Received: by 2002:aa7:8a86:: with SMTP id a6mr15071897pfc.76.1566890727876; Tue, 27 Aug 2019 00:25:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566890727; cv=none; d=google.com; s=arc-20160816; b=irAjfKyKPnoVbIgnB10Xj3nDNSMWOQJ07n63PlzFTYc5Zh5+KE7ELHmeqPEX7Pgj/6 JpqLcA5c9HmnqFvWQpS0WOPuB4z0iC43V7rZ5+MV9GoKvdFbyxTn/m+oHMNlAn2YlwTT MyntF2K0fyC4iamjLVj/CYJXUV7uf2JIIW8O0e0j1+uzz9Y/V1oXWsfY5sWGzLoQnfMj eq30JQyEa9VTFN53H2k/2XjbvJeYADwCW+WPn1p5rvZUoRRXEiIc4ljEj2bpkzyIPcxa T5h3SS+YYeOzc0qJ3hVBQI/plfYRIoQfmvIDcEBaFz042Zez1PxYnOP9ZgJnoKMLOoGe i4fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from; bh=pzHviUK3atqXhQXnPVoHHHqmzFOi+zrzBFXLMguzsmQ=; b=M77sCDnC2kLQ/5vPRA2/TMu4DGdLoB0KFYoULOT8HT1H6dM7rCRM/6GRHfI7fjbeux 8fUy5BMiQzENaWdRl+bc9g36O01Q1TGF8K8oY03QQytin/tCUbqnB40FMzWgYfOY1ju4 MAr8duJslX41PuMzvyS8CrVzRv8XBv5kr8g1vstqRwqtRo70hd+AQR7dObyk7e4VWwBc k3MLYY/boincn0qAuSUh8zG82yW5xW6rbO/vLJUS1GzmkrkKzKz/dwPXh4MKrNWb2HgG q84bzKI/N484+RD4S6KKLUpSC6iSHezv5lqIcN0PLjvMqHSNLi/u6Lt0zJNAG7jtADLl pZfQ== 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 c5si11809783plr.291.2019.08.27.00.25.12; Tue, 27 Aug 2019 00:25:27 -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 S1726616AbfH0HWy (ORCPT + 99 others); Tue, 27 Aug 2019 03:22:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42920 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725825AbfH0HWy (ORCPT ); Tue, 27 Aug 2019 03:22:54 -0400 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 216123C93 for ; Tue, 27 Aug 2019 07:22:53 +0000 (UTC) Received: by mail-wm1-f72.google.com with SMTP id b11so671984wmj.0 for ; Tue, 27 Aug 2019 00:22:53 -0700 (PDT) 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:in-reply-to:references:date :message-id:mime-version; bh=pzHviUK3atqXhQXnPVoHHHqmzFOi+zrzBFXLMguzsmQ=; b=Mc2i4zQh+MqsdXIcWlVq056KjPEUy/bSzbLMVAW8h0FX5RyJoclZKMPhKPRWEncAWd gM/wi9Cb3h+iP9oEmQHna0EIJxHOb63Pjc1rVcqlQ6cnb0tOD6fzg6jHkkwFzM+OahX+ HlH3KDUAkgRBk/y+psdnQ/uEf1GMaUlhvAEodoaXlXSaWRuvn+8waZkjUW35ZK6WzgRB 6qGfX/+RGgPBCiNYEuvrYYMEadXJS6FG+/xoOqKPn+rIguMtPl4pFxsiotws5LTQZ4yO CuPQyi2wuq65FB2HgXO1i56m/BflYAFtZIBja/feu+v7rR3nQfMiNj8AkNewk92ucQ6h R75g== X-Gm-Message-State: APjAAAV5lBL5wgXQOUnvLrLw4d7PLACuZKMyGK1j/dE0Dh5s501bL18z +erAc+yt8w5ePXnTi/LFhhPGGw9WzLWxYQrryzVGu6wzWhvdcFQR1mVN0VM/LYjxcx3A9NJ/yci k3lV9Xhpca6qCz1hNYGF5vtxW X-Received: by 2002:a5d:4b05:: with SMTP id v5mr27160280wrq.208.1566890571861; Tue, 27 Aug 2019 00:22:51 -0700 (PDT) X-Received: by 2002:a5d:4b05:: with SMTP id v5mr27160234wrq.208.1566890571484; Tue, 27 Aug 2019 00:22:51 -0700 (PDT) Received: from vitty.brq.redhat.com (ip-89-176-161-20.net.upcbroadband.cz. [89.176.161.20]) by smtp.gmail.com with ESMTPSA id f7sm18038767wrf.8.2019.08.27.00.22.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Aug 2019 00:22:51 -0700 (PDT) From: Vitaly Kuznetsov To: "Suthikulpanit\, Suravee" Cc: "pbonzini\@redhat.com" , "rkrcmar\@redhat.com" , "joro\@8bytes.org" , "graf\@amazon.com" , "jschoenh\@amazon.de" , "karahmed\@amazon.de" , "rimasluk\@amazon.com" , "Grimm\, Jon" , "Suthikulpanit\, Suravee" , "linux-kernel\@vger.kernel.org" , "kvm\@vger.kernel.org" Subject: Re: [PATCH v2 05/15] kvm: lapic: Introduce APICv update helper function In-Reply-To: <1565886293-115836-6-git-send-email-suravee.suthikulpanit@amd.com> References: <1565886293-115836-1-git-send-email-suravee.suthikulpanit@amd.com> <1565886293-115836-6-git-send-email-suravee.suthikulpanit@amd.com> Date: Tue, 27 Aug 2019 09:22:50 +0200 Message-ID: <87a7bvm5rp.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Suthikulpanit, Suravee" writes: > Re-factor code into a helper function for setting lapic parameters when > activate/deactivate APICv, and export the function for subsequent usage. > > Signed-off-by: Suravee Suthikulpanit > --- > arch/x86/kvm/lapic.c | 22 +++++++++++++++++----- > arch/x86/kvm/lapic.h | 1 + > 2 files changed, 18 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c > index 4dabc31..90f79ca 100644 > --- a/arch/x86/kvm/lapic.c > +++ b/arch/x86/kvm/lapic.c > @@ -2153,6 +2153,21 @@ void kvm_lapic_set_base(struct kvm_vcpu *vcpu, u64 value) > > } > > +void kvm_apic_update_apicv(struct kvm_vcpu *vcpu) > +{ > + struct kvm_lapic *apic = vcpu->arch.apic; > + > + if (vcpu->arch.apicv_active) { > + /* irr_pending is always true when apicv is activated. */ > + apic->irr_pending = true; > + apic->isr_count = 1; > + } else { > + apic->irr_pending = (apic_search_irr(apic) != -1); > + apic->isr_count = count_vectors(apic->regs + APIC_ISR); > + } > +} > +EXPORT_SYMBOL(kvm_apic_update_apicv); EXPORT_SYMBOL_GPL please. > + > void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) > { > struct kvm_lapic *apic = vcpu->arch.apic; > @@ -2197,8 +2212,7 @@ void kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) > kvm_lapic_set_reg(apic, APIC_ISR + 0x10 * i, 0); > kvm_lapic_set_reg(apic, APIC_TMR + 0x10 * i, 0); > } > - apic->irr_pending = vcpu->arch.apicv_active; > - apic->isr_count = vcpu->arch.apicv_active ? 1 : 0; > + kvm_apic_update_apicv(vcpu); > apic->highest_isr_cache = -1; > update_divide_count(apic); > atomic_set(&apic->lapic_timer.pending, 0); > @@ -2468,9 +2482,7 @@ int kvm_apic_set_state(struct kvm_vcpu *vcpu, struct kvm_lapic_state *s) > apic_manage_nmi_watchdog(apic, kvm_lapic_get_reg(apic, APIC_LVT0)); > update_divide_count(apic); > start_apic_timer(apic); > - apic->irr_pending = true; > - apic->isr_count = vcpu->arch.apicv_active ? > - 1 : count_vectors(apic->regs + APIC_ISR); > + kvm_apic_update_apicv(vcpu); > apic->highest_isr_cache = -1; > if (vcpu->arch.apicv_active) { > kvm_x86_ops->apicv_post_state_restore(vcpu); > diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h > index d6d049b..3892d50 100644 > --- a/arch/x86/kvm/lapic.h > +++ b/arch/x86/kvm/lapic.h > @@ -90,6 +90,7 @@ bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, > int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq, > struct dest_map *dest_map); > int kvm_apic_local_deliver(struct kvm_lapic *apic, int lvt_type); > +void kvm_apic_update_apicv(struct kvm_vcpu *vcpu); > > bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src, > struct kvm_lapic_irq *irq, int *r, struct dest_map *dest_map); -- Vitaly