From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 980D3C31E46 for ; Wed, 12 Jun 2019 10:17:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77FE4208C4 for ; Wed, 12 Jun 2019 10:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726857AbfFLKR3 (ORCPT ); Wed, 12 Jun 2019 06:17:29 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46011 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727118AbfFLKR2 (ORCPT ); Wed, 12 Jun 2019 06:17:28 -0400 Received: by mail-wr1-f66.google.com with SMTP id f9so16221929wre.12 for ; Wed, 12 Jun 2019 03:17:27 -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:content-transfer-encoding; bh=Kv7LCbEgp/ES7E3A9FpL8uznQf+7YZrzEljrXGATpdE=; b=GHquyGTjKR+8zNxh3jB4tJicitImJ2GfZrjyOAT63D+FnfmZErxUA6Ulo78OFPpocx tEZBpSZCkWq7rYlu0hZkqZxhgF+HNz2tpR3Z4B2DlvWHeaecu1oTu0dR2J77NYKOoR2t y2hrXSymeP8h/modSZbFThZnG/whCVZuHDDOiPFCTKSom4lxGzXj6K+JG9l1//7uzpXF NA/K823s3vlhGL/Rm/JG0f1GTFYclNULxXbXWBPWKKrHH68uU6Y9407WXnBolIt0ttsP Jh2gg3lMjWK/BLYvHO6ySo5Ab7FayQ6N5l2b0d+uPPM67Dn2uK11kpOqdfnM62KYrF7u GcVA== X-Gm-Message-State: APjAAAXJMx8PpHl5PIHoASxPY7REr+5U6923n5kWffI9WN317ynm6T/+ x5TqcCartpTldDqNEa8VkOGIAA== X-Google-Smtp-Source: APXvYqxzPAQxgfE805E8ecOhU0d3jxt3B5r61pAm0pxDc2tqk8vXILX/wSNAPsyKIcVAa7zcSi3nnw== X-Received: by 2002:adf:e841:: with SMTP id d1mr54673237wrn.204.1560334646423; Wed, 12 Jun 2019 03:17:26 -0700 (PDT) Received: from vitty.brq.redhat.com (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id 32sm39077824wra.35.2019.06.12.03.17.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 12 Jun 2019 03:17:25 -0700 (PDT) From: Vitaly Kuznetsov To: Dmitry Safonov , linux-kernel@vger.kernel.org Cc: Prasanna Panchamukhi , Andy Lutomirski , Borislav Petkov , Cathy Avery , Haiyang Zhang , "H. Peter Anvin" , Ingo Molnar , "K. Y. Srinivasan" , "Michael Kelley \(EOSG\)" , Mohammed Gamal , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Roman Kagan , Sasha Levin , Stephen Hemminger , Thomas Gleixner , devel@linuxdriverproject.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, x86@kernel.org Subject: Re: [PATCH] x86/hyperv: Disable preemption while setting reenlightenment vector In-Reply-To: <20190611212003.26382-1-dima@arista.com> References: <20190611212003.26382-1-dima@arista.com> Date: Wed, 12 Jun 2019 12:17:24 +0200 Message-ID: <8736kff6q3.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-hyperv-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hyperv@vger.kernel.org Dmitry Safonov writes: > KVM support may be compiled as dynamic module, which triggers the > following splat on modprobe: > > KVM: vmx: using Hyper-V Enlightened VMCS > BUG: using smp_processor_id() in preemptible [00000000] code: modprobe/466 caller is debug_smp_processor_id+0x17/0x19 > CPU: 0 PID: 466 Comm: modprobe Kdump: loaded Not tainted 4.19.43 #1 > Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS 090007 06/02/2017 > Call Trace: > dump_stack+0x61/0x7e > check_preemption_disabled+0xd4/0xe6 > debug_smp_processor_id+0x17/0x19 > set_hv_tscchange_cb+0x1b/0x89 > kvm_arch_init+0x14a/0x163 [kvm] > kvm_init+0x30/0x259 [kvm] > vmx_init+0xed/0x3db [kvm_intel] > do_one_initcall+0x89/0x1bc > do_init_module+0x5f/0x207 > load_module+0x1b34/0x209b > __ia32_sys_init_module+0x17/0x19 > do_fast_syscall_32+0x121/0x1fa > entry_SYSENTER_compat+0x7f/0x91 Hm, I never noticed this one, you probably need something like CONFIG_PREEMPT enabled so see it. > > The easiest solution seems to be disabling preemption while setting up > reenlightment MSRs. While at it, fix hv_cpu_*() callbacks. > > Fixes: 93286261de1b4 ("x86/hyperv: Reenlightenment notifications > support") > > Cc: Andy Lutomirski > Cc: Borislav Petkov > Cc: Cathy Avery > Cc: Haiyang Zhang > Cc: "H. Peter Anvin" > Cc: Ingo Molnar > Cc: "K. Y. Srinivasan" > Cc: "Michael Kelley (EOSG)" > Cc: Mohammed Gamal > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Roman Kagan > Cc: Sasha Levin > Cc: Stephen Hemminger > Cc: Thomas Gleixner > Cc: Vitaly Kuznetsov > > Cc: devel@linuxdriverproject.org > Cc: kvm@vger.kernel.org > Cc: linux-hyperv@vger.kernel.org > Cc: x86@kernel.org > Reported-by: Prasanna Panchamukhi > Signed-off-by: Dmitry Safonov > --- > arch/x86/hyperv/hv_init.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c > index 1608050e9df9..0bdd79ecbff8 100644 > --- a/arch/x86/hyperv/hv_init.c > +++ b/arch/x86/hyperv/hv_init.c > @@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(hv_max_vp_index); > static int hv_cpu_init(unsigned int cpu) > { > u64 msr_vp_index; > - struct hv_vp_assist_page **hvp = &hv_vp_assist_page[smp_processor_id()]; > + struct hv_vp_assist_page **hvp = &hv_vp_assist_page[cpu]; > void **input_arg; > struct page *pg; > > @@ -103,7 +103,7 @@ static int hv_cpu_init(unsigned int cpu) > > hv_get_vp_index(msr_vp_index); > > - hv_vp_index[smp_processor_id()] = msr_vp_index; > + hv_vp_index[cpu] = msr_vp_index; > > if (msr_vp_index > hv_max_vp_index) > hv_max_vp_index = msr_vp_index; The above is unrelated cleanup (as cpu == smp_processor_id() for CPUHP_AP_ONLINE_DYN callbacks), right? As I'm pretty sure these can'd be preempted. > @@ -182,7 +182,6 @@ void set_hv_tscchange_cb(void (*cb)(void)) > struct hv_reenlightenment_control re_ctrl = { > .vector = HYPERV_REENLIGHTENMENT_VECTOR, > .enabled = 1, > - .target_vp = hv_vp_index[smp_processor_id()] > }; > struct hv_tsc_emulation_control emu_ctrl = {.enabled = 1}; > > @@ -196,7 +195,11 @@ void set_hv_tscchange_cb(void (*cb)(void)) > /* Make sure callback is registered before we write to MSRs */ > wmb(); > > + preempt_disable(); > + re_ctrl.target_vp = hv_vp_index[smp_processor_id()]; > wrmsrl(HV_X64_MSR_REENLIGHTENMENT_CONTROL, *((u64 *)&re_ctrl)); > + preempt_enable(); > + My personal preference would be to do something like int cpu = get_cpu(); ... set things up ... put_cpu(); instead, there are no long-running things in the whole function. But what you've done should work too, so Reviewed-by: Vitaly Kuznetsov > wrmsrl(HV_X64_MSR_TSC_EMULATION_CONTROL, *((u64 *)&emu_ctrl)); > } > EXPORT_SYMBOL_GPL(set_hv_tscchange_cb); -- Vitaly