Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp507132pxj; Fri, 11 Jun 2021 04:53:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxB/+pU7ta0FUsz2Aijs0vaezsKG3TqLaaEzZ6u23DhQ6tQV/oJmiEN/9mqgc4eof+ZywQA X-Received: by 2002:a17:906:a294:: with SMTP id i20mr3344439ejz.330.1623412384566; Fri, 11 Jun 2021 04:53:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623412384; cv=none; d=google.com; s=arc-20160816; b=MEkIXqCwDNZaXUWj+z4YJibfW74l+pMK/RrKj7kpn6zTPr4zGdqwSr76naZSH85oh9 0SxNHOxW6JQrhDODZjLJqycZFxHcbAHWXFlSFyO49E5i/1F8QIDtjn4PLY7Eqp4flEbP 2qu5clQCXUsd2Zaw5aadz1kkVELKl3HcnFDa0qYe+yCBnP8iHkIcrgm8QoQwGAUG/8rD vTqL6tDMSjW/aveq32sc+bHxHSWBvgyt0F2ZD1pLX4yKsBquXMjUwkqgIPz+03lE48i8 /sENIqOMVm/qi8u4YqwPz3Jscy13q0VP+05k2FRDryUwiQtskXcWEBN/AFp+c+LEi3CX NAeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=yAtCEL32DjGgSIxfxPxU5dWT3AR6+igTd5JCoSyHt1o=; b=OXbkGcaRYt+7vkaF0JlspSGsvqIi53LzQEFE8ZTSyDnCZH8rch8lLNZAbuPuDr85yy 6YX8NGWBzkSdaJ3MgKx6exKFSiRIlmaCS7tr0eUOgT5oWT1LI61mMn8Im5nmwSa45L2m Uox+Y/pNURH7TP5GN3bZPKx5gHjiTdYmjDZzBO49iw1OHxjjkkiLDs+SDmiawbuJdyJ/ aYLWQrqiWRg5ATaExx5+K9wOhtQlE2WO3L58HDj9ZfJA2l9rF2MdJAZDtIwrpz5UoamG 9dmirCbNZ3ZcsAwWkLsbl5SCvBc+ZzE4CpM1B5uxX3VxRjl6BXA+fpxVp/1qoh1A+0/w G8Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Y2htFAzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gy3si4684805ejb.557.2021.06.11.04.52.42; Fri, 11 Jun 2021 04:53:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Y2htFAzV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231599AbhFKLvN (ORCPT + 99 others); Fri, 11 Jun 2021 07:51:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231181AbhFKLvM (ORCPT ); Fri, 11 Jun 2021 07:51:12 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDF64C061574 for ; Fri, 11 Jun 2021 04:49:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=yAtCEL32DjGgSIxfxPxU5dWT3AR6+igTd5JCoSyHt1o=; b=Y2htFAzVHmfHPDH8NsQEyrFrjG o3CBZ6de3y7IrZzbmrX4m5wZUqbr6WBqiqD5kLoySPHAHZozBsUs79Bj1iWRQMelTyExWEGFkdH0i Z1Egf0nYHd5g8cxPf3VbNYtBIQ0eamKKfCDDchWI/YP7KGVmi0z9tzv5SfM99Q/01c+Cx4ExuNgPB E4si87PGOqal8uT88SHJhTPTrOemEcje6Hi0AKgRBiYELtojn13lBJ+dwNabQ5oe3LSMeQMaOCvwV VaOIlbwtnrnfmFtxf59GElFQkMgvY4dFQw17PcpgCbri5pVlxLkj8PFrgyuZ6T3Ohtv1LX4JvHe8N OSnX6yFQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1lrfeo-005sKq-A8; Fri, 11 Jun 2021 11:49:09 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 2E9DA300091; Fri, 11 Jun 2021 13:49:08 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 1154321AB0AD9; Fri, 11 Jun 2021 13:49:08 +0200 (CEST) Date: Fri, 11 Jun 2021 13:49:08 +0200 From: Peter Zijlstra To: Frederic Weisbecker Cc: Thomas Gleixner , LKML , "Eric W . Biederman" , Oleg Nesterov , Ingo Molnar Subject: Re: [PATCH 1/6] posix-cpu-timers: Fix rearm racing against process tick Message-ID: References: <20210604113159.26177-1-frederic@kernel.org> <20210604113159.26177-2-frederic@kernel.org> <20210609115400.GD104634@lothringen> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210609115400.GD104634@lothringen> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 09, 2021 at 01:54:00PM +0200, Frederic Weisbecker wrote: > On Fri, Jun 04, 2021 at 01:31:54PM +0200, Frederic Weisbecker wrote: > > Since the process wide cputime counter is started locklessly from > > posix_cpu_timer_rearm(), it can be concurrently stopped by operations > > on other timers from the same thread group, such as in the following > > unlucky scenario: > > > > CPU 0 CPU 1 > > ----- ----- > > timer_settime(TIMER B) > > posix_cpu_timer_rearm(TIMER A) > > cpu_clock_sample_group() > > (pct->timers_active already true) > > > > handle_posix_cpu_timers() > > check_process_timers() > > stop_process_timers() > > pct->timers_active = false > > arm_timer(TIMER A) > > > > tick -> run_posix_cpu_timers() > > // sees !pct->timers_active, ignore > > // our TIMER A > > > > Fix this with simply locking process wide cputime counting start and > > timer arm in the same block. > > > > Signed-off-by: Frederic Weisbecker > > Cc: Oleg Nesterov > > Cc: Thomas Gleixner > > Cc: Peter Zijlstra (Intel) > > Cc: Ingo Molnar > > Cc: Eric W. Biederman > > Fixes: 60f2ceaa8111 ("posix-cpu-timers: Remove unnecessary locking around cpu_clock_sample_group") > Cc: stable@vger.kernel.org Acked-by: Peter Zijlstra (Intel) Problem seems to be calling cpu_clock_sample_group(.start = true) without sighand locked. Do we want a lockdep assertion for that?