llvm.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [intel-tdx:guest-tpm 5/6] drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true
@ 2023-11-25 17:34 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2023-11-25 17:34 UTC (permalink / raw)
  To: Kuppuswamy Sathyanarayanan; +Cc: llvm, oe-kbuild-all

tree:   https://github.com/intel/tdx.git guest-tpm
head:   8fc95ae74b62b245179fb0a0a84dc5f5d8ce80aa
commit: db9652ec7a5bff8428a39af5c4aa706f62550ee2 [5/6] tpm: Add vTPM TDX support
config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20231126/202311260013.rBRWcyzN-lkp@intel.com/config)
compiler: clang version 16.0.4 (https://github.com/llvm/llvm-project.git ae42196bc493ffe877a7e3dff8be32035dea4d07)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231126/202311260013.rBRWcyzN-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311260013.rBRWcyzN-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/char/tpm/tpm_tdx.c:26:
   In file included from drivers/char/tpm/tpm.h:28:
   include/linux/tpm_eventlog.h:167:6: warning: variable 'mapping_size' set but not used [-Wunused-but-set-variable]
           int mapping_size;
               ^
>> drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
           if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:716:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   drivers/char/tpm/tpm_tdx.c:685:2: note: remove the 'if' if its condition is always false
           if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
           if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:716:9: note: uninitialized use occurs here
           return ret;
                  ^~~
   drivers/char/tpm/tpm_tdx.c:685:6: note: remove the '||' if its condition is always false
           if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:658:9: note: initialize the variable 'ret' to silence this warning
           int ret;
                  ^
                   = 0
   3 warnings generated.


vim +685 drivers/char/tpm/tpm_tdx.c

   648	
   649	/* Parse TDTK ACPI table and initialize the session object */
   650	static int tdx_tpm_init_session(struct tdx_tpm_dev *tdev)
   651	{
   652		struct tdx_tpm_session *info = &tdev->session;
   653		struct acpi_tdtk_aes_256_gcm *aes_gcm;
   654		struct acpi_tdtk_spdm *spdm;
   655		struct acpi_table_tdtk *tdtk;
   656		void __iomem *addr;
   657		acpi_status status;
   658		int ret;
   659	
   660		status = acpi_get_table(ACPI_SIG_TDTK, 1,
   661					(struct acpi_table_header **)&tdtk);
   662		if (ACPI_FAILURE(status) || tdtk->header.length < sizeof(*tdtk)) {
   663			dev_err(tdev->dev, FW_BUG "Failed to get TDTK ACPI table\n");
   664			return -EINVAL;
   665		}
   666	
   667		if (tdtk->version != TDX_SESS_INFO_VER ||
   668		    tdtk->protocol != TDX_SESS_PROT_SPDM) {
   669			dev_err(tdev->dev, "Unsupported TDTK protocol or version\n");
   670			ret = -EINVAL;
   671			goto put_table;
   672		}
   673	
   674		addr = ioremap(tdtk->info_address, tdtk->info_len);
   675		if (!addr) {
   676			dev_err(tdev->dev, "Failed to remap SPDM table %llx\n",
   677				tdtk->info_address);
   678			ret = -EINVAL;
   679			goto put_table;
   680		}
   681	
   682		spdm = (struct acpi_tdtk_spdm *)addr;
   683		aes_gcm = (struct acpi_tdtk_aes_256_gcm *)(addr + sizeof(*spdm));
   684	
 > 685		if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
   686		    spdm->aead_algo != TDX_AEAD_ALGO_AES_256) {
   687			dev_err(tdev->dev, "Invalid SPDM version or Algo\n");
   688			goto unmap_addr;
   689		}
   690	
   691		info->ver = spdm->trans_ver;
   692		info->algo = spdm->aead_algo;
   693		info->sess_id = spdm->sess_id;
   694	
   695		ret = tdx_aes_256_init(&info->send_crypto, aes_gcm->req_key,
   696				       TDX_AEAD_AES_256_KEY_LEN, aes_gcm->req_iv,
   697				       TDX_AEAD_AES_256_IV_LEN,
   698				       TDX_AEAD_AES_256_ATAG_LEN, aes_gcm->req_seq);
   699		if (ret)
   700			goto unmap_addr;
   701	
   702		ret = tdx_aes_256_init(&info->recv_crypto, aes_gcm->resp_key,
   703				       TDX_AEAD_AES_256_KEY_LEN, aes_gcm->resp_iv,
   704				       TDX_AEAD_AES_256_IV_LEN,
   705				       TDX_AEAD_AES_256_ATAG_LEN, aes_gcm->resp_seq);
   706		if (ret)
   707			goto aes_deinit;
   708	
   709		goto unmap_addr;
   710	aes_deinit:
   711		tdx_aes_256_deinit(&info->send_crypto);
   712	unmap_addr:
   713		iounmap(addr);
   714	put_table:
   715		acpi_put_table((struct acpi_table_header *)tdtk);
   716		return ret;
   717	}
   718	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [intel-tdx:guest-tpm 5/6] drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true
