Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2224603ybg; Fri, 5 Jun 2020 08:34:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz39Xy7OP8hogaR2h/k7HSZ+EGNKDoYcGvbYJLa+A0gVoOmy95WZw3qYp2CCZRU7GV0Rf+X X-Received: by 2002:a50:ee04:: with SMTP id g4mr9605493eds.119.1591371281231; Fri, 05 Jun 2020 08:34:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591371281; cv=none; d=google.com; s=arc-20160816; b=RWtwYXJNoMGymjLis5JI+iPhrrJvh17F23a2lANfvBYK7OgiodgVJCBuFZOams23oI hUOfYmYynI6FAxr3x7ngNpWRi3y3wQ/j0YR0MqXdL4Jh7YJEKD2seA9LlXKNZlh/vVH1 mDbYZBYkTgYyorvcSSGMTQfSGJlaPmeK3HqvLLdt/mrWB/A4GYhVZWVOYDlICpmr4FPL f9eCAx7AueGOAX6cSE7b926F1h8iWwDwUsCnLpaow+xN5mTB/G4OC8h1hqxKe0JsoynK NtFojNc/qI/hnMdHw+Ud5UIQ01fU81J5+rN/1Eibxo3zn/CCsiJ3W11iUnslxecvqaN3 /RzA== 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:ironport-sdr:ironport-sdr; bh=+WkTlmc94UzLXP2t7ICbzSUUdKHwTfCZsniHd0yhUEQ=; b=Lx2ouwecIMFy57HPSipUBOSzk1sNUIIcsDJjYc2WXy1CUJDSkF61edzuV/vkFwnI+1 UeyMKHETMpWRL0tliXY6XZOe0Ac4WFEljzhltzZOl9bnRQnnldDEEhv9cFbNIn3hvUiV 79ge4WbPnBqXNmTq7UXSf4XL0lxzARDFmM6RRiUYuIfGG542T+SN491cQVXPrVffQqXu NHzBg6eWekB19YUheP5qzTWbLnMU+F8/Ypn1HSYAK8P5mfpgE7GQ7f8E96d+lGlvAFGo YxxU4nP5UJEyZ+VYs8mEzHXwNTHqhL+U8wQe8R0HkPS1QDadpB43Bqe3oQz5aH3M26CA /fSw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si3810756edq.159.2020.06.05.08.34.18; Fri, 05 Jun 2020 08:34:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727956AbgFEPaR (ORCPT + 99 others); Fri, 5 Jun 2020 11:30:17 -0400 Received: from mga11.intel.com ([192.55.52.93]:52444 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726539AbgFEPaQ (ORCPT ); Fri, 5 Jun 2020 11:30:16 -0400 IronPort-SDR: GHqeNTGuqRupKzxlfd6COaa8C2v2xhhi5jEOCQZPljIno5OR+T51FEcnAU9pmIPM9jU/4OlUrd bVQqRM3SaxNQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2020 08:30:16 -0700 IronPort-SDR: N/CzrSbVq69biVlbnwksUoRgWYUck1vHDiIr75PPTtCIcKI4HVQo0wXL6nrSqJGzp9puKWe0ZT 9HwZm79+okfA== X-IronPort-AV: E=Sophos;i="5.73,476,1583222400"; d="scan'208";a="445925518" Received: from xiaoyaol-mobl.ccr.corp.intel.com (HELO [10.249.169.208]) ([10.249.169.208]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2020 08:30:01 -0700 Subject: Re: [PATCH] x86/split_lock: Sanitize userspace and guest error output To: Prarit Bhargava , 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> From: Xiaoyao Li Message-ID: <96b5c5fa-6b4e-a5f4-34cc-682477a27370@intel.com> Date: Fri, 5 Jun 2020 23:29:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 MIME-Version: 1.0 In-Reply-To: <20200605114459.22200-1-prarit@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > } > > /* >