Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2371517ybt; Tue, 16 Jun 2020 04:30:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyk9tRl+hPz0g23hv85Mi2bDEUzd+Z1V4GVNKBRVcxfxUkTizgBwdyhzBEb2E3KZd5dFng9 X-Received: by 2002:a17:906:971a:: with SMTP id k26mr2162947ejx.230.1592306999775; Tue, 16 Jun 2020 04:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592306999; cv=none; d=google.com; s=arc-20160816; b=TIeSlpLavHyGW6IC0GIAHw5wVxUwIkBg5YWddST6+1q56c8zU5XnPrqkzkRtEJrug4 aCw659nRrXMaTwm2+FXKBl2taBvIi5G3Oa/3ACsECWOEqw3yhqPqOBLOfKZhw1idnWLA ++poHDoDXH+HuFnY5jC94fLkD6D2IVcLCa8vYIoT4fSljKa58cV9wPjKF6EFmbIhtZ5p 7GEVb+xEUWeMjET/H6QoQjgvt4333vzuqmsiznYNxOpD5qrHmLEyO74XMLVeGy+iKyEp q3vUoikhdamKTQfhWAHJY5no8xdjbRCUIJa6O/1xEvdHku+wWtsEcwQqR0vP/1nRAU2B Uhwg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=z2I1PH69r1C+t3GnAosZT31X4STu68UH/RqrSdRETA4=; b=zYaFbOk6wMWIV4pXoQp0xxgbgbS+4WGfgl1MxZRj4ApPZR6M9cfNKgr5hrhIwYYnps LRtTa9OaREzwBGUlyyaXyYRL6Txk/s7TK4zt/CSrPMZBoZ8MTg5MgXChD03BO/i0FM58 bQrCQctaa6IWwuJ9EahFpF37RAi6L1yhpByTYxF9Gngrh32vSrcaTRLCDVCbnxSaFust km9gK0ikrNY7SMlHEUGPjSaFRMK2KpkQpFjFTkjsPmkU7Il+Zsp740ybMqKiEN2gn4jv Jzx+ndFjHof58OxwHXinbahaUg5ozjANAx8JogcPLMLH05fxH5w7J1qZd2vkQm/6WD40 mK5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aNl5M/1B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i22si10904646eja.116.2020.06.16.04.29.36; Tue, 16 Jun 2020 04:29:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="aNl5M/1B"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728454AbgFPL1t (ORCPT + 99 others); Tue, 16 Jun 2020 07:27:49 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39895 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725768AbgFPL1s (ORCPT ); Tue, 16 Jun 2020 07:27:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1592306867; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=z2I1PH69r1C+t3GnAosZT31X4STu68UH/RqrSdRETA4=; b=aNl5M/1BU4qGGftvJYbbZh9i33toPiQ0UlvmRxixJE4GAvMKZvRCJoWmyiuhAVc7dLpbg1 /CCVaij3aSmtwQ2ZhoWoewjz4oKiGriHPKHkKOfNI+zdO6lk1Jg4ejZssZ/0euUuafFSgo /nC+0i98epkS9zfTDtldE/dDBv6vM4g= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-215--u0R3Bt6OBiHrcorKewm_Q-1; Tue, 16 Jun 2020 07:27:43 -0400 X-MC-Unique: -u0R3Bt6OBiHrcorKewm_Q-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7AD668DFFE8; Tue, 16 Jun 2020 11:27:07 +0000 (UTC) Received: from prarit.bos.redhat.com (prarit-guest.7a2m.lab.eng.bos.redhat.com [10.16.222.26]) by smtp.corp.redhat.com (Postfix) with ESMTP id 96449619C1; Tue, 16 Jun 2020 11:27:05 +0000 (UTC) From: Prarit Bhargava To: linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Tony Luck , "Peter Zijlstra (Intel)" , Rahul Tanwar , Xiaoyao Li , Ricardo Neri , Dave Hansen Subject: [PATCH v4] x86/split_lock: Sanitize userspace and guest error output Date: Tue, 16 Jun 2020 07:27:02 -0400 Message-Id: <20200616112702.1703-1-prarit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are two problems with kernel messages in fatal mode that were found during testing of guests and userspace programs. The first is that no kernel message is output when the split lock detector is triggered with a userspace program. As a result the userspace process dies from receiving SIGBUS with no indication to the user of what caused the process to die. The second problem is that only the first triggering guest causes a kernel message to be output because the message is output with pr_warn_once(). This also results in a loss of information to the user. While fixing these I noticed that the same message was being output three times so I'm cleaning that up too. Fix fatal mode output, and use consistent messages for fatal and warn modes for both userspace and guests. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: "H. Peter Anvin" Cc: Tony Luck Cc: "Peter Zijlstra (Intel)" Cc: Sean Christopherson Cc: Rahul Tanwar Cc: Xiaoyao Li Cc: Ricardo Neri Cc: Dave Hansen --- v2: Do not output a message if CPL 3 Alignment Check is turned on (xiaoyao.li) v3: refactor code (sean.j.christopherson) v4: Fix Sign off (sean.j.christopherson) arch/x86/kernel/cpu/intel.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c index 63926c94eb5f..3a373f0be674 100644 --- a/arch/x86/kernel/cpu/intel.c +++ b/arch/x86/kernel/cpu/intel.c @@ -1074,11 +1074,14 @@ static void split_lock_init(void) split_lock_verify_msr(sld_state != sld_off); } -static void split_lock_warn(unsigned long ip) +static bool handle_split_lock(unsigned long ip) { - pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", + pr_warn("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", current->comm, current->pid, ip); + if (sld_state != sld_warn) + return false; + /* * Disable the split lock detection for this task so it can make * progress and set TIF_SLD so the detection is re-enabled via @@ -1086,18 +1089,13 @@ static void split_lock_warn(unsigned long ip) */ sld_update_msr(false); set_tsk_thread_flag(current, TIF_SLD); + return true; } bool handle_guest_split_lock(unsigned long ip) { - if (sld_state == sld_warn) { - split_lock_warn(ip); + if (handle_split_lock(ip)) return true; - } - - pr_warn_once("#AC: %s/%d %s split_lock trap at address: 0x%lx\n", - current->comm, current->pid, - sld_state == sld_fatal ? "fatal" : "bogus", ip); current->thread.error_code = 0; current->thread.trap_nr = X86_TRAP_AC; @@ -1108,10 +1106,10 @@ EXPORT_SYMBOL_GPL(handle_guest_split_lock); bool handle_user_split_lock(struct pt_regs *regs, long error_code) { - if ((regs->flags & X86_EFLAGS_AC) || sld_state == sld_fatal) + if (regs->flags & X86_EFLAGS_AC) return false; - split_lock_warn(regs->ip); - return true; + + return handle_split_lock(regs->ip); } /* -- 2.21.3