Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp356193lqp; Thu, 4 Apr 2024 15:51:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWQBwC7gl8OePkLClcT3a8b+5iA6taWQxy4zo9o/ejpVUzguIOH9OGL1N3in7VKi0U+Syhp2YvrAXhmhXaTb9wnulnXbRpHVwsPIzWoCQ== X-Google-Smtp-Source: AGHT+IHdLkIHeWlUWmEZyAiJETqXCLk9x1f0u9Fnv136nRvE0LgPyYzUsdAW/xoDpROLD6KEHHbu X-Received: by 2002:a05:6402:1c07:b0:56e:2d0a:b9f6 with SMTP id ck7-20020a0564021c0700b0056e2d0ab9f6mr352461edb.14.1712271091018; Thu, 04 Apr 2024 15:51:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712271091; cv=pass; d=google.com; s=arc-20160816; b=tSilGS5JeyyJbBx3Jm84JMM12Vs2gZXO/nouY7fq9N0oBvmIAfJ0f40nfkMksR/ES9 hbzkeIWwfGHsZE87ve8o2djysbRsELRvuylZ7iWdbByvx4ZVqEdlYo/UA4E1+Uk5LbSz udKb2n9MYvbY4t/chdTlM378/Tonr2eex2TGNoUnojdph6lH3cTo6dOFJWIXb5Vdpz9s oo7DrPD2CRVlBGmoAtTptPUU0qO7HDeTFlpLGD1tPpHT5CGxi2mb5Jeyxe56oLPtnge4 vVBkmG5VLP6rE8+uQt91oqDi17lpz8+3DMO+GfI0UjbhIuchBMpk45GiiEp2gnQlzq8G JGkQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=WAtYWfGBb4pA6wo5Aq2hq2Ig+N0guFLyLszlgTaf4nk=; fh=ZqouD5Imx9JUFV5d7k91Pc3jIQ/Xk6eDj6EWQoaj5Vw=; b=J9pNaNfWjKOSDrelu2n0P8sCpD/DUcvY3nLOFE/yt0LrZYnDZL6BcQrG05wXBdyb4P 5/OXOmgqg7bRbx78bJ0C4H9w1fY0iyve0jaq+7z+eYYZQUPw74Qyf9NI8aR48sxi2r9s vx3K5ZUBkev0opAXKUl/TjJ/8ZE87OAvT0DcsjZBWmX1CcMpA8WsV9fwx91wfFCqsi4w ueG7XO8FyEzyGu4b7qVJGJB9Qr4Xg8e+elMCw/HggQpUpc6pSvGg8yyKAWAQ/d1rhWMo 0OSy9ZcEHpYKiTkyXdvPUVImy2mq91s42SrowSYh6LnQGHR7rSZh9MnVjz+mVDI8xKcR 6j6g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=huuEDqmt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id m20-20020a509994000000b0056e05a21726si106633edb.290.2024.04.04.15.51.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 15:51:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=huuEDqmt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-132221-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132221-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id BC31D1F21756 for ; Thu, 4 Apr 2024 22:51:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14DBF70CDE; Thu, 4 Apr 2024 22:51:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="huuEDqmt" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 3CACE6F510 for ; Thu, 4 Apr 2024 22:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712271083; cv=none; b=PuI/oHrqkA6+rQIJgUj4dKremYID1MSXBcXecInOJ8s/zJVxv2a1SG6w1NAM7Nf8nnLCrQ6Lq2bstWjZZVWn162ENMMYWWNRMhr6f7CmuTUhzL+RsNlJI6k75UMn7h/clN8KHaL+LM/RA9djwIppRvjnvci2iic4jxv5yUPXjtY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712271083; c=relaxed/simple; bh=2UN5GNAtSEXlpTizfwZqp5koDj5Ow1gXjAgNuS85JkE=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=o+M8D635M/Ya1I5XUJTRvwu0HY4I+79tGC1f0ZuvNg+X616vpgf8YtQ2laETAAujQUCCf8ns0dk8uqBq1uw0/Gog/8QL11/ac6IKJR8TuX3L0hHH6WbU7C1yPgnb+rTrlAh3E/QUtQ1in/AVWj4pTRwvADqVe6njIPJSl26Tz0w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=huuEDqmt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5612C433C7; Thu, 4 Apr 2024 22:51:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712271082; bh=2UN5GNAtSEXlpTizfwZqp5koDj5Ow1gXjAgNuS85JkE=; h=Date:From:To:Cc:Subject:Reply-To:From; b=huuEDqmtN8iA/Xlr6Lm8EbdM/UjkEeuCdKvRGDv8LaRhDpN5wpoc4NAX495xlbFKo DGjPxlB6nrvQzLNuDJ7gDFsepu7wbF1wjS29cY1yb1pH8lRc2n7aN7h7EJVZUljN4d VSkIaTi6lpgdB4xytWaaWy1rKGzOGl9kqt4MJNW82ArQxOG4fA9WMmSgYYn8g2QrpL pR8FZnh+8QP7MgLwBZ6tNkha21QRTQkYuuXtamyVsqQ2HeOhZhGx6/GWtCE0ep3fLM WXCdPQkSu078Sc8f8XQ341bVucchEaVou+4dPCjXmXrjpGHsrYOkPbzQ9rh5geCI0j ssLlntjqdP8tw== Received: by paulmck-ThinkPad-P17-Gen-1.home (Postfix, from userid 1000) id 68762CE0D0C; Thu, 4 Apr 2024 15:51:22 -0700 (PDT) Date: Thu, 4 Apr 2024 15:51:22 -0700 From: "Paul E. McKenney" To: Julia Lawall Cc: Arnd Bergmann , linux-kernel@vger.kernel.org Subject: Finding open-coded workarounds for 1/2-byte cmpxchg()? Message-ID: Reply-To: paulmck@kernel.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hello, Julia! I hope that things are going well for you and yours. TL;DR: Would you or one of your students be interested in looking for some interesting code patterns involving cmpxchg? If such patterns exist, we would either need to provide fixes or to drop support for old systems. If this would be of interest, please read on! Arnd (CCed) and I are looking for open-coded emulations for one-byte and two-byte cmpxchg(). Such emulations might be attempting to work around the fact that not all architectures support those sizes, being as they are only required to support four-byte cmpxchg() and, if they are 64-bit architectures, eight-byte cmpxchg(). There is a one-byte emulation in RCU (kernel/rcu/tasks.h), which looks like this: ------------------------------------------------------------------------ u8 rcu_trc_cmpxchg_need_qs(struct task_struct *t, u8 old, u8 new) { union rcu_special ret; union rcu_special trs_old = READ_ONCE(t->trc_reader_special); union rcu_special trs_new = trs_old; if (trs_old.b.need_qs != old) return trs_old.b.need_qs; trs_new.b.need_qs = new; ret.s = cmpxchg(&t->trc_reader_special.s, trs_old.s, trs_new.s); return ret.b.need_qs; } ------------------------------------------------------------------------ An additional issue is posed by these, also in kernel/rcu/tasks.h: ------------------------------------------------------------------------ if (trs.b.need_qs == (TRC_NEED_QS_CHECKED | TRC_NEED_QS)) { return smp_load_acquire(&t->trc_reader_special.b.need_qs); smp_store_release(&t->trc_reader_special.b.need_qs, v); ------------------------------------------------------------------------ The additional issue is that these statements assume that each CPU architecture has single-byte load and store instructions, which some of the older Alpha systems do not. Fortunately for me, Arnd was already thinking in terms of removing support for these systems. But there are additional systems that do not support 16-bit loads and stores. So if there is a 16-bit counterpart to rcu_trc_cmpxchg_need_qs() on a quantity that is also subject to 16-bit loads or stores, either that function needs adjustment or a few more ancient systems need to lose their Linux-kernel support. Again, is looking for this sort of thing something that you or one of your students would be interested in? Thanx, Paul