From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53570C27C4F for ; Mon, 24 Jun 2024 00:27:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FBC56B0462; Sun, 23 Jun 2024 20:27:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6ABAC6B0463; Sun, 23 Jun 2024 20:27:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 54C066B0464; Sun, 23 Jun 2024 20:27:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3592C6B0462 for ; Sun, 23 Jun 2024 20:27:12 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 76A951209CC for ; Mon, 24 Jun 2024 00:27:11 +0000 (UTC) X-FDA: 82263892662.16.3D4A043 Received: from out-187.mta0.migadu.com (out-187.mta0.migadu.com [91.218.175.187]) by imf09.hostedemail.com (Postfix) with ESMTP id F0735140002 for ; Mon, 24 Jun 2024 00:27:08 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i9qXaJFI; spf=pass (imf09.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1719188823; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sfBODeRMCmHf0D59NB4VFxImeuRpP9l3RcbtejptEbM=; b=1J1yh4V20lOwwegDSQaMtssusgLYMVbBWoZm5hAyZ803ONwEI+bqIPzx0S+MJ6m1HKUz3p Q3RV/UjBiT7e7p82xmXL4pYZqbJ9sJgGQwwv4BURHwWad9A5RTHVH/voQl/vIIdBLrGeIZ cxpvTAEBHRQcaZSpVw4cAS23byyQXmQ= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=i9qXaJFI; spf=pass (imf09.hostedemail.com: domain of kent.overstreet@linux.dev designates 91.218.175.187 as permitted sender) smtp.mailfrom=kent.overstreet@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719188823; a=rsa-sha256; cv=none; b=PN3SCAEAKhuBPS7vEArtOrJ/Zyl54smK2dzjOX/MKPkg70aQCf1mSM+FD2BYVE9xawnrHM j6OwDjFypPejSsMvKPcURXNqR1rNK5y6W2j/r50LsrRIh2Mj/j4YmZPcVhuSqF3ESQ1eJm yYfCf7Tk3kwtRvJLZiICFFgKBUsTVPc= X-Envelope-To: tglx@linutronix.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1719188826; 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=sfBODeRMCmHf0D59NB4VFxImeuRpP9l3RcbtejptEbM=; b=i9qXaJFIM037T4xJ2YTfT/z1sFypaAX41vPyefFqjROA2U0FvkOU9mjNkciQ+op4EqykLT mXQVlR/F/JG53YyNBNkOu22V26tWM/DuU/lfe/t904NMtmelY1lrxVWT1RJiJtZK0tCADG ZrZYAJXQzjiO0WmGgTM6fRvtKpKVbQM= X-Envelope-To: linux-fsdevel@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: axboe@kernel.dk X-Envelope-To: brauner@kernel.org X-Envelope-To: viro@zeniv.linux.org.uk X-Envelope-To: bernd.schubert@fastmail.fm X-Envelope-To: linux-mm@kvack.org X-Envelope-To: josef@toxicpanda.com Date: Sun, 23 Jun 2024 20:27:02 -0400 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Kent Overstreet To: Thomas Gleixner Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Jens Axboe , brauner@kernel.org, viro@zeniv.linux.org.uk, Bernd Schubert , linux-mm@kvack.org, Josef Bacik Subject: Re: [PATCH 3/5] fs: sys_ringbuffer Message-ID: References: <20240603003306.2030491-1-kent.overstreet@linux.dev> <20240603003306.2030491-4-kent.overstreet@linux.dev> <87frt39ujz.ffs@tglx> <87a5jb9rnk.ffs@tglx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87a5jb9rnk.ffs@tglx> X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: F0735140002 X-Stat-Signature: h6xobykwgembs1i6yefufy5wgzy7hhh8 X-HE-Tag: 1719188828-189036 X-HE-Meta: U2FsdGVkX18LD9VOJTe3Dn0yayA7EXZbZAHqZwvw2YuzBaS36AAb+WkkQs4YRZDi67MUFEkaPvvCrfkOeQXLts5HYyY8CmcFF2CNxWHi39NN4fEnVx0Oycp9VRcw9wqB0mnZrkFbXCfy4Z1UJm88X8t/UV4EdT2hbuptEr+0eoOIatNdGPZRQ0N43kz3Ino74mmDQVHk3tzXZA97y4XhFVNqz1Ul5Gk6UReL9D5sCZA9fIYsamWZ6R1rZ30KKv5A+U5CHBcA7BAc550au1182+qBqqDj7ZtmVcNmv7dfzLVFQLI6q2ifx34EiC6cEepX02b3D3pUfHghfTopCIvh8WAHeUIvthhT6cYTdvP38e5ARV551Zw0MJ1nBCYZyzjHjnNkurZGxI88CwUDV2QkX9NU7OhBgXZliCvFKqUKT4o0qQESMKEJKBuCrWTLuFK2gTW7tl+2Loe9gLqE6zZ51GSTu7aK9KqldkgIrm5AXvQ4BlUPSRySM2TAWjBqrrbRLp07rzDcBWRAUimUFqFmpQG+i7Yh+rfeZvxv9D0cQKvsBYiGkyMTiAhazEmyTIfhweml1U/oQXGSTRArdyVW1K6UNlXNm9oiQ2OrScHskzy43hWrSJzRtKsNNIIzT2ochxB67tfnTE98Er2vEnmLN/OmIfuXpUZaeZ3TfOMrHIb/nw0qoO6GF99jkqtpDnT95o52AqR5U8bbtT1k51pxVYhteENZ0Jxz8PYwG2+zkxGBGTgd8S1wTKzIFUE6RLjIiSqI7bMgZ1bZc9zz34zAMPSDRZu3VgAIH0XNJJxHz4o/VZSf62PmSjNW2L/+kSoZ2mB8v5Z8HjQLzhgtNAUGT5Q6Wwrfg5kO3sD4geBn2pAXVscApvJiqCfRQL+yC9sOvg3YLik1cSagsxoQFC7/Buf5efGeDuLO1ruFIy1kh+Oxrh3B/sP+sPA47jzSoDGBrnkETUTj4GPU7wRQ0zX uc0S0x8W IC6IaXIdEu2aOXkd/QqfcD2oay5WMEsHM+7ge9dSdDygORVpJfuGmHdxeLw56ZXLNDjCQVSMFBhI1ead6lJFcDEFcP9qdMQKJukSZG7+ULoblFf1dCgMHpK0lKVbs76LUyaml/jIYj/doxvwblWtF6Q+JWdnk0uIz7VItxCnRkzq2fw0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Jun 24, 2024 at 01:16:15AM +0200, Thomas Gleixner wrote: > Kent! > > On Sun, Jun 23 2024 at 18:21, Kent Overstreet wrote: > > On Mon, Jun 24, 2024 at 12:13:36AM +0200, Thomas Gleixner wrote: > >> > + /* > >> > + * We use u32s because this type is shared between the kernel and > >> > + * userspace - ulong/size_t won't work here, we might be 32bit userland > >> > + * and 64 bit kernel, and u64 would be preferable (reduced probability > >> > + * of ABA) but not all architectures can atomically read/write to a u64; > >> > + * we need to avoid torn reads/writes. > >> > >> union rbmagic { > >> u64 __val64; > >> struct { > >> // TOOTIRED: Add big/little endian voodoo > >> u32 __val32; > >> u32 __unused; > >> }; > >> }; > >> > >> Plus a bunch of accessors which depend on BITS_PER_LONG, no? > > > > Not sure I follow? > > > > I know biendian machines exist, but I've never heard of both big and > > little endian being used at the same time. Nor why we'd care about > > BITS_PER_LONG? This just uses fixed size integer types. > > Read your comment above. Ideally you want to use u64, right? > > The problem is that you can't do this unconditionally because of 32-bit > systems which do not support 64-bit atomics. > > So a binary which is compiled for 32-bit might unconditionally want the > 32-bit accessors. Ditto for 32-bit kernels. > > The 64bit kernel where it runs on wants to utilize u64, right? > > That's fortunately a unidirectional problem as 64-bit user space cannot > run on a 32-bit kernel ever. Ah! Yeah, that's slick. Your code doesn't quite work though; with this scheme, we can't just subtract the 64 bit head and tail to get the curretly used space in the ringbuffer, that'll give the wrong answer if the other end is 32 bit. But we just need to mask off the high 32 bits (after the subtract, even), and we can still use the full 64 bits for ABA avoidance. I think I like it...