From patchwork Fri Dec 30 04:20:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37562 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720499wrt; Thu, 29 Dec 2022 20:24:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXtNiTQHqIwrxDoOSSGWJ8ncIkreIdrIZNp97WL6YxCGpKycY/UpP3SjE19otb5SS7vyJXwR X-Received: by 2002:a05:6402:408:b0:482:74a:c3d9 with SMTP id q8-20020a056402040800b00482074ac3d9mr20095711edv.23.1672374242697; Thu, 29 Dec 2022 20:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374242; cv=none; d=google.com; s=arc-20160816; b=B8oBj7JasT4RzT5XVkZ7PsCXVGNt2e1VAurf1jfyDciLvmGiM172V9kxUNx+hVk+gb Zuypj4ABdCxtdHkaz4qVlIof89konEuq+pTjhjv6s0ZmiG/UPy4gBwsZRfSTA70z7Tjd bj3427MYEf80Hyk8H/KARN4NjyYGX9KwATEDMnzxWKot5cnvYj/lB7VAzj9jQrZiSmy5 AsBq4kfUINM8rCANSmSUV7Rjr9ly4JhkalAbwkYMhlL1d3Rvv1RAc0VAmBObM7DMVLI7 4pD3mwrtXZDxe6TiONpaZYklqwwGgXmKAbwELtnZzj+0ua9otWP5DFLMqHfNmx/v+JLY QdQg== 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=XJbvEmPb+g1LE1g1xP33R/3TgPpHHXBoBR0U+dGjhMyzWqzQteXojijNGBRii774rw 5EcB+VPFiglF7bElLu6zENAkNbTILD3MCRRmiiwtUD/wgxeHfgcAe+9VfiiJ7MKDorp0 t6ntU82rFJnkG9RbpOqb9L2Oeg7jdv8b6buKyIgnLsWMW2M6qStqmgta14QTU6uw6UTw KLxdKq4fB5w2XHSvbcM3qacL5/RjlHeGO5VOYn01V+IRGQEotyhAoSfPw27ZKE7UWM2i bO66MJXfECm+juF2oMYEsef0QFCvIW26vPGVcTR8hTr0A4v0seg31TQNTkrTDdBREZkq MeEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=N07qjmZ3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=xFgzCHB6; 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 n11-20020a05640206cb00b0046ce55c0f98si16725856edy.111.2022.12.29.20.23.38; Thu, 29 Dec 2022 20:24:02 -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=N07qjmZ3; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=xFgzCHB6; 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 S234158AbiL3EVP (ORCPT + 99 others); Thu, 29 Dec 2022 23:21:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiL3EVK (ORCPT ); Thu, 29 Dec 2022 23:21:10 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECEEA10EE for ; Thu, 29 Dec 2022 20:21:09 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 644215C0152; Thu, 29 Dec 2022 23:21:09 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 29 Dec 2022 23:21:09 -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=1672374069; x=1672460469; bh=yn /S5ROEzSnOph0KuGPaeywtNTs872W1IHLPpJmU4iY=; b=N07qjmZ3Ji/7yGH5Hn EeQsn6g38OB6puVyAnveYv95+MlMyyoyTADCl80OkaUy2YtEF4WTfYrZp49qS8/q w3YWeREnapP1VV3bN7t1L+2CoeEwcuXf5OzC1CnlDwPRaxMbacZ2tRFvFzJJfutX 2f/ogCvnsPLyB5cb+8oNz9mPLEmkrlTuWqBz0izdKsQWXJpmdvYlH1lTGJIVPeBM 4FbhC50u4vHX2kjFE4zSqFXsp6Sx7SUYSIwtIS2Lg6QOCaiOesgAwjN1qcD7irif Inv2ue9MIwzKXZv1UPcAPQ0dVMCXmYFaLSAhFQ9oXnPuu9ngT+7yhcGw5BwfNLvZ Fv1A== 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=1672374069; x=1672460469; bh=yn/S5ROEzSnOp h0KuGPaeywtNTs872W1IHLPpJmU4iY=; b=xFgzCHB6w5ubGeFsVdyWL5cGDdQUF h5/0yA/phVbZf7bjA+Fx0dUU8zg0XeDrH2oV5lt9QZ9KutKDjCjmZ7+rZxiCE1lX BYBoHALbo9nWqAZjGFPp0G+j+kfTvQ1LlhZO+mpc7KvFxGQAcjV9aMkjmLGbN/TZ luL/gHTjsWiYJ7SPrjmDcFp4vKZ6bPVATUmxO2lXPUsAtxOlcnAeSulGSD71KzvW wMuE7rjP/d1WfiTb3onnCWz5SvEMRg6LNu30rsMcoTMjcUQO7iXdjoFrpK+2smt0 wjsGsGgQ6EuBPK1lfp7SNuBiCG4dwABnCy2U1rnVTuH+IlDs+qeg6nK+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:06 -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 v2 1/7] powerpc/pseries: Log hcall return codes for PLPKS debug Date: Fri, 30 Dec 2022 15:20:08 +1100 Message-Id: <20221230042014.154483-2-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611493630152634?= X-GMAIL-MSGID: =?utf-8?q?1753611493630152634?= 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 Reviewed-by: Andrew Donnellan Tested-by: Andrew Donnellan --- 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 Fri Dec 30 04:20:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37559 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720217wrt; Thu, 29 Dec 2022 20:22:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXuwZUmcVfFgI8+tnWmKp/22uF1BO+y/4YJEaiR10K1PTo6xxZ1SF+5C9en7Qi4VaixukN3+ X-Received: by 2002:a05:6402:378c:b0:483:b15a:3206 with SMTP id et12-20020a056402378c00b00483b15a3206mr17345068edb.23.1672374174329; Thu, 29 Dec 2022 20:22:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374174; cv=none; d=google.com; s=arc-20160816; b=JYByLCsdymOnPB/LHXU7MwI0lNbZOiEdTGCcjOkEm92DqCQKKrL2uv7cJ/2RxyPA3s L99ap9xYlJ4U8nIpJGzmoPY3jIS/mq/lg+5bx7C93hQwujD2D3P5xs7Yd+wLy8LRrJ1n /cdyRiTsG83AjD7iIC5x++fcSyNxbQpwO9OuH0XMdXPVk9Hwhb6WC3bg9RQPv8PYlj3V /5uZ5fHw5tTqa0/MPrfbPbay9he+/HuZOAmHR6tN3WsWm5BZfzBeIXv0Y4hlT3vXXUnB u6x0z8gFokIDc9szISgExnJG9dFOHVE3G7VgXe1aD5U+HqFEvwFPiuOBr5I6T9q7H6/A QAUA== 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=Wr3ip+NP2P8FCoiYyYLw6uFCtfFqAdV6YwJf+OCaWiSvoiGA9rLVG+Iwe2ZhSTRUoe FQGWejprtK9FAX/6VgODieoHWhFOBjR/CjFTG9Rci1N6KKhnPGqoLXuWEREVhWBm/tln 0hKySukFkMLoWuSl/mCbIxYMteGtIHapdy1/1b5rhTojVdHOtdQ3kPy1g8zuH9ke/YgZ NRH64buhyuCPglgDQo+9wkWLR7NllM9yuegmustIRI7QU11fDzGVg4r4Bz6xNeFU4B/R ZDgeut7BDs6dWafbsQDFG1VI3Cc/7vR0EWGoOuL5ceFSnqdDKaBvh1uXfDBseaWIHPy5 cg2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=AdfnUSDc; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ZbpGheFs; 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 h3-20020a056402280300b0045731196587si19400469ede.64.2022.12.29.20.22.27; Thu, 29 Dec 2022 20:22:54 -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=AdfnUSDc; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=ZbpGheFs; 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 S234412AbiL3EVd (ORCPT + 99 others); Thu, 29 Dec 2022 23:21:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234024AbiL3EVO (ORCPT ); Thu, 29 Dec 2022 23:21:14 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C00F10FD for ; Thu, 29 Dec 2022 20:21:13 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id E5B9C5C034B; Thu, 29 Dec 2022 23:21:12 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 29 Dec 2022 23:21:12 -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=1672374072; x=1672460472; bh=av aCv9mDt906Bh4sj41n++Uvq9fM0k+OtKCj4mLejVk=; b=AdfnUSDcvhkNMT5qCO AGnXPlAaZOOHNImBd5bJ/NIwV2xgkd+58jc1AoriH5xNS6O3fRcoE6SNRuqLlxaC cK3q7xPoVNJ/o5hpxB1azDqdGxLQgPNxThdDaRbb+DyUP/DynwEuZEMKYpdsAAG5 PYMMGjVpK4SeMEkHZ9Sw7s30jbdUZOiJUuUNGaeD8PvSv8kNtDis/XU7D7endoJF BO0lhG9sD2t3Zj6TpS//5ramOMbnDMAoxhPBXe6aJHOTmSE/78l6fHrJAhnlIRqX iqq0GwF330APEiWRq5gb2p9SsJl46Ntwuwp04/9bm3vpH8hyKfwIOnvM84rx4ahx 2Ucg== 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=1672374072; x=1672460472; bh=avaCv9mDt906B h4sj41n++Uvq9fM0k+OtKCj4mLejVk=; b=ZbpGheFs815c1clpgDCXEJB+Kvsq2 78bKBhR5qE0TTh0YcJGHAK43gEupTOcCfHdBwBxzEEq+9VQ1Ff+HNH7Zzv6Ro7wT jlOXwTxq7aWnVRCGlQ5hsH53iHaPdHApDrqR5LKkAbGJTbKbkjZJHsILoECooYuf T3LbJe06dlYXy1k9J2UCo8FCjJbTVSYRfK659IuDx7/vKVEJEz2Pj8eR6NYsQQ0y MGu3U5OrfayvY4YNSknH2QIhe4AL37llflnp8sxXgPFggduMkGv5lDrM+8i3NYMV 2vVTNpBcYNTZEQZjiX7jI+zAS5cxAMpjnxa4LcRigjwF1CUg/BqOOw5eA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:09 -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 v2 2/7] powerpc/secvar: WARN_ON_ONCE() if multiple secvar ops are set Date: Fri, 30 Dec 2022 15:20:09 +1100 Message-Id: <20221230042014.154483-3-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611422487453982?= X-GMAIL-MSGID: =?utf-8?q?1753611422487453982?= 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 Reviewed-by: Andrew Donnellan --- 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 Fri Dec 30 04:20:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37560 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720224wrt; Thu, 29 Dec 2022 20:22:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXuga3QYRBei58J2D9Q7RiPbEWfuwT9BFuXNw2d01F2mvuLTBujCufJXdR1iA7ttZxJzltLT X-Received: by 2002:a17:906:148a:b0:7cd:dbe8:e4f7 with SMTP id x10-20020a170906148a00b007cddbe8e4f7mr26399262ejc.77.1672374175945; Thu, 29 Dec 2022 20:22:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374175; cv=none; d=google.com; s=arc-20160816; b=qHU/cNnJATufeKcEq3tvMltTBeUE8cEXRgL10DoJju0d55QjVedv71Ef9+wjtHNjIl P0lyU7WFWPwXFfdoVBP24tmeXZ1U6W8XFgO01I1GemnSsxnjrq1+gxnO/eo3JccKLqeK 7fbJqJs3TM/t/7TMH7WpPU/Yyz/LmuGa3RMgZHh+9gZyU0CToiCdcDn84+i67WaFn5WC sJi1io0t9Vkr64tlqwivSNGS3a9xJbqwPFeCHv8zffvt4DUTSiSSUDVmlge8kTtA01XH JVlggL2YKzyXgmvTcg3dV6KByOzSdIu6k7wzS/agIdQidKDtEHSkCeNSnznXx1kVFasU MGOQ== 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=JN9NFHKSRoX2NmbrNsnkR20cy9kBqiSvPpqIXpLNJ9I=; b=BodBXjQVWayAjhUf8XJyi3HPir5gAgQZC1HAfM9YNo666aJccX1SBrl7KSh4u3bWBi /WZMoMJukaNvL/tc/uDjfgugip3WGYFQqWJ/e2npdR3MJ38pVO3uz1CtmvyJtqWnJQQR /LfQPkWtwR4rtn6XgkZKPAdVsiY+x+Y9R6qBiR5rGTHrGmGLZHLPb/wKKeQc6s3V4HHx y0RpK57IJhEtSoFUNGeve38X4c3TrnCyMII4LoOBHfPBw1d5GufMFr3Tt5iTYGJO1QwX qbqpniSRcTrhyo/qXQpqwf+5PRryxCjZJjvLNmAiT1YqGp02OLzHCju6+HXAahIP1ltc ejuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=IoeRkN1W; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="tp8/pSEs"; 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 cs12-20020a170906dc8c00b007c500a2f33asi17996111ejc.208.2022.12.29.20.22.32; Thu, 29 Dec 2022 20:22:55 -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=IoeRkN1W; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="tp8/pSEs"; 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 S234454AbiL3EVj (ORCPT + 99 others); Thu, 29 Dec 2022 23:21:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234234AbiL3EVS (ORCPT ); Thu, 29 Dec 2022 23:21:18 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03DC4266C for ; Thu, 29 Dec 2022 20:21:17 -0800 (PST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 6E5795C0349; Thu, 29 Dec 2022 23:21:16 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 29 Dec 2022 23:21:16 -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=1672374076; x=1672460476; bh=JN 9NFHKSRoX2NmbrNsnkR20cy9kBqiSvPpqIXpLNJ9I=; b=IoeRkN1WglL20SiCEh 2UQIey6viwF29x0zjR7Q9s4ltywDVuL8CFWtA7hAkUZWMFS2gpE+yypCxU3LnTxX fbJFTH45w6Irl0veEzPsEYD6QjMmsC4rDLLPbKsc0DPk4LE7ryT4YmYHqeQ3fqfS gRT6W16jUV2Pv/L+SIe8EBfEXJ7E3c5vfUotPnteOHBkU1mjInfwqXSVWfCdBgtz qDHyjp+lGAOlk5EkqVzPQf80ROpaJVT9dfsPKQptwFuXapvZQ4PmlC8g4tY/wbuD QdyS8jPi7EvCxIcVxJqBYnnAl4zFCd4M5/mMrtx8ppWb/K9I2QrVAkYHCtnh14I/ ZyWw== 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=1672374076; x=1672460476; bh=JN9NFHKSRoX2N mbrNsnkR20cy9kBqiSvPpqIXpLNJ9I=; b=tp8/pSEset17Jvwo3IfyyS8nEYDTn /rOyZWHEij7SxFlKtuw1jFWtOxWHeORgKx4+398lx53JMKTPX0qMxUm+PqJrLCGr Bs4BGCBmtbhIjXiS6zxFE1zEiDdMeuUNWxll5zOfun3vtZytvjFv2bFUxaEMObgH j7Jl+x+/9qtiRLp68yoxjxmVKLQH3HQO+uFJnMjqUwAq/XR0NjGgKYAkev+4YHFe mL5gZ+dKVf3jmbboCRTmIFIpp5Ixqu5byKKJcvOwifzV41dhaEwfqawlayPPEuUK nrxhn+YTpZkB8oe4v5iUcx5LIMjAx1w5cOfq9XAYqFd1sNQn4QC4c3GiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdduhedmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:13 -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 v2 3/7] powerpc/secvar: Use sysfs_emit() instead of sprintf() Date: Fri, 30 Dec 2022 15:20:10 +1100 Message-Id: <20221230042014.154483-4-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611424182068243?= X-GMAIL-MSGID: =?utf-8?q?1753611424182068243?= The secvar format string and object size sysfs files are both ASCII text, and should use sysfs_emit(). No functional change. Suggested-by: Greg Kroah-Hartman Signed-off-by: Russell Currey Reviewed-by: Andrew Donnellan --- v2: new arch/powerpc/kernel/secvar-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kernel/secvar-sysfs.c b/arch/powerpc/kernel/secvar-sysfs.c index 1ee4640a2641..02e9fee1552e 100644 --- a/arch/powerpc/kernel/secvar-sysfs.c +++ b/arch/powerpc/kernel/secvar-sysfs.c @@ -35,7 +35,7 @@ static ssize_t format_show(struct kobject *kobj, struct kobj_attribute *attr, if (rc) goto out; - rc = sprintf(buf, "%s\n", format); + rc = sysfs_emit(buf, "%s\n", format); out: of_node_put(node); @@ -57,7 +57,7 @@ static ssize_t size_show(struct kobject *kobj, struct kobj_attribute *attr, return rc; } - return sprintf(buf, "%llu\n", dsize); + return sysfs_emit(buf, "%llu\n", dsize); } static ssize_t data_read(struct file *filep, struct kobject *kobj, From patchwork Fri Dec 30 04:20:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720268wrt; Thu, 29 Dec 2022 20:23:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXtilDA0gGZdr2o1TFi1AQrcA6WKHmbljcRINKzhyPksAoT9R3c54L1D8ZDBETBG7A+HF8FB X-Received: by 2002:a05:6402:331:b0:48a:e829:76e2 with SMTP id q17-20020a056402033100b0048ae82976e2mr981371edw.11.1672374187539; Thu, 29 Dec 2022 20:23:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374187; cv=none; d=google.com; s=arc-20160816; b=fF/r4D+PdQUBBqrpQG9+1mDV22+1+gWEGvWsPG4rzViIqHMffYKeHmlqDWVBpEHZEp 24Skk2Fgl/j1AS/75kq1uiPsSCFhbHTMHV9GNy90JiNqwPLEUZuGL65iiqM63mr4hytH /pZEUD2CsBhuMFQVwiACHJi56EQlWNKrC579/rP8acNQHlco3PEycRNujnI+pDYkK/fc GHDnZBA/qh0nzM5ns3RHvwBaAbO8TR1JOhuqbP6XX1YPoDb7kZg+mcbpiFOWrSSHspWi 08j4gu2iSS1fpFvvj2IUaV6v14OLSqleWJMxb2dVzTslNUUgnb2Y/MAh7lDJg0ZALiBW xaRA== 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=e4W1n9Rq2Lh1pGU541iP6qdQ1ybWYpnkP5s+p6s8HIE=; b=psheaJ+853Ss8TjOLxDKbLHsn/NEkmKNmkl6a7EL5Ekv+XljLj/SWUw6V56aSTzmIn XP5K6fdOS8v1w4XmI3UHhtWoRBRvD0da4/NzVNjupM+H1P6GTfJtQyM7kSPwYUfl+hB+ Qy0MJ4jLcHiJbvP0YMa1+aVCVbMYyQmEjhcOQNFV3+liXSraFaPn7fnJiq/Uhv7o8Tqx BcXWESzOLyONQFgXyf9+jM8kk7WEwe84rT+nbCrFiJlt8WLzr+RSdr1R1yEweqMAvc8Z DxhiO1tCI093pYm6ibv+4ZxakFnkG/r4ap3W84387swQZ0asSpQ/dxRtl9+nLVpTI3kZ 9UWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=hODI6cBZ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="N4+/Tnzg"; 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 f26-20020a05640214da00b0048999d127f8si2725466edx.526.2022.12.29.20.22.43; Thu, 29 Dec 2022 20:23:07 -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=hODI6cBZ; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="N4+/Tnzg"; 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 S234393AbiL3EWC (ORCPT + 99 others); Thu, 29 Dec 2022 23:22:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234229AbiL3EVV (ORCPT ); Thu, 29 Dec 2022 23:21:21 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4FB2189 for ; Thu, 29 Dec 2022 20:21:20 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id ADE235C034B; Thu, 29 Dec 2022 23:21:19 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 29 Dec 2022 23:21:19 -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=1672374079; x=1672460479; bh=e4 W1n9Rq2Lh1pGU541iP6qdQ1ybWYpnkP5s+p6s8HIE=; b=hODI6cBZkLPfno+wow JZLp+0yufbvAiF4jHRgyFGmzw5qhrdER6aXzUglusJBc9/JuqFJZ8Edhstn3rxL0 FopRzpj1WGK3JDNpl7xYFg5Qdri51N5ICNLyBSNOOeba4+51pHVgk082qO5PLaVJ 3LFAHz5zvGiTGTS7OgdLgFwHUMiRwdnUGoTUbpXexX+bFXvopwzTYQ2hXTO1QkYW EItwJlhb8G9JZRG1mXFLTW+5doDO9gljwJ1oHbfLC+b0IPhnCRy22dmXNdvzcu5C krOomkCsrr93HXosLwS2PvfyDcfbVoOBOnRSfhcZCRowd0dDN8Juy+mwd8ciIX6R AqXQ== 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=1672374079; x=1672460479; bh=e4W1n9Rq2Lh1p GU541iP6qdQ1ybWYpnkP5s+p6s8HIE=; b=N4+/TnzgXl7LlTl5oT1urYsTIhdfV gOyEF9tw7R2B0wOe2FXw9ge1/GFrphHRYctZkI6lLfY3c415tXFEoBd5pPbXPbSU FuzEGHng87OQjAF3tO4Kem9hWJBa96kXQp1CuvDWS8bSw+ddMqIzGUetvIDXCH4F kSdCdq+OQza6QIq2Os/PY3dWtXtwaS4+gR/2r9wMMtn6GjNmWiBQxoIc9jfRCZAy bgn/xIciC5taQvu2otiv+lmCoUaziQN/ULS+/bx0o7uA0N5L6SR3I90ILu3msf1f b6dPJ6L8vP4Fgu7cgEGLQ4kCi9X9j1zzO04F+9v6CKQ4C6PNA1CzsbhiQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdeilecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:16 -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 v2 4/7] powerpc/secvar: Handle format string in the consumer Date: Fri, 30 Dec 2022 15:20:11 +1100 Message-Id: <20221230042014.154483-5-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611436125351498?= X-GMAIL-MSGID: =?utf-8?q?1753611436125351498?= 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 Reviewed-by: Andrew Donnellan --- 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 02e9fee1552e..190238f51335 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 = sysfs_emit(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..5e9de06b2533 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 = sysfs_emit(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 Fri Dec 30 04:20:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720610wrt; Thu, 29 Dec 2022 20:24:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXsr+B1irlSI1LEgoVCIEE1I6Z2WcLtQlkHDw82JE7bNQKOyXBkBWinuk7M7cx1041VmRpAT X-Received: by 2002:a17:906:7187:b0:7bd:f540:9bf9 with SMTP id h7-20020a170906718700b007bdf5409bf9mr27982624ejk.32.1672374277789; Thu, 29 Dec 2022 20:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374277; cv=none; d=google.com; s=arc-20160816; b=NI6UndNFCfKFA/KWM8c+WVtp0o/SKhJJSCWdJ9tS7DVu1vwQSm3FJIA8AuF8OO6rTb qrq10lh0qWV5U97HbFPxJ1BTSwJe/tnIt9czIui7Wg/a9GFtiWICMsOn79Q0s0Fk8/mO qZpTVj20LRNPb4PFsVsdW7/IY/GHSyW1enna6V/9gaXyZ/NEPcDY+j+svEGTpRXzjBay uFtnhrzGYxkaDuMUfdhf5OUItGdjvQ0y6u+G6ruw3AjxXza243tmNaYpdVyW9eBxJP3V OsIouNU56O5KtRs+AcYkAhv1rI/Rmxx/VB97ElkEPr9hXozLtMeZE101BDijJwW/C8ty CDGA== 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=72W0OI05DA+JHi5r5u4GIP3geuabyTmRWs9HRRGhXa4=; b=BW8S4BnjPFwSpjUd+IN8lrKZPzUowH2YCMLIU0E8a4wUdDIhqbjO8mseCDuyyocnI8 G33CZPzOdwQM/wF6ri6auQkEXS3ohGCPda61wXkiekzIp2nRiaABfmrp9nMzuJV1A3EP j2OAGKdMrAVO4oTLBa7ZAUg+q2ybiJrYDqJNb3nPsJl16NEi46qHQwUwlcVwbU7hh0jI bq1LVi+v/Ux1qVuzUY4vbCfc7sB0CHGEA1iB8eeO4GYIw/8g6oZv3/yf7Hs4KQYCQWTS qEVy3zYWe9doLrFx6888medxI8tr8eOBsm95C7IR30AvFS9gz3BHACegTkV1zbiKWjsO 6KzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=noEHZLOK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="oz6/6eAj"; 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 ml21-20020a170906cc1500b007c01c6cf01dsi14142449ejb.800.2022.12.29.20.24.13; Thu, 29 Dec 2022 20:24:37 -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=noEHZLOK; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b="oz6/6eAj"; 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 S234443AbiL3EWF (ORCPT + 99 others); Thu, 29 Dec 2022 23:22:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234395AbiL3EVY (ORCPT ); Thu, 29 Dec 2022 23:21:24 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3DB62DE1 for ; Thu, 29 Dec 2022 20:21:23 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0B1CE5C0327; Thu, 29 Dec 2022 23:21:23 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 29 Dec 2022 23:21:23 -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=1672374083; x=1672460483; bh=72 W0OI05DA+JHi5r5u4GIP3geuabyTmRWs9HRRGhXa4=; b=noEHZLOKfwEayFpy7M Lkdjv+FpOghAHpvBwzQPIa8ccbfOKptS5Wnjs+4nOGuv47qIiEw36sy51OFa1opb 1rvbtnNuyBjxB2jstDY6n9DCbYjdjbS53JfPIuq1a/YHgj6TYmIecADVZ+4f8Vfx 6oMOA+i38bRlYTeGCm1v/7DEr4Vmw521r1Pq2hESaHXysM+Y/aXhrp2CfE5vcNrc 24DPcgUD7rKm4BO3l2U8ZwD2QlvPFSmVZ337G7tpUMCNha++2jCjoIqarcMLVEfZ 3TERlqEwylm+eiFBisyLBLhRLsf6LB7OfhvXxF7yrJg00eSzOHA4//KqSSYLTrKb g1uw== 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=1672374083; x=1672460483; bh=72W0OI05DA+JH i5r5u4GIP3geuabyTmRWs9HRRGhXa4=; b=oz6/6eAjEPtOxB4ASiBh7l7sn2emL EpEoznL1UlztE9eK540gu9Qa4SBYAUgh/rQdl4jPrj7MXjcTR1Rm2x5O99rOIzP8 K1B6LTZdWdAB/GfZqS0sr81sCKSg/xs744aTcTU354vPb7Pw6ccJgGO/XRIdtvzf 6kB0vfGXrxt/5VpnK0bnpkABen4A0uV2kXEf6q/pn9eVqajkU2B4RfFy4Rci29r8 aZIroLEXNYmvZB8l3wTKN9nu16XDLdmsYxjhXXCvLhoQCkWsDAGovRwGOCuqPLhx PrZvaFCzBs1J/BXxtW7rLIagvc/tig5XAKOqvfMhuEQ+s01onzgV0GkMw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:19 -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 v2 5/7] powerpc/secvar: Handle max object size in the consumer Date: Fri, 30 Dec 2022 15:20:12 +1100 Message-Id: <20221230042014.154483-6-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611530874022348?= X-GMAIL-MSGID: =?utf-8?q?1753611530874022348?= 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 Reviewed-by: Andrew Donnellan --- 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 190238f51335..aa1daec480e1 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 5e9de06b2533..07260460e966 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 Fri Dec 30 04:20:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37563 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2720583wrt; Thu, 29 Dec 2022 20:24:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXtRe6vrX1scOJc859ypPmtOQlg3jhYzdOpdX1/0mjPFvXfysBW9+xlhph0NLC0SJAGrMTda X-Received: by 2002:a17:902:848d:b0:189:5f5c:da1d with SMTP id c13-20020a170902848d00b001895f5cda1dmr30265006plo.18.1672374271740; Thu, 29 Dec 2022 20:24:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672374271; cv=none; d=google.com; s=arc-20160816; b=ynBdWtl0WT1FoUjx50IB/CvtreWCzViy/TIhRWdIgh5PE5OznM+fN6hjTNJx8hJYMT nWrEN7qDtM4h4lx74RDmZbenuzCfqP/Aqf13bh3XEv0b6gUMKEBgQlqncf3zn1VVlqsn ePRMJE4PtMxrZSKbT1qdFAWlBAHhfDDL1bDTqoI8r1M/qePryf/M2MWwemKkCz6zDwQi TjfIs5m+4QBh4mu4xsUwp2Ujq/ZiR6MQMD56tDgXWfuU6CRCqVb95ARCZMCSbYvv+wcl eeDWdlPm7V2yUFJnMP135R4PIGjjuKsL0tUVED7qDyeejLk67qr45Ewbi4aDtmvbZ7t9 5KWQ== 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=iTOttKbNR7xkPMRwFqFwNhSHOJKloxjRTq8OiJSL07I=; b=Mx39jtjIPpPNwXpptT2omJUGUxZpNRoOJ+0S9+OxJjWIquioH73rDQm6u3+AnPHD8r SriFpO6tq+hEegUN+PxokAz/jui0EWBu1eBhO/K9y4rINTu3rI0ZQLBdCePFbqc85waF 9JN/EZDLfc8WqMNpsrf9IiyEvnyNO6vL9rZtai7xUDYbDP9G7gRvGXvf4xfj+/WMDAZT KOcMFOnv8wh2sZ5szYfVQbQpteVyheVVmuI68F7RWi9CFD08jizSkMLvcMy4YMAupo7y zGjx53ibYWkrWVXABo4JwEHZdTTdraYE+nbWjCJYVD6gJxaae9CZ7rVZEl9LBLP8oKvj WRVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=Vjau4z2C; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=fYSOlDwX; 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 g2-20020a1709026b4200b00189d0fa14d6si19716197plt.13.2022.12.29.20.24.19; Thu, 29 Dec 2022 20:24:31 -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=Vjau4z2C; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=fYSOlDwX; 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 S234535AbiL3EWM (ORCPT + 99 others); Thu, 29 Dec 2022 23:22:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234450AbiL3EVi (ORCPT ); Thu, 29 Dec 2022 23:21:38 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E27FDBC2F for ; Thu, 29 Dec 2022 20:21:26 -0800 (PST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4F4DD5C0152; Thu, 29 Dec 2022 23:21:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 29 Dec 2022 23:21: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=1672374086; x=1672460486; bh=iT OttKbNR7xkPMRwFqFwNhSHOJKloxjRTq8OiJSL07I=; b=Vjau4z2Cjv9WSC/QJQ KFLCgZfn04hK/3uFBesviigBnvowu3buCYgv0sgx7NjjwJsECaqqPKb/86Gfa44X lENo1cQVVcnuB/a8KstSqkarlQMerhe+7tJINmbZaF21ZROZIgI3Ui2/wL25jAzn 20mAt/VTIKxtwNWlZs2dzN6T2Tg9u7FboAcfOA81352JW4fgya4scByMB75Jdtr4 lhX4CCxsfPblDM/kZwSvUzt+yQAPZ7EgJAzkGzjFXG/gbFCepGXpCVOzg4Dqixjx jYgfDLgJ+tBXj3l16zZgVfA+gGbhr1Gv+3n74aah2gQ+o28fKCHdtItsoR7lYDcj KHmg== 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=1672374086; x=1672460486; bh=iTOttKbNR7xkP MRwFqFwNhSHOJKloxjRTq8OiJSL07I=; b=fYSOlDwXmFv07ShosbMAKkMWi4MJv gs+5tBotLlHPBvn1jnpKJKPnYq3DYfSYfvgz4aekBTvu38y2oKwaFfKZznKJhgeY Rs5/zuJDgL0Kudsu9/IcZCMp4fVftbSWHbRX+zX6j68Qm2OQQBm38Iiqxz/iJnHd JO/eKgULNoZC/805YfT/c23Ac8s9/Gy/L3oZP+qQVx04n6tZ18Fk1FdlCKs2sTA3 xzL9L3scAHbA9v7l+pnRka+74RyRrnF7c1bhakE4Er55n5rnqa6+TnJol1z1PWf9 BUHUvpng31kHa4eTai9cDN92poeQNBBxXVxs/cFtLQyJOdZUQsk8Y4LVw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdeftddmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21:23 -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 v2 6/7] powerpc/secvar: Extend sysfs to include config vars Date: Fri, 30 Dec 2022 15:20:13 +1100 Message-Id: <20221230042014.154483-7-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753611524505190784?= X-GMAIL-MSGID: =?utf-8?q?1753611524505190784?= 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 Reviewed-by: Andrew Donnellan --- 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 aa1daec480e1..ad1e1d72d2ae 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 Fri Dec 30 04:20:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 37565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp2724589wrt; Thu, 29 Dec 2022 20:40:55 -0800 (PST) X-Google-Smtp-Source: AMrXdXssp6BxtYA3s8oNUsBj2ve3vDGRkXrBOH9Y9twYPXrPNnCLB9yIO+gUo/Y+TzoS9SWJyZNL X-Received: by 2002:a17:902:a3c7:b0:192:a1e0:260c with SMTP id q7-20020a170902a3c700b00192a1e0260cmr4189664plb.2.1672375255116; Thu, 29 Dec 2022 20:40:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672375255; cv=none; d=google.com; s=arc-20160816; b=XSsQKrlHXhfSSKuNCRIq5Ded33WuZzm3WatgrfU6UHkkl8Ow143yAG/YmcNOxhbx0I EkP46d7cwUkR8MUmBSKtKBoYQm8SZtnAYQN5+L8A11xWz2xwUrL2cIwkP5b9UymH9YCO VUEaCNh9xAzWqB+ED5NWwdEurHOFPPVVc4WBYuXewRDey2iKK2PCW+vkTHvOnu+HNSem kv4CrBlVJGNBSxlLPVBeb2kEfAi7kLgzSK45PNFOaFKSPe+M3xMm/XQjXQN88FkcczbT zq2uXbJsHMlsNvrSIgC9BhBveh0EaS8P2PalS7l9SsgZXrrR9Zc986UTjBG+5CUihU63 rv1g== 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=0iI9uNdg7u1ePhdspj7we44nPvxltr5QTxIUnJs5cyw=; b=eU3KRj967IM0baIW7xpwVleKHayhiiCs/JAl8c8P9dQi07pg0mM/nmFhOzx6wpGLlQ 9DT5bSgKYXXr4IplOd8HuVz+DrCN4JUGQprYpnbeLJRlQiucTcX9kZ7UCN6Xgv4zaqVy UeU/S4nlknTSCEMwM/5iYw/K8LUrGyiSYx3Z8gl5JF9cOpM7pA4p6ITa3vtP2yTz+OYx 0MTWjkhkaU6ag1lraV4ZxyfhxAJT1De8Ok83fZyLuNzpIq18Fxun81aI1sHYOBbm+cvU a6L9wxi1aWU2ALf/Vc1yC+DX1VTXXrgjFp0GYL9yAC0M6QhBXuqa2NyC8H/nZA7ScQ1K mwxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@russell.cc header.s=fm3 header.b=HV9Y+VHz; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=NAwPkQR6; 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 v6-20020a1709029a0600b0018981c83ffcsi1337414plp.4.2022.12.29.20.40.38; Thu, 29 Dec 2022 20:40:55 -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=HV9Y+VHz; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=NAwPkQR6; 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 S234563AbiL3EWR (ORCPT + 99 others); Thu, 29 Dec 2022 23:22:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234141AbiL3EVn (ORCPT ); Thu, 29 Dec 2022 23:21:43 -0500 Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A43D2AC1 for ; Thu, 29 Dec 2022 20:21:30 -0800 (PST) Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id D719A5C0152; Thu, 29 Dec 2022 23:21:29 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 29 Dec 2022 23:21:29 -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=1672374089; x=1672460489; bh=0i I9uNdg7u1ePhdspj7we44nPvxltr5QTxIUnJs5cyw=; b=HV9Y+VHz/hw9hsNd8a GjV+n/geKnOOrEBHJCKY+KmwR79ocUyaqRjQKFoFCoVy1dc8pqWvBMjHVzPb3+Tq RHVGWd+otuR5m47PWFCDRaNlVEYwwXbsRNzffL1vFuGmpqRWSOL1YwnifHYbg4vZ 3MPQVfwOgbQSh8wVsjil0GAEsjr+1INSx2NkRyYFl9LYdJknutL0iG141LPAvfiE F28cbJDzmievZ+le/d+/qLRKK4DD2G0TriuIuhizzxcnN/EwLPXzOsWgBZ/VzPRv EYs1otARvtlkuWFe8ZGempb+hkxS93QYmDVS5Qyh/Pmwfu+yiYEAplsT17DIpl03 jrOg== 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=1672374089; x=1672460489; bh=0iI9uNdg7u1eP hdspj7we44nPvxltr5QTxIUnJs5cyw=; b=NAwPkQR6lKwHXKbbSKwIyb51J5VoC vBU0urw9GrjR8cdiSzhXzL8XHk0HTYRKJhCKsbyFjiuqAuMn3xsTSdixZGukPaP9 z62dk/Qgcd5zB3MXmQ/uUei2WV+Q6Nc9BByWrmGrIAOcxJ0n4WSsPADULaXyGgIi q0SgAJm2IUGz76cw0xlGik8UsWMMKKXNO5YSWkm4d7edkTReQPBymhb4JKrpyBXq 6zkMub6iZX8Bsdh0ZeZScQSJvqiZ6raq833GhF2O4BpKOK19EzZ3h1Xg8xNqxtfn THh1EJFHAy/qaiDcVjNH7HI0A1jPo6uVl43TlAPHrB5B976AmLWSu3r9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrieehgdejtdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdduhedmnecujfgurhephffvve fufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfhushhsvghllhcuvehurhhr vgihuceorhhushgtuhhrsehruhhsshgvlhhlrdgttgeqnecuggftrfgrthhtvghrnhephf dvuefgtddvieeigefffeffkeeigedvgfeitdejteffveefhfdtheejffeiiedvnecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomheprhhushgtuhhrse hruhhsshgvlhhlrdgttg X-ME-Proxy: Feedback-ID: i4421424f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Dec 2022 23:21: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 v2 7/7] powerpc/pseries: Implement secvars for dynamic secure boot Date: Fri, 30 Dec 2022 15:20:14 +1100 Message-Id: <20221230042014.154483-8-ruscur@russell.cc> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221230042014.154483-1-ruscur@russell.cc> References: <20221230042014.154483-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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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?1753612555908849327?= X-GMAIL-MSGID: =?utf-8?q?1753612555908849327?= 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 --- v2: Remove unnecessary config vars from sysfs and document the others, thanks to review from Greg. If we end up needing to expose more, we can add them later and update the docs. Use sysfs_emit() instead of sprintf(), thanks to Greg. Change the size of the sysfs binary attributes to include the 8-byte flags header, preventing truncation of large writes. Documentation/ABI/testing/sysfs-secvar | 67 ++++- arch/powerpc/platforms/pseries/Kconfig | 13 + arch/powerpc/platforms/pseries/Makefile | 4 +- arch/powerpc/platforms/pseries/plpks-secvar.c | 245 ++++++++++++++++++ 4 files changed, 326 insertions(+), 3 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..466a8cb92b92 100644 --- a/Documentation/ABI/testing/sysfs-secvar +++ b/Documentation/ABI/testing/sysfs-secvar @@ -34,7 +34,7 @@ Description: An integer representation of the size of the content of the What: /sys/firmware/secvar/vars//data Date: August 2019 -Contact: Nayna Jain h +Contact: Nayna Jain Description: A read-only file containing the value of the variable. The size of the file represents the maximum size of the variable data. @@ -44,3 +44,68 @@ 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, which at + present is only PLPKS on the pseries platform. + +What: /sys/firmware/secvar/config/version +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains the config version as reported by the hypervisor in + ASCII decimal format. + +What: /sys/firmware/secvar/config/max_object_size +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains the maximum allowed size of objects in the keystore + in bytes, represented in ASCII decimal format. + + This is not necessarily the same as the max size that can be + written to an update file as writes can contain more than + object data, you should use the size of the update file for + that purpose. + +What: /sys/firmware/secvar/config/total_size +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains the total size of the PLPKS in bytes, represented in + ASCII decimal format. + +What: /sys/firmware/secvar/config/used_space +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains the current space consumed of the PLPKS in bytes, + represented in ASCII decimal format. + +What: /sys/firmware/secvar/config/supported_policies +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains a bitmask of supported policy flags by the hypervisor, + represented as an 8 byte hexadecimal ASCII string. Consult the + hypervisor documentation for what these flags are. + +What: /sys/firmware/secvar/config/signed_update_algorithms +Date: December 2022 +Contact: Nayna Jain +Description: RO file, only present if the secvar implementation is PLPKS. + + Contains a bitmask of flags indicating which algorithms the + hypervisor supports objects to be signed with when modifying + secvars, represented as a 16 byte hexadecimal ASCII string. + Consult the hypervisor documentation for what these flags mean. 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..8298f039bef4 --- /dev/null +++ b/arch/powerpc/platforms/pseries/plpks-secvar.c @@ -0,0 +1,245 @@ +// 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 sysfs_emit(buf, fmt, func()); \ + } \ + static struct kobj_attribute attr_##name = __ATTR_RO(name) + +PLPKS_CONFIG_ATTR(version, "%u\n", plpks_get_version); +PLPKS_CONFIG_ATTR(max_object_size, "%u\n", plpks_get_maxobjectsize); +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(signed_update_algorithms, "%016llx\n", plpks_get_signedupdatealgorithms); + +static const struct attribute *config_attrs[] = { + &attr_version.attr, + &attr_max_object_size.attr, + &attr_total_size.attr, + &attr_used_space.attr, + &attr_supported_policies.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 sysfs_emit(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 = sysfs_emit(buf, "ibm,plpks-sb-%hhu\n", var.data[0]); + + kfree(var.data); + return ret; +} + +static int plpks_max_size(uint64_t *max_size) +{ + // The max object size reported by the hypervisor is accurate for the + // object itself, but we use the first 8 bytes of data on write as the + // signed update flags, so the max size a user can write is larger. + *max_size = (uint64_t)plpks_get_maxobjectsize() + 8; + + 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);