Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp17125rwd; Tue, 30 May 2023 15:25:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7WKV68gwgR3AFfAR8qlGZlnmza7a3D0ltTq3EBW4Fm953r6+KKBGgaXva/z10w4QZEhCld X-Received: by 2002:a05:6a21:6d8c:b0:10b:d70d:f971 with SMTP id wl12-20020a056a216d8c00b0010bd70df971mr4147684pzb.3.1685485523016; Tue, 30 May 2023 15:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685485523; cv=none; d=google.com; s=arc-20160816; b=F487EtF7Yw+pk0Xb3++H5QXreWJHujh33VdIBgm+6aEB8RiQFNi2yrM1y87cjgSqCb +yPSOggsaXNvCl2IO3pqEOkAyHWMOGTK/K1tm9sbD7SBMtKTIwLn7JwvrRI4hVEw1cJl OSKRlkUi0TvdmxNc59qdJTnOD6ia2+as+TzjeQ94XafDYLijlFhvpXv7M341zvVLt6Xy C8WNhxIHlFbXNKI2jlHXUTL/P3AeyJ8go+4QN5T6px6aA0tIOY1RbbF0Ia46r9RX2ssK ukmHtVfybTt6r0YqAX+0UHu7mCNVqNMgyBcXbme6ZETo9tk6lDuYZbmrDqOSSWjADIhk f2eA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=gllGKsW6EGZXrfCcY2RdUJbcNCKzFTs597NLojSvrvI=; b=j4kGwOuORdVhEWbO469WjuDqKd5cDh2qVg5GcorwsrWY4+rSgr+8r4YggH5nixIKAv SWk9AL+m7LZIKxTQf6pEXjdoeVhez+jvrXnHaguE2gecGplM71E+TrN1t9+RWDfgBRLf 6kzMxZ0k/y5EXF5jVlFK84lCsgxFTiOJsLcjzFILo4C37oNCZ+zmV+vUrLU6D+ytXKQW ni/l61dkUUAsUlf1WZxkf+RXu49iWzjfDTXEGM1NVMfeXbRFhrOE0Ym+k54Km55hbEGf xbuljzlBzUHwWrTz0k66KdfRP7r7i62zirS+YoHME3lbpNgJSxQIGMDUGGLKKXzqv/Th /ykw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=YB21CRWL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a637a57000000b00537d3adaa10si11459110pgn.597.2023.05.30.15.25.09; Tue, 30 May 2023 15:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=YB21CRWL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233581AbjE3Voo (ORCPT + 99 others); Tue, 30 May 2023 17:44:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230222AbjE3Von (ORCPT ); Tue, 30 May 2023 17:44:43 -0400 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83278AA for ; Tue, 30 May 2023 14:44:42 -0700 (PDT) Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-64d48b8ecd2so5754315b3a.1 for ; Tue, 30 May 2023 14:44:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685483082; x=1688075082; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gllGKsW6EGZXrfCcY2RdUJbcNCKzFTs597NLojSvrvI=; b=YB21CRWLPbjctiVhKFr/qkUBgxJuoKPSp9aosRn38iTlwGDonkS0O/Z/efZVwH0eaI gW8phHmjr+GiJQZ8ewOsEijJkAOs9fcAFR0JoSwPuyfZuY6kI1nH3o+WdiRmkotLzm7E VZj947GiWEycCEkfzX1DoTNI5bwouXLx3YLqamJ3Dkj61BAHyfpA/tOra1Ct40WXkm9G jl3qNPsprl6wnx/eXDRLVpYH+IDiUfLK/D7yK7Ap9j8KODZ9WXVjJyx/h7sUYiXzddIq CdjwHdDutN+q6h1txM5nGCYa6MW6xx8HDPXIMKAyDiiuBMFOJ2Jc66k5rVxLkpQpsO// p5Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685483082; x=1688075082; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gllGKsW6EGZXrfCcY2RdUJbcNCKzFTs597NLojSvrvI=; b=WCLTYB3JmBof3yFTnK2+R9g5b8954eig7k3zTFb/Aaufd+wSqGfN0RIVJslGNmQoZG +lBsUvVMhnjnHRhD7yVqmHwt2nc/AyUwoabP9FrQ6c13W5nY8W9caFtXViFfBd/gbFO2 nsmz1QKtEkkV0Hybe5aC3sih9/JMbHgX8eFcD/PR6Ee/XJKA+4qtCWUOE6Yu/nWgvWSc aewYj+ncoakJOB6mLIbhBj/u8lm03W+iV+DDnCk1XxEMyMcoKtpRGvoeveg1v85DtTix pN8zR0Jc/I6N0OWC70cY1/iCztUwsN0YLX11fRHJeSfrUKxcIE/VgxGyvWPzw/r7X2DL AueQ== X-Gm-Message-State: AC+VfDz80x+MQbkUO+m+0SYQmI08hTpfT8c+kTjmZCHWUpP7e3qnO7S7 5FelUhvqoHq2AGUmEfEIuw5wt0XKHd8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:1399:b0:647:1eaf:9577 with SMTP id t25-20020a056a00139900b006471eaf9577mr1326642pfg.1.1685483082042; Tue, 30 May 2023 14:44:42 -0700 (PDT) Date: Tue, 30 May 2023 14:44:40 -0700 In-Reply-To: Mime-Version: 1.0 References: <3cece716fc09724793aa832e755abfc9d70a8bb3.1684892404.git-series.apopple@nvidia.com> <5d8e1f752051173d2d1b5c3e14b54eb3506ed3ef.1684892404.git-series.apopple@nvidia.com> <87pm6ii6qi.fsf@nvidia.com> <89dba89c-cb49-f917-31e4-3eafd484f4b2@arm.com> Message-ID: Subject: Re: [PATCH 2/2] arm64: Notify on pte permission upgrades From: Sean Christopherson To: Jason Gunthorpe Cc: Robin Murphy , Alistair Popple , Andrew Morton , will@kernel.org, catalin.marinas@arm.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, nicolinc@nvidia.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, John Hubbard , zhi.wang.linux@gmail.com Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 30, 2023, Jason Gunthorpe wrote: > IMHO I think we messed this up at some point.. > > Joerg added invalidate_range just for the iommu to use, so having it > be arch specific could make some sense. > > However, KVM later co-opted it to do this: > > commit e649b3f0188f8fd34dd0dde8d43fd3312b902fb2 > Author: Eiichi Tsukata > Date: Sat Jun 6 13:26:27 2020 +0900 > > KVM: x86: Fix APIC page invalidation race ... > The fix therefore is to reload the APIC-access page field in the VMCS > from kvm_mmu_notifier_invalidate_range() instead of ..._range_start(). > > Which I think is a hacky fix. Agreed, though as you note below, the invalidate_range() description does make it seem like a somewhat reasonable thing to do. > KVM already has locking for invalidate_start/end - it has to check > mmu_notifier_retry_cache() with the sequence numbers/etc around when > it does does hva_to_pfn() > > The bug is that the kvm_vcpu_reload_apic_access_page() path is > ignoring this locking so it ignores in-progress range > invalidations. It should spin until the invalidation clears like other > places in KVM. > > The comment is kind of misleading because drivers shouldn't be abusing > the iommu centric invalidate_range() thing to fix missing locking in > start/end users. :\ > > So if KVM could be fixed up we could make invalidate_range defined to > be an arch specific callback to synchronize the iommu TLB. And maybe rename invalidate_range() and/or invalidate_range_{start,end}() to make it super obvious that they are intended for two different purposes? E.g. instead of invalidate_range(), something like invalidate_secondary_tlbs(). FWIW, PPC's OpenCAPI support (drivers/misc/ocxl/link.c) also uses invalidate_range(). Though IIUC, the use case is the same as a "traditional" IOMMU, where a device can share the CPU's page tables, so maybe the devices can be considered IOMMUs in practice, if not in name? It allows an accelerator (which could be an FPGA, ASICs, ...) to access the host memory coherently, using virtual addresses. An OpenCAPI device can also host its own memory, that can be accessed from the host. > Sean? It's doable, though definitely not 6.4 material. I have patches coded up. Assuming testing goes well, I'll post them regardless of the OCXL side of things. I've disliked KVM's one-off use of invalidate_range() for a long time, this is a good excuse to get rid of it before KVM gains more usage.