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 X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1696C4338F for ; Mon, 9 Aug 2021 17:56:50 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7976A610FD for ; Mon, 9 Aug 2021 17:56:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7976A610FD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 4A93482F4A; Mon, 9 Aug 2021 17:56:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yrDPcMb4O6Oc; Mon, 9 Aug 2021 17:56:49 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp1.osuosl.org (Postfix) with ESMTPS id 2B7C58294A; Mon, 9 Aug 2021 17:56:49 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 0842FC001A; Mon, 9 Aug 2021 17:56:49 +0000 (UTC) Received: from smtp2.osuosl.org (smtp2.osuosl.org [IPv6:2605:bc80:3010::133]) by lists.linuxfoundation.org (Postfix) with ESMTP id CFAC2C001F for ; Mon, 9 Aug 2021 17:56:47 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id 9C5B8400E5 for ; Mon, 9 Aug 2021 17:56:47 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp2.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Ei71-FKcwQha for ; Mon, 9 Aug 2021 17:56:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.8.0 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by smtp2.osuosl.org (Postfix) with ESMTPS id CB02D402BB for ; Mon, 9 Aug 2021 17:56:46 +0000 (UTC) Received: by mail-pj1-x1035.google.com with SMTP id lw7-20020a17090b1807b029017881cc80b7so56060pjb.3 for ; Mon, 09 Aug 2021 10:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PA42IhHl11PQF+ziOZyqqkyOZi1yWIuNrwvqLKrflPI=; b=h/75TBkZzgYxlqy+5bEldf+iKBjJjuhF9/Luw6D8+gOXVqnAuffjZyZ8csnCHDNkaP TBTvI5UGDLYZrsK4GmYd4KQc+RdWgrfqYrfbFj4qldX8+cUJjwg+jP8IXuDHZJNZVkMx dqt2tJ9id7Atn6XSeMLFGDJd1i/ItPabnc2w1Ou3dfKiAut9APiCcAttSlaxhKd7OD/O LOEDuYsC/sv3oUNGHz6aktEyuu3eBzTJBZiHW3J5x/IjafBs1g2Y/KGYNhEkna86o9xN FAWDsRYmSWvZzVnsYGN53JtMkrKJ/gW510NPFotXeN7Wa7z/uT9Mf7pgcf/x7yOe62Mi h8Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PA42IhHl11PQF+ziOZyqqkyOZi1yWIuNrwvqLKrflPI=; b=JqNIyPggawkLc2Ero7yS3oR/JodQ1pRkCq2zaMcTlkfu7h2s6AAvV7vnOK6Jn/Px3z DEiB+HyXZevLSoEkozZr5ncBnikv92P6eN9hh8FvGTCeVVqly8Vz7r4ZD6VWw1lJ1XHX cuIP9QCJBJtnuhKOQpVpWFLZ5H6mARztN5qobtmkqHuRS+V2ootDA4zsCiRB1vMQ26B1 p4RBiLvah0uEAZ0lYYV560pXFAWrNqjBhoEDQUo351mnxv7DP4Cf3SRMpA/sbK9msjMs 9vx9qjVIO5gkqukna83xJdT1n7uEEPKdFBK5eF5qcsAlRYrV2aWQ2H4BDs/QoxFz6OoB ubvw== X-Gm-Message-State: AOAM532/Kuy4gKzi5qD5K1RymFWQoYNn+zzrncLLv/z/O4C75T240u3f Zkdg9G2yCAVBW05WaonVl/8= X-Google-Smtp-Source: ABdhPJz2DoChBqY2+CqrU5gCYpuDqXcBgTbb8ssn2WkHPgcTXqW+Ddha4uJTbpahTSBY5KgKQGNxrQ== X-Received: by 2002:a17:902:8f87:b029:12c:dda2:39bf with SMTP id z7-20020a1709028f87b029012cdda239bfmr21283718plo.59.1628531806316; Mon, 09 Aug 2021 10:56:46 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:2:106e:6ed1:5da1:2ac4]) by smtp.gmail.com with ESMTPSA id x14sm20589708pfa.127.2021.08.09.10.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Aug 2021 10:56:46 -0700 (PDT) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, peterz@infradead.org, konrad.wilk@oracle.com, boris.ostrovsky@oracle.com, jgross@suse.com, sstabellini@kernel.org, joro@8bytes.org, will@kernel.org, davem@davemloft.net, kuba@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, arnd@arndb.de, hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, brijesh.singh@amd.com, ardb@kernel.org, Tianyu.Lan@microsoft.com, pgonda@google.com, martin.b.radev@gmail.com, akpm@linux-foundation.org, kirill.shutemov@linux.intel.com, rppt@kernel.org, sfr@canb.auug.org.au, saravanand@fb.com, krish.sadhukhan@oracle.com, aneesh.kumar@linux.ibm.com, xen-devel@lists.xenproject.org, rientjes@google.com, hannes@cmpxchg.org, tj@kernel.org, michael.h.kelley@microsoft.com Subject: [PATCH V3 09/13] DMA: Add dma_map_decrypted/dma_unmap_encrypted() function Date: Mon, 9 Aug 2021 13:56:13 -0400 Message-Id: <20210809175620.720923-10-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809175620.720923-1-ltykernel@gmail.com> References: <20210809175620.720923-1-ltykernel@gmail.com> MIME-Version: 1.0 Cc: linux-arch@vger.kernel.org, parri.andrea@gmail.com, linux-hyperv@vger.kernel.org, linux-scsi@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, iommu@lists.linux-foundation.org, vkuznets@redhat.com X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" From: Tianyu Lan In Hyper-V Isolation VM with AMD SEV, swiotlb boucne buffer needs to be mapped into address space above vTOM and so introduce dma_map_decrypted/dma_unmap_encrypted() to map/unmap bounce buffer memory. The platform can populate man/unmap callback in the dma memory decrypted ops. --- include/linux/dma-map-ops.h | 9 +++++++++ kernel/dma/mapping.c | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/linux/dma-map-ops.h b/include/linux/dma-map-ops.h index 0d53a96a3d64..01d60a024e45 100644 --- a/include/linux/dma-map-ops.h +++ b/include/linux/dma-map-ops.h @@ -71,6 +71,11 @@ struct dma_map_ops { unsigned long (*get_merge_boundary)(struct device *dev); }; +struct dma_memory_decrypted_ops { + void *(*map)(void *addr, unsigned long size); + void (*unmap)(void *addr); +}; + #ifdef CONFIG_DMA_OPS #include @@ -374,6 +379,10 @@ static inline void debug_dma_dump_mappings(struct device *dev) } #endif /* CONFIG_DMA_API_DEBUG */ +void *dma_map_decrypted(void *addr, unsigned long size); +int dma_unmap_decrypted(void *addr, unsigned long size); + extern const struct dma_map_ops dma_dummy_ops; +extern struct dma_memory_decrypted_ops dma_memory_generic_decrypted_ops; #endif /* _LINUX_DMA_MAP_OPS_H */ diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 2b06a809d0b9..6fb150dc1750 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -13,11 +13,13 @@ #include #include #include +#include #include "debug.h" #include "direct.h" bool dma_default_coherent; +struct dma_memory_decrypted_ops dma_memory_generic_decrypted_ops; /* * Managed DMA API */ @@ -736,3 +738,23 @@ unsigned long dma_get_merge_boundary(struct device *dev) return ops->get_merge_boundary(dev); } EXPORT_SYMBOL_GPL(dma_get_merge_boundary); + +void *dma_map_decrypted(void *addr, unsigned long size) +{ + if (set_memory_decrypted((unsigned long)addr, + size / PAGE_SIZE)) + return NULL; + + if (dma_memory_generic_decrypted_ops.map) + return dma_memory_generic_decrypted_ops.map(addr, size); + else + return addr; +} + +int dma_unmap_encrypted(void *addr, unsigned long size) +{ + if (dma_memory_generic_decrypted_ops.unmap) + dma_memory_generic_decrypted_ops.unmap(addr); + + return set_memory_encrypted((unsigned long)addr, size / PAGE_SIZE); +} -- 2.25.1 _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu