Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp902881rdb; Wed, 6 Dec 2023 03:22:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/oq1rt74SuMKFXWx+JenTbCPdZp6NWbtvXa+Ga+aQd5DV7R6caHqH5NV9Y8FdmhO1fGQH X-Received: by 2002:a17:90a:b296:b0:286:6cc1:26c with SMTP id c22-20020a17090ab29600b002866cc1026cmr550611pjr.55.1701861757847; Wed, 06 Dec 2023 03:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701861757; cv=none; d=google.com; s=arc-20160816; b=ZV3O2vxgJUjk/XhSdb8BYIrmzNAGOH6T91Q2JsU0ebdrTbxnVvnnGkT2wcN6TMksPz kgYNPCWEw9Uk4ba7p61F21dPYI1uSQ4hMyosrHRrSJBhzvjAsoRN4srb4B48PYJfe1px au734VDZ6MK8F6aLsTbEm0LXAhVWrm2Npe6BJLCgWtVR1WCFruNtIVFehAXGoRyG6rrd cOt0IHtg8EzOsBeC7XYeCUyQoOMjPMyLpg3yOl6L99CfwOBxRJ0Elhk0+JVcLNyYGDlp SNywtNW+pz6EbAUz1XIfsBQO65LdLRVF1Odj+LV7GpcE3Y0+KQpzFe778m+WyMSIqjtw u6wQ== 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; bh=AhOvSRp4d8ISctxTIsyGO/H5m5iiVaQo/R0vXrxgpMA=; fh=6nUPER8aWCkWa2knDTVPSKYVQ4QzARzCXE/CweBJ8E0=; b=zsdnXZl8fccg+FTjd4NMtgckv93mO1gmvGZdhyH4tBTr/i3eCGodojWqg0BhQ2FWCI ueaerafFtA71cPRso9e9Fo6Y62HqS2PRi9Z6DgYCW3YLf5rkY8obCorQNHEA+AlXAA3s Nl2ILCKxgHN7ITtvtxG3GQrPjCmskZfjvAj2k0GBsBakLYgbwofTYcd+AQWhwI73tIJ7 IHmy7y+N3q97nbEMh188sg4LwudFDslHOvSSzIJQ+I/6ePvMUqz31mv4EYaL5La/e4j8 A76D3UGtWz6W/4ecbEszfmHOnb8N1gVx94LaaV72CPSX+wsEd08bpcqVITIwIIFgYyV6 BAJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id ot13-20020a17090b3b4d00b002839e1cb23csi14187169pjb.117.2023.12.06.03.22.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:22:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 5CD2081A7D06; Wed, 6 Dec 2023 03:22:35 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378120AbjLFLWV (ORCPT + 99 others); Wed, 6 Dec 2023 06:22:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378005AbjLFLWU (ORCPT ); Wed, 6 Dec 2023 06:22:20 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26DBDC3 for ; Wed, 6 Dec 2023 03:22:27 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7BF6CC433C8; Wed, 6 Dec 2023 11:22:25 +0000 (UTC) Date: Wed, 6 Dec 2023 11:22:22 +0000 From: Catalin Marinas To: Hillf Danton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Waiman Long , Andrew Morton Subject: Re: [PATCH] kmemleak: Avoid RCU stalls when freeing metadata for per-CPU pointers Message-ID: References: <20231201190829.825856-1-catalin.marinas@arm.com> <20231202075055.1142-1-hdanton@sina.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231202075055.1142-1-hdanton@sina.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 03:22:35 -0800 (PST) On Sat, Dec 02, 2023 at 03:50:55PM +0800, Hillf Danton wrote: > On Fri, 1 Dec 2023 19:08:29 +0000 Catalin Marinas > > @@ -1472,14 +1474,27 @@ static void scan_object(struct kmemleak_object *object) > > /* already freed object */ > > goto out; > > > > - obj_ptr = object->flags & OBJECT_PHYS ? > > - __va((phys_addr_t)object->pointer) : > > - (void *)object->pointer; > > + if (object->flags & OBJECT_PERCPU) { > > + unsigned int cpu; > > > > - if (hlist_empty(&object->area_list) || > > + for_each_possible_cpu(cpu) { > > + void *start = per_cpu_ptr((void __percpu *)object->pointer, cpu); > > + void *end = start + object->size; > > + > > + scan_block(start, end, object); > > + > > + raw_spin_unlock_irqrestore(&object->lock, flags); > > + cond_resched(); > > + raw_spin_lock_irqsave(&object->lock, flags); > > Nit, spin_lock/unlock can be collapsed into need_resched(). > > if (need_resched()) { > raw_spin_unlock_irqrestore(&object->lock, flags); > cond_resched(); > raw_spin_lock_irqsave(&object->lock, flags); > } The reason I'd not do this is that we also want the interrupts to be re-enabled regularly. Keeping them disabled may not even mark the current thread as need_resched(). -- Catalin