From patchwork Fri Nov 4 19:15:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ignacio Alvarado X-Patchwork-Id: 9413131 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 749B860585 for ; Fri, 4 Nov 2016 19:16:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6409B2B1A5 for ; Fri, 4 Nov 2016 19:16:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 586CF2B1E6; Fri, 4 Nov 2016 19:16:07 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 E59E52B1A5 for ; Fri, 4 Nov 2016 19:16:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751147AbcKDTQD (ORCPT ); Fri, 4 Nov 2016 15:16:03 -0400 Received: from mail-pf0-f173.google.com ([209.85.192.173]:36448 "EHLO mail-pf0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750719AbcKDTQC (ORCPT ); Fri, 4 Nov 2016 15:16:02 -0400 Received: by mail-pf0-f173.google.com with SMTP id 189so56442470pfz.3 for ; Fri, 04 Nov 2016 12:16:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MOYvkCjvUsnX3So4OQtXN3YeQYAZBljTRI9ZrBWheho=; b=UrwUvQVI0I1RaF4dtQnTiQ/iBiQYNduXcZShDll68pctqcWBpZD2Bynj12huYii7Ur sHkYoaxoBdhfyToqS0SH7FcfufWqN0mCi1c570XIixnpO4xQEZt/CKusmQ2kf+t2aovF S6TKYPpF79PbYQmQgiG+Fzd93PJDeA6D9OQJSMCnT6OQ70exks/UvdV960lLgnHnvAfk pV/qsF0YVtGZbmyOoN8w9Yt7xi/VaAZKB/KIcTnv9tDXZc9bWdM81Ai4mYmoqTRIP6KA Dfp4D24IlFm6wZNaypxqrMDhkt3WPmgg1BrxypbVEei77+jnUVfgMcq7G+Zw9kyjHiaN Iqog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MOYvkCjvUsnX3So4OQtXN3YeQYAZBljTRI9ZrBWheho=; b=YKBfaMEgL7GiFJ9acuu9Thaae+r0B/yg8EZ6OldYAQV4/C3T8xirSUVDpDA1IJKaIK A7pLLKFnVI46k6oPehrYAZmPQSrN1TQD1syNSMmfLR/X+sDTsOz3drvIYLzWBJIxL0JC bek2Py6UWmWuavc/q9o2wHniawB6AJ70tXrxftyREzWkIZqyq1TD3WiIuOXSK7K6coOP Zw/ro1p5Q8SUIkKAOuGboGcIJbTr+5HoSFL/ApfHzG7xZx5kasCARPpL2hhLNrGugNb2 ECf4iKhXIivEhDBDos5T83gkPqY1stnRRk7sg9/4OOuWwOp4m4kgnnujEpqnIAI3fSOp O/pQ== X-Gm-Message-State: ABUngvehJFNR/WeLu3ks79//7ua9dheco5g41l0ui6+A9QocHnTjzANZNr7CC5/r9E/hPRbe X-Received: by 10.98.0.198 with SMTP id 189mr29630804pfa.75.1478286961482; Fri, 04 Nov 2016 12:16:01 -0700 (PDT) Received: from ikalvarado.sea.corp.google.com ([172.31.88.94]) by smtp.gmail.com with ESMTPSA id 70sm22146856pfc.50.2016.11.04.12.16.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Nov 2016 12:16:00 -0700 (PDT) From: Ignacio Alvarado To: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: kvm@vger.kernel.org, =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Paolo Bonzini , David Matlack , Ignacio Alvarado Subject: [PATCH v2] KVM: Disable irq while unregistering user notifier Date: Fri, 4 Nov 2016 12:15:55 -0700 Message-Id: <1478286955-108360-1-git-send-email-ikalvarado@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Function user_notifier_unregister should be called only once for each registered user notifier. Function kvm_arch_hardware_disable can be executed from an IPI context which could cause a race condition with a VCPU returning to user mode and attempting to unregister the notifier. Signed-off-by: Ignacio Alvarado Reviewed-by: Paolo Bonzini --- Changelog since v1: - Move unregistration to the beginning of kvm_on_user_return arch/x86/kvm/x86.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index e375235..952e19d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -210,7 +210,18 @@ static void kvm_on_user_return(struct user_return_notifier *urn) struct kvm_shared_msrs *locals = container_of(urn, struct kvm_shared_msrs, urn); struct kvm_shared_msr_values *values; + unsigned long flags; + /* + * Disabling irqs at this point since the following code could be + * interrupted and executed through kvm_arch_hardware_disable() + */ + local_irq_save(flags); + if (locals->registered) { + locals->registered = false; + user_return_notifier_unregister(urn); + } + local_irq_restore(flags); for (slot = 0; slot < shared_msrs_global.nr; ++slot) { values = &locals->values[slot]; if (values->host != values->curr) { @@ -218,8 +229,6 @@ static void kvm_on_user_return(struct user_return_notifier *urn) values->curr = values->host; } } - locals->registered = false; - user_return_notifier_unregister(urn); } static void shared_msr_update(unsigned slot, u32 msr)