Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4588965pxv; Tue, 20 Jul 2021 07:14:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfBljxhEvu+7O3VAcKRFnwXBsjF2IZXwjM/12kkL/TDFgjc8wgNeSrMsmkdPZsXSJB1fvg X-Received: by 2002:a05:6402:3489:: with SMTP id v9mr26364890edc.124.1626790484894; Tue, 20 Jul 2021 07:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626790484; cv=none; d=google.com; s=arc-20160816; b=zM7zJX6L1b8ludjYmIW0vdr8EOMkJG7Ligs8F51QYfkbXGwi7huw6qjqUh7IauxIIX 3mhyHrm+AcnPE86IFNQU09xC4BDicQoqe92hkQYZ3VcKKskemDNfpD/GaC3foy5CVzYi WZwzp/0NsskEiDDlO6syLM1y3rQDnvnMyuWeLbf0s8bRP6DMRPMbJNTnWkX5bO/GAy0S HaTYP4mlYgGI0M5omeTGGgGnwbzVyMvpgV38+rMULAwOhRRzBUj2UJJR+vV6YtFDJ3Si VTUhfg4aI+DiIaElST0zzfxjIBcLzMUli9V4LiBfkaEdTkRdNar/0+gNaYuUn5xqge+W 97sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=zoHnx53AyMJwz149SQ82bd+i5A8LKjVSEPs9ITMRjkc=; b=hHYYt1IjENKx9YemBFwOLvknyBKY3oNxUR4aWpCGoAA9coAqNfxTslAFzPZD6lCCJu 5DGq+7WRuV2VzeOhIgEI1kHApeg2x9JhoDwmEFPi7WZi9Wy2M0GTh8qydcBKSjpVpPZ2 8Q4N0r/E8l+cPRgTWCK+76Ix2OXqwYLcLHPJTxuXH7kWfJipJZnH47cTXLgm4RZ+SFER t3Ru8jHpg2UvMciOywvplmlOcnzA6ITmWHbdniQH5nnhr+Bq9s3C+4a/0yfCyv5MIaUm qpJ1UxRmCI5lGXRsAoz8JHyy07C9EY4ctLhRxpsGiHwKfx4LpuufRbAOhF0rsOLnNHXB aOfw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id fs15si21278915ejc.430.2021.07.20.07.14.20; Tue, 20 Jul 2021 07:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238463AbhGTNcP (ORCPT + 99 others); Tue, 20 Jul 2021 09:32:15 -0400 Received: from verein.lst.de ([213.95.11.211]:55312 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239348AbhGTNOG (ORCPT ); Tue, 20 Jul 2021 09:14:06 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id C76616736F; Tue, 20 Jul 2021 15:54:37 +0200 (CEST) Date: Tue, 20 Jul 2021 15:54:37 +0200 From: Christoph Hellwig To: Tianyu Lan Cc: 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, kirill.shutemov@linux.intel.com, akpm@linux-foundation.org, rppt@kernel.org, Tianyu.Lan@microsoft.com, thomas.lendacky@amd.com, ardb@kernel.org, robh@kernel.org, nramas@linux.microsoft.com, pgonda@google.com, martin.b.radev@gmail.com, david@redhat.com, krish.sadhukhan@oracle.com, saravanand@fb.com, xen-devel@lists.xenproject.org, keescook@chromium.org, rientjes@google.com, hannes@cmpxchg.org, michael.h.kelley@microsoft.com, iommu@lists.linux-foundation.org, linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org, netdev@vger.kernel.org, vkuznets@redhat.com, brijesh.singh@amd.com, anparri@microsoft.com Subject: Re: [Resend RFC PATCH V4 09/13] x86/Swiotlb/HV: Add Swiotlb bounce buffer remap function for HV IVM Message-ID: <20210720135437.GA13554@lst.de> References: <20210707154629.3977369-1-ltykernel@gmail.com> <20210707154629.3977369-10-ltykernel@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210707154629.3977369-10-ltykernel@gmail.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Please split the swiotlb changes into a separate patch from the consumer. > } > + > +/* > + * hv_map_memory - map memory to extra space in the AMD SEV-SNP Isolation VM. > + */ > +unsigned long hv_map_memory(unsigned long addr, unsigned long size) > +{ > + unsigned long *pfns = kcalloc(size / HV_HYP_PAGE_SIZE, > + sizeof(unsigned long), > + GFP_KERNEL); > + unsigned long vaddr; > + int i; > + > + if (!pfns) > + return (unsigned long)NULL; > + > + for (i = 0; i < size / HV_HYP_PAGE_SIZE; i++) > + pfns[i] = virt_to_hvpfn((void *)addr + i * HV_HYP_PAGE_SIZE) + > + (ms_hyperv.shared_gpa_boundary >> HV_HYP_PAGE_SHIFT); > + > + vaddr = (unsigned long)vmap_pfn(pfns, size / HV_HYP_PAGE_SIZE, > + PAGE_KERNEL_IO); > + kfree(pfns); > + > + return vaddr; This seems to miss a 'select VMAP_PFN'. But more importantly I don't think this actually works. Various DMA APIs do expect a struct page backing, so how is this going to work with say dma_mmap_attrs or dma_get_sgtable_attrs? > +static unsigned long __map_memory(unsigned long addr, unsigned long size) > +{ > + if (hv_is_isolation_supported()) > + return hv_map_memory(addr, size); > + > + return addr; > +} > + > +static void __unmap_memory(unsigned long addr) > +{ > + if (hv_is_isolation_supported()) > + hv_unmap_memory(addr); > +} > + > +unsigned long set_memory_decrypted_map(unsigned long addr, unsigned long size) > +{ > + if (__set_memory_enc_dec(addr, size / PAGE_SIZE, false)) > + return (unsigned long)NULL; > + > + return __map_memory(addr, size); > +} > + > +int set_memory_encrypted_unmap(unsigned long addr, unsigned long size) > +{ > + __unmap_memory(addr); > + return __set_memory_enc_dec(addr, size / PAGE_SIZE, true); > +} Why this obsfucation into all kinds of strange helpers? Also I think we want an ops vectors (or alternative calls) instead of the random if checks here. > + * @vstart: The virtual start address of the swiotlb memory pool. The swiotlb > + * memory pool may be remapped in the memory encrypted case and store Normall we'd call this vaddr or cpu_addr. > - set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT); > - memset(vaddr, 0, bytes); > + mem->vstart = (void *)set_memory_decrypted_map((unsigned long)vaddr, bytes); Please always pass kernel virtual addresses as pointers. And I think these APIs might need better names, e.g. arch_dma_map_decrypted and arch_dma_unmap_decrypted. Also these will need fallback versions for non-x86 architectures that currently use memory encryption.