lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <871pznq229.ffs@tglx>
Date: Thu, 07 Nov 2024 02:12:46 +0100
From: Thomas Gleixner <tglx@...utronix.de>
To: "Chang S. Bae" <chang.seok.bae@...el.com>, Borislav Petkov <bp@...en8.de>
Cc: linux-kernel@...r.kernel.org, x86@...nel.org, mingo@...hat.com,
 dave.hansen@...ux.intel.com
Subject: Re: [PATCH RFC 4/7] x86/microcode/intel: Prepare for microcode staging

On Wed, Nov 06 2024 at 10:28, Chang S. Bae wrote:
> On 11/4/2024 3:16 AM, Borislav Petkov wrote:
>> On Tue, Oct 01, 2024 at 09:10:39AM -0700, Chang S. Bae wrote:
>>> +
>>> +static bool need_staging(u64 *mmio_addrs, u64 pa)
>>> +{
>>> +	unsigned int i;
>>> +
>>> +	for (i = 0; mmio_addrs[i] != 0; i++) {
>>> +		if (mmio_addrs[i] == pa)
>>> +			return false;
>>> +	}
>>> +	mmio_addrs[i] = pa;
>> 
>> This is a weird function - its name is supposed to mean it queries something
>> but then it has side effects too.
>
> I think I've carved out a bit more out of the loop and convoluted them
> into a single function.
>
> Instead, let the helper simply find the position in the array,
>
>          static unsigned int find_pos(u64 *mmio_addrs, u64 mmio_pa)
>          {
>                  unsigned int i;
>
>                  for (i = 0; mmio_addrs[i] != 0; i++) {
>                          if (mmio_addrs[i] == mmio_pa)
>                                  break;
>                  }
>                  return i;
>          }
>
> and update the array from there:
>
>          static void stage_microcode(void)
>          {
>                  unsigned int pos;
>                  ...
>                  for_each_cpu(cpu, cpu_online_mask) {
>                          /* set 'mmio_pa' from RDMSR */
>
>                          pos = find_pos(mmio_addrs, mmio_pa);
>                          if (mmio_addrs[pos] == mmio_pa)
>                                  continue;
>
>                          /* do staging */
>
>                          mmio_addrs[pos] = mmio_pa;
>                  }
>                  ...
>          }
>
> Or, even the loop code can include it:
>
>          for_each_cpu(...) {
>                  /* set 'mmio_pa' from RDMSR */
>
>                  /* Find either the last position or a match */
>                  for (i = 0; mmio_addrs[i] != 0 && mmio_addrs[i] != 
> mmio_pa; i++);
>
>                  if (mmio_addrs[i] == mmio_pa)
>                          continue;
>
>                  /* do staging */
>
>                  mmio_addrs[i] = mmio_pa;
>          }

This looks all overly complicated. The documentation says:

  "There is one set of mailbox registers and internal staging buffers per
   physical processor package. Therefore, the IA32_MCU_STAGING_MBOX_ADDR
   MSR is package-scoped and will provide a different physical address on
   each physical package."

So why going through loops and hoops?

   pkg_id = UINT_MAX;

   for_each_online_cpu(cpu) {
   	if (topology_logical_package_id(cpu) == pkg_id)
              continue;
        pkg_id = topology_logical_package_id(cpu);

        rdmsrl_on_cpu(cpu, MSR_IA32_MCU_STAGING_MBOX_ADDR, &pa);
        staging_work(pa, ucode_patch_late, totalsize);
   }

Something like that should just work, no?

Thanks,

        tglx




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