Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp911628rwr; Wed, 19 Apr 2023 15:19:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bLjnHs8eDdYb9Ra71p7//TQVg2KdovVKn3G8DZTg8p/bJ6HusJLdoGribbQ3An3edJWxAg X-Received: by 2002:a05:6a00:a09:b0:63b:7fc0:a4af with SMTP id p9-20020a056a000a0900b0063b7fc0a4afmr4945484pfh.26.1681942745268; Wed, 19 Apr 2023 15:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681942745; cv=none; d=google.com; s=arc-20160816; b=SXaCoT4hj8ynultQQlMAh6UL2kE3mm+g+PDcttxTlBJd+no4aK6VhtPyASfOml2GvZ wB5DrjlrZMOPKGAptLCpd8JGFZmJAPxRXUEoG8kHDszjDuLU84raMUBuJlio+F81Ey9P JAVV9otD38/N/sfyH/8cP5k9O68DtwscNRZ92wbaiP08a5toK8BwtT2dIUFtX/BhcMCF ADzD+AnyAwrBvz460guenWDml0gjxwud1pdG5ZnKvCRqlyfsZZTaduSzmLYqw5vxnWnW 2Bwrcohf7SeSEbEa6JVLnB0675TsxQKpuPoy1A2fHSyF0yYL6xcJ1O4Rj5M9xfRBpG15 UTvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mljZsiO5QRb1GQDkLUDPFjVfkuRVaSDyhp9y+byMdss=; b=aH0h/waUgLfWQNemETq0PSaPJC5Cn8Jl1xL7aReFmEYXGyXKoWUJTiZ32QsT46J1wX +bfY2ivQw0rvymWR4aAKvENIhkmYy6CPu8pg6S+wG+UfK1qMp+wBbj+X3aU7HzhUoMWa 0Eryw8CI/owrmTKhI91PH4fk/0RgZymjpPuMF6GdmuFgCsbY+d5z5031vJds3nEmG7y8 klxGUUm3Mt3Fta9GeWgY0s0CxXXJ9lbcXxfyAdiwoW4jtihiyJP1rfolFcPqJRId5vgS jZwsVYmOoyrepOxt4453sJ645BvyRGpHloR9G+JxnlhzvvEa6jbtWuxMdpJVUarr4c53 m/Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=rSiuLSw6; 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 m63-20020a625842000000b0063b1fbbb8c5si16389545pfb.131.2023.04.19.15.18.33; Wed, 19 Apr 2023 15:19:05 -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=rSiuLSw6; 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 S231218AbjDSWRi (ORCPT + 99 others); Wed, 19 Apr 2023 18:17:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbjDSWRd (ORCPT ); Wed, 19 Apr 2023 18:17:33 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A78151BD1 for ; Wed, 19 Apr 2023 15:17:32 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1a69f686345so4522935ad.2 for ; Wed, 19 Apr 2023 15:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681942652; x=1684534652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mljZsiO5QRb1GQDkLUDPFjVfkuRVaSDyhp9y+byMdss=; b=rSiuLSw6DyvgYFbph9bmFmqDG3DBHXwiC4IjLHTdoeoNqI3Zj5mvjcgftruD3sRQcL WxDYcG6ScHPYH/tsYrRzbCoTKzHkW8KNXh7K15sX/3vd0JxNdmgwDLmJ5Gbl1ptnc8kV B413qUWKvROFulz1VG3quMom7gr4KDz5SG6hA7i1NB7suVliV8jg80Ei4eKibGK25dVw IUKYu3sVmnUrAoFcDhoqyEJFPDZqPR+RsU7ZbMNTfRONc8CY2sotnhibyQDIiJL6WP4d uPsZMJmzwj1MOrHzXnjW7uCJa6/KKt6iVnYO2QkJX8Ox8I1aJyUyI4qshbT0yxib1Rsh ovBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681942652; x=1684534652; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mljZsiO5QRb1GQDkLUDPFjVfkuRVaSDyhp9y+byMdss=; b=bE8vPNDuv9TUXTxNBW6D6B9jRUpltjTiEeryg7UzXNSOSmgrY3CM1LRtHKyeekkdMv RAVC3YQRhxYgb9XkeDGjtuerdc9d2iCqcoW3GD6CzLMw6AgLLuF1ZnwM3g+GA9a8T6E3 bo4YyqsfMh7/wOxWnGAlOc7m22PqQquSsWVVVC7f7zpek6U//IH8Y0xyOj7apSkwo4GZ 4wy3/ybrGkRxbuz/eZNNfrGEEHM1qvxJR90e5Di5DMGrfR+lHNADInmnhBK8CXXSZedQ 961N7s3CVlgkqKFTK4G7Ie2xtkPARG1Gx4COlmnANtUXq8aSJO8D51Y0hWWM51nt3X8f UZQw== X-Gm-Message-State: AAQBX9esqhcSQMrWai4PZvuyoazGsyNrY5zhno0ygfo4sey2aENFOX0N xiGSgmzgs9f0SVHBmDFgalXW8VPLAr/eMHOyg3M= X-Received: by 2002:a17:902:e74c:b0:1a6:4200:bef4 with SMTP id p12-20020a170902e74c00b001a64200bef4mr7961111plf.56.1681942651818; Wed, 19 Apr 2023 15:17:31 -0700 (PDT) Received: from atishp.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id jn11-20020a170903050b00b00196807b5189sm11619190plb.292.2023.04.19.15.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Apr 2023 15:17:31 -0700 (PDT) From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Rajnesh Kanwal , Atish Patra , Alexandre Ghiti , Andrew Jones , Andrew Morton , Anup Patel , Atish Patra , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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 Subject: [RFC 01/48] mm/vmalloc: Introduce arch hooks to notify ioremap/unmap changes Date: Wed, 19 Apr 2023 15:16:29 -0700 Message-Id: <20230419221716.3603068-2-atishp@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230419221716.3603068-1-atishp@rivosinc.com> References: <20230419221716.3603068-1-atishp@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 guest. Add a pair if arch specific callbacks to track the ioremapped regions. 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. 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) +{ +} + 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, unsigned 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(vm)); + kfree(vm); } EXPORT_SYMBOL(vunmap); -- 2.25.1