From patchwork Fri Feb 17 15:59:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 58672 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp966557wrn; Fri, 17 Feb 2023 08:04:26 -0800 (PST) X-Google-Smtp-Source: AK7set+xMQ0IxjNGgmX/ELl0HGDscs/cTo82VSjKF9IMomKy1la/mNQDrzCd0DPl7IPFBMd9K8At X-Received: by 2002:a17:906:856:b0:8b1:78bc:7508 with SMTP id f22-20020a170906085600b008b178bc7508mr3912089ejd.20.1676649866626; Fri, 17 Feb 2023 08:04:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676649866; cv=none; d=google.com; s=arc-20160816; b=BpxAYsgH0I4eSjefJYT1XFy8iUhar687KC06bVe+Lo3T0hL2/ALMBVrtDg3iePaR+W HO1jILYx5olxsC/xpY0D/nSt/WHdhN1p4uIqgj77UL1GQMCKkbd1XemVTHzgqqxae/XX Mc60tozCGeIQMpD9b++rWU8Q4jx016qHeAPQOATFHqeDUgn0BDHDnMc54FBLwAJbN6G5 44BQSO4OQKPsniMu6wFGB8knt1Flf2TwHE9m+uirqhIrJRUOjLmSYYSthoRVN1zFZ1vz HRV4Np5HSUUUphsK6nVRtBXVznGIAAvndlZViLP/PZrtj3nyFtYiEdWhy+CqJwFZvu4i NIBw== 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=k7MziM86Jp36VM4jxhVJ2bX7itnWn8ka4z/tx3RV0Gg=; b=VeIkAtPWYlLk2UoFePBYuhCGgJPOBn3lEp+h1rGoG/533N4xpwVvCDYl64k9x+CPKQ 8m0yCc4+hD/QYrl649yYQcPRQBlXZ6lF9h9VO01TEZsmf3/LZ/XcSMpduJbMqYhOPZH2 eQeisBgtvb0GTCGuW6xS7Zq2BFosWhyOQhHhd9bhQyTmG3galERWe/6UKsQmWEb/eWAK fsthsGwUEZ7IAkX41cfPNQZ5gbS8ek8UL4+OIEj7z1tIMbd93SZwFkR1tlPaTeSPNVEB AJ1oPLV9ZKQqhroB6TRVjNbxWd/Kc4rrSeTbDk2Du4dktE2k8XEiq/y5UrjpvGBF9jFo /2aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b=jUmghVuP; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fv30-20020a170907509e00b008af39315aeesi5251180ejc.72.2023.02.17.08.04.04; Fri, 17 Feb 2023 08:04:26 -0800 (PST) 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=fail header.i=@mailo.com header.s=mailo header.b=jUmghVuP; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229991AbjBQQAB (ORCPT + 99 others); Fri, 17 Feb 2023 11:00:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229582AbjBQQAA (ORCPT ); Fri, 17 Feb 2023 11:00:00 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8870CC15; Fri, 17 Feb 2023 07:59:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676649552; bh=YsoKXCZB4yem8v+/jW+r+OuwCoAnnlpeCH9iiRWsCrk=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=jUmghVuPh9BLCOM7a8uHH977hTqe/EDP1DOykQD75vO5bI/moXXGulslxdMZfyxxU msJ1X2bSza05NaDchlEo9NP5t7Il9M9gcKFr3aMMJe7/MGnxQo0U951IXhmC9EgIiN B5PImmQAE64mqrgGf19+4CgEDj42NfjurAmxqdAw= Received: by b-2.in.mailobj.net [192.168.90.12] with ESMTP via ip-206.mailobj.net [213.182.55.206] Fri, 17 Feb 2023 16:59:12 +0100 (CET) X-EA-Auth: CbPnAWdQkC53lyFOtoipqkXCf5CkMDnnPU83CE2BgCWjTYLvVlHwaBnCsrI9WOoVp0HjBONIwasmbRx5xO3k10OS3G1xNPK1 Date: Fri, 17 Feb 2023 21:29:07 +0530 From: Deepak R Varma To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH 2/3] perf/x86/intel/pt: Use sysfs_emit() in show() callback function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758094810292081291?= X-GMAIL-MSGID: =?utf-8?q?1758094810292081291?= Using sprintf/snprintf functions are error prone and suggested to be replaced by scnprintf/vscnrptintf as outlined in this [1] LWN article. A more recent recommendation is to use sysfs_emit() or sysfs_emit_at() as per Documentation/filesystems/sysfs.rst in show() callback function when formatting values to be returned to user-space. These helper functions are PAGE_SIZE aware and wrap a safer call to vscnprintf(). [1] https://lwn.net/Articles/69419/ Issue identified using the coccinelle device_attr_show.cocci script. Signed-off-by: Deepak R Varma --- arch/x86/events/intel/pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c index 42a55794004a..d9e6d771b458 100644 --- a/arch/x86/events/intel/pt.c +++ b/arch/x86/events/intel/pt.c @@ -96,7 +96,7 @@ static ssize_t pt_cap_show(struct device *cdev, container_of(attr, struct dev_ext_attribute, attr); enum pt_capabilities cap = (long)ea->var; - return snprintf(buf, PAGE_SIZE, "%x\n", intel_pt_validate_hw_cap(cap)); + return sysfs_emit(buf, "%x\n", intel_pt_validate_hw_cap(cap)); } static struct attribute_group pt_cap_group __ro_after_init = { From patchwork Fri Feb 17 16:00:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak R Varma X-Patchwork-Id: 58675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp968166wrn; Fri, 17 Feb 2023 08:06:46 -0800 (PST) X-Google-Smtp-Source: AK7set+RLS9GSrguOwhwGGHlejuX74wy8+urngFfNN/kGdUA6PtUWYb8XLthEfJdTwTHgPOnXI4E X-Received: by 2002:a17:906:f8c6:b0:7c0:efb9:bc0e with SMTP id lh6-20020a170906f8c600b007c0efb9bc0emr1203393ejb.62.1676650006561; Fri, 17 Feb 2023 08:06:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676650006; cv=none; d=google.com; s=arc-20160816; b=RBEg/9I9/geNC65v+vn1/BSVe9/q8W4nphhwEXQK5KZ5ksV66y8+dFeMR49hdrcWEi hQJyNvrLWMicuDYRMKi6I2BHGWHyB/as02ogKRTLp9oqOwduleCPMO8fpA/Qegsze+h8 Gc5Jxr4qWYYRAFJHqumQP/QHdKnlWttm43+HaSyJohCcfr14mSyGQZBkOq/Uk6Cvk4+y HQTQWgTPeJIaC8r3eit2mQl62pAv6koszeuKdAzZ2LD7NpdqMK2iyzowpXorx0R14GGP kecFTAAlGf6UpqlVTDtk67aGkl12hRKco7nI92SwpTf0rOmNvWwYeg6/A1FTCI8jUYaP nQpg== 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=qgEOQqdbFztN2JT2YnLEwbs6aO5TsSPecyU7uj8s098=; b=NbMvG089ngAnEwN+nLGj7ttjba94Jbw5fy+R9G2ri/dtnxtpc8PsDqcQiZC2956y9/ rbxO98kW8AXAYjxhg/AhbD+xQg7F/ZRYTAdOtoDIKrH/PriNSnsCNwf5yHOAXMu68knA aRctZisIqgazwgHOMs2n8cQX5k6PA9rJZxWe8zSv2WaxcgTH9xiNsqEc387JOGreqXkd 1/n4NahD8rgXkudhUSly1sdv8u/Jp51fpYtHorPaqgKVHNoDmUd73+1BWxW1EH9D45vv 55HTeyCNVmKNqitSmGDUImDDBM7VSVcoCMP9iQKgyfxWxJgh7iAklMZ2ELuk5wO4tHIG HKng== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@mailo.com header.s=mailo header.b="ojRUod/H"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gg21-20020a170906899500b008b138144755si5085391ejc.138.2023.02.17.08.06.00; Fri, 17 Feb 2023 08:06:46 -0800 (PST) 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=fail header.i=@mailo.com header.s=mailo header.b="ojRUod/H"; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229766AbjBQQBA (ORCPT + 99 others); Fri, 17 Feb 2023 11:01:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230110AbjBQQA7 (ORCPT ); Fri, 17 Feb 2023 11:00:59 -0500 Received: from msg-2.mailo.com (msg-2.mailo.com [213.182.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBC1D6FF0A; Fri, 17 Feb 2023 08:00:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1676649618; bh=wB3ZPtCGa5PrJ93JY1yIkav8LyCt0ajpRd6tRiIfc/I=; h=X-EA-Auth:Date:From:To:Cc:Subject:Message-ID:References: MIME-Version:Content-Type:In-Reply-To; b=ojRUod/HyzYRmrh4lI3SyTbTiA8YiLEmum4FtWfI5VAcmQit7cVOsEd7MhK+IPXoE WXpbIHv3ifGjhPRV596qQGAkT/D+3fphZHhrGDvRtDtFzG01ZxMXf04ej7fhHsWq6v zpcL5rR3Xydsnn7WzPmUeFuYH7cG5ih/VsTX1Hlw= Received: by b-5.in.mailobj.net [192.168.90.15] with ESMTP via ip-206.mailobj.net [213.182.55.206] Fri, 17 Feb 2023 17:00:18 +0100 (CET) X-EA-Auth: BdYOlj2NrjJjrAs+Rzq1GDtXgCk6fB/Aq7d7XEgknADjOjaT57Ntx1JGFn/P1Tn43rCp7Jx3MNK6FXoZrJtpVp9h/TAYq2QS Date: Fri, 17 Feb 2023 21:30:08 +0530 From: Deepak R Varma To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Saurabh Singh Sengar , Praveen Kumar , Deepak R Varma Subject: [PATCH 3/3] perf/x86/intel: Use sysfs_emit() in show() callback function Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758094957622862803?= X-GMAIL-MSGID: =?utf-8?q?1758094957622862803?= Using sprintf/snprintf functions are error prone and suggested to be replaced by scnprintf/vscnrptintf as outlined in this [1] LWN article. A more recent recommendation is to use sysfs_emit() or sysfs_emit_at() as per Documentation/filesystems/sysfs.rst in show() callback function when formatting values to be returned to user-space. These helper functions are PAGE_SIZE aware and wrap a safer call to vscnprintf(). [1] https://lwn.net/Articles/69419/ Issue identified using the coccinelle device_attr_show.cocci script. Signed-off-by: Deepak R Varma --- arch/x86/events/intel/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c index bafdc2be479a..8fb1225123ef 100644 --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -5273,7 +5273,7 @@ static ssize_t show_sysctl_tfa(struct device *cdev, struct device_attribute *attr, char *buf) { - return snprintf(buf, 40, "%d\n", allow_tsx_force_abort); + return sysfs_emit(buf, "%d\n", allow_tsx_force_abort); } static ssize_t set_sysctl_tfa(struct device *cdev, @@ -5307,7 +5307,7 @@ static ssize_t branches_show(struct device *cdev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", x86_pmu.lbr_nr); + return sysfs_emit(buf, "%d\n", x86_pmu.lbr_nr); } static DEVICE_ATTR_RO(branches); @@ -5323,7 +5323,7 @@ static ssize_t pmu_name_show(struct device *cdev, struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%s\n", pmu_name_str); + return sysfs_emit(buf, "%s\n", pmu_name_str); } static DEVICE_ATTR_RO(pmu_name);