From patchwork Wed Dec 28 07:29:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37122 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763347wrt; Tue, 27 Dec 2022 23:32:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXtdfQ3Wby9P2qlT++/ZO8CE1Ll93XKutI7abiT7w+8fMS02eZzLPn1HAXXEw8E9j3LiYmZY X-Received: by 2002:a05:6a20:1a81:b0:ad:87b4:948e with SMTP id ci1-20020a056a201a8100b000ad87b4948emr27535673pzb.12.1672212748219; Tue, 27 Dec 2022 23:32:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212748; cv=none; d=google.com; s=arc-20160816; b=gpMJSVl9L8S+Paxay3PGScb25sWFe3FKkhUsSOFsFqQy1SN4M0CDVY4iy9lWDxjhqJ /lq2jngN16kznhLyMmqpAQUVwah8trfRGe3gyNaa7TkcwS/Choy+OL+EtG4EGjjAmp3/ JG2Qgae5n9VVWTn3yd0L6+CDjDYbn4NSrtbTz+WrA3Fp+nUAb13L6MFBZKI3vCb+Gkqv qjltnKO6iUIQMMXGVbE6hmcStQZesU2gbGii2OcZPkjXz1wy/ADoysegBYxlr2Q/u15l +2Tp7Y1VpR/+MTsWvtL0xxqdZSOrLOu8Kz6ZoO7w3T49XWKvNP1gFK39hFyKUpLb6K5s PEow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=yn/S5ROEzSnOph0KuGPaeywtNTs872W1IHLPpJmU4iY=; b=baUPVIfRAwV7xTwEL0U/4AwvP1aCResAyAAw3gQ0XwPZWIwnsn+BAb3GAwiJH5PoLc rO8bKzRuNQdFYCeuyy+nft2feEoVrSVgEVmdC3mXIylFrRb2MM4FIV5bRkUDMoN9hUFC KnaE3obmj7xtNXlIVrRorBv+PAqEWTpY803JdDn87+CZR4jV2g4RhXF3xQxwnH2mguaI wKqzkB7iZJIpvoUueKF/WDgeTxzCDZ/8nrDiPto2wo/pHQ3UMUoxyovV+cAntMNPGMC4 1RALhLwrI6U1dWoRkJo0+tjECRQ8QptxPqsYuu14x4gJ3Akck8Uc2o5rD5wXnz94bAAB 58HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=L64sfh8y; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=A+lFhYv1; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 27-20020a630c5b000000b0045131d08c18si15915897pgm.244.2022.12.27.23.32.15; Tue, 27 Dec 2022 23:32:28 -0800 (PST) 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=@russell.cc header.s=fm3 header.b=L64sfh8y; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=A+lFhYv1; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbiL1Han (ORCPT + 99 others); Wed, 28 Dec 2022 02:30:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbiL1Ha1 (ORCPT ); Wed, 28 Dec 2022 02:30:27 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4CCE1119 for ; Tue, 27 Dec 2022 23:30:26 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 6D5DA320090E; Wed, 28 Dec 2022 02:30:25 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 28 Dec 2022 02:30:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212624; x=1672299024; bh=yn /S5ROEzSnOph0KuGPaeywtNTs872W1IHLPpJmU4iY=; b=L64sfh8yUDUAW0dE0k T7RuEKTunT8wEC70MkP9XpVQHTFwOtb9gcWg6OG6kHlUWzbDtyoHPkY8rYdAdZR2 lSVwHfgLxGiAOpT+bS/swz7iVvpjI9vPXixdBDeHpm60mqGNX4Z7tu/R6had50bv YfGgYSGxjrOnRIffOrBbhKrabA2mTEajuIYUGvhK35coq3K9NHkip5QllqJXgAdm cQGjD2hdD+3TtZY0ylIZ+hzySMi5+BZ20uybU0y9OlAmnhwoMRhhkhn1y4rlPDAK KKINlPpXBlYKmJL+rbTdhuadWoBGGduBNx67H8R71wyBzNgW/Oj4GbqlD4YX/Tza eEBw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212624; x=1672299024; bh=yn/S5ROEzSnOp h0KuGPaeywtNTs872W1IHLPpJmU4iY=; b=A+lFhYv1cVQqKoGr0XyWw/bCHvMKQ immRLXwo9cc9CIUG5Zn8cIQ/dMCt8UkgaWDLYlFBYabpuawh3IiTc+8Ja0NWIH7d e4WIp9YrwrEn0x6uE7bOUUNfqTOurfsX36PGl5wQkbV1tVJtCISkdmcWLgRcVmyD oTqBt2lqgpYm03xM6iT/0SyIbPBIcPZhagl2DXB5ogFxS3kC948ctyGAdVDGYKE3 M7+ADKN9WQ4/6+tgJ1OjlohnnJ6j/elBHhKwn8LJA0iyNKSA7Uvr5xkSiRVvsyAn oWeppeS23e0YSnS7orF+dMP9Cfyu9rv/nkG0WjzFWLG8dyVBKYG4DLTBg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:22 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 1/6] powerpc/pseries: Log hcall return codes for PLPKS debug Date: Wed, 28 Dec 2022 18:29:38 +1100 Message-Id: <20221228072943.429266-2-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442154717686882?= X-GMAIL-MSGID: =?utf-8?q?1753442154717686882?= The plpks code converts hypervisor return codes into their Linux equivalents so that users can understand them. Having access to the original return codes is really useful for debugging, so add a pr_debug() so we don't lose information from the conversion. Signed-off-by: Russell Currey --- arch/powerpc/platforms/pseries/plpks.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/platforms/pseries/plpks.c b/arch/powerpc/platforms/pseries/plpks.c index 9e4401aabf4f..820218eb894f 100644 --- a/arch/powerpc/platforms/pseries/plpks.c +++ b/arch/powerpc/platforms/pseries/plpks.c @@ -131,6 +131,8 @@ static int pseries_status_to_err(int rc) err = -EINVAL; } + pr_debug("Converted hypervisor code %d to Linux %d\n", rc, err); + return err; } From patchwork Wed Dec 28 07:29:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37124 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763559wrt; Tue, 27 Dec 2022 23:33:18 -0800 (PST) X-Google-Smtp-Source: AMrXdXuhvjU8ymxjdehEHvrOfZ74UTLqUkzUAyRVHxmgFC/LVXtEhz7IioG2nT4W7zQLYdFnSDkC X-Received: by 2002:a17:907:7094:b0:844:1d1d:1fa with SMTP id yj20-20020a170907709400b008441d1d01famr20392836ejb.23.1672212798457; Tue, 27 Dec 2022 23:33:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212798; cv=none; d=google.com; s=arc-20160816; b=dzvyUZW9NTKnlXjaE+A5lUiBrba5/BVJEptN/+lGT7qUCkzXeJV9O7AMC1HjZ9Yz09 bYzvbX93pNp3JDCPR4aWmFU2GanSXrcl4QIxqHGXxIGGmXPpeA2Oj2/NPBIZtRRTGPcn HBGswN1D4G28bPc+TBOvIwoI2UxBQP4nBhsKXVRrpGI+sw+KsPH/YfOn0kMl+vdWM8cb 7aMaPUWhAQP1ydaOygW5S3Ra99k8yXZ67yZeDO9vdcHnPwDmzv/DsBeIOFCS2Si3/Lzl e8qvU1bdNCYi22rzm/J58o37WRtjqO4fw1ojQYkYqIosvjN/Vvhe8yS5dXlK+4F9nv1I iu0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=avaCv9mDt906Bh4sj41n++Uvq9fM0k+OtKCj4mLejVk=; b=P1NskxbDqhvSBy+Q7d3GniEia5DopbMQ5j/u16eFo7QyqUBt/tRasr/TUmsT1RVukR NeLXmRtKsYq/IW5dxYyeQ+OdXNz3cE70h6PlkhmDkmDv0PC2pwv/ZmrTZYLPF8zyVRBP xjKkYXZbWSaNREeHdn0GyntN5Me2Ofkk/7/GVJwDJeVZvKpDN5JQTlCJxYwcU/L54v3U GT/OFSyCpPI6IHSieUq4xZFEB8zt1nVk2r7k/tIjuk0xgS6kAXsEDzerkqnPsM/q+HKB 9jn7Xl5leT4h9rcdXqDdqFjUw3jdKpGVm53um0AOjvrsIDkRlqhdKOSiKhJqzdGCLpS3 ykgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b="J4MTx/6D"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=iC7cLEPb; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402350700b00461b661d906si14284371edd.256.2022.12.27.23.32.54; Tue, 27 Dec 2022 23:33:18 -0800 (PST) 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=@russell.cc header.s=fm3 header.b="J4MTx/6D"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=iC7cLEPb; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbiL1Hat (ORCPT + 99 others); Wed, 28 Dec 2022 02:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232619AbiL1Hac (ORCPT ); Wed, 28 Dec 2022 02:30:32 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51945EA6 for ; Tue, 27 Dec 2022 23:30:31 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 1F4963200902; Wed, 28 Dec 2022 02:30:30 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Wed, 28 Dec 2022 02:30:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212629; x=1672299029; bh=av aCv9mDt906Bh4sj41n++Uvq9fM0k+OtKCj4mLejVk=; b=J4MTx/6DSY86I1XPwH SXekn71UCI6T3R/aU6g6Y2eZoN/84Mdcb4RaW1vPUY63leUA3w6JqdUQLMe/AFJB IoOPqx+AaklEy4fSw5T8e6HP7Vl32AAauRe4zeNshFAlcj3AXc4F/jkk1ojTQ2A/ vSgE5I1WNK0Y9GIWLO4pvhe2Dap3FBy3rpDmfSqdR/IpljCfseNdZuYuUByME9Wx ZMk5qS3i7lybZrRaFG6CV9hONZtHWe2kRVX0cRXMHRNZrAclaEc4T1OhT+1+kTby JC2oI2wEhee5T5FUgPqUPmDvFhoCL6V5m+MzCDyp0vMKvFqvUbM0kRym0FVwSFk4 JjqA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212629; x=1672299029; bh=avaCv9mDt906B h4sj41n++Uvq9fM0k+OtKCj4mLejVk=; b=iC7cLEPbfula0gN/zS5qUdjw70ZZp hVo9Dmhkf/OUiPVPDW3Tuupka+cPw6ONJ2Ya//dr4T1+R+UUrwDe7t69ZGLLycCy sA7HqJsBckVAx2HYJyJ+nYXnCgqtlvY3QYeq9ZbSl4eGFsRA9+umhYP2mnwHtvbM OwUa9jjsT5zcJhuk83ZPVFrsGqwNY156JN4tt7MRBoVnTHO3nYwrQ85V0JPEnZiN UL+oRsB4g8KuGUSVslzJtGd1YEp11h3QeI4T3PInDzZvPVHU5bYht894YYWxnjjE ETD+8zVT9bKNlM9vx0+za+xaf7sY5kp+lIgLl+2Hb5kPEruZ1zqd29Ciw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:26 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 2/6] powerpc/secvar: WARN_ON_ONCE() if multiple secvar ops are set Date: Wed, 28 Dec 2022 18:29:39 +1100 Message-Id: <20221228072943.429266-3-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442206857414137?= X-GMAIL-MSGID: =?utf-8?q?1753442206857414137?= The secvar code only supports one consumer at a time. Multiple consumers aren't possible at this point in time, but we'd want it to be obvious if it ever could happen. Signed-off-by: Russell Currey --- arch/powerpc/kernel/secvar-ops.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/secvar-ops.c b/arch/powerpc/kernel/secvar-ops.c index 6a29777d6a2d..aa1b2adc2710 100644 --- a/arch/powerpc/kernel/secvar-ops.c +++ b/arch/powerpc/kernel/secvar-ops.c @@ -8,10 +8,12 @@ #include #include +#include -const struct secvar_operations *secvar_ops __ro_after_init; +const struct secvar_operations *secvar_ops __ro_after_init = NULL; void set_secvar_ops(const struct secvar_operations *ops) { + WARN_ON_ONCE(secvar_ops); secvar_ops = ops; } From patchwork Wed Dec 28 07:29:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37123 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763440wrt; Tue, 27 Dec 2022 23:32:49 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFUlJHi/eYgJYsggtrLvIIbVYUUIw69kWmxRVKu9TtnuDIAcX8wJTfUh0vsAjQyUV2Oxue X-Received: by 2002:a50:9eec:0:b0:486:6d28:dabc with SMTP id a99-20020a509eec000000b004866d28dabcmr5850775edf.18.1672212769551; Tue, 27 Dec 2022 23:32:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212769; cv=none; d=google.com; s=arc-20160816; b=J3ojJf2fodD5a/lA9va0moEVf8ZfjOfDuw/7qL+vLEJswWN/zAZes2lWaT9OXnhEnV 1fteYHSikxVE90QTjL9WebSEM2xNv8TYKm2ZRWrZ25J/5hd+3fJEDRSppaYt2MJOquai 3RU8h0kZ/4FMK4PCtKDmsqeyvTIJ+43AdmydNgEuLuj2eyyYu+XiElyQoWq0zGl4ivAw kgJ9586a0vASk2dKJbCBNR+1ZiTwYO7OemB4LHVTBGoz49xcEPxLn1u551dwVQcWw7yI gEkSWxQf07HCWZtWS2SDTUic268A28Vf5odA/Th8Qie97O4CvScQITKKXKQji5Rg5d8U VkmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=WNXT52ksa1LSW+Evq+GXqK8F8+ErNwjr8XxtvfSaKZc=; b=DRHRYgKCCg0s7fAOa+oo9xG65OOQKY521pvfv7BqJPGJjpevHv7c2SurUioIRdM7zd fgowSbF9vpZWN45BjcQLNEuTmMiarbATcPuQZCPm+41K7z7dHedaOYarZZ8+rY3vmjD9 oy2b6nFt4GOdu+GNNjm53C+mKiDr6KESt5djW/6vTKIHwfrfimH26vE0wBd0s8s12F2M PGexWBxjgLDXpYXy8Vd997GV7ZTDWK5WZuW7HIAI15UahAYs03UeDnHi9px9qlicSVh5 al6HrwNjXLvjwgsfJSzq7NwAsn6q5Xy7A38LlJdc8ucxoC8nnMOh6UHFeiqPtKuyejuY ek/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=A+2ZT9G3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=l3C92B6l; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a05640227d300b0046b807c1a06si11915738ede.350.2022.12.27.23.32.26; Tue, 27 Dec 2022 23:32:49 -0800 (PST) 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=@russell.cc header.s=fm3 header.b=A+2ZT9G3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=l3C92B6l; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232672AbiL1Hay (ORCPT + 99 others); Wed, 28 Dec 2022 02:30:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232625AbiL1Hag (ORCPT ); Wed, 28 Dec 2022 02:30:36 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D5A71119 for ; Tue, 27 Dec 2022 23:30:36 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.west.internal (Postfix) with ESMTP id E40933200921; Wed, 28 Dec 2022 02:30:34 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Wed, 28 Dec 2022 02:30:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212634; x=1672299034; bh=WN XT52ksa1LSW+Evq+GXqK8F8+ErNwjr8XxtvfSaKZc=; b=A+2ZT9G3iOeqh15YyA /mAkKPEKOMp/GGJ3/yFkAiTe9Hy4eLaYx81D5Fjbmq+0n+6BCRGGPUzG13jC3CPt HJaDlI/JYzDEhuLyRjKOhKOkyOugqJhefiSTc6tiCTMXdq4aKP7CgipX2YpcUNfM VaLM7c15XIh8oE75rYpkNJ++pYhkA3PVXACBxXTncMbYlNfB00QO/xXkXTQsNaoK Kmi645QWbJDAqqVd65Bhpo2yhkmvRbxjTuMxyTilsCbNzpoLy5uTNc3W+w+3kj50 9RsxoPK0ornwX6PQxzDl7JMGLXuqhLt0yjrxmvNX6XR0DaGElukqQemssT1uYLFg 6wng== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212634; x=1672299034; bh=WNXT52ksa1LSW +Evq+GXqK8F8+ErNwjr8XxtvfSaKZc=; b=l3C92B6l9aaihvIIKo0MSTXo7406P LBrJ+5D63UabOyg2JCbhO0oJ64YAoFNzMHi5z7Vk3P+/va0TVOp4oZxPgrEva1RO 66FGuSI1e0OT34jnSzwyJi2ObBNQDrZlJyk5JrDLqT4BL8aGPgObpiGt0nRjvJml OCQahAki/ZrZtxrTWs3zPWIPDx9bqSoVLSXDZ9aVS8KOGJtEu/j626WxAnykfgRf QSvpAxYsDdBX2VZzbX6rPK8+TDl1pgt+t1ddWG+cYQesv1cw5o4a/tOnOKNwfoVe sOA/lsvPCRaN9zCB7BR/iKqpeHi2YtYCHB7ESz7ZEY9jLPBDdnicc4Uuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugddutdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:31 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 3/6] powerpc/secvar: Handle format string in the consumer Date: Wed, 28 Dec 2022 18:29:40 +1100 Message-Id: <20221228072943.429266-4-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442177194771779?= X-GMAIL-MSGID: =?utf-8?q?1753442177194771779?= The code that handles the format string in secvar-sysfs.c is entirely OPAL specific, so create a new "format" op in secvar_operations to make the secvar code more generic. No functional change. Signed-off-by: Russell Currey --- arch/powerpc/include/asm/secvar.h | 1 + arch/powerpc/kernel/secvar-sysfs.c | 21 +--------------- arch/powerpc/platforms/powernv/opal-secvar.c | 25 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/arch/powerpc/include/asm/secvar.h b/arch/powerpc/include/asm/secvar.h index 4cc35b58b986..3b7e5a3625bd 100644 --- a/arch/powerpc/include/asm/secvar.h +++ b/arch/powerpc/include/asm/secvar.h @@ -20,6 +20,7 @@ struct secvar_operations { uint64_t keybufsize); int (*set)(const char *key, uint64_t key_len, u8 *data, uint64_t data_size); + ssize_t (*format)(char *buf); }; #ifdef CONFIG_PPC_SECURE_BOOT diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c index 1ee4640a2641..daf28b11866f 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -21,26 +21,7 @@ static struct kset *secvar_kset; static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { - ssize_t rc = 0; - struct device_node *node; - const char *format; - - node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend"); - if (!of_device_is_available(node)) { - rc = -ENODEV; - goto out; - } - - rc = of_property_read_string(node, "format", &format); - if (rc) - goto out; - - rc = sprintf(buf, "%s\n", format); - -out: - of_node_put(node); - - return rc; + return secvar_ops->format(buf); } diff --git a/arch/powerpc/platforms/powernv/opal-secvar.c b/arch/powerpc/platforms/powernv/opal-secvar.c index 14133e120bdd..cd5b5c06c091 100644 --- a/arch/powerpc/platforms/powernv/opal-secvar.c +++ b/arch/powerpc/platforms/powernv/opal-secvar.c @@ -101,10 +101,35 @@ static int opal_set_variable(const char *key, uint64_t ksize, u8 *data, return opal_status_to_err(rc); } +static ssize_t opal_secvar_format(char *buf) +{ + ssize_t rc = 0; + struct device_node *node; + const char *format; + + node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend"); + if (!of_device_is_available(node)) { + rc = -ENODEV; + goto out; + } + + rc = of_property_read_string(node, "format", &format); + if (rc) + goto out; + + rc = sprintf(buf, "%s\n", format); + +out: + of_node_put(node); + + return rc; +} + static const struct secvar_operations opal_secvar_ops = { .get = opal_get_variable, .get_next = opal_get_next_variable, .set = opal_set_variable, + .format = opal_secvar_format, }; static int opal_secvar_probe(struct platform_device *pdev) From patchwork Wed Dec 28 07:29:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37126 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763868wrt; Tue, 27 Dec 2022 23:34:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXuqRlMIVGPQmMLjhaxuiuc9D7a/irWa0ofT/PUWfgufCcBbTTXkIGKW8sqIKqeyCEOCiGdb X-Received: by 2002:aa7:d299:0:b0:470:26d9:5da8 with SMTP id w25-20020aa7d299000000b0047026d95da8mr23801688edq.30.1672212860235; Tue, 27 Dec 2022 23:34:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212860; cv=none; d=google.com; s=arc-20160816; b=ChSTKKMrWSnmx0EgWNU2sJAY2fY5eKZbIGqel2nuaO1JMMgAr/dxWpTiq9Y5rSQHRV tDweUQuaAmQYKEKIJDjjZ5Ib4rHMtj4TC0JmuiG4nwCJpJlT4KOm13wRJmKdHSSd6Hbm lS0Zb2DL1VROB1mlGGEISRmxzpJZ893V8DYnhAq1GlEATmmtDa7UwgPTou5z5RWzQOr3 uiU4N7obWeOSgAEXFpkb9H4wTfQZofw+sspaXmehEKmDlWJjg0XLI6RBJTIHCmwkDzJf yV+IH6miQ0be0Xd/sOxlF9wH6fYf7S5hzvg23wm1Kl89yMG7K5WHsKTQPH8idKpuu4mH ZoPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=BrFC+57y08hRIR+Z3gCskLpXrFWtKi5jsyNeZhcK7F0=; b=p+LiESMUKpRD1FDTWWTs3gJhCvnUhQlT+4ikoOtHi9DP9hMoKI6asUSdkQF4fYNZtp WaQzzgpx5PAJbB/TUfK/gl9FaTJoK9BnTQzM7kV+d+uugolmHHKJi/vFsjph/37jPWc9 52J1X91kN+Rlx8uP/qt2AN/MxYdi/jyBjTFKT6bBdhQM4NfnLt3JwIhPc/N7J9u0dc3N a9zDadK1oDPtX1E1weo5FMojcT1/Ffl6kuUtxrhps9pCYttFL9wj/TN4C5KayhVJ3SHt nba//C7p4mwpc3g+XFYIvKxW/x+67/LaqbNdN8/v7/mXASj53aTOXhltpZb49vfnpEVu 1u6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=MzHkDSTe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=NWs1T5Nz; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r18-20020a056402035200b004837d089deasi8420339edw.413.2022.12.27.23.33.53; Tue, 27 Dec 2022 23:34:20 -0800 (PST) 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=@russell.cc header.s=fm3 header.b=MzHkDSTe; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=NWs1T5Nz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbiL1HbU (ORCPT + 99 others); Wed, 28 Dec 2022 02:31:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58460 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232475AbiL1Hal (ORCPT ); Wed, 28 Dec 2022 02:30:41 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 088B2F58C for ; Tue, 27 Dec 2022 23:30:41 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id C98BA320092B; Wed, 28 Dec 2022 02:30:39 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 28 Dec 2022 02:30:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212639; x=1672299039; bh=Br FC+57y08hRIR+Z3gCskLpXrFWtKi5jsyNeZhcK7F0=; b=MzHkDSTeWqYBp25vS1 T2Dw05oAOs4l89qU0oLHNXQQDp+x5IobZkCLYBXW0xRhR5E3qG4WC/jiBGRVdaoa FvbjAB6S0/kvsqZUoTDfHjWQTWNMELVxvNMwb75ESsSSEMrpmTVCcGKxiagGRsir KPxwILrYE6z+2ZTkjGKeVTGrNQeLAU90x3DF+EDBqS0qfJltJmuexrhbU0nhKAUj cmxvt7X5/n5P0PcUoqHSuSd2PVgOWgMIP8YyCp7UVsYk++yDqKPIYSIpxz5KxVDT zwAV9efRGy6szHKa3P7UTtYUtpIoVXX7l2KYMz3UJn77052PuhfRJNkWMsXjAQms KC8A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212639; x=1672299039; bh=BrFC+57y08hRI R+Z3gCskLpXrFWtKi5jsyNeZhcK7F0=; b=NWs1T5Nzd557sJFnJxB+8HVaZ/gY5 7ELJ2ZzgnPPfAjRgqQF5HNt3Wy1ub5ywFVFHOoCtlkg5n/DrzWi7WWENYY1cVKgq psqWiPliuieZaWfBbQ0VuxzAzWcpU+LM73Xwi1SxQrSx2/KLrGfZR3/JdlbbaPNr 8G/2B8r7w5wvfqTKA2rlRrPAiAeXsrsR1kFRvSsgYxCkeoOD7gNahTzVmtdNyg/8 Tyo1g5lwve0GD3DB69TyEox1n8hyhBvCEwBFZ2f75yVK3D1FVgPK5QtJNt1ABo/L hP1q4qFLOSOiW/pq3Ohz8P7K/IYHm3jwL16JAE/Qob+SlwJNyXFBhoL4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:36 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 4/6] powerpc/secvar: Handle max object size in the consumer Date: Wed, 28 Dec 2022 18:29:41 +1100 Message-Id: <20221228072943.429266-5-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442272142754025?= X-GMAIL-MSGID: =?utf-8?q?1753442272142754025?= Currently the max object size is handled in the core secvar code with an entirely OPAL-specific implementation, so create a new max_size() op and move the existing implementation into the powernv platform. Should be no functional change. Signed-off-by: Russell Currey --- arch/powerpc/include/asm/secvar.h | 1 + arch/powerpc/kernel/secvar-sysfs.c | 17 +++-------------- arch/powerpc/platforms/powernv/opal-secvar.c | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/include/asm/secvar.h b/arch/powerpc/include/asm/secvar.h index 3b7e5a3625bd..92d2c051918b 100644 --- a/arch/powerpc/include/asm/secvar.h +++ b/arch/powerpc/include/asm/secvar.h @@ -21,6 +21,7 @@ struct secvar_operations { int (*set)(const char *key, uint64_t key_len, u8 *data, uint64_t data_size); ssize_t (*format)(char *buf); + int (*max_size)(uint64_t *max_size); }; #ifdef CONFIG_PPC_SECURE_BOOT diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c index daf28b11866f..ea408763dc78 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -122,27 +122,16 @@ static struct kobj_type secvar_ktype = { static int update_kobj_size(void) { - struct device_node *node; u64 varsize; - int rc = 0; + int rc = secvar_ops->max_size(&varsize); - node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend"); - if (!of_device_is_available(node)) { - rc = -ENODEV; - goto out; - } - - rc = of_property_read_u64(node, "max-var-size", &varsize); if (rc) - goto out; + return rc; data_attr.size = varsize; update_attr.size = varsize; -out: - of_node_put(node); - - return rc; + return 0; } static int secvar_sysfs_load(void) diff --git a/arch/powerpc/platforms/powernv/opal-secvar.c b/arch/powerpc/platforms/powernv/opal-secvar.c index cd5b5c06c091..3ef6b9afd129 100644 --- a/arch/powerpc/platforms/powernv/opal-secvar.c +++ b/arch/powerpc/platforms/powernv/opal-secvar.c @@ -125,11 +125,30 @@ static ssize_t opal_secvar_format(char *buf) return rc; } +static int opal_secvar_max_size(uint64_t *max_size) +{ + int rc; + struct device_node *node; + + node = of_find_compatible_node(NULL, NULL, "ibm,secvar-backend"); + if (!of_device_is_available(node)) { + rc = -ENODEV; + goto out; + } + + rc = of_property_read_u64(node, "max-var-size", max_size); + +out: + of_node_put(node); + return rc; +} + static const struct secvar_operations opal_secvar_ops = { .get = opal_get_variable, .get_next = opal_get_next_variable, .set = opal_set_variable, .format = opal_secvar_format, + .max_size = opal_secvar_max_size, }; static int opal_secvar_probe(struct platform_device *pdev) From patchwork Wed Dec 28 07:29:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37127 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763913wrt; Tue, 27 Dec 2022 23:34:28 -0800 (PST) X-Google-Smtp-Source: AMrXdXsvuzZk55J3+9Cm9Q8XxJw92wxobHlC+Z7tGUrjK26uPsE9eMZmhFT971Y+6DD509x7D3El X-Received: by 2002:a17:906:1410:b0:7bb:7d69:da90 with SMTP id p16-20020a170906141000b007bb7d69da90mr17880563ejc.31.1672212868654; Tue, 27 Dec 2022 23:34:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212868; cv=none; d=google.com; s=arc-20160816; b=Oy6TKU5UPoH+lf5Kx4EAdvleK6i4LR8comdwzHrYxRx1eFFwwwLZa3vJrNSNXAFSIk msDXMayR5hzg9vb8J1BJKHKpkkyJTvciTDu0mTu4BewlOF2FvN1GMfJXEqT0ZvcRmRo1 4dYiTnei2VjJkkJK9hKW6IVoH9UB3DHnUyzwui6wycKR7LvYEwaVlF77Vj2tRj7p1O8i G04do8wx0Y2dLhN6O9UoL9CYtbMZw2yYnxevmtd1O31Zyg0znB5Fg/w+kwisPfPa5gHL zbc+JlqqFA59KHc7rgimhIsQhpuqX1XhjFMQbKPGi043kxbri3z1FIECxYXuLoy1+Ncc 2LAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=G1FeSOpt3gkzQCJztNRktkYJbX5ca/fOhO+UA6pN5AU=; b=iCSLwyro0WIoZTDM5k6HwgtosUzJssAKqnL403J71TnGFGr0aSqDLM7yvUPjoZplj8 RirGj5M6YMr56+gp7G6s/IhYu+GH4rWEfa5Qt3jDiGe0sEzEA9pTSEr45L5rOdxaGs7+ B/TrO1rAJ92oTH4TYtUi9AZL6A2444GlN4kM2qNea1lsr8C6gCxFywuZryo5hGswn0vk Z0UkmAyAwxN6MbLMoYOkvM0LtGp7WGPBOLaBkp1oqLaP5zzy4JIxEX1KNlas2nG4e4vR 1ZNi0+ZjJtaSTEcdLMOqMO9XrvCO7g90MezTpPsr1f/loMjU3f70hz6L6k3QrcWC4dgT U+hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b="mh9/6rSE"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=MWaK4nmW; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sb38-20020a1709076da600b007ad8bc64c89si12326266ejc.701.2022.12.27.23.34.05; Tue, 27 Dec 2022 23:34:28 -0800 (PST) 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=@russell.cc header.s=fm3 header.b="mh9/6rSE"; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=MWaK4nmW; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232542AbiL1HbN (ORCPT + 99 others); Wed, 28 Dec 2022 02:31:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232554AbiL1Haq (ORCPT ); Wed, 28 Dec 2022 02:30:46 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEB0BF63 for ; Tue, 27 Dec 2022 23:30:45 -0800 (PST) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 797A53200922; Wed, 28 Dec 2022 02:30:44 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 28 Dec 2022 02:30:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212644; x=1672299044; bh=G1 FeSOpt3gkzQCJztNRktkYJbX5ca/fOhO+UA6pN5AU=; b=mh9/6rSE2bVsR8C4sw EDzrkZNmhqkIuMfUaiLxuNFhb+ggTkQgy0TvRXbw6qhuPoj5IesXT9LTJaEAPwz7 cFtfWnvbaw4bjN30xBQyq2I0KN7K6VoAIr9Gn9BXq6XYVisN1uVdXeAdS/LgDPSv X1mO/QhXYMtS4eKQvPAYO06V1ErBIn9NFSGrQvSpn0Jb630kdbNkqylcmhgoFMcP uQ70xe+NgM4Mu5HJHI2Ym/WpNcX9iU/geAiKhGSPjmKoO+QUbR6QEzN4bdET2vGi PIShy06MArXLiElxMwESSjrtakrUW1dT6UqLYwFs5X5WIHCsT6mQbh22NSiGn8Sc sFfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212644; x=1672299044; bh=G1FeSOpt3gkzQ CJztNRktkYJbX5ca/fOhO+UA6pN5AU=; b=MWaK4nmWLmaNoMmWgKHQoR7GQULUh CWwwqk/SzY8uE3iCO6KJU9K715Ajp/CQ5Mo0RCIqV1ycqmrd8cAX6RjBplM2L3yW 3qNqDU/fMhxuRpibHPd/ygOviiRkm2dlrpi75kQwojniRaJX3U1v5LE5yK88HOlM JWyqK3oH4ADNCwRf4t4vjBpTulDTa9b1Ty1tOICXlLI/hbBxmd9r2KdThJ/NIRcl wK9YIeSUSDLYVTgu08SvE0l+831aF2u5BxzC5qxmx6vC3ZvM68Q8f+we43P6Clln vSws+ZOyheSNswQoOrUu/yihJect4H2yrRdIZK/OjLsd+ZGVysPA1a54g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugdduuddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdlfedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedunecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:41 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 5/6] powerpc/secvar: Extend sysfs to include config vars Date: Wed, 28 Dec 2022 18:29:42 +1100 Message-Id: <20221228072943.429266-6-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442281045805723?= X-GMAIL-MSGID: =?utf-8?q?1753442281045805723?= The forthcoming pseries consumer of the secvar API wants to expose a number of config variables. Allowing secvar implementations to provide their own sysfs attributes makes it easy for consumers to expose what they need to. This is not being used by the OPAL secvar implementation at present, and the config directory will not be created if no attributes are set. Signed-off-by: Russell Currey --- I played around with adding an API call to facilitate a more generic key/value interface for config variables and it seemed like unnecessary complexity. I think this is cleaner. If there was ever a secvar interface other than sysfs we'd have to rework it, though. arch/powerpc/include/asm/secvar.h | 3 +++ arch/powerpc/kernel/secvar-sysfs.c | 40 ++++++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/secvar.h b/arch/powerpc/include/asm/secvar.h index 92d2c051918b..250e7066b6da 100644 --- a/arch/powerpc/include/asm/secvar.h +++ b/arch/powerpc/include/asm/secvar.h @@ -10,6 +10,7 @@ #include #include +#include extern const struct secvar_operations *secvar_ops; @@ -27,10 +28,12 @@ struct secvar_operations { #ifdef CONFIG_PPC_SECURE_BOOT extern void set_secvar_ops(const struct secvar_operations *ops); +extern void set_secvar_config_attrs(const struct attribute **attrs); #else static inline void set_secvar_ops(const struct secvar_operations *ops) { } +static inline void set_secvar_config_attrs(const struct attribute **attrs) { } #endif diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c index ea408763dc78..0c3790345403 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -15,9 +15,17 @@ #define NAME_MAX_SIZE 1024 +const struct attribute **secvar_config_attrs __ro_after_init = NULL; + static struct kobject *secvar_kobj; static struct kset *secvar_kset; +void set_secvar_config_attrs(const struct attribute **attrs) +{ + WARN_ON_ONCE(secvar_config_attrs); + secvar_config_attrs = attrs; +} + static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) { @@ -134,6 +142,16 @@ static int update_kobj_size(void) return 0; } +static int secvar_sysfs_config(struct kobject *kobj) +{ + struct attribute_group config_group = { + .name = "config", + .attrs = (struct attribute **)secvar_config_attrs, + }; + + return sysfs_create_group(kobj, &config_group); +} + static int secvar_sysfs_load(void) { char *name; @@ -196,26 +214,38 @@ static int secvar_sysfs_init(void) rc = sysfs_create_file(secvar_kobj, &format_attr.attr); if (rc) { - kobject_put(secvar_kobj); - return -ENOMEM; + pr_err("secvar: Failed to create format object\n"); + rc = -ENOMEM; + goto err; } secvar_kset = kset_create_and_add("vars", NULL, secvar_kobj); if (!secvar_kset) { pr_err("secvar: sysfs kobject registration failed.\n"); - kobject_put(secvar_kobj); - return -ENOMEM; + rc = -ENOMEM; + goto err; } rc = update_kobj_size(); if (rc) { pr_err("Cannot read the size of the attribute\n"); - return rc; + goto err; + } + + if (secvar_config_attrs) { + rc = secvar_sysfs_config(secvar_kobj); + if (rc) { + pr_err("secvar: Failed to create config directory\n"); + goto err; + } } secvar_sysfs_load(); return 0; +err: + kobject_put(secvar_kobj); + return rc; } late_initcall(secvar_sysfs_init); From patchwork Wed Dec 28 07:29:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37125 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1763844wrt; Tue, 27 Dec 2022 23:34:14 -0800 (PST) X-Google-Smtp-Source: AMrXdXtjAUPTGNuG7u+KfLi2fyuGWmsSDq1spIGfE8sIAxTfEtIjc6/SgZOs9sYBtKTnT54eB8n4 X-Received: by 2002:aa7:c0d6:0:b0:488:6fd0:cf88 with SMTP id j22-20020aa7c0d6000000b004886fd0cf88mr1029802edp.36.1672212854098; Tue, 27 Dec 2022 23:34:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672212854; cv=none; d=google.com; s=arc-20160816; b=PkVM+ljt8AwHeMrCgflD1XEGiE4cyoHnrhUY4KmG6NZpwg2LiRv/i4brIXG/RKKGNK blxGLMxhVcIYhJUE8ENMFLa3QP4W4yBg0V0eMqYOXgzYQdnI69wHLizkSHwfbCifuXVc 4oyNMpRqVfwRvMC41nHgY0+BEyRD1/1fCsvjopwyATpK1r2WlRs1T/f5i21RgRcJVrx8 moQNVcxEDQYfSmR8qnIIumUy/glHhDZmE7ykt66Ed9Zc+OU7a/nE79vfBOxtAjuOg/PP WpaYCX2tzID7WDq1ZNuL5srnZrLANZfSSKMisFNxKqb8rvUcpWpV61OY4WtbCeVo0WMS H12w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=44+zc9E97R2R+SFM8ijIWLMom02/6ELql1sdLwVrY1I=; b=vOZSA9jjqvzd1yrCSZhJzQu9SEL3CllKYwRO4f6skLc5mg9WjqYnHd6lmSihrtQhnc dwHoI8zjNaPqLxZ+nOfnUzTJUpb/6HI11Veekio/ot8GUuMHrcIYlwwkdGxDzz9JNSO8 Bc+D3xfPrEzC9aInAl8HbM/WRS2jMvyPNodIiLEUcWP9FWutWYXdnAkS3M4v9iq/G9of I5dL6iEDbOKQqw0voYoo7dUHTWbahCFss+l8as3kQvs5ThtRIdSRa387jaHqICNFIV2H /HD15Td7S9Ds1a+PNClXnIDwa/VTImxJ+ck5SlyfcQf2H20XJX33au/H2fSvveAUJjfP v9aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=l7UZcfnv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=a+FKGEmr; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w22-20020a056402269600b0046a8fe6d173si14297917edd.456.2022.12.27.23.33.50; Tue, 27 Dec 2022 23:34:14 -0800 (PST) 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=@russell.cc header.s=fm3 header.b=l7UZcfnv; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=a+FKGEmr; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbiL1HbY (ORCPT + 99 others); Wed, 28 Dec 2022 02:31:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232661AbiL1Hax (ORCPT ); Wed, 28 Dec 2022 02:30:53 -0500 Received: from wout5-smtp.messagingengine.com (wout5-smtp.messagingengine.com [64.147.123.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0CA7F58C for ; Tue, 27 Dec 2022 23:30:50 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 6EB24320092F; Wed, 28 Dec 2022 02:30:49 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 28 Dec 2022 02:30:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=russell.cc; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1672212648; x=1672299048; bh=44 +zc9E97R2R+SFM8ijIWLMom02/6ELql1sdLwVrY1I=; b=l7UZcfnvVrgpjuqggC Grdzit/mHSAE89fMlshNIlrwdZeGWWDA/npS/KWuPQ91qeRAbvcG5b2eUVos4xLI zy5Q7NbkB52OZoZrvKsS9/sdQ0NKaQ/bgyBawS1MmK+1goOte3Aiv5Q6cVQpczGZ V26wyMxlZWfpNeakM571Ls2cOhBHQWuaspCWtJDKomYszY6Dpvtsf1GSDAD/C+lc EeV+aEj3SLNyTpbjnLqZnOUggp6cn3qmBoo6EEOg/MlNBHjCTpmvKBR55vWjvGoY CrEFKjGow14oT3LhVsaey6tLPEBvrB2+ZkbKBE7aAaGXlEN1KgtdycxjW/1MtSPa goOA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; t=1672212648; x=1672299048; bh=44+zc9E97R2R+ SFM8ijIWLMom02/6ELql1sdLwVrY1I=; b=a+FKGEmrCQDz5LdzK7YgTWJP8kHeA 7tIm8KB81tCZ5BRzj4R8qIZxJin3Yy034f/bEGMdVpD1ZD5YXu4eApwhu+APpC5T SsHHxSt6mbZgPiwQ2Y5WiEaNJ2laTB4/CMXvVlMBd5NwN7ibzcwsC0pa37iERyhZ xfTLeXbNGe9UNDSm+7TKdsU8IxUEbw7qi6Sqk/aHxsXshMQXt+GIJlPCZjF7xwHW 4ywcpPCY4H9n6GUbKwLt/16Plo6Uig07X+r8if6PYQBsJYmIlwj4DRnbYnBU7KbH KuBcZrlMy2zyOGSQ/4OdiCI7Ylb26FDOuNbpuB0lmHY+YciXsE+qY5Sbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedriedugddutdelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdludehmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeftuhhsshgvlhhlucevuhhr rhgvhicuoehruhhstghurhesrhhushhsvghllhdrtggtqeenucggtffrrghtthgvrhhnpe fhvdeugfdtvdeiieegffefffekieegvdfgiedtjeetffevfefhtdehjeffieeivdenucev lhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehruhhstghurh esrhhushhsvghllhdrtggt X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Dec 2022 02:30:45 -0500 (EST) From: Russell Currey To: linuxppc-dev@lists.ozlabs.org Cc: gregkh@linuxfoundation.org, gcwilson@linux.ibm.com, linux-kernel@vger.kernel.org, nayna@linux.ibm.com, ajd@linux.ibm.com, zohar@linux.ibm.com, mpe@ellerman.id.au, Russell Currey Subject: [PATCH 6/6] powerpc/pseries: Implement secvars for dynamic secure boot Date: Wed, 28 Dec 2022 18:29:43 +1100 Message-Id: <20221228072943.429266-7-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221228072943.429266-1-ruscur@russell.cc> References: <20221228072943.429266-1-ruscur@russell.cc> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753442265727422603?= X-GMAIL-MSGID: =?utf-8?q?1753442265727422603?= The pseries platform can support dynamic secure boot (i.e. secure boot using user-defined keys) using variables contained with the PowerVM LPAR Platform KeyStore (PLPKS). Using the powerpc secvar API, expose the relevant variables for pseries dynamic secure boot through the existing secvar filesystem layout. The relevant variables for dynamic secure boot are signed in the keystore, and can only be modified using the H_PKS_SIGNED_UPDATE hcall. Object labels in the keystore are encoded using ucs2 format. With our fixed variable names we don't have to care about encoding outside of the necessary byte padding. When a user writes to a variable, the first 8 bytes of data must contain the signed update flags as defined by the hypervisor. When a user reads a variable, the first 4 bytes of data contain the policies defined for the object. Limitations exist due to the underlying implementation of sysfs binary attributes, as is the case for the OPAL secvar implementation - partial writes are unsupported and writes cannot be larger than PAGE_SIZE. Co-developed-by: Nayna Jain Signed-off-by: Nayna Jain Co-developed-by: Andrew Donnellan Signed-off-by: Andrew Donnellan Signed-off-by: Russell Currey --- Documentation/ABI/testing/sysfs-secvar | 8 + arch/powerpc/platforms/pseries/Kconfig | 13 + arch/powerpc/platforms/pseries/Makefile | 4 +- arch/powerpc/platforms/pseries/plpks-secvar.c | 250 ++++++++++++++++++ 4 files changed, 273 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/platforms/pseries/plpks-secvar.c diff --git a/Documentation/ABI/testing/sysfs-secvar b/Documentation/ABI/testing/sysfs-secvar index feebb8c57294..e6fef664c9c8 100644 --- a/Documentation/ABI/testing/sysfs-secvar +++ b/Documentation/ABI/testing/sysfs-secvar @@ -44,3 +44,11 @@ Contact: Nayna Jain Description: A write-only file that is used to submit the new value for the variable. The size of the file represents the maximum size of the variable data that can be written. + +What: /sys/firmware/secvar/config +Date: December 2022 +Contact: Nayna Jain +Description: This optional directory contains read-only config attributes as + defined by the secure variable implementation. All data is in + ASCII format. The directory is only created if the backing + implementation provides variables to populate it. diff --git a/arch/powerpc/platforms/pseries/Kconfig b/arch/powerpc/platforms/pseries/Kconfig index a3b4d99567cb..94e08c405d50 100644 --- a/arch/powerpc/platforms/pseries/Kconfig +++ b/arch/powerpc/platforms/pseries/Kconfig @@ -162,6 +162,19 @@ config PSERIES_PLPKS If unsure, select N. +config PSERIES_PLPKS_SECVAR + depends on PSERIES_PLPKS + depends on PPC_SECURE_BOOT + bool "Support for the PLPKS secvar interface" + help + PowerVM can support dynamic secure boot with user-defined keys + through the PLPKS. Keystore objects used in dynamic secure boot + can be exposed to the kernel and userspace through the powerpc + secvar infrastructure. Select this to enable the PLPKS backend + for secvars for use in pseries dynamic secure boot. + + If unsure, select N. + config PAPR_SCM depends on PPC_PSERIES && MEMORY_HOTPLUG && LIBNVDIMM tristate "Support for the PAPR Storage Class Memory interface" diff --git a/arch/powerpc/platforms/pseries/Makefile b/arch/powerpc/platforms/pseries/Makefile index 92310202bdd7..807756991f9d 100644 --- a/arch/powerpc/platforms/pseries/Makefile +++ b/arch/powerpc/platforms/pseries/Makefile @@ -27,8 +27,8 @@ obj-$(CONFIG_PAPR_SCM) += papr_scm.o obj-$(CONFIG_PPC_SPLPAR) += vphn.o obj-$(CONFIG_PPC_SVM) += svm.o obj-$(CONFIG_FA_DUMP) += rtas-fadump.o -obj-$(CONFIG_PSERIES_PLPKS) += plpks.o - +obj-$(CONFIG_PSERIES_PLPKS) += plpks.o +obj-$(CONFIG_PSERIES_PLPKS_SECVAR) += plpks-secvar.o obj-$(CONFIG_SUSPEND) += suspend.o obj-$(CONFIG_PPC_VAS) += vas.o vas-sysfs.o diff --git a/arch/powerpc/platforms/pseries/plpks-secvar.c b/arch/powerpc/platforms/pseries/plpks-secvar.c new file mode 100644 index 000000000000..3f9ff16c03c8 --- /dev/null +++ b/arch/powerpc/platforms/pseries/plpks-secvar.c @@ -0,0 +1,250 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Secure variable implementation using the PowerVM LPAR Platform KeyStore (PLPKS) + * + * Copyright 2022, IBM Corporation + * Authors: Russell Currey + * Andrew Donnellan + * Nayna Jain + */ + +#define pr_fmt(fmt) "secvar: "fmt + +#include +#include +#include +#include +#include +#include +#include +#include "plpks.h" + +// Config attributes for sysfs +#define PLPKS_CONFIG_ATTR(name, fmt, func) \ + static ssize_t name##_show(struct kobject *kobj, \ + struct kobj_attribute *attr, \ + char *buf) \ + { \ + return sprintf(buf, fmt, func()); \ + } \ + static struct kobj_attribute attr_##name = __ATTR_RO(name) + +PLPKS_CONFIG_ATTR(version, "%u\n", plpks_get_version); +PLPKS_CONFIG_ATTR(object_overhead, "%u\n", plpks_get_objoverhead); +PLPKS_CONFIG_ATTR(max_password_size, "%u\n", plpks_get_maxpwsize); +PLPKS_CONFIG_ATTR(max_object_size, "%u\n", plpks_get_maxobjectsize); +PLPKS_CONFIG_ATTR(max_object_label_size, "%u\n", plpks_get_maxobjectlabelsize); +PLPKS_CONFIG_ATTR(total_size, "%u\n", plpks_get_totalsize); +PLPKS_CONFIG_ATTR(used_space, "%u\n", plpks_get_usedspace); +PLPKS_CONFIG_ATTR(supported_policies, "%08x\n", plpks_get_supportedpolicies); +PLPKS_CONFIG_ATTR(max_large_object_size, "%u\n", plpks_get_maxlargeobjectsize); +PLPKS_CONFIG_ATTR(signed_update_algorithms, "%016llx\n", plpks_get_signedupdatealgorithms); + +static const struct attribute *config_attrs[] = { + &attr_version.attr, + &attr_object_overhead.attr, + &attr_max_password_size.attr, + &attr_max_object_size.attr, + &attr_max_object_label_size.attr, + &attr_total_size.attr, + &attr_used_space.attr, + &attr_supported_policies.attr, + &attr_max_large_object_size.attr, + &attr_signed_update_algorithms.attr, + NULL, +}; + +static u16 get_ucs2name(const char *name, uint8_t **ucs2_name) +{ + int namelen = strlen(name) * 2; + *ucs2_name = kzalloc(namelen, GFP_KERNEL); + + if (!*ucs2_name) + return 0; + + for (int i = 0; name[i]; i++) { + (*ucs2_name)[i * 2] = name[i]; + (*ucs2_name)[i * 2 + 1] = '\0'; + } + + return namelen; +} + +static u32 get_policy(const char *name) +{ + if ((strcmp(name, "db") == 0) || + (strcmp(name, "dbx") == 0) || + (strcmp(name, "grubdb") == 0) || + (strcmp(name, "sbat") == 0)) + return (WORLDREADABLE | SIGNEDUPDATE); + else + return SIGNEDUPDATE; +} + +#define PLPKS_SECVAR_COUNT 8 +static char *var_names[PLPKS_SECVAR_COUNT] = { + "PK", + "KEK", + "db", + "dbx", + "grubdb", + "sbat", + "moduledb", + "trustedcadb", +}; + +static int plpks_get_variable(const char *key, uint64_t key_len, + u8 *data, uint64_t *data_size) +{ + struct plpks_var var = {0}; + u16 ucs2_namelen; + u8 *ucs2_name; + int rc = 0; + + ucs2_namelen = get_ucs2name(key, &ucs2_name); + if (!ucs2_namelen) + return -ENOMEM; + + var.name = ucs2_name; + var.namelen = ucs2_namelen; + var.os = PLPKS_VAR_LINUX; + rc = plpks_read_os_var(&var); + + if (rc) + goto err; + + *data_size = var.datalen + sizeof(var.policy); + + // We can be called with data = NULL to just get the object size. + if (data) { + memcpy(data, &var.policy, sizeof(var.policy)); + memcpy(data + sizeof(var.policy), var.data, var.datalen); + } + + kfree(var.data); +err: + kfree(ucs2_name); + return rc; +} + +static int plpks_set_variable(const char *key, uint64_t key_len, + u8 *data, uint64_t data_size) +{ + struct plpks_var var = {0}; + u16 ucs2_namelen; + u8 *ucs2_name; + int rc = 0; + u64 flags; + + // Secure variables need to be prefixed with 8 bytes of flags. + // We only want to perform the write if we have at least one byte of data. + if (data_size <= sizeof(flags)) + return -EINVAL; + + ucs2_namelen = get_ucs2name(key, &ucs2_name); + if (!ucs2_namelen) + return -ENOMEM; + + memcpy(&flags, data, sizeof(flags)); + + var.datalen = data_size - sizeof(flags); + var.data = kzalloc(var.datalen, GFP_KERNEL); + if (!var.data) { + rc = -ENOMEM; + goto err; + } + + memcpy(var.data, data + sizeof(flags), var.datalen); + + var.name = ucs2_name; + var.namelen = ucs2_namelen; + var.os = PLPKS_VAR_LINUX; + var.policy = get_policy(key); + + rc = plpks_signed_update_var(var, flags); + + kfree(var.data); +err: + kfree(ucs2_name); + return rc; +} + +/* + * get_next() in the secvar API is designed for the OPAL API. + * If *key is 0, it returns the first variable in the keystore. + * Otherwise, you pass the name of a key and it returns next in line. + * + * We're going to cheat here - since we have fixed keys and don't care about + * key_len, we can just use it as an index. + */ +static int plpks_get_next_variable(const char *key, uint64_t *key_len, uint64_t keybufsize) +{ + if (!key || !key_len) + return -EINVAL; + + if (*key_len >= PLPKS_SECVAR_COUNT) + return -ENOENT; + + if (strscpy((char *)key, var_names[(*key_len)++], keybufsize) < 0) + return -E2BIG; + + return 0; +} + +// PLPKS dynamic secure boot doesn't give us a format string in the same way OPAL does. +// Instead, report the format using the SB_VERSION variable in the keystore. +static ssize_t plpks_secvar_format(char *buf) +{ + struct plpks_var var = {0}; + ssize_t ret; + + var.component = NULL; + // Only the signed variables have ucs2-encoded names, this one doesn't + var.name = "SB_VERSION"; + var.namelen = 10; + var.datalen = 0; + var.data = NULL; + + // Unlike the other vars, SB_VERSION is owned by firmware instead of the OS + ret = plpks_read_fw_var(&var); + if (ret) { + if (ret == -ENOENT) + return sprintf(buf, "ibm,plpks-sb-unknown\n"); + + pr_err("Error %ld reading SB_VERSION from firmware\n", ret); + return ret; + } + + // Hypervisor defines SB_VERSION as a "1 byte unsigned integer value" + ret = sprintf(buf, "ibm,plpks-sb-%hhu\n", var.data[0]); + + kfree(var.data); + return ret; +} + +static int plpks_max_size(uint64_t *max_size) +{ + *max_size = (uint64_t)plpks_get_maxobjectsize(); + + return 0; +} + + +static const struct secvar_operations plpks_secvar_ops = { + .get = plpks_get_variable, + .get_next = plpks_get_next_variable, + .set = plpks_set_variable, + .format = plpks_secvar_format, + .max_size = plpks_max_size, +}; + +static int plpks_secvar_init(void) +{ + if (!plpks_is_available()) + return -ENODEV; + + set_secvar_ops(&plpks_secvar_ops); + set_secvar_config_attrs(config_attrs); + return 0; +} +device_initcall(plpks_secvar_init);