Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2920489rwd; Fri, 16 Jun 2023 09:49:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RO+RA1rh8/7BBbzne97o1XnGuyDErZcvZIuR3HpZDkYFaNmeuXIxYw3tzWl/RfjKagNa0 X-Received: by 2002:a05:6a00:1691:b0:665:c10f:709c with SMTP id k17-20020a056a00169100b00665c10f709cmr3629023pfc.21.1686934144235; Fri, 16 Jun 2023 09:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686934144; cv=none; d=google.com; s=arc-20160816; b=FDvSEPW7edyGBas+hWhRBkEXORAwBaDhohAWuapQcosE0KtU1BBa2YoDWCDxpLcuY+ nfxM2G60DZYNAqvrZFaAz5CtTyIxtsnIkQ7d1CIBqfxkw6fsNXa8jwsJRRB2aox5514E 0R6g7na1JDhaUBd3IdEb/AkD+5XTHZ7M3WkJq6YpolI7JEIqw6fNPh1BpXIjULf3M0Hf KurTis+j4VnducUiSdUjM+8qUHXeqzFXEhSRRtUd54pGlKR53TrUkrCHlNt3ISUuDJVD XMNhWclyycx9AwspUQOYluv1jvswylj9micb1gF1tNl9OcGMfJmhMnR55LdxHm4fQf/7 ujZA== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=f6a4/W3pKSlgo/ri+UOl6JpmW3ssaXyK0cijHBo31ek=; b=JlB9NeQcUm2gb8QQNBY/JNDnd/vgrnQmdcQzZMwkTV8Pwg8mq8PUVpD0hy+BecwNWs ZiKvAXWyyAm/paZfHII7djIa1X8IW/L6w2WTTg9v36spJw+Z3S/VvugYjLWajjEcBcJc Y+TWML4ZE9xHdd36C1APx35WQaMyo7jlWeXHfyzZsIACqPLjUOFc3b839v620kkMexx5 wWbHetSx4JVuStX+PaoacvedYcIMv1+IRc5ljyeUQByAB1GOolHzuvky3CJCczFAhnzb 6bPR5Ag/JLD0B2DEJ808uOvOAjkUMuLLcx4e4iv8wSU8ikCFdzMHZ8kmLRnJhYrE8xbN PIvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V43zJ2tJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c12-20020aa7952c000000b00666982292a2si3748373pfp.166.2023.06.16.09.48.50; Fri, 16 Jun 2023 09:49:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=V43zJ2tJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343895AbjFPQjn (ORCPT + 99 others); Fri, 16 Jun 2023 12:39:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229653AbjFPQjl (ORCPT ); Fri, 16 Jun 2023 12:39:41 -0400 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDE752D48; Fri, 16 Jun 2023 09:39:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686933580; x=1718469580; h=message-id:subject:from:to:cc:date:in-reply-to: references:mime-version:content-transfer-encoding; bh=7ksvNxfLF9nc4Gxz9YoJmx4LwenYmKnMcgqFDHXrwp0=; b=V43zJ2tJoUJ/kYYN1LPzy0JhGMOBUB3YP1vRGqiYSidBDeW7b945xTf5 rNucFYRbOO27MkCpvGKFdVCAiOEQaBx6NxAw0Yti8XRhxKh/s+wMrtmtn 8zY6WEIsTxPUgQvuzDetmBW8UaKzJ/N7LflIO7p3hKow98PW1x4eLZ0O8 83Ds5o1Uww72FxYqH01lV/vB5v2TE7WTN4flp4rUCci985VTKzpn8ST+W tU/6KN/7w7si0HHkCdwacM7cOkV3bfgZ6ncMBfkvIqhadpiEFnTqL+FrJ pHrmRO4UlW2/k6AN28x2rPvv1Yogg/KYlHm5+fsbQcqnp9TRafJrwGt/j A==; X-IronPort-AV: E=McAfee;i="6600,9927,10743"; a="339589389" X-IronPort-AV: E=Sophos;i="6.00,248,1681196400"; d="scan'208";a="339589389" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 09:39:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10743"; a="716083284" X-IronPort-AV: E=Sophos;i="6.00,248,1681196400"; d="scan'208";a="716083284" Received: from jbonds-mobl.amr.corp.intel.com (HELO spandruv-desk1.amr.corp.intel.com) ([10.209.56.162]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 09:39:40 -0700 Message-ID: Subject: Re: [PATCH 1/2] platform/x86/intel/tpmi: Read feature control status From: srinivas pandruvada To: Ilpo =?ISO-8859-1?Q?J=E4rvinen?= Cc: hdegoede@redhat.com, markgross@kernel.org, platform-driver-x86@vger.kernel.org, LKML , Andy Shevchenko Date: Fri, 16 Jun 2023 09:39:39 -0700 In-Reply-To: References: <20230615193302.2507338-1-srinivas.pandruvada@linux.intel.com> <20230615193302.2507338-2-srinivas.pandruvada@linux.intel.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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, 2023-06-16 at 10:13 +0300, Ilpo Järvinen wrote: > On Thu, 15 Jun 2023, Srinivas Pandruvada wrote: > > > [...] > > +       /* set command id to 0x10 for TPMI_GET_STATE */ > > +       data = TPMI_GET_STATE_CMD; > > +       /* 32 bits for DATA offset and +8 for feature_id field */ > > +       data |= ((u64)feature_id << (TPMI_CMD_DATA_OFFSET + > > TPMI_GET_STATE_CMD_DATA_OFFSET)); > > This looks like you should add the GENMASK_ULL() for the fields and > use > FIELD_PREP() instead of adding all those OFFSET defines + custom > shifting. You mean, I should change one shift instruction, to FIELD_PREP() which will use three instructions to shift, sub and AND? ((typeof(_mask))(_val) << __bf_shf(_mask)) & (_mask); > > > + > > +       /* Write at command offset for qword access */ > > +       writeq(data, tpmi_info->tpmi_control_mem + > > TPMI_COMMAND_OFFSET); > > + > > +       ret = tpmi_wait_for_owner(tpmi_info, TPMI_OWNER_IN_BAND); > > +       if (ret) > > +               goto err_unlock; > > + > > +       /* Set Run Busy and packet length of 2 dwords */ > > +       writeq(BIT_ULL(TPMI_CONTROL_RB_BIT) | (TPMI_CMD_PKT_LEN << > > TPMI_CMD_PKT_LEN_OFFSET), > > Define using BIT_ULL(0) instead. Use FIELD_PREP(). This code will run only on X86 64 bit, not a common device driver which will run in any architecture. Please let me know why FIELD_PREP() is better. > > I'd drop _BIT from the define name but I leave it up to you, it just > makes your lines longer w/o much added value. > > > +              tpmi_info->tpmi_control_mem + > > TPMI_CONTROL_STATUS_OFFSET); > > + > > +       ret = read_poll_timeout(readq, control, !(control & > > BIT_ULL(TPMI_CONTROL_RB_BIT)), > > +                               TPMI_RB_TIMEOUT_US, > > TPMI_RB_TIMEOUT_MAX_US, false, > > +                               tpmi_info->tpmi_control_mem + > > TPMI_CONTROL_STATUS_OFFSET); > > +       if (ret) > > +               goto done_proc; > > + > > +       control = FIELD_GET(TPMI_GENMASK_STATUS, control); > > +       if (control != TPMI_CMD_STATUS_SUCCESS) { > > +               ret = -EBUSY; > > +               goto done_proc; > > +       } > > + > > +       data = readq(tpmi_info->tpmi_control_mem + > > TPMI_COMMAND_OFFSET); > > +       data >>= TPMI_CMD_DATA_OFFSET; /* Upper 32 bits are for > > TPMI_DATA */ > > Define the field with GENMASK() and use FIELD_GET(). > Again 3 instructions instead of 1. > > + > > +       *disabled = 0; > > +       *locked = 0; > > + > > +       if (!(data & BIT_ULL(TPMI_GET_STATUS_BIT_ENABLE))) > > Put BIT_ULL() into the define. Good idea. > > Perhaps drop _BIT_ from the name. I can do that. > > > +               *disabled = 1; > > + > > +       if (data & BIT_ULL(TPMI_GET_STATUS_BIT_LOCKED)) > > Ditto. > > > +               *locked = 1; > > + > > +       ret = 0; > > + > > +done_proc: > > +       /* SET CPL "completion"bit */ > > Missing space. > OK > > +       writeq(BIT_ULL(TPMI_CONTROL_CPL_BIT), > > BIT_ULL() to define. > > > +              tpmi_info->tpmi_control_mem + > > TPMI_CONTROL_STATUS_OFFSET); > > + > > +err_unlock: > > +       mutex_unlock(&tpmi_dev_lock); > > + > > +       return ret; > > +} > > + > > +int tpmi_get_feature_status(struct auxiliary_device *auxdev, int > > feature_id, > > +                           int *locked, int *disabled) > > +{ > > +       struct intel_vsec_device *intel_vsec_dev = > > dev_to_ivdev(auxdev->dev.parent); > > +       struct intel_tpmi_info *tpmi_info = > > auxiliary_get_drvdata(&intel_vsec_dev->auxdev); > > + > > +       return tpmi_read_feature_status(tpmi_info, feature_id, > > locked, disabled); > > +} > > +EXPORT_SYMBOL_NS_GPL(tpmi_get_feature_status, INTEL_TPMI); > > + > > +static void tpmi_set_control_base(struct auxiliary_device *auxdev, > > +                                 struct intel_tpmi_info > > *tpmi_info, > > +                                 struct intel_tpmi_pm_feature > > *pfs) > > +{ > > +       void __iomem *mem; > > +       u16 size; > > + > > +       size = pfs->pfs_header.num_entries * pfs- > > >pfs_header.entry_size * 4; > > Can this overflow u16? Where does pfs_header content originate from? We can add a check, but this is coming from a trusted and validated x86 core (Not an add on IP), which not only driver uses but all PM IP in the hardware. Thanks, Srinivas > If > from HW, how is it the input validated? >