From mboxrd@z Thu Jan 1 00:00:00 1970 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 B1198EB64DC for ; Tue, 18 Jul 2023 18:18:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 020CB280005; Tue, 18 Jul 2023 14:18:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F13128D0012; Tue, 18 Jul 2023 14:18:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E01C1280005; Tue, 18 Jul 2023 14:18:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D28088D0012 for ; Tue, 18 Jul 2023 14:18:04 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9E6831C8D3F for ; Tue, 18 Jul 2023 18:18:04 +0000 (UTC) X-FDA: 81025541688.18.74E8085 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf07.hostedemail.com (Postfix) with ESMTP id B727540018 for ; Tue, 18 Jul 2023 18:18:02 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=FNRlqRi1; dmarc=none; spf=pass (imf07.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689704282; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=a1bIpMgG1zI6JwKodCNWlBnTaKXYcih1lskBJDBEehY=; b=c7WFussVFkqFrhXafNhCwJYa3DqGBiPKIU2tF3rvd+fQcExoh+FPCqUGdCdNsBJi06FoqB KAA1/GZN3Ug7KUz1XhcyQlXNeB9YsMonA0ZyFmNLybaT7HqjzDa7XADZqVsxSUEXdLbGTp VznWYJetr7S6YcrZwXcN5AqaKQM8AKg= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=FNRlqRi1; dmarc=none; spf=pass (imf07.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689704282; a=rsa-sha256; cv=none; b=Z7QmFxq2YOEz3zSbF2rd7h4UCglJQwZETOP2YLaI9mfHy8Ey7Gnqo8djpBoT0dNsMMivG4 XJEZdIHsDYWBXC4Kp7pV1fvfFLIMB9M4NPEkzcvZX24LUE8wHn820nlVIYRlWO/ltoPUc6 Wb78gu2u6YckU2ac0MRzma54D39mPB0= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AFA64616A9; Tue, 18 Jul 2023 18:18:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A5D3C433C7; Tue, 18 Jul 2023 18:18:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1689704281; bh=d+shrDRi9kk42aZV2mW7vxjklY0jpOFHpDdmUYO9Dqc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=FNRlqRi1A1ztUfMn/6WIB9xmZD59uhsQOC2e0G2SWRRwPvCu2EckzeGu+U4WeGeZ/ VsDlgtsZpKDhvdZQNN+yppX82+DGNSCBhGzBVek50PYsACLJGww+19Xlciuyn3Ijbt xwmFaowIPLHn3A3F4NP+KAhTWKUGxgd/oAcDp/U0= Date: Tue, 18 Jul 2023 11:17:59 -0700 From: Andrew Morton To: Alistair Popple Cc: ajd@linux.ibm.com, catalin.marinas@arm.com, fbarrat@linux.ibm.com, iommu@lists.linux.dev, jgg@ziepe.ca, jhubbard@nvidia.com, kevin.tian@intel.com, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, mpe@ellerman.id.au, nicolinc@nvidia.com, npiggin@gmail.com, robin.murphy@arm.com, seanjc@google.com, will@kernel.org, x86@kernel.org, zhi.wang.linux@gmail.com Subject: Re: [PATCH 3/4] mmu_notifiers: Call arch_invalidate_secondary_tlbs() when invalidating TLBs Message-Id: <20230718111759.5642b4c4ffd72ddd9c8aa29f@linux-foundation.org> In-Reply-To: <791a6c1c4a79de6f99bffc594b53a39a6234e87f.1689666760.git-series.apopple@nvidia.com> References: <791a6c1c4a79de6f99bffc594b53a39a6234e87f.1689666760.git-series.apopple@nvidia.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B727540018 X-Stat-Signature: cc75qypwz44qs1uwb7jtzkuxakfuqw9d X-Rspam-User: X-HE-Tag: 1689704282-78974 X-HE-Meta: U2FsdGVkX1+5oHVHdWp6owp55Wcddw+gHGxiaTrYiCFYPcP1pkc0mvEO5ifF4DJe9ezKS8eKW+GUK1i+SoGOraY7m2KC2cJEVeyEXYK5h/vIzcIQnjU15es5yHaoN/+xMsZJ2mBf2ikdVwPf/mToFZFZquv/fEPoV3g+2FFr7mNI2YwJDrN8kMdXIAMA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JowBthEv030UI2Ld68uSrlE2AV/8ty029OhtHkUrdhIcK1e/xiKBuAP9k7KxxO8VO6gJXKzRWftL53Z1fW1ujnIqd5aIdoMYz7+B3+IL0JDC02PxuEUx2JYCNExwjETmNw1EDS7sN9ThQdiAPjS/eXqeok/9EFdK/g+/ZXIvC+lj0TFRQ== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, 18 Jul 2023 17:56:17 +1000 Alistair Popple wrote: > The arch_invalidate_secondary_tlbs() is an architecture specific mmu > notifier used to keep the TLB of secondary MMUs such as an IOMMU in > sync with the CPU page tables. Currently it is called from separate > code paths to the main CPU TLB invalidations. This can lead to a > secondary TLB not getting invalidated when required and makes it hard > to reason about when exactly the secondary TLB is invalidated. > > To fix this move the notifier call to the architecture specific TLB > maintenance functions for architectures that have secondary MMUs > requiring explicit software invalidations. > > This fixes a SMMU bug on ARM64. On ARM64 PTE permission upgrades > require a TLB invalidation. This invalidation is done by the > architecutre specific ptep_set_access_flags() which calls > flush_tlb_page() if required. However this doesn't call the notifier > resulting in infinite faults being generated by devices using the SMMU > if it has previously cached a read-only PTE in it's TLB. This sounds like a pretty serious bug. Can it happen in current released kernels? If so, is a -stable backport needed? > Moving the invalidations into the TLB invalidation functions ensures > all invalidations happen at the same time as the CPU invalidation. The > architecture specific flush_tlb_all() routines do not call the > notifier as none of the IOMMUs require this.