From patchwork Fri Apr 28 15:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charan Teja Kalla X-Patchwork-Id: 13226532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25E90C77B60 for ; Fri, 28 Apr 2023 15:03:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EE276B0072; Fri, 28 Apr 2023 11:03:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89F166B0074; Fri, 28 Apr 2023 11:03:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 73FA36B0075; Fri, 28 Apr 2023 11:03:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 61DB06B0072 for ; Fri, 28 Apr 2023 11:03:10 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 2B94C80216 for ; Fri, 28 Apr 2023 15:03:10 +0000 (UTC) X-FDA: 80731117740.07.70A5690 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by imf24.hostedemail.com (Postfix) with ESMTP id 78BB4180012 for ; Fri, 28 Apr 2023 15:03:06 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=P9E7iJit; spf=pass (imf24.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1682694186; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MvMChziDPbKmzDjW3D5kNKcLaF7qRiZICSZYLgBSpNw=; b=1Wtu/f4oItOEmHfGrqudSi+XwHrD3/WK7PTBUFM9W/SPBBGa377EH967zMyppRWboRSmn/ fNEiVZ2uXz9aJP+vC0yPIP+xoiOhIKp6L16yOy8wWQNmPynpp+SF4+mXSoyXy7UUYaEpl6 p/StUB35gPTFqHK6QAaClOTjuo+0TUY= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=quicinc.com header.s=qcppdkim1 header.b=P9E7iJit; spf=pass (imf24.hostedemail.com: domain of quic_charante@quicinc.com designates 205.220.180.131 as permitted sender) smtp.mailfrom=quic_charante@quicinc.com; dmarc=pass (policy=none) header.from=quicinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1682694186; a=rsa-sha256; cv=none; b=lPYzQlfjw3AH2RNHXllKJMMjp1JGtt4jse8YnMiDNArBme7f/dg8o2AyCGoen1d3yNH0A7 WlPdDq9JNL5htdDPuDdVaXoW1kH3jpAxZ1DRCedqS8g4ksgmZ63zgWTqCanZsFIL6Pwqkw 7/Jb5ut5FuXh2NH74j+kN8YBQIcWsjo= Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33SDe4us016525; Fri, 28 Apr 2023 15:02:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=qcppdkim1; bh=MvMChziDPbKmzDjW3D5kNKcLaF7qRiZICSZYLgBSpNw=; b=P9E7iJit7t6xsb7sTGHCympRV/V6E2U7Rq9M5U8fp6K4hMIOvaf0hU7y5esW+kfSFqoS 3zHF69KKiSrmz2ViYd++J+THezxe9ZwtYVzykVqDN6HcH3KUhIQ//MIY4qJrfIPdMaVg 27Za8fZtmZpNGsjgpOIM+HfF4yeeeONVO2adYdwIz2cZ+yR+RLCRgAVWh6c9gXa+MRnn uPo8a7SY5BdrtQ8bZEsA+Tc3ns3++iYSykhho1kLi8ARqAzvoQ5QEenJNKNkuRWVVPL/ rT8Y9Uqp5R1MDMGv5sp/mOIxvEriEup9Ot8Ezi6IUsy3d0i7C9rsztjx20GqKhbi6cks og== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3q7thv3d1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Apr 2023 15:02:58 +0000 Received: from nalasex01a.na.qualcomm.com (nalasex01a.na.qualcomm.com [10.47.209.196]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 33SF2vaS010116 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 28 Apr 2023 15:02:57 GMT Received: from hu-charante-hyd.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Fri, 28 Apr 2023 08:02:53 -0700 From: Charan Teja Kalla To: , , , , , , , , CC: , , Charan Teja Kalla Subject: [PATCH V8 1/2] mm: fadvise: move 'endbyte' calculations to helper function Date: Fri, 28 Apr 2023 20:32:26 +0530 Message-ID: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nalasex01a.na.qualcomm.com (10.47.209.196) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: kUudwVprHoqD1M9JhQEoLmFroyjROCTM X-Proofpoint-ORIG-GUID: kUudwVprHoqD1M9JhQEoLmFroyjROCTM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-28_04,2023-04-27_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 priorityscore=1501 mlxlogscore=755 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304280120 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 78BB4180012 X-Rspam-User: X-Stat-Signature: mkindep8iyo4pkidrzqcncqeutjao3k7 X-HE-Tag: 1682694186-250822 X-HE-Meta: U2FsdGVkX18RIFoWCHeLqXNzsApooyEjcCw5RrmC+W0uJXzG54VyRMH4a4Cxdr/t668KcmGwavK+UBZuKBGN2v/FOuj26mb2b7Q8gGd2WUvulcMiVtpG/36RXI6OPo6hPb6ME92US1akKU33udzCCAbwClZBzvf2QrEdFisibmRJChHXd6kNzhJo5DoMNagnq/4P+jaE/8vHnLvHZ2cXOJcqP6HpZHKt8KpYiTTjkYOOBH8vxzztvklMjGG4iNBgDRznNors5F3m25sQyOWuJYdgAKAla6nbNB9mXYLmdWdoIR08M1tHn0Ij2rIEKoFbZOXgYeyrusBJu9ma4ybqn/fZHBa73Me9rY0L/kkSsa3s8RvGHRCZtp4C7YgmKPkksWu4hr1wAKeZRiA2mlV1WnicfWvFNfTomM4z9sDT29kZ9CUkUcjESoSkIQsUKshdJZZgPCEPKxoIvK49nXGjtQB/7H6jEHzYnMW7VUu5V1XvNp12WYk5pv46utvCI4hOqbiqd6WDxi8g1+GKyItfETCfJTX/ApM8A2vYiN9KVDafspnRlzL3AiioQJbZ6OixQ4/EXiXppxOdtsYlT0L7PrCfTF5KGBUsFk/mOg0Q6nW7J8Jhb8ni3tJhG32elc84FuN3DHlhgEIHxlhJHDNHVEY7NjignQSvGi+oh22yGRGRSuoUgJLafmnAnMVQzyiDeL3N7sxFWcIu/9WwnhR2zmjzwWs4NlnWYwQ1KsoUKA+CU3qbpnDWxz/cwzcK27Wna4EjhtvDF62CmdzkbTKCpbdAifCyl+ZRTHfvOnmwknCHamWyAQ3YGRZ1kWuPzzy3LfkjUG6qcWIH9JlwqJi3n8Fx2HYbUOOw6VX1JhuuPLFdK7t4VXWVLodlRLMxTSNN3o98ECPyfIqNQ9+MDhLS8/gd+DzJGrWGDnGfLcSHUN+ITXPTvIa1ysdlYrF0ijXiJlqM+O8Uj42FXjHVsrU sPWw9FXp xKwhKsaTPxhcpCQUwwA7dxh5rHZWyse2DgornD2y2dK6K372Bt/Cf/dgQ4HsJhQNKD1QajGUudwf53J0XXXrIMyMsjSxRcQOBKrCAWl8wF9DC2o+BiLO28chHPWikMW0Q5veeAaF1MWPaxJr5bMDyeOXZNeKsPX1XQePKw2xkuWTa8JDKQPuik4V0J2xof9Vglr5CHU9FkO9AA/369b4/FMfWJg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move the 'endbyte' calculations that determines last byte that fadvise can to a helper function. This is a preparatory change made for shmem_fadvise() functionality in the next patch. No functional changes in this patch. Signed-off-by: Charan Teja Kalla --- mm/fadvise.c | 11 +---------- mm/internal.h | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mm/fadvise.c b/mm/fadvise.c index fb7c5f4..1b3cac5 100644 --- a/mm/fadvise.c +++ b/mm/fadvise.c @@ -65,16 +65,7 @@ int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice) return 0; } - /* - * Careful about overflows. Len == 0 means "as much as possible". Use - * unsigned math because signed overflows are undefined and UBSan - * complains. - */ - endbyte = (u64)offset + (u64)len; - if (!len || endbyte < len) - endbyte = LLONG_MAX; - else - endbyte--; /* inclusive */ + endbyte = fadvise_calc_endbyte(offset, len); switch (advice) { case POSIX_FADV_NORMAL: diff --git a/mm/internal.h b/mm/internal.h index 7920a8b..8d96811 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -657,6 +657,27 @@ static inline void vunmap_range_noflush(unsigned long start, unsigned long end) } #endif /* !CONFIG_MMU */ +/* + * Helper function to get the endbyte of a file that fadvise can operate on. + */ +static inline loff_t fadvise_calc_endbyte(loff_t offset, loff_t len) +{ + loff_t endbyte; + + /* + * Careful about overflows. Len == 0 means "as much as possible". Use + * unsigned math because signed overflows are undefined and UBSan + * complains. + */ + endbyte = (u64)offset + (u64)len; + if (!len || endbyte < len) + endbyte = LLONG_MAX; + else + endbyte--; /* inclusive */ + + return endbyte; +} + /* Memory initialisation debug and verification */ enum mminit_level { MMINIT_WARNING,