Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp137731imp; Tue, 19 Feb 2019 20:09:59 -0800 (PST) X-Google-Smtp-Source: AHgI3IZeguznlWF5fFdxxLKwHw4A/m6uCZ1UIfcx7uMSl+5dnLiDPMrrbTHufcjAoHgGfU99pJUd X-Received: by 2002:aa7:838c:: with SMTP id u12mr24855267pfm.189.1550635799282; Tue, 19 Feb 2019 20:09:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550635799; cv=none; d=google.com; s=arc-20160816; b=g43Tu5zQGOQ5fSIc+0ZwDhPQyUC537wvPoUVb1AMDWtDNuPXNeFTh0R1NuzcQJWuMB CBxvCAyH6+frzJiEzyWoGfGNq2DiyY/lwbZMDZTFzJQxR8xBRVneYlFunYUdd1idVWnN sillT7XO3E8dax0FNUAXbe9AyBO+d9fCpb2OvUOP20dWnUWQNBkcVGpkpbguK/KNMgKa DywFpya/WBwlhPxjpyUsdEGWQrC9B1T0iwyD+ipS5D79bM89y8uCBNdKtTU521f2S9ZL sny7H3VtkgM7jLhimAykxEbsu1fEwfcD2HR2qZ6XTXxdt5kmoGnuvIjtS02wdBOyGXFD cjdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xEHb23Q2l1fYivVKgVEsDTK7wpL+EEEEuo8D6bsBm4g=; b=rFc84u8iQudzhY+EWVYTXUsv16UuNwxxDNSYhsqvGQC00PKmPbSgTy8e9yScll/JTL TBR0PH2FoG19fF4XHhow7t/v9JmqJqPoPYQrJWM5JQMICUZVJgOP+LP6rAkEzxYDuyiI SXtEBLf/j5xzM0mfETqhWEBRmK2YEiIkRIvPdDbtN2u0zfqV3g7BInPOVTi+U+l2eguK iZKYYeCrzHyA7eBZm2TO+qrFruwWOwCeQUtUnZOuKlCkW7wVop2Juukn08YKwlA/xOKv XsfUf51NBVhMlCzygSEAc6PsGnnIM7h4qSj7kV2k9XG9x70C/sP7Dg7ikZ5+8GeTucPF phFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=A3JbZHRJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z185si17145864pgb.222.2019.02.19.20.09.44; Tue, 19 Feb 2019 20:09:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=A3JbZHRJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730452AbfBTEJO (ORCPT + 99 others); Tue, 19 Feb 2019 23:09:14 -0500 Received: from mail-qk1-f193.google.com ([209.85.222.193]:34139 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730434AbfBTEJN (ORCPT ); Tue, 19 Feb 2019 23:09:13 -0500 Received: by mail-qk1-f193.google.com with SMTP id a15so1152675qkc.1 for ; Tue, 19 Feb 2019 20:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xEHb23Q2l1fYivVKgVEsDTK7wpL+EEEEuo8D6bsBm4g=; b=A3JbZHRJxkJwV8HNuhnHXbDyTIP+RTNQzkhc2x3XKphSexBqf4wuhin81QHZEZngot QnyMIJAPqNF3zVB9NzqO65BWwX6NomXaVgjc5fnE7IlTDPQZiWcH9U7Is4ShPStkmTQQ bUq7nf+6uLHJjpTXhBXZSWxdyYG4jjk0yTHTk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xEHb23Q2l1fYivVKgVEsDTK7wpL+EEEEuo8D6bsBm4g=; b=gDg/ydhiQy0DpmdMknK6XzUBjGhgNNx66FLk4hmKbQyXLGa/Nl1tP7mXoNC7BLgPp+ rfrHlKY79XDm5Hkh4zuEEL2LNBCtR9WkLk0s9zdPsAJR+Jq0dOIeJv/unhHLiYHlnCp1 9ZNAa5ZXQImXFFH2qeJbQciJEVO5gy8u/ncdA2AttDAsZoQerrVEPC3ClvSjenzl5CkI xYtv4L7sJxxZHfi1IA34m1lUOlFbxv9Kt0VeUkuy/Aw22bq2Tj2BPIl1QTheDw1WBe48 l4PQLDGhNczwC6WncKDRiyucFjHzYrlAJy3wIkLtKLd5V2YUJ9XH6Q/OSo4+nri2BOJ2 EbJQ== X-Gm-Message-State: AHQUAubq9MrWPjUDO/9X7DJXNbszu6HPRE/exhDb7SUWzjQGaJPv0lZK 7hCJPgZwjElPgWc7HPnmdlZRrIGrchs= X-Received: by 2002:a0c:d0db:: with SMTP id b27mr74215qvh.223.1550635751731; Tue, 19 Feb 2019 20:09:11 -0800 (PST) Received: from joelaf.cam.corp.google.com ([2620:0:1004:1100:cca9:fccc:8667:9bdc]) by smtp.gmail.com with ESMTPSA id s19sm2024593qth.80.2019.02.19.20.09.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 20:09:10 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org, rcu@vger.kernel.org Cc: Joel Fernandes , paulmck@linux.ibm.com Subject: [RFC 3/5] sched/cpufreq: Fix incorrect RCU API usage Date: Tue, 19 Feb 2019 23:08:25 -0500 Message-Id: <20190220040827.136184-4-joel@joelfernandes.org> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: <20190220040827.136184-1-joel@joelfernandes.org> References: <20190220040827.136184-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Joel Fernandes Recently I added an RCU annotation check to rcu_assign_pointer(). All pointers assigned to RCU protected data are to be annotated with __rcu inorder to be able to use rcu_assign_pointer() similar to checks in other RCU APIs. This resulted in a sparse error: kernel//sched/cpufreq.c:41:9: sparse: error: incompatible types in comparison expression (different address spaces) Fix this by using the correct APIs for RCU accesses. This will potentially avoid any future bugs in the code. If it is felt that RCU protection is not needed here, then the rcu_assign_pointer call can be dropped and replaced with, say, WRITE_ONCE or smp_store_release. Or, may be we add a new API to do it. But calls rcu_assign_pointer seems an abuse of the RCU API. Signed-off-by: Joel Fernandes --- kernel/sched/cpufreq.c | 8 ++++++-- kernel/sched/sched.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/sched/cpufreq.c b/kernel/sched/cpufreq.c index 22bd8980f32f..c9aeb3bf5dc2 100644 --- a/kernel/sched/cpufreq.c +++ b/kernel/sched/cpufreq.c @@ -7,7 +7,7 @@ */ #include "sched.h" -DEFINE_PER_CPU(struct update_util_data *, cpufreq_update_util_data); +DEFINE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data); /** * cpufreq_add_update_util_hook - Populate the CPU's update_util_data pointer. @@ -34,8 +34,12 @@ void cpufreq_add_update_util_hook(int cpu, struct update_util_data *data, if (WARN_ON(!data || !func)) return; - if (WARN_ON(per_cpu(cpufreq_update_util_data, cpu))) + rcu_read_lock(); + if (WARN_ON(rcu_dereference(per_cpu(cpufreq_update_util_data, cpu)))) { + rcu_read_unlock(); return; + } + rcu_read_unlock(); data->func = func; rcu_assign_pointer(per_cpu(cpufreq_update_util_data, cpu), data); diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index d04530bf251f..2ab545d40381 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -2166,7 +2166,7 @@ static inline u64 irq_time_read(int cpu) #endif /* CONFIG_IRQ_TIME_ACCOUNTING */ #ifdef CONFIG_CPU_FREQ -DECLARE_PER_CPU(struct update_util_data *, cpufreq_update_util_data); +DECLARE_PER_CPU(struct update_util_data __rcu *, cpufreq_update_util_data); /** * cpufreq_update_util - Take a note about CPU utilization changes. -- 2.21.0.rc0.258.g878e2cd30e-goog