From patchwork Thu Jul 27 07:54:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 126778 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a985:0:b0:3e4:2afc:c1 with SMTP id t5csp938151vqo; Thu, 27 Jul 2023 01:15:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlHWckLqcdo/fIgz23s/KKHwHEmTmQTpXaRdnKYINn98d8BWIHDz0zc4AGHPJrRVuIBRdu07 X-Received: by 2002:a17:906:769a:b0:98e:2423:708 with SMTP id o26-20020a170906769a00b0098e24230708mr1495621ejm.62.1690445731827; Thu, 27 Jul 2023 01:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690445731; cv=none; d=google.com; s=arc-20160816; b=UprKNK9zAMBBUIGjYV9OV9YeKO8mJMnkgmvK1ePYurVV9xd2v4bOk823z8B0gHvAjg fXnJj45wKGj6s4d08yUIlQH6yyj4J4ahfk8kGxtaC6XmT793HYZQS1O7x1HvL00mpMiA kd3NW5ZPEyxQPMAUsC9PJIxWueobgQCO2o9xxHVzbVmOoO+M/3y7akYAsHzf5RL2QiEh 6s2ylLipf34demOsDLGVtkVwgtNpQQbvL34J/cXToAbGoaloqEwjoRi7a9zOe6L9BpDJ iU/RrNUQI7iUhmwckhGSZ+y+owLCjjxPSZlTYkaepl94J3PS9g4r25dgRRzZvEIGT1lr GYZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wSxwMI6iTWlc8CQ5+CmIo2ka2i1bO3cYp5kFn1ZMdYI=; fh=v7HrfMc3g4PZ2P+bAx5NqzbPK7NODbCo/bwq2IzTnPw=; b=NgOHTFRnOtp/XOyWHikJ0tXRrIYMAnRgjniQ9T2pGpMczNF+m0jHMRGshYXmulfJwh iPYLeHcFJe7oO4FZdk004LHy82A1yjk+LV7REqk2wzrv5mQvWC9+3F4idnCK6jWicmmK xfpDQ+t5LJt/OGAL+I6fViKL9zTyTAk9N1tDPIedUL5GKJvBgli5lPBOmDaSI2QZ32af 0nKjgMt9GHzqhONVr7EX8wW/hH5L49DprG9/XTtlb/BaI2vHBCD8/G56a2Vnklnkf6VG cvqmjsHjUj2XC7ekfNoXrXTp0GhJKqGo04BQDsMNhxfQ0254MXJl9IhbAM19SD74YxvS uvKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="EfLy4/WA"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u23-20020a1709064ad700b00992ee70a0afsi668037ejt.12.2023.07.27.01.15.07; Thu, 27 Jul 2023 01:15:31 -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=@suse.com header.s=susede1 header.b="EfLy4/WA"; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233622AbjG0H5v (ORCPT + 99 others); Thu, 27 Jul 2023 03:57:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233630AbjG0H5U (ORCPT ); Thu, 27 Jul 2023 03:57:20 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BF1C32685 for ; Thu, 27 Jul 2023 00:54:53 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7E7E521AF8; Thu, 27 Jul 2023 07:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1690444492; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=wSxwMI6iTWlc8CQ5+CmIo2ka2i1bO3cYp5kFn1ZMdYI=; b=EfLy4/WAskIouv5rxvEmdHlFj3FESHYvCBQIeMk066Gamse8nqqzhOc9v7r186DjuVTx0w IxBX3vZGZdKCEe1S9ciYupkB8ZCGLkRERbnkmeupIkZV4h9fgjrevxyZujANz2qoI5eONC n/CqicCMfepooCttUnGlOFr/9/HN8C0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 2A503138E5; Thu, 27 Jul 2023 07:54:52 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id NxPDB8wiwmR4PwAAMHmgww (envelope-from ); Thu, 27 Jul 2023 07:54:52 +0000 From: Nikolay Borisov To: x86@kernel.org Cc: bp@alien8.de, tglx@linutronix.de, linux-kernel@vger.kernel.org, Nikolay Borisov Subject: [PATCH] x86/cpu/amd: Report zenbleed in sysfs Date: Thu, 27 Jul 2023 10:54:46 +0300 Message-Id: <20230727075446.1749969-1-nik.borisov@suse.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 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_PASS, T_SCC_BODY_TEXT_LINE,T_SPF_HELO_TEMPERROR 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772560823621585424 X-GMAIL-MSGID: 1772560823621585424 Initial submission of Zenbleed fix omitted reporting the bug in sysfs. There's no reason why it shouldn't be reported so let's add it among the other vulnerabilities. Signed-off-by: Nikolay Borisov --- .../ABI/testing/sysfs-devices-system-cpu | 1 + arch/x86/kernel/cpu/amd.c | 15 +++++++++++++++ drivers/base/cpu.c | 8 ++++++++ include/linux/cpu.h | 2 ++ 4 files changed, 26 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-devices-system-cpu b/Documentation/ABI/testing/sysfs-devices-system-cpu index ecd585ca2d50..30bb4196e451 100644 --- a/Documentation/ABI/testing/sysfs-devices-system-cpu +++ b/Documentation/ABI/testing/sysfs-devices-system-cpu @@ -524,6 +524,7 @@ What: /sys/devices/system/cpu/vulnerabilities /sys/devices/system/cpu/vulnerabilities/itlb_multihit /sys/devices/system/cpu/vulnerabilities/mmio_stale_data /sys/devices/system/cpu/vulnerabilities/retbleed + /sys/devices/system/cpu/vulnerabilities/zenbleed Date: January 2018 Contact: Linux kernel mailing list Description: Information about CPU vulnerabilities diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 26ad7ca423e7..3ab9745eafc5 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1279,6 +1279,21 @@ u32 amd_get_highest_perf(void) } EXPORT_SYMBOL_GPL(amd_get_highest_perf); +ssize_t cpu_show_zenbleed(struct device *dev, struct device_attribute *attr, char *buf) +{ + + if (!cpu_has_amd_erratum(&boot_cpu_data, amd_zenbleed) || + !boot_cpu_has(X86_FEATURE_AVX) || + boot_cpu_has(X86_FEATURE_HYPERVISOR)) + return sysfs_emit(buf, "Not affected\n"); + + if (!cpu_has_zenbleed_microcode()) { + return sysfs_emit(buf, "Mitigation: Chickenbit\n"); + } else { + return sysfs_emit(buf, "Mitigation: Microcode\n"); + } +} + static void zenbleed_check_cpu(void *unused) { struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); diff --git a/drivers/base/cpu.c b/drivers/base/cpu.c index c1815b9dae68..49c963a0f362 100644 --- a/drivers/base/cpu.c +++ b/drivers/base/cpu.c @@ -577,6 +577,12 @@ ssize_t __weak cpu_show_retbleed(struct device *dev, return sysfs_emit(buf, "Not affected\n"); } +ssize_t __weak cpu_show_zenbleed(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return sysfs_emit(buf, "Not affected\n"); +} + static DEVICE_ATTR(meltdown, 0444, cpu_show_meltdown, NULL); static DEVICE_ATTR(spectre_v1, 0444, cpu_show_spectre_v1, NULL); static DEVICE_ATTR(spectre_v2, 0444, cpu_show_spectre_v2, NULL); @@ -588,6 +594,7 @@ static DEVICE_ATTR(itlb_multihit, 0444, cpu_show_itlb_multihit, NULL); static DEVICE_ATTR(srbds, 0444, cpu_show_srbds, NULL); static DEVICE_ATTR(mmio_stale_data, 0444, cpu_show_mmio_stale_data, NULL); static DEVICE_ATTR(retbleed, 0444, cpu_show_retbleed, NULL); +static DEVICE_ATTR(zenbleed, 0444, cpu_show_zenbleed, NULL); static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_meltdown.attr, @@ -601,6 +608,7 @@ static struct attribute *cpu_root_vulnerabilities_attrs[] = { &dev_attr_srbds.attr, &dev_attr_mmio_stale_data.attr, &dev_attr_retbleed.attr, + &dev_attr_zenbleed.attr, NULL }; diff --git a/include/linux/cpu.h b/include/linux/cpu.h index 6e6e57ec69e8..8ed8fa142067 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h @@ -70,6 +70,8 @@ extern ssize_t cpu_show_mmio_stale_data(struct device *dev, char *buf); extern ssize_t cpu_show_retbleed(struct device *dev, struct device_attribute *attr, char *buf); +extern ssize_t cpu_show_zenbleed(struct device *dev, + struct device_attribute *attr, char *buf); extern __printf(4, 5) struct device *cpu_device_create(struct device *parent, void *drvdata,