Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp888006pxb; Fri, 22 Apr 2022 13:29:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE4zrqcsYtjnXFmGcfG5W9BCtWRwu+Xyosyh6cYNv1NPRCB1uBW74SP/HPRsRZ1imGJYga X-Received: by 2002:a17:902:7794:b0:156:7641:a6cf with SMTP id o20-20020a170902779400b001567641a6cfmr6302418pll.35.1650659388260; Fri, 22 Apr 2022 13:29:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650659388; cv=none; d=google.com; s=arc-20160816; b=M8CHMNDxLkMgrMXDkyXGMU8BdfkGiTRv9nJ84UXp8sD3jjTJ/GDy4WuwdavI3v7V6X NFMmAZdZYELa45DJzIwEzEGHZY0dIzZz3g71JF0RwHH7Li/aUtZjaB939B3FHdXd62mv HGQKOduM1/O/vzyTsEc/YPG74itLP7vin91iimpge0UmAMe95U6SqfFBynip4pv9HDYm rNSI69fSMnOOsWr3lj1G/pIY/6LtwKoGiAT50T7fOAEleRwww4sFa8a72jpqJp25k/XK U+gnoEzAou8g7dq1lJ+B5lWOZsJEfxxPQhOhH4jcfljqhNS2KrOPOGfsJiNiqg7IOzeB 6gRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XOKJyrS8QtzQoeHSOkLR7Y1klkfAcATQqfMHIhBU3dw=; b=lqKNMKdtRhKagHMaUpzFY4dEQy1aj9Wpja3o79eGyrP2Gn2Z/gB2mcuTlxLrXtGgRX FAv6Ije/noThyWcgx4kAsOH+9fwqVkQx1Xhost8y0d/EbgxpUjbDgtRkIMT84BS0XyIE O7s9sW7Q0Qu7nxkQYaD4YYIiTDF6526mk51MWE/KpZCIb3QltmmRQoMffRzb6mQhRUFS XCfOe364coBYOkk7Ir5c8UZodc4krDniHNGEXa3ccEbG7jZ18OTaO1ssRp00Yhop+brZ ox0ANcMDBfs9roNIFpMZna/cIjxaNKPiiuoI+Cjt9+aVa8KfOBGtk/B7BhiOTfz98f0B KmPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZX3TjlWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id y1-20020a655b41000000b0039d46296184si9417278pgr.838.2022.04.22.13.29.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:29:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=ZX3TjlWV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 CBDD3282806; Fri, 22 Apr 2022 12:16:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379255AbiDTOIb (ORCPT + 99 others); Wed, 20 Apr 2022 10:08:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379228AbiDTOI3 (ORCPT ); Wed, 20 Apr 2022 10:08:29 -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 D86E73E0DD for ; Wed, 20 Apr 2022 07:05:42 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id z16so2031254pfh.3 for ; Wed, 20 Apr 2022 07:05:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XOKJyrS8QtzQoeHSOkLR7Y1klkfAcATQqfMHIhBU3dw=; b=ZX3TjlWVIUa6DvnJkhrX3gVqjsqt6eo7qvybPLa7T6oIsBDQw7Mb0r7DCJog0kL2Ol UH0MM6WRaZpuwbYQKyYfRLfEjhOsTDGfL4Bpga8Bv5xTUWvAWbWWcSd8XejK2Pd5cVf6 hGkgMpxNaZq5N7U69xre+mNALmWV1kex7FWpXVXvpPwDYweXGLrLQQaVXgM+1M8gER/z rUqaOucEHqdNVbx5YKuzMOL3zJ4XqLPkZ7/8kc+3mgeBpAOh0vo4LgmU1s51Al+K2kO7 hMHMYe0j+XJA0PIpN7aQJV+9W2BxmpwpyNQ/JNT9qTpbfaBjPcewH+6wHkwtTG/FmEEC BG/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XOKJyrS8QtzQoeHSOkLR7Y1klkfAcATQqfMHIhBU3dw=; b=SJa5QR6+nhbqhfIhDJPckvn167oY2Fy/tFAAuCMJyoKBrxOlwglnMPY+jNPM0zzSRc i7bh3iHUE5pz3AqyY+PZ55i7EAiOBkg4y0E71cYX6/X5XBop8MUajvL+d+4sG1388nmI aBGt2KDwRcvrur6lXT3z+PLLfbEGDCx1x1FBXPOUKmDSYDbrPYjyuqEBnUvtzxI539Q5 APu0SPPHvlnH1fmjnvAZFEJtbKs/Snm5YMqcsgROnQMVY5sfihhOtcFzsonoY26Gkv11 HxGEIlXajfWY5qclqyvS8hNCPMpUfHw9YDJieTO0ngACZRkLnH26hQd6sNCMYAC2Qa7G HgIw== X-Gm-Message-State: AOAM531ik6cJh8hxL425JKhCy+qqvOiaetAonSlu6hgnL30gnzacu/gJ rwQJ49ZjIk6Kb/2s44X51Cy3z2rOiA== X-Received: by 2002:a63:ec46:0:b0:381:81c4:ebbd with SMTP id r6-20020a63ec46000000b0038181c4ebbdmr19418649pgj.534.1650463542277; Wed, 20 Apr 2022 07:05:42 -0700 (PDT) Received: from piliu.users.ipa.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id br10-20020a056a00440a00b0050a777cd10csm10959178pfb.91.2022.04.20.07.05.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Apr 2022 07:05:42 -0700 (PDT) From: Pingfan Liu To: linux-kernel@vger.kernel.org Cc: Pingfan Liu , Thomas Gleixner Subject: [PATCH 1/9] irq/irqdesc: put the lock at the exact place in irq_sysfs_init() Date: Wed, 20 Apr 2022 22:05:13 +0800 Message-Id: <20220420140521.45361-2-kernelfans@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220420140521.45361-1-kernelfans@gmail.com> References: <20220420140521.45361-1-kernelfans@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 sparse_irq_lock is used to protect irq_desc, and furthermore irq_sysfs_init() is called only once, so put irq_lock_sparse() at the exact place, where the race condition may start. Signed-off-by: Pingfan Liu Cc: Thomas Gleixner To: linux-kernel@vger.kernel.org --- kernel/irq/irqdesc.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c index 939d21cd55c3..8d0982233277 100644 --- a/kernel/irq/irqdesc.c +++ b/kernel/irq/irqdesc.c @@ -312,15 +312,14 @@ static int __init irq_sysfs_init(void) struct irq_desc *desc; int irq; - /* Prevent concurrent irq alloc/free */ - irq_lock_sparse(); - irq_kobj_base = kobject_create_and_add("irq", kernel_kobj); if (!irq_kobj_base) { - irq_unlock_sparse(); return -ENOMEM; } + /* Prevent concurrent irq alloc/free */ + irq_lock_sparse(); + /* Add the already allocated interrupts */ for_each_irq_desc(irq, desc) irq_sysfs_add(irq, desc); -- 2.31.1