Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp954311rdh; Thu, 26 Oct 2023 23:42:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGg4xKDPPyanCxESn64YoeQ5eseIwN0uPQRSxSk51bcqxpbPIwqgZMSHWiGj6rtKFeDFTo+ X-Received: by 2002:a67:c113:0:b0:457:c9d2:4624 with SMTP id d19-20020a67c113000000b00457c9d24624mr1856117vsj.31.1698388934328; Thu, 26 Oct 2023 23:42:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698388934; cv=none; d=google.com; s=arc-20160816; b=buYnpa/K93FN0moUecEpJkmLiys24VHd6tfkdAulf8xjKTUMcbQX91PvJZRgrzwf4m iCYmjC8t1phLvMhePpkpDDV4a++vdsZyctTIKDGw3VMmhN9oEZpUo6ucouFPYwTQ9RAY D22deBjQR9SRAMOvnLGhP4peTIQpsXJJMzjfuylhUSWeYlzW2/rq06f3RoVQtpc7+H3j tGgcX80ErCzyW1xslhRr9liPQGQNw++eCFApxw/r5RCiGetIHpoWKt5UETKOqmk8YY9Z /6/WUhdCS2hXGeOOOuh2p8JoxjCTJLL7vtHbFEy8RSG0fd6DfNXhMjUbwz1fVy/zSlD0 k2Yg== 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=GRyFJrR5fk8DHlbv1dDr6nCLPbHAmO3CAZkM/W8M2k8=; fh=aGwVq0yI2hA3NxfRheqKnlgmGWMsgS5P54tyvkFIg8w=; b=cWM7NuF8rHMkG3kxo/fLhUfYktSOQ3+uf0B+rhCKs8URCUp79pawAhMdtk80dRR0dG qmRvMtoC7Q2r+13Rp9he+XmiSAvOECrWSACqNCmO3Dd6NVGBbFdx5UFGoOz/7h7ulPFo qzXcWDr3p+izf3ihURj8gNegT+yc8d+Wuwy5gBiWjhkBkM8dGP2bbCfXTjWBrL1SbUNG pyJ+h7lDrYkZMS0Xgv88MfwOdF++/4asIX1NGMZSg0XEciRU8P6R5hMH813Q7B2WEZA5 hRVU+6hHs2LKRuGGu7aA4e0FKThucSkZ14acHg4zI9f13xgt/Z08qusJk3lxrgFXig1o l8eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MRcMCl8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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. [23.128.96.36]) by mx.google.com with ESMTPS id 126-20020a250a84000000b00d9a47ec8c7asi1524094ybk.164.2023.10.26.23.42.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 23:42:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MRcMCl8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 17A91835939A; Thu, 26 Oct 2023 23:42: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 S230164AbjJ0GmC (ORCPT + 99 others); Fri, 27 Oct 2023 02:42:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjJ0GmB (ORCPT ); Fri, 27 Oct 2023 02:42:01 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C1F721B1 for ; Thu, 26 Oct 2023 23:41:59 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6bb744262caso429452b3a.0 for ; Thu, 26 Oct 2023 23:41:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698388919; x=1698993719; 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=GRyFJrR5fk8DHlbv1dDr6nCLPbHAmO3CAZkM/W8M2k8=; b=MRcMCl8WWv9tTvpaDNBzLQTDVmSgr2zB/wlp7kD4QWoSzNyAm0N1qvrwnxxDOsdVFt ArEv7D4iC0r/pVfh83pwHZ+dgWSsZuh73y8nBiCvbFaSDcJvmVfcDr3jaFAJ1iohrnB7 E3sVj6vx4oSv+smGWIWD1Y8dGv3QYSJATu48vHRu5VJaJKRvQg9ux7Tdy1zLBNOKf76h gHVUPOveuyU0tFt6+T7CsyYGueG5Mxho6DdI3sSvqPWjW6u/zXzD8v4hr8TDLSEzWy+4 HJPwIIAXSqUmPoz1lVlrkdpHmBya/XbwXkxdMlirdVAXd/DccOynfqJ6YijxaSp3cenJ Bz0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698388919; x=1698993719; 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=GRyFJrR5fk8DHlbv1dDr6nCLPbHAmO3CAZkM/W8M2k8=; b=HUFz3gXkzrrdIOnBlgUBL1J3CY75BFsUAYptm69S0DrHZ14GI72jo/HtyQg9ewx3+w qgSvfHTyf1PDIkHkyYrhnnlt9/qv5QRd2Wz0Zj2JuBoQzfYDtJ/dk9X7z2VFWsipbjXH k0FH1D/fnk9taWB6QHd2DyOD8ZOWCOZtvRYxh3R3npHJapZxVxMkFNAo0gQWp1rIHT9d s5glp9f3n84E59wCy5V/zsU6g3xL3kPoKZsoEMgqSgnHrzD5NEMm58a/yM8hiHmin20I d6m/uMbmDzkitLL6Wauww4hXr4vl0zlSjKEoXCexnARj1zDr129sUzYmohmW7FX5+qHv tkRA== X-Gm-Message-State: AOJu0YxlQPXSgXQMQxxlv7d9S+2q7bs+c/DrvkiBOtEjbEP1iZE7nP78 fgVy0ptAHwU+Fipz4KDv6IU= X-Received: by 2002:a05:6a20:440d:b0:163:ab09:195d with SMTP id ce13-20020a056a20440d00b00163ab09195dmr2371620pzb.0.1698388919131; Thu, 26 Oct 2023 23:41:59 -0700 (PDT) Received: from [192.168.0.152] ([103.75.161.208]) by smtp.gmail.com with ESMTPSA id t6-20020a62d146000000b006babcf86b84sm678650pfl.34.2023.10.26.23.41.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Oct 2023 23:41:58 -0700 (PDT) Message-ID: Date: Fri, 27 Oct 2023 12:11:47 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] Fixing directly deferencing a __rcu pointer warning Content-Language: en-US To: akpm@linux-foundation.org, brauner@kernel.org, surenb@google.com, mst@redhat.com, michael.christie@oracle.com, mathieu.desnoyers@efficios.com, mjguzik@gmail.com, npiggin@gmail.com, shakeelb@google.com, peterz@infradead.org Cc: linux-kernel@vger.kernel.org, linux-kernel-mentees@lists.linuxfoundation.org References: <20231026114632-mutt-send-email-mst@kernel.org> <20231027063713.1018624-1-singhabhinav9051571833@gmail.com> From: Abhinav Singh In-Reply-To: <20231027063713.1018624-1-singhabhinav9051571833@gmail.com> 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,URIBL_BLOCKED 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 23:42:11 -0700 (PDT) On 10/27/23 12:07, 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 > --- > kernel/fork.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/kernel/fork.c b/kernel/fork.c > index 10917c3e1f03..e78649974669 100644 > --- a/kernel/fork.c > +++ b/kernel/fork.c > @@ -2369,7 +2369,7 @@ __latent_entropy struct task_struct *copy_process( > > retval = -EAGAIN; > if (is_rlimit_overlimit(task_ucounts(p), UCOUNT_RLIMIT_NPROC, rlimit(RLIMIT_NPROC))) { > - if (p->real_cred->user != INIT_USER && > + if (rcu_dereference(p->real_cred)->user != INIT_USER && > !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN)) > goto bad_fork_cleanup_count; > } > @@ -2690,9 +2690,9 @@ __latent_entropy struct task_struct *copy_process( > * tasklist_lock with adding child to the process tree > * for propagate_has_child_subreaper optimization. > */ > - p->signal->has_child_subreaper = p->real_parent->signal->has_child_subreaper || > - p->real_parent->signal->is_child_subreaper; > - list_add_tail(&p->sibling, &p->real_parent->children); > + p->signal->has_child_subreaper = rcu_dereference(p->real_parent)->signal->has_child_subreaper || > + rcu_dereference(p->real_parent)->signal->is_child_subreaper; > + list_add_tail(&p->sibling, &rcu_dereference(p->real_parent)->children); > list_add_tail_rcu(&p->tasks, &init_task.tasks); > attach_pid(p, PIDTYPE_TGID); > attach_pid(p, PIDTYPE_PGID); For this particular file I have resolved the rcu pointer dereferencing issue and I have tested the above by using qemu using this command qemu-system-x86_64 \ -m 2G \ -smp 2 \ -kernel /home/abhinav/linux_work/linux/arch/x86/boot/bzImage \ -append "console=ttyS0 root=/dev/sda earlyprintk=serial net.ifnames=0" \ -drive file=/home/abhinav/linux_work/boot_images/bullseye.img,format=raw \ -net user,host=10.0.2.10,hostfwd=tcp:127.0.0.1:10021-:22 \ -net nic,model=e1000 \ -enable-kvm \ -nographic \ -pidfile vm.pid \ 2>&1 | tee vm.log it booted without any issues.