Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1427713rwr; Thu, 20 Apr 2023 15:07:33 -0700 (PDT) X-Google-Smtp-Source: AKy350buU2mNwjnYu0acA8+PZnJKJF4tlb+8HRi+aScNjNk42E8G4JokEyEa3iU5qLwtqlDsTToR X-Received: by 2002:a05:6a20:3ca4:b0:f0:a92a:5088 with SMTP id b36-20020a056a203ca400b000f0a92a5088mr4080276pzj.44.1682028452915; Thu, 20 Apr 2023 15:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682028452; cv=none; d=google.com; s=arc-20160816; b=Qe6rBIiN8+m7A/bpmFbwGiIpK33Yv4ggN4GuODCeJx0VuPV4jjGQxgPag5yVHSK+4C dTrOvXpiW0lyZ/wiRccfw3VdctYDcsY2+xpzLrZWePBe7QJZj15uDeYmL/war5mBv4nd pxTZVlDv29uvb/4hZF92DKMtaAcV/se4ybE1+rWKg52AC62EpfzCfeGxUO3CKt+FJmOg l34dW1OLFo400lT6AHsZYNw9KI6te7ukLk1D7hJQWXja318Qxtc0hWtU3dbh/YrvFtqJ TgurK42wshMq0GuAeiYCDBCAbLWaQYO6/ADSTnYceX1ycrlCWiChetczXhm5RFKgOfGP 1kig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=m2Ev3XkqPH6pBRfYHzJ+uQ7XVHtYSI/8IWEmQRBv/YI=; b=ixLnrpTB4Ou4H2nMcX/gEKVFpQOL0xz9Tdre1AOlTDV2QokG+vgG2ghTgaU5Pa2eUz 1/7j/bD7imy2jxYhurSXYWieb+YtWM0P/NbZsZOjDxmcsH2ktOC/JeNkQhaOI7xJ/KmC m9Mzm3D+6xPEAfwsbeqbD9G7WTH2aWAD630+/lGh+KyYHmQKeI6CVjda3VcDg1H2LQyy RIooTGN7y8kUFh90UoEm191tJaX9BGdPmCfvyIjC83uft+VgaD+jKLvZTTgqI+QzgrWu mXiiw9YmYLnnyKZPHHFWxZQVjKdNBx+7jSIKhyCd2Ig/RDivWN5IgX1ND+VnRSnG2YQz s5fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=XccRPyOw; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 2-20020a631442000000b004fb95c8f645si2686981pgu.392.2023.04.20.15.07.18; Thu, 20 Apr 2023 15:07:32 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=XccRPyOw; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232762AbjDTWBa (ORCPT + 99 others); Thu, 20 Apr 2023 18:01:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229599AbjDTWB2 (ORCPT ); Thu, 20 Apr 2023 18:01:28 -0400 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 006141FE9 for ; Thu, 20 Apr 2023 15:01:26 -0700 (PDT) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-51b0f9d7d70so1529540a12.1 for ; Thu, 20 Apr 2023 15:01:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1682028086; x=1684620086; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=m2Ev3XkqPH6pBRfYHzJ+uQ7XVHtYSI/8IWEmQRBv/YI=; b=XccRPyOwGtCXf7M5O+HNfS7PIZwaQD/v87OkbY9kPKXbSXCwAHUwb77DmpKXQM0oF7 R0iGe67jW+b5DNWOVTJNemJXy3OKOX6KdYoUmETuzx9PGEbJFJQ2pUniMRMuVPMdDiGU /5tCrXANgIgLRaYyadJDbdo+RbIOZFK426WywYo54ew0ofNLXcABU5+/CMzqIREzPHeY nozuQwG7Zt6NpmqIblntxNB1TQq9MjpSBvyrh0FYtiq26IkPB90nc3IN0Z5SPpjDuFAg Uf2dafkB6vN/Ipj35Qgs/T7S7nQT6pBp/glwP+uShCgN0NssPyN9BTUsrhgWhmezZtGB kVTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682028086; x=1684620086; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=m2Ev3XkqPH6pBRfYHzJ+uQ7XVHtYSI/8IWEmQRBv/YI=; b=EYkfflrBR7cTZdmzIKCEl2PAuBH6kkmErnOgOBsV69Qugzixie3qsP7CuffMIbD3qJ K5wjk1Dha36jpUzTBXMzTLp6zPWkZJM8arsPfWH/6QWB2tUsgpA0Tj9NZeqZvY6iXK3K ahiFSNgH0SEdhtzlSiH3lFywFoUwT5Z7UXWJ5KNeOF7PYYzZFu/PcoiKANPdB7XrBNLd /SGJgLrb/QmGmjaypaVnYojOTGHzltMVTToMVyoooqpNnJWYY6lT553eE7bPYPjNDNlb 8VUudLz4URbgmHbs9BmKoVFbM0Tl636gXC0jIJ3GbYqvXrcXpi+GgqKTG3jvbgEUKTUQ Du6w== X-Gm-Message-State: AAQBX9eWBGYuRI8WorCoRAf6rxlVaOA+2QViYQVYPNO/hqed2lw91xG6 R2oSqwhy8i2EZuobHuXRXJVjD9yj8/hNTF2bboXzrw== X-Received: by 2002:a17:90a:5509:b0:247:a272:71d1 with SMTP id b9-20020a17090a550900b00247a27271d1mr3035541pji.7.1682028086370; Thu, 20 Apr 2023 15:01:26 -0700 (PDT) MIME-Version: 1.0 References: <20230419221716.3603068-1-atishp@rivosinc.com> <20230419221716.3603068-2-atishp@rivosinc.com> In-Reply-To: From: Atish Kumar Patra Date: Fri, 21 Apr 2023 03:31:15 +0530 Message-ID: Subject: Re: [RFC 01/48] mm/vmalloc: Introduce arch hooks to notify ioremap/unmap changes To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, Rajnesh Kanwal , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Suzuki K Poulose , Will Deacon , Marc Zyngier , Sean Christopherson , linux-coco@lists.linux.dev, Dylan Reid , abrestic@rivosinc.com, Samuel Ortiz , Christoph Hellwig , Conor Dooley , Greg Kroah-Hartman , Guo Ren , Heiko Stuebner , Jiri Slaby , kvm-riscv@lists.infradead.org, kvm@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, Mayuresh Chitale , Palmer Dabbelt , Paolo Bonzini , Paul Walmsley , Uladzislau Rezki Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Fri, Apr 21, 2023 at 1:12=E2=80=AFAM Lorenzo Stoakes wrote: > > I'm a vmalloc reviewer too now -next/mm-unstable get_maintainer.pl should= say > so, but forgivable because perhaps you ran against another tree but FYI f= or > future I'd appreciate a cc- :) > Ahh. Thanks for pointing that out. I see the patch for that now https://lkml.org/lkml/2023/3/21/1084 This series is based on 6.3-rc4. That's probably why get_maintainer.pl did not pick it up. I will make sure it includes you in the future revisions. > On Wed, Apr 19, 2023 at 03:16:29PM -0700, Atish Patra wrote: > > From: Rajnesh Kanwal > > > > In virtualization, the guest may need notify the host about the ioremap > > regions. This is a common usecase in confidential computing where the > > host only provides MMIO emulation for the regions specified by the gues= t. > > > > Add a pair if arch specific callbacks to track the ioremapped regions. > > Nit: typo if -> of. > Fixed. Thanks. > > > > This patch is based on pkvm patches. A generic arch config can be added > > similar to pkvm if this is going to be the final solution. The device > > authorization/filtering approach is very different from this and we > > may prefer that one as it provides more flexibility in terms of which > > devices are allowed for the confidential guests. > > So it's an RFC that assumes existing patches are already applied or do yo= u mean > something else here? What do I need to do to get to a vmalloc.c with your= patch > applied? > > I guess this is pretty nitty since your changes are small here but be goo= d to > know! > Here is a bit more context: This patch is inspired from Marc's pkvm patch[1= ] We haven't seen a revised version of that series. Thus, we are not sure if this is what will be the final solution for pKVM. The alternative solution is the guest device filtering approach. We are also tracking that which introduces a new set of functions (ioremap_hardned)[1] for authorized devices allowed for. That series doesn't require any changes to the vmalloc.c and this patch can be dropped. As the TDX implementation is not ready yet, we chose to go this way to get the ball rolling for implementing confidential computing in RISC-V. Our plan is to align with the solution that the upstream community finally agrees upon. [1] https://lore.kernel.org/kvm/20211007143852.pyae42sbovi4vk23@gator/t/#mc= 3480e2a1d69f91999aae11004941dbdfbbdd600 [2] https://github.com/intel/tdx/commit/d8bb168e10d1ba534cb83260d9a8a3c5b26= 9eb50 > > > > Signed-off-by: Rajnesh Kanwal > > Signed-off-by: Atish Patra > > --- > > mm/vmalloc.c | 16 ++++++++++++++++ > > 1 file changed, 16 insertions(+) > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index bef6cf2..023630e 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -304,6 +304,14 @@ static int vmap_range_noflush(unsigned long addr, = unsigned long end, > > return err; > > } > > > > +__weak void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size= , pgprot_t prot) > > +{ > > +} > > + > > +__weak void iounmap_phys_range_hook(phys_addr_t phys_addr, size_t size= ) > > +{ > > +} > > + > > I'm not sure if this is for efficiency by using a weak reference, however= , and > perhaps a nit, but I'd prefer an arch_*() that's defined in a header some= where, > as it does hide the call paths quite effectively. > Sure. Will do that. > > int ioremap_page_range(unsigned long addr, unsigned long end, > > phys_addr_t phys_addr, pgprot_t prot) > > { > > @@ -315,6 +323,10 @@ int ioremap_page_range(unsigned long addr, unsigne= d long end, > > if (!err) > > kmsan_ioremap_page_range(addr, end, phys_addr, prot, > > ioremap_max_page_shift); > > + > > + if (!err) > > + ioremap_phys_range_hook(phys_addr, end - addr, prot); > > + > > return err; > > } > > > > @@ -2772,6 +2784,10 @@ void vunmap(const void *addr) > > addr); > > return; > > } > > + > > + if (vm->flags & VM_IOREMAP) > > + iounmap_phys_range_hook(vm->phys_addr, get_vm_area_size(v= m)); > > + > > There are places other than ioremap_page_range() that can set VM_IOREMAP, > e.g. vmap_pfn(), so this may trigger with addresses other than those spec= ified > in the original hook. Is this intended? > Thanks for pointing that out. Yeah. That is not intentional. > > kfree(vm); > > } > > EXPORT_SYMBOL(vunmap); > > -- > > 2.25.1 > >