Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7411858imu; Thu, 31 Jan 2019 09:39:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN40gKDFKvS99yGFR19+AZ1k0VytgW5L5uNqkDp83gdZ1kTdLaP561VfpwAA5AmJRW71Zge8 X-Received: by 2002:aa7:80d7:: with SMTP id a23mr35070551pfn.86.1548956364903; Thu, 31 Jan 2019 09:39:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548956364; cv=none; d=google.com; s=arc-20160816; b=ARyoZxc+7Mr7FWnbgeOtV189jTMWeJ1uAgZId1XVQuMGLZug8hrnVZkB8qaBJPfZqS o0txsh5s2xphM6Jr6W8eMt6mEr86VlLXh0j1LF1T/D226FpoFzmKMlp9gFoZ3POxvko4 fue+Ss+y02Bj1REZk/q41svJF9n350etIgEhvYNxLDyuLLnfSmb31T4AWGkjtwh7qrSP yfgxp39iCbJ5w9oF/EOeV53FTPWUAqK4SJrcv3mtAkVP2jlIUISBw72fqLKLfih0nZCX t1t3ce5NDVLzsOA9ym9DmlK6no09QamxoGSS8kYspU0YKXsHEwLdJwVpYndu29FPC9fk E16Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=caCipjrTHzk4BZMUKsbg3nffTKj/BrJ9/IkfrB5OOdY=; b=Y53CEfu0o2ml/+YGg3f0DGERmhIE6F75OylFsmutfKczklYn3RWOc3M2h+M/4ppxVL aqCgDoAbg7PSVnYOUQAr2H9gYjQ+M+Gz1pO7nT8fxmP52y/8hExu9Lf+E8EZWAROo93r fE/d3OsK5L+95Vq0GXGeqjz0DCXNCCXJHhvzlO6yTcSyPtiApKSvImVUSsCPlq8j9Jnu 3EJiTIhGjQW14MJjyi8QqzBG+2kZE5l1iiqJjMChcix/cpQbq4+HZM623oyazwSxzqSx HBOVvoAnkPevMbEw6WhxYAnmYlzlxC/4YmaJF9cJgPHg+NQoQwXoPcujkfCo8KUT8GeL c1ow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q5si4274763pgb.245.2019.01.31.09.39.09; Thu, 31 Jan 2019 09:39:24 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730331AbfAaRLh (ORCPT + 99 others); Thu, 31 Jan 2019 12:11:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51278 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbfAaRLg (ORCPT ); Thu, 31 Jan 2019 12:11:36 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44F0F2F3; Thu, 31 Jan 2019 17:11:35 +0000 (UTC) Received: from sky.random (ovpn-121-14.rdu2.redhat.com [10.10.121.14]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24AEB1048128; Thu, 31 Jan 2019 17:11:07 +0000 (UTC) Date: Thu, 31 Jan 2019 12:11:06 -0500 From: Andrea Arcangeli To: Peter Xu Cc: linux-kernel@vger.kernel.org, Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Alistair Popple , Alexey Kardashevskiy , Mark Hairgrove , Balbir Singh , David Gibson , Jerome Glisse , Jason Wang , linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH] powerpc/powernv/npu: Remove redundant change_pte() hook Message-ID: <20190131171106.GD19324@redhat.com> References: <20190131103022.10218-1-peterx@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190131103022.10218-1-peterx@redhat.com> User-Agent: Mutt/1.11.2 (2019-01-07) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 31 Jan 2019 17:11:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 31, 2019 at 06:30:22PM +0800, Peter Xu wrote: > The change_pte() notifier was designed to use as a quick path to > update secondary MMU PTEs on write permission changes or PFN changes. > For KVM, it could reduce the vm-exits when vcpu faults on the pages > that was touched up by KSM. It's not used to do cache invalidations, > for example, if we see the notifier will be called before the real PTE > update after all (please see set_pte_at_notify that set_pte_at was > called later). > > All the necessary cache invalidation should all be done in > invalidate_range() already. > > CC: Benjamin Herrenschmidt > CC: Paul Mackerras > CC: Michael Ellerman > CC: Alistair Popple > CC: Alexey Kardashevskiy > CC: Mark Hairgrove > CC: Balbir Singh > CC: David Gibson > CC: Andrea Arcangeli > CC: Jerome Glisse > CC: Jason Wang > CC: linuxppc-dev@lists.ozlabs.org > CC: linux-kernel@vger.kernel.org > Signed-off-by: Peter Xu > --- > arch/powerpc/platforms/powernv/npu-dma.c | 10 ---------- > 1 file changed, 10 deletions(-) Reviewed-by: Andrea Arcangeli It doesn't make sense to implement change_pte as an invalidate, change_pte is not compulsory to implement so if one wants to have invalidates only, change_pte method shouldn't be implemented in the first place and the common code will guarantee to invoke the range invalidates instead. Currently the whole change_pte optimization is effectively disabled as noted in past discussions with Jerome (because of the range invalidates that always surrounds it), so we need to revisit the whole change_pte logic and decide it to re-enable it or to drop it as a whole, but in the meantime it's good to cleanup spots like below that should leave change_pte alone. There are several examples of mmu_notifiers_ops in the kernel that don't implement change_pte, in fact it's the majority. Of all mmu notifier users, only nv_nmmu_notifier_ops, intel_mmuops_change and kvm_mmu_notifier_ops implements change_pte and as Peter found out by source review nv_nmmu_notifier_ops, intel_mmuops_change are wrong about it and should stop implementing it as an invalidate. In short change_pte is only implemented correctly from KVM which can really updates the spte and flushes the TLB but the spte update remains and could avoid a vmexit if we figure out how to re-enable the optimization safely (the TLB fill after change_pte in KVM EPT/shadow secondary MMU will be looked up by the CPU in hardware). If change_pte is implemented, it should update the mapping like KVM does and not do an invalidate. Thanks, Andrea > > diff --git a/arch/powerpc/platforms/powernv/npu-dma.c b/arch/powerpc/platforms/powernv/npu-dma.c > index 3f58c7dbd581..c003b29d870e 100644 > --- a/arch/powerpc/platforms/powernv/npu-dma.c > +++ b/arch/powerpc/platforms/powernv/npu-dma.c > @@ -917,15 +917,6 @@ static void pnv_npu2_mn_release(struct mmu_notifier *mn, > mmio_invalidate(npu_context, 0, ~0UL); > } > > -static void pnv_npu2_mn_change_pte(struct mmu_notifier *mn, > - struct mm_struct *mm, > - unsigned long address, > - pte_t pte) > -{ > - struct npu_context *npu_context = mn_to_npu_context(mn); > - mmio_invalidate(npu_context, address, PAGE_SIZE); > -} > - > static void pnv_npu2_mn_invalidate_range(struct mmu_notifier *mn, > struct mm_struct *mm, > unsigned long start, unsigned long end) > @@ -936,7 +927,6 @@ static void pnv_npu2_mn_invalidate_range(struct mmu_notifier *mn, > > static const struct mmu_notifier_ops nv_nmmu_notifier_ops = { > .release = pnv_npu2_mn_release, > - .change_pte = pnv_npu2_mn_change_pte, > .invalidate_range = pnv_npu2_mn_invalidate_range, > }; > > -- > 2.17.1 >