From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 B65B0132466; Thu, 15 Feb 2024 13:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708005097; cv=none; b=dlbr3Fzq7ezxPfcFNQTERtL6cRrUHtEhl04fBoZ4NsO8yi7zNyGmzoAwGY0Y+BxoxnmPAMRe9pjPRGs9+uEqI/Z8oJBT9LuFFi1P8jSdzEbWs0DPJ4SEJ+bJgQc54zYwCGiGtaxjzwbzMmBss6XHDuBe6Dz8osg/sk4sVVOg1Po= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708005097; c=relaxed/simple; bh=RzDVzAMbt/0O8rLENBgNMOIiu2ews2E1U5PQyx+Ji0k=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=duthAThQ7ST3q+IY+RI12/l/pID7L0Nmhb/kMpJj1MT6zmByzVq7B5SDMxItlbgOcnxPCuti79DYQfuELHiISOzmgiKhs7y/wXpy7QpK36g0g8faMeSDsaTLkhxhBB5wvP2OHOcegKXZUBQke9WW5qKyMLtN8/I9b3PlSb4JNs8= 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=U3huoTOG; arc=none smtp.client-ip=209.85.128.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U3huoTOG" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4121954d4c0so3306335e9.0; Thu, 15 Feb 2024 05:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708005094; x=1708609894; darn=lists.linux.dev; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=5t9mkBRSLuX6Whm+p+USkACVg0A1ZTFUPoQmMKDP/ks=; b=U3huoTOGv3ZZLKaGr6em9+pbTKZvNF/aEa3yZZzK3ZRb4mZRY724epLKmUh0pfz9lr Dii/Vy7BOWolB0lk8QrHWdXC/gKSrJmBeeu/E7+Y/UM97Lt2fpxMTZi6fi0pZ3mw/qyD jlzZyG3xPNPVfLYh8RXEfODhltQbOhq4Kxx4nqpe5EusVfNoB8Ofej2e7Uj6IKPMVqGy bpA3db/EGgQS75L3yDfqXQpcD2LIE1NSaJEQzEgwgV6HN8u1RD+lHixOw4qEWfcl3icl Z3JP5o/4Mnmr5f5hM7fYMg1DzMhNt3m1582gOA9ojFWJ7DNSSZtdNJEXfDti/bGnztRL VJKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708005094; x=1708609894; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=5t9mkBRSLuX6Whm+p+USkACVg0A1ZTFUPoQmMKDP/ks=; b=Ayegmfao7y5LVC1ng2jdCY6kcRy4Bgew9mlmKYYwE5qNTa1BmEUcSX2QRDGVBDXPId dIXDrhCADbrsvuuU5VVFJuhEkiAf5RkBjEBEMs2sKey8WKgXBtRw0HgP+Q0PtsKfmZGc vn+fny2UkXyHUvruXPBKxsPjM8zhkWN/Ajdxknsq3Ipr2EKQ5/E/QfrKgxvtpS0xeSh+ 3ZZ/DO0MFpDO5rpPcGtNwwmLlZj3q0em6eNMoRPz4jOthrIKH9kbrxuwwiOO7tQNQeEM 90dOS6Zi07jBZX+AQYQuo936Cl+WshEjS7Zyw8wBj4yMdt93ezg6eaPbMAciwa9D6PXO Vl6Q== X-Forwarded-Encrypted: i=1; AJvYcCW4KkEYzMbxMnZCCn4Do8u2RVOuLpzi5k3th4jexUEDxNAGw+ZSJpiOqviE0QjZY64jRtsaoK4y7qXq17s/L5V4PTH9NVaN1AATrtOeV738S0n73oknchcD4xoYIgcszYg1kxh84XMWklEJqkdqSZjKXxqIUK5Qo68m0tnAk41Uweq0rw== X-Gm-Message-State: AOJu0Yw5iIAKsgqU4IibP8K63I9bkneq1Ciwwp++LdrXhLCANwoHjz+4 oPNgH0tSJ3m3NBhdJpiLgVqYRWhpdJkBKGktuynTrugOUdkI2ffo X-Google-Smtp-Source: AGHT+IH7k9jN1LEPjklm49kSSJGmdKPhxpWNQecPQqPdKhvRMqEI/U195h3M4bWUY8DUrcLpEFVYaQ== X-Received: by 2002:a05:600c:3503:b0:412:7d0:d83 with SMTP id h3-20020a05600c350300b0041207d00d83mr1601111wmq.16.1708005093670; Thu, 15 Feb 2024 05:51:33 -0800 (PST) Received: from ?IPv6:2001:a61:3456:4e01:6ae:b55a:bd1d:57fc? ([2001:a61:3456:4e01:6ae:b55a:bd1d:57fc]) by smtp.gmail.com with ESMTPSA id i7-20020a05600c290700b00410add3af79sm5061337wmd.23.2024.02.15.05.51.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 05:51:33 -0800 (PST) Message-ID: <63b248efcbd62a121610cbf37ea0339bd87c99e7.camel@gmail.com> Subject: Re: [PATCH v6 003/164] pwm: Provide pwmchip_alloc() function and a devm variant of it From: Nuno =?ISO-8859-1?Q?S=E1?= To: Uwe =?ISO-8859-1?Q?Kleine-K=F6nig?= , Andy Shevchenko Cc: Alexandre Belloni , Michael Walle , Heiko Stuebner , linux-doc@vger.kernel.org, Linus Walleij , Paul Walmsley , Alexandre Torgue , Nicolas Ferre , Paul Cercueil , linux-tegra@vger.kernel.org, Conor Dooley , Thierry Reding , James Clark , Pavel Machek , Broadcom internal kernel review list , Guenter Roeck , chrome-platform@lists.linux.dev, Nobuhiro Iwamatsu , Fabio Estevam , linux-riscv@lists.infradead.org, Alyssa Rosenzweig , Jerome Brunet , Rob Herring , Samuel Holland , linux-samsung-soc@vger.kernel.org, Bjorn Andersson , Florian Fainelli , Jonathan Corbet , Sean Anderson , Benson Leung , Bartosz Golaszewski , Lee Jones , Jernej Skrabec , Jonathan Hunter , Hammer Hsieh , linux-rockchip@lists.infradead.org, Chen-Yu Tsai , Michal Simek , NXP Linux Team , linux-leds@vger.kernel.org, Ilpo =?ISO-8859-1?Q?J=E4rvinen?= , Alim Akhtar , linux-mips@vger.kernel.org, linux-sunxi@lists.linux.dev, platform-driver-x86@vger.kernel.org, linux-pwm@vger.kernel.org, Kees Cook , Sven Peter , Martin Blumenstingl , Ray Jui , Sascha Hauer , Jonathan =?ISO-8859-1?Q?Neusch=E4fer?= , Vladimir Zapolskiy , Hans de Goede , Mark Brown , linux-mediatek@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, Baolin Wang , Jonathan Cameron , Matthias Brugger , linux-amlogic@lists.infradead.org, Orson Zhai , Mika Westerberg , kernel@pengutronix.de, linux-arm-kernel@lists.infradead.org, AngeloGioacchino Del Regno , Neil Armstrong , Alexander Shiyan , Scott Branden , linux-gpio@vger.kernel.org, Daire McNamara , Chunyan Zhang , Hector Martin , linux-stm32@st-md-mailman.stormreply.com, Claudiu Beznea , Krzysztof Kozlowski , Fabrice Gasnier , Palmer Dabbelt , asahi@lists.linux.dev, Maxime Coquelin , Kevin Hilman , Shawn Guo , Anjelique Melendez Date: Thu, 15 Feb 2024 14:51:31 +0100 In-Reply-To: References: <9577d6053a5a52536057dc8654ff567181c2da82.1707900770.git.u.kleine-koenig@pengutronix.de> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 (3.50.3-1.fc39) Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Thu, 2024-02-15 at 13:01 +0100, Uwe Kleine-K=C3=B6nig wrote: > On Wed, Feb 14, 2024 at 02:49:26PM +0200, Andy Shevchenko wrote: > > On Wed, Feb 14, 2024 at 10:30:50AM +0100, Uwe Kleine-K=C3=B6nig wrote: > > > This function allocates a struct pwm_chip and driver data. Compared t= o > > > the status quo the split into pwm_chip and driver data is new, otherw= ise > > > it doesn't change anything relevant (yet). > > >=20 > > > The intention is that after all drivers are switched to use this > > > allocation function, its possible to add a struct device to struct > > > pwm_chip to properly track the latter's lifetime without touching all > > > drivers again. Proper lifetime tracking is a necessary precondition t= o > > > introduce character device support for PWMs (that implements atomic > > > setting and doesn't suffer from the sysfs overhead of the /sys/class/= pwm > > > userspace support). > > >=20 > > > The new function pwmchip_priv() (obviously?) only works for chips > > > allocated with pwmchip_alloc(). > >=20 > > ... > >=20 > > > +#define PWMCHIP_ALIGN ARCH_DMA_MINALIGN > > > + > > > +static void *pwmchip_priv(struct pwm_chip *chip) > > > +{ > > > + return (void *)chip + ALIGN(sizeof(*chip), PWMCHIP_ALIGN); > > > +} > >=20 > > Why not use dma_get_cache_alignment() ? >=20 > Hmm, that function returns 1 if ARCH_HAS_DMA_MINALIGN isn't defined. The > idea of using ARCH_DMA_MINALIGN was to ensure that the priv data has the > same minimal alignment as kmalloc(). Took my inspriration from > https://lore.kernel.org/r/20240209-counter-align-fix-v2-1-5777ea0a2722@an= alog.com > . The implementation of dma_get_cache_alignment suggests that not all > archs provide ARCH_DMA_MINALIGN? Also there is ARCH_KMALLOC_MINALIGN. > Hmm, don't know yet what to do here. Here it goes my 2 cents... AFAIK, ARCH_DMA_MINALIGN gives you the same alig= nment guarantees than devm_kmalloc() for instance. In some archs it will effectiv= ely be the same as ARCH_KMALLOC_MINALIGN. Now, I think it only matters if the owners o= f private data intend to have a DMA safe buffer in their structs. If that is the case= , we need to ensure a proper alignment for that structure. In IIO for example, the co= nstruct is like this: https://elixir.bootlin.com/linux/latest/source/drivers/iio/dac/ltc2688.c#L9= 6 The buffers should come last in the struct so they are alone in the line. I= n IIO, Jonathan has a strict policy for this. Like, even if you just want to trans= fer 2/4 bytes via spi, we need to make the buffer safe (apparently there are some c= ontrollers only doing DMA - even for small transfers). I would say that if unsure, go with ARCH_DMA_MINALIGN. You just might waste= some space in some archs. OTOH, if you think DMA is not really a thing for pwm c= hips, you might go ARCH_KMALLOC_MINALIGN. And since you already have your own PWMCHIP= _ALIGN, it should be easy to change the requirements down the road (if needed). That said, I'm not familiar with dma_get_cache_alignment(). - Nuno S=C3=A1