From nobody Sat Feb 7 22:01:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638692331; cv=none; d=zohomail.com; s=zohoarc; b=lX3pmxmdzJjhad2F0o5si2ODNiYsF90JOGE01pi0jRMz/h57who7VuN4vl7eGYRXNlRjqrboRbChe/i3Hrcd85TVyVigWJzAdpP3mN/mt0J8ti5NXEn/5FYpQeKaM5vurdPVOQkTat2kGg7gd0LgMM0nBTiit0cx3EHqKjiU4yI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638692331; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=brPB+isubduGZ0dFkchshqyMjV+4uHMaO2+7Xc0wGRk=; b=kMPRgO9Wpb3CeSlpdIvrVGnmbZjFAGeaw1MXepGa2NnGPqF8FrXDFIfmaaIiYIaGl0DzCQiypcTf2PQit1PYDu4WLKoHlzAdhTOE7TygraXFdLAHeK9mQ+zdMSlMSdX9s5PXryUvja0PC/TszC8rtn9AixdXe383GNEwjpP33mU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1638692331756597.6431452926593; Sun, 5 Dec 2021 00:18:51 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.238267.413028 (Exim 4.92) (envelope-from ) id 1mtmj6-0007WH-4b; Sun, 05 Dec 2021 08:18:28 +0000 Received: by outflank-mailman (output) from mailman id 238267.413028; Sun, 05 Dec 2021 08:18:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mtmj6-0007Vj-0l; Sun, 05 Dec 2021 08:18:28 +0000 Received: by outflank-mailman (input) for mailman id 238267; Sun, 05 Dec 2021 08:18:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mtmj4-0006T9-1E for xen-devel@lists.xenproject.org; Sun, 05 Dec 2021 08:18:26 +0000 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [2607:f8b0:4864:20::102a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id ea5d6651-55a3-11ec-a5e1-b9374ead2679; Sun, 05 Dec 2021 09:18:25 +0100 (CET) Received: by mail-pj1-x102a.google.com with SMTP id w33-20020a17090a6ba400b001a722a06212so7590564pjj.0 for ; Sun, 05 Dec 2021 00:18:25 -0800 (PST) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:7:87aa:e334:f070:ebca]) by smtp.gmail.com with ESMTPSA id s8sm6439905pgl.77.2021.12.05.00.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Dec 2021 00:18:23 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ea5d6651-55a3-11ec-a5e1-b9374ead2679 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=brPB+isubduGZ0dFkchshqyMjV+4uHMaO2+7Xc0wGRk=; b=d+pRTiyTvRH5TOIdeq8tkDweJDBPZRanHXQhj0YflzD4Il2KCdLON3cC58pHDs8qX9 OGEp/At7kf/f/+6HkyyKsAqzvAGnInBSq0i+DqkcYw3qOwJNcz5v/DdzlqrsWBz4dp3r ZrUePPnfHGvvxMJ8axGmVh/ZjNrM6QEcFVD5j49e0lYjjHlQN9RN9/AqEVHhOVaGGenW gtzqWAeiHKj1f/U/EfydqsGjRVi6DCB3x4MgQhKfD33v6xwaiSXh2e2GWM2D2iVnFMLP yQbMKY3jgpbGK4JwlKTX8SQfCFNQpLUcN96i5b7r6lFGqNBYGmwfN8dQSHd9Ipcb2/Mo U55A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=brPB+isubduGZ0dFkchshqyMjV+4uHMaO2+7Xc0wGRk=; b=Fn0em6kJvRkaE6LN+pQ5aUF81jgi95PI8i/5frhuh+ahYStfUsjZ0DLnNfKSa2D8m5 IIzp3vQRt7/gN/FKh2MUIk94vjDVJWnNcjz3U/t4A/jJWMLow1bgaI7JXgwHM2w3co6D G6rtaPiohVf3AWUjUO2r84lC/VJqGazU+LF39JnSzoeIemy8cePnsoZ36cHVk7yJKdad Gf8i1x6AfL/F75l5FcKhe48O5JMvGxQrMGXNG64nJeZh3eA5TTY5CtsVxeR+QZ/9Dccu X06JMPrECQB6GwD2qtB5ua95UVYodxfwCixkixDpgbTzJrj4sR24+4yPNdi8fwL5Gv/d Jgow== X-Gm-Message-State: AOAM531VelUd7+PbmkMnESHI7vbt40bKQ5hgBXUMUVz+X0p8PTWalBWP ndQJhFTM40uZjrJwfqM5biA= X-Google-Smtp-Source: ABdhPJzWds7gw4/7Hsf56r+CojhqWW7GcWTPaWgp5Pi8SFfxCERK/Yp6qhd5zk9W3uMOhKEfc1n27g== X-Received: by 2002:a17:90a:c287:: with SMTP id f7mr28508697pjt.114.1638692303692; Sun, 05 Dec 2021 00:18:23 -0800 (PST) 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, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, jgross@suse.com, sstabellini@kernel.org, boris.ostrovsky@oracle.com, joro@8bytes.org, will@kernel.org, davem@davemloft.net, kuba@kernel.org, jejb@linux.ibm.com, martin.petersen@oracle.com, arnd@arndb.de, hch@infradead.org, m.szyprowski@samsung.com, robin.murphy@arm.com, thomas.lendacky@amd.com, Tianyu.Lan@microsoft.com, xen-devel@lists.xenproject.org, michael.h.kelley@microsoft.com Cc: 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, konrad.wilk@oracle.com, hch@lst.de, parri.andrea@gmail.com, dave.hansen@intel.com Subject: [PATCH V4 4/5] scsi: storvsc: Add Isolation VM support for storvsc driver Date: Sun, 5 Dec 2021 03:18:12 -0500 Message-Id: <20211205081815.129276-5-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211205081815.129276-1-ltykernel@gmail.com> References: <20211205081815.129276-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1638692333302100003 Content-Type: text/plain; charset="utf-8" From: Tianyu Lan In Isolation VM, all shared memory with host needs to mark visible to host via hvcall. vmbus_establish_gpadl() has already done it for storvsc rx/tx ring buffer. The page buffer used by vmbus_sendpacket_ mpb_desc() still needs to be handled. Use DMA API(scsi_dma_map/unmap) to map these memory during sending/receiving packet and return swiotlb bounce buffer dma address. In Isolation VM, swiotlb bounce buffer is marked to be visible to host and the swiotlb force mode is enabled. Set device's dma min align mask to HV_HYP_PAGE_SIZE - 1 in order to keep the original data offset in the bounce buffer. Signed-off-by: Tianyu Lan --- drivers/hv/vmbus_drv.c | 1 + drivers/scsi/storvsc_drv.c | 37 +++++++++++++++++++++---------------- include/linux/hyperv.h | 1 + 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 0a64ccfafb8b..ae6ec503399a 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -2121,6 +2121,7 @@ int vmbus_device_register(struct hv_device *child_dev= ice_obj) hv_debug_add_dev_dir(child_device_obj); =20 child_device_obj->device.dma_mask =3D &vmbus_dma_mask; + child_device_obj->device.dma_parms =3D &child_device_obj->dma_parms; return 0; =20 err_kset_unregister: diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c index 20595c0ba0ae..ae293600d799 100644 --- a/drivers/scsi/storvsc_drv.c +++ b/drivers/scsi/storvsc_drv.c @@ -21,6 +21,8 @@ #include #include #include +#include + #include #include #include @@ -1336,6 +1338,7 @@ static void storvsc_on_channel_callback(void *context) continue; } request =3D (struct storvsc_cmd_request *)scsi_cmd_priv(scmnd); + scsi_dma_unmap(scmnd); } =20 storvsc_on_receive(stor_device, packet, request); @@ -1749,7 +1752,6 @@ static int storvsc_queuecommand(struct Scsi_Host *hos= t, struct scsi_cmnd *scmnd) struct hv_host_device *host_dev =3D shost_priv(host); struct hv_device *dev =3D host_dev->dev; struct storvsc_cmd_request *cmd_request =3D scsi_cmd_priv(scmnd); - int i; struct scatterlist *sgl; unsigned int sg_count; struct vmscsi_request *vm_srb; @@ -1831,10 +1833,11 @@ static int storvsc_queuecommand(struct Scsi_Host *h= ost, struct scsi_cmnd *scmnd) payload_sz =3D sizeof(cmd_request->mpb); =20 if (sg_count) { - unsigned int hvpgoff, hvpfns_to_add; unsigned long offset_in_hvpg =3D offset_in_hvpage(sgl->offset); unsigned int hvpg_count =3D HVPFN_UP(offset_in_hvpg + length); - u64 hvpfn; + struct scatterlist *sg; + unsigned long hvpfn, hvpfns_to_add; + int j, i =3D 0; =20 if (hvpg_count > MAX_PAGE_BUFFER_COUNT) { =20 @@ -1848,21 +1851,22 @@ static int storvsc_queuecommand(struct Scsi_Host *h= ost, struct scsi_cmnd *scmnd) payload->range.len =3D length; payload->range.offset =3D offset_in_hvpg; =20 + sg_count =3D scsi_dma_map(scmnd); + if (sg_count < 0) + return SCSI_MLQUEUE_DEVICE_BUSY; =20 - for (i =3D 0; sgl !=3D NULL; sgl =3D sg_next(sgl)) { + for_each_sg(sgl, sg, sg_count, j) { /* - * Init values for the current sgl entry. hvpgoff - * and hvpfns_to_add are in units of Hyper-V size - * pages. Handling the PAGE_SIZE !=3D HV_HYP_PAGE_SIZE - * case also handles values of sgl->offset that are - * larger than PAGE_SIZE. Such offsets are handled - * even on other than the first sgl entry, provided - * they are a multiple of PAGE_SIZE. + * Init values for the current sgl entry. hvpfns_to_add + * is in units of Hyper-V size pages. Handling the + * PAGE_SIZE !=3D HV_HYP_PAGE_SIZE case also handles + * values of sgl->offset that are larger than PAGE_SIZE. + * Such offsets are handled even on other than the first + * sgl entry, provided they are a multiple of PAGE_SIZE. */ - hvpgoff =3D HVPFN_DOWN(sgl->offset); - hvpfn =3D page_to_hvpfn(sg_page(sgl)) + hvpgoff; - hvpfns_to_add =3D HVPFN_UP(sgl->offset + sgl->length) - - hvpgoff; + hvpfn =3D HVPFN_DOWN(sg_dma_address(sg)); + hvpfns_to_add =3D HVPFN_UP(sg_dma_address(sg) + + sg_dma_len(sg)) - hvpfn; =20 /* * Fill the next portion of the PFN array with @@ -1872,7 +1876,7 @@ static int storvsc_queuecommand(struct Scsi_Host *hos= t, struct scsi_cmnd *scmnd) * the PFN array is filled. */ while (hvpfns_to_add--) - payload->range.pfn_array[i++] =3D hvpfn++; + payload->range.pfn_array[i++] =3D hvpfn++; } } =20 @@ -2016,6 +2020,7 @@ static int storvsc_probe(struct hv_device *device, stor_device->vmscsi_size_delta =3D sizeof(struct vmscsi_win8_extension); spin_lock_init(&stor_device->lock); hv_set_drvdata(device, stor_device); + dma_set_min_align_mask(&device->device, HV_HYP_PAGE_SIZE - 1); =20 stor_device->port_number =3D host->host_no; ret =3D storvsc_connect_to_vsp(device, storvsc_ringbuffer_size, is_fc); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 1f037e114dc8..74f5e92f91a0 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1261,6 +1261,7 @@ struct hv_device { =20 struct vmbus_channel *channel; struct kset *channels_kset; + struct device_dma_parameters dma_parms; =20 /* place holder to keep track of the dir for hv device in debugfs */ struct dentry *debug_dir; --=20 2.25.1