Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2274987ybg; Fri, 5 Jun 2020 09:45:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwfGxDtUe4APvpC5kzx1ZwOsfcjV9qlgJ2XE1Qg9bRJDG2fh2H2sacmvNsXr29X0ybyvRUl X-Received: by 2002:aa7:de08:: with SMTP id h8mr9879187edv.164.1591375508206; Fri, 05 Jun 2020 09:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591375508; cv=none; d=google.com; s=arc-20160816; b=FHD4UUyOHstufKqjSGxMgJSdtR0hOBIQJXnY7lTx7aNvoJkEyB26FziznuQXNI0QY1 p8iIh64M415GTDx3UtyqXd0VBdH/R8kMLOyD0i8NcA4htAh+nlLvukTuzteU5w06rGw6 6aAzCkJ3wTh8/ODsPlxBbMASRBm5KfipxkLJTPiy4RJzQtCxYBmeupMvOUQaQtdmCAkG S9KZH/MMIsV2t1BKo8tQRewpr1SQcYum39AbTxQhm3wyrl1RSym17f/rwGRAo9BRvVRs CJG4V28nhcpJ1R7SOJrQOgmalt8ina1InjKcGcDWltvrRLMJaNNoxJUtCUdB84JuvX8W rJkQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=bdEGpZ06r/Y0nQCCHtiMh+9RZsiujmklfqlTK0kVMWY=; b=ALcWraih6RpJvfw0zzgxMJ5YD6utRaExrHLTrWMQ/n7i0iZDOU/9JXhTWUbKYfRPiu Ecoi80QXeqhrszC1sd5aid/oHkJD6F3AqE8+jKH0u26VRLBnfZkDGDcJAGgflSz/kfKT bT3mMFwNsUWV2gBSRelfwfeCXXHraklzZdNWFldm0ZjOFx808xSfet8WZ7AMuOwJplqD BTs7c+347vwchgW4NU+kskFUTNx+DnaEejIUEhfR8d9S8b7x6ECjOatns+ZhOQ5v5SXN HOvPFev4G8O2w6g2l+MBVtf4TH/FA6/kBNSRjYe+P300MZqDGADYC9CIkLm0Uq3HfZEn r6lQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=C8r73mxW; 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 g10si2722944edr.463.2020.06.05.09.44.45; Fri, 05 Jun 2020 09:45:08 -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=C8r73mxW; 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 S1726090AbgFEQm5 (ORCPT + 99 others); Fri, 5 Jun 2020 12:42:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:50572 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725961AbgFEQm4 (ORCPT ); Fri, 5 Jun 2020 12:42:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591375374; h=from:from: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=bdEGpZ06r/Y0nQCCHtiMh+9RZsiujmklfqlTK0kVMWY=; b=C8r73mxW26ju2I5z6ra4baQ3CTWB+HOr9bT0Tt+En3AIsd9jQMe5enfAEakHI8O91GOWZ9 Yq1ny3QitH7jN+UBGsu9niWDd5cK4MNedqsnXWOaskXhTyO0JkC+m7jdZLYcBHp+ngFgLV lYgmb+sf7MpHFHe+mITc17XYDMnWwsw= 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-212-1-nvlzMDPPOd3JyJIWPl1w-1; Fri, 05 Jun 2020 12:42:50 -0400 X-MC-Unique: 1-nvlzMDPPOd3JyJIWPl1w-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6E36A107ACF5; Fri, 5 Jun 2020 16:42:48 +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 0EF8C19C58; Fri, 5 Jun 2020 16:42:45 +0000 (UTC) Subject: Re: [PATCH] x86/split_lock: Sanitize userspace and guest error output To: Xiaoyao Li , linux-kernel@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , Tony Luck , "Peter Zijlstra (Intel)" , Sean Christopherson , Rahul Tanwar , Ricardo Neri , Dave Hansen References: <20200605114459.22200-1-prarit@redhat.com> <96b5c5fa-6b4e-a5f4-34cc-682477a27370@intel.com> From: Prarit Bhargava Message-ID: <3e1f1fac-fa46-7a2a-1424-d5c931e521d7@redhat.com> Date: Fri, 5 Jun 2020 12:42:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <96b5c5fa-6b4e-a5f4-34cc-682477a27370@intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6/5/20 11:29 AM, Xiaoyao Li wrote: > On 6/5/2020 7:44 PM, Prarit Bhargava wrote: >> 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. >> >> Signed-off-by: Prarit Bhargava >> 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 >> --- >>   arch/x86/kernel/cpu/intel.c | 24 ++++++++++-------------- >>   1 file changed, 10 insertions(+), 14 deletions(-) >> >> diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c >> index 166d7c355896..463022aa9b7a 100644 >> --- a/arch/x86/kernel/cpu/intel.c >> +++ b/arch/x86/kernel/cpu/intel.c >> @@ -1074,10 +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 split_lock_warn(unsigned long ip, int fatal) >>   { >> -    pr_warn_ratelimited("#AC: %s/%d took a split_lock trap at address: 0x%lx\n", >> -                current->comm, current->pid, ip); >> +    pr_warn_ratelimited("#AC: %s/%d %ssplit_lock trap at address: 0x%lx\n", >> +                current->comm, current->pid, >> +                sld_state == sld_fatal ? "fatal " : "", ip); >> + >> +    if (sld_state == sld_fatal || fatal) >> +        return false; >>         /* >>        * Disable the split lock detection for this task so it can make >> @@ -1086,18 +1090,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 (split_lock_warn(ip, 0)) >>           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 +1107,7 @@ 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) >> -        return false; >> -    split_lock_warn(regs->ip); >> -    return true; >> +    return split_lock_warn(regs->ip, regs->flags & X86_EFLAGS_AC); > > It's incorrect. You change the behavior that it will print the split lock > warning even when CPL 3 Alignment Check is turned on. Do you want the message to be displayed in the fatal case of CPL 3 Alignment check? P.