From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BBB2A37B71 for ; Tue, 6 Jun 2023 14:29:18 +0000 (UTC) Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-569ca440bf0so26377697b3.3 for ; Tue, 06 Jun 2023 07:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686061757; x=1688653757; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Mrmslx87A+AZGfHGJkL0tEHV/zprTybhJszuOn39+0U=; b=UPqTBByhBMUtPGT9UfJhbHwP88I/lwRPfVkLFjZ4pMiAJ3eAnWGbLNiOA07VUWHtEf Q26Yn+yHleID76NwX7JbREPS9S+YFy11RdrjEIbl/g32K49RZbVacl8pnxDld+c0dglB Q3TS33PiiXpcrELcOAvuMcCJRviH2e0XPhaIJxPDY+1nCVhVYl4RgpJOemKcxMgLIAUC BelYAfKJjVywy49mPXc7oKz+slBIruOfNCNJsMcV+vFOM4x/iMddFj50JZykpMJIa+Uo HAwJV/HQRwh/US8AFYSBxwOYY1aF4D5xwXBs9zpBkAtPqdFWtErKftUw5Gi4TN36RVa4 MfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686061757; x=1688653757; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Mrmslx87A+AZGfHGJkL0tEHV/zprTybhJszuOn39+0U=; b=BKnrb//QlZJwrCMCtFSa6oNuCByiw85UcmvN2YMVjFEZXxvBAbgOIfyR4QF/IPQmz7 iWXV4ZYtqdPfTvrscqOD1Jofs7SN/JnVQMs2grQNwfwLU4oB0riaPWJCgVdQfhOsTA8K MEtFySH5cp7g9fth8wRk+grTRvsh0pryKWWNtyQ3rlOX73w/kpVT6llzmxFoBBZwxTT0 u2sRpOBATvQHMZ+A5yFvif2NBzQIXNEY/CPFyxtVsZO/9L13DuSWsf8KZOUhnSjUAXj9 C0tyGyGz8/3foyh4tABCT0+zVXXzMU62i8gyw6C3x1SyGTL54lkhNtvCYmyGmMq29LZs Yd9w== X-Gm-Message-State: AC+VfDxB2IBsH2DgXlfq7ttfsVzQAgiQEk9u221IX6Add7cIhxqzP6OZ aOUa+rESnZI35NLekWR/5AT1HW6DfbM= X-Google-Smtp-Source: ACHHUZ4Cl9QaCN+iZoQhs5r7QH5SzDjvwgOS9YmErQUF6o30gzflB1KRF/zhyfkgFYKWnwOFMO+gxRQzMsM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ec4c:0:b0:560:c30c:75f7 with SMTP id r12-20020a0dec4c000000b00560c30c75f7mr1162947ywn.2.1686061757665; Tue, 06 Jun 2023 07:29:17 -0700 (PDT) Date: Tue, 6 Jun 2023 07:29:16 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <2f16f83e-ed60-fcb7-7f3d-0fa216c41cb9@redhat.com> Message-ID: Subject: Re: [PATCH] KVM: arm64: Fix smp_processor_id() call in preemptible context From: Sean Christopherson To: Oliver Upton Cc: Sebastian Ott , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Marc Zyngier Content-Type: text/plain; charset="us-ascii" On Tue, Jun 06, 2023, Oliver Upton wrote: > The call from a preemptible context is intentional, so this really > should just be raw_smp_processor_id(). Do you mind if we fix it with the > following? ... > Nonetheless, there's no functional requirement for disabling preemption, > as the cpu # is only used to walk the arm_pmus list. Fix it by using > raw_smp_processor_id() instead. As a partial outsider, that needs an explanation, and the code could really use a comment. I assume KVM's ABI is that it's userspace's responsibility to ensure that the CPU(s) used for KVM_RUN is compatible with the CPU used for KVM_ARM_VCPU_PMU_V3_CTRL, but neither the original changelog nor the above state that, nor does anything explain what happens if userspace doesn't uphold its side of things. That stuff might be covered in documentation somewhere, but for someone just looking at git blame, this is all very magical. > Fixes: 1c913a1c35aa ("KVM: arm64: Iterate arm_pmus list to probe for default PMU") > Reported-by: Sebastian Ott > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/pmu-emul.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index 491ca7eb2a4c..933a6331168b 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -700,7 +700,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) > > mutex_lock(&arm_pmus_lock); > > - cpu = smp_processor_id(); > + cpu = raw_smp_processor_id(); > list_for_each_entry(entry, &arm_pmus, entry) { > tmp = entry->arm_pmu; > > > base-commit: 9561de3a55bed6bdd44a12820ba81ec416e705a7 > -- > 2.41.0.rc0.172.g3f132b7071-goog > 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 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 352C9C7EE24 for ; Tue, 6 Jun 2023 14:29:47 +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: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:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HWO3yuDhDZX5ODLi/nF1wmSBkEBGDQwNWKWOBu176ZM=; b=mfvj4kX/cpxne7A2RmfHKLtC0S NZ2q/JbBvGztnP/QTH6NAcrMAvGjMkjU61fVze5rqx8F8P3Dcg1gKnVYKou5Y6EE7oQMj7qcPuezE oQrCrtwecvaSa94abuKk6TLBOBSnHdNNB/nxNOR9YVA4YlODOnXdCwbk4CvUBS7tA1VA27YsZs71E ec+8C8yhiEJmsSaag5KVIhl/ahTcBzykShWh4AOcItg/wjVaKt0N7NgbxiSEIfxCnOSs+XELG73oM d6Ep3po6NymkfdMIDGpZNx9dy0kR5Q7q5ZrGj/S3YSieOzJrTq8daQuMEYfIKpFXV6qVfiJyYUZrE Tb1fGtaQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q6XgX-0021Eu-2i; Tue, 06 Jun 2023 14:29:21 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q6XgV-0021EK-0a for linux-arm-kernel@lists.infradead.org; Tue, 06 Jun 2023 14:29:20 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-56942667393so77143007b3.2 for ; Tue, 06 Jun 2023 07:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1686061757; x=1688653757; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Mrmslx87A+AZGfHGJkL0tEHV/zprTybhJszuOn39+0U=; b=UPqTBByhBMUtPGT9UfJhbHwP88I/lwRPfVkLFjZ4pMiAJ3eAnWGbLNiOA07VUWHtEf Q26Yn+yHleID76NwX7JbREPS9S+YFy11RdrjEIbl/g32K49RZbVacl8pnxDld+c0dglB Q3TS33PiiXpcrELcOAvuMcCJRviH2e0XPhaIJxPDY+1nCVhVYl4RgpJOemKcxMgLIAUC BelYAfKJjVywy49mPXc7oKz+slBIruOfNCNJsMcV+vFOM4x/iMddFj50JZykpMJIa+Uo HAwJV/HQRwh/US8AFYSBxwOYY1aF4D5xwXBs9zpBkAtPqdFWtErKftUw5Gi4TN36RVa4 MfpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686061757; x=1688653757; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Mrmslx87A+AZGfHGJkL0tEHV/zprTybhJszuOn39+0U=; b=HMs8KpFPLHGEjUs4Li8X9GU5+FafeEMXIA9JWw2CTk/vwZR7QLBgcNgbtGFnSG+vu+ KWMytUmLhKwqkiqDlNP8M5d237NlrXoWCN4PAnyGHpjfTya8uFDxYKKmip0AvCqyY5tW 8uN8gkahMza+GS5Fx6CyUNtQrSDyckomu40Yvy1WzyMTDuYvqMyBB6JhFhiQcRGrGmHu M93flXmIb51NLC474D9dJdgNobwKglokkyH0fXhEFtZdikKkKEdS0lI5gfulSQZQgCSu INkTOG5OGQsfcG+U4A+fVIYgOI7qFdm97U/9JEP0Cs/lF2DHEAjcrq3eSVasG06zPxpY hwgg== X-Gm-Message-State: AC+VfDxRfJGdWnl7RcIcAvxOVBuhaFf86JH/wYwaoEqj9mJhRR4d0grl jpuWvg/jjgKWsyj8v09fy45PwRZwBzI= X-Google-Smtp-Source: ACHHUZ4Cl9QaCN+iZoQhs5r7QH5SzDjvwgOS9YmErQUF6o30gzflB1KRF/zhyfkgFYKWnwOFMO+gxRQzMsM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a0d:ec4c:0:b0:560:c30c:75f7 with SMTP id r12-20020a0dec4c000000b00560c30c75f7mr1162947ywn.2.1686061757665; Tue, 06 Jun 2023 07:29:17 -0700 (PDT) Date: Tue, 6 Jun 2023 07:29:16 -0700 In-Reply-To: Mime-Version: 1.0 References: <2f16f83e-ed60-fcb7-7f3d-0fa216c41cb9@redhat.com> Message-ID: Subject: Re: [PATCH] KVM: arm64: Fix smp_processor_id() call in preemptible context From: Sean Christopherson To: Oliver Upton Cc: Sebastian Ott , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Marc Zyngier X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230606_072919_220874_2946D864 X-CRM114-Status: GOOD ( 22.57 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 06, 2023, Oliver Upton wrote: > The call from a preemptible context is intentional, so this really > should just be raw_smp_processor_id(). Do you mind if we fix it with the > following? ... > Nonetheless, there's no functional requirement for disabling preemption, > as the cpu # is only used to walk the arm_pmus list. Fix it by using > raw_smp_processor_id() instead. As a partial outsider, that needs an explanation, and the code could really use a comment. I assume KVM's ABI is that it's userspace's responsibility to ensure that the CPU(s) used for KVM_RUN is compatible with the CPU used for KVM_ARM_VCPU_PMU_V3_CTRL, but neither the original changelog nor the above state that, nor does anything explain what happens if userspace doesn't uphold its side of things. That stuff might be covered in documentation somewhere, but for someone just looking at git blame, this is all very magical. > Fixes: 1c913a1c35aa ("KVM: arm64: Iterate arm_pmus list to probe for default PMU") > Reported-by: Sebastian Ott > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/pmu-emul.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/pmu-emul.c b/arch/arm64/kvm/pmu-emul.c > index 491ca7eb2a4c..933a6331168b 100644 > --- a/arch/arm64/kvm/pmu-emul.c > +++ b/arch/arm64/kvm/pmu-emul.c > @@ -700,7 +700,7 @@ static struct arm_pmu *kvm_pmu_probe_armpmu(void) > > mutex_lock(&arm_pmus_lock); > > - cpu = smp_processor_id(); > + cpu = raw_smp_processor_id(); > list_for_each_entry(entry, &arm_pmus, entry) { > tmp = entry->arm_pmu; > > > base-commit: 9561de3a55bed6bdd44a12820ba81ec416e705a7 > -- > 2.41.0.rc0.172.g3f132b7071-goog > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel