Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp356782lqh; Tue, 7 May 2024 00:48:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXwE6rE1cK3IwqsSF8WbCVSEpxz0TDop7kNH58uGLahDSqkjJUrjYMfhpZMOTnkq13yfyppLpeQdhQSHrHIQxnBNCcAgMr85gxue4ouNA== X-Google-Smtp-Source: AGHT+IHcvpZ7n+a9N+5rQi8VYHh4zW2zUHtcI52LITmAYjwy7FDRZQ2SAoq5FWv67HcH6NnkwjdG X-Received: by 2002:a17:907:eab:b0:a59:b6a8:4d7a with SMTP id ho43-20020a1709070eab00b00a59b6a84d7amr5140832ejc.43.1715068102605; Tue, 07 May 2024 00:48:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715068102; cv=pass; d=google.com; s=arc-20160816; b=QehdHM58TeWovy55ZJoXmGrDwqy122KarVTIGcPZrmqdCGjQx+Q1b3ilrHjrzlCGG6 wK7ddEQ7+CCfFhfMgolsqUkl5zvRyoWyicQTwEsE1HZlL4qS2IfkMzf8sPQ6fclqsyVu PXOLLeUGpCGPlr4u5VYcTcNON+XMMNVqhkMEYe/e3pPQkJOGKfNvsoNbTYPpQppFjVjB J+OhDEBvcdmIP0rxmSldjzUVs35vcwwnS4GtWNkYJS4ywd7gwvQCxdVAHtj193Plnu6N B9LabNscRSxMKJ+Yo5QCKIpbq8G5aCXG4FkYr68y2Jph4iPg2QimvPEw+oyZzfF9CerM hyxQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=55sgICp9dEeReEW4hPgwUAkiFoYtNZzkvXHlRBri2ig=; fh=d7fS8hkRF+5BpTd2awDj3rOQYMR6EB+bcWDhYXq4Pr8=; b=qEX2D/hnQbyXtfs5Jb0/NN2MDEarGHm6jl32lRKFyUcTeVFqqKo/uUKedRJzWgBF8M Vg6CTINkkD0tvwI9Lg3/mHdSEYoO+MbGOCPM6UK7Z4CuRlLdI3pTvyzdyaxNBzBoy6+u fbzElWbivlONttD+zHjYXmMzyC52q+Iufz1/s+xyfnjrvU2swhNvVrOAlxd/Q7Zvw8sO gWdQNuQt4vpUJbJQxvdUFdzc68NGtdWTPli/9WdnMZil2zRbsTe3/PhJdq0G6HjQz9vr AqiRrZH/gGcQ9t7kK/6joDbDQh93sw4h7a/6s2L7OH3z/K0ejPuvyQ1PqMRKpwRagkPu cy/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=eFfL7MIw; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-170835-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170835-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id l16-20020a170906795000b00a59f4f34d11si42379ejo.114.2024.05.07.00.48.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 May 2024 00:48:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170835-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=@xry111.site header.s=default header.b=eFfL7MIw; arc=pass (i=1 spf=pass spfdomain=xry111.site dkim=pass dkdomain=xry111.site dmarc=pass fromdomain=xry111.site); spf=pass (google.com: domain of linux-kernel+bounces-170835-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170835-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site 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 5988F1F2432A for ; Tue, 7 May 2024 07:48:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1A1913C67C; Tue, 7 May 2024 07:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b="eFfL7MIw" Received: from xry111.site (xry111.site [89.208.246.23]) (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 ABDB313BAE9 for ; Tue, 7 May 2024 07:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=89.208.246.23 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715068096; cv=none; b=ClRJ0mq3jVjqmsn3CuqWQeo7xIC9IGqWZ0DcBzHd7Jw3IiQ0eVMk2UJvIlb3ja/jSN5XYJI1B1EyX51t4njVPo6Z5RvmV0LOmu/I9fp3X71sTuWEMYEJl25xKjlKU2jd7Bd4I1/cdL55+QnMZ12mf4anQEuDtJeKAkrjaji5xw4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715068096; c=relaxed/simple; bh=QpWK8tGEk5ck2XW/s8yztEHz7kBviwnCEcPgX3pHC6c=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=GBlJVwDqEHgVEXWr2zZ+y5B36eKzLVP40ZY0b8VyGfXNB5YlF1Cc46+BEFDOKU4IAHnYokh2oWZ5SV+pxOjhzuEHbuGSXKdozODektfm6ujwYg9MdMidYzhNeGKJJkE4CDKxkKkGOtCAL3z7ZlwhvKT3TrOlDzEooay3j/EomVo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site; spf=pass smtp.mailfrom=xry111.site; dkim=pass (1024-bit key) header.d=xry111.site header.i=@xry111.site header.b=eFfL7MIw; arc=none smtp.client-ip=89.208.246.23 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xry111.site DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1715068091; bh=QpWK8tGEk5ck2XW/s8yztEHz7kBviwnCEcPgX3pHC6c=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=eFfL7MIwrp2A/VxUjep4YMKQVqF8O3SN3tqBicAghYfA6B05bOFPYzKluJaCEd/ZG 2YmpET+UOQ7qg9OYJ1+b87/+2ZtqDbLoA6yngIJdC1o4Kf92FJEx96Ki3d0dZt7RAw KqQVlAwJcfDXFf5wxPdFgFuo14FBCcuG+N775SNg= Received: from [192.168.124.11] (unknown [113.200.174.35]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 528FC673F0; Tue, 7 May 2024 03:48:09 -0400 (EDT) Message-ID: Subject: Re: [PATCH] LoongArch: Update the flush cache policy From: Xi Ruoyao To: lijun , chenhuacai@kernel.org, kernel@xen0n.name, lvjianmin@loongson.cn, dongbiao@loongson.cn, zhangbaoqi@loongson.cn Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Date: Tue, 07 May 2024 15:48:05 +0800 In-Reply-To: <18342368-ce79-9820-26be-01834876fc9e@kylinos.cn> References: <20240506092419.4109941-1-lijun01@kylinos.cn> <8a8135eb0f1dc724cfbb4402dc6daf08db5b0bc7.camel@xry111.site> <8809f5a7-de6e-0794-feab-726c26f87344@kylinos.cn> <18342368-ce79-9820-26be-01834876fc9e@kylinos.cn> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.52.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2024-05-07 at 14:38 +0800, lijun wrote: > I guess, final the value of addr is not important, just all of addr must= =20 > read once is very important, >=20 > so use two 'for()' and 'volatile' to flush all of addr=C2=A0 's cache,= =20 > exactly as the name of the function is >=20 > "flush_cache_last_level". AFAIK do a read does not mean flushing the cache. The cacop instruction is intended to do the cache flushing. So why the cacop instruction in flush_cache_leaf is not enough to flush it? Is there something wrong in flush_cache_leaf? It currently reads: static void flush_cache_leaf(unsigned int leaf) { int i, j, nr_nodes; uint64_t addr =3D CSR_DMW0_BASE; struct cache_desc *cdesc =3D current_cpu_data.cache_leaves + leaf; nr_nodes =3D cache_private(cdesc) ? 1 : loongson_sysconf.nr_nodes; do { for (i =3D 0; i < cdesc->sets; i++) { for (j =3D 0; j < cdesc->ways; j++) { flush_cache_line(leaf, addr); addr++; } addr -=3D cdesc->ways; addr +=3D cdesc->linesz; } addr +=3D (1ULL << NODE_ADDRSPACE_SHIFT); } while (--nr_nodes > 0);=20 } There is something bizarre: the flush_cache_line function uses the cacop instruction in the Index Invalidate / Invalidate and Writeback mode, and if I read the LoongArch manual correctly in this mode CSR_DMW0_BASE and 1ULL << NODE_ADDRSPACE_SHIFT are just ignored. Is this something undocumented or flush_cache_leaf is just "incorrect"? --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University