From patchwork Thu Jul 20 21:42:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 123462 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp3408352vqt; Thu, 20 Jul 2023 15:12:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHjeVjTao+6urfEjNBE/xmb2xf38A65bisBCLprw4gSqY33nzjV5TlHJLvhZOtSXElEVAd0 X-Received: by 2002:a17:907:78c5:b0:973:daa0:2f6 with SMTP id kv5-20020a17090778c500b00973daa002f6mr66032ejc.3.1689891149137; Thu, 20 Jul 2023 15:12:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689891149; cv=none; d=google.com; s=arc-20160816; b=kvnhCmqFfsEciYXO5JMmm8eFvn0Bw9DvdKMLaD58GjDsh/AVQjuauCg2OWwYBFOjD/ vpPiVPZHrQZ41EyU70WFmpHhhckQV8l81Aqfx/Hya/lSvZRdki+22rWeMz8BftAuy0pz jEgZ9Wb5VM/9fWRjp9uYpsNUUPjkotfxkeTFAzM7LzQdPMOT7dGDTp5AcJqmKP1mG5XC 48HeQutjqwASg8GPmkl504GEihH5FeLPbRNr1neYNZXDlIXvq86oEyjTZqFUYjb7p+yM kC5KKJ45Aygmu/fjaqpUZTsxbGUsZvhsDXGkL5IezC+xdX5dLjimQiRSXPLW3YSwHeIM YCXw== 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:dkim-filter; bh=q2L8Aprxr7L3JdhqehKzgX5TwglfdvsCDN/hciIXqRg=; fh=IiLlUAYZQ4hWuQbi3V9KE00VdjFsw4tg4Y6JCUFRLn0=; b=EQotsS0FBaKPmqWG4WdN1D4ksCuCuyZ5JzxCocMUqMKkHzpJ9yAjm8SiOQlhjgPeLV U4pPyYeeJOeobJJu3x/XdiPDOVaDBT4IwCa2FlXhVLLofqfZe8krm6VZvhpJMsd04Yza +IatgiVFydhXUk2OTJncS7ofbyMSTMDiBNiO+I4fpMQ0YSujzvQU7+wKyUz3jbIlSE+Y eLN2t8kw757RY6h/q7u+PhcJNJTR4D4g3JQeCxo5M3SBIeYGjAflTT58bUPxzsgQ5bm6 CpAuWXWzDuYFc6HUqYY+78QnnvJl7kq5NrRShIiCJaeB3D1fRaM16tX/pRJWDGe/E7rM OcrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ZkHbtJLX; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y8-20020a170906470800b009882f2a8aabsi1352317ejq.551.2023.07.20.15.12.04; Thu, 20 Jul 2023 15:12:29 -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=@sberdevices.ru header.s=mail header.b=ZkHbtJLX; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=sberdevices.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229576AbjGTVsv (ORCPT + 99 others); Thu, 20 Jul 2023 17:48:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229457AbjGTVsc (ORCPT ); Thu, 20 Jul 2023 17:48:32 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23E642712; Thu, 20 Jul 2023 14:48:31 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id B11A4120005; Fri, 21 Jul 2023 00:48:29 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru B11A4120005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1689889709; bh=q2L8Aprxr7L3JdhqehKzgX5TwglfdvsCDN/hciIXqRg=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ZkHbtJLXlEqBfn+30e47IR3U42FVFr4417kJljm6Tsn25txsAz38HpHRR/pIpFk73 CiCERKgWQuYbQj8gXhDw8kKRBsLfo6gJFhVoYb1DWiygjf2jB9AtjBJsMpgVOiSSXg 5I8VZSvkX7DmASaL5Bw00Wc1mAciTv4+SbzRCBcEfwwMEo/mcyfc96k4TUulVt0t1W yOrS4vttqYfjwmFgUI1cgkXEAR9VWVlhifq0crHpNFrdUFjo2UPKL4gaFO4oxn8fpt pnsniuY+QsXkSWG13821PitpT4GIm7gnRUkqvG422oVKNfRUhDMj9XChihmBndmPTM PF0JixXLYj4zA== Received: from p-i-exch-sc-m01.sberdevices.ru (p-i-exch-sc-m01.sberdevices.ru [172.16.192.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.sberdevices.ru (Postfix) with ESMTPS; Fri, 21 Jul 2023 00:48:29 +0300 (MSK) Received: from localhost.localdomain (100.64.160.123) by p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Fri, 21 Jul 2023 00:48:28 +0300 From: Arseniy Krasnov To: Stefan Hajnoczi , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , "Michael S. Tsirkin" , Jason Wang , Bobby Eshleman CC: , , , , , , , Arseniy Krasnov Subject: [PATCH net-next v3 2/4] vsock/virtio: support to send non-linear skb Date: Fri, 21 Jul 2023 00:42:43 +0300 Message-ID: <20230720214245.457298-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230720214245.457298-1-AVKrasnov@sberdevices.ru> References: <20230720214245.457298-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [100.64.160.123] X-ClientProxiedBy: p-i-exch-sc-m02.sberdevices.ru (172.16.192.103) To p-i-exch-sc-m01.sberdevices.ru (172.16.192.107) X-KSMG-Rule-ID: 10 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Lua-Profiles: 178763 [Jul 20 2023] X-KSMG-AntiSpam-Version: 5.9.59.0 X-KSMG-AntiSpam-Envelope-From: AVKrasnov@sberdevices.ru X-KSMG-AntiSpam-Rate: 0 X-KSMG-AntiSpam-Status: not_detected X-KSMG-AntiSpam-Method: none X-KSMG-AntiSpam-Auth: dkim=none X-KSMG-AntiSpam-Info: LuaCore: 525 525 723604743bfbdb7e16728748c3fa45e9eba05f7d, {Tracking_from_domain_doesnt_match_to}, sberdevices.ru:5.0.1,7.1.1;127.0.0.199:7.1.2;p-i-exch-sc-m01.sberdevices.ru:5.0.1,7.1.1;100.64.160.123:7.1.2;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1, FromAlignment: s, {Tracking_white_helo}, ApMailHostAddress: 100.64.160.123 X-MS-Exchange-Organization-SCL: -1 X-KSMG-AntiSpam-Interceptor-Info: scan successful X-KSMG-AntiPhishing: Clean X-KSMG-LinksScanning: Clean X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.0.1.6960, bases: 2023/07/20 17:17:00 #21648761 X-KSMG-AntiVirus-Status: Clean, skipped X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE,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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771979301748061927 X-GMAIL-MSGID: 1771979301748061927 For non-linear skb use its pages from fragment array as buffers in virtio tx queue. These pages are already pinned by 'get_user_pages()' during such skb creation. Signed-off-by: Arseniy Krasnov Reviewed-by: Stefano Garzarella --- Changelog: v2 -> v3: * Comment about 'page_to_virt()' is updated. I don't remove R-b, as this change is quiet small I guess. net/vmw_vsock/virtio_transport.c | 41 +++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index e95df847176b..7bbcc8093e51 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -100,7 +100,9 @@ virtio_transport_send_pkt_work(struct work_struct *work) vq = vsock->vqs[VSOCK_VQ_TX]; for (;;) { - struct scatterlist hdr, buf, *sgs[2]; + /* +1 is for packet header. */ + struct scatterlist *sgs[MAX_SKB_FRAGS + 1]; + struct scatterlist bufs[MAX_SKB_FRAGS + 1]; int ret, in_sg = 0, out_sg = 0; struct sk_buff *skb; bool reply; @@ -111,12 +113,39 @@ virtio_transport_send_pkt_work(struct work_struct *work) virtio_transport_deliver_tap_pkt(skb); reply = virtio_vsock_skb_reply(skb); + sg_init_one(&bufs[out_sg], virtio_vsock_hdr(skb), + sizeof(*virtio_vsock_hdr(skb))); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + + if (!skb_is_nonlinear(skb)) { + if (skb->len > 0) { + sg_init_one(&bufs[out_sg], skb->data, skb->len); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + } + } else { + struct skb_shared_info *si; + int i; + + si = skb_shinfo(skb); + + for (i = 0; i < si->nr_frags; i++) { + skb_frag_t *skb_frag = &si->frags[i]; + void *va; - sg_init_one(&hdr, virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb))); - sgs[out_sg++] = &hdr; - if (skb->len > 0) { - sg_init_one(&buf, skb->data, skb->len); - sgs[out_sg++] = &buf; + /* We will use 'page_to_virt()' for the userspace page + * here, because virtio or dma-mapping layers will call + * 'virt_to_phys()' later to fill the buffer descriptor. + * We don't touch memory at "virtual" address of this page. + */ + va = page_to_virt(skb_frag->bv_page); + sg_init_one(&bufs[out_sg], + va + skb_frag->bv_offset, + skb_frag->bv_len); + sgs[out_sg] = &bufs[out_sg]; + out_sg++; + } } ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL);