Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1444186pxj; Sat, 15 May 2021 15:19:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1F9cN8XbGAo0mFeQh3ZyZtf9qr3g7pYe9pRn7CQQyEXyr5zVdmBbuw7GD36tFKdQq0uNO X-Received: by 2002:a05:6402:487:: with SMTP id k7mr32416881edv.315.1621117183311; Sat, 15 May 2021 15:19:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621117183; cv=none; d=google.com; s=arc-20160816; b=GoBNDAKlQ+7/NHxmz9ecaHeZc6+WrbTz7pjCHYg9hHS0j6UdHBvOhQdq7gUgTw606w kH2DBmpAAQ9WVo0VyxpfVkCJH7lYM6P2dpSUx1JwxnO7BBUnRN046wD0mPbnZCEJqJ0u kB15xiMcoLKQ3604/yjkQOrmh1Oowyjwn576cyglStS5v9hacnPQHW8zJ8BbpK4lbCwi kklLEZKOFAZky+VLuoRH7DPMB3yRlpRqbb52JUqauDZBTll/9/RaeHlsH9WA9b+ESUVU daKLmv33ogGjtUWu6UrGfrPN65xWqD1RIsTlI51o06P0IiVzIbaoLoph3ymK4ZPxjIPz SWaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TY2A/7GXlI7hn1JRkuvl1QVRaeatJaTaxqvW5yt1zhg=; b=Qo0H9hRrUDT4aOTQe1eH637RzpFOt8NFPioF2pPyFgCaOhynx5lZkLWTdN4dgTjQes ed8wiUAYATRipWi/tKuDMxjSgHAD+N2xYeMvSck+PH7TitwEzM3crAdkZw9M0ODp1q6X fp/cR23dsJgIvHrdaZDnd54KoH0C7f318qWbG+1QyNLMr0Yd+ifMStRFp3h0HavWN6t+ ypCJkW0qs83dRtVrlCUOTOnYhbpBUmUd0TML16c34cnzTozWHMahG7oLyq8kBh8T0ZwI 1O2QUN5f6fpCqsTGl2GXDbrRO4KTqfJnXPS0oqHs7vXlWoAJqXnKaFfS4p4s++JipmcV Pgeg== 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=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id do11si9166090ejc.354.2021.05.15.15.19.19; Sat, 15 May 2021 15:19:43 -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=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231421AbhEOOA3 (ORCPT + 99 others); Sat, 15 May 2021 10:00:29 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:3699 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229571AbhEOOA0 (ORCPT ); Sat, 15 May 2021 10:00:26 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4Fj6Pm4KhNz16PjK; Sat, 15 May 2021 21:56:28 +0800 (CST) Received: from code-website.localdomain (10.175.127.227) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.498.0; Sat, 15 May 2021 21:59:01 +0800 From: Zheng Yejian To: CC: , , , , Subject: [PATCH 1/2] acct: Fix accuracy loss for input value of encode_comp_t() Date: Sat, 15 May 2021 22:06:30 +0800 Message-ID: <20210515140631.369106-2-zhengyejian1@huawei.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20210515140631.369106-1-zhengyejian1@huawei.com> References: <20210515140631.369106-1-zhengyejian1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org See calculation of ac_{u,s}time in fill_ac(): > ac->ac_utime = encode_comp_t(nsec_to_AHZ(pacct->ac_utime)); > ac->ac_stime = encode_comp_t(nsec_to_AHZ(pacct->ac_stime)); Return value of nsec_to_AHZ() is always type of 'u64', but it is handled as type of 'unsigned long' in encode_comp_t, and accuracy loss would happen on 32-bit platform when 'unsigned long' value is 32-bit-width. So 'u64' value of encode_comp_t() may look better. Signed-off-by: Zheng Yejian --- kernel/acct.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/acct.c b/kernel/acct.c index a64102be2bb0..9e143ed5b5d0 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -301,7 +301,7 @@ void acct_exit_ns(struct pid_namespace *ns) } /* - * encode an unsigned long into a comp_t + * encode an u64 into a comp_t * * This routine has been adopted from the encode_comp_t() function in * the kern_acct.c file of the FreeBSD operating system. The encoding @@ -312,7 +312,7 @@ void acct_exit_ns(struct pid_namespace *ns) #define EXPSIZE 3 /* Base 8 (3 bit) exponent. */ #define MAXFRACT ((1 << MANTSIZE) - 1) /* Maximum fractional value. */ -static comp_t encode_comp_t(unsigned long value) +static comp_t encode_comp_t(u64 value) { int exp, rnd; -- 2.17.1