Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp741266lqb; Wed, 17 Apr 2024 09:22:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWUUynOmxxQUbdBKrKj3Fz91sACWGh+sVpJJ5C5ltZgY6nKi5IZYyN8bJaPsFbVDMVbYSqLO7yYbU8AcmuS1x44lUZDKn7ZhszC598i0A== X-Google-Smtp-Source: AGHT+IFoOwn8OeMBg1dBh6Lexx2a4THjEIiBAy8Xyn2I7B7TC8jPcR2dAxHAaANgPZWO1U6JR6wm X-Received: by 2002:a05:6a00:2407:b0:6ea:c3bc:2031 with SMTP id z7-20020a056a00240700b006eac3bc2031mr23101pfh.7.1713370950409; Wed, 17 Apr 2024 09:22:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713370950; cv=pass; d=google.com; s=arc-20160816; b=lJwKjEoJxmzfJRDr/a6CSoNS+jITRK2R8YEN9jAAxohLCXCm+/RxRL/MHiSnX2H0fb Z81ugeVgULrH2lj/prSxSX4j86j/uy7gfRo420UtsmTnGo5RIxKM3ALuejK+Yhe40c+d h9flHfXho9sZoIMhEZNAVG7hEhtAKIcpV7k7aZiSoehBKaAT2CdQBAW/9dOXiG2fCnKf oNzj4A+jbBYioKdKJAXyGmdNn+VKzRB8/h60DFnT928vKoh3iF8WdWM3orjymyIgVAhD QcsDj4plVBTLjc3nEMCcWgZ4wFakO9mQe20cdok+7Nl9z0F2LYNqAawxulrY5feqXq0R pwCw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=Nq5XbwnS+WFQsMRXNS2/WLzQBLtULwJiFEsG0xNKfbk=; fh=FvxmfBSDXAVnuf9cXpIDKSe8pcQ/lZNNTGKoZ8JUmRI=; b=O9N5rOwuAtI58waTGtVNLfC2FgdZesWq98E7N5B5VqZAZ1KPL8cbrge9PvRG0fWyrS WiwvVmDOlRkm/7wrASLrmuNTDxBXQxQaZLSaJfl01WktXgnDL9wJNQODni2Z/bq+tlMh oc8u2qoohteoyNeAJXjhJkULhnGP1w089dtFmjHge77wPRD8Yj3pXgo8XByFJDZmC/SF URrQdObhwoLJGaX7wT7mLbdSveldHtWesw7ICEPm5jgjX5RTBnHJQNAoWiUlbZpcBBAD p6cU37IxVUbidUwqW/aai9HtJqQYcRpn8gq3tQhGAihCR4jhwigEsNPdVywRmAtvvQ7+ xS8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fgH0htXd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-148872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148872-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id j23-20020a634a57000000b005e4a4aa2528si11656098pgl.48.2024.04.17.09.22.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Apr 2024 09:22:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-148872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=fgH0htXd; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-148872-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-148872-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BBF2A284EE2 for ; Wed, 17 Apr 2024 16:02:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 33AF21482E8; Wed, 17 Apr 2024 16:02:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="fgH0htXd" Received: from mail-lj1-f180.google.com (mail-lj1-f180.google.com [209.85.208.180]) (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 B150F1487D9 for ; Wed, 17 Apr 2024 16:02:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713369765; cv=none; b=a76wLKKq0y81TAK+NfWAb5Z9/dAqaVgCB6FvdEutavDqXQvFHpcEj0ljtJyXJmTi0A2ypOzMbgREZUWSn3AI+kyj9DZDp7DqUhZ+ba6EtgFukNCrsTLCft5Az8e2pLbDU8EPcOVQ2EaSBq48f5JzbpQFG5lXmvOygJE43pJBDCg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713369765; c=relaxed/simple; bh=9i5GLFu0+txx2oabKEnFrp3VW7oPnVCY8MLnNIpHG6Q=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=DIBgaj9wpx1E0Pku+jeOtuhyAHWF8u0rUXVV8v5atlOcQB1ZNY6pSX+A16ysaN0Ff6TNv6pzdWHABZ1fkx1ibaiMyeiOOQj2Av9IOA+ZO30H2Lkibs54MNFbyFit+tCsXo665xHoN7lCrqKKZ8/P6jRqGg1gZVXuxFUuaYxmclQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=fgH0htXd; arc=none smtp.client-ip=209.85.208.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-lj1-f180.google.com with SMTP id 38308e7fff4ca-2db13ca0363so18992611fa.3 for ; Wed, 17 Apr 2024 09:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1713369762; x=1713974562; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Nq5XbwnS+WFQsMRXNS2/WLzQBLtULwJiFEsG0xNKfbk=; b=fgH0htXdSSmMkNY4k7dHlDgp2o3+1XlO+F9VYbFNb/a8jtysrIUYzJmEWrrFSZeUb/ 9T3ydVYP2tCiJECXf4t0k84xgJBUJD7Ymx5CPJA3Y6KLsPd2HUxl8KWtm2D4XkxFu7ca AvwMY8KRFCHPkkqT8+CcRjWm0sQAkdJfcmKRwABZhRzmHHK640gDwkdnebz5j6Wxv+9b RcnpoirM+nGWuYhkJw/QlA3yNPWavPwNNBjuYKi2C1ATmLLdAcGUsjtb3ptoxAMrxbg2 /ZJYqxVg263o/zfrUofXA5crcV34dXne4hWqwYf6tbaY7UiI1wSU4fUBAl/c4QRs3vnw lvfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713369762; x=1713974562; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Nq5XbwnS+WFQsMRXNS2/WLzQBLtULwJiFEsG0xNKfbk=; b=aexHuH3hfB9OeOqto9k3C/5QYtTjIqDAAt3iEbRIEQh9kw8Wa8/yq16J5qRRhJmkhf +9bmA5uRBtaP8RmKIGYp3enGoTaSCLdx/3hO9l6NQ9ylzBjq0dLmCUG7qYTliHjCr42s 6N+nR9nDad8KiT9QUL+0irca3LJiAjsHloLsVXW6m4CvgMCwrefqViHJPmyqMmxIYc9D TJ2zkUb8y3OzRcWRaE+UUhZXMiB/uxopNAvqRMv6u3igqIqDNRt4fIGeW0qa1IWL7VMq LsadPAhHEfogthHrYYeEAHjkI2PpVPo/eqeDvhx3RG4wbfR8IlqQHlON5Q8nUOAnJ3Cs 3Hvg== X-Forwarded-Encrypted: i=1; AJvYcCVAia/Omc280ykqbg1WAugi7EsO4cQVrVs/6AuC29U7bbjwK+zKJI/5z9xu4f2LIyR9pIAciZaM7G7BgGDliWNFBnBPhIK5LlwrCWEe X-Gm-Message-State: AOJu0YzoeJoK/zVGVUdXNugbiWR/Cfmc/YlLTDj2uvygK9r5y3aeUFK1 NnEeIXawV8/zGYPm9pxsvAxVB3gwpBw0ORlojcav9DXyA+2DA2AaqXuJ1i6h6ZaBjuplJF0kXUx x1lAt1tEShdY4Cqb9RFME5XuRYHmCnTx4WMVAKg== X-Received: by 2002:ac2:538c:0:b0:515:9c73:e29a with SMTP id g12-20020ac2538c000000b005159c73e29amr12657720lfh.66.1713369761613; Wed, 17 Apr 2024 09:02:41 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240411-dev-charlie-support_thead_vector_6_9-v1-2-4af9815ec746@rivosinc.com> <20240412-tuesday-resident-d9d07e75463c@wendy> <20240412-eastcoast-disparity-9c9e7d178df5@spud> <20240412-chemist-haunt-0a30a8f280ca@spud> <20240413-sharper-unlivable-5a65660b19e2@spud> <20240416-husband-flavored-96c1dad58b6e@wendy> In-Reply-To: From: Evan Green Date: Wed, 17 Apr 2024 09:02:05 -0700 Message-ID: Subject: Re: [PATCH 02/19] riscv: cpufeature: Fix thead vector hwcap removal To: Charlie Jenkins Cc: Conor Dooley , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , =?UTF-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= , Jonathan Corbet , Shuah Khan , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Apr 16, 2024 at 9:25=E2=80=AFPM Charlie Jenkins wrote: > > On Tue, Apr 16, 2024 at 08:36:33AM +0100, Conor Dooley wrote: > > On Mon, Apr 15, 2024 at 08:34:05PM -0700, Charlie Jenkins wrote: > > > On Sat, Apr 13, 2024 at 12:40:26AM +0100, Conor Dooley wrote: > > > > On Fri, Apr 12, 2024 at 02:31:42PM -0700, Charlie Jenkins wrote: > > > > > On Fri, Apr 12, 2024 at 10:27:47PM +0100, Conor Dooley wrote: > > > > > > On Fri, Apr 12, 2024 at 01:48:46PM -0700, Charlie Jenkins wrote= : > > > > > > > On Fri, Apr 12, 2024 at 07:47:48PM +0100, Conor Dooley wrote: > > > > > > > > On Fri, Apr 12, 2024 at 10:12:20AM -0700, Charlie Jenkins w= rote: > > > > > > > > > > > > > This is already falling back on the boot CPU, but that is= not a solution > > > > > > > > > that scales. Even though all systems currently have homog= enous > > > > > > > > > marchid/mvendorid I am hesitant to assert that all system= s are > > > > > > > > > homogenous without providing an option to override this. > > > > > > > > > > > > > > > > There are already is an option. Use the non-deprecated prop= erty in your > > > > > > > > new system for describing what extesions you support. We do= n't need to > > > > > > > > add any more properties (for now at least). > > > > > > > > > > > > > > The issue is that it is not possible to know which vendor ext= ensions are > > > > > > > associated with a vendor. That requires a global namespace wh= ere each > > > > > > > extension can be looked up in a table. I have opted to have a > > > > > > > vendor-specific namespace so that vendors don't have to worry= about > > > > > > > stepping on other vendor's toes (or the other way around). In= order to > > > > > > > support that, the vendorid of the hart needs to be known prio= r. > > > > > > > > > > > > Nah, I think you're mixing up something like hwprobe and having > > > > > > namespaces there with needing namespacing on the devicetree pro= bing side > > > > > > too. You don't need any vendor namespacing, it's perfectly fine= (IMO) > > > > > > for a vendor to implement someone else's extension and I think = we should > > > > > > allow probing any vendors extension on any CPU. > > > > > > > > > > I am not mixing it up. Sure a vendor can implement somebody else'= s > > > > > extension, they just need to add it to their namespace too. > > > > > > > > I didn't mean that you were mixing up how your implementation worke= d, my > > > > point was that you're mixing up the hwprobe stuff which may need > > > > namespacing for $a{b,p}i_reason and probing from DT which does not. > > > > I don't think that the kernel should need to be changed at all if > > > > someone shows up and implements another vendor's extension - we alr= eady > > > > have far too many kernel changes required to display support for > > > > extensions and I don't welcome potential for more. > > > > > > Yes I understand where you are coming from. We do not want it to requ= ire > > > very many changes to add an extension. With this framework, there are > > > the same number of changes to add a vendor extension as there is to a= dd > > > a standard extension. > > > > No, it is actually subtly different. Even if the kernel already support= s > > the extension, it needs to be patched for each vendor > > > > > There is the upfront cost of creating the struct > > > for the first vendor extension from a vendor, but after that the > > > extension only needs to be added to the associated vendor's file (I a= m > > > extracting this out to a vendor file in the next version). This is al= so > > > a very easy task since the fields from a different vendor can be copi= ed > > > and adapted. > > > > > > > Another thing I just thought of was systems where the SoC vendor > > > > implements some extension that gets communicated in the ISA string = but > > > > is not the vendor in mvendorid in their various CPUs. I wouldn't wa= nt to > > > > see several different entries in structs (or several different hwpr= obe > > > > keys, but that's another story) for this situation because you're o= nly > > > > allowing probing what's in the struct matching the vendorid. > > > > > > Since the isa string is a per-hart field, the vendor associated with = the > > > hart will be used. > > > > I don't know if you just didn't really read what I said or didn't > > understand it, but this response doesn't address my comment. > > I read what you said! This question seemed to me as another variant of > "what happens when one vendor implements an extension from a different > vendor", and since we already discussed that I was trying to figure out > what you were actually asking. > > > Consider SoC vendor S buys CPUs from vendors A & B and asks both of the= m > > to implement Xsjam. The CPUs are have the vendorid of either A or B, > > depending on who made it. This scenario should not result in two > > different hwprobe keys nor two different in-kernel riscv_has_vendor_ext= () > > checks to see if the extension is supported. *If* the extension is vend= or > > namespaced, it should be to the SoC vendor whose extension it is, not > > the individual CPU vendors that implemented it. > > > > Additionally, consider that CPUs from both vendors are in the same SoC > > and all CPUs support Xsjam. Linux only supports homogeneous extensions > > so we should be able to detect that all CPUs support the extension and > > use it in a driver etc, but that's either not going to work (or be > > difficult to orchestrate) with different mappings per CPU vendor. I saw > > your v2 cover letter, in which you said: > > Only patch vendor extension if all harts are associated with the same > > vendor. This is the best chance the kernel has for working properly i= f > > there are multiple vendors. > > I don't think that level of paranoia is required: if firmware tells us > > that an extension is supported, then we can trust that those extensions > > have been implemented correctly. If the fear of implementation bugs is > > what is driving the namespacing that you've gone for, I don't think tha= t > > it is required and we can simplify things, with the per-vendor structs > > being the vendor of the extension (so SoC vendor S in my example), not > > A and B who are the vendors of the CPU IP. > > > > Thanks, > > Conor. > > > > Thank you for expanding upon this idea further. This solution of > indexing the extensions based on the vendor who proposed them does make > a lot of sense. There are some key differences here of note. When > vendors are able to mix vendor extensions, defining a bitmask that > contains all of the vendor extensions gets a bit messier. I see two > possible solutions. > > 1. Vendor keys cannot overlap between vendors. A set bit in the bitmask > is associated with exactly one extension. > > 2. Vendor keys can overlap between vendors. There is a vendor bitmask > per vendor. When setting/checking a vendor extension, first index into > the vendor extension bitmask with the vendor associated with the > extension and then with the key of the vendor extension. > > A third option would be to use the standard extension framework. This > causes the standard extension list to become populated with extensions > that most harts will never implement so I am opposed to that. > > This problem carries over into hwprobe since the schemes proposed by > Evan and I both rely on the mvendorid of harts associated with the > cpumask. To have this level of support in hwprobe for SoCs with a mix of > vendors but the same extensions I again see two options: > > 1. Vendor keys cannot overlap between vendors. A set bit in the bitmask > is associated with exactly one extension. This bitmask would be returned > by the vendor extension hwprobe key. > > 2. Vendor keys can overlap between vendors. There is an hwprobe key per > vendor. Automatic resolution of the vendor doesn't work because the > vendor-specific feature being requested (extensions in the case) may be > of a vendor that is different than the hart's vendor, in otherwords > there are two variables necessary: the vendor and a way to ask hwprobe > for a list of the vendor extensions. With hwprobe there is only the > "key" that can be used to encode these variables simultaneously. We > could have something like a HWPROBE_THEAD_EXT_0 key that would return > all thead vendor extensions supported by the harts corresponding to the > cpumask. I was a big proponent of the vendor namespacing in hwprobe, as I liked the tidiness of it, and felt it could handle most cases (including mix-n-matching multiple mvendorids in a single SoC). However my balloon lost its air after chatting with Palmer, as there's one case it really can't handle: white labeling. This is where I buy a THead (for instance) CPU for my SoC, including all its vendor extensions, and do nothing but change the mvendorid to my own. If this is a thing, then the vendor extensions basically have to be a single global namespace in hwprobe (sigh). I do like Charlie's idea of at least letting vendors allocate a key at a time, eg HWPROBE_THEAD_EXT_0, rather than racing to allocate a bit at a time in a key like HWPROBE_VENDOR_EXT_0. That gives it some semblance of organization, and still gives us a chance of a cleanup/deprecation path for vendors that stop producing chips. -Evan