From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D27E1DDD0 for ; Tue, 31 Oct 2023 16:53:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xICgJ7CK"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="iK28zELF" Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6718D386F; Tue, 31 Oct 2023 09:52:51 -0700 (PDT) Date: Tue, 31 Oct 2023 17:52:45 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1698771167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aAD4PZZPRqR2qqqz8EHQ+Hmek2C4MZMfqNDCeCXy6SU=; b=xICgJ7CKCPP612P/GeGfpN7jEdqws8T9RkJ5uBAsvulrBrYFMRnTyjjb0KmmXf/beQw/IT zBym7HVItEc55tJ/UFv0ACD3UNdpV/tCxHgpi7LHAUv4l5L+5yI11v2GQctUM0Vhu8sJen hmqRnvBzszDs9QME3/Cp/aV9g4S5F9fbOQuO6MANPi2H1rIpNQOzdhuBEdbGJBBbL9e1Ea Fz/8eG7oFPAyFkYb4k0hEqlR7+hAmZsyFFbpWWSFnLWEIcruogq2uPRpVgIrgcFOeusJyz eOG2+RLIQo2QjDW1onheqOtT76r6FAOXEtv3tPF7BdsIwdN5+7RodzCLEY4kBQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1698771167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aAD4PZZPRqR2qqqz8EHQ+Hmek2C4MZMfqNDCeCXy6SU=; b=iK28zELFzCeYTkCb2gCtc0jpeTewvtKn2reWTzzJxY/VQxP9ZdPySwiv/alRNwHNnCXfvu nltW1oFCxqmJDrBg== From: Sebastian Andrzej Siewior To: Oliver Hartkopp Cc: Marc Kleine-Budde , linux-can@vger.kernel.org, netdev@vger.kernel.org, Thomas Gleixner Subject: Re: [RFC] Questionable RCU/BH usage in cgw_create_job(). Message-ID: <20231031165245.-pTSiGsg@linutronix.de> References: <20231031112349.y0aLoBrz@linutronix.de> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: On 2023-10-31 17:14:01 [+0100], Oliver Hartkopp wrote: > Hi Sebastian, Hi Oliver, > The content of gwj->mod can be overwritten with new modification rules at > runtime. But this update (with memcpy) has to take place when there is no > incoming network traffic. This is my assumption. But "no incoming network traffic" is not ensured, right? > > If not, my suggestion would be replacing the bh-off, memcpy part with: > > | old_mod = rcu_replace_pointer(gwj->mod, new_mod, true); > > | kfree_rcu_mightsleep(old_mod); > > > > and doing the needed pointer replacement with for struct cgw_job::mod > > and RCU annotation. > > Replacing a pointer does not copy any data to the cf_mod structure, right? Yes. The cf_mod data structure is embedded into cgw_job. So it would have to become a pointer. Then cgw_create_job() would create a new cf_mod via cgw_parse_attr() but it would be a new allocated structure instead on stack like it is now. And then in the existing case you would do the swap. Otherwise (non-existing, brand new) it becomes part of the new created cgw_job. The point is to replace/ update cf_mod at runtime while following RCU rules so always either new or the old object is observed. Never an intermediate step. > Best regards, > Oliver Sebastian