Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1639241rdb; Mon, 8 Jan 2024 06:00:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEE7vc9K+DJDise+FIgM6fDbLjmnwtCJUoY5gSx9VuSyPeBosrjXDzktlGN5qt3LB0834p6 X-Received: by 2002:a05:6214:d4d:b0:680:d4a0:7173 with SMTP id 13-20020a0562140d4d00b00680d4a07173mr3135809qvr.96.1704722437970; Mon, 08 Jan 2024 06:00:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704722437; cv=none; d=google.com; s=arc-20160816; b=I/gg4Ax0/WV53JXqCX2Bt9cfQh3Qrkrx69EEKJt3TnWjOzjw/5PpGR6jAV6iczhFP+ 7ugbpdyNtD/+M/8yWw8qp5Fekw3wF4nAnZ3hRpqHnVTfib7ihLoM25PmyEqB7gAsvCmj WVQF6dqR90acu2jzK3ieEF0HDcRRnggV9il38PoepwYG5/W3bguG5TISF3gOmNgkJ8B2 nhOgHk7h6luOT2gbyn4fs4/u2RH7RL4x8gHYp8CibPvVgYR5W2jKXk33zSKByCjLkZGK k4LFvOvsPLajoJVAGC7ty5WD9uq5/tQufco5hM7jSPyJ0IGXSOZTtWktj/ZZVnWDLieu kqWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=CI9CfQfyZuKPdVQRzj+Ve+9P4EocoHayH44GiCsZhs0=; fh=YV9sm+238rh61pEFohXPzAfeYIwssiQmuyuLZ7d61Ek=; b=0UFZuFoadgoT9wm9YDz5OSiLyEsQ519K3PWNo1s0FgDFa1pO56wkKur/UmjQQcIUG7 7ayJR7ENqbhC+x1yKd41v043XXxKwc/NXuePSiIE5YEkW4HZFhIXVy/Fif76N6e0Y61z /w+i4gORQEkTUsnsKKITQvt2c6IihvEfQQdfmFsbnMuI4NKMwCQnaCpWwEiL4hqYSWIo FuLPvI6oKbDIybPZDoUOAmG7IgS3uX3dZfy4kP50+HiRWcEx/4j26XjA67NMMq41jCYK oK1wFdKm5JQYnVW/yU8+KkqcmPmeXhP2uz/2OmJyp2Qr22D1q5ONX4RxggJ/bOHWifq2 xLrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v17-20020a05622a131100b00427e87ba3e6si7846003qtk.157.2024.01.08.06.00.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 06:00:37 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-19660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19660-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A2EE51C2030B for ; Mon, 8 Jan 2024 14:00:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 032E546555; Mon, 8 Jan 2024 14:00:17 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3C9346442 for ; Mon, 8 Jan 2024 14:00:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4T7wdX71J2z1Q7sX; Mon, 8 Jan 2024 21:58:40 +0800 (CST) Received: from kwepemm600020.china.huawei.com (unknown [7.193.23.147]) by mail.maildlp.com (Postfix) with ESMTPS id 9EF3C140416; Mon, 8 Jan 2024 22:00:11 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Mon, 8 Jan 2024 22:00:10 +0800 From: Peng Zhang To: , , , , , CC: , , Subject: [PATCH] swiotlb: check alloc_size before the allocation of a new memory pool Date: Mon, 8 Jan 2024 22:00:05 +0800 Message-ID: <20240108140005.3355316-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemm600020.china.huawei.com (7.193.23.147) From: ZhangPeng The allocation request for swiotlb contiguous memory greater than 128*2KB cannot be fulfilled because it exceeds the maximum contiguous memory limit. If the swiotlb memory we allocate is larger than 128*2KB, swiotlb_find_slots() will still schedule the allocation of a new memory pool, which will increase memory overhead. Fix it by adding a check with alloc_size no more than 128*2KB before scheduling the allocation of a new memory pool in swiotlb_find_slots(). Signed-off-by: ZhangPeng --- kernel/dma/swiotlb.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 33d942615be5..cc92cff02c60 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -1126,6 +1126,9 @@ static int swiotlb_find_slots(struct device *dev, phys_addr_t orig_addr, u64 phys_limit; int index; + if (alloc_size > IO_TLB_SEGSIZE * IO_TLB_SIZE) + return -1; + rcu_read_lock(); list_for_each_entry_rcu(pool, &mem->pools, node) { index = swiotlb_pool_find_slots(dev, pool, orig_addr, -- 2.25.1