Received: by 2002:ab2:6991:0:b0:1f7:f6c3:9cb1 with SMTP id v17csp979827lqo; Thu, 9 May 2024 00:41:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQ0iZlMlg1uIaOwyPjkY3t5DQ9fw/gEbCIIXSh8Hci5UstdRjyLcpjYrzc5355qMoQRh+ZTzBCF5TLPxgoLu/QM9foujbyNulZumz1aA== X-Google-Smtp-Source: AGHT+IETbIOqAPW9KuXShQPyIESuH8Tyw6H5UlN+ee93R7tvkP/jMoKxjjB3oaobK/sL9nAv62d8 X-Received: by 2002:a05:6a00:69a7:b0:6f3:e6e0:d9fb with SMTP id d2e1a72fcca58-6f49c205ca8mr5461660b3a.11.1715240470711; Thu, 09 May 2024 00:41:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715240470; cv=pass; d=google.com; s=arc-20160816; b=qS7TGRC0X+wkSX0Vz5UWGWfO50cQ7MMlPlEKl5fsD78d0pjoO72cckEDgzPFVTTOBX lP+yluXPB5UM2ajBl1i6BDsKDirkhQpXx9sDJ0Y1a6Ap9PieKsDlHhVfv2RfW7vjupF2 S7NmsbakmCBcMxD+pWmzxw1pUZfOgDJT/wSeZJ5FEDvG/Y/c+4tYlogYDLHd/6Yfqd8N NAERySGCgEArJsj5YqlZQMWmp200CbSwuB8dR2zaOiktn9KA8cXrjjtvWniDDFv3JFaK M4CvmmbVCWu+wmWOQWSpZHphB1n5c7V5II8OJ+x+oNiaY8mfynY99fIFC61hmw0uvpBq YykQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:message-id:date :subject:cc:to:from:dkim-signature; bh=XKiSBeXRcVkUUdzkMxkRSXFHQgmY3xB5UE0hRtjhYGQ=; fh=IjTrs43vI69TB30WBo+Gp8Qf3Cog4AEJm93MaEMzKIQ=; b=Bwh7crymSdecEyaRVrgY9Nr0fFTYYG0Gm1hVfXRnE5P/trGKfJ9TPzZ+zE/YkWSx2q R2KmN5tTT3VSLVYY0kO8m5aCUZpixHSDUZbWTeTi5QSjn4VMlhZI61Dx9vcCGElW9Slc EtXm5CaN7fpi7rNR1U6AjndKydCXelTXCr4ksQYoMBq/EKnBWcbg7DbqykptXuzMMrtJ LXgb1OfcTAEs4VDXPu4X47pmbhokw4q2Q4C36lb+QKV4Pd1L66zT2hHSgjuGCGc5gSlT MjI63ygcyQQnUZ95zvgzKs0A5ytm6pPaHgFxI+K85FkYNjALH5fzEleopdOsOEyUJ+kv wm1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nshiaoNo; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63412863d87si816637a12.612.2024.05.09.00.41.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 00:41:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-174243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=nshiaoNo; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-174243-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-174243-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id EC36DB21F2C for ; Thu, 9 May 2024 07:41:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E211149C4C; Thu, 9 May 2024 07:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nshiaoNo" Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1949F2747D; Thu, 9 May 2024 07:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715240459; cv=none; b=tifoVr5FXz46442XTuJBoQQgbcud5T0b9CAs51d7yFWqk+2C/fJ4V3ndF5DrAJ80SHxC8AAJFUAr43ICEm9ecd5HPqVTWZNh0hBrw0VfVvvzaxYM+TfutSK0YNgMCXbv03mQ9r1ieitpemyMqj6MX62T5fhHhHCW3M1h1Lxr9Fs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715240459; c=relaxed/simple; bh=/Hk+HDUCApUoxRrI1cEqlgRHMEvYYo4NSGj6AmNqJRo=; h=From:To:Cc:Subject:Date:Message-Id; b=jBaNi9WGpisirLAfAGiisZVWkFhDEw4sEUgrsnDOfB+CjL5RxRYz7jo5ZF+3HgCuIOF/h8i4iDzTYJLDm5fbA9+SLBLQSVIDMGo+fUAFZBShj593xIiGBD+J9AY5Dy/u8AIxqICr7rEWvXsJTJmwxxc5y9wj6Wui0Tmlb8DkAxY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nshiaoNo; arc=none smtp.client-ip=209.85.215.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-61aef9901deso491091a12.1; Thu, 09 May 2024 00:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715240457; x=1715845257; darn=vger.kernel.org; h=message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XKiSBeXRcVkUUdzkMxkRSXFHQgmY3xB5UE0hRtjhYGQ=; b=nshiaoNoJHZhtaSYtDZwrThTj3gQTCbQlEuNPkhKmxGMHusLRozZZSRFx/ml6E7t9L Mux5J8FtznMQBNGHhyXquEqv2wREcotkLcRnMBy71Dm5mCq6lt6S45lCLhSqc3KJ1i7k frrfd8PrX7gi5uCwKxqav28pOAxRzmN105K1bVr+W0R2kw4GvNg4XZk2848lz4aQngEn XH2ht2aivgJZuyx6A2UzrK8quXIx9/zxPDyMrbmxjY3wW73uX5WmcCdfaXpW1yB99Rws ZgrQR1Y4m3pB/kHu5kHKJnBtrw+AkMZ0mBIq3RwyWsIW/AYRnRbwcp5AlErqeHrPQVDr H3iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715240457; x=1715845257; h=message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XKiSBeXRcVkUUdzkMxkRSXFHQgmY3xB5UE0hRtjhYGQ=; b=JbOJORqyl9Ybh3Q3bZxKPiTQD3F5lh52As3+t2bIeEz69LlOuy0HV7NjE2HXxAym+J pxES+RhUwJjENJ13UVjbqKAz7xmS1Pe/AN1TRBmoY13m7oiuHAmSvvfLyEy+4J5lS7jp 7y0z+kthLEBLJ0mTsYE2RI0w3u5I9nHVsVpaDU89pvj1w7ZTsawqrDvxm48cHHwt3c9E 6MyZECHbPF4T+gGKIv7pwnaNGOA/mGrlkzbb939tltLKQWWSKgXF8RvkNK6eMR2m7adj dTHZdKNpnlPEKoOtgYyNxIsrwE4ny06/2DsXhazLJFBWI96SuzBYnpxqae698LCLqJoy o0fg== X-Forwarded-Encrypted: i=1; AJvYcCWea6c3mut0Uro196W2g6WDaDerm5flQkIyJ15wqg/weEVdqPLD9ADmZYgf9ijHA9zfa9D1ENp3sYHXFx1fnSUtCu/sRkcsGodW6Poiq8ZXpdUlSa4lps2qGV02FigDKVgT X-Gm-Message-State: AOJu0YyG87l8iLYTtT4bibn6C7rSa3dVZeWhR7efOB4YkY0wFLZ87Qox S057U2rlpVoU0Xt+acFU2tFCx/5wkVpYRma+Ud93vP0Vjl3OFf/R X-Received: by 2002:a05:6a20:2d23:b0:1ad:5325:d9b7 with SMTP id adf61e73a8af0-1afc8ddc16cmr6140115637.52.1715240457349; Thu, 09 May 2024 00:40:57 -0700 (PDT) Received: from MSCND1355B05.fareast.nevint.com ([117.128.58.94]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0c256299sm7569085ad.286.2024.05.09.00.40.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 00:40:57 -0700 (PDT) From: Zqiang To: paulmck@kernel.org, frederic@kernel.org, neeraj.upadhyay@kernel.org, joel@joelfernandes.org Cc: qiang.zhang1211@gmail.com, rcu@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] rcu/nocb: Fix using smp_processor_id() in preemptible warning Date: Thu, 9 May 2024 15:40:46 +0800 Message-Id: <20240509074046.15629-1-qiang.zhang1211@gmail.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Currently, the this_cpu_ptr(&rcu_data) in rcu_rdp_is_offloaded() is called before the condition "!(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible())" is checked, and occurs in preemptible task context, this will trigger the following warning. [ 4.106221][ T18] BUG: using smp_processor_id() in preemptible [00000000] code: rcuop/0/18 [ 4.107796][ T18] caller is debug_smp_processor_id (lib/smp_processor_id.c:61) [ 4.108547][ T18] CPU: 0 PID: 18 Comm: rcuop/0 Not tainted 6.9.0-rc2-00079-g4c66bc7cacc0 #1 [ 4.109667][ T18] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 [ 4.111064][ T18] Call Trace: [ 4.111064][ T18] [ 4.111064][ T18] dump_stack_lvl (lib/dump_stack.c:116) [ 4.111064][ T18] dump_stack (lib/dump_stack.c:124) [ 4.111064][ T18] check_preemption_disabled (arch/x86/include/asm/preempt.h:84 (discriminator 15) lib/smp_processor_id.c:53 (discriminator 15)) [ 4.111064][ T18] debug_smp_processor_id (lib/smp_processor_id.c:61) [ 4.111064][ T18] rcu_rdp_is_offloaded (kernel/rcu/tree_plugin.h:27 (discriminator 1)) [ 4.111064][ T18] nocb_cb_wait (kernel/rcu/tree_nocb.h:936 (discriminator 2)) [ 4.111064][ T18] rcu_nocb_cb_kthread (kernel/rcu/tree_nocb.h:983 (discriminator 1)) [ 4.111064][ T18] ? nocb_cb_wait (kernel/rcu/tree_nocb.h:976) [ 4.111064][ T18] kthread (kernel/kthread.c:388) [ 4.111064][ T18] ? kthread (kernel/kthread.c:373 (discriminator 2)) [ 4.111064][ T18] ? kthread_complete_and_exit (kernel/kthread.c:341) [ 4.111064][ T18] ret_from_fork (arch/x86/kernel/process.c:153) [ 4.111064][ T18] ? kthread_complete_and_exit (kernel/kthread.c:341) [ 4.111064][ T18] ret_from_fork_asm (arch/x86/entry/entry_64.S:256) [ 4.111064][ T18] This commit fix this warning by priority check the condition "!(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible())" , to ensure whether the this_cpu_ptr(&rcu_data) can be executed in rcu_rdp_is_offloaded(). Fixes: 8feeeba60711 ("rcu/nocb: Use kthread parking instead of ad-hoc implementation") Tested-by: kernel test robot Signed-off-by: Zqiang --- kernel/rcu/tree_plugin.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h index 340bbefe5f65..1bb73466a8a9 100644 --- a/kernel/rcu/tree_plugin.h +++ b/kernel/rcu/tree_plugin.h @@ -28,8 +28,8 @@ static bool rcu_rdp_is_offloaded(struct rcu_data *rdp) !(lockdep_is_held(&rcu_state.barrier_mutex) || (IS_ENABLED(CONFIG_HOTPLUG_CPU) && lockdep_is_cpus_held()) || rcu_lockdep_is_held_nocb(rdp) || - (rdp == this_cpu_ptr(&rcu_data) && - !(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible())) || + (!(IS_ENABLED(CONFIG_PREEMPT_COUNT) && preemptible()) && + rdp == this_cpu_ptr(&rcu_data)) || rcu_current_is_nocb_kthread(rdp)), "Unsafe read of RCU_NOCB offloaded state" ); -- 2.17.1