Received: by 2002:a05:6359:322:b0:b3:69d0:12d8 with SMTP id ef34csp144581rwb; Wed, 10 Aug 2022 16:37:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR46hY7WI16u0FvsSxWM1by1SaIhOOSKirhFUHulM/l4DEjS9vDojQpQ6yOIMNFCWaEzwsLQ X-Received: by 2002:a17:907:6295:b0:703:92b8:e113 with SMTP id nd21-20020a170907629500b0070392b8e113mr22411351ejc.594.1660174624916; Wed, 10 Aug 2022 16:37:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660174624; cv=none; d=google.com; s=arc-20160816; b=XdUml41D1p4Czs0Zy2hcvcvTAlG0jDca2b/YifpfQXjQJGQMfe3tn99bQqk2deYJH3 YAWAs4Tyc5+PdEQbfboMZqkUdoI+A1EOINAwY2aMVE3QHYc0E4NUEsBbC0BQBV0q9Yz6 V08TwkqdxQ6dvlxizxHzOXei2LuoyXWCSZEGo1NCnMFCPFhzkvdsUh/IALXg40MjothQ CgRCwehPaYpQakuoZ1qN36byI51QEAaQ4au4bZf0S2YMe7wBv6xN8bhobiK2CG4PW94X pGcV5i2iRGdDhJtcvm9K+41MsAjZJDLKwCqcnINxUGjq2ew3ZqvlbSS0RlJ6K9Sr+uVL vKRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=J1S4AO51CUHE+MiRUkGQ/82rQ/8c9Jpi9FTf1saPf2w=; b=J22EVbnJmhAg7hGcsxGoR5Gxq6gaEzkNhVmFhbTrOVQK2tAwtbzKSN228OlbH8Xcgz E+yTMcKXstgHwaPSCyj8n3f+K4o2mSsdRH+HbOLFziUk3B36vZmBzV1r2dv4bswfZjpZ JSJkf4pG/LpINZmKSml6U3Iktvgg7HEw6VgudSbxOxpAqvx1+5RoiXMBgR+v7oqdB5lX hT1W6s96fpeEKmS3pXQXzjyYogBONEoFBBEOyaSERZxIxHuubipgX+b149ZhU6wgqM6D OWiyQXujSS+A2AU3TxMNMD8rFKIgKYR+6B0mMWceA0dDE5ial2DcFxpjeuGwfdA8/BVw bBog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QeShLouU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id zk19-20020a17090733d300b007313013c1adsi5329208ejb.259.2022.08.10.16.36.39; Wed, 10 Aug 2022 16:37:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=QeShLouU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232771AbiHJW0p (ORCPT + 99 others); Wed, 10 Aug 2022 18:26:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229487AbiHJW0o (ORCPT ); Wed, 10 Aug 2022 18:26:44 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D65A8D3E5 for ; Wed, 10 Aug 2022 15:26:43 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id z16so19275967wrh.12 for ; Wed, 10 Aug 2022 15:26:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=J1S4AO51CUHE+MiRUkGQ/82rQ/8c9Jpi9FTf1saPf2w=; b=QeShLouUtmJpWBEkceLNBWarGOX1MYjbKzCn1nv4kKocJLEFoP031jL8s0SsSDrENB Wda5fKDvu+0K5YNCaq9SuXTz69ykH/ukcSSjdJuM+sS8nvvKrNPrvoDt4SKJhqBeu7zc YW7340fBZAbgY7HZArLppFuPztV1DCTsGz3hw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=J1S4AO51CUHE+MiRUkGQ/82rQ/8c9Jpi9FTf1saPf2w=; b=pCrz3VfAfgm12Anr1FkE6bQTGiqkBomA97wTOXfSOoxscpiEvUoCZlTrUye7uT3kr5 P7qQNFeE5bk5oI5nJedu304TMF9nBG2fLFdNE09mybc103eXuGtWil7iH4g6554Rxe6j DFC8CinfJV9J7WlQ40L5VRNNnKKRJo1zJcYvmiTIuXI68GdCSrmklgwbpvQrKvwkMKeY DndJ6FIryKGfCmlcUNgAcYxBqyUu5B2k4Do6NMwU+Awjz0aFbFzyWggYq8d0noLjrA42 lQuKi6LkPH4no3SnIqEwSil/FR1sf8pJcwquY6tdrza77+KPZf5TyOrVh6KYhxxm3ssM 7JqQ== X-Gm-Message-State: ACgBeo0cPC4gQwBmrgRuLtILb/LdynCrocEsL5zzBKRtMqmVueiearny cyV1Z9SMSWEwJyQTdoKmfr9isABeDdrOKpePwhYLFQ== X-Received: by 2002:a5d:47a4:0:b0:220:600d:2b0f with SMTP id 4-20020a5d47a4000000b00220600d2b0fmr18598230wrb.407.1660170401636; Wed, 10 Aug 2022 15:26:41 -0700 (PDT) MIME-Version: 1.0 References: <20220804142856.306032-1-jrosenth@chromium.org> In-Reply-To: From: Julius Werner Date: Wed, 10 Aug 2022 15:26:30 -0700 Message-ID: Subject: Re: [PATCH v7] firmware: google: Implement cbmem in sysfs driver To: Stephen Boyd Cc: Julius Werner , Jack Rosenthal , chrome-platform@lists.linux.dev, LKML , Tzung-Bi Shih , Guenter Roeck Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Alright cool. The bug says 'vbnv' so I was guessing 'nv' meant > non-volatile. "vbnv" is non-volatile memory, but this driver doesn't actually access vbnv (which is on SPI flash). This driver is meant to access an in-memory cache of vbnv that was put there by firmware. > > We really only care about one of these right now and many of them will > > never be relevant to the kernel, but I still thought that while we're > > doing this we might as well provide a generic interface to all of them > > because others may become useful in the future (and then you don't > > have to update the kernel every time you get a new use case for some > > userspace tool wanting to interact with some resident data structure > > from coreboot). > > Exposing more than is necessary in the kernel ABI could get into > problems with backwards compatibility. It also means we have to review > the ABI with the consideration that something may change in the future > and cbmem would be exposing something we don't want exposed, or maybe it > is writeable when it shouldn't be? I think we have a bit of a different concept of what this is supposed to be. Forget about the vbnv and vboot workbuffer parts for the moment, those are where our overall motivation for doing this comes from but those should not be concerns for the kernel itself. From the kernel's point of view, all we have here is a firmware information structure it already knows about (the coreboot tables) pointing to a list of opaque, firmware-specific memory buffers labeled with an ID, and we want it to expose read and write access to those buffers to userspace to make it easier for firmware-specific userspace helper tools to work with them. Note that we already have userspace tools doing that today anyway, e.g. the `cbmem` utility uses /dev/mem to search for and parse the whole coreboot table itself before then using it to access individual CBMEM buffers. But implementing all the logic to do that in each tool that wants to support anything coreboot-specific separately is cumbersome, so we thought that since the kernel already has this coreboot table parsing support anyway, we might as well export the info to userspace to make this job easier. So really all the kernel does here is expose the address, size and ID values from the coreboot table itself, it doesn't (and isn't supposed to) have any understanding about the pointed to buffer. (We could also leave out the `mem` node from this driver and just let our userspace utilities read the `address` and `size` nodes and then use that info to go through /dev/mem. Giving them a direct `mem` node for the buffer just makes that process a bit easier and cleaner.) So backwards compatibility should not be a concern (unless we're talking about changes in the coreboot table itself, which we strongly try to avoid and which would be an issue for existing kernel drivers already anyway). Understanding of these buffers' contents is explicitly supposed to be the responsibility of the userspace tool that has an easier time keeping up with frequent firmware data format changes and maintaining long lists of back-translating routines for older structure formats for the specific kind of buffer it looks for if necessary (something I specifically wouldn't want to clutter the kernel with). In regards to write access, I don't really see a point restricting this since all these buffers are already accessible through /dev/mem anyway. But that should only be needed for very few of these buffers anyway, so if people think it's a concern I think we could also keep a small explicit allowlist for the IDs that can be writable (shouldn't need to be updated frequently) and disallow it for everything else. Also, of course there's still the normal file system access permissions that makes these only writable for root and users specifically granted access by root. (Actually, Jack, that reminds me... having the `mem` nodes world-readable is maybe not a good idea, there's usually not anything specifically secret in there, but since /dev/mem also isn't world-readable I think this one probably shouldn't either. I'd suggest changing the initial umask to 0660 or 0600.) > Furthermore, if the ABI that the kernel can expose already exists then > we're better off because there may already be userspace programs written > for that ABI with lessons learned and bugs ironed out. In this case, I > was hoping that it was an nvmem, in which case we could tie it into the > nvmem framework and piggyback on the nvmem APIs. It also helps to expose > a more generic ABI to userspace instead of developing a bespoke solution > requiring boutique software. Of course sometimes things can't be so > generic so code has to be written. Yeah but this isn't anything that can be genericized, this is specifically meant for boutique software to maintain its internal data structures. vbnv and the vb2_shared_data structure in the workbuffer are supposed to be completely internal to vboot and not interpreted by any code other than vboot itself -- even coreboot never accesses them directly (only by linking in vboot functions and calling those). We explicitly don't want to deal with having to sync data structure format changes to anywhere outside the vboot repository. The problem is just that unlike most software, vboot is a framework that contains both firmware and userspace components, so the latter necessarily need some help from the kernel (as an oblivious forwarder of opaque data) to be able to access the internal data structures passed on from the former.