On Thu, Apr 04, 2024 at 11:13:49AM +1300, Huang, Kai wrote: > > >On 22/03/2024 3:17 am, Yamahata, Isaku wrote: >> > > + >> > > + for_each_online_cpu(i) { >> > > + int pkg = topology_physical_package_id(i); >> > > + >> > > + if (cpumask_test_and_set_cpu(pkg, packages)) >> > > + continue; >> > > + >> > > + /* >> > > + * Program the memory controller in the package with an >> > > + * encryption key associated to a TDX private host key id >> > > + * assigned to this TDR. Concurrent operations on same memory >> > > + * controller results in TDX_OPERAND_BUSY. Avoid this race by >> > > + * mutex. >> > > + */ >> > > + mutex_lock(&tdx_mng_key_config_lock[pkg]); >> > the lock is superfluous to me. with cpu lock held, even if multiple CPUs try to >> > create TDs, the same set of CPUs (the first online CPU of each package) will be >> > selected to configure the key because of the cpumask_test_and_set_cpu() above. >> > it means, we never have two CPUs in the same socket trying to program the key, >> > i.e., no concurrent calls. >> Makes sense. Will drop the lock. > >Hmm.. Skipping in cpumask_test_and_set_cpu() would result in the second >TDH.MNG.KEY.CONFIG not being done for the second VM. No? No. Because @packages isn't shared between VMs.