@ 2024-10-05 19:29 kernel test robot
  0 siblings, 0 replies; 2+ messages in thread
From: kernel test robot @ 2024-10-05 19:29 UTC (permalink / raw)
  To: Kuppuswamy Sathyanarayanan; +Cc: llvm, oe-kbuild-all

tree:   https://github.com/intel/tdx.git guest-tpm
head:   2e411a732a435e867d000fe01aa5c1380c9630c8
commit: 6d4ad81993ed6f40f1f82c07cfe9fedf4b4d4722 [5/6] tpm: Add vTPM TDX support
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20241006/202410060310.PMUz8eIJ-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241006/202410060310.PMUz8eIJ-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202410060310.PMUz8eIJ-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/char/tpm/tpm_tdx.c:26:
   In file included from drivers/char/tpm/tpm.h:28:
   include/linux/tpm_eventlog.h:167:6: warning: variable 'mapping_size' set but not used [-Wunused-but-set-variable]
     167 |         int mapping_size;
         |             ^
>> drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
     685 |         if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     686 |             spdm->aead_algo != TDX_AEAD_ALGO_AES_256) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:716:9: note: uninitialized use occurs here
     716 |         return ret;
         |                ^~~
   drivers/char/tpm/tpm_tdx.c:685:2: note: remove the 'if' if its condition is always false
     685 |         if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     686 |             spdm->aead_algo != TDX_AEAD_ALGO_AES_256) {
         |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     687 |                 dev_err(tdev->dev, "Invalid SPDM version or Algo\n");
         |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     688 |                 goto unmap_addr;
         |                 ~~~~~~~~~~~~~~~~
     689 |         }
         |         ~
>> drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever '||' condition is true [-Wsometimes-uninitialized]
     685 |         if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:716:9: note: uninitialized use occurs here
     716 |         return ret;
         |                ^~~
   drivers/char/tpm/tpm_tdx.c:685:6: note: remove the '||' if its condition is always false
     685 |         if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
         |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   drivers/char/tpm/tpm_tdx.c:658:9: note: initialize the variable 'ret' to silence this warning
     658 |         int ret;
         |                ^
         |                 = 0
