From patchwork Mon Apr 29 21:22:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cupertino Miranda X-Patchwork-Id: 13647752 X-Patchwork-Delegate: bpf@iogearbox.net Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 72BE91836EF for ; Mon, 29 Apr 2024 21:23:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425824; cv=fail; b=tSgLW0ihXDBWKBBUtuLE+iVtRHb05uBdH89SsAVOiLPjS/7Jcc7saTaZIZ9Ekc+2uvrTmIPchlyvJoTko4OfBWWB228O0uQ5Yq3GNLn1jCzmunzojgOFsU5sjmEVhG7OCYI1/KyG8FT+ecwSm5C5bxWMHALaMnpIuGISIw8RxKs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714425824; c=relaxed/simple; bh=i8S/+wrErany3wbZTX14ooLr381ax0IlqpQ0kBXQJww=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=VxqFoCuzIOIHpNSjipagrrhzxHq4qt3+WjynkV/9aQ/bwk8ZyXz+oLik9+b882sp/ENpt3Dfiho1dXHNsXh0okk7G2crupbt3w0JXkBwvHkvU95s9lNE4LltZCSEovwhhh0x0Is7TXRuIvnVCWJA48Nr25q+cnmIhEw3bVZZ2Yo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=F7s+eZM/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=BAUPfpTM; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="F7s+eZM/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="BAUPfpTM" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43TKFmgE005279; Mon, 29 Apr 2024 21:23:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-transfer-encoding : content-type : mime-version; s=corp-2023-11-20; bh=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=F7s+eZM/HQHOxSP9fHLbO0sHlDGMdRlPG1Pakdha/ujuVOma/9p6nUG1AyyT3mAh9aZL pb/fEA0AAUMQMFojL1kgulJDUSpHE27stG9eQHmuXMswgq24iLQqDmLiCVXmBndiPnHt HTv7Y0UsuC7wWJuwws5MP5cO9rqCHk3YD6Cc8nUAv/RfR8XyjM/bZD9H8t/jzZmnGuQz AfpiSqqjGw9E/zloPjG6ZT/4IJx8CkdhEHWQPcuSkQ4gJTwVsdVcEwDGYdVGH66BJzXn TRRXG0tptCW5yvLkNHfEf12L/SX8mxhzP6uhV+53J5SVwUCSLmauFy1sVnOw6Oz3mIsy Sw== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3xrswvkpd9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:38 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 43TK84Ao008598; Mon, 29 Apr 2024 21:23:37 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2173.outbound.protection.outlook.com [104.47.58.173]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3xrqt6wbww-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 29 Apr 2024 21:23:37 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PPj6aFUqOjgyt6awPBhGMPigLxTsPLjVJvRVxDP0PMgnAdW+1/TVbD5u8J03M7AUsvO/dPH9++edCHYrOOJ4Xd987JNBXkwaq8RNEukgvrqRfL9Ff+sOpHH+l4FIim0yWNdM68E8tfmouVx773JwhOVyRAhNXI8pVQtYF3B3ofiHPSd+5aH5/dVVCi0snH5OWSkJ/BFzFfpcRLZeWXy+gSqCijceTc7mcVfstIF4VfiXCAHcwsh9oa+/ptOxtOV+cL75/XxHQoHzuWIYK79pC1aUhJKzQp/uQFv10ieKs53PE6vyREOUFciEZSgC4Fdxg4gKzcIbnvAN13Psp8sS3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=bQ30AwmKlinJ7lVaAq3rK9hHjz89MFdFjNY+7tenRP8VPQl6643kpAmogQPVeSI8KMo/PjeBs3gBSMabq4AnHR487rkXIX6Rtdh0hTpP4q6SevHeFh0Nyx3h8DFOX4PnRZtWMWAHQqxk67lGD7a/qGN4l9BxfzbDjCIS9TeSy59kRuvvkhvV02xRGgGN4aCdCesQJ3VMpeA9YsFfJPiIQ9+NGhhElyganzUNjcFnwoGUNwMazyWTqoGBJrLJyjRz2kyTW6XcStumXpXaLqj+uggKLYT9SWrPsfWeSaLCuYGt0rTAvFQR7VQQj/UgSx6UWgb22JoCFnWvhEyFkFkLVQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Kiy1j7ZxtprfAnIbOIFVcUwqUiROQa96z0TzvqUhSvs=; b=BAUPfpTMOmO24gmknvrPXNSx6g20ctGWkSTk63CI8ZDQ6mtesXazzb1g9xXPMoIJrGluvl92OhJg9UhRUB1NrgDaOys2g0Bhrwtj2/ab+qY1MFr6jVZn2zNrVEJHbB1j8cEaktFY2BYjVkdiRMfxqUTeVjd/bW9U0juVB3ePxP4= Received: from MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) by IA0PR10MB7232.namprd10.prod.outlook.com (2603:10b6:208:406::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.35; Mon, 29 Apr 2024 21:23:35 +0000 Received: from MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c]) by MN2PR10MB4382.namprd10.prod.outlook.com ([fe80::1e11:7917:d2c:e44c%4]) with mapi id 15.20.7519.030; Mon, 29 Apr 2024 21:23:35 +0000 From: Cupertino Miranda To: bpf@vger.kernel.org Cc: Cupertino Miranda , Eduard Zingerman , Yonghong Song , Alexei Starovoitov , David Faust , Jose Marchesi , Elena Zannoni , Andrii Nakryiko Subject: [PATCH bpf-next v4 3/7] bpf/verifier: improve XOR and OR range computation Date: Mon, 29 Apr 2024 22:22:46 +0100 Message-Id: <20240429212250.78420-4-cupertino.miranda@oracle.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240429212250.78420-1-cupertino.miranda@oracle.com> References: <20240429212250.78420-1-cupertino.miranda@oracle.com> X-ClientProxiedBy: AM4PR05CA0010.eurprd05.prod.outlook.com (2603:10a6:205::23) To MN2PR10MB4382.namprd10.prod.outlook.com (2603:10b6:208:1d7::13) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MN2PR10MB4382:EE_|IA0PR10MB7232:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bd4b8f8-d1c7-4414-b269-08dc6892a096 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|1800799015|376005|366007; X-Microsoft-Antispam-Message-Info: /wY7MPCuQxcQnPtOXJkbaB2dzPbYOTV7Qka8kyYM+bX1swAaUdPaBa9z2UyKYWaag5IEt9sB0znY7xDQSycotP5IqGqsIFgD+nKOUYAlqAoIReX0cU1+9kA30uMe/CuhuUVw41krQyCLFr+OInC/KgDk627h/ARuFRtA8Khd5t8XtxwqhWGmiQsv7K9U8ka1K3+090AwcR6C8DJ2rzemuEYXrb6oupW1XZC3o1ziwVXioB6Y3MXG9n3iBYmmS/dBYcTCUNVsrGP4Q3UBN1piRzWUnFxEZj73Y5l4kTB2s6Znqs9r2sUj45M7diWuLLJnJDpSk26UOC0HJFOSbJd3t8G7VzjYVafV75Az1em83w3VzXaScNt4xYu2AculGQblpVjsVSbxdLILu25xs+B1xOdrtiJUK1MKCZFbK8OLH9K7/YnQkx8X90TpqqmBz9YjYFOEZIpjzBnfd3c7onqNgbiQURTZWlWSjVdUzYtMYoJPNvoksqeesitxYsCmoYPsoixx2npAmXKeqrIwWwpGJp/SxCO6qxyn1JaALi+QV55hWXKrZyqtJVnvTZFer3CgCjDZc5d7lhVPvYl6uWxkHgv4PvH+TPbP0Ar4UJ6y97S69i6UCC9lZg9XqBF73K5coyFXSqtPj8WsUz8dfHAZNlyt1ui62B6zxnuxP1AF87v5ta4EctlrNSssFbuXOJamZ/5irnlsjHKrgi6qYk6gCMANBVOBQTW3oPZkeK0qaEl0U+9xv4mFNhFTTMIW3W0ZBEq96PkS43chFXvUdR0C9R9ym/SvPHDgM5gOsJdYhdiGE5OaDVEYfjGZzI5qpLwkniOaiRYsqxHkQFHKr94Y+ZgkWwTYbhmTHmyhNUVZXK2g8jlo/QC39GGuwEij9aHl5Y71adked5HGEbBSvL4YpTM0ox6YZsJieiIEqX8rSOVd5kJgdXVcoZZZPxfyHN/yw3LFTdJ8e/PgtmQ7E/Xpob9qM49KYmpnkGvnrAFpKNU5UdreYn8JXDzD/H1y0ls432+xpGq5n9gR5LCNBjSiwqTyzkjYqYnQ/1ZWKCsxrXvsrx6jy3HB7IBGqAKhwxjyax2m1QXqFCHy0w5B93m3EEzhqByS+KqxBn5PrEXlOZOwFyKgG2YECaQlZ5snm/h8SypP7MxoUw+63tHCMJIcHW9LeSdDhDwsaGPf//0+6qis/8xlRj//R5rMI51kNV05cUWs3wrbM1hNemfUkelzblS+PkpBKVKNbw6bmyJXyEfmu2V8nGPKjBplLip/pbgw362exqxgjoz55IKxjAj4Xw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR10MB4382.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(1800799015)(376005)(366007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-Chunk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L+y2gKbuhMg5XY2Svn3hM05VxZGlp3Ws+tu952+HSX0ETqU8wJI4Zhw+Vt759xCrHBDNzy6Tv4mgP01L7wpQ691ftsq4Z8C7Q5adB19tT0yuokhJCBGzB56BPSdjoycQ1xfCWAooHChL1pULFeEtOLVT+Ylo8ZvhloSzGlYFjb3Abr54fBoxBsphworuMEFQfU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd4b8f8-d1c7-4414-b269-08dc6892a096 X-MS-Exchange-CrossTenant-AuthSource: MN2PR10MB4382.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:23:35.0168 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: VVypPe1FqYvoJRgHPg88QTeYMbJcYO9YQFgrn0aeRNpteGvKf/Y/uEg2g4tOZqFU+uyP2tkCR+GL5o7fIHYs4lYHMjiRmKUX4QzP/XAEgjY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB7232 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1011,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-04-29_18,2024-04-29_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 adultscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2404010000 definitions=main-2404290141 X-Proofpoint-GUID: dozftlAR2o2G6nlv7DRn9NXqoqkOYmwr X-Proofpoint-ORIG-GUID: dozftlAR2o2G6nlv7DRn9NXqoqkOYmwr X-Patchwork-Delegate: bpf@iogearbox.net Range for XOR and OR operators would not be attempted unless src_reg would resolve to a single value, i.e. a known constant value. This condition is unnecessary, and the following XOR/OR operator handling could compute a possible better range. Acked-by: Eduard Zingerman Signed-off-by: Cupertino Miranda Cc: Yonghong Song Cc: Alexei Starovoitov Cc: David Faust Cc: Jose Marchesi Cc: Elena Zannoni Cc: Eduard Zingerman Cc: Andrii Nakryiko --- kernel/bpf/verifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 1777ab00068b..54aca9b377a4 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13744,12 +13744,12 @@ static bool is_safe_to_compute_dst_reg_range(struct bpf_insn *insn, case BPF_ADD: case BPF_SUB: case BPF_AND: + case BPF_XOR: + case BPF_OR: return true; /* Compute range for the following only if the src_reg is const. */ - case BPF_XOR: - case BPF_OR: case BPF_MUL: return src_is_const;