From patchwork Tue Jul 17 00:24:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Shier X-Patchwork-Id: 10527821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A67C5603ED for ; Tue, 17 Jul 2018 00:24:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80D7028CE8 for ; Tue, 17 Jul 2018 00:24:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 70F1E28CF1; Tue, 17 Jul 2018 00:24:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C76828CE8 for ; Tue, 17 Jul 2018 00:24:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729930AbeGQAya (ORCPT ); Mon, 16 Jul 2018 20:54:30 -0400 Received: from mail-vk0-f74.google.com ([209.85.213.74]:38125 "EHLO mail-vk0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729814AbeGQAy3 (ORCPT ); Mon, 16 Jul 2018 20:54:29 -0400 Received: by mail-vk0-f74.google.com with SMTP id d134-v6so13148119vkf.5 for ; Mon, 16 Jul 2018 17:24:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to:cc; bh=9jDgz6wuFC2zQJKxMah81CncQ+IrSw1RDZkeyEqnPzA=; b=YFksl+4CJzKITjdhk8DCqW8xQ3ZVwX2SFOWcJ4hIwvN6QrxAB0q21DLUlGy7bxaUKP yUS3Gtv05Db43y0iGRU7+6Y4tBbyVYk5FnPYTVy1V+iDNH6B1rjyR/vuiawGo/k0wlcX f1Vx1wuLvEWn+QZ8mGUQKdIgzF6ZybT0gnoPgOtifwwtLM5bEBl1fUn0Oawd50i+rFRJ vEpHUNRtPwyMJNvcF/WkbYK9yPfsLslnrEiV4A85MFqLAhTqRqIrxyAu3ycL91QXXAhC KaSvAvFpyp8P6Qbd3PHoFlpKjdaW63H03VgXk01c4Ia9GoTxqKG1/L19zJ92MOd6Mhgo YXpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc; bh=9jDgz6wuFC2zQJKxMah81CncQ+IrSw1RDZkeyEqnPzA=; b=hQXWesyako9Iy78R5TAlwUYsS4etrYgq/d07rtbjgKYenBmb/vZr25Jd85HKR47gY3 vh+GuWdm75FzWYlfUifIvg1Ec2jJ6B2t2p04ydjt8bxzUhpkO1BA7ysSTAzfqH1zlCpz P8prtZEzu2BBFbjcclZlTgQwRP/juwdGQI50n2xCr5TAySHsrz0kM062q9q31/0RLVMc yUl4dB6v8sqxp2eBDJRrKz7p8w5XNwQOtRzKRw6eXDVwaOjljAJtOY2XSCW9SSadkjir rFY0DoA6IDcASiYI3s4dOj8V1KvQGnMxiYGRSSPI8os01pgogoD1rY0vryW7oWRcIgcm qC5g== X-Gm-Message-State: AOUpUlFx/Nz4+aNZTEsgrWQLG2YQVNd2ZvI2pyKLT3TO4dHbOHFmAdwV eGyAwn8iT6KmzeGUDEXKtEMdyc+rZfCNYHBKwQgMQ6ZGso39Dews9i46FKMP6hdnr3RDVHexY4Z Lomr4WEaa1HeG8y69Dm8YxFYDTZzDziFGLtMnu3sKNqRA2fnQumZdTzMIeQ== X-Google-Smtp-Source: AAOMgpdAewxlAEHrDgpqkEad3r4Yu0F3LCrE/2T7zRn1KpknDPysd5vWbl4mD2kzORNtENH2MFIngIVIUOA= MIME-Version: 1.0 X-Received: by 2002:a1f:83c7:: with SMTP id f190-v6mr8638733vkd.74.1531787080101; Mon, 16 Jul 2018 17:24:40 -0700 (PDT) Date: Mon, 16 Jul 2018 17:24:27 -0700 Message-Id: <20180717002428.39055-1-pshier@google.com> X-Mailer: git-send-email 2.18.0.203.gfac676dfb9-goog Subject: [PATCH] kvm: Clear stale posted interrupts when restoring apic state. From: Peter Shier To: kvm@vger.kernel.org Cc: Andrew Honig , Peter Shier Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andrew Honig Prior to this change if userspace set the local apic state while there was a posted interrupt waiting, then the posted interrupt would not be cleared. To fix this issue we clear all the not-yet-delivered posted interrupts and put them in the apic, so that when userspace overwrites the apic, registers, it also clears any posted interrupts. Signed-off-by: Andrew Honig Signed-off-by: Peter Shier --- arch/x86/kvm/x86.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0046aa70205aa..cbb097946d32f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3163,6 +3163,9 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu, { int r; + if (vcpu->arch.apicv_active) + kvm_x86_ops->sync_pir_to_irr(vcpu); + r = kvm_apic_set_state(vcpu, s); if (r) return r;