Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp3273554lqo; Wed, 15 May 2024 05:12:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVR5PNabHw6lm8fuYB6S+LQzfAWB2JLHmRuJOaKVxA0zx1WroEEHRu3fSDWjaawcBJODreF0aVL7nPa7kYSHxREcB5fa21fV0/UHv53VA== X-Google-Smtp-Source: AGHT+IHooxxKT+tVZ2rReyKhuuiFF+NaOE1KlsjE4RQiC1qRvcCWveye9i18zZgJ4nWpWRBy9k+k X-Received: by 2002:a05:6830:45:b0:6f0:e557:5160 with SMTP id 46e09a7af769-6f0e9148dc9mr18468334a34.17.1715775134664; Wed, 15 May 2024 05:12:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715775134; cv=pass; d=google.com; s=arc-20160816; b=Tmzej7kTDU5aZFFZHoCu97AwXLDEvps6d/wHjHDLoXsw09uP2vAxH/UVleyC38T/J9 CWgFK8oExX/J6MEmV2bB/l7lbYO6kI4NQ+Rid8cia5uzAaTs5kUs4amWiDjhj9mSngfY yaaohD5avBqK06h1VzQL2l1AoX9AKZcCRKvqPDmmmZFw0AnlE8cLGlVPwALkBIAYJzoJ 3XJjmMG8QkvqhUMvSbyhyhwMQE5hb+q8oouhz/DBAW8dzO542QiehjeMzzTiJaF9eVva 33Nr+PqyR7cZROPUeyFFHQvKkQQpAurA9fYWjLf7X5sR4tMnD17GzzQoYC5VgWo2/UTh umNA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=72QZOpdo96lmoRKXORKqVHqLcvGZpjrAbq+YO9YrStM=; fh=op5BfTenrJ3tvGfEFadurSlKnY2zl1dziDqKnx4E7+w=; b=EKj0jUaZ/rtkYgZiEsWFEHl9j2BE3FOm88/vTwHFCD2ANui/4AT0KMZjxE0biG9vu2 iDnT44+z9GvwKG9V8Ze1XfLaVFPl4YoabG1UUH8EUwNSUjtMhTK0zN3grfXDxZWJn3vZ QfTH2cL+9HPyeijmcrKAew4+/yMhGiBq12qH4ZQFHtE6boDCrzR/syB/SLYNqDpE7bDd /4cFX5zsdFgImoeJqs3PnTdEWrNq969DCpj53oKe6kI5AFUo4/vWGgAX8D80MWdhUxL9 msE4gBGZ2n2TdzpmgflMRgggDt6+mvBEoKZldcUYry+E2i9UPVfLpcbqcTOkQynAKzx1 Zpfw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-179836-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179836-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 71dfb90a1353d-4df7bf82d0bsi2042422e0c.105.2024.05.15.05.12.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 05:12:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-179836-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-179836-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-179836-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id D13951C21D90 for ; Wed, 15 May 2024 12:12:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 405147441E; Wed, 15 May 2024 12:12:08 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 87E506A005 for ; Wed, 15 May 2024 12:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775127; cv=none; b=WM055ki9x4Eo8KYKwNpApEhPMPSrA/Nc8JfyeX6pDFbpMd4eba95DhENA+ae3AvyUhav+Tngh7LPoEjMuBRAMLXej5AJlX+68d/14761thp+swsND1UekIc4ksAM1umngyNfH0AZo/Tmi+UD36YSY1tF/HBfI/vME4f7NhZk7eg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715775127; c=relaxed/simple; bh=7GmX9sSAglcsdgg1nnDNLqsskVmSveiPobBelaVNMeY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=FivVrl/h8u5Lzkvqycg/P3y9e4QM0l7gHI7tdJTNuVvLUhjxQBi1r+8rO8a0A1kfRl+YyNywJqU+nr1S6xQssVHnrNNPQ4C9/K+ejbaQf3zshLqZVNV7by8IPq4cyktxIosg2koqHLnhzsc6LTnCWGUUfKjogVtI57WgOl4xIqk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 374C41042; Wed, 15 May 2024 05:12:29 -0700 (PDT) Received: from [10.57.5.6] (unknown [10.57.5.6]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E2CC23F641; Wed, 15 May 2024 05:12:02 -0700 (PDT) Message-ID: <0a454227-ab99-4eb9-a736-1c826cfeb97d@arm.com> Date: Wed, 15 May 2024 13:12:02 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] perf/arm-dmc620: Fix lockdep assert in ->event_init() To: Namhyung Kim , Will Deacon , Mark Rutland Cc: Ingo Molnar , Peter Zijlstra , LKML , linux-arm-kernel@lists.infradead.org, Greg Thelen , Tuan Phan References: <20240514180050.182454-1-namhyung@kernel.org> From: Robin Murphy Content-Language: en-GB In-Reply-To: <20240514180050.182454-1-namhyung@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024-05-14 7:00 pm, Namhyung Kim wrote: > for_each_sibling_event() checks leader's ctx but it doesn't have the ctx > yet if it's the leader. Like in perf_event_validate_size(), we should > skip checking siblings in that case. Ugh, looking around for_each_sibling_event() sites, it looks like there are a fair few other drivers using this pattern as well :( I'd love for groups to be less horribly complicated, but I think I can follow the underlying reasoning here. I suppose one could argue that the assertion could take into account that there's nothing to protect in the case where event->ctx is still NULL, since nobody else should be able to touch the event's own empty sibling list at this point before perf_event_open() has even returned. However by the same token there's also no real reason for drivers *not* to return early when they equally can tell that the sibling list must be empty, and indeed that seems to be a fairly common pattern too, so I see no issue with fixing up all the offending drivers for consistency either. Reviewed-by: Robin Murphy > Fixes: f3c0eba287049 ("perf: Add a few assertions") > Reported-by: Greg Thelen > Cc: Robin Murphy > Cc: Tuan Phan > Signed-off-by: Namhyung Kim > --- > drivers/perf/arm_dmc620_pmu.c | 9 ++++++--- > 1 file changed, 6 insertions(+), 3 deletions(-) > > diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c > index 8a81be2dd5ec..88c17c1d6d49 100644 > --- a/drivers/perf/arm_dmc620_pmu.c > +++ b/drivers/perf/arm_dmc620_pmu.c > @@ -542,12 +542,16 @@ static int dmc620_pmu_event_init(struct perf_event *event) > if (event->cpu < 0) > return -EINVAL; > > + hwc->idx = -1; > + > + if (event->group_leader == event) > + return 0; > + > /* > * We can't atomically disable all HW counters so only one event allowed, > * although software events are acceptable. > */ > - if (event->group_leader != event && > - !is_software_event(event->group_leader)) > + if (!is_software_event(event->group_leader)) > return -EINVAL; > > for_each_sibling_event(sibling, event->group_leader) { > @@ -556,7 +560,6 @@ static int dmc620_pmu_event_init(struct perf_event *event) > return -EINVAL; > } > > - hwc->idx = -1; > return 0; > } >