Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1040833ima; Sun, 21 Oct 2018 03:25:36 -0700 (PDT) X-Google-Smtp-Source: ACcGV62MuV+QJqGt4gyOUR3bNZNq3MYSRCt0Shifrd2/l3v+dm2o9PTOERLVk34pTOrHEssPMm0a X-Received: by 2002:a62:7107:: with SMTP id m7-v6mr33923919pfc.56.1540117536732; Sun, 21 Oct 2018 03:25:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540117536; cv=none; d=google.com; s=arc-20160816; b=e8ZxIYlcSDOt/FwFR4a42c8ZBdW9KKEueHO9JlcHZ+0yW/1flLk62/kfDT6kJ6aarF 4jZgqTDUi34QNEQlhn+wRn/0Wxlb2sOlYtD/2c8O3YZxmRqS/Za2BAJHU888to6aDBzD 9/wWUMMCb+kKdT+eiWf4Cx4Rjj7MADEhxsfOBAk4i0KgAUbNImQmNOkhoLFVJDpUCkCK RqDLwhe6uoNFWx3/Jgg3/no+ZHAnc9ZxfEuKDe6A+dKsTDo052Qh6ORMn9XvZ1BOMVGv DWkhXnuy8mNa3ONMnjFAl0I7wd9nWngaqY+Btc+p+VZni2WEL8g/cdZU1QVMA1jr0uXZ LxrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=UFAfbi3RkAXSVsoU97LNELw6sKVKwwVJjCpdJlzkZd8=; b=0G4oqZ0cEpCgcnEroYiH3CS2adIIcZ9D94AmlX7nfu+hKnVCJTkHofzMdiKCf6vHx3 XlLESmhrqy5A+TTD60nIZOg/pF5CVL/SuBHV+Y3qNJTSeUirOxbyWejyanzEI2/oNEIr vlvGkKnx4csERU7vTP8g0aqM0UpJMAV4gOVfrJK1JOtVqvAdUnNCZF6cEQV1Xcjh+PQ/ 8Wnw6j0mWiHpRzURbfv4rmL/aozfeMzQk9yqRyiKqlT9chV5zsZ1vdmWn2siY//CPZED nxu57Q3jNW1ttuHxMZ1XVBdd9Iw1uUYtPx6kKoPJ2VR6AyaNcxndmMCc04/mFXlIXxWk liZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8-v6si9883976pgj.283.2018.10.21.03.25.06; Sun, 21 Oct 2018 03:25:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727336AbeJUSfD (ORCPT + 99 others); Sun, 21 Oct 2018 14:35:03 -0400 Received: from Galois.linutronix.de ([146.0.238.70]:41175 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726842AbeJUSfC (ORCPT ); Sun, 21 Oct 2018 14:35:02 -0400 Received: from tmo-101-14.customers.d1-online.com ([80.187.101.14] helo=nanos) by Galois.linutronix.de with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1gEAqn-0003hN-DV; Sun, 21 Oct 2018 12:20:49 +0200 Date: Sun, 21 Oct 2018 12:20:47 +0200 (CEST) From: Thomas Gleixner To: Andi Kleen cc: Andi Kleen , peterz@infradead.org, x86@kernel.org, eranian@google.com, kan.liang@intel.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/2] x86/cpufeature: Add facility to match microcode revisions In-Reply-To: <20181020143857.GC27951@tassilo.jf.intel.com> Message-ID: References: <20181010162608.23899-1-andi@firstfloor.org> <20181019234743.GA27951@tassilo.jf.intel.com> <20181020143857.GC27951@tassilo.jf.intel.com> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andi, On Sat, 20 Oct 2018, Andi Kleen wrote: > On Sat, Oct 20, 2018 at 10:19:37AM +0200, Thomas Gleixner wrote: > > On Fri, 19 Oct 2018, Andi Kleen wrote: > > There is no point to return the pointer because it's not a compound > > structure. If you want to provide the possibility to use the index then > > return the index and an error code if it does not match. > > It will be useful with the driver_data pointer, which you short sightedly > forced me to remove, and likely will need to be readded at some point > anyways if this gets more widely used. It's good and established practice not to add functionality on a 'might be used' basis. If you'd provide at least one or two patches which demonstrate how that is useful then that would be convincing. > At least with the pointer not all callers will need to be changed then. It doesn't need to be changed at all, when done correctly. So lets walk through that again: 1) x86_match_microcode() is a misnomer because it's not as the name suggests a match function. It compares whether the micro code revision is greater or equal the minimal required micro code revision for the current CPU. 2) None of the existing implementations needs a pointer return value, neither does your use case at hand. 3) If this should be extended to a generic cpu id matching facility, then it can be very well designed so. See below. Step 1: struct x86_cpu_check { u8 vendor; u8 family; u8 model; u8 stepping; }; struct x86_cpu_check *x86_match_cpu(struct x86_cpu_check *table) { // Find matching vendor, family, model, stepping entry ... { return entry; } return NULL; } Genuine CPU match function, which can be extended by extending the data structure. Step 2: struct x86_cpu_check { u8 vendor; u8 family; u8 model; u8 stepping; u32 microcode_rev; }; bool x86_cpu_has_min_microcode(struct x86_cpu_check *table) { struct x86_cpu_check *res = x86_match_cpu(table); if (!res) return false; return res->microcode_revision >= boot_cpu_data.microcode; } Step 3: struct x86_cpu_check { u8 vendor; u8 family; u8 model; u8 stepping; union { u32 microcode_rev; void *driver_data; } }; Can be used with x86_match_cpu() for all non microcode based matching. So if you really need something which checks the microcode and provides the pointer, then it's easy enough to do: Step 4: struct x86_cpu_check { u8 vendor; u8 family; u8 model; u8 stepping; u32 microcode_rev; void *driver_data; }; struct x86_cpu_check *x86_check_min_microcode(struct x86_cpu_check *table) { struct x86_cpu_check *res = x86_match_cpu(table); if (!res || res->microcode_rev < boot_cpu_data.microcode) return NULL; return res; } static inline bool x86_cpu_has_min_microcode(struct x86_cpu_check *table) { return !!x86_check_min_microcode(table); } None of these steps requires to change a call site or a table. But probably I'm too short sighted and missing something crucial. Looking forward for enlightment. > Also it's symmetric with how the PCI and USB and the existing x86 match > discovery interfaces work. And the point is? That we need to keep everything as we've done it 20 years ago? > > > > VENDOR_INTEL = 0, so this check is obscure to begin with. Either you chose > > > > a explicit condition to put at the end of the table, e.g. vendor = U8_MAX > > > > or you hand in the array size to the function. > > > > > > That would both be awkward. It's the same as match_cpu, and 0 terminators > > > are standard practice in practical all similar code. I removed > > > the or with the family. > > > > That's debatable because it's more easy to miss the terminator than getting > > the ARRAY_SIZE() argument wrong. But it doesn't matter much. > > Ok then please apply it. Sure, once this argument is settled and all review comments are addressed. Thanks, tglx