Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp11749485rwb; Fri, 25 Nov 2022 21:43:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf4Bj1CfIB9XTBXNTBGIapWaoj+5XNWDs/rz/VeFUpvfc/woogLVk5dfxvCeio3dMMGRwztV X-Received: by 2002:a17:906:94d6:b0:7bd:3a3d:804e with SMTP id d22-20020a17090694d600b007bd3a3d804emr3933248ejy.701.1669441433368; Fri, 25 Nov 2022 21:43:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669441433; cv=none; d=google.com; s=arc-20160816; b=Rkr9OoapIqWmL1Wd8SzPH+kVBfT9F8Fu3ncL9+mb1v9Uv56n2D5l0/tYRUGWcZcnif OAON8Carn9DJ7F+g63Wn4L9Eoio/XpNtuQ4WL5Vt9ksjSzqA8Bk+ZvNWpdUi30y3Itus p6nk7HqbA9sAuqnzfC+l5dBFlAEiRpAE+vGV0h0mKjjK/d2pkQPWJAYd5XtKi2RcG2bQ HNf8oWBkPyQ3wJewQVK+U0p1Rdtgx5YcoYfA0eG8SfHT04PumIWn9A3NpvdwiTsCTgq8 aWi3TFiNXbNp+bX5cAEOvYIWhZX57qg0nK59zfgn2T4l3Vn9PSK1NeROqmeFsFjR9Zg1 uZ6g== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=i5V6pAuncwvgyudnVxg16U0ks0E+4Nu+5DZ35eeYYDE=; b=poSgNyVaAqDEkMO2unJufV1nhVKKuJMLOZnAc+EU9orohZd9QNCM9IbJrHH3H8Ej8D ZqDtCUldZETvUxwL4TwvZkQmBDg0UMJrEQq1iwzVLA/qvkyXbR7o00OcnGc2uFsbjzyx 7DosQlANapuy4lPripWNbUQ4tlMmUruPtC9FKfJMUZ3GdJ3fJZKj67tGLcTccubqXZl3 Pjd7J7j+bTTfnovDAXpHCpPvR8DCrZIYjJmME1TmcFGojnMuU1RYQ9WX+6OuPuP2pS9B BSLa2KCmBxTBJvWzw1q8DkUJlCw/ODOOyAVhSB4V/+vF+UEb0uPwHsZY9Z9ZkNVqmvuw IiIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=e6Zj0Vir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a16-20020aa7cf10000000b00461b2c460c8si4075244edy.531.2022.11.25.21.43.31; Fri, 25 Nov 2022 21:43:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=e6Zj0Vir; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230023AbiKZFUd (ORCPT + 85 others); Sat, 26 Nov 2022 00:20:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229549AbiKZFUa (ORCPT ); Sat, 26 Nov 2022 00:20:30 -0500 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3F721F60B; Fri, 25 Nov 2022 21:20:28 -0800 (PST) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2AQ5GVlT005875; Sat, 26 Nov 2022 05:20:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=qcppdkim1; bh=i5V6pAuncwvgyudnVxg16U0ks0E+4Nu+5DZ35eeYYDE=; b=e6Zj0Vir+0oj2T1qIjc1HLMivLMVM86ln6E2Dx3cqvJXpQbvXJdxgGUhjAoyohhFgB0s fwlqC+ROt6GJReod937WL66pya47z/fswk1v8r1YR6sXdSUYI6qZt+O5a/8LwrRDCLru alr4Es4wfug1xl+7F2zYdepRdqDLZcW4VWOWc1yXJZJAg47jYJiCO1Q5v2Eb/TcRtK4N sYhV2Pa5a6+petx1eu47JBWfCuyir/YRYFUyOGqnbdZriciJWpaTNmL9Tfbmn6E4jI7I 6U3UARKkyIe0ZOd2G/fv/XeALie0TG8m7RDQeLXivId7svjgutALTq5ZWT/31pqX1Vge Lw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3m3a4t86vu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 26 Nov 2022 05:20:16 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 2AQ5KFdV023119 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 26 Nov 2022 05:20:15 GMT Received: from [10.50.56.30] (10.80.80.8) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.36; Fri, 25 Nov 2022 21:20:12 -0800 Message-ID: Date: Sat, 26 Nov 2022 10:49:54 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 Subject: Re: [PATCH] rcu-tasks: Make rude RCU-Tasks work well with CPU hotplug To: Zqiang , , , CC: , References: <20221125155427.1381933-1-qiang1.zhang@intel.com> Content-Language: en-US From: Neeraj Upadhyay In-Reply-To: <20221125155427.1381933-1-qiang1.zhang@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: bCWqU_oNO9aPN7TZNdZRNb2Hq09O9jRR X-Proofpoint-ORIG-GUID: bCWqU_oNO9aPN7TZNdZRNb2Hq09O9jRR X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-26_04,2022-11-25_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxscore=0 clxscore=1011 bulkscore=0 priorityscore=1501 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2211260041 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 Hi Zqiang, On 11/25/2022 9:24 PM, Zqiang wrote: > Currently, for the case of num_online_cpus() <= 1, return directly, > indicates the end of current grace period and then release old data. > it's not accurate, for SMP system, when num_online_cpus() is equal > one, maybe another cpu that in offline process(after invoke > __cpu_disable()) is still in the rude RCU-Tasks critical section > holding the old data, this lead to memory corruption. > Was this race seen in your testing? For the outgoing CPU, once that CPU marks itself offline (and decrements __num_online_cpus), do we have tracing active on that CPU, and synchronize_rcu_tasks_rude() not waiting for it could potentially lead to memory corruption? As per my understanding, given that outgoing/incoming CPU decrements/increments the __num_online_cpus value, and num_online_cpus() is a plain read, problem could happen when the incoming CPU updates the __num_online_cpus value, however, rcu_tasks_rude_wait_gp()'s num_online_cpus() call didn't observe the increment. So, cpus_read_lock/unlock() seems to be required to handle this case. Thanks Neeraj > Therefore, this commit add cpus_read_lock/unlock() before executing > num_online_cpus(). > > Signed-off-by: Zqiang > --- > kernel/rcu/tasks.h | 20 ++++++++++++++++++-- > 1 file changed, 18 insertions(+), 2 deletions(-) > > diff --git a/kernel/rcu/tasks.h b/kernel/rcu/tasks.h > index 4a991311be9b..08e72c6462d8 100644 > --- a/kernel/rcu/tasks.h > +++ b/kernel/rcu/tasks.h > @@ -1033,14 +1033,30 @@ static void rcu_tasks_be_rude(struct work_struct *work) > { > } > > +static DEFINE_PER_CPU(struct work_struct, rude_work); > + > // Wait for one rude RCU-tasks grace period. > static void rcu_tasks_rude_wait_gp(struct rcu_tasks *rtp) > { > + int cpu; > + struct work_struct *work; > + > + cpus_read_lock(); > if (num_online_cpus() <= 1) > - return; // Fastpath for only one CPU. > + goto end;// Fastpath for only one CPU. > > rtp->n_ipis += cpumask_weight(cpu_online_mask) > - schedule_on_each_cpu(rcu_tasks_be_rude); > + for_each_online_cpu(cpu) { > + work = per_cpu_ptr(&rude_work, cpu); > + INIT_WORK(work, rcu_tasks_be_rude); > + schedule_work_on(cpu, work); > + } > + > + for_each_online_cpu(cpu) > + flush_work(per_cpu_ptr(&rude_work, cpu)); > + > +end: > + cpus_read_unlock(); > } > > void call_rcu_tasks_rude(struct rcu_head *rhp, rcu_callback_t func);