From patchwork Tue Jun 6 10:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Ott X-Patchwork-Id: 13268918 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 EABD7C77B7A for ; Tue, 6 Jun 2023 10:39:32 +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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=5ywB50sZ8/oovUx+QADTSVeF0pDT3PC6kuCvjKUJfzI=; b=HU7uF6uMGd0Ewh6AVHlvRfC/+J dzvsb2tKdO3TeqUsVbOM7lH+YeVlIQr14bYiqg+beys3R6NqKeibFL8kmC32uPnTUCtrfvJYsbk2V 2BTrWoaqBLt8XU7Lna3AYHQnf5XzDtHpU7sWwY5xNdIJ0scn/GoToLIyfn0013El2uPwIvOcqmq2X jriaIo3pZMJoHlKsxw6LU+SpPPdfhQ6IT9j2ddauRZI8LeTc9lAFFhzEtBuydOZO8x1QShjOYchQl y2b2OjfKaVNXHgWzfCd9Ucmvpf3Xm0yLhInymDZ7XDrGaq/30wTXy0sCqbYa4tIqOSa9x18FtBAbB lMX2pgqA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6U5n-001GLi-1r; Tue, 06 Jun 2023 10:39:11 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6U5k-001GIL-28 for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2023 10:39:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686047946; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=4KMnL3g6L7UfqVOiJLSwGrD+RRorX7NHeH1AseOGRLI=; b=QxKB7P5/eQbzf/HQZpm4h5zPdkSS2lmjYDk4SdY4n0xOPO03c/XcuB09n+BMaJDJIGbH16 ctAOjEqnAJMhquGGuj+C1G7nyTpLUypGyN+yCDYIuIEK7cKUSq6g8XgJlQvRsgQTRGxne5 MtI2tIR+RBF/CE7Dsxqv48IwiJ+qZF4= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-ltxbhP_tMmOoNhN_eDvl7Q-1; Tue, 06 Jun 2023 06:37:35 -0400 X-MC-Unique: ltxbhP_tMmOoNhN_eDvl7Q-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-62a25948da5so40909776d6.2 for ; Tue, 06 Jun 2023 03:37:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686047855; x=1688639855; h=mime-version:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=4KMnL3g6L7UfqVOiJLSwGrD+RRorX7NHeH1AseOGRLI=; b=SnJ9A7iVsFXormzfRmTgU+QMfQ2m8eEvf3FeZBSJVCrR4pcZPLjnh5QQ/LNtNle2MV um6O4sQ8FINxQuuEny8XMqvATFWR2UX8sM5AgkhBzEEjuZui/7V9Cy6JjfzwmmyLa73S QYi6Yk9k3uYzz6OQ351NnamVTPYYIqFRCGenVyTSRUufalPmbTuOjlm0/N+cfW0Wn1jl EDwszh5VgA9slgYMRRp0Gv9fBcbEF+T1dXv+fcsNKsZeCk+hLXcydT8NAGNG87XfkpNB kyw+aqrO/3+1v6yVzbnxwvq+YOmt5wFAKcmdYTmsrBtO/lukPRL0CHmjv0H9wNODa6a7 k8OQ== X-Gm-Message-State: AC+VfDyS4AqYQqIi7tMynvW9AMDz+hycfJ4HRN8Zod/lcqR6Fhe5Th9K LNAM+Net2DNF9cr6vm4G9tLekSGGVVrgmZfxojuh80KSHb+jd2dWJjL6AvkZI92AklZawOLbcF7 8ORxazIOJeKt+RlGs482GwflvN7lnFgqvm45gXy7jsvo= X-Received: by 2002:a05:6214:ccd:b0:628:474b:aae3 with SMTP id 13-20020a0562140ccd00b00628474baae3mr2005211qvx.56.1686047855028; Tue, 06 Jun 2023 03:37:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Fnoh5EPJQcdGxF8wYBBRgI2/kwJhla0tSeyQUZqahEbjELaHGgoKcsfvZVCwLchTjXGiBRw== X-Received: by 2002:a05:6214:ccd:b0:628:474b:aae3 with SMTP id 13-20020a0562140ccd00b00628474baae3mr2005200qvx.56.1686047854769; Tue, 06 Jun 2023 03:37:34 -0700 (PDT) Received: from rh (p200300c93f2d6400aa29c1eaa0912abc.dip0.t-ipconnect.de. [2003:c9:3f2d:6400:aa29:c1ea:a091:2abc]) by smtp.gmail.com with ESMTPSA id ep12-20020a05621418ec00b0061b731bf3c2sm5244560qvb.80.2023.06.06.03.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jun 2023 03:37:34 -0700 (PDT) Date: Tue, 6 Jun 2023 12:37:30 +0200 (CEST) From: Sebastian Ott To: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org cc: Marc Zyngier , Oliver Upton Subject: [PATCH] KVM: arm64: Fix smp_processor_id() call in preemptible context Message-ID: <2f16f83e-ed60-fcb7-7f3d-0fa216c41cb9@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230606_033908_794622_BBE3CBEC X-CRM114-Status: GOOD ( 10.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Commit 1c913a1c35aa ("KVM: arm64: Iterate arm_pmus list to probe for default PMU") introduced a smp_processor_id() call in preemtible context: [70506.110187] BUG: using smp_processor_id() in preemptible [00000000] code: qemu-system-aar/3078242 [70506.119077] caller is debug_smp_processor_id+0x20/0x30 [70506.124229] CPU: 129 PID: 3078242 Comm: qemu-system-aar Tainted: G W 6.4.0-rc5 #25 [70506.133176] Hardware name: GIGABYTE R181-T92-00/MT91-FS4-00, BIOS F34 08/13/2020 [70506.140559] Call trace: [70506.142993] dump_backtrace+0xa4/0x130 [70506.146737] show_stack+0x20/0x38 [70506.150040] dump_stack_lvl+0x48/0x60 [70506.153704] dump_stack+0x18/0x28 [70506.157007] check_preemption_disabled+0xe4/0x108 [70506.161701] debug_smp_processor_id+0x20/0x30 [70506.166046] kvm_arm_pmu_v3_set_attr+0x460/0x628 [70506.170662] kvm_arm_vcpu_arch_set_attr+0x88/0xd8 [70506.175363] kvm_arch_vcpu_ioctl+0x258/0x4a8 [70506.179632] kvm_vcpu_ioctl+0x32c/0x6b8 [70506.183465] __arm64_sys_ioctl+0xb4/0x100 [70506.187467] invoke_syscall+0x78/0x108 [70506.191205] el0_svc_common.constprop.0+0x4c/0x100 [70506.195984] do_el0_svc+0x34/0x50 [70506.199287] el0_svc+0x34/0x108 [70506.202416] el0t_64_sync_handler+0xf4/0x120 [70506.206674] el0t_64_sync+0x194/0x198 Just disable preemption for this section. Fixes: 1c913a1c35aa ("KVM: arm64: Iterate arm_pmus list to probe for default PMU") Signed-off-by: Sebastian Ott Reported-by: Sebastian Ott Signed-off-by: Oliver Upton --- arch/arm64/kvm/pmu-emul.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c index 491ca7eb2a4c..f9e4e4334875 100644 --- a/arch/arm64/kvm/pmu-emul.c +++ b/arch/arm64/kvm/pmu-emul.c @@ -700,6 +700,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) mutex_lock(&arm_pmus_lock); + preempt_disable(); cpu = smp_processor_id(); list_for_each_entry(entry, &arm_pmus, entry) { tmp = entry->arm_pmu; @@ -709,7 +710,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) break; } } - + preempt_enable(); mutex_unlock(&arm_pmus_lock); return pmu;