Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3127498rwb; Wed, 30 Nov 2022 16:00:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Bre418Dtny9SrtFKv9AM+OLb4AuEl8nOkyYjRrpWi3v+JWhbHlv4gIwjE8xNLYqNWIhdZ X-Received: by 2002:aa7:d85a:0:b0:46b:81a8:1ff6 with SMTP id f26-20020aa7d85a000000b0046b81a81ff6mr8919645eds.174.1669852857204; Wed, 30 Nov 2022 16:00:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669852857; cv=none; d=google.com; s=arc-20160816; b=kpsqYHEnupjmHuzj5FElcv32Dxsn4vlg3YnJE2tOrPudsfxmp2p65ZTFe89f9ViYMo IxFcnvKc23dBiR6GMKv8O/QmufSBw3S+ueHhhK2rw1Zv9ep1kfHaK0kX/rOeB8Ru2gHn VHYeX8R92TfZONrmD34qeoSrKVu6A6AaFcJ/QB1+AkiEhi0UypLIXmym76nvwOHD2Gzi 16bM44Z6s4gAUdcX+zznodwLSGXZdqKdsAAaI6hjYCDs6dhZvwIgQggjkfigPbUBcw5P dfivox1of1bmRNxemLG0ENMiSvwj6kbATyYWm8zqB7dEe1PKquXp5TKpTWWhNT1jrdLY JSNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=X0tmq9TjsMbdzf016NYPEZWLDrtJgEerkZwlPByjvHs=; b=mF0Y4tXQvwDLuPCIh0xjLY51Gy86QUZiaW1M3xgLTQcdkXfQgSr9ndgFpzgYA6Jmw5 S7Al+4Rzx992I47G//Y0Da5kmzKQzSWsZdOyyDF2DK79SCnqZoaf4oCRrIpyI8PB47O2 3CW7b02MXONzE2eetilufnlPZOTQ6fMZrJexW98/cAXQJNFwvhIROCJjbASLLk1DfjNK XDS+fe42nQmBs5mcj+uvGeaqUQCCG0r+fvVq+Ffv5f85hulsKUyrNGR6mwm+rlnHBbLP LZebGrtLwzzcHy/XnZ2beN890ThFouY8TaTW075ex2ue1gOdFAZ/wluAOcprU+EqDnwB uggA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ffiAil8t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a056402354b00b00462e7873c10si2458901edd.337.2022.11.30.16.00.36; Wed, 30 Nov 2022 16:00:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ffiAil8t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230046AbiK3XQj (ORCPT + 83 others); Wed, 30 Nov 2022 18:16:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiK3XQD (ORCPT ); Wed, 30 Nov 2022 18:16:03 -0500 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D6ABA320F for ; Wed, 30 Nov 2022 15:11:26 -0800 (PST) Received: by mail-pg1-x549.google.com with SMTP id 38-20020a630b26000000b004773803dda1so64074pgl.17 for ; Wed, 30 Nov 2022 15:11:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=X0tmq9TjsMbdzf016NYPEZWLDrtJgEerkZwlPByjvHs=; b=ffiAil8tYfi3nQXQblraVPD6jbdbOOCVG7uQkkKJrYkDL25R/TkQAeFRDogqa/QMMv 6wZOWt9R/eeSPWTlpWV3IYmrtl04WJOPJAhS7DhGuKTgLTJnehBcyBsLWlgRsCVFi/Ix ksxZjkBOqqqo9hOr9qKhrYgS8WLlfTE4UM6Vkkhhf880kZVvVEdvLhl4X0FaFYBb/6vC 1lACz1AHExA2AbJQILx7vCyuTDoL44EAFEV/X6CifJwvfMkGg0ai47n8Yg94c4IO+cHQ jlRTeSXfVKpq0j3GPFNIBJZpOCvznvIZyM5DfqXmXJnRlhyCma48IFWCHmjS0A3NCAbs hdMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X0tmq9TjsMbdzf016NYPEZWLDrtJgEerkZwlPByjvHs=; b=NaWc25oH8btg9akjfJEWPW5ic+2qoQiiSiIYiOtsePmjRswniuvfhHXmpTXzyFF6mN xn9K2Ut1JuaAp3YC27B3l4d5An+dH5NtsznvVr9OyrJT4Ftd868q25uZ+Qkb2mHc/3Po VmkrRgEn1Zj93zRUzNiUnsqdf7imtGTW+p1hPb7duw+GNDSc5hahzAtj9O2/8tff8a3p TWrWkdHggnl358CD7fB6IP8C4r8qS3qtM8ipmj+ymbEb2YiDgq8fYNtJWmHSlFm8UGTs Mj2u/I0zfiJsLRmxtn8OPrntasJJ4ntgJdO001cV7MGNXrGGTODknRGAqGPjWb//MhDG gaDQ== X-Gm-Message-State: ANoB5pmBLnNGWx49XMK//gqEwYBe9bmVdgTTut1RQRul5krTq+7IdT5z 6Wq7kwTobP6+aogGkZ3FWf/ygKcF9G8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:aa7:8487:0:b0:56c:3bb4:28a8 with SMTP id u7-20020aa78487000000b0056c3bb428a8mr44633084pfn.83.1669849852226; Wed, 30 Nov 2022 15:10:52 -0800 (PST) Reply-To: Sean Christopherson Date: Wed, 30 Nov 2022 23:09:27 +0000 In-Reply-To: <20221130230934.1014142-1-seanjc@google.com> Mime-Version: 1.0 References: <20221130230934.1014142-1-seanjc@google.com> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog Message-ID: <20221130230934.1014142-44-seanjc@google.com> Subject: [PATCH v2 43/50] KVM: Ensure CPU is stable during low level hardware enable/disable From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Matthew Rosato , Eric Farman , Sean Christopherson , Vitaly Kuznetsov , David Woodhouse , Paul Durrant Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Atish Patra , David Hildenbrand , kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Yuan Yao , Cornelia Huck , Isaku Yamahata , "=?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?=" , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use the non-raw smp_processor_id() in the low hardware enable/disable helpers as KVM absolutely relies on the CPU being stable, e.g. KVM would end up with incorrect state if the task were migrated between accessing cpus_hardware_enabled and actually enabling/disabling hardware. Signed-off-by: Sean Christopherson --- virt/kvm/kvm_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index d985b24c423b..a46d61e9c053 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -5028,7 +5028,7 @@ static struct miscdevice kvm_dev = { static void hardware_enable_nolock(void *junk) { - int cpu = raw_smp_processor_id(); + int cpu = smp_processor_id(); int r; if (cpumask_test_cpu(cpu, cpus_hardware_enabled)) @@ -5070,7 +5070,7 @@ static int kvm_online_cpu(unsigned int cpu) static void hardware_disable_nolock(void *junk) { - int cpu = raw_smp_processor_id(); + int cpu = smp_processor_id(); if (!cpumask_test_cpu(cpu, cpus_hardware_enabled)) return; -- 2.38.1.584.g0f3c55d4c2-goog