Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5506614imw; Wed, 20 Jul 2022 07:05:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s3NNIgKi+4ujFUIfxJvUqxrp/GrC6I3nlZCRnRefzFVFsgNSBgL5Lpspeny2H5woQCgDt+ X-Received: by 2002:a17:907:75f2:b0:72b:564c:465e with SMTP id jz18-20020a17090775f200b0072b564c465emr34290454ejc.689.1658325944992; Wed, 20 Jul 2022 07:05:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658325944; cv=none; d=google.com; s=arc-20160816; b=bbkuL0Y47V2H/S1F/sFEE+JapDiv39WCm3Jq3/fVBzpdTNIZrXquSfMhEpU1ZBzO0p qoNh1QwUxQlyM9jtUJQc0B76baW+LsuAqhF/8NQ3XiK7xRTzfmB4PdOacXHHXdwqIvvC 7GISz1pt88Dt/mJHOEVHwbReG0LyzEl/+J3giBLRFrtbr4ktdZayDKXvijUcNKuvpz8Z ID2ihYPpRacBuRGNYQHzZ7cJ+4cD9A8nI3PRo4y2Jakot9iHBhVgjrJlFMPgie+Rco+V UGeQp+YazZ2fxhrFL0SB+X7YpQo1Bfn+9nh+SfLHF+9biCkHCADXcKALnmbmin5h52Ek B45A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=l5j/XUYVJV6TzECVxoFZvugNE6eLacXjE6R0TC4Xphc=; b=gtKsUVkunHxyZB4xShA86oRfa6L08XuosPoqaogv8f7X1SXS12phK8b1tJqwAIkliY LKE/uGGjxvaaIzvKhrLhvrm9vPzuKEJbIzINr2qyUax29alR8ICOipv0lOd5VnbgOh0T Q4knQmJG0V9GvHz/UhPoS9K+a7KJxHsbigV/74edFB5zmMA1C5dVZvGp6sbJn+dNf296 3SGVqpAuOManAQFTLLAwNtB79PL/7SwOnePUJx3FUQx458Kp3GAwQjf077Q4m9bjwgXO w7KDicaKHCLwvayMaaJNWevH0GdOrFFpPik5cjOJ/L5l2X/nAzzsH6wE8ntUop1uNlWf FE+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=Y6gFdpVO; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id by17-20020a0564021b1100b0043adbbf1040si2862482edb.167.2022.07.20.07.05.19; Wed, 20 Jul 2022 07:05:44 -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=@infradead.org header.s=desiato.20200630 header.b=Y6gFdpVO; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237872AbiGTNo4 (ORCPT + 99 others); Wed, 20 Jul 2022 09:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229638AbiGTNoy (ORCPT ); Wed, 20 Jul 2022 09:44:54 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E2056B94 for ; Wed, 20 Jul 2022 06:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=l5j/XUYVJV6TzECVxoFZvugNE6eLacXjE6R0TC4Xphc=; b=Y6gFdpVOD4RZ4eeS/V3NhKMoj4 Fj3T1FF8cKMNTykO1VNn0+uXJQiOaRxP6U5w5Tq61kCTbaeaKCsmyen5rQtSDmovtuikALa/OV8zu hFPjgUVJHHlkvAYZhWWqDPYOuUdl7WqxgXE7leesb35cJDzLdwDdU5SEbI1DiW4VXIewGijLB3dUk nV/kggbFgEHJK0/wcQlxIBHL0MsM+I5mgyDxzTg0S+EftlnjWnOGIjukCCZW/vtZ5c5mRmkYeZhTP h7Wg1pUnY9sJhR0+mVpv0Tyew1imcuk2vnVvTsENaQ8RZNCcl0ShrNbJEE7nweGRl8kA5L5SRkv5o s7yQtnQg==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1oEA0K-005Kip-0v; Wed, 20 Jul 2022 13:44:44 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 4911A980BBE; Wed, 20 Jul 2022 15:44:43 +0200 (CEST) Date: Wed, 20 Jul 2022 15:44:43 +0200 From: Peter Zijlstra To: Stephane Eranian Cc: LKML , Eric Dumazet , jpoimboe@redhat.com, Steven Rostedt , tannerlove@google.com, maheshb@google.com Subject: [PATCH] x86/extable: Fix ex_handler_msr() print condition Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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_NONE 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 On Wed, Jul 20, 2022 at 03:48:56PM +0300, Stephane Eranian wrote: > Tested-by: Stephane Eranian Thanks, I'll queue the below. --- Subject: x86/extable: Fix ex_handler_msr() print condition From: Peter Zijlstra Date: Fri, 17 Jun 2022 16:52:06 +0200 On Fri, Jun 17, 2022 at 02:08:52PM +0300, Stephane Eranian wrote: > Some changes to the way invalid MSR accesses are reported by the > kernel is causing some problems with messages printed on the > console. > > We have seen several cases of ex_handler_msr() printing invalid MSR > accesses once but the callstack multiple times causing confusion on > the console. > The problem here is that another earlier commit (5.13): > > a358f40600b3 ("once: implement DO_ONCE_LITE for non-fast-path "do once" functionality") > > Modifies all the pr_*_once() calls to always return true claiming > that no caller is ever checking the return value of the functions. > > This is why we are seeing the callstack printed without the > associated printk() msg. Extract the ONCE_IF(cond) part into __ONCE_LTE_IF() and use that to implement DO_ONCE_LITE_IF() and fix the extable code. Fixes: a358f40600b3 ("once: implement DO_ONCE_LITE for non-fast-path "do once" functionality") Reported-by: Stephane Eranian Signed-off-by: Peter Zijlstra (Intel) Tested-by: Stephane Eranian Link: https://lkml.kernel.org/r/YqyVFsbviKjVGGZ9@worktop.programming.kicks-ass.net --- arch/x86/mm/extable.c | 16 +++++++++------- include/linux/once_lite.h | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 11 deletions(-) --- a/arch/x86/mm/extable.c +++ b/arch/x86/mm/extable.c @@ -94,16 +94,18 @@ static bool ex_handler_copy(const struct static bool ex_handler_msr(const struct exception_table_entry *fixup, struct pt_regs *regs, bool wrmsr, bool safe, int reg) { - if (!safe && wrmsr && - pr_warn_once("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, (unsigned int)regs->dx, - (unsigned int)regs->ax, regs->ip, (void *)regs->ip)) + if (__ONCE_LITE_IF(!safe && wrmsr)) { + pr_warn("unchecked MSR access error: WRMSR to 0x%x (tried to write 0x%08x%08x) at rIP: 0x%lx (%pS)\n", + (unsigned int)regs->cx, (unsigned int)regs->dx, + (unsigned int)regs->ax, regs->ip, (void *)regs->ip); show_stack_regs(regs); + } - if (!safe && !wrmsr && - pr_warn_once("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n", - (unsigned int)regs->cx, regs->ip, (void *)regs->ip)) + if (__ONCE_LITE_IF(!safe && !wrmsr)) { + pr_warn("unchecked MSR access error: RDMSR from 0x%x at rIP: 0x%lx (%pS)\n", + (unsigned int)regs->cx, regs->ip, (void *)regs->ip); show_stack_regs(regs); + } if (!wrmsr) { /* Pretend that the read succeeded and returned 0. */ --- a/include/linux/once_lite.h +++ b/include/linux/once_lite.h @@ -9,15 +9,27 @@ */ #define DO_ONCE_LITE(func, ...) \ DO_ONCE_LITE_IF(true, func, ##__VA_ARGS__) -#define DO_ONCE_LITE_IF(condition, func, ...) \ + +#define __ONCE_LITE_IF(condition) \ ({ \ static bool __section(".data.once") __already_done; \ - bool __ret_do_once = !!(condition); \ + bool __ret_cond = !!(condition); \ + bool __ret_once = false; \ \ - if (unlikely(__ret_do_once && !__already_done)) { \ + if (unlikely(__ret_cond && !__already_done)) { \ __already_done = true; \ - func(__VA_ARGS__); \ + __ret_once = true; \ } \ + unlikely(__ret_once); \ + }) + +#define DO_ONCE_LITE_IF(condition, func, ...) \ + ({ \ + bool __ret_do_once = !!(condition); \ + \ + if (__ONCE_LITE_IF(__ret_do_once)) \ + func(__VA_ARGS__); \ + \ unlikely(__ret_do_once); \ })