From patchwork Wed Dec 16 19:41:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ioanna Alifieraki X-Patchwork-Id: 1417376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cx59X5S6xz9sTg; Thu, 17 Dec 2020 06:41:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1kpcgH-00010p-Oy; Wed, 16 Dec 2020 19:41:49 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpcgF-00010I-Ca for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 19:41:47 +0000 Received: from mail-wm1-f69.google.com ([209.85.128.69]) by youngberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kpcgF-00031d-35 for kernel-team@lists.ubuntu.com; Wed, 16 Dec 2020 19:41:47 +0000 Received: by mail-wm1-f69.google.com with SMTP id r1so2053645wmn.8 for ; Wed, 16 Dec 2020 11:41:47 -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:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9DUC4p4njO4AIpQm2mHznoe4yYD/jGMdS6uiK1y8gpo=; b=CMhU+uJ5AUY70LNm8WwRJ+iH0WASl5YWxThg2NMmZ8HOaYyt6sDrvo3RhFtTAv4grb oDAJ0louUxuOCaLt4MY6+oBfoS89uR++N3bUHPjq7JjEu3KAKhflOtlNuBN44wrdbeN2 KTfO0gii4VSpv0U2fq/SvPf3PgEeFs/eGuS9jRW47DshStiOHBfpyiNU90lNyOMVZUWM /vyRxmd7ixGVGei66QzIPRuYidQJnbC/FFHAvN5Tgv2lUQUd8jlog44sAiJCv0hwnCPT K/KgeYfTbSLYR9eyRQ3haDNvbl98CaEJ9r8QEkOWfY5A8wOmttj9YpD5nu9FDUkWOVEs DL4Q== X-Gm-Message-State: AOAM5300HYKUo+5hgD7uvB+gkv5ThHYfJhDryDNPyKYdnxhX0T0qVGI2 alMBzWsTBZjIFGaMoEhBUKrPeHfrJ4uUv+Fsmartgk9/AaDdzxaHwCK7M325qdldf/y8CoKqbpb PsvGwhk2Hjz7nKD3Wc/nGnpaFKwA3WcyCoPkKRJgjzQ== X-Received: by 2002:a5d:6a83:: with SMTP id s3mr40667889wru.334.1608147706611; Wed, 16 Dec 2020 11:41:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8fKaknXwvoLLD+1PKM2SwBhC5JA0a+5Jb4E0ZORN64fteLcVrmFDdZO4FY7DS7yP4+NERHg== X-Received: by 2002:a5d:6a83:: with SMTP id s3mr40667872wru.334.1608147706349; Wed, 16 Dec 2020 11:41:46 -0800 (PST) Received: from localhost ([2001:67c:1560:8007::aac:c2e0]) by smtp.gmail.com with ESMTPSA id k10sm4092778wrq.38.2020.12.16.11.41.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 16 Dec 2020 11:41:45 -0800 (PST) From: Ioanna Alifieraki To: kernel-team@lists.ubuntu.com Subject: [SRU][Xenial][PATCH 1/3] KVM: VMX: extract __pi_post_block Date: Wed, 16 Dec 2020 19:41:43 +0000 Message-Id: <20201216194145.24239-2-ioanna-maria.alifieraki@canonical.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201216194145.24239-1-ioanna-maria.alifieraki@canonical.com> References: <20201216194145.24239-1-ioanna-maria.alifieraki@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Paolo Bonzini BugLink: https://bugs.launchpad.net/bugs/1908428 Simple code movement patch, preparing for the next one. Cc: Huangweidong Cc: Gonglei Cc: wangxin Cc: Radim Krčmář Tested-by: Longpeng (Mike) Cc: stable@vger.kernel.org Signed-off-by: Paolo Bonzini (backported from commit cd39e1176d320157831ce030b4c869bd2d5eb142) [hunk 2 : Original commit changes pi_post_block function. This function is not present in 4.4 kernel, see upstream commit bc22512bb24c(kvm: vmx: rename vmx_pre/post_block to pi_pre/post_block). Make relevant changes in vmx_post_block function.] Signed-off-by: Ioanna Alifieraki --- arch/x86/kvm/vmx.c | 71 +++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 46d1293baa04..472d089f0bd2 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -11145,6 +11145,43 @@ static void vmx_enable_log_dirty_pt_masked(struct kvm *kvm, kvm_mmu_clear_dirty_pt_masked(kvm, memslot, offset, mask); } +static void __pi_post_block(struct kvm_vcpu *vcpu) +{ + struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); + struct pi_desc old, new; + unsigned int dest; + unsigned long flags; + + do { + old.control = new.control = pi_desc->control; + + dest = cpu_physical_id(vcpu->cpu); + + if (x2apic_enabled()) + new.ndst = dest; + else + new.ndst = (dest << 8) & 0xFF00; + + /* Allow posting non-urgent interrupts */ + new.sn = 0; + + /* set 'NV' to 'notification vector' */ + new.nv = POSTED_INTR_VECTOR; + } while (cmpxchg(&pi_desc->control, old.control, + new.control) != old.control); + + if(vcpu->pre_pcpu != -1) { + spin_lock_irqsave( + &per_cpu(blocked_vcpu_on_cpu_lock, + vcpu->pre_pcpu), flags); + list_del(&vcpu->blocked_vcpu_list); + spin_unlock_irqrestore( + &per_cpu(blocked_vcpu_on_cpu_lock, + vcpu->pre_pcpu), flags); + vcpu->pre_pcpu = -1; + } +} + /* * This routine does the following things for vCPU which is going * to be blocked if VT-d PI is enabled. @@ -11226,43 +11263,11 @@ static int vmx_pre_block(struct kvm_vcpu *vcpu) static void vmx_post_block(struct kvm_vcpu *vcpu) { - struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); - struct pi_desc old, new; - unsigned int dest; - unsigned long flags; - if (!kvm_arch_has_assigned_device(vcpu->kvm) || !irq_remapping_cap(IRQ_POSTING_CAP)) return; - do { - old.control = new.control = pi_desc->control; - - dest = cpu_physical_id(vcpu->cpu); - - if (x2apic_enabled()) - new.ndst = dest; - else - new.ndst = (dest << 8) & 0xFF00; - - /* Allow posting non-urgent interrupts */ - new.sn = 0; - - /* set 'NV' to 'notification vector' */ - new.nv = POSTED_INTR_VECTOR; - } while (cmpxchg64(&pi_desc->control, old.control, - new.control) != old.control); - - if(vcpu->pre_pcpu != -1) { - spin_lock_irqsave( - &per_cpu(blocked_vcpu_on_cpu_lock, - vcpu->pre_pcpu), flags); - list_del(&vcpu->blocked_vcpu_list); - spin_unlock_irqrestore( - &per_cpu(blocked_vcpu_on_cpu_lock, - vcpu->pre_pcpu), flags); - vcpu->pre_pcpu = -1; - } + __pi_post_block(vcpu); } /*