Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp176042rwl; Wed, 9 Aug 2023 12:48:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEqilBQ/l1xkdDJ3j3RdPOml+8jzlrZRAEt7HtXspS0369Xz83Bdp7YB4xIl7VilmZubSV1 X-Received: by 2002:a17:906:2001:b0:99c:9e69:6a19 with SMTP id 1-20020a170906200100b0099c9e696a19mr79713ejo.18.1691610537239; Wed, 09 Aug 2023 12:48:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691610537; cv=none; d=google.com; s=arc-20160816; b=I+NQ2Yb/LhXir/3iYYkyIz/2MMNVOvxPcO00yZIoClIC5Cx1SqL+ciKCp0btSfmTM/ dzxyXKHIW8LR2SrJCgBm5oZrM5LTvhW36JHSaEKomop7z5u5gnH6CsdCh3HV9XCSUDgZ 0/eTZF3v7+l/emEQmISehtLaJP9h3U5GqspsqmXjFvf31pZd3EJfYYMfc8Vnu7g5mD7n ztfAvXhh7rn1TcKOjJqHUMJhsWhDvc4nFGkn3Wow4zQp5ybmP043qYYS/05/oyuI7Ng+ mxB5k2vmYTKsHexZ/beSUEXk6rtStFhGREzg9pvIqLxrrDw1f+GNCEXJPWapy1XFojmS NWOA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=RZ0TDIAWVWjKzQG/fNH2WZoDHlB8BqVrxrTKmYL0yWg=; fh=+jlIs6EWMXzKCHPfFzWh9BwqBP8lWjcuSsbyiMBXRrE=; b=IZXBIvOfeJn61bp4EHf3rRpjQKYppr8NbIv+JoplMvKtnECnJUyuR6k78yRWckRwIS /9za4bxbNZFhS7fmJ48D9hApCpz70QnJNd5BSblDE3UbrRxUWo9231X0Wf6zHW/MhRF7 IyafVJLu1cVpvUUQeomxrcnY7jCvrhZXJZGh9ZEcnyd1pBB6GQuKHwO0AXjsfIAhSoC2 b/nKTouFuK6hff36JPtJqiV8lBbaHGPxizd/BLm/L0OTaGZrzvrTOUEsAJFnZ7aou/7m KBRvQRhs/wvNg3rxuub08FmvXtE4kiQzsYych1QkorSX3dc+2eGPQt00241tr7R4cU2G tR8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=i4YqLRU+; 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=amazon.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ay10-20020a170906d28a00b0098e1bbc2cffsi9222231ejb.958.2023.08.09.12.48.32; Wed, 09 Aug 2023 12:48:57 -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=@amazon.com header.s=amazon201209 header.b=i4YqLRU+; 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=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbjHIQsD (ORCPT + 99 others); Wed, 9 Aug 2023 12:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229537AbjHIQsC (ORCPT ); Wed, 9 Aug 2023 12:48:02 -0400 Received: from smtp-fw-52003.amazon.com (smtp-fw-52003.amazon.com [52.119.213.152]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 618AF1FCC; Wed, 9 Aug 2023 09:48:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1691599682; x=1723135682; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=RZ0TDIAWVWjKzQG/fNH2WZoDHlB8BqVrxrTKmYL0yWg=; b=i4YqLRU+bm0mYYtMw0nAxEroCu+WZB/RppLKwPI7QaW9/bA61fBX/058 dxGrFD5vYwtPiNxF3WjU98p8tdahTc0S/QRO9B65FHRW6qd6Gv5/asp5U ByQ3LTOOczDMYUUtxGBqMJAgvFBToxWBelkGm9p6Y/MxT7DoWNOcNhCv7 Q=; X-IronPort-AV: E=Sophos;i="6.01,159,1684800000"; d="scan'208";a="601118400" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-1197e3af.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-52003.iad7.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Aug 2023 16:48:00 +0000 Received: from EX19MTAUWC001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2a-m6i4x-1197e3af.us-west-2.amazon.com (Postfix) with ESMTPS id BEB0D1040B3; Wed, 9 Aug 2023 16:47:58 +0000 (UTC) Received: from EX19D019UWB001.ant.amazon.com (10.13.139.189) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 9 Aug 2023 16:47:57 +0000 Received: from EX19MTAUEA001.ant.amazon.com (10.252.134.203) by EX19D019UWB001.ant.amazon.com (10.13.139.189) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Wed, 9 Aug 2023 16:47:56 +0000 Received: from u7187ce7291cc57.ant.amazon.com (10.135.199.88) by mail-relay.amazon.com (10.252.134.102) with Microsoft SMTP Server id 15.2.1118.30 via Frontend Transport; Wed, 9 Aug 2023 16:47:55 +0000 From: Tahsin Erdogan To: Willem de Bruijn , Jason Wang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Herbert Xu CC: Tahsin Erdogan , , Subject: [PATCH v4] tun: avoid high-order page allocation for packet header Date: Wed, 9 Aug 2023 09:47:52 -0700 Message-ID: <20230809164753.2247594-1-trdgn@amazon.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 When gso.hdr_len is zero and a packet is transmitted via write() or writev(), all payload is treated as header which requires a contiguous memory allocation. This allocation request is harder to satisfy, and may even fail if there is enough fragmentation. Note that sendmsg() code path limits the linear copy length, so this change makes write()/writev() and sendmsg() paths more consistent. Signed-off-by: Tahsin Erdogan --- v4: updated commit message address comments from Willem v3: rebase to latest net-next v2: replace linear == 0 with !linear v1: https://lore.kernel.org/all/20230726030936.1587269-1-trdgn@amazon.com/ drivers/net/tun.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index 973b2fc74de3..62106464f1b9 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -1523,7 +1523,7 @@ static struct sk_buff *tun_alloc_skb(struct tun_file *tfile, int err; /* Under a page? Don't bother with paged skb. */ - if (prepad + len < PAGE_SIZE || !linear) + if (prepad + len < PAGE_SIZE) linear = len; if (len - linear > MAX_SKB_FRAGS * (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) @@ -1840,6 +1840,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile, */ zerocopy = false; } else { + if (!linear) + linear = min_t(size_t, good_linear, copylen); + skb = tun_alloc_skb(tfile, align, copylen, linear, noblock); } -- 2.41.0