Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp243872pxw; Fri, 8 Apr 2022 06:35:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzwxHQnfjJteoi/8GwCvCo4KuCSTbRtTy2UoGIcEUB/VnWgCWZsOm6Brl7x9G/FOcY/Hjbr X-Received: by 2002:a17:902:da83:b0:156:aa83:8409 with SMTP id j3-20020a170902da8300b00156aa838409mr19798304plx.22.1649424959651; Fri, 08 Apr 2022 06:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649424959; cv=none; d=google.com; s=arc-20160816; b=QRWTyRiejWcbC4Pi18dgZLQTl3fJI2mBsC/bZ4wop6u+WR5fSh/kXtafJjWW4ehV7f Z2fEslp0FoL2jnFU8mKGQyv6QM9gehms2Ewistqew5iIRJfinTlHpnv34rJt6aroOSfl FVy+ZwlK2k6ltwZwYvN/YNXmR+s9Tuw3chGe+pI9Fo72EFLPVCqZCjR/YDwZXp1PPZrf QCtWBi1Pr/utje9lSUm3eguZrijG0MW4Yiu3/ID3CX4MgrB+Vfq2vVoUHcJNlfJFy/7b Q6UcJltjPl0miDlotrNjMLwHgz0ZiHmG06NVTKGx3WRDDe9kPA4z6GAIMFs+IoemRTo8 JK8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=rZp3DFyUl6wOs7StHaj5old/wdmCSVIRiMeVsd6IyEI=; b=fuKvOrvmqGUutr/9WZ0MjQGmjDQz21wKGM8jGT+8utsNtj/e0GZNX74+Rx0hnBQdyx /3TWytYlSR2ycs+rBM5Uty+tfQ1BQfJ4QAQTKSiYN/aq96ivldMUUTmE8wznjHoKQSU5 +j6iRH1XJrpXjYExso1CVUomVvNSVENRFXu+rFE23eDB3NNPxGoGJHEesHlOxaU25bpo 0OKfa6RXNSFL5V07OH+ZQJCoaUnaLOhGubQy73sPMy8eLFLaSKXfScN1nbj0jMyh+0EQ 90Vmptgqx6koEeYFkQxDfbXyRmrPM+fHcqwTxxiK06Cuu4lWB4gPOYGfl65ogNnXFdzh +o7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y0CL0SNp; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z7-20020aa78887000000b005057337354asi1185586pfe.273.2022.04.08.06.35.41; Fri, 08 Apr 2022 06:35:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Y0CL0SNp; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233441AbiDHJRY (ORCPT + 99 others); Fri, 8 Apr 2022 05:17:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233156AbiDHJMb (ORCPT ); Fri, 8 Apr 2022 05:12:31 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAD3D24BD52; Fri, 8 Apr 2022 02:09:17 -0700 (PDT) Date: Fri, 08 Apr 2022 09:09:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649408956; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZp3DFyUl6wOs7StHaj5old/wdmCSVIRiMeVsd6IyEI=; b=Y0CL0SNp09RHIZLsJql/PjqJOzq1RAtUscHN8XAs2uggOKCSoJ2yjB3UoXWRxgN/kFmFdW 9vD1lAYluUZLe28GPFSxiO7cc/7E3Yty4iE5H20NzcG16e69kBcK1odZdgvT7AuXnQHS0N yA4V0mkDrPVevY5IZmRmnKbtK1l79PwyzEALbpfww8M/CCa16tjqXRdfcHEMkRfDMNabmD 4UEtcx3U1iabOeQu8KAx07SoMbUHe+mqGegD23y8RiGnAnLXvot7SM0I3Ft4llV57vu/m8 cD5T4r51DqW2WmkEkIf747fMcHbGWwSeBQDZCRlvvSHdCIQw/2QRaCU03WbgeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649408956; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rZp3DFyUl6wOs7StHaj5old/wdmCSVIRiMeVsd6IyEI=; b=sojZxL9mGEvMTB4JRkXi4STnQQ4/e+A1zW9Y7lfmNzn9KAJa4kft4lLwm02CXpip05ZziM 3ZDirlyiRyLoGjAQ== From: "tip-bot2 for Michael Roth" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/boot: Introduce helpers for MSR reads/writes Cc: Borislav Petkov , Michael Roth , Borislav Petkov , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220307213356.2797205-6-brijesh.singh@amd.com> References: <20220307213356.2797205-6-brijesh.singh@amd.com> MIME-Version: 1.0 Message-ID: <164940895518.389.9359948563702984420.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following commit has been merged into the x86/sev branch of tip: Commit-ID: 176db622573f028f85221873ea4577e096785315 Gitweb: https://git.kernel.org/tip/176db622573f028f85221873ea4577e096785315 Author: Michael Roth AuthorDate: Wed, 09 Feb 2022 12:09:59 -06:00 Committer: Borislav Petkov CommitterDate: Wed, 06 Apr 2022 12:59:17 +02:00 x86/boot: Introduce helpers for MSR reads/writes The current set of helpers used throughout the run-time kernel have dependencies on code/facilities outside of the boot kernel, so there are a number of call-sites throughout the boot kernel where inline assembly is used instead. More will be added with subsequent patches that add support for SEV-SNP, so take the opportunity to provide a basic set of helpers that can be used by the boot kernel to reduce reliance on inline assembly. Use boot_* prefix so that it's clear these are helpers specific to the boot kernel to avoid any confusion with the various other MSR read/write helpers. [ bp: Disambiguate parameter names and trim comment. ] Suggested-by: Borislav Petkov Signed-off-by: Michael Roth Signed-off-by: Borislav Petkov Link: https://lore.kernel.org/r/20220307213356.2797205-6-brijesh.singh@amd.com --- arch/x86/boot/msr.h | 26 ++++++++++++++++++++++++++ arch/x86/include/asm/msr.h | 11 +---------- arch/x86/include/asm/shared/msr.h | 15 +++++++++++++++ 3 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 arch/x86/boot/msr.h create mode 100644 arch/x86/include/asm/shared/msr.h diff --git a/arch/x86/boot/msr.h b/arch/x86/boot/msr.h new file mode 100644 index 0000000..aed66f7 --- /dev/null +++ b/arch/x86/boot/msr.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Helpers/definitions related to MSR access. + */ + +#ifndef BOOT_MSR_H +#define BOOT_MSR_H + +#include + +/* + * The kernel proper already defines rdmsr()/wrmsr(), but they are not for the + * boot kernel since they rely on tracepoint/exception handling infrastructure + * that's not available here. + */ +static inline void boot_rdmsr(unsigned int reg, struct msr *m) +{ + asm volatile("rdmsr" : "=a" (m->l), "=d" (m->h) : "c" (reg)); +} + +static inline void boot_wrmsr(unsigned int reg, const struct msr *m) +{ + asm volatile("wrmsr" : : "c" (reg), "a"(m->l), "d" (m->h) : "memory"); +} + +#endif /* BOOT_MSR_H */ diff --git a/arch/x86/include/asm/msr.h b/arch/x86/include/asm/msr.h index d42e6c6..65ec196 100644 --- a/arch/x86/include/asm/msr.h +++ b/arch/x86/include/asm/msr.h @@ -10,16 +10,7 @@ #include #include #include - -struct msr { - union { - struct { - u32 l; - u32 h; - }; - u64 q; - }; -}; +#include struct msr_info { u32 msr_no; diff --git a/arch/x86/include/asm/shared/msr.h b/arch/x86/include/asm/shared/msr.h new file mode 100644 index 0000000..1e6ec10 --- /dev/null +++ b/arch/x86/include/asm/shared/msr.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_X86_SHARED_MSR_H +#define _ASM_X86_SHARED_MSR_H + +struct msr { + union { + struct { + u32 l; + u32 h; + }; + u64 q; + }; +}; + +#endif /* _ASM_X86_SHARED_MSR_H */