Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1769294ybh; Tue, 14 Jul 2020 06:57:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxduK1kHM0GYPIlVmGY9H8nh2B4vwkybX3908+41v5rIkmIqbpATvyTjAzx6m1AdEkO9C4X X-Received: by 2002:a17:906:4dd4:: with SMTP id f20mr4848827ejw.170.1594735052932; Tue, 14 Jul 2020 06:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594735052; cv=none; d=google.com; s=arc-20160816; b=QkKbPAbvdzRWM9TKpYVVBonfXMGbW3k28xqcIDvJbVxzjCS4GKgNK1cBJnTBkfxYeU 81wOq0nnqos8dCfSDlHPHOYPcSEXS38wKCMifYb/xAjrpFcZ7vBNKGKcxQIqByaqAmzr ltruVmUVX4wNjI7HU2viQjEuSgQCMgVheEfWBRVocZZXbP4CNYGQSI48rphpr5xldk96 LUWe47o5BR3mcvao3yzzGXFkJc0FJC2u4kC+3ZCpkPgn3zgFc7xU51ANB97WgsFq1aBd 81aoTA9WKk7T2ZiOJl0ojoCd2p6u455TfnqtADfAqJEvwR1gvoxjg31EbOzlMRz4zgd9 fO3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=9AtOfmz3gCl8DWD/3GijOiPN9AosKFdyzHfDCOf9TrE=; b=B+bgA2V/4q3kmWBUgkJNoyZdf9sup/QD2QnzLCaXzyifRKaO/2E94umWUU8SKUkQR2 9P1RNp8Shq/3gLXtoEYKEenVGNON4vZd/HcCCqfCtwmr3b9ic6Hbk5EUsEg9SP4gHCLT i/IANWSf4NVic39Uw6zfL6BcSAlZut21zw7aHPDr29I6medzKEax6YDoGHwFVaIJfYg2 kt61zIkWMPEHMdWs5wk76CTXD+gBNQUuOLVvv6OJbmCH8FcsmsVF/OK51E2umYPQSSk5 6vwh8RRQ2YVxY8TXVZEBzjKzW5NHfy3Km0d/l3TbP2CM2D5/cOVonJVhH3klWOmQc96R UQUw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e13si10864618ejx.153.2020.07.14.06.57.09; Tue, 14 Jul 2020 06:57:32 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbgGNN5E (ORCPT + 99 others); Tue, 14 Jul 2020 09:57:04 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:57448 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725821AbgGNN5D (ORCPT ); Tue, 14 Jul 2020 09:57:03 -0400 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id A5B01131134F9A7732CE; Tue, 14 Jul 2020 21:51:53 +0800 (CST) Received: from [127.0.0.1] (10.174.186.75) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.487.0; Tue, 14 Jul 2020 21:51:44 +0800 Subject: Re: [PATCH v2 2/2] arm64: tlb: Use the TLBI RANGE feature in arm64 To: Catalin Marinas CC: , , , , , , , , , , , , , , References: <20200710094420.517-1-yezhenyu2@huawei.com> <20200710094420.517-3-yezhenyu2@huawei.com> <20200714103629.GA18793@gaia> From: Zhenyu Ye Message-ID: Date: Tue, 14 Jul 2020 21:51:42 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.0 MIME-Version: 1.0 In-Reply-To: <20200714103629.GA18793@gaia> Content-Type: text/plain; charset="gbk" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.186.75] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/7/14 18:36, Catalin Marinas wrote: > On Fri, Jul 10, 2020 at 05:44:20PM +0800, Zhenyu Ye wrote: >> +#define __TLBI_RANGE_PAGES(num, scale) (((num) + 1) << (5 * (scale) + 1)) >> +#define MAX_TLBI_RANGE_PAGES __TLBI_RANGE_PAGES(31, 3) >> + >> +#define TLBI_RANGE_MASK GENMASK_ULL(4, 0) >> +#define __TLBI_RANGE_NUM(range, scale) \ >> + (((range) >> (5 * (scale) + 1)) & TLBI_RANGE_MASK) > [...] >> + int num = 0; >> + int scale = 0; > [...] >> + start += __TLBI_RANGE_PAGES(num, scale) << PAGE_SHIFT; > [...] > > Since num is an int, __TLBI_RANGE_PAGES is still an int. Shifting it by > PAGE_SHIFT can overflow as the maximum would be 8GB for 4K pages (or > 128GB for 64K pages). I think we probably get away with this because of > some implicit type conversion but I'd rather make __TLBI_RANGE_PAGES an > explicit unsigned long: > > #define __TLBI_RANGE_PAGES(num, scale) ((unsigned long)((num) + 1) << (5 * (scale) + 1)) > This is valuable and I will update this in next series, with the check for binutils (or encode the instructions by hand), as soon as possible. > Without this change, the CBMC check fails (see below for the test). In > the kernel, we don't have this problem as we encode the address via > __TLBI_VADDR_RANGE and it doesn't overflow.> The good part is that CBMC reckons the algorithm is correct ;). Thanks for your test! Zhenyu