Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2259969rwr; Fri, 28 Apr 2023 08:07:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5V6zSbMXFAWG9I8/31r6lcrGV5OUVLg+Xma+BjKiNEkh/GHMXWdwZKAWxqSDWxn3OyfKPw X-Received: by 2002:a25:f44:0:b0:b92:2e21:fbd6 with SMTP id 65-20020a250f44000000b00b922e21fbd6mr4295383ybp.26.1682694470381; Fri, 28 Apr 2023 08:07:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682694470; cv=none; d=google.com; s=arc-20160816; b=OKbDnq/tJQpDCklUrXFJpx2VvhG/FBg2slCDmgjEl0Z2aSxkd85bPbx4FywBcJ62Ui ODsIQRyDis8/Y0ZVrTopZrp0a6OsTzNX20MfMoz+K+IdMPiQ2nuHD4MTLQs9puNjS6Tt 75BdxowctbetgXCdgrklh+r8vNBx54Wz/5V2ObtVFDjctClpvx3xutLuo4t629EFKXXe Nz4ibxDgcpm/rAp/SZ/m3vWaeJ2gRQEmNdYT0Vu8ZDJii1aD3IG0sM2iJdRAv/JKIQH0 jPAVVw8pg29RMqvqL18WfGGSO81dBSFwmZ0Knl27oXIgmxYePJ1qcP5T+UHidG+sxcGm aepw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=JenPzQlIuF7J8p54MWPw88/YQhGaeWH6osoTclpO1zo=; b=B2893L3yZyplmIFOxTVEZngoh0aJTgN9+nPg20+maq3mNqYgpuU4m0l3sKhS0hpboF ju4tIHNxMOhKs7OhHif3I5TdF2s7dALZ5LYZrTYZnyvBszogSfpW2+Q6/7ovHHSriH0n nYu5qLz6TewB9uVwDXv2F2X4Hopccr12VGzvTWvFyWF2wkxAd5Sv8UIOQsKIMECzkfGE ZB8bOvfhY2CJwL0yAR3FVIjUjebDYyFKY1PDuC411r6GTrZGJWfU/om0wX22LfbnYYr7 KeLaSWNzC8hThAfMDYGPX+v/qDV20FqvATKU2RWwteFcZ1TtDwyGnKkxUfJhHCUa7na4 JoMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Crxo6YOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 132-20020a25118a000000b00b9967478781si7970494ybr.366.2023.04.28.08.07.34; Fri, 28 Apr 2023 08:07:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Crxo6YOj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346233AbjD1O6b (ORCPT + 99 others); Fri, 28 Apr 2023 10:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbjD1O6a (ORCPT ); Fri, 28 Apr 2023 10:58:30 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 532492D5B; Fri, 28 Apr 2023 07:58:28 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4efec123b28so8314385e87.1; Fri, 28 Apr 2023 07:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682693906; x=1685285906; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JenPzQlIuF7J8p54MWPw88/YQhGaeWH6osoTclpO1zo=; b=Crxo6YOjva/7wIi4nHL2RFumtUF8Utx6nUgSngUI3Mx5V7WflzyHkR6TDKHqmlifSX l/GyCpYgHsw2LjaUHUL+nhrgL27/tJJqnRVhGg4sPDG4MuwZKoB0jiwaQuvvp1UQC/90 Wm9ioxXDqDIyyQYlZYSaxdLqgjkFI9f0WRcYMtn5p0N2SBEtGDoPfE31JRubDx9hxuWl 0hTlKh3PHIk/NZrZSgSin1JMSgqHyGwzxffhy/aZWiW0opogJcYpOp4AG0FSN8YE3UCr Jh39x2ZFMTkg0Dw1HiQwu/l0HvsgwhJBAaKH4w7TUQgmCGtl0rpEK8dW8d5HKyEmaPhR eSMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682693906; x=1685285906; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JenPzQlIuF7J8p54MWPw88/YQhGaeWH6osoTclpO1zo=; b=KO+BpWzv6va5jap5daoLyguA7odHEGRwpHGwQFfKdERHYnO8HV2tPDk0ixX3wC6P9p qD5+9v0mIdklcMSo73YTSBzmgCI5zDl2FUsSqpd3QNfiNsXyK75b5NiMvQw5PjpTZXDx V2UObT9nPf95eak3bCLQfuu6GFwmFZGSeFPXWJRI5hdyGieG0dkJY4sKcLR5sUM31EmR CS3itO8/OBff0rnNe3mO5u8nHyCJueKN6eHmHc2+3vNcahGQyLcQATNPhs4DXQ3CSmh2 Vbk0yEqAi5VmoOW+OBNnX8vlg8sHBNF1Fhi2s/9l9nKtJJJqmFTu2i65rEOk8w681Sbv KxUA== X-Gm-Message-State: AC+VfDwSRakgqb1YD+kc7HlWshhls2bR39bEwPeS0QIpFdtXNrziXP/z IdPQlpK82oCHV8SaayDM73tCwGueY8SiErOLrLLzaT6TjkA= X-Received: by 2002:ac2:4895:0:b0:4ec:9f24:3e5f with SMTP id x21-20020ac24895000000b004ec9f243e5fmr1659763lfc.0.1682693906297; Fri, 28 Apr 2023 07:58:26 -0700 (PDT) MIME-Version: 1.0 References: <20230420165454.9517-1-jorge.lopez2@hp.com> <20230420165454.9517-13-jorge.lopez2@hp.com> <479b18e3-a35b-45c7-8c8a-cd30af646977@t-8ch.de> In-Reply-To: <479b18e3-a35b-45c7-8c8a-cd30af646977@t-8ch.de> From: Jorge Lopez Date: Fri, 28 Apr 2023 09:58:01 -0500 Message-ID: Subject: Re: [PATCH v11 12/14] HP BIOSCFG driver - surestart-attributes To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= Cc: hdegoede@redhat.com, platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 On Fri, Apr 28, 2023 at 1:03=E2=80=AFAM Thomas Wei=C3=9Fschuh wrote: > > On 2023-04-27 17:17:57-0500, Jorge Lopez wrote: > > On Sun, Apr 23, 2023 at 7:16=E2=80=AFAM Thomas Wei=C3=9Fschuh wrote: > > > > > > On 2023-04-20 11:54:52-0500, Jorge Lopez wrote: > > > > .../x86/hp/hp-bioscfg/surestart-attributes.c | 130 ++++++++++++++= ++++ > > > > 1 file changed, 130 insertions(+) > > > > create mode 100644 drivers/platform/x86/hp/hp-bioscfg/surestart-at= tributes.c > > > > > > > > diff --git a/drivers/platform/x86/hp/hp-bioscfg/surestart-attribute= s.c b/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c > > > > new file mode 100644 > > > > index 000000000000..72952758ffe3 > > > > --- /dev/null > > > > +++ b/drivers/platform/x86/hp/hp-bioscfg/surestart-attributes.c > > > > @@ -0,0 +1,130 @@ > > > > > > > + > > > > +/* > > > > + * audit_log_entries_show() - Return all entries found in log file > > > > + */ > > > > +static ssize_t audit_log_entries_show(struct kobject *kobj, > > > > + struct kobj_attribute *attr, ch= ar *buf) > > > > +{ > > > > + int ret; > > > > + int i; > > > > + u32 count =3D 0; > > > > + > > > > + // Get the number of event logs > > > > + ret =3D hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG_COUNT, > > > > + HPWMI_SURESTART, > > > > + &count, 1, sizeof(count)); > > > > + > > > > + /* > > > > + * The show() api will not work if the audit logs ever go > > > > + * beyond 4KB > > > > + */ > > > > + if (count * LOG_ENTRY_SIZE > PAGE_SIZE) > > > > + return -EFAULT; > > > > > > The error code seems not to match. > > > > > > > Changing error to -EINVAL > > -EIO seems better. Done! > > The problem is not due to some value a user passed but an unhandled from > the hardware. > > > > > > Instead of not returning any data, why not show as many results as > > > possible? > > > > > > > if count * LOG_ENTRY_SIZE > PAGE_SIZE then I prefer to return an error. > > if the count is correct but a failure occurs while reading individual > > audit logs then we will return a partial list of all audit logs > > This changes will be included in Version 12 > > What prevents the firmware from having more log entries? > Wouldn't these audit log entries not accumulate for each logged > operation over the lifetime of the device / boot? > > This would make the interface unusable as soon as there are more > entries. BIOS stores a max number of audit logs appropriate to the current audit log size.The first audit logs are kept in a FIFO queue by BIOS so when the queue is full and a new audit log arrives, then the first audit log will be deleted. > > > > > + > > > > + if (ret < 0) > > > > + return ret; > > And this should first validate ret and then count. Done! > > > > > + > > > > + /* > > > > + * We are guaranteed the buffer is 4KB so today all the event > > > > + * logs will fit > > > > + */ > > > > + > > > > + for (i =3D 0; ((i < count) & (ret >=3D 0)); i++) { > > > > > > && > > > > > > Better yet, pull the condition ret >=3D 0 into the body, as an else-b= ranch > > > for the existing check. > > > > > > > Done! > > > > > > + *buf =3D (i + 1); > > > > > > Isn't this directly overwritten by the query below? > > > > buf input value indicates the audit log to be read hence the reason > > why it is overwritten. > > This is an expected behavior. > > So this is read by the HPWMI_SURESTART_GET_LOG method in the firmware? > > Make sense but need a comment. Done! > > > > > > > > + ret =3D hp_wmi_perform_query(HPWMI_SURESTART_GET_LOG, > > > > + HPWMI_SURESTART, > > > > + buf, 1, 128); > > > > + if (ret >=3D 0) > > > > + buf +=3D LOG_ENTRY_SIZE; > > > > > > So 128 bytes are read but only the first 16 bytes are preserved? > > > > > > The documentation says that each entry has 128 bytes in the file. > > > And that they are separated by ";", which is not implemented. > > > > The statement will be removed from documentation (separated by ";") > > audit log size is 16 bytes. > > > > > > Can the audit-log not contain all-zero bytes? > > > If it does this would need to be a bin_attribute. > > > > Bytes 16-127 are ignored and not used at this time. If the audit log > > changes, then the driver will need to change to accommodate the new > > audit log size. > > buf is not guaranteed to have 128 bytes left for this data. > > For example if this is entry number 253 we are at offset 253 * 16 =3D 404= 8 > in the sysfs buffer. Now hw_wmi_perform_query may try to write to 4048 + > 127 =3D 4175 which is out of bounds for the buf of size 4096. > > Writing first to a stack buffer would be better, > or pass outsize =3D LOG_ENTRY_SIZE. > BIOS currently stores 16 bytes for each audit log although the WMI query reads 128 bytes. The 128 bytes size is set to provide support in future BIOS for audit log sizes >=3D 16 and < 128 bytes. > > The audit log file cannot contain all zero bytes. > > I doublechecked this and zero bytes seem to also be fine in normal text > attributes. > > > > > + return (count * LOG_ENTRY_SIZE); > > If one of the calls to hp_wmi_perform_query() fails this return value is = wrong, > it does not reflect the amount of actually written data. Version 12 of the code takes such a condition in consideration and recalculates the value of 'count' to match the one number of valid audit logs read.