Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2525902lqz; Tue, 2 Apr 2024 23:50:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQ+hb6Z7TS5fKlvfy534t6DrF9WSObZL8ulhRxGbWQuHGQkSokOfegLKdet0LRP1eplqMo4ufW/1X+SyvAItOTmAJ3N14mP5jZUBUFFw== X-Google-Smtp-Source: AGHT+IESxdA29QkX0cTJ0ylNDsKu1RQRcamlAfPHN+43D77taVTQHOkBqsDTNQ5Blz3jbaQB+dJ9 X-Received: by 2002:a05:6402:5253:b0:56d:ee15:4925 with SMTP id t19-20020a056402525300b0056dee154925mr3595612edd.0.1712127014375; Tue, 02 Apr 2024 23:50:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712127014; cv=pass; d=google.com; s=arc-20160816; b=mPzhZQNjZVTqMZeSRbIL0pWVJq8V6Nl6mpeVsl38XykGnLkyAx1du8q2FaxRjSTKNu PLxW3uLv8760N7e9PJ0ewR8pjK2Ji2khPxTyU+VCF9vanRCjJNdIAvjvQu6afcIoIrHU M0/T6zwQ1rpYyb9aav/EKm+3hMeCUTs8APmoRuMJOcndaBMtCMaqGT+tI3koSRt1/J5t eu2p2Bfmf+czXokM9StoCZ8U6q5qzrWdm6xmswHADod57GDweEz7Uhoqi3AhrDl1umw8 nOg3miUjnUdPTkesdyLfaf1aGF2GcY32YP/E/FvdHq+vx60X0ARzrg+wSE+/RNiTL75a a2Sg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=8OA5M2JySvtjyWS+tMniT9ifxm3Iouz7728YRKZW3ys=; fh=o631n5u/N9OWzojgzBwx/fcaUEb9x0Po1+X+0av5kKc=; b=PhrAarspMt64dKXTXHBrtnUz0VczmXGeN867vje6skXBY9HaOryGqJWzdquj0Vk4VY Y//GUMTtsij9a9CW7BDrtdvoaKB4mI1GqPk6mBMiAYZf84LdNOlwCfY92LM/WzzOrIMZ wIuJ0BZmWzL9loq1m84IlTj7orwKzZpdlU5BvUq2S1gSNGQA5r7QdakIJuGGckDtcvHd plFLUZVpWH87FaCBt+y+SFYtZN31XDg6NrdbWhX14AFtW/W5MyzgtBt9LoRxEZzJmsmy 2oM5kpeJHdIkkOZNLydV8F7EJtAPK6PXJo627lanSGNAX5ZkFEOd56k86OSvmGmV4X5P CmqQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IAke3zN5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-129098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id r24-20020a50aad8000000b0056dfbb18956si715653edc.337.2024.04.02.23.50.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 23:50:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IAke3zN5; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-129098-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129098-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 205CF1F233ED for ; Wed, 3 Apr 2024 06:50:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C61924D13B; Wed, 3 Apr 2024 06:50:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="IAke3zN5" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 28E0D17C64 for ; Wed, 3 Apr 2024 06:50:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712127006; cv=none; b=EU0924Ook0sj9j96OgWDlfDV2saaFvwCXWAqXA87Gwr2baArDDZtLIdF+wn7Wj3lNVzGrXmeqCebpWhkP3YacVZm7uPycw/5KmvM1cJnZKy1AW3nBKsr/fLF1SyzBpPDOTzyDg382+SN1U6p45EVk1yb2mnXgBhrsdgBfBSx3bU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712127006; c=relaxed/simple; bh=vAd3eDrBGIEIBL0EqzSfwZ7ValaoEk3VWTmlQq7RBGw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=D3IzBKPxNARnxgLOlJ4ZhJ1o1cHTOKgzXMOiOS6E+G8RVbn2e4EOE+mYqZNtaKT8tx1n73hfbs6SNQLA/XSTMS3T3u7cz3p/jPmuy5lLvzVuIQMC8r+/d69rsMDxLnA7XKgo5JTbRtr2JMvLIOL+/zZ2fQjjsMEFHlnEAdxQlrI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=IAke3zN5; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712127002; h=from:from: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:content-transfer-encoding; bh=8OA5M2JySvtjyWS+tMniT9ifxm3Iouz7728YRKZW3ys=; b=IAke3zN5/t6joXJUPXHkNdwyFZS+ZKd2qlTKq0JmL81pW2tyw+Au15g+GR1haIFZZ+3OrX ukaR2rv/fH54wLtGkyk7zpR+K19mNIbCPwkVHlci383v54YZvmGvIycVpnuB2Kj5v7LkIR CV3nw/zP/LXMnr1QylXvwvgeL++0pJE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-510-FpJhxRD0MiaZGxQMtnZNtQ-1; Wed, 03 Apr 2024 02:49:56 -0400 X-MC-Unique: FpJhxRD0MiaZGxQMtnZNtQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 286F4920701; Wed, 3 Apr 2024 06:49:56 +0000 (UTC) Received: from gshan-thinkpadx1nanogen2.remote.csb (unknown [10.64.136.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B99152166B4F; Wed, 3 Apr 2024 06:49:50 +0000 (UTC) From: Gavin Shan To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, akpm@linux-foundation.org, maz@kernel.org, apopple@nvidia.com, mark.rutland@arm.com, ryan.roberts@arm.com, rananta@google.com, yangyicong@hisilicon.com, v-songbaohua@oppo.com, yezhenyu2@huawei.com, yihyu@redhat.com, shan.gavin@gmail.com Subject: [PATCH] arm64: tlb: Fix TLBI RANGE operand Date: Wed, 3 Apr 2024 16:49:29 +1000 Message-ID: <20240403064929.1438475-1-gshan@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 KVM/arm64 relies on TLBI RANGE feature to flush TLBs when the dirty bitmap is collected by VMM and the corresponding PTEs need to be write-protected again. Unfortunately, the operand passed to the TLBI RANGE instruction isn't correctly sorted out by commit d1d3aa98b1d4 ("arm64: tlb: Use the TLBI RANGE feature in arm64"). It leads to crash on the destination VM after live migration because some of the dirty pages are missed. For example, I have a VM where 8GB memory is assigned, starting from 0x40000000 (1GB). Note that the host has 4KB as the base page size. All TLBs for VM can be covered by one TLBI RANGE operation. However, I receives 0xffff708000040000 as the operand, which is wrong and the correct one should be 0x00007f8000040000. From the wrong operand, we have 3 and 1 for SCALE (bits[45:44) and NUM (bits943:39], only 1GB instead of 8GB memory is covered. Fix the macro __TLBI_RANGE_NUM() so that the correct NUM and TLBI RANGE operand are provided. Fixes: d1d3aa98b1d4 ("arm64: tlb: Use the TLBI RANGE feature in arm64") Cc: stable@kernel.org # v5.10+ Reported-by: Yihuang Yu Signed-off-by: Gavin Shan --- arch/arm64/include/asm/tlbflush.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/tlbflush.h b/arch/arm64/include/asm/tlbflush.h index 3b0e8248e1a4..07c4fb4b82b4 100644 --- a/arch/arm64/include/asm/tlbflush.h +++ b/arch/arm64/include/asm/tlbflush.h @@ -166,7 +166,7 @@ static inline unsigned long get_trans_granule(void) */ #define TLBI_RANGE_MASK GENMASK_ULL(4, 0) #define __TLBI_RANGE_NUM(pages, scale) \ - ((((pages) >> (5 * (scale) + 1)) & TLBI_RANGE_MASK) - 1) + ((((pages) >> (5 * (scale) + 1)) - 1) & TLBI_RANGE_MASK) /* * TLB Invalidation -- 2.44.0