Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2823929lqt; Tue, 23 Apr 2024 02:43:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW27/WFg+APPchSKfzbWBVbHxn2IuZDWkG6s5A19tD8zFIZxJ8yG0Za3ShDDafTFq/OL4KQlr9naZN50Szjk4AoKFAZ4Cs9lLx+7h8cJg== X-Google-Smtp-Source: AGHT+IGyILp0gFi2hSjIlcunYTWJKY8+/2rq/A7jPHS/4hdJ6dfOHyV6sQBCT7/Hcj6/hpX2BJ+F X-Received: by 2002:a05:6902:1b92:b0:d80:68d1:b826 with SMTP id ei18-20020a0569021b9200b00d8068d1b826mr13523841ybb.6.1713865383185; Tue, 23 Apr 2024 02:43:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713865383; cv=pass; d=google.com; s=arc-20160816; b=l0thyKRG6SxLjeFt6F+9srTV9jfUxdpp/jfJclMmkpcyddpEx0cYc9+0PH7VVZfa5w OKh+oug/ZvvNIpUJdeWeTFHzESd3rYLCCbeyR5f0xBGIplzQHzwXzyPlAY1P2r0QnXDW 4s9g6DYdtXd+A3chBFj9MqzeQHofwFvUuxhwicfFu0BVt0lYOJGA8ZOGx2eFJvlDRv3I dlbtGqw+7O6GveVSseJ4Ng2n9ptsoAirMKeO4NceosF6ySADKbcUgEXPgBZNJfJElJVt 8M24/DEL4X2rpDTmRKZGuYhhiI73Elou2Ke0zozvmIM5yGU265fymY/ag5lupY1p7lFb kSeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=wu3rM+NWF29G0mKPrRprfP3JFYvx5eY1+SSAupebpFo=; fh=PQh9x28GSs7iKaLfYEppaEeHcuRobSMERDjq4vD8crE=; b=oAasuZFavcFqHUu9u06I5mEeedV2gdSdgzwEokBGGUnWL/8FvrfLfEMdKEoR1dnU5S d9yHT/aSKnXPIwigyDuI+s9cvKOuWHlip2ttvnkLS4NVMRO0+ekeHArCqaE91XxmgE/E j7tp33HFELWJYqimZi+wgCGm0LD2gGKBKMfB0SWsl6TSrdFajf93oncZawYSOrX2Xajp 8LTACmC4FkXPJbE+5bm2UqbgyjOBGJqfqFnz7rElU/w5Wav7WrKOtQFCf4eQ4dNNzkuz f9pDB3U0iICFur/UAcNuFbSyULnMLZAX+CaSd6g2n2uBocRM2IzXWO46dJr+qKBcMgKk OPyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t3sUCms4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154801-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pt16-20020a056214049000b0069948077216si12547368qvb.267.2024.04.23.02.43.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Apr 2024 02:43:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-154801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=t3sUCms4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-154801-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-154801-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D69811C21901 for ; Tue, 23 Apr 2024 09:43:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 870A05FDD2; Tue, 23 Apr 2024 09:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="t3sUCms4" 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 64D015FBA0; Tue, 23 Apr 2024 09:42:42 +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=1713865362; cv=none; b=sbSUN88sQ07extI6xqCm7kPUho1wCtv63lujQp31+HreTJmaklr7rT/ta2jISH+NKWHpBk15dYRjXBwXdhx3DfJOw+wEyo+06rAPEpGKn4AQzZeGk4kbvKAUxAx1zdjLWCPSpsPqlQ/EXahnJPow4LHbd3cPx3wCggN6+2O1Tuc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713865362; c=relaxed/simple; bh=Ls/UifY5Dz1wJAlodWBpmzK5RW2Ga9GWujeLPVUWApE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=f5gekUayicBEMipOi1k8RV80kLKh5YCx4z9S2rY0/FopporVaYB0YnTSRAFf1Nx0x/i2ZXuBIvniZz1YldLSPJsUfH7Go/3ozH6O8M9M713I3Cf72pLsnwhrkcXz4JWd8W8NyJV4uTHIK5Kb1DobsiP3raIR4UW0YoxrVIWV+k4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=t3sUCms4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 235C1C116B1; Tue, 23 Apr 2024 09:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713865361; bh=Ls/UifY5Dz1wJAlodWBpmzK5RW2Ga9GWujeLPVUWApE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=t3sUCms4mYpMabtasGNhGocxGbl4sFKtiI5xMv3GUseqBt8syt6ltOpJw5h+mhkm9 aFw/mfjIIPxTOgX3aSOEh8CQ9MDDltzwMmO7D/WChVF9JWgnNlfVL892FNWud09dKb FSA60+icHOuitAqK+1F/rbKWBFDweKEPHeGK3ckswBDSwzaQs+WEOy7vQNwL9Y8luP xYndgb4wDz00KwaLl7Uhr0PI6sa3C6nq5pot9Z3qY6+LMLbM+8e/iSegNeK7NbIhHP +qqwJies09VxEMlzq045chEuTCG3ApsAakzZW3oCkuQ9Zt7KVPauqvMQOtnyBHP4I0 PSMBeRefA9q6g== Message-ID: Date: Tue, 23 Apr 2024 11:42:33 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 00/14] ASoC: Constify local snd_sof_dsp_ops To: Pierre-Louis Bossart , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Daniel Baluta , Kai Vehmanen , Mark Brown , Jaroslav Kysela , Takashi Iwai , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , Matthias Brugger , AngeloGioacchino Del Regno Cc: sound-open-firmware@alsa-project.org, linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20240414-n-const-ops-var-v1-0-8f53ee5d981c@kernel.org> <89f8f0be-2534-46c8-9058-cabea4f68568@linux.intel.com> <9d1eda85-32a0-4e53-86ca-ce3137439bd7@kernel.org> <138ac465-1576-4e86-a05d-63f8acc6fb70@kernel.org> <3acfbe3c-8b83-4c40-83c2-437f963fd25a@linux.intel.com> <7490bce3-3bd6-4beb-b8be-d47a6b0a30f0@kernel.org> From: Krzysztof Kozlowski Content-Language: en-US Autocrypt: addr=krzk@kernel.org; keydata= xsFNBFVDQq4BEAC6KeLOfFsAvFMBsrCrJ2bCalhPv5+KQF2PS2+iwZI8BpRZoV+Bd5kWvN79 cFgcqTTuNHjAvxtUG8pQgGTHAObYs6xeYJtjUH0ZX6ndJ33FJYf5V3yXqqjcZ30FgHzJCFUu JMp7PSyMPzpUXfU12yfcRYVEMQrmplNZssmYhiTeVicuOOypWugZKVLGNm0IweVCaZ/DJDIH gNbpvVwjcKYrx85m9cBVEBUGaQP6AT7qlVCkrf50v8bofSIyVa2xmubbAwwFA1oxoOusjPIE J3iadrwpFvsZjF5uHAKS+7wHLoW9hVzOnLbX6ajk5Hf8Pb1m+VH/E8bPBNNYKkfTtypTDUCj NYcd27tjnXfG+SDs/EXNUAIRefCyvaRG7oRYF3Ec+2RgQDRnmmjCjoQNbFrJvJkFHlPeHaeS BosGY+XWKydnmsfY7SSnjAzLUGAFhLd/XDVpb1Een2XucPpKvt9ORF+48gy12FA5GduRLhQU vK4tU7ojoem/G23PcowM1CwPurC8sAVsQb9KmwTGh7rVz3ks3w/zfGBy3+WmLg++C2Wct6nM Pd8/6CBVjEWqD06/RjI2AnjIq5fSEH/BIfXXfC68nMp9BZoy3So4ZsbOlBmtAPvMYX6U8VwD TNeBxJu5Ex0Izf1NV9CzC3nNaFUYOY8KfN01X5SExAoVTr09ewARAQABzSVLcnp5c3p0b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NwGL6tGt/6BkRikNOs7VDEa4/HlbaSJo 7FgndGw1kWmkeL6oQh7wBvYll2buKod4qYntmNKEicoHGU+x91Gcan8mCoqhJkbqrL7+nXG2 5Q/GS5M9RFWS+nYyJh+c3OcfKqVcZQNANItt7+ULzdNJuhvTRRdC3g9hmCEuNSr+CLMdnRBY fv0= In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 22/04/2024 23:24, Pierre-Louis Bossart wrote: > > >>>> There are multiple reasons and benefits for const, like compiler >>>> optimization, code readability (meaning) up to security improvements, >>>> e.g. by some GCC plugins or marking rodata as really non-writeable, so >>>> closing some ways of exploits. There are many opportunities here, even >>>> if they are not yet enabled. >>> >>> Possibly, but the SOF core does not know if the structure it uses is >>> rodata or not. Using the 'const' identifier would be misleading. >> >> How so? If core does not modify structure, it should take it via ops, >> just like 100 other widely known structures (see checkpatch). Why is >> this different? > > I don't understand "it should take it via ops" > > We are already fetching the structure with private_data. I meant, drivers using such core library functions or directly calling to the core, pass some private data structure with "struct foo_ops". Sometimes pass directly "struct foo_ops". This is happening everywhere and is common pattern. And everywhere we try to make it const, where following conditions are met: 1. the driver allocates "struct foo_ops" statically, 2. the driver does not change it, 3. the core (or library) does not change it. > >>>>> that's a different interpretation to the 'software' view you're >>>>> describing. "this structure will not modified by this function" is not >>>>> the same thing as "this structure CANNOT be modified". >>>> >>>> Yes, but can we please discuss specific patchset then? Patches which >>>> change pointers to const have one "interpretation". Patches which modify >>>> static or global data have another. >>> >>> Just look at sound/soc/sof/intel/mtl.c... The core will sometimes use a >> >> That's a driver (or specific implementation), not core. > > You are making an assumption on what the SOF core is. The core is used > by ACPI or PCI drivers as a library. The structures are all allocated in > ACPI/PCI drivers and passed to the core library. The same as everywhere else. The distinction, that this is "library" and in other cases often is "core framework" or "subsystem", does not matter. Behaves the same. > >>> constant structure and sometimes not, depending on the PCI ID reported >>> by hardware. This was intentional to override common defaults and make >>> the differences limited in scope between hardware generations. >> >> >>> >>> int sof_mtl_ops_init(struct snd_sof_dev *sdev) >>> { >>> struct sof_ipc4_fw_data *ipc4_data; >>> >>> /* common defaults */ >>> memcpy(&sof_mtl_ops, &sof_hda_common_ops, sizeof(struct >>> snd_sof_dsp_ops)); <<<< THE BASELINE IS CONSTANT >> >> Yes, I saw it and such users are not changed. They won't receive any >> safety. But all others are getting safer. > > > Maybe there's a misunderstanding on what the 'SOF core' is. This is just > a helper library that are used by the PCI drivers. The core has zero > knowledge on anything really. The "core" or the "library" either modifies the structure or not. That is only that matters from the core point of view. > >> I really do not understand what is the problem here. In entire Linux all >> of such changes are welcomed with open arms. So what is different here? > Adding 'const' at the SOF core level does not mean that we can treat > structures as rodata. It only means that the structure is not modified > by the core library. Not the same thing. Are we talking about basic C now? Of course it does not mean that and I already explained what is the goal of this - the static or global memory in the driver can be moved to rodata. Just like everywhere else. I keep repeating the same arguments and keep repeating the same: please bring me any argument why this should be different than all other 100 structs (or more, I count based on checkpatch). So far you did not bring any argument for this, so I don't know how to provide any other technical feedback. According to my knowledge and easily visible here, this is exactly the same as in all other cases. Drivers have some static or global struct which can be moved to rodata, because nothing modifies it. Best regards, Krzysztof