From patchwork Wed Nov 30 23:09:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13060715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3F38EC4321E for ; Wed, 30 Nov 2022 23:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=WYOUFQMv7DlLNxK7HMuXYc6abEBa222EwWJIu+OU8ik=; b=jXHiiIoAFduW1C xwYeM+SFIINd9lOQAfvFH2car2dDnoPcA1i0PUWE3Xexv9VCGQ5DNu5NYlNWtpLw6zEKEHRtlajNV WvGfSRxMNVZD6ionK6uk2wrxmPmpv+7uB27/wKAq2vMyqamgXyVAROIuXUJr9us3cLKd00nujzvBd QKQpQmtnFCxrVnV+kVme0xhi5JRPMO1x5oQ1ME/FC6Ow+t5dcS3H7Yr8h91eUOqVJRPBuuQS31GIg 5QYaTLpSQ0KwelNYMtaHkDW3+D5QoMbf5YAxxmW+3DDoADW/8BzaHbxXF9PWPn+j6fU+8Yg2+5gil ufSKji9G4mnafrJmm0lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0Wbi-003Gyf-4b; Wed, 30 Nov 2022 23:35:14 +0000 Received: from mail-vs1-xe49.google.com ([2607:f8b0:4864:20::e49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p0WLG-003AEx-Jt for linux-riscv@lists.infradead.org; Wed, 30 Nov 2022 23:18:15 +0000 Received: by mail-vs1-xe49.google.com with SMTP id j8-20020a67ef08000000b003b08119d0bfso7097017vsr.18 for ; Wed, 30 Nov 2022 15:18:13 -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=4uP8kCoK/gOIj6RU92t2NY5G3hEXAaJV/q+FUFmZ3X9INlRDcJ9qGir+BUSzsk4kti M33iWgr28ucjtOz2OvWioJvJKcl7tP2y+UQWxhSM20lihEBdelOwx9Me/I36tKpLena+ r0wgjs8CaRT81L6tFMiU1mCaSGB2IB0+sH/qc300mqFornLJhBQJA5WASyTy1+o1BSKI gWbMzVF+IrqrQzX//1Le2/s7fzjget3Ukc2ecP0FYQgUrDKDl8MY6n48RMxZybRYNusH Ms56AT7xH+4m1eJQOgbkDR7xc7rifNZd03uGuepqL+G7hdn30m6OP8fHpwiQetsvFh2u 2aHQ== X-Gm-Message-State: ANoB5pnXJr+Eb4ho36xRrX/1VAUfAvVaOffx0oQx1pyOBn4B6lPcGagw hkjq0t63dEUKu/B4ny4ixc6O+bi/XeQ= X-Google-Smtp-Source: AA0mqf4tYdOmumtBwzOsj2b757evhXiqjnmJBxVweHABwP7YhX6XXp+28OecLtWsiEbLYyMEiAceUWRYidE= 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) 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_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= " , Fabiano Rosas , Michael Ellerman , Kai Huang , Chao Gao , Thomas Gleixner X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221130_151814_677811_85B8CC56 X-CRM114-Status: GOOD ( 11.54 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Sean Christopherson Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.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;