From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 245AD342530 for ; Fri, 10 Apr 2026 09:28:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=192.198.163.8 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775813290; cv=fail; b=MmxzhwS+f9VcDKaOCpkVVa73RRs5eGReOAQLxhDn4IYlAhcQ0e/7CmevMXEG84oQftcuYUyTbzqqjptUAyIPYCsckoEdUC8uEivmKFOt7nmIg2mWi73L+gNzVYzWksLrfoNsKKmZc+mNamDgvmNImbqx6hpi3O9RX7lhkpOltY0= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775813290; c=relaxed/simple; bh=CE2XGkfWKCwmfEgPg6nY2ule82zqIdOFqX/6uzNv+BI=; h=Date:From:To:CC:Subject:Message-ID:References:Content-Type: Content-Disposition:In-Reply-To:MIME-Version; b=HyUY/0+fNHomegk3KDmkalBrdJAwQyD1Y9PCTTTqsIW6UfGpHwMlFXsamC64IbjuZz7Fc/hP9ABIEYiVtqi/8wme48eJ4WHWp8RedGE+sD3OGv/Qir9CsfJf1bBEnRsMgLnh7fHPEJ0ywFhJ9GqL7PNE+RdH5QYhQLVs7jKUvM8= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=g+dRTeg8; arc=fail smtp.client-ip=192.198.163.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="g+dRTeg8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775813289; x=1807349289; h=date:from:to:cc:subject:message-id:reply-to:references: in-reply-to:mime-version; bh=CE2XGkfWKCwmfEgPg6nY2ule82zqIdOFqX/6uzNv+BI=; b=g+dRTeg8cw+VHa9ZUNhXfD/2EpDrgHy6X8u7pmSlJ1aHLck93oUfVu+0 8b2UqP6egsGe88pDBntmBJ+qBeyNBzMaq6REJ8DvMXGkDHwuxgAzo6X/P rfKsjn33sB3XGlwG3sTfSmgocsn/C12uM+j5dvxABVri1kSpVtu6i3nO2 xtw7gYPlkDfFiXOAWRDY4LD7psDZrZeKw3TrRsfjg+6hAIFwVLOI2jx+d VZ2PhVse0ZH+8aZAQbDnkSxnEQg0qa+o8pXyC0I2bZWAwsVPMhWKfWMUP KQAY5fpa5YuTELVLf9m3OpSbu4+HTsDQax7xfpiNnUEb/YQo+vNl7sceO w==; X-CSE-ConnectionGUID: 8f1nomRWQSmKzaZx6ph4VQ== X-CSE-MsgGUID: jrLWHv/VRROc2pzD2Tq8Aw== X-IronPort-AV: E=McAfee;i="6800,10657,11754"; a="94408728" X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="94408728" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 02:28:08 -0700 X-CSE-ConnectionGUID: W9lQHDsNTaeED2UujHgcqw== X-CSE-MsgGUID: /E3eX9G3Qkywmz1J579acA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,171,1770624000"; d="scan'208";a="228037563" Received: from orsmsx901.amr.corp.intel.com ([10.22.229.23]) by orviesa006.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2026 02:28:08 -0700 Received: from ORSMSX901.amr.corp.intel.com (10.22.229.23) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 10 Apr 2026 02:28:07 -0700 Received: from ORSEDG902.ED.cps.intel.com (10.7.248.12) by ORSMSX901.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37 via Frontend Transport; Fri, 10 Apr 2026 02:28:07 -0700 Received: from PH0PR06CU001.outbound.protection.outlook.com (40.107.208.3) by edgegateway.intel.com (134.134.137.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.37; Fri, 10 Apr 2026 02:28:06 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MbMaGqf6ijxw4qokT91qdqvoANgUQapapNlFzDnsHVH6xhVwKpkzeJ90u5oxEXog1I8ctvk8RNq3QSKJWDJhgJAWMtGVqTnk5hfwbryWDaxyTgjI/m7vvAfpXhY2B+K6IxSfCu93mVSR90Jo31gcSckFT0xbMGbBJlBkk9wN3Npio9nqMG97RLMXDJrLaTvhOGbHZWEEylgqeBwGKAFX8vEWEUb3LheM+q4wcaL2+F+B0RRxh63rRBdwtp/8zieBv5XUMuR56LyI08e0Q8P4uuxI/sbtqfuk8rqfQtQQJJteIQd/P2RV4/gGEumr8JqTYis2NYiSaSQioItunc8j8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xybJUg1sxdDSUoiteENjhnMjjKHxijLucHqJD3ODctY=; b=oHbQjK51+bbQ1qubUoLsI6jzp3ClGgLJc7mjQNim/dnYRwcRmwpYAqqzlZFfVwfaSZ7hOlTZyABcteL4KhZnIG3Abt4bV4jkHl33/7kNTm+w63MjRYLWIHhXQAkJ2f+NMITMzb5ZgTIMYGvYXBLaC60Pgf91alIlKWDilWFtUuWMcwxOwxh2pgfAQSnTsVUdzzan5rsdHR3LZQKhZ/DrG7XjteZ+sGDEUbo+lR3G91ZIlZ3bFg2zsBhEXtbMzoMjYQ8SJBXVDFhuZPemWy6Y91EFlVtU/upKYqiWnK0WJ/IgziyuHWIjSP4aogcv5vTEE7G+Bcrhrp+GQC6m7VAKYQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7457.namprd11.prod.outlook.com (2603:10b6:8:140::18) by SJ0PR11MB5213.namprd11.prod.outlook.com (2603:10b6:a03:2da::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9769.19; Fri, 10 Apr 2026 09:28:04 +0000 Received: from DS0PR11MB7457.namprd11.prod.outlook.com ([fe80::4ea:83b3:a90:5436]) by DS0PR11MB7457.namprd11.prod.outlook.com ([fe80::4ea:83b3:a90:5436%3]) with mapi id 15.20.9769.041; Fri, 10 Apr 2026 09:28:04 +0000 Date: Fri, 10 Apr 2026 16:48:25 +0800 From: Yan Zhao To: Sean Christopherson CC: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , , Peter Zijlstra Subject: Re: [PATCH] x86/bug: Add printf() validation to HAVE_ARCH_BUG_FORMAT_ARGS WARNs Message-ID: Reply-To: Yan Zhao References: <20260409182941.1912856-1-seanjc@google.com> Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20260409182941.1912856-1-seanjc@google.com> X-ClientProxiedBy: TP0P295CA0009.TWNP295.PROD.OUTLOOK.COM (2603:1096:910:2::19) To DS0PR11MB7457.namprd11.prod.outlook.com (2603:10b6:8:140::18) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7457:EE_|SJ0PR11MB5213:EE_ X-MS-Office365-Filtering-Correlation-Id: f5c78746-64a8-48da-6e87-08de96e377d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|366016|1800799024|18002099003|22082099003|56012099003; X-Microsoft-Antispam-Message-Info: 0wPOdzks9hw0e0D8XaD3voZ/d2dL/8/V5x3trUih7q1ruPGNp0Q7jTTGElz6POOztDouD0wbIvcbnhIX1Wa5qUXZPpaQxXyTXcLFFsNwDMjCQRrm/fovnTACAtvEsN/QjJje4hxnXF6BVcZcj3XL8c03Prt67o4WuTHSPbPdiK7HkXQneizrji/Zh7v65EP9ctNPU/M42xaTDmYGSUMVIP1+y0DfHJ900hfQGa8k6TWgi7xNI1PtcrDaGoLGSGhlZHQ/5ww/+it66xTgBRPy6bcP0ozEqDJ7yFvatP624aAipjdzHNaQGwHUpCt+F5XU4GgTdb1JyHBHhQZQ2Jc2qiQISxxMqbphttOQbvnZRWkSK6QyhsrKYVLXtQfhOHMJIxJUQ1J2h7HFPHLIFsT2i9kF6cYnbbt4xsUHwKNXNiRlRdvSmkMqswFRji1Y6ubE0C+aVeT7SzlXzC5hQJGTn8FVv4TZX52QC+s28c6934E5mSQVgNS2m6iKOB+UVaBBGk2MmGYPJfryewRgeFwplRpMNQzSUz/xjl3VCKEo+AXMR/+7HhfptJcqMrp2Q8QmwP0Jev/BUZzZd0cpubDAOdUfd/4ZE1EvEQOzN2yJ7na9S1rcLl2F35XCswqkapZWD7xlvdFebdOH5NRg0cOMHFFtddAM+ipswreYMMmY1Qau28Tb+mzGrwO8Sb6O1JQ5 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR11MB7457.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(366016)(1800799024)(18002099003)(22082099003)(56012099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?OW0rjQ7VIZznSOi/X7S3k4V+APIqsXkNY+2bL2VLzDLqjRVJN0beyZbfGtlK?= =?us-ascii?Q?ovU+BTalMjpFe3nvgJLGjtgQMaQLaVWB5s2mfU6Fe43JbL/FtSNdlDKnE0Pm?= =?us-ascii?Q?X3oH3ohP3lQje5ZTWTTI0xfqWGoQu8dCZD9rGpJUM3wZ20iBg1m85NZEN0qh?= =?us-ascii?Q?UrCpkel1b6xoSRhEf6VW4cGHmDm8JnMT9b7fVH4F1IG6l/kWw/GdTEhqNo5b?= =?us-ascii?Q?QkD/tm2XTqhg9vh5Z60qmz1pBNZ00VYe9kZkeIkMgVQNYoeu1sy7YLY4dvq2?= =?us-ascii?Q?RWCFUPdcHxV4qOD9PApezl34PNOCcZcfxy28haejvPb2J6+OK4kPglIm7Cqy?= =?us-ascii?Q?tu5/XZHpGBqtTYHqfjX/3ear3FEK9z/u5dMebMotfRCUKoHZwRxyRcJe1eq4?= =?us-ascii?Q?lcsynNEu9EuEJpwd7NDm5kRuY2juWEKgRuuV7p86NiY+YbryABL0archiNcL?= =?us-ascii?Q?tJ11UWCmi6hIwzM4NDXavw3be/tbl7zX9swBaTj0cD0kMRsx1ALiEHuTSlh1?= =?us-ascii?Q?0MCZgH31T4lHx7TxSRhvyAZsyZqR9GY/sLFTBgHg/2bgo7S+x//IQak/RhlO?= =?us-ascii?Q?ceYbRcbM4I938WF0LaC6ZzWX+tSa92S1P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+4XjybPEp8xMHapaS/pivqfgok+YBY04zfRhp44fttK8dWqvFJ9Q?= =?us-ascii?Q?RTma/zy/EHN+4EPzJ4mb2W0F9424eN+z/wvotdSyn+KoQOr3196ImxC5MnlL?= =?us-ascii?Q?LNwvVhu8JelEa9a1ZIg8N+RLDt9QmSPHTydz7Zo01D2V8Q4S//1lN9w4A4nP?= =?us-ascii?Q?exl27Xsf8ncVsUuXCbEgk0r4MPFWX2n8EcWSYeq4AxW8/CCYhCDh1UHOvWVb?= =?us-ascii?Q?btpcDwpE+w=3D=3D?= X-Exchange-RoutingPolicyChecked: fg+YKEEVrybXLjyMmPzLSiNOQyXT3aKrKDtrlUP7SHQTKjZi649IXQx8wYuusrBVKIsIyDh9OD+/X806HMSQgvXnXLWmT+Y8Wv8bFuJq+YnjQojwBry1AKShMcm2YvhDPorzvWRyr7a4o+Es82wyMmMMZyNodftqmU2cyc7zE1aruawzk/1RdJFsyVsB1PwynCawhaLdi6oCcbbIa7wsYIoc2CN9MjNkqdWfSQCkHQFhBlGTna4W40E8+fJSBQw2IG/Ml8kza5NLfJ+wg9b/gw9zAB4fCnrvEI/VWokStv3QpT2vbzIvcOYDVfpKus93Jn1p/l9rLBw7v+fbfVZSmA== X-MS-Exchange-CrossTenant-Network-Message-Id: f5c78746-64a8-48da-6e87-08de96e377d4 X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7457.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Apr 2026 09:28:04.6271 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DjB5yDXVYk894NtkXvSnUWsyHYYI28aDA2o4R+Z7GaBIdqncEb5VhRvQkRKYr+BSwOOm9rDmeGHeImyUkJ10Qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5213 X-OriginatorOrg: intel.com On Thu, Apr 09, 2026 at 11:29:41AM -0700, Sean Christopherson wrote: > Add explicit printf() validation for x86-64's newfangled WARN > implementation, as most (all?) compilers fail to detect basic formatting > issues without the annotation. Lack of validation is especially > problematic for code that is 64-bit-only, as blatant goofs can easily go > unnoticed. > > Cc: Yan Zhao > Cc: Peter Zijlstra (Intel) > Link: https://lore.kernel.org/all/adc1IrD8uqWdaOKv@yzhao56-desk.sh.intel.com > Fixes: 5b472b6e5bd9 ("x86_64/bug: Implement __WARN_printf()") > Fixes: 11bb4944f014 ("x86/bug: Implement WARN_ONCE()") > Signed-off-by: Sean Christopherson > --- > > This is *very* lightly tested. Yan reported a bug against a commit in the > kvm-x86 tree (see the link) where I botched the formatting of a WARN_ONCE() > argument, but none of my builds (with W=1 and -Werror) detected the issue, > nor did any of the build bots (AFAIK). I'm not entirely sure how Yan managed > to trigger the diagnostic, but it's easy to observe the lack of validation by I triggered it by having CONFIG_BUG=n. See details at https://lore.kernel.org/all/adiq6GTAhbVubEg%2F@yzhao56-desk.sh.intel.com/ With CONFIG_BUG=y, this patch allows detecting the error on my side. > creating a malformed WARN/WARN_ONCE, and then toggling > HAVE_ARCH_BUG_FORMAT_ARGS. > > Thankfully, it looks like my goof is the only one that has snuck in (and I > need to rebase that commit anyways). > > arch/x86/include/asm/bug.h | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/arch/x86/include/asm/bug.h b/arch/x86/include/asm/bug.h > index 80c1696d8d59..29b7dad4d5ef 100644 > --- a/arch/x86/include/asm/bug.h > +++ b/arch/x86/include/asm/bug.h > @@ -153,6 +153,9 @@ struct arch_va_list { > struct sysv_va_list args; > }; > extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs); > +static __always_inline __printf(1, 2) void __WARN_validate_printf(const char *fmt, ...) { } > +#else > +#define __WARN_validate_printf(fmt, ...) Maybe a dumb question, why do we need this define in __ASSEMBLER__ case? Could the macro WARN_ONCE() be included in an assembly file? Should we also include WARN_ONCE() and __WARN_*() in this file under #ifndef __ASSEMBLER__ ? > #endif /* __ASSEMBLER__ */ > > #define __WARN_bug_entry(flags, format) ({ \ > @@ -172,6 +175,7 @@ extern void *__warn_args(struct arch_va_list *args, struct pt_regs *regs); > #define __WARN_print_arg(flags, format, arg...) \ > do { \ > int __flags = (flags) | BUGFLAG_WARNING | BUGFLAG_ARGS ; \ > + __WARN_validate_printf(format, ## arg); \ > static_call_mod(WARN_trap)(__WARN_bug_entry(__flags, format), ## arg); \ > asm (""); /* inhibit tail-call optimization */ \ > } while (0) > > base-commit: c9904c53ca958b5ebf5165dd1705c52f6afc2b2f > -- > 2.53.0.1213.gd9a14994de-goog >