>> drivers/char/tpm/tpm_tdx.c:884:32: warning: unused variable 'tdx_guest_ids' [-Wunused-const-variable]
     884 | static const struct x86_cpu_id tdx_guest_ids[] = {
         |                                ^~~~~~~~~~~~~
   4 warnings generated.
--
>> drivers/char/tpm/tpm_tdx.c:175: warning: Function parameter or member 'tdvmcall_status' not described in 'tdx_tpm_msg_resp'
>> drivers/char/tpm/tpm_tdx.c:175: warning: Function parameter or member 'service_cmd_status' not described in 'tdx_tpm_msg_resp'
>> drivers/char/tpm/tpm_tdx.c:175: warning: Function parameter or member 'rsvd' not described in 'tdx_tpm_msg_resp'


vim +685 drivers/char/tpm/tpm_tdx.c

   648	
   649	/* Parse TDTK ACPI table and initialize the session object */
   650	static int tdx_tpm_init_session(struct tdx_tpm_dev *tdev)
   651	{
   652		struct tdx_tpm_session *info = &tdev->session;
   653		struct acpi_tdtk_aes_256_gcm *aes_gcm;
   654		struct acpi_tdtk_spdm *spdm;
   655		struct acpi_table_tdtk *tdtk;
   656		void __iomem *addr;
   657		acpi_status status;
   658		int ret;
   659	
   660		status = acpi_get_table(ACPI_SIG_TDTK, 1,
   661					(struct acpi_table_header **)&tdtk);
   662		if (ACPI_FAILURE(status) || tdtk->header.length < sizeof(*tdtk)) {
   663			dev_err(tdev->dev, FW_BUG "Failed to get TDTK ACPI table\n");
   664			return -EINVAL;
   665		}
   666	
   667		if (tdtk->version != TDX_SESS_INFO_VER ||
   668		    tdtk->protocol != TDX_SESS_PROT_SPDM) {
   669			dev_err(tdev->dev, "Unsupported TDTK protocol or version\n");
   670			ret = -EINVAL;
   671			goto put_table;
   672		}
   673	
   674		addr = ioremap(tdtk->info_address, tdtk->info_len);
   675		if (!addr) {
   676			dev_err(tdev->dev, "Failed to remap SPDM table %llx\n",
   677				tdtk->info_address);
   678			ret = -EINVAL;
   679			goto put_table;
   680		}
   681	
   682		spdm = (struct acpi_tdtk_spdm *)addr;
   683		aes_gcm = (struct acpi_tdtk_aes_256_gcm *)(addr + sizeof(*spdm));
   684	
 > 685		if (spdm->trans_ver != TDX_SESS_SPDM_TRANS_VER ||
   686		    spdm->aead_algo != TDX_AEAD_ALGO_AES_256) {
   687			dev_err(tdev->dev, "Invalid SPDM version or Algo\n");
   688			goto unmap_addr;
   689		}
   690	
   691		info->ver = spdm->trans_ver;
   692		info->algo = spdm->aead_algo;
   693		info->sess_id = spdm->sess_id;
   694	
   695		ret = tdx_aes_256_init(&info->send_crypto, aes_gcm->req_key,
   696				       TDX_AEAD_AES_256_KEY_LEN, aes_gcm->req_iv,
   697				       TDX_AEAD_AES_256_IV_LEN,
   698				       TDX_AEAD_AES_256_ATAG_LEN, aes_gcm->req_seq);
   699		if (ret)
   700			goto unmap_addr;
   701	
   702		ret = tdx_aes_256_init(&info->recv_crypto, aes_gcm->resp_key,
   703				       TDX_AEAD_AES_256_KEY_LEN, aes_gcm->resp_iv,
   704				       TDX_AEAD_AES_256_IV_LEN,
   705				       TDX_AEAD_AES_256_ATAG_LEN, aes_gcm->resp_seq);
   706		if (ret)
   707			goto aes_deinit;
   708	
   709		goto unmap_addr;
   710	aes_deinit:
   711		tdx_aes_256_deinit(&info->send_crypto);
   712	unmap_addr:
   713		iounmap(addr);
   714	put_table:
   715		acpi_put_table((struct acpi_table_header *)tdtk);
   716		return ret;
   717	}
   718	
   719	static void free_shared_pages(void *buf, size_t len)
   720	{
   721		unsigned int count = PAGE_ALIGN(len) >> PAGE_SHIFT;
   722	
   723		set_memory_encrypted((unsigned long)buf, count);
   724	
   725		free_pages_exact(buf, PAGE_ALIGN(len));
   726	}
   727	
   728	static void *alloc_shared_pages(size_t len)
   729	{
   730		unsigned int count = PAGE_ALIGN(len) >> PAGE_SHIFT;
   731		void *addr;
   732		int ret;
   733	
   734		addr = alloc_pages_exact(len, GFP_KERNEL);
   735		if (!addr)
   736			return NULL;
   737	
   738		ret = set_memory_decrypted((unsigned long)addr, count);
   739		if (ret) {
   740			free_pages_exact(addr, PAGE_ALIGN(len));
   741			return NULL;
   742		}
   743	
   744		return addr;
   745	}
   746	
   747	static void tdx_tpm_free_buf(struct tdx_tpm_dev *tdev)
   748	{
   749		free_shared_pages((void *)tdev->req, tdev->msg_len);
   750		free_shared_pages((void *)tdev->resp, tdev->msg_len);
   751	}
   752	
   753	static int tdx_tpm_alloc_buf(struct tdx_tpm_dev *tdev)
   754	{
   755		tdev->msg_len = TDX_TPM_MSG_LEN;
   756	
   757		tdev->req = (struct tdx_tpm_msg_req *)alloc_shared_pages(tdev->msg_len);
   758		if (!tdev->req)
   759			goto alloc_failed;
   760	
   761		tdev->resp = (struct tdx_tpm_msg_resp *)alloc_shared_pages(tdev->msg_len);
   762		if (!tdev->resp)
   763			goto alloc_failed;
   764	
   765		return 0;
   766	
   767	alloc_failed:
   768		dev_err(tdev->dev, "Buffer allocation failed\n");
   769		tdx_tpm_free_buf(tdev);
   770		return -ENOMEM;
   771	}
   772	
   773	static int tdx_tpm_alloc_irq(struct tdx_tpm_dev *tdev)
   774	{
   775		int ret, irq;
   776	
   777		/* Allocate an IRQ vector for service callback */
   778		irq = tdx_alloc_event_irq();
   779		if (irq <= 0)
   780			return -EIO;
   781	
   782		/*
   783		 * VMM will use the same CPU that makes the TDX service call for
   784		 * event notification. Set the IRQ with IRQF_NOBALANCING to prevent
   785		 * its affinity from being changed.
   786		 */
   787		ret = request_irq(irq, tdx_service_irq_handler, IRQF_NOBALANCING | IRQF_SHARED,
   788	                          "tdx_service_irq", tdev);
   789	        if (ret) {
   790	                pr_err("Event notification IRQ request failed ret:%d\n", ret);
   791	                return -EIO;
   792	        }
   793	
   794	
   795		tdev->irq = irq;
   796	
   797		return ret;
   798	}
   799	
   800	static void tdx_tpm_free_irq(struct tdx_tpm_dev *tdev)
   801	{
   802		if (tdev->irq <= 0)
   803			return;
   804	
   805		free_irq(tdev->irq, tdev);
   806		tdx_free_event_irq(tdev->irq);
   807	}
   808	
   809	static int tdx_tpm_probe(struct platform_device *pdev)
   810	{
   811		struct tdx_tpm_dev *tdev;
   812		struct tpm_chip *chip;
   813		int err;
   814	
   815		tdev = kzalloc(sizeof(*tdev), GFP_KERNEL);
   816		if (!tdev)
   817			return -ENOMEM;
   818	
   819		tdev->dev = &pdev->dev;
   820		mutex_init(&tdev->tpm_req_lock);
   821	
   822		err = tdx_tpm_alloc_buf(tdev);
   823		if (err)
   824			goto free_tdev;
   825	
   826		err = tdx_tpm_init_session(tdev);
   827		if (err)
   828			goto free_buf;
   829	
   830		init_completion(&tdev->service.compl);
   831	
   832		err = tdx_tpm_alloc_irq(tdev);
   833		if (err)
   834			goto free_session;
   835	
   836		chip = tpmm_chip_alloc(&pdev->dev, &tpm_chip_ops);
   837		if (IS_ERR(chip)) {
   838			err = PTR_ERR(chip);
   839			goto free_cb;
   840		}
   841	
   842		tdev->chip = chip;
   843		dev_set_drvdata(&chip->dev, tdev);
   844	
   845		chip->flags |= TPM_CHIP_FLAG_IRQ;
   846		err = tpm2_probe(chip);
   847		if (err)
   848			goto free_cb;
   849	
   850		err = tpm_chip_register(chip);
   851		if (err)
   852			goto free_cb;
   853	
   854		dev_info(&pdev->dev, "TDX vTPM %s device\n",
   855			 (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2");
   856	
   857		return 0;
   858	
   859	free_cb:
   860		tdx_tpm_free_irq(tdev);
   861	free_session:
   862		tdx_tpm_deinit_session(tdev);
   863	free_buf:
   864		tdx_tpm_free_buf(tdev);
   865	free_tdev:
   866		kfree(tdev);
   867	
   868		return err;
   869	}
   870	
   871	static int tdx_tpm_remove(struct platform_device *pdev)
   872	{
   873		struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
   874		struct tdx_tpm_dev *tdev = dev_get_drvdata(&chip->dev);
   875	
   876		tdx_tpm_free_irq(tdev);
   877		tdx_tpm_deinit_session(tdev);
   878		tdx_tpm_free_buf(tdev);
   879		tpm_chip_unregister(tdev->chip);
   880		kfree(tdev);
   881		return 0;
   882	}
   883	
 > 884	static const struct x86_cpu_id tdx_guest_ids[] = {
   885		X86_MATCH_FEATURE(X86_FEATURE_TDX_GUEST, NULL),
   886		{}
   887	};
   888	MODULE_DEVICE_TABLE(x86cpu, tdx_guest_ids);
   889	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-10-05 19:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-05 19:29 [intel-tdx:guest-tpm 5/6] drivers/char/tpm/tpm_tdx.c:685:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2023-11-25 17:34 kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).