From patchwork Sat Jun 3 20:49:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 102922 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1843842vqr; Sat, 3 Jun 2023 14:04:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7+IG+k6+dTmD+mCigy/6jlXWYX7Es1zJNgl/csTQdTBbq8+f5hHz6maippgKYBXd/xTmQ0 X-Received: by 2002:a92:ca8a:0:b0:335:ebb8:1128 with SMTP id t10-20020a92ca8a000000b00335ebb81128mr12406082ilo.2.1685826265466; Sat, 03 Jun 2023 14:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685826265; cv=none; d=google.com; s=arc-20160816; b=klaQVgLA1swmx1AJuOBs2ak4Tr4y7K+RZcyYsQLPsQVlalLjC/KJAsLVEhYP+nT/Nf y0//j8uKmoAjg5T3wo0mKJi7WceHt4OsxZIJqfNgQSW2Cxtn7ESh6T9wKYLyyI4leBwa AueqdJAaLDglNrY+A5TNOnAbO1Zu/fykxf/4UieBrnF1PctPiPuITusB489TfmjYGUpe z4m1u0zWfI4JMbFEckT8q70uClthcIOOjoIUeQPcmAvovykOZcodreqUFimUwqR7NiMU TAnGopnoqkh2K2xL19OyxzbQexaNLhtlF6YEkBHylNuLFSZOhIgmY43D2slVkx+LOIrO jP2A== 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=12J3aUkd1001dQlCLmszH/Jlw+bRp81nuK6DQ+iFTnk=; b=peXh2fmvgMK69cTB7QjRi9wFEhJACJnoz4AYchbP6gaVavdqxEbwAp0yeEH+u5aWdW r4G5QPnJHKckclTA5fDZfXlYDqjpfpGF8cpc+Mb/s/FcdUR6tBQUt9JgWReRYeTZ2HP5 6IMPpp7JCuN7jToYP4T+1rQZHHOwHUgjgaU+KvCZZJ2ZLm5xMtjyErrsd/jCp1aFLhY5 R4GRtrOXA1LGPD+x/IzLXZ5lkxPwtwtZEGikY1pm6OjTrI8B7Ufi0J23ETlnZpM+w4R6 YCv7fbkhGZnaYKtv73BMhkteRCClITXZYywmnaGH/aq58RWioM/D5506vX/JCYm28Thd 9kcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=OzeEQXlL; 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 19-20020a631753000000b005346bd7dee9si3093727pgx.682.2023.06.03.14.04.13; Sat, 03 Jun 2023 14:04:25 -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=OzeEQXlL; 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 S232941AbjFCUzJ (ORCPT + 99 others); Sat, 3 Jun 2023 16:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbjFCUyy (ORCPT ); Sat, 3 Jun 2023 16:54:54 -0400 Received: from mx.sberdevices.ru (mx.sberdevices.ru [45.89.227.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16A191B7; Sat, 3 Jun 2023 13:54:49 -0700 (PDT) Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B18B55FD33; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1685825686; bh=12J3aUkd1001dQlCLmszH/Jlw+bRp81nuK6DQ+iFTnk=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=OzeEQXlLUG5SLF1/btlSkjrBq7Gu1yg80/B6vqrl87g4u7MaLTpJaA5RHB0iNpE6e 6jMjrxTYvjBHo8xkTKp8dbedDsCpyZGSBMSCclSL/POgWCysWXX88ERx78+mBhyoaT KB+A3amjimOeeAQPX9tV19GRNC4FzEAaNdpZjFNkOiiOWULHWn1x3P76q5GRGd7Hex qwATekJY0ZJwGczQsqdREfumXHCxL9wpUgMczRSVbXp9CL5BDXYUsnd/rfnnpgL/d3 fQMJcz4y2sxpOtgLzlYda5qcZ4U0zFQnHN6B0i4zNTNA35ptEOiQYfoVU143e71lgQ eKFsuvFBrfydA== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Sat, 3 Jun 2023 23:54:46 +0300 (MSK) 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: [RFC PATCH v4 03/17] vsock/virtio: support to send non-linear skb Date: Sat, 3 Jun 2023 23:49:25 +0300 Message-ID: <20230603204939.1598818-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> References: <20230603204939.1598818-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH02.sberdevices.ru (172.16.1.5) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/06/03 16:55:00 #21417531 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,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767716962199201786?= X-GMAIL-MSGID: =?utf-8?q?1767716962199201786?= 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: Bobby Eshleman --- net/vmw_vsock/virtio_transport.c | 37 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index e95df847176b..6053d8341091 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,35 @@ 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[0], virtio_vsock_hdr(skb), sizeof(*virtio_vsock_hdr(skb))); + sgs[out_sg++] = &bufs[0]; + + if (skb_is_nonlinear(skb)) { + 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 = page_to_virt(skb_frag->bv_page); + + /* We will use 'page_to_virt()' for userspace page here, + * because virtio layer will call 'virt_to_phys()' later + * to fill buffer descriptor. We don't touch memory at + * "virtual" address of this page. + */ + sg_init_one(&bufs[i + 1], + va + skb_frag->bv_offset, + skb_frag->bv_len); + sgs[out_sg++] = &bufs[i + 1]; + } + } else { + if (skb->len > 0) { + sg_init_one(&bufs[1], skb->data, skb->len); + sgs[out_sg++] = &bufs[1]; + } - 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; } ret = virtqueue_add_sgs(vq, sgs, out_sg, in_sg, skb, GFP_KERNEL);