Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp5526147imm; Tue, 19 Jun 2018 11:50:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIUyT9aYV4OIPJBffzFFJ4ucVrQflLInuR/ICkvwiTcPSXMCzVWTIJQjtdnqyBmKMbyHwcF X-Received: by 2002:a65:644f:: with SMTP id s15-v6mr16023749pgv.228.1529434206331; Tue, 19 Jun 2018 11:50:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529434206; cv=none; d=google.com; s=arc-20160816; b=BPVqwvJDi8tJ2c9Iw8/E59PocXxKNGiAHMGkSrVX6Ua5YGe/znxac5jNrN3edJ2A0p baFSPNAjKt0WZdY0pWYP4yHAV5rdMYDyLTvduPY1mNnoE9uHZtrJUEV7e3ZEbuxSokq3 6GglRn35uRCNwxG13tFhTEWf9c1l2650f+6RSSOE+DDICIaaXlYkYQuJZKrzAGp+S0z/ jApyxRLbs0KHjgxTnULPPGPsqWNi0MK1PiK8kXcR/DsvkIhxKhyDQiqBjeF3XUM5tsR0 F3mPjB3QYZKgxFXcebQ/XWZrI16uKXb6tOT8nXrgqtJBwOekASuyu2vHQaWQ/EQ7SqCd 6KtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=w5uOq7Q2ev5J9TqWh+36eGNTf4Qmp1ReyKNpawu8fXk=; b=IX6Ppk4CkU6zVoy/xeQx4GepDC/Vd59mTDuLLcGa3hhZMTAbGyymurfBp/AGrvTsWU p3L3AgU5CEVslE868MfNDYYcJb7KAux4RUfi1zaQzPCKJ5GQkRXEYP3suqFClXC+2WqR /97nmwvWXFxeabV430+cTUUrFXVEox+I60cJZhnGNupttF9n3bi4ZVLjCD5ZR17w19K5 nnaSei/Qms0b8nQDbPxmvpI9yEmchyT8seAf1bNnepfEilvadbyebRUL8WRWVpry+jKD o1my/mSy8BqVmWtQktufqsdKH4Yrrk2iX6kKZnVUDm2yPlP3EFcnlC2E/BGuH82I6yN8 kZnQ== 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 y16-v6si332667pfl.11.2018.06.19.11.49.52; Tue, 19 Jun 2018 11:50:06 -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 S1030456AbeFSSrx (ORCPT + 99 others); Tue, 19 Jun 2018 14:47:53 -0400 Received: from vps-vb.mhejs.net ([37.28.154.113]:39574 "EHLO vps-vb.mhejs.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030320AbeFSSrv (ORCPT ); Tue, 19 Jun 2018 14:47:51 -0400 Received: by vps-vb.mhejs.net with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fVLfI-0003W1-Rh; Tue, 19 Jun 2018 20:47:40 +0200 From: "Maciej S. Szmigiero" To: Borislav Petkov Cc: Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , x86@kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 5/9] x86/microcode/AMD: Split status from data to skip in verify_and_add_patch() Date: Tue, 19 Jun 2018 20:47:35 +0200 Message-Id: <84b3976f5879d7a58c3774d1f86e493b34c9759c.1529424596.git.mail@maciej.szmigiero.name> X-Mailer: git-send-email 2.17.0 In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org verify_and_add_patch() returned a single "int" value which encoded both this function error status and also a length of microcode container data to skip. Unfortunately, ranges of these two values collide: the length of data to skip can be any value between 1 and UINT_MAX, so, for example, error status of -EINVAL maps to a valid return value of 4294967274 bytes. That's why these two values need to be split. Let's keep the common convention that a function zero return value means success while a negative value means an error while moving the returned length of microcode container data to skip to a separate output parameter. Signed-off-by: Maciej S. Szmigiero --- arch/x86/kernel/cpu/microcode/amd.c | 35 +++++++++++++++-------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/cpu/microcode/amd.c b/arch/x86/kernel/cpu/microcode/amd.c index c05531540b57..9e29374ce4d0 100644 --- a/arch/x86/kernel/cpu/microcode/amd.c +++ b/arch/x86/kernel/cpu/microcode/amd.c @@ -754,45 +754,46 @@ static void cleanup(void) } /* - * We return the current size even if some of the checks failed so that - * we can skip over the next patch. If we return a negative value, we - * signal a grave error like a memory allocation has failed and the - * driver cannot continue functioning normally. In such cases, we tear - * down everything we've used up so far and exit. + * We return zero (success) and the current patch data size in @crnt_size + * even if some of the checks failed so that we can skip over the next patch. + * If we return a negative value, we signal a grave error like a memory + * allocation has failed and the driver cannot continue functioning normally. + * In such cases, we tear down everything we've used up so far and exit. */ -static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) +static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover, + unsigned int *crnt_size) { struct microcode_header_amd *mc_hdr; struct ucode_patch *patch; - unsigned int patch_size, crnt_size; + unsigned int patch_size; u32 proc_fam; u16 proc_id; patch_size = *(u32 *)(fw + 4); - crnt_size = patch_size + SECTION_HDR_SIZE; + *crnt_size = patch_size + SECTION_HDR_SIZE; mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE); proc_id = mc_hdr->processor_rev_id; proc_fam = find_cpu_family_by_equiv_cpu(proc_id); if (!proc_fam) { pr_err("No patch family for equiv ID: 0x%04x\n", proc_id); - return crnt_size; + return 0; } /* check if patch is for the current family */ proc_fam = ((proc_fam >> 8) & 0xf) + ((proc_fam >> 20) & 0xff); if (proc_fam != family) - return crnt_size; + return 0; if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) { pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n", mc_hdr->patch_id); - return crnt_size; + return 0; } - if (!verify_patch(family, fw, leftover, &crnt_size, false)) { + if (!verify_patch(family, fw, leftover, crnt_size, false)) { pr_err("Patch-ID 0x%08x: size mismatch.\n", mc_hdr->patch_id); - return crnt_size; + return 0; } patch = kzalloc(sizeof(*patch), GFP_KERNEL); @@ -818,7 +819,7 @@ static int verify_and_add_patch(u8 family, u8 *fw, unsigned int leftover) /* ... and add to cache. */ update_cache(patch); - return crnt_size; + return 0; } static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, @@ -827,7 +828,6 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, enum ucode_state ret = UCODE_ERROR; unsigned int leftover; u8 *fw = (u8 *)data; - int crnt_size = 0; int offset; offset = install_equiv_cpu_table(data); @@ -845,8 +845,9 @@ static enum ucode_state __load_microcode_amd(u8 family, const u8 *data, } while (leftover) { - crnt_size = verify_and_add_patch(family, fw, leftover); - if (crnt_size < 0) + unsigned int crnt_size; + + if (verify_and_add_patch(family, fw, leftover, &crnt_size) < 0) return ret; fw += crnt_size;