Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp530055rdh; Thu, 26 Oct 2023 08:38:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF45F5hPJGjpYtBOPMxt0hhWTINvvpkZFgg09jzgnwXE/CQLVV7LQej3pFchL/ey7ZlWVrm X-Received: by 2002:a05:6870:fe8e:b0:1d6:439d:d03e with SMTP id qm14-20020a056870fe8e00b001d6439dd03emr17837560oab.18.1698334694194; Thu, 26 Oct 2023 08:38:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698334694; cv=none; d=google.com; s=arc-20160816; b=g63ge8hh7AP3fplRhltpXAh4ew2BzsgN5YWkDDUOHklz5CkxX2rGWyXJtNhOx7k8qD Uka+3x6SJO4p0MBigbglsVEQXOVhU6HUKvnKmtvGu21Fi2mEmbhXK2GvipdV9Bzuq+5+ +mQqcqY6ZNF2upngHUGWfv42WmDldT1NpxuqKFlbdYLrntl2Srsvj2ervJ61gsL77VH5 Puu6Bz2dElDO8NCRfZeHh2Jk60STIRv+qf2djvuKnKNw1s7u8wQdYoXZugGYStqNE5WB PAun59ZVTbQfx6mxnUNUkXk4erOT/JQ8Tk+NosCDNip5UX+usdAkHcH9aUdge5DnIZxd X6ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=x/ia5iYg44wnoHJ0oC/4cmxCohdGQUTHKCQk0kzxu1E=; fh=DsH4Hi1tDDiDpmOM7Z2JLTY10fIWKqTwi/7nw0G+zWs=; b=RV2qw0zLbGV23cpgj7WVxuLGAjnM/uczHjIK5/1he7Y2suLEjl9s2dn7If979eDOO3 0ANhd+gaOTgvS3LRn//0zFNiHKQl+BtRRvb6J3Wguzbcsg00txR+lh646BEY8B0tVsV+ eg+p/dpl1NPYNWgxMDV2hQUPvXPVeYVubPQa6KwB4yeknkjZ20UX/TRy/dRj0dpbIb/1 uGlrYYxEiNwZ21V7lFjVZN3ZHB5CeOUpM8XQpe8ZMEqjE4wgQdAOIE4cMwuEdE6HPei1 FjlqRDVufHq6iKhNK4FGHeWskvjVx7mcHu56zPWaX1zgHGUvvASIAsPPQzT8t74qTJiX mJWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VQIIFYze; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id 123-20020a250c81000000b00d9a4f9f7353si4107496ybm.51.2023.10.26.08.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 08:38:14 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20230601 header.b=VQIIFYze; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 2C20F8185944; Thu, 26 Oct 2023 08:38:11 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbjJZPiC (ORCPT + 99 others); Thu, 26 Oct 2023 11:38:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231280AbjJZPiB (ORCPT ); Thu, 26 Oct 2023 11:38:01 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48BD81A7 for ; Thu, 26 Oct 2023 08:37:59 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6bcdfcde944so237997b3a.1 for ; Thu, 26 Oct 2023 08:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698334679; x=1698939479; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=x/ia5iYg44wnoHJ0oC/4cmxCohdGQUTHKCQk0kzxu1E=; b=VQIIFYzev/4OHuT+U/kvGBbK3bMyqfeTMbd+NXVoi+7/3LQveG/lIXJrRSDqKbqG41 XrT1JkO+4mXEQUHlZuGcGyDH2UEgJLFFj+kVv/88Hi4Q/+XL66r8PlR3biygLeIsQHcv PqF+EzSQ36QulfGfc2/d7IVu5Vu9N52eMaBCxba7WXMLci6XYyDx4UCyb7GK6DMWX73N MFXo2H99CbgzBxErHCl96GIVu5gYrGlHdntmCjpHMYHKjfSxNDi4i/DHsCd+kkU1xZvm UMQPWsLNQ70tHy7ngsjD8GZWRSCga/RcEknfhUKNcxS4RzzuPXFNV5fE3fZneDLjCL8G i+Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698334679; x=1698939479; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x/ia5iYg44wnoHJ0oC/4cmxCohdGQUTHKCQk0kzxu1E=; b=PYR0NwKK3/ntYbmCOFljnS3Rk5F3SXg3FdxYq1xjl+ulkuPDBaUEwOLJjX0dwFOApF Vor78r/I0sU82kd8Ng3BH6QOCmMCv7hvb8dG//Z8/SCtcy6zm0gEXj9ZFUHZWqY8Zf2h o+gwJBdlAqsn839mZCjcLu4MvOGMu6o0jeFvhDBFYGDLIMcj7HX+pfigCSTWKD+61pF7 fw2qk0JGx62gNOVq1UFtgcHmxm4pucDFpbM+4269SptGLnGmjfZvMD+q5eSGFHh7YxWa ClD1tGrjBBznNGgjA0uqnxot/zyLTy1BYzIqNDlc5fL3lznQgNhswV0dF/g+9KEsu9/K y2wQ== X-Gm-Message-State: AOJu0YwYxi8bFaLOp+fp6Jdc3fw1HmTHmy4qGS7QtURo/V/xLJqkWGCR QjXRdnAH9ahOLIsfl/ugAAz+kJJX1qpFULyP X-Received: by 2002:a62:b518:0:b0:690:c79c:1912 with SMTP id y24-20020a62b518000000b00690c79c1912mr18392426pfe.0.1698334678676; Thu, 26 Oct 2023 08:37:58 -0700 (PDT) Received: from [192.168.0.152] ([103.75.161.210]) by smtp.gmail.com with ESMTPSA id k28-20020aa79d1c000000b006bde2480806sm11399447pfp.47.2023.10.26.08.37.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Oct 2023 08:37:58 -0700 (PDT) Message-ID: Date: Thu, 26 Oct 2023 21:07:46 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2] Fixing directly deferencing a __rcu pointer warning Content-Language: en-US To: "Michael S. Tsirkin" , Mateusz Guzik Cc: akpm@linux-foundation.org, brauner@kernel.org, surenb@google.com, michael.christie@oracle.com, mathieu.desnoyers@efficios.com, npiggin@gmail.com, shakeelb@google.com, peterz@infradead.org, linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org, "Paul E. McKenney" References: <20231025165002.64ab92e6d55d204b66e055f4@linux-foundation.org> <20231026121621.358388-1-singhabhinav9051571833@gmail.com> <20231026091222-mutt-send-email-mst@kernel.org> <20231026110925-mutt-send-email-mst@kernel.org> From: Abhinav Singh In-Reply-To: <20231026110925-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS 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]); Thu, 26 Oct 2023 08:38:11 -0700 (PDT) On 10/26/23 20:47, Michael S. Tsirkin wrote: > On Thu, Oct 26, 2023 at 04:06:24PM +0200, Mateusz Guzik wrote: >> On 10/26/23, Michael S. Tsirkin wrote: >>> On Thu, Oct 26, 2023 at 05:46:21PM +0530, Abhinav Singh wrote: >>>> This patch fixes the warning about directly dereferencing a pointer >>>> tagged with __rcu annotation. >>>> >>>> Dereferencing the pointers tagged with __rcu directly should >>>> always be avoided according to the docs. There is a rcu helper >>>> functions rcu_dereference(...) to use when dereferencing a __rcu >>>> pointer. This functions returns the non __rcu tagged pointer which >>>> can be dereferenced just like a normal pointers. >>>> >>>> Signed-off-by: Abhinav Singh >>> >>> Well yes but these need to be called under rcu_read_lock. >>> Who does it here? >>> If no one then maybe you found an actual bug and we need to >>> fix it not paper over it. >>> >> >> There is no bug here. >> >> p is the newly created thread, ->real_cred was initialized just prior >> to this code and there is nobody to whack the creds from under it. >> >> Second bit in the patch changes one real_parent deref, but leaves 2 >> others just above it. Once more no bug since the entire thing happens >> under tasklist_lock, but the patch should either sort all these cases >> or none. Sparse reported 3 similar dereferencing warning this patch contains 2 fixes for 2, but yeah I should fixed all 3 of them. >> >> I think it would help if the submitter had shown warnings they see. The warning message :- warning: dereference of noderef expression > > Yes, and this must be tested under lockdep, which I think would > spit out warnings for this patch. Not sure, but I tested this with sparse (make C=2) and after the above changes I dont get the warning. > > What should be used here I'm not sure. IIUC rcu_dereference_protected(p, 1) > is discouraged now? > Not sure but I read that, rcu_dereference should be prefered when reading and rcu_dereference_protected should when writing.