Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4425163ioa; Wed, 27 Apr 2022 03:41:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwKSNJiYVaQCT8OGfH+/uoNhxZsCI/BXhWzZM8AtdR0TNZ7GFYypTiwdxRpQ9rh/VTYsLux X-Received: by 2002:a63:5710:0:b0:399:365e:5dde with SMTP id l16-20020a635710000000b00399365e5ddemr24206413pgb.192.1651056095961; Wed, 27 Apr 2022 03:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651056095; cv=none; d=google.com; s=arc-20160816; b=R1mS46tzE76J0ccBoFM3z/tbmBhDeRinghfNOt4W0Po+aI9BltylWkMuw1gAFbEXvX sH0XgPQTqiRLq2RELHXGvzzcIEVf7SXT1NfpxY7Ne/41Ykn1Qx3H52wslUyteP9bdc1S 34M+elKDUrDyZYoZcQYg2srAWLdDimYCsvjDd1WDRZBGx/2Yn8XNwPQiwGY5mKj2hDC5 B3qBQC5jZnJP+CvTPdKifKfFKYn5/7/riRZqGkGPPvCRd0/5ZTPk+bsZEM+AbVTS4WDY vezUFMMSlOIF95+Dy6mDvRtgFM+DDfhvAnMVcbG+DsZT+zIAZaSjx3d34GLtwJHsBaAr ai1A== 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=aXW2xhYPAvf1o0MLOP8hSxUxRqA0uZfff+kPH1xQuyk=; b=rYE4vI68vip++sII5O/JwUPo1Zrv80bYBO+qwOYc1YiIDGHsb/N51SSXs7hRJijoCn voYye23uzygoL4GVCNN7R4FdHLtJh8M2H/VPtLRQzysDh8eJvRFHhfgXQX/uAapeO4lA nr5uY07CIW1aqq4vxotc0QF4a3fOh2Tus/pT8QuWhClFPxfOCTP7jxrCTAL5C26y9EaW 8sEBNQo2T0YtftPQjApNnT+wfg0UcHuAqa+6q86fN4IZseBM5PNYLwS5/S78g6QnxEmc WXQzL/2Tuw7MhZWSD6PN6sFL3Vz9Q/4vPVPpS+bV7hAi+l3UTVFzvNiM1lDcheqk0YPL nilQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A9LnDAyK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id k3-20020a17090a658300b001da3cfee1bdsi997924pjj.25.2022.04.27.03.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:41:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=A9LnDAyK; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E204401D3D; Wed, 27 Apr 2022 02:53:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357965AbiD0GFO (ORCPT + 99 others); Wed, 27 Apr 2022 02:05:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357964AbiD0GFN (ORCPT ); Wed, 27 Apr 2022 02:05:13 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E51A4968F for ; Tue, 26 Apr 2022 23:02:03 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id a11so751899pff.1 for ; Tue, 26 Apr 2022 23:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=aXW2xhYPAvf1o0MLOP8hSxUxRqA0uZfff+kPH1xQuyk=; b=A9LnDAyKD6fVClrbsOpT+UhD6x0zNiOrPNfIyF+1WxKBC/+8bt3HtOdIM90ev/eL7H W7HWZlLtJfOEC8v+rAOYi4DTzrJ1OWmyE7/E4BKxbjktdxEAoEaGGfkvBBGsWIqDCzXS /HMKDxjfn7LKgwe+9xzwXPway6GD81+oaQuNwQDCCHZFTXrZGRaALTFmC1mX2F++YLBm abFERD1OsvujKTIldw2jdKqXPnPeMUeEJL6PNA+IDqAzvMr5q53GPvwzcOoLOO72GNLz vKp4jg4Djt9N9bDMLtv3cvoMeNfhwtRGKYIQwT9Cm2IWvz7quH+MzD9ygvMx00Ttgocz esUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=aXW2xhYPAvf1o0MLOP8hSxUxRqA0uZfff+kPH1xQuyk=; b=S3po7uktub8IgNae3QHprBA2BB+Q8h1lKJ//cVmUQsb+fH3UJLlojej4AqWjNu/4tx AapyxDgh1vvwPGaeLYcs+OXjFaSm3IvdbX5xbTD+xEGHl4UabQ3SULM1canOkahJmi88 iqm79v9E40fer3nLOjqP0z1bCURmymPoDByuQuHXdKWdhx3d6tfHNaVN4StQv1DmQ+er 5TcyUw9YATi8Ql4+Kzvm/F2YlK2eXoKJrIthkT6fa0pI9haAYcZqC0+wgm1b1hTBztu2 TmeqcmsE3kiiCfh93zDsCqnivOLcULCOb08JLV/tuIHQRtrJ3kBWtivRCjoScaS+oicc xr8g== X-Gm-Message-State: AOAM532uFQzYPMlOgAGwzkdcMPLhKdCT+fH9CXIciLfPjR8TjV+TTn+K skEiFHGYwp0H59Hb8wTUjA== X-Received: by 2002:a63:e245:0:b0:3a7:dce1:64b1 with SMTP id y5-20020a63e245000000b003a7dce164b1mr22781817pgj.67.1651039322602; Tue, 26 Apr 2022 23:02:02 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p2-20020a634202000000b003a0c6ec24d2sm14915417pga.89.2022.04.26.23.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Apr 2022 23:02:02 -0700 (PDT) Date: Wed, 27 Apr 2022 14:01:55 +0800 From: Pingfan Liu To: Thomas Gleixner Cc: linux-kernel@vger.kernel.org, Valentin Schneider , Peter Zijlstra , Frederic Weisbecker , Baokun Li , Mark Rutland , Steven Price , "Jason A. Donenfeld" , Yuan ZhaoXiong , YueHaibing , Randy Dunlap Subject: Re: [PATCH 7/9] irq: remove needless lock in takedown_cpu() Message-ID: References: <20220420140521.45361-1-kernelfans@gmail.com> <20220420140521.45361-8-kernelfans@gmail.com> <87y1zys9f7.ffs@tglx> <87czh533dk.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87czh533dk.ffs@tglx> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 25, 2022 at 11:43:03AM +0200, Thomas Gleixner wrote: > On Mon, Apr 25 2022 at 10:57, Pingfan Liu wrote: > > On Thu, Apr 21, 2022 at 06:11:56PM +0200, Thomas Gleixner wrote: > >> > - irq_lock_sparse(); > >> > >> Not everything is about RCU here. You really need to look at all moving > >> parts: > >> > >> irq_migrate_all_off_this_cpu() relies on the allocated_irqs bitmap and > >> the sparse tree to be in consistent state, which is only guaranteed when > >> the sparse lock is held. > >> > > > > For the irq which transfer from active to inactive(disappearing) after > > fetching, desc->lock can serve the sync purpose. In this case, > > irq_lock_sparse() is not needed. For a emergeing irq, I am not sure > > about it. > > No, it's required for the free case. The alloc case is > uninteresting. Care to look into the code? > Yes, it is a good exercise. Thanks for the enlightenment. > irq_free_descs() > lock(sparse); > free_descs(); > bitmap_clear(allocated_irqs, from, cnt); > unlock_sparse); > > As free_descs() sets the sparse tree entry to NULL, up to the point > where bitmap_clear() finishes the state is inconsistent. > > Now look at irq_migrate_all_off_this_cpu() and figure out what happens > when stop_machine() hits into the inconsistent state. > So the following code should fix the inconsistence between bitmap and sparse tree. diff --git a/kernel/irq/cpuhotplug.c b/kernel/irq/cpuhotplug.c index 1ed2b1739363..cd0d180f082d 100644 --- a/kernel/irq/cpuhotplug.c +++ b/kernel/irq/cpuhotplug.c @@ -161,6 +161,8 @@ void irq_migrate_all_off_this_cpu(void) bool affinity_broken; desc = irq_to_desc(irq); + if (!desc) + continue; raw_spin_lock(&desc->lock); affinity_broken = migrate_one_irq(desc); raw_spin_unlock(&desc->lock); > This can be fixed, but not by making mysterious claims about RCU and > desc->lock. > But I still think that desc->lock is critical to the consistence of the irq _affinity_ if removing sparse lock in takedown_cpu(). For the free case, after applying the above patch, it should work. void irq_migrate_all_off_this_cpu(void) { for_each_active_irq(irq) { desc = irq_to_desc(irq); if (!desc) continue; ---> if breaking in by free, then migrate_one_irq() will skip it since the irq is not activated any long raw_spin_lock(&desc->lock); affinity_broken = migrate_one_irq(desc); raw_spin_unlock(&desc->lock); ... } } But for the alloc case, it could be a problem. void irq_migrate_all_off_this_cpu(void) { for_each_active_irq(irq) { desc = irq_to_desc(irq); if (!desc) continue; raw_spin_lock(&desc->lock); affinity_broken = migrate_one_irq(desc); raw_spin_unlock(&desc->lock); ... ---> any new irq will not be detected. But alloc_descs(start, cnt, node, affinity) still associate the irq with this cpu. There is _no_ opportunity to clear out this cpu from desc->irq_common_data.affinity. This is the affinity inconsistent problem. } Thanks, Pingfan