From patchwork Thu Jul 27 22:26: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: 127241 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp63634vqg; Thu, 27 Jul 2023 16:10:03 -0700 (PDT) X-Google-Smtp-Source: APBJJlHIzj7YJNUaHGs4k2SJC/zfBUksc47ylqbqgv0nzPeNRO/V60j0HEbhpWED9z/JAitoq/eg X-Received: by 2002:a05:6a20:3d05:b0:125:dd60:957a with SMTP id y5-20020a056a203d0500b00125dd60957amr58770pzi.26.1690499403236; Thu, 27 Jul 2023 16:10:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690499403; cv=none; d=google.com; s=arc-20160816; b=EoH4QRwTuFIOKBBUQtFSWX2Oib+6f1LERN/bj/Kph7vnfMkhqjBO2zQEYuRGYaxq4O QZc6XSj6XDJsax3wyS/LuddGyGUYMsQ9HCAei9RbqY3pEeF/9bJKbGQMgM0oyGafuMV7 uQ9PN4osaSk+joPDRU5VqhR+3nQ5B6mt+C3OH7IxA2zHoqSKFaKDeIyn7QCNsg7YfEC7 jyge6us1VKYER2ixsvefjFuWIP4BK2ZHQspVCIfd6f3619/gu9EhztjLunoMsGsVQ5tX dCgPjp1uk5VteJL3yCv5qTzQb1KGwhM4+zAbq/pAbt236moFzA5VMXh5VXmQBspU0ifu 3j2A== 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=PEfv2BHCQJ3YrSRsbnqxgJ0FO3uHkHDrfuvYGC2DIdxgM/bPHUOFMGzwLFFOmrXYzC H7+Q/ocPGWFubAdi0ckElRJRGj4jmO+QUuAfY1cHVOTkDfTPXMuPmZIvnp/B0yO71P5k r//wFtii6gaFHTB4jFCLqWgZwpkjx8WQvnlnkxAf1ijb6hLmMcABcEFcjWswy45Jsu/c DuCVc1+irGkwqcGr7vEj8YqAH+DEAdkPGt/mg9gTTzPw9RQmeSJsCo55ZR476G3nU4hS z4kx4VXivRFNFkCg/lYqCokhsSCGiXg7ULJihYCb4VWf3/G1nez+tezuWnAzQ2f/k0AN UCVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sberdevices.ru header.s=mail header.b=ErewW2HF; 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 a21-20020a63d415000000b0056371f9322asi1862447pgh.478.2023.07.27.16.09.49; Thu, 27 Jul 2023 16:10:03 -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=ErewW2HF; 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 S232958AbjG0Wc0 (ORCPT + 99 others); Thu, 27 Jul 2023 18:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232833AbjG0WcR (ORCPT ); Thu, 27 Jul 2023 18:32:17 -0400 Received: from mx1.sberdevices.ru (mx2.sberdevices.ru [45.89.224.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15A932D7E; Thu, 27 Jul 2023 15:32:14 -0700 (PDT) Received: from p-infra-ksmg-sc-msk02 (localhost [127.0.0.1]) by mx1.sberdevices.ru (Postfix) with ESMTP id 8DADC120006; Fri, 28 Jul 2023 01:32:12 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.sberdevices.ru 8DADC120006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1690497132; bh=q2L8Aprxr7L3JdhqehKzgX5TwglfdvsCDN/hciIXqRg=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ErewW2HFhBN8H0IaSaZJ6Oij7qHR1ZgFnFF21MT93X8vJwx5F8DHGvItZiwGR3KPi 98eR9WHjHvuxtT2DgNbXv+vzIp96vCnBUl7ZKZ4G/j8uPoZoFUOpmiYxzo52NtXdMs Lpib8A6bR4NjTQS8unUeZhUelYtPDCwL+SnQISzgOO+lx1m/nuY8YP9a0M1DyEEXT+ 9SlFuj1ljuJAp8MHkTFLGLT0Y9uZv/3IZ0lQUfilB8xMNP6e7WK3I9h4z92Oky97jX 6yIl3bvBn9cZxkD/BT6+8zcEayT01dHCfNpPthA8sdPVAHSWMSFfZjst02DfnzJsq9 z9oW3cmd7+kBg== 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, 28 Jul 2023 01:32:12 +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, 28 Jul 2023 01:31:52 +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 v4 2/4] vsock/virtio: support to send non-linear skb Date: Fri, 28 Jul 2023 01:26:25 +0300 Message-ID: <20230727222627.1895355-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230727222627.1895355-1-AVKrasnov@sberdevices.ru> References: <20230727222627.1895355-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: 178796 [Jul 22 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}, FromAlignment: s, 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/23 08:49:00 #21663637 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: 1772617102128129400 X-GMAIL-MSGID: 1772617102128129400 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);