Received: by 10.213.65.68 with SMTP id h4csp260914imn; Sat, 24 Mar 2018 21:21:26 -0700 (PDT) X-Google-Smtp-Source: AG47ELuQ2bGaYYAKSA1aPL1t00+A2LUvLYgSpW0rnKdpre2MkK28zzCpDVeilq8sfZppLlCZYtpE X-Received: by 10.101.64.68 with SMTP id h4mr7073473pgp.76.1521951686924; Sat, 24 Mar 2018 21:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521951686; cv=none; d=google.com; s=arc-20160816; b=03YAIOWvZfXcwNwSPnFtuxvNAADk9Apqb8AArUvdAZQfcoq2+3fxqpDa4hjKbVdYOb npbAXk1XwF3VcI9mMqg4gDWBX8vyuNLN0pdKDatZnXp86kHh55v40R7z0jGohSgP7r2t KR9cmLW5dFWbfs/5EfBF+fOtO/wupKMhNhGJiAIccGJ6vHXu9f+gHmFVHJLpCmj6RmzT FZQB//cUMbGg2HpDqBs3WGP7hR+YjR1kDDUFuzXSfL4a1jabfv521CzIX7wegehHYqU0 1K/S8fWJ+JTIZcmxLbyQvuHbJAA1Rp+pIWbmxbYUiF6Fl9Qv64UJVnCmvZfwzYqsxrbG 5aJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=rDDNJ66QHFiT9F1+TIR8zTsirR5MrCJ/0YdJGoNGer8=; b=Z8qLYo8qAhKRijs4D4oyqA0nBnvZdjdeyCj/Ns3Hpnw2lmiwghy3oQ4ixBwBjNcgSQ l7px1l2M//UWHQCZe0Y6CRbxBaQmJLn78rjaVQKaHVCXBMg6yfkaKGsydp40jzH32/lx /Vhay567gADD9e1dc+hrgxGIPrB6zdQEPvm3sHRrHjqgKRnRSPEtRsYVuUI3k9gJ9Xa6 yPonJp3jvkIMp9EpCBSDpy15vsg7FkuqX9W60mcAMSjDLlauhgqQGrk/CRzYxKJthN6r sktkJ2j72ehaXeBHxPOPvfjkbjvQWHSv3U0qBIHO43rNTWWZOM3OlF2uHqdLNhPzcz8g ylaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rAWh61UA; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l13-v6si12954090pln.437.2018.03.24.21.20.32; Sat, 24 Mar 2018 21:21:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=rAWh61UA; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751179AbeCYES2 (ORCPT + 99 others); Sun, 25 Mar 2018 00:18:28 -0400 Received: from mail-pl0-f67.google.com ([209.85.160.67]:45269 "EHLO mail-pl0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751123AbeCYES0 (ORCPT ); Sun, 25 Mar 2018 00:18:26 -0400 Received: by mail-pl0-f67.google.com with SMTP id n15-v6so9844533plp.12; Sat, 24 Mar 2018 21:18:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=rDDNJ66QHFiT9F1+TIR8zTsirR5MrCJ/0YdJGoNGer8=; b=rAWh61UAD4sSoWYZBkGJ341zIqOEuoxp9R8zHLcz17i3TgtB0eBwF1ELX+OVw/tCW2 zM+taJy58txQlpi9DULUZ+XpcC+8bJXAwpBWaRPGcLyFc9f79jOw0x4EbUD2zs7Wrjzi xKye2fpuVHv6pmRBJ4qNTwZQzic9Tvu8cPiTUyMivIf7Q/8bDOTEmlY0MfCncgdNSUVU PN/uiLWK1n6e8VJiLQD8g+oyuzheeNl481FcNQVsOIDG/0+bk7ve/TkmTqWHOd6uAaXe ok4I0f2U2veysWFSzaxJ7PujtpquKdjF6AgNNewD4MR9ynCoY8A7qpyY5D87BzoY4tWd sqEg== 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:date:message-id:mime-version :content-transfer-encoding; bh=rDDNJ66QHFiT9F1+TIR8zTsirR5MrCJ/0YdJGoNGer8=; b=Tk32fqXAcKhvo59169flKby3kI9X2qomsqqz0+OixwHJ+Ao2yRIVVrmsBiAGrdqcCO 4PbonBHI2Kw8izzjBWKujoXFT4bvDpgLaxIzSf2qe4m/WH9/BaDV2AhyiA8nY3IzQ/tK R1QCxBZz1HcV8DQNYZeGX7ZbP5jdt0ap8QQOPbwhIOK3iLtD17UHFDsIMW/Tw1DdJuy6 DbkjW3qMYl6/jwmzoitPo+Gvbjvy957hRMKBT0e1rcvXIw1YqmbRJKJ9Iu0lgqY1LuoI 6Q3s+f2DSFyfxftBC06JCwAFay6ik8g9CtGuFPUVUQgcouPQZmQslvklTcdBE7tE1XLm Oesw== X-Gm-Message-State: AElRT7EzptzKBcDLzIH0O6CMex0gXqNOM7GFHliIulmY9vLRk96OciBI GPyfo+S+S7uRj0X2Xd9LzV/CEg== X-Received: by 2002:a17:902:3e5:: with SMTP id d92-v6mr763144pld.104.1521951505976; Sat, 24 Mar 2018 21:18:25 -0700 (PDT) Received: from localhost.localdomain ([45.248.77.205]) by smtp.googlemail.com with ESMTPSA id v18sm21965515pgb.23.2018.03.24.21.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Mar 2018 21:18:25 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Davidlohr Bueso Subject: [PATCH 1/2] KVM: X86: Fix setup the virt_spin_lock_key before static key get initialized Date: Sat, 24 Mar 2018 21:17:24 -0700 Message-Id: <1521951444-5087-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li static_key_disable_cpuslocked(): static key 'virt_spin_lock_key+0x0/0x20' used before call to jump_label_init() WARNING: CPU: 0 PID: 0 at kernel/jump_label.c:161 static_key_disable_cpuslocked+0x61/0x80 RIP: 0010:static_key_disable_cpuslocked+0x61/0x80 Call Trace: static_key_disable+0x16/0x20 start_kernel+0x192/0x4b3 secondary_startup_64+0xa5/0xb0 Qspinlock will be choosed when dedicated pCPUs are available, however, the static virt_spin_lock_key is set in kvm_spinlock_init() before jump_label_init() has been called, which will result in a WARN(). This patch fixes it by delaying the virt_spin_lock_key setup to .smp_prepare_cpus(). Reported-by: Davidlohr Bueso Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Davidlohr Bueso Signed-off-by: Wanpeng Li --- Note: Peterz pointed out in the IRC we have to audit all the architectures that implement smp_prepare_boot_cpu() to see what they depend on if we want to move jump_label_init() before smp_prepare_boot_cpu(). So what this patch does is similar to the issue which handled in xen ca5d376e. arch/x86/kernel/kvm.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 4ccbff6..747c61b 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -454,6 +454,13 @@ static void __init sev_map_percpu_data(void) } #ifdef CONFIG_SMP +static void __init kvm_smp_prepare_cpus(unsigned int max_cpus) +{ + native_smp_prepare_cpus(max_cpus); + if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) + static_branch_disable(&virt_spin_lock_key); +} + static void __init kvm_smp_prepare_boot_cpu(void) { /* @@ -557,6 +564,7 @@ static void __init kvm_guest_init(void) kvm_setup_vsyscall_timeinfo(); #ifdef CONFIG_SMP + smp_ops.smp_prepare_cpus = kvm_smp_prepare_cpus; smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu; if (cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "x86/kvm:online", kvm_cpu_online, kvm_cpu_down_prepare) < 0) @@ -737,10 +745,8 @@ void __init kvm_spinlock_init(void) if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) return; - if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) { - static_branch_disable(&virt_spin_lock_key); + if (kvm_para_has_hint(KVM_HINTS_DEDICATED)) return; - } __pv_init_lock_hash(); pv_lock_ops.queued_spin_lock_slowpath = __pv_queued_spin_lock_slowpath; -- 2.7.4